@edx/frontend-app-subscription-manage 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data/services/subscription/getIsCurrentUserSubscriber.js +5 -1
- package/dist/data/services/subscription/getIsCurrentUserSubscriber.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/subscriptionView.js +19 -1
- package/dist/utils/subscriptionView.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ import { GET_IS_CURRENT_USER_SUBSCRIBER } from '../../../utils/queries';
|
|
|
11
11
|
/** Check whether the authenticated user has an active / recent subscription. */
|
|
12
12
|
export function getIsCurrentUserSubscriber(gql) {
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
14
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
15
15
|
const data = yield gql(GET_IS_CURRENT_USER_SUBSCRIBER);
|
|
16
16
|
const result = data === null || data === void 0 ? void 0 : data.tIsCurrentUserSubscriber;
|
|
17
17
|
if (!result || typeof result !== 'object') {
|
|
@@ -31,6 +31,10 @@ export function getIsCurrentUserSubscriber(gql) {
|
|
|
31
31
|
canceledAt: (_k = (_j = result.canceledAt) !== null && _j !== void 0 ? _j : result.cancelledAt) !== null && _k !== void 0 ? _k : null,
|
|
32
32
|
amount: (_m = (_l = result.amount) !== null && _l !== void 0 ? _l : result.price) !== null && _m !== void 0 ? _m : null,
|
|
33
33
|
currency: (_o = result.currency) !== null && _o !== void 0 ? _o : null,
|
|
34
|
+
billingPlanUid: (_p = result.billingPlanUid) !== null && _p !== void 0 ? _p : null,
|
|
35
|
+
interval: (_q = result.interval) !== null && _q !== void 0 ? _q : null,
|
|
36
|
+
billingInterval: (_r = result.billingInterval) !== null && _r !== void 0 ? _r : null,
|
|
37
|
+
bipOwnershipModel: (_s = result.bipOwnershipModel) !== null && _s !== void 0 ? _s : null,
|
|
34
38
|
};
|
|
35
39
|
});
|
|
36
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIsCurrentUserSubscriber.js","sourceRoot":"","sources":["../../../../src/data/services/subscription/getIsCurrentUserSubscriber.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAExE,gFAAgF;AAChF,MAAM,UAAgB,0BAA0B,CAC9C,GAAc;;;QAEd,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,8BAA8B,CAAC,CAAC;QACvD,MAAM,MAAM,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,wBAAwB,CAAC;QAC9C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO;YACL,YAAY,EAAE,MAAM,CAAC,YAAY,KAAK,IAAI;YAC1C,SAAS,EAAE,MAAM,CAAC,SAAS,KAAK,IAAI;YACpC,gBAAgB,EAAE,MAAA,MAAM,CAAC,gBAAgB,mCAAI,IAAI;YACjD,MAAM,EAAE,MAAA,MAAM,CAAC,MAAM,mCAAI,IAAI;YAC7B,gBAAgB,EAAE,MAAA,MAAM,CAAC,gBAAgB,mCAAI,IAAI;YACjD,qBAAqB,EAAE,MAAA,MAAM,CAAC,qBAAqB,mCAAI,IAAI;YAC3D,mBAAmB,EAAE,MAAA,MAAM,CAAC,mBAAmB,mCAAI,IAAI;YACvD,yEAAyE;YACzE,uDAAuD;YACvD,WAAW,EACT,MAAA,MAAA,MAAA,MAAM,CAAC,gBAAgB,mCAAI,MAAM,CAAC,WAAW,mCAAI,MAAM,CAAC,QAAQ,mCAAI,IAAI;YAC1E,UAAU,EAAE,MAAA,MAAA,MAAM,CAAC,UAAU,mCAAI,MAAM,CAAC,WAAW,mCAAI,IAAI;YAC3D,MAAM,EAAE,MAAA,MAAA,MAAM,CAAC,MAAM,mCAAI,MAAM,CAAC,KAAK,mCAAI,IAAI;YAC7C,QAAQ,EAAE,MAAA,MAAM,CAAC,QAAQ,mCAAI,IAAI;
|
|
1
|
+
{"version":3,"file":"getIsCurrentUserSubscriber.js","sourceRoot":"","sources":["../../../../src/data/services/subscription/getIsCurrentUserSubscriber.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAExE,gFAAgF;AAChF,MAAM,UAAgB,0BAA0B,CAC9C,GAAc;;;QAEd,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,8BAA8B,CAAC,CAAC;QACvD,MAAM,MAAM,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,wBAAwB,CAAC;QAC9C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO;YACL,YAAY,EAAE,MAAM,CAAC,YAAY,KAAK,IAAI;YAC1C,SAAS,EAAE,MAAM,CAAC,SAAS,KAAK,IAAI;YACpC,gBAAgB,EAAE,MAAA,MAAM,CAAC,gBAAgB,mCAAI,IAAI;YACjD,MAAM,EAAE,MAAA,MAAM,CAAC,MAAM,mCAAI,IAAI;YAC7B,gBAAgB,EAAE,MAAA,MAAM,CAAC,gBAAgB,mCAAI,IAAI;YACjD,qBAAqB,EAAE,MAAA,MAAM,CAAC,qBAAqB,mCAAI,IAAI;YAC3D,mBAAmB,EAAE,MAAA,MAAM,CAAC,mBAAmB,mCAAI,IAAI;YACvD,yEAAyE;YACzE,uDAAuD;YACvD,WAAW,EACT,MAAA,MAAA,MAAA,MAAM,CAAC,gBAAgB,mCAAI,MAAM,CAAC,WAAW,mCAAI,MAAM,CAAC,QAAQ,mCAAI,IAAI;YAC1E,UAAU,EAAE,MAAA,MAAA,MAAM,CAAC,UAAU,mCAAI,MAAM,CAAC,WAAW,mCAAI,IAAI;YAC3D,MAAM,EAAE,MAAA,MAAA,MAAM,CAAC,MAAM,mCAAI,MAAM,CAAC,KAAK,mCAAI,IAAI;YAC7C,QAAQ,EAAE,MAAA,MAAM,CAAC,QAAQ,mCAAI,IAAI;YACjC,cAAc,EAAE,MAAA,MAAM,CAAC,cAAc,mCAAI,IAAI;YAC7C,QAAQ,EAAE,MAAA,MAAM,CAAC,QAAQ,mCAAI,IAAI;YACjC,eAAe,EAAE,MAAA,MAAM,CAAC,eAAe,mCAAI,IAAI;YAC/C,iBAAiB,EAAE,MAAA,MAAM,CAAC,iBAAiB,mCAAI,IAAI;SACpD,CAAC;IACJ,CAAC;CAAA","sourcesContent":["import type { GqlRunner, CurrentUserSubscriberResult } from '../../../types';\nimport { GET_IS_CURRENT_USER_SUBSCRIBER } from '../../../utils/queries';\n\n/** Check whether the authenticated user has an active / recent subscription. */\nexport async function getIsCurrentUserSubscriber(\n gql: GqlRunner,\n): Promise<CurrentUserSubscriberResult | null> {\n const data = await gql(GET_IS_CURRENT_USER_SUBSCRIBER);\n const result = data?.tIsCurrentUserSubscriber;\n if (!result || typeof result !== 'object') {\n return null;\n }\n\n return {\n isSubscriber: result.isSubscriber === true,\n canEnroll: result.canEnroll === true,\n subscriptionBiId: result.subscriptionBiId ?? null,\n status: result.status ?? null,\n currentPeriodEnd: result.currentPeriodEnd ?? null,\n subscriptionStartDate: result.subscriptionStartDate ?? null,\n subscriptionEndDate: result.subscriptionEndDate ?? null,\n // Prefer billingFrequency (e.g. ANNUAL / MONTHLY); planName is a display\n // label and usually does not encode the billing cycle.\n renewalType:\n result.billingFrequency ?? result.renewalType ?? result.planName ?? null,\n canceledAt: result.canceledAt ?? result.cancelledAt ?? null,\n amount: result.amount ?? result.price ?? null,\n currency: result.currency ?? null,\n billingPlanUid: result.billingPlanUid ?? null,\n interval: result.interval ?? null,\n billingInterval: result.billingInterval ?? null,\n bipOwnershipModel: result.bipOwnershipModel ?? null,\n };\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -24,6 +24,17 @@ export interface CurrentUserSubscriberResult {
|
|
|
24
24
|
/** Optional price display amount when present. */
|
|
25
25
|
amount?: string | null;
|
|
26
26
|
currency?: string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Billing-plan fallback fields used when `renewalType` is missing
|
|
29
|
+
* (e.g. PayPal payloads). See `resolvePlanLabel`.
|
|
30
|
+
*/
|
|
31
|
+
billingPlanUid?: string | null;
|
|
32
|
+
interval?: string | null;
|
|
33
|
+
billingInterval?: string | null;
|
|
34
|
+
bipOwnershipModel?: {
|
|
35
|
+
uid?: string;
|
|
36
|
+
omName?: string;
|
|
37
|
+
} | null;
|
|
27
38
|
}
|
|
28
39
|
/** Normalized enrollment for the cancel confirmation course list. */
|
|
29
40
|
export interface SubscriptionEnrollment {
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG","sourcesContent":["/**\n * Manage Subscription — domain types for Viax subscriber + enrollment data.\n */\n\n/** GraphQL runner used by VIAX fetchers. */\nexport type GqlRunner = (\n query: string,\n variables?: Record<string, unknown>,\n) => Promise<any>;\n\n/** Result of `tIsCurrentUserSubscriber` (JSON scalar). */\nexport interface CurrentUserSubscriberResult {\n /** Has/expects access — drive manage vs upsell messaging. */\n isSubscriber: boolean,\n /** Enrollable right now (ACTIVE / TRIAL_ACTIVE). */\n canEnroll: boolean,\n subscriptionBiId: string | null,\n status: string | null,\n currentPeriodEnd: string | null,\n subscriptionStartDate: string | null,\n subscriptionEndDate: string | null,\n /**\n * Billing cycle / plan label used by UI (from `billingFrequency`,\n * `renewalType`, or `planName` on the API payload).\n */\n renewalType?: string | null,\n /** Optional cancel timestamp when present. */\n canceledAt?: string | null,\n /** Optional price display amount when present. */\n amount?: string | null,\n currency?: string | null,\n}\n\n/** Normalized enrollment for the cancel confirmation course list. */\nexport interface SubscriptionEnrollment {\n biId: string,\n courseMaId: string | null,\n courseName: string | null,\n courseSlug: string | null,\n /** Course card / thumbnail image. */\n imageUrl: string | null,\n orgName: string | null,\n orgLogoUrl: string | null,\n courseRunKey: string | null,\n /** TwouEnrollment bpStatus.code (ACTIVE, COMPLETED, …). */\n status: string | null,\n /** True when the enrollment has a certificate id and/or URL. */\n hasCertificate: boolean,\n /** Absolute certificate link (`COURSES_BASE_URL` + `tCertificateUrl`). */\n certificateUrl: string | null,\n}\n\n/** Normalized invoice row for the Payment history tab. */\nexport interface PaymentHistoryItem {\n biId: string,\n /** Display order number, e.g. EDX-BI3X25N5SY30OSIK */\n orderNumber: string,\n stripeInvoiceId: string | null,\n status: string | null,\n billDate: string | null,\n periodStart: string | null,\n periodEnd: string | null,\n /** Charged amount in major currency units (e.g. 59.00). */\n amount: number,\n currency: string,\n isTrial: boolean,\n}\n\n/** UI view derived from subscriber status. */\nexport type SubscriptionView =\n | 'none'\n | 'active'\n | 'canceled_access'\n | 'canceled_expired';\n\nexport type ManageTab = 'subscription' | 'payment-history';\n\nexport type BillingCycle = 'monthly' | 'annual';\n\nexport interface BillingPlanOwnershipModel {\n uid: string,\n omName: string,\n}\n\n/** Normalized row from `filterCustomerBillingPlan`. */\nexport interface BillingPlan {\n uid: string,\n stripePriceId: string,\n /** Price amount e.g. \"39.99\" */\n amount: string,\n /** Currency code e.g. \"USD\" */\n currency: string,\n isTemplate: boolean,\n ownershipModel: BillingPlanOwnershipModel,\n}\n\nexport interface BillingPlansResult {\n plans: BillingPlan[],\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG","sourcesContent":["/**\n * Manage Subscription — domain types for Viax subscriber + enrollment data.\n */\n\n/** GraphQL runner used by VIAX fetchers. */\nexport type GqlRunner = (\n query: string,\n variables?: Record<string, unknown>,\n) => Promise<any>;\n\n/** Result of `tIsCurrentUserSubscriber` (JSON scalar). */\nexport interface CurrentUserSubscriberResult {\n /** Has/expects access — drive manage vs upsell messaging. */\n isSubscriber: boolean,\n /** Enrollable right now (ACTIVE / TRIAL_ACTIVE). */\n canEnroll: boolean,\n subscriptionBiId: string | null,\n status: string | null,\n currentPeriodEnd: string | null,\n subscriptionStartDate: string | null,\n subscriptionEndDate: string | null,\n /**\n * Billing cycle / plan label used by UI (from `billingFrequency`,\n * `renewalType`, or `planName` on the API payload).\n */\n renewalType?: string | null,\n /** Optional cancel timestamp when present. */\n canceledAt?: string | null,\n /** Optional price display amount when present. */\n amount?: string | null,\n currency?: string | null,\n /**\n * Billing-plan fallback fields used when `renewalType` is missing\n * (e.g. PayPal payloads). See `resolvePlanLabel`.\n */\n billingPlanUid?: string | null,\n interval?: string | null,\n billingInterval?: string | null,\n bipOwnershipModel?: { uid?: string, omName?: string } | null,\n}\n\n/** Normalized enrollment for the cancel confirmation course list. */\nexport interface SubscriptionEnrollment {\n biId: string,\n courseMaId: string | null,\n courseName: string | null,\n courseSlug: string | null,\n /** Course card / thumbnail image. */\n imageUrl: string | null,\n orgName: string | null,\n orgLogoUrl: string | null,\n courseRunKey: string | null,\n /** TwouEnrollment bpStatus.code (ACTIVE, COMPLETED, …). */\n status: string | null,\n /** True when the enrollment has a certificate id and/or URL. */\n hasCertificate: boolean,\n /** Absolute certificate link (`COURSES_BASE_URL` + `tCertificateUrl`). */\n certificateUrl: string | null,\n}\n\n/** Normalized invoice row for the Payment history tab. */\nexport interface PaymentHistoryItem {\n biId: string,\n /** Display order number, e.g. EDX-BI3X25N5SY30OSIK */\n orderNumber: string,\n stripeInvoiceId: string | null,\n status: string | null,\n billDate: string | null,\n periodStart: string | null,\n periodEnd: string | null,\n /** Charged amount in major currency units (e.g. 59.00). */\n amount: number,\n currency: string,\n isTrial: boolean,\n}\n\n/** UI view derived from subscriber status. */\nexport type SubscriptionView =\n | 'none'\n | 'active'\n | 'canceled_access'\n | 'canceled_expired';\n\nexport type ManageTab = 'subscription' | 'payment-history';\n\nexport type BillingCycle = 'monthly' | 'annual';\n\nexport interface BillingPlanOwnershipModel {\n uid: string,\n omName: string,\n}\n\n/** Normalized row from `filterCustomerBillingPlan`. */\nexport interface BillingPlan {\n uid: string,\n stripePriceId: string,\n /** Price amount e.g. \"39.99\" */\n amount: string,\n /** Currency code e.g. \"USD\" */\n currency: string,\n isTemplate: boolean,\n ownershipModel: BillingPlanOwnershipModel,\n}\n\nexport interface BillingPlansResult {\n plans: BillingPlan[],\n}\n"]}
|
|
@@ -40,11 +40,29 @@ export function resolveSubscriptionView(subscriber) {
|
|
|
40
40
|
}
|
|
41
41
|
/** Human-readable plan label from renewal type / status. */
|
|
42
42
|
export function resolvePlanLabel(subscriber) {
|
|
43
|
-
var _a;
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
44
|
const raw = ((_a = subscriber === null || subscriber === void 0 ? void 0 : subscriber.renewalType) !== null && _a !== void 0 ? _a : '').toLowerCase();
|
|
45
45
|
if (raw.includes('annual') || raw.includes('year')) {
|
|
46
46
|
return 'annual';
|
|
47
47
|
}
|
|
48
|
+
if (raw) {
|
|
49
|
+
return 'monthly';
|
|
50
|
+
}
|
|
51
|
+
// renewalType/tStripePriceId unavailable (e.g. PayPal) — fall back to billing-plan fields.
|
|
52
|
+
const omName = (_b = subscriber === null || subscriber === void 0 ? void 0 : subscriber.bipOwnershipModel) === null || _b === void 0 ? void 0 : _b.omName;
|
|
53
|
+
if (omName === 'Annual Subscription') {
|
|
54
|
+
return 'annual';
|
|
55
|
+
}
|
|
56
|
+
if (omName === 'Monthly Subscription') {
|
|
57
|
+
return 'monthly';
|
|
58
|
+
}
|
|
59
|
+
const cycle = ((_d = (_c = subscriber === null || subscriber === void 0 ? void 0 : subscriber.interval) !== null && _c !== void 0 ? _c : subscriber === null || subscriber === void 0 ? void 0 : subscriber.billingInterval) !== null && _d !== void 0 ? _d : '').toLowerCase();
|
|
60
|
+
if (cycle.includes('annual') || cycle.includes('year')) {
|
|
61
|
+
return 'annual';
|
|
62
|
+
}
|
|
63
|
+
if (cycle.includes('month')) {
|
|
64
|
+
return 'monthly';
|
|
65
|
+
}
|
|
48
66
|
return 'monthly';
|
|
49
67
|
}
|
|
50
68
|
//# sourceMappingURL=subscriptionView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptionView.js","sourceRoot":"","sources":["../../src/utils/subscriptionView.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,UAA0D;;IAE1D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,MAAM,GAAG,CAAC,MAAA,UAAU,CAAC,MAAM,mCAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACvD,MAAM,gBAAgB,GAAG,CACvB,8BAA8B,CAAC,GAAG,CAAC,MAAM,CAAC;WACvC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAC7B,CAAC;IAEF,IACE,CAAC,gBAAgB;WACd,CACD,UAAU,CAAC,SAAS;eACjB,UAAU,CAAC,YAAY;eACvB,4BAA4B,CAAC,GAAG,CAAC,MAAM,CAAC,CAC5C,EACD,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,eAAe,GAAG,YAAY,CAAC,UAAU,CAAC,gBAAgB,CAAC;WAC5D,YAAY,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAElD,IAAI,gBAAgB,EAAE,CAAC;QACrB,IAAI,UAAU,CAAC,YAAY,IAAI,eAAe,EAAE,CAAC;YAC/C,OAAO,iBAAiB,CAAC;QAC3B,CAAC;QACD,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED,IAAI,UAAU,CAAC,gBAAgB,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QACzD,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,gBAAgB,CAC9B,UAA0D;;IAE1D,MAAM,GAAG,GAAG,CAAC,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,WAAW,mCAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1D,IAAI,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Derive which manage-subscription UI to show from subscriber API data.\n */\n\nimport {\n ACTIVE_SUBSCRIPTION_STATUSES,\n CANCELED_SUBSCRIPTION_STATUSES,\n} from '../constants';\nimport type { CurrentUserSubscriberResult, SubscriptionView } from '../types';\nimport { isFutureDate } from './formatDate';\n\n/**\n * Map subscriber payload → UI view.\n *\n * - active: can enroll / ACTIVE / TRIAL / isSubscriber without cancel status\n * - canceled_access: canceled but period end still in the future (or isSubscriber)\n * - canceled_expired: previously subscribed, no current access\n * - none: never subscribed / no useful subscription context\n */\nexport function resolveSubscriptionView(\n subscriber: CurrentUserSubscriberResult | null | undefined,\n): SubscriptionView {\n if (!subscriber) {\n return 'none';\n }\n\n const status = (subscriber.status ?? '').toUpperCase();\n const isCanceledStatus = (\n CANCELED_SUBSCRIPTION_STATUSES.has(status)\n || status.includes('CANCEL')\n );\n\n if (\n !isCanceledStatus\n && (\n subscriber.canEnroll\n || subscriber.isSubscriber\n || ACTIVE_SUBSCRIPTION_STATUSES.has(status)\n )\n ) {\n return 'active';\n }\n\n const periodStillOpen = isFutureDate(subscriber.currentPeriodEnd)\n || isFutureDate(subscriber.subscriptionEndDate);\n\n if (isCanceledStatus) {\n if (subscriber.isSubscriber || periodStillOpen) {\n return 'canceled_access';\n }\n return 'canceled_expired';\n }\n\n if (subscriber.subscriptionBiId || subscriber.canceledAt) {\n return 'canceled_expired';\n }\n\n return 'none';\n}\n\n/** Human-readable plan label from renewal type / status. */\nexport function resolvePlanLabel(\n subscriber: CurrentUserSubscriberResult | null | undefined,\n): 'monthly' | 'annual' {\n const raw = (subscriber?.renewalType ?? '').toLowerCase();\n if (raw.includes('annual') || raw.includes('year')) {\n return 'annual';\n }\n return 'monthly';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"subscriptionView.js","sourceRoot":"","sources":["../../src/utils/subscriptionView.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,UAA0D;;IAE1D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,MAAM,GAAG,CAAC,MAAA,UAAU,CAAC,MAAM,mCAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACvD,MAAM,gBAAgB,GAAG,CACvB,8BAA8B,CAAC,GAAG,CAAC,MAAM,CAAC;WACvC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAC7B,CAAC;IAEF,IACE,CAAC,gBAAgB;WACd,CACD,UAAU,CAAC,SAAS;eACjB,UAAU,CAAC,YAAY;eACvB,4BAA4B,CAAC,GAAG,CAAC,MAAM,CAAC,CAC5C,EACD,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,eAAe,GAAG,YAAY,CAAC,UAAU,CAAC,gBAAgB,CAAC;WAC5D,YAAY,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAElD,IAAI,gBAAgB,EAAE,CAAC;QACrB,IAAI,UAAU,CAAC,YAAY,IAAI,eAAe,EAAE,CAAC;YAC/C,OAAO,iBAAiB,CAAC;QAC3B,CAAC;QACD,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED,IAAI,UAAU,CAAC,gBAAgB,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QACzD,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,gBAAgB,CAC9B,UAA0D;;IAE1D,MAAM,GAAG,GAAG,CAAC,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,WAAW,mCAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1D,IAAI,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,2FAA2F;IAC3F,MAAM,MAAM,GAAG,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,iBAAiB,0CAAE,MAAM,CAAC;IACrD,IAAI,MAAM,KAAK,qBAAqB,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,MAAM,KAAK,sBAAsB,EAAE,CAAC;QACtC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,MAAA,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,mCAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,eAAe,mCAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACxF,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACvD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Derive which manage-subscription UI to show from subscriber API data.\n */\n\nimport {\n ACTIVE_SUBSCRIPTION_STATUSES,\n CANCELED_SUBSCRIPTION_STATUSES,\n} from '../constants';\nimport type { CurrentUserSubscriberResult, SubscriptionView } from '../types';\nimport { isFutureDate } from './formatDate';\n\n/**\n * Map subscriber payload → UI view.\n *\n * - active: can enroll / ACTIVE / TRIAL / isSubscriber without cancel status\n * - canceled_access: canceled but period end still in the future (or isSubscriber)\n * - canceled_expired: previously subscribed, no current access\n * - none: never subscribed / no useful subscription context\n */\nexport function resolveSubscriptionView(\n subscriber: CurrentUserSubscriberResult | null | undefined,\n): SubscriptionView {\n if (!subscriber) {\n return 'none';\n }\n\n const status = (subscriber.status ?? '').toUpperCase();\n const isCanceledStatus = (\n CANCELED_SUBSCRIPTION_STATUSES.has(status)\n || status.includes('CANCEL')\n );\n\n if (\n !isCanceledStatus\n && (\n subscriber.canEnroll\n || subscriber.isSubscriber\n || ACTIVE_SUBSCRIPTION_STATUSES.has(status)\n )\n ) {\n return 'active';\n }\n\n const periodStillOpen = isFutureDate(subscriber.currentPeriodEnd)\n || isFutureDate(subscriber.subscriptionEndDate);\n\n if (isCanceledStatus) {\n if (subscriber.isSubscriber || periodStillOpen) {\n return 'canceled_access';\n }\n return 'canceled_expired';\n }\n\n if (subscriber.subscriptionBiId || subscriber.canceledAt) {\n return 'canceled_expired';\n }\n\n return 'none';\n}\n\n/** Human-readable plan label from renewal type / status. */\nexport function resolvePlanLabel(\n subscriber: CurrentUserSubscriberResult | null | undefined,\n): 'monthly' | 'annual' {\n const raw = (subscriber?.renewalType ?? '').toLowerCase();\n if (raw.includes('annual') || raw.includes('year')) {\n return 'annual';\n }\n if (raw) {\n return 'monthly';\n }\n\n // renewalType/tStripePriceId unavailable (e.g. PayPal) — fall back to billing-plan fields.\n const omName = subscriber?.bipOwnershipModel?.omName;\n if (omName === 'Annual Subscription') {\n return 'annual';\n }\n if (omName === 'Monthly Subscription') {\n return 'monthly';\n }\n\n const cycle = (subscriber?.interval ?? subscriber?.billingInterval ?? '').toLowerCase();\n if (cycle.includes('annual') || cycle.includes('year')) {\n return 'annual';\n }\n if (cycle.includes('month')) {\n return 'monthly';\n }\n\n return 'monthly';\n}\n"]}
|