Skip to content

Commit bf84fa6

Browse files
committed
complete fapi
1 parent d68a042 commit bf84fa6

File tree

11 files changed

+109
-125
lines changed

11 files changed

+109
-125
lines changed

packages/clerk-js/src/core/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ export const SIGN_UP_MODES = {
5454
} satisfies Record<string, SignUpModes>;
5555

5656
// This is the currently supported version of the Frontend API
57-
export const SUPPORTED_FAPI_VERSION = '2025-10-01';
57+
export const SUPPORTED_FAPI_VERSION = '2025-11-10';

packages/clerk-js/src/core/resources/BillingCheckout.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class BillingCheckout extends BaseResource implements BillingCheckoutReso
2828
status!: 'needs_confirmation' | 'completed';
2929
totals!: BillingCheckoutTotals;
3030
isImmediatePlanChange!: boolean;
31-
freeTrialEndsAt!: Date | null;
31+
freeTrialEndsAt?: Date;
3232
payer!: BillingPayerResource;
3333
needsPaymentMethod!: boolean;
3434

@@ -52,7 +52,9 @@ export class BillingCheckout extends BaseResource implements BillingCheckoutReso
5252
this.status = data.status;
5353
this.totals = billingTotalsFromJSON(data.totals);
5454
this.isImmediatePlanChange = data.is_immediate_plan_change;
55-
this.freeTrialEndsAt = data.free_trial_ends_at ? unixEpochToDate(data.free_trial_ends_at) : null;
55+
if (data.free_trial_ends_at) {
56+
this.freeTrialEndsAt = unixEpochToDate(data.free_trial_ends_at);
57+
}
5658
this.payer = new BillingPayer(data.payer);
5759
this.needsPaymentMethod = data.needs_payment_method;
5860
return this;

packages/clerk-js/src/core/resources/BillingPayer.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { BaseResource } from './internal';
66

77
export class BillingPayer extends BaseResource implements BillingPayerResource {
88
id!: string;
9-
createdAt?: Date | null;
10-
updatedAt?: Date | null;
11-
imageUrl?: string | null;
12-
userId?: string | null;
9+
createdAt?: Date;
10+
updatedAt?: Date;
11+
imageUrl?: string;
12+
userId: string | null = null;
1313
email?: string | null;
1414
firstName?: string | null;
1515
lastName?: string | null;
16-
organizationId?: string | null;
16+
organizationId: string | null = null;
1717
organizationName?: string | null;
1818

1919
constructor(data: BillingPayerJSON) {
@@ -27,10 +27,12 @@ export class BillingPayer extends BaseResource implements BillingPayerResource {
2727
}
2828

2929
this.id = data.id;
30-
this.createdAt =
31-
data.created_at === undefined ? undefined : data.created_at === null ? null : unixEpochToDate(data.created_at);
32-
this.updatedAt =
33-
data.updated_at === undefined ? undefined : data.updated_at === null ? null : unixEpochToDate(data.updated_at);
30+
if (data.created_at) {
31+
this.createdAt = unixEpochToDate(data.created_at);
32+
}
33+
if (data.updated_at) {
34+
this.updatedAt = unixEpochToDate(data.updated_at);
35+
}
3436
this.imageUrl = data.image_url;
3537
this.userId = data.user_id ?? null;
3638
this.email = data.email ?? null;

packages/clerk-js/src/core/resources/BillingPayment.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { BaseResource, BillingPaymentMethod, BillingSubscriptionItem } from './i
1515
export class BillingPayment extends BaseResource implements BillingPaymentResource {
1616
id!: string;
1717
amount!: BillingMoneyAmount;
18-
failedAt?: Date;
19-
paidAt?: Date;
18+
failedAt: Date | null = null;
19+
paidAt: Date | null = null;
2020
updatedAt!: Date;
2121
paymentMethod: BillingPaymentMethodResource | null = null;
2222
subscriptionItem!: BillingSubscriptionItemResource;
@@ -35,8 +35,8 @@ export class BillingPayment extends BaseResource implements BillingPaymentResour
3535

3636
this.id = data.id;
3737
this.amount = billingMoneyAmountFromJSON(data.amount);
38-
this.paidAt = data.paid_at ? unixEpochToDate(data.paid_at) : undefined;
39-
this.failedAt = data.failed_at ? unixEpochToDate(data.failed_at) : undefined;
38+
this.paidAt = data.paid_at ? unixEpochToDate(data.paid_at) : null;
39+
this.failedAt = data.failed_at ? unixEpochToDate(data.failed_at) : null;
4040
this.updatedAt = unixEpochToDate(data.updated_at);
4141
this.paymentMethod = data.payment_method ? new BillingPaymentMethod(data.payment_method) : null;
4242
this.subscriptionItem = new BillingSubscriptionItem(data.subscription_item);

packages/clerk-js/src/core/resources/BillingPaymentMethod.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { BaseResource, DeletedObject } from './internal';
1717
export class BillingPaymentMethod extends BaseResource implements BillingPaymentMethodResource {
1818
id!: string;
1919
last4: string | null = null;
20-
paymentType?: 'card' | 'link';
20+
paymentType?: 'card';
2121
cardType: string | null = null;
2222
isDefault?: boolean;
2323
isRemovable?: boolean;
@@ -39,20 +39,17 @@ export class BillingPaymentMethod extends BaseResource implements BillingPayment
3939
}
4040

4141
this.id = data.id;
42-
this.last4 = data.last4 ?? null;
43-
const rawPaymentType = data.payment_type ?? data.payment_method;
44-
this.paymentType = rawPaymentType === undefined ? undefined : (rawPaymentType as 'card' | 'link');
45-
this.cardType = data.card_type ?? null;
46-
this.isDefault = data.is_default ?? undefined;
47-
this.isRemovable = data.is_removable ?? undefined;
42+
this.last4 = data.last4;
43+
this.paymentType = data.payment_type;
44+
this.cardType = data.card_type;
45+
this.isDefault = data.is_default;
46+
this.isRemovable = data.is_removable;
4847
this.status = data.status;
49-
this.walletType = data.wallet_type === undefined ? undefined : data.wallet_type;
50-
this.expiryYear = data.expiry_year ?? null;
51-
this.expiryMonth = data.expiry_month ?? null;
52-
this.createdAt =
53-
data.created_at === undefined ? undefined : data.created_at === null ? null : unixEpochToDate(data.created_at);
54-
this.updatedAt =
55-
data.updated_at === undefined ? undefined : data.updated_at === null ? null : unixEpochToDate(data.updated_at);
48+
this.walletType = data.wallet_type;
49+
this.expiryYear = data.expiry_year;
50+
this.expiryMonth = data.expiry_month;
51+
this.createdAt = data.created_at == null ? data.created_at : unixEpochToDate(data.created_at);
52+
this.updatedAt = data.updated_at == null ? data.updated_at : unixEpochToDate(data.updated_at);
5653

5754
return this;
5855
}

packages/clerk-js/src/core/resources/BillingSubscription.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export class BillingSubscription extends BaseResource implements BillingSubscrip
2323
createdAt!: Date;
2424
pastDueAt!: Date | null;
2525
updatedAt!: Date | null;
26-
nextPayment: {
26+
nextPayment?: {
2727
amount: BillingMoneyAmount;
2828
date: Date;
29-
} | null = null;
29+
};
3030
subscriptionItems!: BillingSubscriptionItemResource[];
31-
eligibleForFreeTrial?: boolean;
31+
eligibleForFreeTrial!: boolean;
3232

3333
constructor(data: BillingSubscriptionJSON) {
3434
super();
@@ -46,12 +46,14 @@ export class BillingSubscription extends BaseResource implements BillingSubscrip
4646
this.updatedAt = data.updated_at ? unixEpochToDate(data.updated_at) : null;
4747
this.activeAt = unixEpochToDate(data.active_at);
4848
this.pastDueAt = data.past_due_at ? unixEpochToDate(data.past_due_at) : null;
49-
this.nextPayment = data.next_payment
50-
? {
51-
amount: billingMoneyAmountFromJSON(data.next_payment.amount),
52-
date: unixEpochToDate(data.next_payment.date),
53-
}
54-
: null;
49+
50+
if (data.next_payment) {
51+
this.nextPayment = {
52+
amount: billingMoneyAmountFromJSON(data.next_payment.amount),
53+
date: unixEpochToDate(data.next_payment.date),
54+
};
55+
}
56+
5557
this.subscriptionItems = (data.subscription_items || []).map(item => new BillingSubscriptionItem(item));
5658
this.eligibleForFreeTrial = this.withDefault(data.eligible_for_free_trial, false);
5759
return this;

packages/clerk-js/src/core/resources/CommerceSettings.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BaseResource } from './internal';
77
*/
88
export class CommerceSettings extends BaseResource implements CommerceSettingsResource {
99
billing: CommerceSettingsResource['billing'] = {
10-
stripePublishableKey: '',
10+
stripePublishableKey: null,
1111
organization: {
1212
enabled: false,
1313
hasPaidPlans: false,
@@ -28,11 +28,11 @@ export class CommerceSettings extends BaseResource implements CommerceSettingsRe
2828
return this;
2929
}
3030

31-
this.billing.stripePublishableKey = data.billing.stripe_publishable_key || '';
32-
this.billing.organization.enabled = data.billing.organization.enabled || false;
33-
this.billing.organization.hasPaidPlans = data.billing.organization.has_paid_plans || false;
34-
this.billing.user.enabled = data.billing.user.enabled || false;
35-
this.billing.user.hasPaidPlans = data.billing.user.has_paid_plans || false;
31+
this.billing.stripePublishableKey = data.billing.stripe_publishable_key;
32+
this.billing.organization.enabled = data.billing.organization.enabled;
33+
this.billing.organization.hasPaidPlans = data.billing.organization.has_paid_plans;
34+
this.billing.user.enabled = data.billing.user.enabled;
35+
this.billing.user.hasPaidPlans = data.billing.user.has_paid_plans;
3636

3737
return this;
3838
}

packages/clerk-js/src/utils/billing.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,22 @@ export const billingTotalsFromJSON = <T extends BillingStatementTotalsJSON | Bil
2525
taxTotal: billingMoneyAmountFromJSON(data.tax_total),
2626
};
2727

28-
if ('total_due_now' in data) {
29-
totals.totalDueNow = data.total_due_now ? billingMoneyAmountFromJSON(data.total_due_now) : null;
28+
if ('past_due' in data) {
29+
totals.pastDue = data.past_due ? billingMoneyAmountFromJSON(data.past_due) : null;
3030
}
3131
if ('credit' in data) {
3232
totals.credit = data.credit ? billingMoneyAmountFromJSON(data.credit) : null;
3333
}
34-
if ('past_due' in data) {
35-
totals.pastDue = data.past_due ? billingMoneyAmountFromJSON(data.past_due) : null;
34+
35+
if ('total_due_now' in data) {
36+
totals.totalDueNow = billingMoneyAmountFromJSON(data.total_due_now);
3637
}
38+
3739
if ('total_due_after_free_trial' in data) {
3840
totals.totalDueAfterFreeTrial = data.total_due_after_free_trial
3941
? billingMoneyAmountFromJSON(data.total_due_after_free_trial)
4042
: null;
4143
}
42-
if ('proration' in data) {
43-
if (data.proration) {
44-
totals.proration = {
45-
credit: data.proration.credit ? billingMoneyAmountFromJSON(data.proration.credit) : null,
46-
};
47-
} else {
48-
totals.proration = null;
49-
}
50-
}
51-
52-
// WHY `total_due_after_free_trial` and why `proration`
5344

5445
return totals as T extends { total_due_now: BillingMoneyAmountJSON } ? BillingCheckoutTotals : BillingStatementTotals;
5546
};

0 commit comments

Comments
 (0)