Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/fix-billing-typedoc-pages.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Fix broken Billing TypeDoc links and add missing JSDoc descriptions for the credit and discount types.
90 changes: 90 additions & 0 deletions .typedoc/__tests__/relative-link-replacements.test.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
import { describe, expect, it } from 'vitest';

// @ts-expect-error — .mjs plugin has no type declarations
import { applyRelativeLinkReplacements } from '../custom-plugin.mjs';

/**
* Unit coverage for the `LINK_REPLACEMENTS` rules exercised through the exported
* `applyRelativeLinkReplacements()` entry point. These guard the Billing checkout
* links so an incorrect route or anchor cannot silently pass CI.
*/
describe('applyRelativeLinkReplacements', () => {
const cases: Array<[label: string, input: string, expected: string]> = [
[
'confirm-checkout-params routes to the #confirm-parameters section',
'[x](confirm-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#confirm-parameters)',
],
[
'update-checkout-params routes to the #update-parameters section',
'[x](update-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#update-parameters)',
],
[
'preserves an anchor from the source link',
'[x](billing-credits.mdx#total)',
'[x](/docs/reference/types/billing-credits#total)',
],
[
'billing-credits routes to its standalone page',
'[x](billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'billing-applied-discount routes to its standalone page',
'[x](billing-applied-discount.mdx)',
'[x](/docs/reference/types/billing-applied-discount)',
],
[
'billing-discount-redemption routes to its standalone page',
'[x](billing-discount-redemption.mdx)',
'[x](/docs/reference/types/billing-discount-redemption)',
],
[
'billing-payer-credit routes to its standalone page',
'[x](billing-payer-credit.mdx)',
'[x](/docs/reference/types/billing-payer-credit)',
],
[
'billing-proration-credit-detail routes to its standalone page',
'[x](billing-proration-credit-detail.mdx)',
'[x](/docs/reference/types/billing-proration-credit-detail)',
],
[
'resolves relative path prefixes',
'[x](../../types/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'resolves nested object-doc links',
'[x](billing-credits/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
];

it.each(cases)('%s', (_label, input, expected) => {
expect(applyRelativeLinkReplacements(input)).toBe(expected);
});

it('routes the two sibling next-payment pages independently', () => {
expect(applyRelativeLinkReplacements('[x](billing-subscription-item-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-item-next-payment)',
);
expect(applyRelativeLinkReplacements('[x](billing-subscription-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-next-payment)',
);
});

it('does not rewrite a page whose name is a prefix of a replacement key', () => {
// `billing-payer` is a prefix of `billing-payer-credit`, but the `.mdx` boundary
// must keep an unrelated `billing-payer-resource.mdx` link from being mis-routed.
expect(applyRelativeLinkReplacements('[x](billing-payer-resource.mdx)')).toBe(
'[x](/docs/reference/types/billing-payer-resource)',
);
});

it('leaves content without matching links untouched', () => {
expect(applyRelativeLinkReplacements('no links here')).toBe('no links here');
expect(applyRelativeLinkReplacements('')).toBe('');
});
});
15 changes: 14 additions & 1 deletion .typedoc/custom-plugin.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ const FILES_WITHOUT_HEADINGS = [
'organization-membership-public-user-data.mdx',
'checkout-signal-value.mdx',
'checkout-flow-resource.mdx',
'update-checkout-params.mdx',
'use-checkout-options.mdx',
'use-payment-element-return.mdx',
'use-payment-methods-return.mdx',
Expand DownExpand Up@@ -108,26 +109,38 @@ const LINK_REPLACEMENTS = [
['invitation', '/docs/reference/backend/types/backend-invitation'],
['verify-token-options', '#verify-token-options'],
['localization-resource', '/docs/guides/customizing-clerk/localization'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#parameters'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#confirm-parameters'],
['update-checkout-params', '/docs/reference/types/billing-checkout-resource#update-parameters'],
['billing-applied-discount', '/docs/reference/types/billing-applied-discount'],
['billing-credits', '/docs/reference/types/billing-credits'],
['billing-discount-redemption', '/docs/reference/types/billing-discount-redemption'],
['billing-discounts', '/docs/reference/types/billing-discounts'],
['billing-payment-totals', '/docs/reference/types/billing-payment-totals'],
['billing-payment-method-resource', '/docs/reference/types/billing-payment-method-resource'],
['billing-payer-credit', '/docs/reference/types/billing-payer-credit'],
['billing-payer-resource', '/docs/reference/types/billing-payer-resource'],
['billing-period-totals', '/docs/reference/types/billing-period-totals'],
['billing-plan-price', '/docs/reference/types/billing-plan-price'],
['billing-plan-resource', '/docs/reference/types/billing-plan-resource'],
['billing-plan-unit-price', '/docs/reference/types/billing-plan-unit-price'],
['billing-plan-unit-price-tier', '/docs/reference/types/billing-plan-unit-price-tier'],
['billing-proration-discount', '/docs/reference/types/billing-proration-discount'],
['billing-proration-credit-detail', '/docs/reference/types/billing-proration-credit-detail'],
['billing-checkout-totals', '/docs/reference/types/billing-checkout-totals'],
['billing-checkout-resource', '/docs/reference/types/billing-checkout-resource'],
['billing-money-amount', '/docs/reference/types/billing-money-amount'],
['billing-per-unit-total', '/docs/reference/types/billing-per-unit-total'],
['billing-per-unit-total-tier', '/docs/reference/types/billing-per-unit-total-tier'],
['billing-subscription-item-resource', '/docs/reference/types/billing-subscription-item-resource'],
['billing-subscription-item-next-payment', '/docs/reference/types/billing-subscription-item-next-payment'],
['billing-subscription-item-seats', '/docs/reference/types/billing-subscription-item-seats'],
['billing-subscription-item-status', '/docs/reference/backend/types/billing-subscription-item-status'],
['feature-resource', '/docs/reference/types/feature-resource'],
['billing-statement-group', '/docs/reference/types/billing-statement-group'],
['billing-statement-resource', '/docs/reference/types/billing-statement-resource'],
['billing-totals', '/docs/reference/types/billing-totals'],
['billing-subscription-resource', '/docs/reference/types/billing-subscription-resource'],
['billing-subscription-next-payment', '/docs/reference/types/billing-subscription-next-payment'],
['clerk-api-response-error', '/docs/reference/types/clerk-api-response-error'],
['clerk-api-error', '/docs/reference/types/clerk-api-error'],
['billing-statement-totals', '/docs/reference/types/billing-statement-totals'],
Expand Down
139 changes: 134 additions & 5 deletions packages/shared/src/types/billing.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -852,6 +852,9 @@ export interface BillingSubscriptionItemResource extends ClerkResource {
*/
amount: BillingMoneyAmount;
};
/**
* The credits applied to this subscription item.
*/
credits?: BillingCredits;
/**
* The active discount applied to this subscription item.
Expand DownExpand Up@@ -994,21 +997,63 @@ export interface BillingMoneyAmount {
currencySymbol: string;
}

/**
* Contains details about a proration credit, including the remaining portion of the billing cycle.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingProrationCreditDetail {
/**
* The monetary value of the proration credit.
*/
amount: BillingMoneyAmount;
/**
* The number of days remaining in the current billing cycle.
*/
cycleDaysRemaining: number;
/**
* The total number of days in the billing cycle.
*/
cycleDaysTotal: number;
/**
* The percentage of the billing cycle that remains.
*/
cycleRemainingPercent: number;
}

/**
* Contains details about the payer's available credit and the amount applied to the transaction.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingPayerCredit {
/**
* The payer's credit balance remaining after the transaction.
*/
remainingBalance: BillingMoneyAmount;
/**
* The amount of payer credit applied to the transaction.
*/
appliedAmount: BillingMoneyAmount;
}

/**
* The `BillingCredits` type represents the credits applied to a checkout or payment.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingCredits {
/**
* The credit for the unused portion of the current billing cycle. `null` when no proration credit applies.
*/
proration: BillingProrationCreditDetail | null;
/**
* The payer credit applied to the transaction. `null` when no payer credit applies.
*/
payer: BillingPayerCredit | null;
/**
* The total monetary value of all credits applied to the transaction.
*/
total: BillingMoneyAmount;
}

Expand DownExpand Up@@ -1043,14 +1088,44 @@ export interface BillingProrationDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingAppliedDiscount {
/**
* The monetary value of the discount applied to the transaction.
*/
amount: BillingMoneyAmount;
/**
* The unique identifier of the discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The promotion code used to apply the discount.
*/
promoCode?: string;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The originally configured duration in billing cycles. `null` means the discount does not expire after a fixed
* number of cycles.
*/
durationInCycles?: number | null;
}

Expand All@@ -1060,20 +1135,67 @@ export interface BillingAppliedDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingDiscountRedemption {
/**
* The unique identifier of the discount redemption.
*/
id: string;
/**
* The unique identifier of the subscription item receiving the discount.
*/
subscriptionItemId: string;
/**
* The unique identifier of the redeemed discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* How the discount was applied to the subscription item.
*/
source: 'promotion' | 'manual' | 'promo_code';
/**
* The promotion code used to redeem the discount.
*/
promoCode?: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect?: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The monetary value of the discount applied to the subscription item.
*/
amount?: BillingMoneyAmount;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The number of billing cycles to which the discount has already been applied.
*/
cyclesApplied: number;
/**
* The current status of the discount redemption.
*/
status?: 'active' | 'exhausted' | 'removed';
/**
* The date and time when the discount was redeemed.
*/
redeemedAt: Date;
/**
* The identifier of the user who redeemed the discount. `null` if no user was recorded.
*/
redeemedBy: string | null;
}

Expand DownExpand Up@@ -1232,6 +1354,9 @@ export interface BillingCheckoutTotals {
* Any credits (like account balance or promo credits) that are being applied to the checkout.
*/
credit: BillingMoneyAmount | null;
/**
* The credits applied to the checkout. `null` when no credits apply.
*/
credits: BillingCredits | null;
/**
* Any outstanding amount from previous unpaid invoices that is being collected as part of the checkout.
Expand DownExpand Up@@ -1302,16 +1427,20 @@ export type CreateCheckoutParams = WithOptionalOrgType<{
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export type UpdateCheckoutParams = WithOptionalOrgType<{
export type UpdateCheckoutParams = {
/**
* The unique identifier for the checkout session.
*/
id: string;
/**
* The Organization ID to perform the request on.
*/
orgId?: string;
/**
* The promo code to apply. Use an empty string to remove the applied promo code.
*/
promoCode: string;
}>;
};

/**
* The `confirm()` method accepts the following parameters. **Only one of `paymentMethodId`, `paymentToken`, or `useTestCard` should be provided.**
Expand DownExpand Up@@ -1392,7 +1521,7 @@ export interface BillingCheckoutResource extends ClerkResource {
*/
totals: BillingTotals;
/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<BillingCheckoutResource>;
/**
Expand DownExpand Up@@ -1542,12 +1671,12 @@ export interface CheckoutFlowFinalizeParams {
*/
interface CheckoutFlowMethods {
/**
* Updates the current checkout. Use an empty promo code to remove the applied promo code.
* Updates the current checkout. Use an empty promo code to remove the applied promo code. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#update)
*/
update: (params: Pick<UpdateCheckoutParams, 'promoCode'>) => Promise<{ error: ClerkError | null }>;

/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<{ error: ClerkError | null }>;

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
docs(repo): Fixing billing broken links for Typedoc output by SarahSoutoul · Pull Request #9393 · clerk/javascript · GitHub
Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/fix-billing-typedoc-pages.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Fix broken Billing TypeDoc links and add missing JSDoc descriptions for the credit and discount types.
90 changes: 90 additions & 0 deletions .typedoc/__tests__/relative-link-replacements.test.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
import { describe, expect, it } from 'vitest';

// @ts-expect-error — .mjs plugin has no type declarations
import { applyRelativeLinkReplacements } from '../custom-plugin.mjs';

/**
* Unit coverage for the `LINK_REPLACEMENTS` rules exercised through the exported
* `applyRelativeLinkReplacements()` entry point. These guard the Billing checkout
* links so an incorrect route or anchor cannot silently pass CI.
*/
describe('applyRelativeLinkReplacements', () => {
const cases: Array<[label: string, input: string, expected: string]> = [
[
'confirm-checkout-params routes to the #confirm-parameters section',
'[x](confirm-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#confirm-parameters)',
],
[
'update-checkout-params routes to the #update-parameters section',
'[x](update-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#update-parameters)',
],
[
'preserves an anchor from the source link',
'[x](billing-credits.mdx#total)',
'[x](/docs/reference/types/billing-credits#total)',
],
[
'billing-credits routes to its standalone page',
'[x](billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'billing-applied-discount routes to its standalone page',
'[x](billing-applied-discount.mdx)',
'[x](/docs/reference/types/billing-applied-discount)',
],
[
'billing-discount-redemption routes to its standalone page',
'[x](billing-discount-redemption.mdx)',
'[x](/docs/reference/types/billing-discount-redemption)',
],
[
'billing-payer-credit routes to its standalone page',
'[x](billing-payer-credit.mdx)',
'[x](/docs/reference/types/billing-payer-credit)',
],
[
'billing-proration-credit-detail routes to its standalone page',
'[x](billing-proration-credit-detail.mdx)',
'[x](/docs/reference/types/billing-proration-credit-detail)',
],
[
'resolves relative path prefixes',
'[x](../../types/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'resolves nested object-doc links',
'[x](billing-credits/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
];

it.each(cases)('%s', (_label, input, expected) => {
expect(applyRelativeLinkReplacements(input)).toBe(expected);
});

it('routes the two sibling next-payment pages independently', () => {
expect(applyRelativeLinkReplacements('[x](billing-subscription-item-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-item-next-payment)',
);
expect(applyRelativeLinkReplacements('[x](billing-subscription-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-next-payment)',
);
});

it('does not rewrite a page whose name is a prefix of a replacement key', () => {
// `billing-payer` is a prefix of `billing-payer-credit`, but the `.mdx` boundary
// must keep an unrelated `billing-payer-resource.mdx` link from being mis-routed.
expect(applyRelativeLinkReplacements('[x](billing-payer-resource.mdx)')).toBe(
'[x](/docs/reference/types/billing-payer-resource)',
);
});

it('leaves content without matching links untouched', () => {
expect(applyRelativeLinkReplacements('no links here')).toBe('no links here');
expect(applyRelativeLinkReplacements('')).toBe('');
});
});
15 changes: 14 additions & 1 deletion .typedoc/custom-plugin.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ const FILES_WITHOUT_HEADINGS = [
'organization-membership-public-user-data.mdx',
'checkout-signal-value.mdx',
'checkout-flow-resource.mdx',
'update-checkout-params.mdx',
'use-checkout-options.mdx',
'use-payment-element-return.mdx',
'use-payment-methods-return.mdx',
Expand DownExpand Up@@ -108,26 +109,38 @@ const LINK_REPLACEMENTS = [
['invitation', '/docs/reference/backend/types/backend-invitation'],
['verify-token-options', '#verify-token-options'],
['localization-resource', '/docs/guides/customizing-clerk/localization'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#parameters'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#confirm-parameters'],
['update-checkout-params', '/docs/reference/types/billing-checkout-resource#update-parameters'],
['billing-applied-discount', '/docs/reference/types/billing-applied-discount'],
['billing-credits', '/docs/reference/types/billing-credits'],
['billing-discount-redemption', '/docs/reference/types/billing-discount-redemption'],
['billing-discounts', '/docs/reference/types/billing-discounts'],
['billing-payment-totals', '/docs/reference/types/billing-payment-totals'],
['billing-payment-method-resource', '/docs/reference/types/billing-payment-method-resource'],
['billing-payer-credit', '/docs/reference/types/billing-payer-credit'],
['billing-payer-resource', '/docs/reference/types/billing-payer-resource'],
['billing-period-totals', '/docs/reference/types/billing-period-totals'],
['billing-plan-price', '/docs/reference/types/billing-plan-price'],
['billing-plan-resource', '/docs/reference/types/billing-plan-resource'],
['billing-plan-unit-price', '/docs/reference/types/billing-plan-unit-price'],
['billing-plan-unit-price-tier', '/docs/reference/types/billing-plan-unit-price-tier'],
['billing-proration-discount', '/docs/reference/types/billing-proration-discount'],
['billing-proration-credit-detail', '/docs/reference/types/billing-proration-credit-detail'],
['billing-checkout-totals', '/docs/reference/types/billing-checkout-totals'],
['billing-checkout-resource', '/docs/reference/types/billing-checkout-resource'],
['billing-money-amount', '/docs/reference/types/billing-money-amount'],
['billing-per-unit-total', '/docs/reference/types/billing-per-unit-total'],
['billing-per-unit-total-tier', '/docs/reference/types/billing-per-unit-total-tier'],
['billing-subscription-item-resource', '/docs/reference/types/billing-subscription-item-resource'],
['billing-subscription-item-next-payment', '/docs/reference/types/billing-subscription-item-next-payment'],
['billing-subscription-item-seats', '/docs/reference/types/billing-subscription-item-seats'],
['billing-subscription-item-status', '/docs/reference/backend/types/billing-subscription-item-status'],
['feature-resource', '/docs/reference/types/feature-resource'],
['billing-statement-group', '/docs/reference/types/billing-statement-group'],
['billing-statement-resource', '/docs/reference/types/billing-statement-resource'],
['billing-totals', '/docs/reference/types/billing-totals'],
['billing-subscription-resource', '/docs/reference/types/billing-subscription-resource'],
['billing-subscription-next-payment', '/docs/reference/types/billing-subscription-next-payment'],
['clerk-api-response-error', '/docs/reference/types/clerk-api-response-error'],
['clerk-api-error', '/docs/reference/types/clerk-api-error'],
['billing-statement-totals', '/docs/reference/types/billing-statement-totals'],
Expand Down
139 changes: 134 additions & 5 deletions packages/shared/src/types/billing.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -852,6 +852,9 @@ export interface BillingSubscriptionItemResource extends ClerkResource {
*/
amount: BillingMoneyAmount;
};
/**
* The credits applied to this subscription item.
*/
credits?: BillingCredits;
/**
* The active discount applied to this subscription item.
Expand DownExpand Up@@ -994,21 +997,63 @@ export interface BillingMoneyAmount {
currencySymbol: string;
}

/**
* Contains details about a proration credit, including the remaining portion of the billing cycle.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingProrationCreditDetail {
/**
* The monetary value of the proration credit.
*/
amount: BillingMoneyAmount;
/**
* The number of days remaining in the current billing cycle.
*/
cycleDaysRemaining: number;
/**
* The total number of days in the billing cycle.
*/
cycleDaysTotal: number;
/**
* The percentage of the billing cycle that remains.
*/
cycleRemainingPercent: number;
}

/**
* Contains details about the payer's available credit and the amount applied to the transaction.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingPayerCredit {
/**
* The payer's credit balance remaining after the transaction.
*/
remainingBalance: BillingMoneyAmount;
/**
* The amount of payer credit applied to the transaction.
*/
appliedAmount: BillingMoneyAmount;
}

/**
* The `BillingCredits` type represents the credits applied to a checkout or payment.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingCredits {
/**
* The credit for the unused portion of the current billing cycle. `null` when no proration credit applies.
*/
proration: BillingProrationCreditDetail | null;
/**
* The payer credit applied to the transaction. `null` when no payer credit applies.
*/
payer: BillingPayerCredit | null;
/**
* The total monetary value of all credits applied to the transaction.
*/
total: BillingMoneyAmount;
}

Expand DownExpand Up@@ -1043,14 +1088,44 @@ export interface BillingProrationDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingAppliedDiscount {
/**
* The monetary value of the discount applied to the transaction.
*/
amount: BillingMoneyAmount;
/**
* The unique identifier of the discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The promotion code used to apply the discount.
*/
promoCode?: string;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The originally configured duration in billing cycles. `null` means the discount does not expire after a fixed
* number of cycles.
*/
durationInCycles?: number | null;
}

Expand All@@ -1060,20 +1135,67 @@ export interface BillingAppliedDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingDiscountRedemption {
/**
* The unique identifier of the discount redemption.
*/
id: string;
/**
* The unique identifier of the subscription item receiving the discount.
*/
subscriptionItemId: string;
/**
* The unique identifier of the redeemed discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* How the discount was applied to the subscription item.
*/
source: 'promotion' | 'manual' | 'promo_code';
/**
* The promotion code used to redeem the discount.
*/
promoCode?: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect?: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The monetary value of the discount applied to the subscription item.
*/
amount?: BillingMoneyAmount;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The number of billing cycles to which the discount has already been applied.
*/
cyclesApplied: number;
/**
* The current status of the discount redemption.
*/
status?: 'active' | 'exhausted' | 'removed';
/**
* The date and time when the discount was redeemed.
*/
redeemedAt: Date;
/**
* The identifier of the user who redeemed the discount. `null` if no user was recorded.
*/
redeemedBy: string | null;
}

Expand DownExpand Up@@ -1232,6 +1354,9 @@ export interface BillingCheckoutTotals {
* Any credits (like account balance or promo credits) that are being applied to the checkout.
*/
credit: BillingMoneyAmount | null;
/**
* The credits applied to the checkout. `null` when no credits apply.
*/
credits: BillingCredits | null;
/**
* Any outstanding amount from previous unpaid invoices that is being collected as part of the checkout.
Expand DownExpand Up@@ -1302,16 +1427,20 @@ export type CreateCheckoutParams = WithOptionalOrgType<{
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export type UpdateCheckoutParams = WithOptionalOrgType<{
export type UpdateCheckoutParams = {
/**
* The unique identifier for the checkout session.
*/
id: string;
/**
* The Organization ID to perform the request on.
*/
orgId?: string;
/**
* The promo code to apply. Use an empty string to remove the applied promo code.
*/
promoCode: string;
}>;
};

/**
* The `confirm()` method accepts the following parameters. **Only one of `paymentMethodId`, `paymentToken`, or `useTestCard` should be provided.**
Expand DownExpand Up@@ -1392,7 +1521,7 @@ export interface BillingCheckoutResource extends ClerkResource {
*/
totals: BillingTotals;
/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<BillingCheckoutResource>;
/**
Expand DownExpand Up@@ -1542,12 +1671,12 @@ export interface CheckoutFlowFinalizeParams {
*/
interface CheckoutFlowMethods {
/**
* Updates the current checkout. Use an empty promo code to remove the applied promo code.
* Updates the current checkout. Use an empty promo code to remove the applied promo code. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#update)
*/
update: (params: Pick<UpdateCheckoutParams, 'promoCode'>) => Promise<{ error: ClerkError | null }>;

/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<{ error: ClerkError | null }>;

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' docs(repo): Fixing billing broken links for Typedoc output by SarahSoutoul · Pull Request #9393 · clerk/javascript · GitHub
Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/fix-billing-typedoc-pages.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Fix broken Billing TypeDoc links and add missing JSDoc descriptions for the credit and discount types.
90 changes: 90 additions & 0 deletions .typedoc/__tests__/relative-link-replacements.test.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
import { describe, expect, it } from 'vitest';

// @ts-expect-error — .mjs plugin has no type declarations
import { applyRelativeLinkReplacements } from '../custom-plugin.mjs';

/**
* Unit coverage for the `LINK_REPLACEMENTS` rules exercised through the exported
* `applyRelativeLinkReplacements()` entry point. These guard the Billing checkout
* links so an incorrect route or anchor cannot silently pass CI.
*/
describe('applyRelativeLinkReplacements', () => {
const cases: Array<[label: string, input: string, expected: string]> = [
[
'confirm-checkout-params routes to the #confirm-parameters section',
'[x](confirm-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#confirm-parameters)',
],
[
'update-checkout-params routes to the #update-parameters section',
'[x](update-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#update-parameters)',
],
[
'preserves an anchor from the source link',
'[x](billing-credits.mdx#total)',
'[x](/docs/reference/types/billing-credits#total)',
],
[
'billing-credits routes to its standalone page',
'[x](billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'billing-applied-discount routes to its standalone page',
'[x](billing-applied-discount.mdx)',
'[x](/docs/reference/types/billing-applied-discount)',
],
[
'billing-discount-redemption routes to its standalone page',
'[x](billing-discount-redemption.mdx)',
'[x](/docs/reference/types/billing-discount-redemption)',
],
[
'billing-payer-credit routes to its standalone page',
'[x](billing-payer-credit.mdx)',
'[x](/docs/reference/types/billing-payer-credit)',
],
[
'billing-proration-credit-detail routes to its standalone page',
'[x](billing-proration-credit-detail.mdx)',
'[x](/docs/reference/types/billing-proration-credit-detail)',
],
[
'resolves relative path prefixes',
'[x](../../types/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'resolves nested object-doc links',
'[x](billing-credits/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
];

it.each(cases)('%s', (_label, input, expected) => {
expect(applyRelativeLinkReplacements(input)).toBe(expected);
});

it('routes the two sibling next-payment pages independently', () => {
expect(applyRelativeLinkReplacements('[x](billing-subscription-item-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-item-next-payment)',
);
expect(applyRelativeLinkReplacements('[x](billing-subscription-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-next-payment)',
);
});

it('does not rewrite a page whose name is a prefix of a replacement key', () => {
// `billing-payer` is a prefix of `billing-payer-credit`, but the `.mdx` boundary
// must keep an unrelated `billing-payer-resource.mdx` link from being mis-routed.
expect(applyRelativeLinkReplacements('[x](billing-payer-resource.mdx)')).toBe(
'[x](/docs/reference/types/billing-payer-resource)',
);
});

it('leaves content without matching links untouched', () => {
expect(applyRelativeLinkReplacements('no links here')).toBe('no links here');
expect(applyRelativeLinkReplacements('')).toBe('');
});
});
15 changes: 14 additions & 1 deletion .typedoc/custom-plugin.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ const FILES_WITHOUT_HEADINGS = [
'organization-membership-public-user-data.mdx',
'checkout-signal-value.mdx',
'checkout-flow-resource.mdx',
'update-checkout-params.mdx',
'use-checkout-options.mdx',
'use-payment-element-return.mdx',
'use-payment-methods-return.mdx',
Expand DownExpand Up@@ -108,26 +109,38 @@ const LINK_REPLACEMENTS = [
['invitation', '/docs/reference/backend/types/backend-invitation'],
['verify-token-options', '#verify-token-options'],
['localization-resource', '/docs/guides/customizing-clerk/localization'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#parameters'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#confirm-parameters'],
['update-checkout-params', '/docs/reference/types/billing-checkout-resource#update-parameters'],
['billing-applied-discount', '/docs/reference/types/billing-applied-discount'],
['billing-credits', '/docs/reference/types/billing-credits'],
['billing-discount-redemption', '/docs/reference/types/billing-discount-redemption'],
['billing-discounts', '/docs/reference/types/billing-discounts'],
['billing-payment-totals', '/docs/reference/types/billing-payment-totals'],
['billing-payment-method-resource', '/docs/reference/types/billing-payment-method-resource'],
['billing-payer-credit', '/docs/reference/types/billing-payer-credit'],
['billing-payer-resource', '/docs/reference/types/billing-payer-resource'],
['billing-period-totals', '/docs/reference/types/billing-period-totals'],
['billing-plan-price', '/docs/reference/types/billing-plan-price'],
['billing-plan-resource', '/docs/reference/types/billing-plan-resource'],
['billing-plan-unit-price', '/docs/reference/types/billing-plan-unit-price'],
['billing-plan-unit-price-tier', '/docs/reference/types/billing-plan-unit-price-tier'],
['billing-proration-discount', '/docs/reference/types/billing-proration-discount'],
['billing-proration-credit-detail', '/docs/reference/types/billing-proration-credit-detail'],
['billing-checkout-totals', '/docs/reference/types/billing-checkout-totals'],
['billing-checkout-resource', '/docs/reference/types/billing-checkout-resource'],
['billing-money-amount', '/docs/reference/types/billing-money-amount'],
['billing-per-unit-total', '/docs/reference/types/billing-per-unit-total'],
['billing-per-unit-total-tier', '/docs/reference/types/billing-per-unit-total-tier'],
['billing-subscription-item-resource', '/docs/reference/types/billing-subscription-item-resource'],
['billing-subscription-item-next-payment', '/docs/reference/types/billing-subscription-item-next-payment'],
['billing-subscription-item-seats', '/docs/reference/types/billing-subscription-item-seats'],
['billing-subscription-item-status', '/docs/reference/backend/types/billing-subscription-item-status'],
['feature-resource', '/docs/reference/types/feature-resource'],
['billing-statement-group', '/docs/reference/types/billing-statement-group'],
['billing-statement-resource', '/docs/reference/types/billing-statement-resource'],
['billing-totals', '/docs/reference/types/billing-totals'],
['billing-subscription-resource', '/docs/reference/types/billing-subscription-resource'],
['billing-subscription-next-payment', '/docs/reference/types/billing-subscription-next-payment'],
['clerk-api-response-error', '/docs/reference/types/clerk-api-response-error'],
['clerk-api-error', '/docs/reference/types/clerk-api-error'],
['billing-statement-totals', '/docs/reference/types/billing-statement-totals'],
Expand Down
139 changes: 134 additions & 5 deletions packages/shared/src/types/billing.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -852,6 +852,9 @@ export interface BillingSubscriptionItemResource extends ClerkResource {
*/
amount: BillingMoneyAmount;
};
/**
* The credits applied to this subscription item.
*/
credits?: BillingCredits;
/**
* The active discount applied to this subscription item.
Expand DownExpand Up@@ -994,21 +997,63 @@ export interface BillingMoneyAmount {
currencySymbol: string;
}

/**
* Contains details about a proration credit, including the remaining portion of the billing cycle.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingProrationCreditDetail {
/**
* The monetary value of the proration credit.
*/
amount: BillingMoneyAmount;
/**
* The number of days remaining in the current billing cycle.
*/
cycleDaysRemaining: number;
/**
* The total number of days in the billing cycle.
*/
cycleDaysTotal: number;
/**
* The percentage of the billing cycle that remains.
*/
cycleRemainingPercent: number;
}

/**
* Contains details about the payer's available credit and the amount applied to the transaction.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingPayerCredit {
/**
* The payer's credit balance remaining after the transaction.
*/
remainingBalance: BillingMoneyAmount;
/**
* The amount of payer credit applied to the transaction.
*/
appliedAmount: BillingMoneyAmount;
}

/**
* The `BillingCredits` type represents the credits applied to a checkout or payment.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingCredits {
/**
* The credit for the unused portion of the current billing cycle. `null` when no proration credit applies.
*/
proration: BillingProrationCreditDetail | null;
/**
* The payer credit applied to the transaction. `null` when no payer credit applies.
*/
payer: BillingPayerCredit | null;
/**
* The total monetary value of all credits applied to the transaction.
*/
total: BillingMoneyAmount;
}

Expand DownExpand Up@@ -1043,14 +1088,44 @@ export interface BillingProrationDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingAppliedDiscount {
/**
* The monetary value of the discount applied to the transaction.
*/
amount: BillingMoneyAmount;
/**
* The unique identifier of the discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The promotion code used to apply the discount.
*/
promoCode?: string;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The originally configured duration in billing cycles. `null` means the discount does not expire after a fixed
* number of cycles.
*/
durationInCycles?: number | null;
}

Expand All@@ -1060,20 +1135,67 @@ export interface BillingAppliedDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingDiscountRedemption {
/**
* The unique identifier of the discount redemption.
*/
id: string;
/**
* The unique identifier of the subscription item receiving the discount.
*/
subscriptionItemId: string;
/**
* The unique identifier of the redeemed discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* How the discount was applied to the subscription item.
*/
source: 'promotion' | 'manual' | 'promo_code';
/**
* The promotion code used to redeem the discount.
*/
promoCode?: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect?: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The monetary value of the discount applied to the subscription item.
*/
amount?: BillingMoneyAmount;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The number of billing cycles to which the discount has already been applied.
*/
cyclesApplied: number;
/**
* The current status of the discount redemption.
*/
status?: 'active' | 'exhausted' | 'removed';
/**
* The date and time when the discount was redeemed.
*/
redeemedAt: Date;
/**
* The identifier of the user who redeemed the discount. `null` if no user was recorded.
*/
redeemedBy: string | null;
}

Expand DownExpand Up@@ -1232,6 +1354,9 @@ export interface BillingCheckoutTotals {
* Any credits (like account balance or promo credits) that are being applied to the checkout.
*/
credit: BillingMoneyAmount | null;
/**
* The credits applied to the checkout. `null` when no credits apply.
*/
credits: BillingCredits | null;
/**
* Any outstanding amount from previous unpaid invoices that is being collected as part of the checkout.
Expand DownExpand Up@@ -1302,16 +1427,20 @@ export type CreateCheckoutParams = WithOptionalOrgType<{
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export type UpdateCheckoutParams = WithOptionalOrgType<{
export type UpdateCheckoutParams = {
/**
* The unique identifier for the checkout session.
*/
id: string;
/**
* The Organization ID to perform the request on.
*/
orgId?: string;
/**
* The promo code to apply. Use an empty string to remove the applied promo code.
*/
promoCode: string;
}>;
};

/**
* The `confirm()` method accepts the following parameters. **Only one of `paymentMethodId`, `paymentToken`, or `useTestCard` should be provided.**
Expand DownExpand Up@@ -1392,7 +1521,7 @@ export interface BillingCheckoutResource extends ClerkResource {
*/
totals: BillingTotals;
/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<BillingCheckoutResource>;
/**
Expand DownExpand Up@@ -1542,12 +1671,12 @@ export interface CheckoutFlowFinalizeParams {
*/
interface CheckoutFlowMethods {
/**
* Updates the current checkout. Use an empty promo code to remove the applied promo code.
* Updates the current checkout. Use an empty promo code to remove the applied promo code. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#update)
*/
update: (params: Pick<UpdateCheckoutParams, 'promoCode'>) => Promise<{ error: ClerkError | null }>;

/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<{ error: ClerkError | null }>;

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' docs(repo): Fixing billing broken links for Typedoc output by SarahSoutoul · Pull Request #9393 · clerk/javascript · GitHub
Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/fix-billing-typedoc-pages.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Fix broken Billing TypeDoc links and add missing JSDoc descriptions for the credit and discount types.
90 changes: 90 additions & 0 deletions .typedoc/__tests__/relative-link-replacements.test.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
import { describe, expect, it } from 'vitest';

// @ts-expect-error — .mjs plugin has no type declarations
import { applyRelativeLinkReplacements } from '../custom-plugin.mjs';

/**
* Unit coverage for the `LINK_REPLACEMENTS` rules exercised through the exported
* `applyRelativeLinkReplacements()` entry point. These guard the Billing checkout
* links so an incorrect route or anchor cannot silently pass CI.
*/
describe('applyRelativeLinkReplacements', () => {
const cases: Array<[label: string, input: string, expected: string]> = [
[
'confirm-checkout-params routes to the #confirm-parameters section',
'[x](confirm-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#confirm-parameters)',
],
[
'update-checkout-params routes to the #update-parameters section',
'[x](update-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#update-parameters)',
],
[
'preserves an anchor from the source link',
'[x](billing-credits.mdx#total)',
'[x](/docs/reference/types/billing-credits#total)',
],
[
'billing-credits routes to its standalone page',
'[x](billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'billing-applied-discount routes to its standalone page',
'[x](billing-applied-discount.mdx)',
'[x](/docs/reference/types/billing-applied-discount)',
],
[
'billing-discount-redemption routes to its standalone page',
'[x](billing-discount-redemption.mdx)',
'[x](/docs/reference/types/billing-discount-redemption)',
],
[
'billing-payer-credit routes to its standalone page',
'[x](billing-payer-credit.mdx)',
'[x](/docs/reference/types/billing-payer-credit)',
],
[
'billing-proration-credit-detail routes to its standalone page',
'[x](billing-proration-credit-detail.mdx)',
'[x](/docs/reference/types/billing-proration-credit-detail)',
],
[
'resolves relative path prefixes',
'[x](../../types/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'resolves nested object-doc links',
'[x](billing-credits/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
];

it.each(cases)('%s', (_label, input, expected) => {
expect(applyRelativeLinkReplacements(input)).toBe(expected);
});

it('routes the two sibling next-payment pages independently', () => {
expect(applyRelativeLinkReplacements('[x](billing-subscription-item-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-item-next-payment)',
);
expect(applyRelativeLinkReplacements('[x](billing-subscription-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-next-payment)',
);
});

it('does not rewrite a page whose name is a prefix of a replacement key', () => {
// `billing-payer` is a prefix of `billing-payer-credit`, but the `.mdx` boundary
// must keep an unrelated `billing-payer-resource.mdx` link from being mis-routed.
expect(applyRelativeLinkReplacements('[x](billing-payer-resource.mdx)')).toBe(
'[x](/docs/reference/types/billing-payer-resource)',
);
});

it('leaves content without matching links untouched', () => {
expect(applyRelativeLinkReplacements('no links here')).toBe('no links here');
expect(applyRelativeLinkReplacements('')).toBe('');
});
});
15 changes: 14 additions & 1 deletion .typedoc/custom-plugin.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ const FILES_WITHOUT_HEADINGS = [
'organization-membership-public-user-data.mdx',
'checkout-signal-value.mdx',
'checkout-flow-resource.mdx',
'update-checkout-params.mdx',
'use-checkout-options.mdx',
'use-payment-element-return.mdx',
'use-payment-methods-return.mdx',
Expand DownExpand Up@@ -108,26 +109,38 @@ const LINK_REPLACEMENTS = [
['invitation', '/docs/reference/backend/types/backend-invitation'],
['verify-token-options', '#verify-token-options'],
['localization-resource', '/docs/guides/customizing-clerk/localization'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#parameters'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#confirm-parameters'],
['update-checkout-params', '/docs/reference/types/billing-checkout-resource#update-parameters'],
['billing-applied-discount', '/docs/reference/types/billing-applied-discount'],
['billing-credits', '/docs/reference/types/billing-credits'],
['billing-discount-redemption', '/docs/reference/types/billing-discount-redemption'],
['billing-discounts', '/docs/reference/types/billing-discounts'],
['billing-payment-totals', '/docs/reference/types/billing-payment-totals'],
['billing-payment-method-resource', '/docs/reference/types/billing-payment-method-resource'],
['billing-payer-credit', '/docs/reference/types/billing-payer-credit'],
['billing-payer-resource', '/docs/reference/types/billing-payer-resource'],
['billing-period-totals', '/docs/reference/types/billing-period-totals'],
['billing-plan-price', '/docs/reference/types/billing-plan-price'],
['billing-plan-resource', '/docs/reference/types/billing-plan-resource'],
['billing-plan-unit-price', '/docs/reference/types/billing-plan-unit-price'],
['billing-plan-unit-price-tier', '/docs/reference/types/billing-plan-unit-price-tier'],
['billing-proration-discount', '/docs/reference/types/billing-proration-discount'],
['billing-proration-credit-detail', '/docs/reference/types/billing-proration-credit-detail'],
['billing-checkout-totals', '/docs/reference/types/billing-checkout-totals'],
['billing-checkout-resource', '/docs/reference/types/billing-checkout-resource'],
['billing-money-amount', '/docs/reference/types/billing-money-amount'],
['billing-per-unit-total', '/docs/reference/types/billing-per-unit-total'],
['billing-per-unit-total-tier', '/docs/reference/types/billing-per-unit-total-tier'],
['billing-subscription-item-resource', '/docs/reference/types/billing-subscription-item-resource'],
['billing-subscription-item-next-payment', '/docs/reference/types/billing-subscription-item-next-payment'],
['billing-subscription-item-seats', '/docs/reference/types/billing-subscription-item-seats'],
['billing-subscription-item-status', '/docs/reference/backend/types/billing-subscription-item-status'],
['feature-resource', '/docs/reference/types/feature-resource'],
['billing-statement-group', '/docs/reference/types/billing-statement-group'],
['billing-statement-resource', '/docs/reference/types/billing-statement-resource'],
['billing-totals', '/docs/reference/types/billing-totals'],
['billing-subscription-resource', '/docs/reference/types/billing-subscription-resource'],
['billing-subscription-next-payment', '/docs/reference/types/billing-subscription-next-payment'],
['clerk-api-response-error', '/docs/reference/types/clerk-api-response-error'],
['clerk-api-error', '/docs/reference/types/clerk-api-error'],
['billing-statement-totals', '/docs/reference/types/billing-statement-totals'],
Expand Down
139 changes: 134 additions & 5 deletions packages/shared/src/types/billing.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -852,6 +852,9 @@ export interface BillingSubscriptionItemResource extends ClerkResource {
*/
amount: BillingMoneyAmount;
};
/**
* The credits applied to this subscription item.
*/
credits?: BillingCredits;
/**
* The active discount applied to this subscription item.
Expand DownExpand Up@@ -994,21 +997,63 @@ export interface BillingMoneyAmount {
currencySymbol: string;
}

/**
* Contains details about a proration credit, including the remaining portion of the billing cycle.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingProrationCreditDetail {
/**
* The monetary value of the proration credit.
*/
amount: BillingMoneyAmount;
/**
* The number of days remaining in the current billing cycle.
*/
cycleDaysRemaining: number;
/**
* The total number of days in the billing cycle.
*/
cycleDaysTotal: number;
/**
* The percentage of the billing cycle that remains.
*/
cycleRemainingPercent: number;
}

/**
* Contains details about the payer's available credit and the amount applied to the transaction.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingPayerCredit {
/**
* The payer's credit balance remaining after the transaction.
*/
remainingBalance: BillingMoneyAmount;
/**
* The amount of payer credit applied to the transaction.
*/
appliedAmount: BillingMoneyAmount;
}

/**
* The `BillingCredits` type represents the credits applied to a checkout or payment.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingCredits {
/**
* The credit for the unused portion of the current billing cycle. `null` when no proration credit applies.
*/
proration: BillingProrationCreditDetail | null;
/**
* The payer credit applied to the transaction. `null` when no payer credit applies.
*/
payer: BillingPayerCredit | null;
/**
* The total monetary value of all credits applied to the transaction.
*/
total: BillingMoneyAmount;
}

Expand DownExpand Up@@ -1043,14 +1088,44 @@ export interface BillingProrationDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingAppliedDiscount {
/**
* The monetary value of the discount applied to the transaction.
*/
amount: BillingMoneyAmount;
/**
* The unique identifier of the discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The promotion code used to apply the discount.
*/
promoCode?: string;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The originally configured duration in billing cycles. `null` means the discount does not expire after a fixed
* number of cycles.
*/
durationInCycles?: number | null;
}

Expand All@@ -1060,20 +1135,67 @@ export interface BillingAppliedDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingDiscountRedemption {
/**
* The unique identifier of the discount redemption.
*/
id: string;
/**
* The unique identifier of the subscription item receiving the discount.
*/
subscriptionItemId: string;
/**
* The unique identifier of the redeemed discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* How the discount was applied to the subscription item.
*/
source: 'promotion' | 'manual' | 'promo_code';
/**
* The promotion code used to redeem the discount.
*/
promoCode?: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect?: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The monetary value of the discount applied to the subscription item.
*/
amount?: BillingMoneyAmount;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The number of billing cycles to which the discount has already been applied.
*/
cyclesApplied: number;
/**
* The current status of the discount redemption.
*/
status?: 'active' | 'exhausted' | 'removed';
/**
* The date and time when the discount was redeemed.
*/
redeemedAt: Date;
/**
* The identifier of the user who redeemed the discount. `null` if no user was recorded.
*/
redeemedBy: string | null;
}

Expand DownExpand Up@@ -1232,6 +1354,9 @@ export interface BillingCheckoutTotals {
* Any credits (like account balance or promo credits) that are being applied to the checkout.
*/
credit: BillingMoneyAmount | null;
/**
* The credits applied to the checkout. `null` when no credits apply.
*/
credits: BillingCredits | null;
/**
* Any outstanding amount from previous unpaid invoices that is being collected as part of the checkout.
Expand DownExpand Up@@ -1302,16 +1427,20 @@ export type CreateCheckoutParams = WithOptionalOrgType<{
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export type UpdateCheckoutParams = WithOptionalOrgType<{
export type UpdateCheckoutParams = {
/**
* The unique identifier for the checkout session.
*/
id: string;
/**
* The Organization ID to perform the request on.
*/
orgId?: string;
/**
* The promo code to apply. Use an empty string to remove the applied promo code.
*/
promoCode: string;
}>;
};

/**
* The `confirm()` method accepts the following parameters. **Only one of `paymentMethodId`, `paymentToken`, or `useTestCard` should be provided.**
Expand DownExpand Up@@ -1392,7 +1521,7 @@ export interface BillingCheckoutResource extends ClerkResource {
*/
totals: BillingTotals;
/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<BillingCheckoutResource>;
/**
Expand DownExpand Up@@ -1542,12 +1671,12 @@ export interface CheckoutFlowFinalizeParams {
*/
interface CheckoutFlowMethods {
/**
* Updates the current checkout. Use an empty promo code to remove the applied promo code.
* Updates the current checkout. Use an empty promo code to remove the applied promo code. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#update)
*/
update: (params: Pick<UpdateCheckoutParams, 'promoCode'>) => Promise<{ error: ClerkError | null }>;

/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<{ error: ClerkError | null }>;

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' docs(repo): Fixing billing broken links for Typedoc output by SarahSoutoul · Pull Request #9393 · clerk/javascript · GitHub
Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/fix-billing-typedoc-pages.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Fix broken Billing TypeDoc links and add missing JSDoc descriptions for the credit and discount types.
90 changes: 90 additions & 0 deletions .typedoc/__tests__/relative-link-replacements.test.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
import { describe, expect, it } from 'vitest';

// @ts-expect-error — .mjs plugin has no type declarations
import { applyRelativeLinkReplacements } from '../custom-plugin.mjs';

/**
* Unit coverage for the `LINK_REPLACEMENTS` rules exercised through the exported
* `applyRelativeLinkReplacements()` entry point. These guard the Billing checkout
* links so an incorrect route or anchor cannot silently pass CI.
*/
describe('applyRelativeLinkReplacements', () => {
const cases: Array<[label: string, input: string, expected: string]> = [
[
'confirm-checkout-params routes to the #confirm-parameters section',
'[x](confirm-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#confirm-parameters)',
],
[
'update-checkout-params routes to the #update-parameters section',
'[x](update-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#update-parameters)',
],
[
'preserves an anchor from the source link',
'[x](billing-credits.mdx#total)',
'[x](/docs/reference/types/billing-credits#total)',
],
[
'billing-credits routes to its standalone page',
'[x](billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'billing-applied-discount routes to its standalone page',
'[x](billing-applied-discount.mdx)',
'[x](/docs/reference/types/billing-applied-discount)',
],
[
'billing-discount-redemption routes to its standalone page',
'[x](billing-discount-redemption.mdx)',
'[x](/docs/reference/types/billing-discount-redemption)',
],
[
'billing-payer-credit routes to its standalone page',
'[x](billing-payer-credit.mdx)',
'[x](/docs/reference/types/billing-payer-credit)',
],
[
'billing-proration-credit-detail routes to its standalone page',
'[x](billing-proration-credit-detail.mdx)',
'[x](/docs/reference/types/billing-proration-credit-detail)',
],
[
'resolves relative path prefixes',
'[x](../../types/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'resolves nested object-doc links',
'[x](billing-credits/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
];

it.each(cases)('%s', (_label, input, expected) => {
expect(applyRelativeLinkReplacements(input)).toBe(expected);
});

it('routes the two sibling next-payment pages independently', () => {
expect(applyRelativeLinkReplacements('[x](billing-subscription-item-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-item-next-payment)',
);
expect(applyRelativeLinkReplacements('[x](billing-subscription-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-next-payment)',
);
});

it('does not rewrite a page whose name is a prefix of a replacement key', () => {
// `billing-payer` is a prefix of `billing-payer-credit`, but the `.mdx` boundary
// must keep an unrelated `billing-payer-resource.mdx` link from being mis-routed.
expect(applyRelativeLinkReplacements('[x](billing-payer-resource.mdx)')).toBe(
'[x](/docs/reference/types/billing-payer-resource)',
);
});

it('leaves content without matching links untouched', () => {
expect(applyRelativeLinkReplacements('no links here')).toBe('no links here');
expect(applyRelativeLinkReplacements('')).toBe('');
});
});
15 changes: 14 additions & 1 deletion .typedoc/custom-plugin.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ const FILES_WITHOUT_HEADINGS = [
'organization-membership-public-user-data.mdx',
'checkout-signal-value.mdx',
'checkout-flow-resource.mdx',
'update-checkout-params.mdx',
'use-checkout-options.mdx',
'use-payment-element-return.mdx',
'use-payment-methods-return.mdx',
Expand DownExpand Up@@ -108,26 +109,38 @@ const LINK_REPLACEMENTS = [
['invitation', '/docs/reference/backend/types/backend-invitation'],
['verify-token-options', '#verify-token-options'],
['localization-resource', '/docs/guides/customizing-clerk/localization'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#parameters'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#confirm-parameters'],
['update-checkout-params', '/docs/reference/types/billing-checkout-resource#update-parameters'],
['billing-applied-discount', '/docs/reference/types/billing-applied-discount'],
['billing-credits', '/docs/reference/types/billing-credits'],
['billing-discount-redemption', '/docs/reference/types/billing-discount-redemption'],
['billing-discounts', '/docs/reference/types/billing-discounts'],
['billing-payment-totals', '/docs/reference/types/billing-payment-totals'],
['billing-payment-method-resource', '/docs/reference/types/billing-payment-method-resource'],
['billing-payer-credit', '/docs/reference/types/billing-payer-credit'],
['billing-payer-resource', '/docs/reference/types/billing-payer-resource'],
['billing-period-totals', '/docs/reference/types/billing-period-totals'],
['billing-plan-price', '/docs/reference/types/billing-plan-price'],
['billing-plan-resource', '/docs/reference/types/billing-plan-resource'],
['billing-plan-unit-price', '/docs/reference/types/billing-plan-unit-price'],
['billing-plan-unit-price-tier', '/docs/reference/types/billing-plan-unit-price-tier'],
['billing-proration-discount', '/docs/reference/types/billing-proration-discount'],
['billing-proration-credit-detail', '/docs/reference/types/billing-proration-credit-detail'],
['billing-checkout-totals', '/docs/reference/types/billing-checkout-totals'],
['billing-checkout-resource', '/docs/reference/types/billing-checkout-resource'],
['billing-money-amount', '/docs/reference/types/billing-money-amount'],
['billing-per-unit-total', '/docs/reference/types/billing-per-unit-total'],
['billing-per-unit-total-tier', '/docs/reference/types/billing-per-unit-total-tier'],
['billing-subscription-item-resource', '/docs/reference/types/billing-subscription-item-resource'],
['billing-subscription-item-next-payment', '/docs/reference/types/billing-subscription-item-next-payment'],
['billing-subscription-item-seats', '/docs/reference/types/billing-subscription-item-seats'],
['billing-subscription-item-status', '/docs/reference/backend/types/billing-subscription-item-status'],
['feature-resource', '/docs/reference/types/feature-resource'],
['billing-statement-group', '/docs/reference/types/billing-statement-group'],
['billing-statement-resource', '/docs/reference/types/billing-statement-resource'],
['billing-totals', '/docs/reference/types/billing-totals'],
['billing-subscription-resource', '/docs/reference/types/billing-subscription-resource'],
['billing-subscription-next-payment', '/docs/reference/types/billing-subscription-next-payment'],
['clerk-api-response-error', '/docs/reference/types/clerk-api-response-error'],
['clerk-api-error', '/docs/reference/types/clerk-api-error'],
['billing-statement-totals', '/docs/reference/types/billing-statement-totals'],
Expand Down
139 changes: 134 additions & 5 deletions packages/shared/src/types/billing.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -852,6 +852,9 @@ export interface BillingSubscriptionItemResource extends ClerkResource {
*/
amount: BillingMoneyAmount;
};
/**
* The credits applied to this subscription item.
*/
credits?: BillingCredits;
/**
* The active discount applied to this subscription item.
Expand DownExpand Up@@ -994,21 +997,63 @@ export interface BillingMoneyAmount {
currencySymbol: string;
}

/**
* Contains details about a proration credit, including the remaining portion of the billing cycle.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingProrationCreditDetail {
/**
* The monetary value of the proration credit.
*/
amount: BillingMoneyAmount;
/**
* The number of days remaining in the current billing cycle.
*/
cycleDaysRemaining: number;
/**
* The total number of days in the billing cycle.
*/
cycleDaysTotal: number;
/**
* The percentage of the billing cycle that remains.
*/
cycleRemainingPercent: number;
}

/**
* Contains details about the payer's available credit and the amount applied to the transaction.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingPayerCredit {
/**
* The payer's credit balance remaining after the transaction.
*/
remainingBalance: BillingMoneyAmount;
/**
* The amount of payer credit applied to the transaction.
*/
appliedAmount: BillingMoneyAmount;
}

/**
* The `BillingCredits` type represents the credits applied to a checkout or payment.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingCredits {
/**
* The credit for the unused portion of the current billing cycle. `null` when no proration credit applies.
*/
proration: BillingProrationCreditDetail | null;
/**
* The payer credit applied to the transaction. `null` when no payer credit applies.
*/
payer: BillingPayerCredit | null;
/**
* The total monetary value of all credits applied to the transaction.
*/
total: BillingMoneyAmount;
}

Expand DownExpand Up@@ -1043,14 +1088,44 @@ export interface BillingProrationDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingAppliedDiscount {
/**
* The monetary value of the discount applied to the transaction.
*/
amount: BillingMoneyAmount;
/**
* The unique identifier of the discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The promotion code used to apply the discount.
*/
promoCode?: string;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The originally configured duration in billing cycles. `null` means the discount does not expire after a fixed
* number of cycles.
*/
durationInCycles?: number | null;
}

Expand All@@ -1060,20 +1135,67 @@ export interface BillingAppliedDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingDiscountRedemption {
/**
* The unique identifier of the discount redemption.
*/
id: string;
/**
* The unique identifier of the subscription item receiving the discount.
*/
subscriptionItemId: string;
/**
* The unique identifier of the redeemed discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* How the discount was applied to the subscription item.
*/
source: 'promotion' | 'manual' | 'promo_code';
/**
* The promotion code used to redeem the discount.
*/
promoCode?: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect?: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The monetary value of the discount applied to the subscription item.
*/
amount?: BillingMoneyAmount;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The number of billing cycles to which the discount has already been applied.
*/
cyclesApplied: number;
/**
* The current status of the discount redemption.
*/
status?: 'active' | 'exhausted' | 'removed';
/**
* The date and time when the discount was redeemed.
*/
redeemedAt: Date;
/**
* The identifier of the user who redeemed the discount. `null` if no user was recorded.
*/
redeemedBy: string | null;
}

Expand DownExpand Up@@ -1232,6 +1354,9 @@ export interface BillingCheckoutTotals {
* Any credits (like account balance or promo credits) that are being applied to the checkout.
*/
credit: BillingMoneyAmount | null;
/**
* The credits applied to the checkout. `null` when no credits apply.
*/
credits: BillingCredits | null;
/**
* Any outstanding amount from previous unpaid invoices that is being collected as part of the checkout.
Expand DownExpand Up@@ -1302,16 +1427,20 @@ export type CreateCheckoutParams = WithOptionalOrgType<{
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export type UpdateCheckoutParams = WithOptionalOrgType<{
export type UpdateCheckoutParams = {
/**
* The unique identifier for the checkout session.
*/
id: string;
/**
* The Organization ID to perform the request on.
*/
orgId?: string;
/**
* The promo code to apply. Use an empty string to remove the applied promo code.
*/
promoCode: string;
}>;
};

/**
* The `confirm()` method accepts the following parameters. **Only one of `paymentMethodId`, `paymentToken`, or `useTestCard` should be provided.**
Expand DownExpand Up@@ -1392,7 +1521,7 @@ export interface BillingCheckoutResource extends ClerkResource {
*/
totals: BillingTotals;
/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<BillingCheckoutResource>;
/**
Expand DownExpand Up@@ -1542,12 +1671,12 @@ export interface CheckoutFlowFinalizeParams {
*/
interface CheckoutFlowMethods {
/**
* Updates the current checkout. Use an empty promo code to remove the applied promo code.
* Updates the current checkout. Use an empty promo code to remove the applied promo code. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#update)
*/
update: (params: Pick<UpdateCheckoutParams, 'promoCode'>) => Promise<{ error: ClerkError | null }>;

/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<{ error: ClerkError | null }>;

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' docs(repo): Fixing billing broken links for Typedoc output by SarahSoutoul · Pull Request #9393 · clerk/javascript · GitHub
Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/fix-billing-typedoc-pages.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Fix broken Billing TypeDoc links and add missing JSDoc descriptions for the credit and discount types.
90 changes: 90 additions & 0 deletions .typedoc/__tests__/relative-link-replacements.test.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
import { describe, expect, it } from 'vitest';

// @ts-expect-error — .mjs plugin has no type declarations
import { applyRelativeLinkReplacements } from '../custom-plugin.mjs';

/**
* Unit coverage for the `LINK_REPLACEMENTS` rules exercised through the exported
* `applyRelativeLinkReplacements()` entry point. These guard the Billing checkout
* links so an incorrect route or anchor cannot silently pass CI.
*/
describe('applyRelativeLinkReplacements', () => {
const cases: Array<[label: string, input: string, expected: string]> = [
[
'confirm-checkout-params routes to the #confirm-parameters section',
'[x](confirm-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#confirm-parameters)',
],
[
'update-checkout-params routes to the #update-parameters section',
'[x](update-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#update-parameters)',
],
[
'preserves an anchor from the source link',
'[x](billing-credits.mdx#total)',
'[x](/docs/reference/types/billing-credits#total)',
],
[
'billing-credits routes to its standalone page',
'[x](billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'billing-applied-discount routes to its standalone page',
'[x](billing-applied-discount.mdx)',
'[x](/docs/reference/types/billing-applied-discount)',
],
[
'billing-discount-redemption routes to its standalone page',
'[x](billing-discount-redemption.mdx)',
'[x](/docs/reference/types/billing-discount-redemption)',
],
[
'billing-payer-credit routes to its standalone page',
'[x](billing-payer-credit.mdx)',
'[x](/docs/reference/types/billing-payer-credit)',
],
[
'billing-proration-credit-detail routes to its standalone page',
'[x](billing-proration-credit-detail.mdx)',
'[x](/docs/reference/types/billing-proration-credit-detail)',
],
[
'resolves relative path prefixes',
'[x](../../types/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'resolves nested object-doc links',
'[x](billing-credits/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
];

it.each(cases)('%s', (_label, input, expected) => {
expect(applyRelativeLinkReplacements(input)).toBe(expected);
});

it('routes the two sibling next-payment pages independently', () => {
expect(applyRelativeLinkReplacements('[x](billing-subscription-item-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-item-next-payment)',
);
expect(applyRelativeLinkReplacements('[x](billing-subscription-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-next-payment)',
);
});

it('does not rewrite a page whose name is a prefix of a replacement key', () => {
// `billing-payer` is a prefix of `billing-payer-credit`, but the `.mdx` boundary
// must keep an unrelated `billing-payer-resource.mdx` link from being mis-routed.
expect(applyRelativeLinkReplacements('[x](billing-payer-resource.mdx)')).toBe(
'[x](/docs/reference/types/billing-payer-resource)',
);
});

it('leaves content without matching links untouched', () => {
expect(applyRelativeLinkReplacements('no links here')).toBe('no links here');
expect(applyRelativeLinkReplacements('')).toBe('');
});
});
15 changes: 14 additions & 1 deletion .typedoc/custom-plugin.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ const FILES_WITHOUT_HEADINGS = [
'organization-membership-public-user-data.mdx',
'checkout-signal-value.mdx',
'checkout-flow-resource.mdx',
'update-checkout-params.mdx',
'use-checkout-options.mdx',
'use-payment-element-return.mdx',
'use-payment-methods-return.mdx',
Expand DownExpand Up@@ -108,26 +109,38 @@ const LINK_REPLACEMENTS = [
['invitation', '/docs/reference/backend/types/backend-invitation'],
['verify-token-options', '#verify-token-options'],
['localization-resource', '/docs/guides/customizing-clerk/localization'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#parameters'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#confirm-parameters'],
['update-checkout-params', '/docs/reference/types/billing-checkout-resource#update-parameters'],
['billing-applied-discount', '/docs/reference/types/billing-applied-discount'],
['billing-credits', '/docs/reference/types/billing-credits'],
['billing-discount-redemption', '/docs/reference/types/billing-discount-redemption'],
['billing-discounts', '/docs/reference/types/billing-discounts'],
['billing-payment-totals', '/docs/reference/types/billing-payment-totals'],
['billing-payment-method-resource', '/docs/reference/types/billing-payment-method-resource'],
['billing-payer-credit', '/docs/reference/types/billing-payer-credit'],
['billing-payer-resource', '/docs/reference/types/billing-payer-resource'],
['billing-period-totals', '/docs/reference/types/billing-period-totals'],
['billing-plan-price', '/docs/reference/types/billing-plan-price'],
['billing-plan-resource', '/docs/reference/types/billing-plan-resource'],
['billing-plan-unit-price', '/docs/reference/types/billing-plan-unit-price'],
['billing-plan-unit-price-tier', '/docs/reference/types/billing-plan-unit-price-tier'],
['billing-proration-discount', '/docs/reference/types/billing-proration-discount'],
['billing-proration-credit-detail', '/docs/reference/types/billing-proration-credit-detail'],
['billing-checkout-totals', '/docs/reference/types/billing-checkout-totals'],
['billing-checkout-resource', '/docs/reference/types/billing-checkout-resource'],
['billing-money-amount', '/docs/reference/types/billing-money-amount'],
['billing-per-unit-total', '/docs/reference/types/billing-per-unit-total'],
['billing-per-unit-total-tier', '/docs/reference/types/billing-per-unit-total-tier'],
['billing-subscription-item-resource', '/docs/reference/types/billing-subscription-item-resource'],
['billing-subscription-item-next-payment', '/docs/reference/types/billing-subscription-item-next-payment'],
['billing-subscription-item-seats', '/docs/reference/types/billing-subscription-item-seats'],
['billing-subscription-item-status', '/docs/reference/backend/types/billing-subscription-item-status'],
['feature-resource', '/docs/reference/types/feature-resource'],
['billing-statement-group', '/docs/reference/types/billing-statement-group'],
['billing-statement-resource', '/docs/reference/types/billing-statement-resource'],
['billing-totals', '/docs/reference/types/billing-totals'],
['billing-subscription-resource', '/docs/reference/types/billing-subscription-resource'],
['billing-subscription-next-payment', '/docs/reference/types/billing-subscription-next-payment'],
['clerk-api-response-error', '/docs/reference/types/clerk-api-response-error'],
['clerk-api-error', '/docs/reference/types/clerk-api-error'],
['billing-statement-totals', '/docs/reference/types/billing-statement-totals'],
Expand Down
139 changes: 134 additions & 5 deletions packages/shared/src/types/billing.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -852,6 +852,9 @@ export interface BillingSubscriptionItemResource extends ClerkResource {
*/
amount: BillingMoneyAmount;
};
/**
* The credits applied to this subscription item.
*/
credits?: BillingCredits;
/**
* The active discount applied to this subscription item.
Expand DownExpand Up@@ -994,21 +997,63 @@ export interface BillingMoneyAmount {
currencySymbol: string;
}

/**
* Contains details about a proration credit, including the remaining portion of the billing cycle.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingProrationCreditDetail {
/**
* The monetary value of the proration credit.
*/
amount: BillingMoneyAmount;
/**
* The number of days remaining in the current billing cycle.
*/
cycleDaysRemaining: number;
/**
* The total number of days in the billing cycle.
*/
cycleDaysTotal: number;
/**
* The percentage of the billing cycle that remains.
*/
cycleRemainingPercent: number;
}

/**
* Contains details about the payer's available credit and the amount applied to the transaction.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingPayerCredit {
/**
* The payer's credit balance remaining after the transaction.
*/
remainingBalance: BillingMoneyAmount;
/**
* The amount of payer credit applied to the transaction.
*/
appliedAmount: BillingMoneyAmount;
}

/**
* The `BillingCredits` type represents the credits applied to a checkout or payment.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingCredits {
/**
* The credit for the unused portion of the current billing cycle. `null` when no proration credit applies.
*/
proration: BillingProrationCreditDetail | null;
/**
* The payer credit applied to the transaction. `null` when no payer credit applies.
*/
payer: BillingPayerCredit | null;
/**
* The total monetary value of all credits applied to the transaction.
*/
total: BillingMoneyAmount;
}

Expand DownExpand Up@@ -1043,14 +1088,44 @@ export interface BillingProrationDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingAppliedDiscount {
/**
* The monetary value of the discount applied to the transaction.
*/
amount: BillingMoneyAmount;
/**
* The unique identifier of the discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The promotion code used to apply the discount.
*/
promoCode?: string;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The originally configured duration in billing cycles. `null` means the discount does not expire after a fixed
* number of cycles.
*/
durationInCycles?: number | null;
}

Expand All@@ -1060,20 +1135,67 @@ export interface BillingAppliedDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingDiscountRedemption {
/**
* The unique identifier of the discount redemption.
*/
id: string;
/**
* The unique identifier of the subscription item receiving the discount.
*/
subscriptionItemId: string;
/**
* The unique identifier of the redeemed discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* How the discount was applied to the subscription item.
*/
source: 'promotion' | 'manual' | 'promo_code';
/**
* The promotion code used to redeem the discount.
*/
promoCode?: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect?: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The monetary value of the discount applied to the subscription item.
*/
amount?: BillingMoneyAmount;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The number of billing cycles to which the discount has already been applied.
*/
cyclesApplied: number;
/**
* The current status of the discount redemption.
*/
status?: 'active' | 'exhausted' | 'removed';
/**
* The date and time when the discount was redeemed.
*/
redeemedAt: Date;
/**
* The identifier of the user who redeemed the discount. `null` if no user was recorded.
*/
redeemedBy: string | null;
}

Expand DownExpand Up@@ -1232,6 +1354,9 @@ export interface BillingCheckoutTotals {
* Any credits (like account balance or promo credits) that are being applied to the checkout.
*/
credit: BillingMoneyAmount | null;
/**
* The credits applied to the checkout. `null` when no credits apply.
*/
credits: BillingCredits | null;
/**
* Any outstanding amount from previous unpaid invoices that is being collected as part of the checkout.
Expand DownExpand Up@@ -1302,16 +1427,20 @@ export type CreateCheckoutParams = WithOptionalOrgType<{
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export type UpdateCheckoutParams = WithOptionalOrgType<{
export type UpdateCheckoutParams = {
/**
* The unique identifier for the checkout session.
*/
id: string;
/**
* The Organization ID to perform the request on.
*/
orgId?: string;
/**
* The promo code to apply. Use an empty string to remove the applied promo code.
*/
promoCode: string;
}>;
};

/**
* The `confirm()` method accepts the following parameters. **Only one of `paymentMethodId`, `paymentToken`, or `useTestCard` should be provided.**
Expand DownExpand Up@@ -1392,7 +1521,7 @@ export interface BillingCheckoutResource extends ClerkResource {
*/
totals: BillingTotals;
/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<BillingCheckoutResource>;
/**
Expand DownExpand Up@@ -1542,12 +1671,12 @@ export interface CheckoutFlowFinalizeParams {
*/
interface CheckoutFlowMethods {
/**
* Updates the current checkout. Use an empty promo code to remove the applied promo code.
* Updates the current checkout. Use an empty promo code to remove the applied promo code. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#update)
*/
update: (params: Pick<UpdateCheckoutParams, 'promoCode'>) => Promise<{ error: ClerkError | null }>;

/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<{ error: ClerkError | null }>;

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' docs(repo): Fixing billing broken links for Typedoc output by SarahSoutoul · Pull Request #9393 · clerk/javascript · GitHub
Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/fix-billing-typedoc-pages.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Fix broken Billing TypeDoc links and add missing JSDoc descriptions for the credit and discount types.
90 changes: 90 additions & 0 deletions .typedoc/__tests__/relative-link-replacements.test.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
import { describe, expect, it } from 'vitest';

// @ts-expect-error — .mjs plugin has no type declarations
import { applyRelativeLinkReplacements } from '../custom-plugin.mjs';

/**
* Unit coverage for the `LINK_REPLACEMENTS` rules exercised through the exported
* `applyRelativeLinkReplacements()` entry point. These guard the Billing checkout
* links so an incorrect route or anchor cannot silently pass CI.
*/
describe('applyRelativeLinkReplacements', () => {
const cases: Array<[label: string, input: string, expected: string]> = [
[
'confirm-checkout-params routes to the #confirm-parameters section',
'[x](confirm-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#confirm-parameters)',
],
[
'update-checkout-params routes to the #update-parameters section',
'[x](update-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#update-parameters)',
],
[
'preserves an anchor from the source link',
'[x](billing-credits.mdx#total)',
'[x](/docs/reference/types/billing-credits#total)',
],
[
'billing-credits routes to its standalone page',
'[x](billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'billing-applied-discount routes to its standalone page',
'[x](billing-applied-discount.mdx)',
'[x](/docs/reference/types/billing-applied-discount)',
],
[
'billing-discount-redemption routes to its standalone page',
'[x](billing-discount-redemption.mdx)',
'[x](/docs/reference/types/billing-discount-redemption)',
],
[
'billing-payer-credit routes to its standalone page',
'[x](billing-payer-credit.mdx)',
'[x](/docs/reference/types/billing-payer-credit)',
],
[
'billing-proration-credit-detail routes to its standalone page',
'[x](billing-proration-credit-detail.mdx)',
'[x](/docs/reference/types/billing-proration-credit-detail)',
],
[
'resolves relative path prefixes',
'[x](../../types/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'resolves nested object-doc links',
'[x](billing-credits/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
];

it.each(cases)('%s', (_label, input, expected) => {
expect(applyRelativeLinkReplacements(input)).toBe(expected);
});

it('routes the two sibling next-payment pages independently', () => {
expect(applyRelativeLinkReplacements('[x](billing-subscription-item-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-item-next-payment)',
);
expect(applyRelativeLinkReplacements('[x](billing-subscription-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-next-payment)',
);
});

it('does not rewrite a page whose name is a prefix of a replacement key', () => {
// `billing-payer` is a prefix of `billing-payer-credit`, but the `.mdx` boundary
// must keep an unrelated `billing-payer-resource.mdx` link from being mis-routed.
expect(applyRelativeLinkReplacements('[x](billing-payer-resource.mdx)')).toBe(
'[x](/docs/reference/types/billing-payer-resource)',
);
});

it('leaves content without matching links untouched', () => {
expect(applyRelativeLinkReplacements('no links here')).toBe('no links here');
expect(applyRelativeLinkReplacements('')).toBe('');
});
});
15 changes: 14 additions & 1 deletion .typedoc/custom-plugin.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ const FILES_WITHOUT_HEADINGS = [
'organization-membership-public-user-data.mdx',
'checkout-signal-value.mdx',
'checkout-flow-resource.mdx',
'update-checkout-params.mdx',
'use-checkout-options.mdx',
'use-payment-element-return.mdx',
'use-payment-methods-return.mdx',
Expand DownExpand Up@@ -108,26 +109,38 @@ const LINK_REPLACEMENTS = [
['invitation', '/docs/reference/backend/types/backend-invitation'],
['verify-token-options', '#verify-token-options'],
['localization-resource', '/docs/guides/customizing-clerk/localization'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#parameters'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#confirm-parameters'],
['update-checkout-params', '/docs/reference/types/billing-checkout-resource#update-parameters'],
['billing-applied-discount', '/docs/reference/types/billing-applied-discount'],
['billing-credits', '/docs/reference/types/billing-credits'],
['billing-discount-redemption', '/docs/reference/types/billing-discount-redemption'],
['billing-discounts', '/docs/reference/types/billing-discounts'],
['billing-payment-totals', '/docs/reference/types/billing-payment-totals'],
['billing-payment-method-resource', '/docs/reference/types/billing-payment-method-resource'],
['billing-payer-credit', '/docs/reference/types/billing-payer-credit'],
['billing-payer-resource', '/docs/reference/types/billing-payer-resource'],
['billing-period-totals', '/docs/reference/types/billing-period-totals'],
['billing-plan-price', '/docs/reference/types/billing-plan-price'],
['billing-plan-resource', '/docs/reference/types/billing-plan-resource'],
['billing-plan-unit-price', '/docs/reference/types/billing-plan-unit-price'],
['billing-plan-unit-price-tier', '/docs/reference/types/billing-plan-unit-price-tier'],
['billing-proration-discount', '/docs/reference/types/billing-proration-discount'],
['billing-proration-credit-detail', '/docs/reference/types/billing-proration-credit-detail'],
['billing-checkout-totals', '/docs/reference/types/billing-checkout-totals'],
['billing-checkout-resource', '/docs/reference/types/billing-checkout-resource'],
['billing-money-amount', '/docs/reference/types/billing-money-amount'],
['billing-per-unit-total', '/docs/reference/types/billing-per-unit-total'],
['billing-per-unit-total-tier', '/docs/reference/types/billing-per-unit-total-tier'],
['billing-subscription-item-resource', '/docs/reference/types/billing-subscription-item-resource'],
['billing-subscription-item-next-payment', '/docs/reference/types/billing-subscription-item-next-payment'],
['billing-subscription-item-seats', '/docs/reference/types/billing-subscription-item-seats'],
['billing-subscription-item-status', '/docs/reference/backend/types/billing-subscription-item-status'],
['feature-resource', '/docs/reference/types/feature-resource'],
['billing-statement-group', '/docs/reference/types/billing-statement-group'],
['billing-statement-resource', '/docs/reference/types/billing-statement-resource'],
['billing-totals', '/docs/reference/types/billing-totals'],
['billing-subscription-resource', '/docs/reference/types/billing-subscription-resource'],
['billing-subscription-next-payment', '/docs/reference/types/billing-subscription-next-payment'],
['clerk-api-response-error', '/docs/reference/types/clerk-api-response-error'],
['clerk-api-error', '/docs/reference/types/clerk-api-error'],
['billing-statement-totals', '/docs/reference/types/billing-statement-totals'],
Expand Down
139 changes: 134 additions & 5 deletions packages/shared/src/types/billing.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -852,6 +852,9 @@ export interface BillingSubscriptionItemResource extends ClerkResource {
*/
amount: BillingMoneyAmount;
};
/**
* The credits applied to this subscription item.
*/
credits?: BillingCredits;
/**
* The active discount applied to this subscription item.
Expand DownExpand Up@@ -994,21 +997,63 @@ export interface BillingMoneyAmount {
currencySymbol: string;
}

/**
* Contains details about a proration credit, including the remaining portion of the billing cycle.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingProrationCreditDetail {
/**
* The monetary value of the proration credit.
*/
amount: BillingMoneyAmount;
/**
* The number of days remaining in the current billing cycle.
*/
cycleDaysRemaining: number;
/**
* The total number of days in the billing cycle.
*/
cycleDaysTotal: number;
/**
* The percentage of the billing cycle that remains.
*/
cycleRemainingPercent: number;
}

/**
* Contains details about the payer's available credit and the amount applied to the transaction.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingPayerCredit {
/**
* The payer's credit balance remaining after the transaction.
*/
remainingBalance: BillingMoneyAmount;
/**
* The amount of payer credit applied to the transaction.
*/
appliedAmount: BillingMoneyAmount;
}

/**
* The `BillingCredits` type represents the credits applied to a checkout or payment.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingCredits {
/**
* The credit for the unused portion of the current billing cycle. `null` when no proration credit applies.
*/
proration: BillingProrationCreditDetail | null;
/**
* The payer credit applied to the transaction. `null` when no payer credit applies.
*/
payer: BillingPayerCredit | null;
/**
* The total monetary value of all credits applied to the transaction.
*/
total: BillingMoneyAmount;
}

Expand DownExpand Up@@ -1043,14 +1088,44 @@ export interface BillingProrationDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingAppliedDiscount {
/**
* The monetary value of the discount applied to the transaction.
*/
amount: BillingMoneyAmount;
/**
* The unique identifier of the discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The promotion code used to apply the discount.
*/
promoCode?: string;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The originally configured duration in billing cycles. `null` means the discount does not expire after a fixed
* number of cycles.
*/
durationInCycles?: number | null;
}

Expand All@@ -1060,20 +1135,67 @@ export interface BillingAppliedDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingDiscountRedemption {
/**
* The unique identifier of the discount redemption.
*/
id: string;
/**
* The unique identifier of the subscription item receiving the discount.
*/
subscriptionItemId: string;
/**
* The unique identifier of the redeemed discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* How the discount was applied to the subscription item.
*/
source: 'promotion' | 'manual' | 'promo_code';
/**
* The promotion code used to redeem the discount.
*/
promoCode?: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect?: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The monetary value of the discount applied to the subscription item.
*/
amount?: BillingMoneyAmount;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The number of billing cycles to which the discount has already been applied.
*/
cyclesApplied: number;
/**
* The current status of the discount redemption.
*/
status?: 'active' | 'exhausted' | 'removed';
/**
* The date and time when the discount was redeemed.
*/
redeemedAt: Date;
/**
* The identifier of the user who redeemed the discount. `null` if no user was recorded.
*/
redeemedBy: string | null;
}

Expand DownExpand Up@@ -1232,6 +1354,9 @@ export interface BillingCheckoutTotals {
* Any credits (like account balance or promo credits) that are being applied to the checkout.
*/
credit: BillingMoneyAmount | null;
/**
* The credits applied to the checkout. `null` when no credits apply.
*/
credits: BillingCredits | null;
/**
* Any outstanding amount from previous unpaid invoices that is being collected as part of the checkout.
Expand DownExpand Up@@ -1302,16 +1427,20 @@ export type CreateCheckoutParams = WithOptionalOrgType<{
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export type UpdateCheckoutParams = WithOptionalOrgType<{
export type UpdateCheckoutParams = {
/**
* The unique identifier for the checkout session.
*/
id: string;
/**
* The Organization ID to perform the request on.
*/
orgId?: string;
/**
* The promo code to apply. Use an empty string to remove the applied promo code.
*/
promoCode: string;
}>;
};

/**
* The `confirm()` method accepts the following parameters. **Only one of `paymentMethodId`, `paymentToken`, or `useTestCard` should be provided.**
Expand DownExpand Up@@ -1392,7 +1521,7 @@ export interface BillingCheckoutResource extends ClerkResource {
*/
totals: BillingTotals;
/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<BillingCheckoutResource>;
/**
Expand DownExpand Up@@ -1542,12 +1671,12 @@ export interface CheckoutFlowFinalizeParams {
*/
interface CheckoutFlowMethods {
/**
* Updates the current checkout. Use an empty promo code to remove the applied promo code.
* Updates the current checkout. Use an empty promo code to remove the applied promo code. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#update)
*/
update: (params: Pick<UpdateCheckoutParams, 'promoCode'>) => Promise<{ error: ClerkError | null }>;

/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<{ error: ClerkError | null }>;

Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); docs(repo): Fixing billing broken links for Typedoc output by SarahSoutoul · Pull Request #9393 · clerk/javascript · GitHub
Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/fix-billing-typedoc-pages.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Fix broken Billing TypeDoc links and add missing JSDoc descriptions for the credit and discount types.
90 changes: 90 additions & 0 deletions .typedoc/__tests__/relative-link-replacements.test.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
import { describe, expect, it } from 'vitest';

// @ts-expect-error — .mjs plugin has no type declarations
import { applyRelativeLinkReplacements } from '../custom-plugin.mjs';

/**
* Unit coverage for the `LINK_REPLACEMENTS` rules exercised through the exported
* `applyRelativeLinkReplacements()` entry point. These guard the Billing checkout
* links so an incorrect route or anchor cannot silently pass CI.
*/
describe('applyRelativeLinkReplacements', () => {
const cases: Array<[label: string, input: string, expected: string]> = [
[
'confirm-checkout-params routes to the #confirm-parameters section',
'[x](confirm-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#confirm-parameters)',
],
[
'update-checkout-params routes to the #update-parameters section',
'[x](update-checkout-params.mdx)',
'[x](/docs/reference/types/billing-checkout-resource#update-parameters)',
],
[
'preserves an anchor from the source link',
'[x](billing-credits.mdx#total)',
'[x](/docs/reference/types/billing-credits#total)',
],
[
'billing-credits routes to its standalone page',
'[x](billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'billing-applied-discount routes to its standalone page',
'[x](billing-applied-discount.mdx)',
'[x](/docs/reference/types/billing-applied-discount)',
],
[
'billing-discount-redemption routes to its standalone page',
'[x](billing-discount-redemption.mdx)',
'[x](/docs/reference/types/billing-discount-redemption)',
],
[
'billing-payer-credit routes to its standalone page',
'[x](billing-payer-credit.mdx)',
'[x](/docs/reference/types/billing-payer-credit)',
],
[
'billing-proration-credit-detail routes to its standalone page',
'[x](billing-proration-credit-detail.mdx)',
'[x](/docs/reference/types/billing-proration-credit-detail)',
],
[
'resolves relative path prefixes',
'[x](../../types/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
[
'resolves nested object-doc links',
'[x](billing-credits/billing-credits.mdx)',
'[x](/docs/reference/types/billing-credits)',
],
];

it.each(cases)('%s', (_label, input, expected) => {
expect(applyRelativeLinkReplacements(input)).toBe(expected);
});

it('routes the two sibling next-payment pages independently', () => {
expect(applyRelativeLinkReplacements('[x](billing-subscription-item-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-item-next-payment)',
);
expect(applyRelativeLinkReplacements('[x](billing-subscription-next-payment.mdx)')).toBe(
'[x](/docs/reference/types/billing-subscription-next-payment)',
);
});

it('does not rewrite a page whose name is a prefix of a replacement key', () => {
// `billing-payer` is a prefix of `billing-payer-credit`, but the `.mdx` boundary
// must keep an unrelated `billing-payer-resource.mdx` link from being mis-routed.
expect(applyRelativeLinkReplacements('[x](billing-payer-resource.mdx)')).toBe(
'[x](/docs/reference/types/billing-payer-resource)',
);
});

it('leaves content without matching links untouched', () => {
expect(applyRelativeLinkReplacements('no links here')).toBe('no links here');
expect(applyRelativeLinkReplacements('')).toBe('');
});
});
15 changes: 14 additions & 1 deletion .typedoc/custom-plugin.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ const FILES_WITHOUT_HEADINGS = [
'organization-membership-public-user-data.mdx',
'checkout-signal-value.mdx',
'checkout-flow-resource.mdx',
'update-checkout-params.mdx',
'use-checkout-options.mdx',
'use-payment-element-return.mdx',
'use-payment-methods-return.mdx',
Expand DownExpand Up@@ -108,26 +109,38 @@ const LINK_REPLACEMENTS = [
['invitation', '/docs/reference/backend/types/backend-invitation'],
['verify-token-options', '#verify-token-options'],
['localization-resource', '/docs/guides/customizing-clerk/localization'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#parameters'],
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#confirm-parameters'],
['update-checkout-params', '/docs/reference/types/billing-checkout-resource#update-parameters'],
['billing-applied-discount', '/docs/reference/types/billing-applied-discount'],
['billing-credits', '/docs/reference/types/billing-credits'],
['billing-discount-redemption', '/docs/reference/types/billing-discount-redemption'],
['billing-discounts', '/docs/reference/types/billing-discounts'],
['billing-payment-totals', '/docs/reference/types/billing-payment-totals'],
['billing-payment-method-resource', '/docs/reference/types/billing-payment-method-resource'],
['billing-payer-credit', '/docs/reference/types/billing-payer-credit'],
['billing-payer-resource', '/docs/reference/types/billing-payer-resource'],
['billing-period-totals', '/docs/reference/types/billing-period-totals'],
['billing-plan-price', '/docs/reference/types/billing-plan-price'],
['billing-plan-resource', '/docs/reference/types/billing-plan-resource'],
['billing-plan-unit-price', '/docs/reference/types/billing-plan-unit-price'],
['billing-plan-unit-price-tier', '/docs/reference/types/billing-plan-unit-price-tier'],
['billing-proration-discount', '/docs/reference/types/billing-proration-discount'],
['billing-proration-credit-detail', '/docs/reference/types/billing-proration-credit-detail'],
['billing-checkout-totals', '/docs/reference/types/billing-checkout-totals'],
['billing-checkout-resource', '/docs/reference/types/billing-checkout-resource'],
['billing-money-amount', '/docs/reference/types/billing-money-amount'],
['billing-per-unit-total', '/docs/reference/types/billing-per-unit-total'],
['billing-per-unit-total-tier', '/docs/reference/types/billing-per-unit-total-tier'],
['billing-subscription-item-resource', '/docs/reference/types/billing-subscription-item-resource'],
['billing-subscription-item-next-payment', '/docs/reference/types/billing-subscription-item-next-payment'],
['billing-subscription-item-seats', '/docs/reference/types/billing-subscription-item-seats'],
['billing-subscription-item-status', '/docs/reference/backend/types/billing-subscription-item-status'],
['feature-resource', '/docs/reference/types/feature-resource'],
['billing-statement-group', '/docs/reference/types/billing-statement-group'],
['billing-statement-resource', '/docs/reference/types/billing-statement-resource'],
['billing-totals', '/docs/reference/types/billing-totals'],
['billing-subscription-resource', '/docs/reference/types/billing-subscription-resource'],
['billing-subscription-next-payment', '/docs/reference/types/billing-subscription-next-payment'],
['clerk-api-response-error', '/docs/reference/types/clerk-api-response-error'],
['clerk-api-error', '/docs/reference/types/clerk-api-error'],
['billing-statement-totals', '/docs/reference/types/billing-statement-totals'],
Expand Down
139 changes: 134 additions & 5 deletions packages/shared/src/types/billing.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -852,6 +852,9 @@ export interface BillingSubscriptionItemResource extends ClerkResource {
*/
amount: BillingMoneyAmount;
};
/**
* The credits applied to this subscription item.
*/
credits?: BillingCredits;
/**
* The active discount applied to this subscription item.
Expand DownExpand Up@@ -994,21 +997,63 @@ export interface BillingMoneyAmount {
currencySymbol: string;
}

/**
* Contains details about a proration credit, including the remaining portion of the billing cycle.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingProrationCreditDetail {
/**
* The monetary value of the proration credit.
*/
amount: BillingMoneyAmount;
/**
* The number of days remaining in the current billing cycle.
*/
cycleDaysRemaining: number;
/**
* The total number of days in the billing cycle.
*/
cycleDaysTotal: number;
/**
* The percentage of the billing cycle that remains.
*/
cycleRemainingPercent: number;
}

/**
* Contains details about the payer's available credit and the amount applied to the transaction.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingPayerCredit {
/**
* The payer's credit balance remaining after the transaction.
*/
remainingBalance: BillingMoneyAmount;
/**
* The amount of payer credit applied to the transaction.
*/
appliedAmount: BillingMoneyAmount;
}

/**
* The `BillingCredits` type represents the credits applied to a checkout or payment.
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingCredits {
/**
* The credit for the unused portion of the current billing cycle. `null` when no proration credit applies.
*/
proration: BillingProrationCreditDetail | null;
/**
* The payer credit applied to the transaction. `null` when no payer credit applies.
*/
payer: BillingPayerCredit | null;
/**
* The total monetary value of all credits applied to the transaction.
*/
total: BillingMoneyAmount;
}

Expand DownExpand Up@@ -1043,14 +1088,44 @@ export interface BillingProrationDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingAppliedDiscount {
/**
* The monetary value of the discount applied to the transaction.
*/
amount: BillingMoneyAmount;
/**
* The unique identifier of the discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The promotion code used to apply the discount.
*/
promoCode?: string;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The originally configured duration in billing cycles. `null` means the discount does not expire after a fixed
* number of cycles.
*/
durationInCycles?: number | null;
}

Expand All@@ -1060,20 +1135,67 @@ export interface BillingAppliedDiscount {
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export interface BillingDiscountRedemption {
/**
* The unique identifier of the discount redemption.
*/
id: string;
/**
* The unique identifier of the subscription item receiving the discount.
*/
subscriptionItemId: string;
/**
* The unique identifier of the redeemed discount.
*/
discountId: string;
/**
* The display name of the discount.
*/
name: string;
/**
* How the discount was applied to the subscription item.
*/
source: 'promotion' | 'manual' | 'promo_code';
/**
* The promotion code used to redeem the discount.
*/
promoCode?: string;
/**
* Whether the discount subtracts a percentage or a fixed amount.
*/
effect?: 'percentage' | 'fixed_amount';
/**
* The percentage deducted when `effect` is `'percentage'`.
*/
percentOff?: number;
/**
* The configured fixed amount off when `effect` is `'fixed_amount'`. This is the discount's configured value, which
* can differ from the `amount` actually applied to the transaction.
*/
amountOff?: BillingMoneyAmount;
/**
* The monetary value of the discount applied to the subscription item.
*/
amount?: BillingMoneyAmount;
/**
* The number of billing cycles for which the discount remains active. `null` means the discount does not expire
* after a fixed number of cycles.
*/
cyclesRemaining: number | null;
/**
* The number of billing cycles to which the discount has already been applied.
*/
cyclesApplied: number;
/**
* The current status of the discount redemption.
*/
status?: 'active' | 'exhausted' | 'removed';
/**
* The date and time when the discount was redeemed.
*/
redeemedAt: Date;
/**
* The identifier of the user who redeemed the discount. `null` if no user was recorded.
*/
redeemedBy: string | null;
}

Expand DownExpand Up@@ -1232,6 +1354,9 @@ export interface BillingCheckoutTotals {
* Any credits (like account balance or promo credits) that are being applied to the checkout.
*/
credit: BillingMoneyAmount | null;
/**
* The credits applied to the checkout. `null` when no credits apply.
*/
credits: BillingCredits | null;
/**
* Any outstanding amount from previous unpaid invoices that is being collected as part of the checkout.
Expand DownExpand Up@@ -1302,16 +1427,20 @@ export type CreateCheckoutParams = WithOptionalOrgType<{
*
* @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes.
*/
export type UpdateCheckoutParams = WithOptionalOrgType<{
export type UpdateCheckoutParams = {
/**
* The unique identifier for the checkout session.
*/
id: string;
/**
* The Organization ID to perform the request on.
*/
orgId?: string;
/**
* The promo code to apply. Use an empty string to remove the applied promo code.
*/
promoCode: string;
}>;
};

/**
* The `confirm()` method accepts the following parameters. **Only one of `paymentMethodId`, `paymentToken`, or `useTestCard` should be provided.**
Expand DownExpand Up@@ -1392,7 +1521,7 @@ export interface BillingCheckoutResource extends ClerkResource {
*/
totals: BillingTotals;
/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<BillingCheckoutResource>;
/**
Expand DownExpand Up@@ -1542,12 +1671,12 @@ export interface CheckoutFlowFinalizeParams {
*/
interface CheckoutFlowMethods {
/**
* Updates the current checkout. Use an empty promo code to remove the applied promo code.
* Updates the current checkout. Use an empty promo code to remove the applied promo code. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#update)
*/
update: (params: Pick<UpdateCheckoutParams, 'promoCode'>) => Promise<{ error: ClerkError | null }>;

/**
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm)
* A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](https://clerk.com/docs/reference/types/billing-checkout-resource#confirm)
*/
confirm: (params: ConfirmCheckoutParams) => Promise<{ error: ClerkError | null }>;

Expand Down
Loading
Loading