@edx/frontend-app-subscription-checkout 1.23.0 → 1.24.1

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.
@@ -15,6 +15,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
15
  * billingPlanUid — selected from filterCustomerBillingPlan by the caller.
16
16
  */
17
17
  import { GET_CUSTOMER, GET_BILLING_PLANS, GET_PRODUCT, GET_ACTIVE_SUBSCRIPTIONS_STATE, GET_IS_CURRENT_USER_SUBSCRIBER, GET_COURSE_DETAIL } from './queries';
18
+ import { getSiteConfig } from '@openedx/frontend-base';
19
+ function encodeCourseRunKey(key) {
20
+ return encodeURIComponent(key.trim());
21
+ }
18
22
  /** Resolve the viax customer uid for the authenticated user by email. */
19
23
  export function getCustomerUid(gql, userEmail) {
20
24
  return __awaiter(this, void 0, void 0, function* () {
@@ -104,38 +108,63 @@ export function getActiveSubscriptions(gql) {
104
108
  * Sends the course key to Viax exactly as provided (e.g. HarvardX+CS50+X). */
105
109
  export function getCourseDetail(gql, courseKey) {
106
110
  return __awaiter(this, void 0, void 0, function* () {
107
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
111
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
108
112
  const key = courseKey.trim();
109
113
  if (!key)
110
114
  return null;
115
+ const encodedKey = encodeCourseRunKey(key);
116
+ const siteConfig = getSiteConfig();
117
+ const LMS_BASE_URL = siteConfig.lmsBaseUrl;
118
+ // 1. Fetch resolved key from Partner REST API
119
+ let resolvedCourseKey = key;
120
+ try {
121
+ const url = new URL(`${LMS_BASE_URL.replace(/\/$/, '')}/api/subscription/course-runs`);
122
+ url.search = `key=${encodedKey}`;
123
+ const res = yield fetch(url.toString(), {
124
+ method: 'GET',
125
+ headers: { Accept: 'application/json' },
126
+ });
127
+ if (res.ok) {
128
+ const payload = yield res.json();
129
+ // Extract key from elements array as per Partner API response format
130
+ const partnerCourseKey = (_b = (_a = payload === null || payload === void 0 ? void 0 : payload.elements) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.course;
131
+ if (partnerCourseKey) {
132
+ resolvedCourseKey = partnerCourseKey;
133
+ }
134
+ }
135
+ }
136
+ catch (error) {
137
+ // If Partner API fails, fallback gracefully to the original key
138
+ console.error('Failed to fetch course run key from Partner API:', error);
139
+ }
111
140
  // Escape single quotes for the filter string only — do not alter `+` or other chars.
112
- const filter = `tCourseKey = '${key.replace(/'/g, "''")}'`;
141
+ const filter = `tCourseKey = '${resolvedCourseKey.replace(/'/g, "''")}'`;
113
142
  const data = yield gql(GET_COURSE_DETAIL, { filter });
114
- const node = (_c = (_b = (_a = data === null || data === void 0 ? void 0 : data.filterTwouCourse) === null || _a === void 0 ? void 0 : _a.edges) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.node;
143
+ const node = (_e = (_d = (_c = data === null || data === void 0 ? void 0 : data.filterTwouCourse) === null || _c === void 0 ? void 0 : _c.edges) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.node;
115
144
  if (!(node === null || node === void 0 ? void 0 : node.maId))
116
145
  return null;
117
146
  return {
118
147
  maId: node.maId,
119
- maName: (_d = node.maName) !== null && _d !== void 0 ? _d : '',
120
- maDescription: (_e = node.maDescription) !== null && _e !== void 0 ? _e : null,
121
- tShortDescription: (_f = node.tShortDescription) !== null && _f !== void 0 ? _f : null,
122
- imageUrl: (_g = node.imageUrl) !== null && _g !== void 0 ? _g : null,
123
- tCourseKey: (_h = node.tCourseKey) !== null && _h !== void 0 ? _h : null,
124
- tBrandText: (_j = node.tBrandText) !== null && _j !== void 0 ? _j : null,
125
- tPrimarySubjectArea: (_k = node.tPrimarySubjectArea) !== null && _k !== void 0 ? _k : null,
126
- tLevelType: (_l = node.tLevelType) !== null && _l !== void 0 ? _l : null,
127
- tLanguage: (_m = node.tLanguage) !== null && _m !== void 0 ? _m : null,
128
- tPacingType: (_p = (_o = node.tPacingType) === null || _o === void 0 ? void 0 : _o.code) !== null && _p !== void 0 ? _p : null,
129
- tDurationLow: (_q = node.tDurationLow) !== null && _q !== void 0 ? _q : null,
130
- tDurationHigh: (_r = node.tDurationHigh) !== null && _r !== void 0 ? _r : null,
131
- tDurationUnit: (_t = (_s = node.tDurationUnit) === null || _s === void 0 ? void 0 : _s.code) !== null && _t !== void 0 ? _t : null,
132
- tEffortLow: (_u = node.tEffortLow) !== null && _u !== void 0 ? _u : null,
133
- tEffortHigh: (_v = node.tEffortHigh) !== null && _v !== void 0 ? _v : null,
134
- tEffortUnit: (_x = (_w = node.tEffortUnit) === null || _w === void 0 ? void 0 : _w.code) !== null && _x !== void 0 ? _x : null,
135
- tUrlCourse: (_y = node.tUrlCourse) !== null && _y !== void 0 ? _y : null,
136
- tB2cSubscriptionInclusion: (_z = node.tB2cSubscriptionInclusion) !== null && _z !== void 0 ? _z : null,
137
- tHasOfacRestrictions: (_0 = node.tHasOfacRestrictions) !== null && _0 !== void 0 ? _0 : null,
138
- tCatalogActive: (_1 = node.tCatalogActive) !== null && _1 !== void 0 ? _1 : null,
148
+ maName: (_f = node.maName) !== null && _f !== void 0 ? _f : '',
149
+ maDescription: (_g = node.maDescription) !== null && _g !== void 0 ? _g : null,
150
+ tShortDescription: (_h = node.tShortDescription) !== null && _h !== void 0 ? _h : null,
151
+ imageUrl: (_j = node.imageUrl) !== null && _j !== void 0 ? _j : null,
152
+ tCourseKey: (_k = node.tCourseKey) !== null && _k !== void 0 ? _k : null,
153
+ tBrandText: (_l = node.tBrandText) !== null && _l !== void 0 ? _l : null,
154
+ tPrimarySubjectArea: (_m = node.tPrimarySubjectArea) !== null && _m !== void 0 ? _m : null,
155
+ tLevelType: (_o = node.tLevelType) !== null && _o !== void 0 ? _o : null,
156
+ tLanguage: (_p = node.tLanguage) !== null && _p !== void 0 ? _p : null,
157
+ tPacingType: (_r = (_q = node.tPacingType) === null || _q === void 0 ? void 0 : _q.code) !== null && _r !== void 0 ? _r : null,
158
+ tDurationLow: (_s = node.tDurationLow) !== null && _s !== void 0 ? _s : null,
159
+ tDurationHigh: (_t = node.tDurationHigh) !== null && _t !== void 0 ? _t : null,
160
+ tDurationUnit: (_v = (_u = node.tDurationUnit) === null || _u === void 0 ? void 0 : _u.code) !== null && _v !== void 0 ? _v : null,
161
+ tEffortLow: (_w = node.tEffortLow) !== null && _w !== void 0 ? _w : null,
162
+ tEffortHigh: (_x = node.tEffortHigh) !== null && _x !== void 0 ? _x : null,
163
+ tEffortUnit: (_z = (_y = node.tEffortUnit) === null || _y === void 0 ? void 0 : _y.code) !== null && _z !== void 0 ? _z : null,
164
+ tUrlCourse: (_0 = node.tUrlCourse) !== null && _0 !== void 0 ? _0 : null,
165
+ tB2cSubscriptionInclusion: (_1 = node.tB2cSubscriptionInclusion) !== null && _1 !== void 0 ? _1 : null,
166
+ tHasOfacRestrictions: (_2 = node.tHasOfacRestrictions) !== null && _2 !== void 0 ? _2 : null,
167
+ tCatalogActive: (_3 = node.tCatalogActive) !== null && _3 !== void 0 ? _3 : null,
139
168
  };
140
169
  });
141
170
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrapApi.js","sourceRoot":"","sources":["../../src/utils/bootstrapApi.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,8BAA8B,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG5J,yEAAyE;AACzE,MAAM,UAAgB,cAAc,CAAC,GAAc,EAAE,SAAiB;;;QACpE,MAAM,MAAM,GAAG,gCAAgC,SAAS,GAAG,CAAC;QAC5D,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,YAAY,EAA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.ts — fetch the runtime ids needed to create a cart.\n *\n * customerUid — looked up by the user's email from their viax party record.\n * salableUid — the product uid from getProduct(maId), used as biiSalable.\n * billingPlanUid — selected from filterCustomerBillingPlan by the caller.\n */\nimport { GET_CUSTOMER, GET_BILLING_PLANS, GET_PRODUCT, GET_ACTIVE_SUBSCRIPTIONS_STATE, GET_IS_CURRENT_USER_SUBSCRIBER, GET_COURSE_DETAIL } from './queries';\nimport type { GqlRunner, BillingPlansResult, BillingPlan, TwouCustomer, ProductInfo, CurrentUserSubscriberResult, CourseDetail } from '../types';\n\n/** Resolve the viax customer uid for the authenticated user by email. */\nexport async function getCustomerUid(gql: GqlRunner, userEmail: string): Promise<string> {\n const filter = `parParty.paContacts.email = '${userEmail}'`;\n const data = await gql(GET_CUSTOMER, { filter });\n const node: TwouCustomer | undefined = data?.filterTwouCustomer?.edges?.[0]?.node;\n if (!node?.uid) throw new Error(`No viax customer found for ${userEmail}. Ensure your account is linked.`);\n return node.uid;\n}\n\n/**\n * Fetch the TwouSubscriptionPlan uid to use as biiSalable in createTwouCart.\n * The maId is the product market-area identifier, e.g. \"TWOU-SUB-PLAN-001\".\n * The returned `uid` is passed as biiSalable when creating the cart.\n */\nexport async function getSalableUid(gql: GqlRunner, maId: string): Promise<ProductInfo> {\n const data = await gql(GET_PRODUCT, { maId });\n const product = data?.getProduct;\n if (!product?.uid) throw new Error(`Product \"${maId}\" not found.`);\n return {\n uid: product.uid,\n maName: product.maName ?? '',\n ownershipModels: (product.saOwnershipModels ?? []).map(\n (m: { uid: string, omName: string }) => ({ uid: m.uid, omName: m.omName }),\n ),\n };\n}\n\n/** Fetch all available customer billing plans. */\nexport async function getBillingPlans(gql: GqlRunner): Promise<BillingPlansResult> {\n const data = await gql(GET_BILLING_PLANS);\n const edges: {\n node: {\n uid: string,\n tStripePriceId: string,\n tStripeAmount?: { amount: string, units?: { code: string } },\n bipIsTemplate: boolean,\n bipOwnershipModel?: { uid: string, omName: string },\n },\n }[] = data?.filterCustomerBillingPlan?.edges ?? [];\n\n if (!edges.length) throw new Error('No billing plans found.');\n\n const plans: BillingPlan[] = edges.map(({ node }) => ({\n uid: node.uid,\n stripePriceId: node.tStripePriceId,\n amount: node.tStripeAmount?.amount ?? '0',\n currency: node.tStripeAmount?.units?.code ?? 'USD',\n isTemplate: node.bipIsTemplate,\n ownershipModel: {\n uid: node.bipOwnershipModel?.uid ?? '',\n omName: node.bipOwnershipModel?.omName ?? '',\n },\n }));\n\n return { plans };\n}\n\n/** Check whether the currently authenticated user already has an active subscription. */\nexport async function isCurrentUserSubscriber(gql: GqlRunner): Promise<CurrentUserSubscriberResult | null> {\n const data = await gql(GET_IS_CURRENT_USER_SUBSCRIBER);\n const result = data?.tIsCurrentUserSubscriber;\n if (!result) return null;\n return {\n isSubscriber: result.isSubscriber === true,\n subscriptionBiId: result.subscriptionBiId ?? null,\n status: result.status ?? null,\n subscriptionStartDate: result.subscriptionStartDate ?? null,\n currentPeriodEnd: result.currentPeriodEnd ?? null,\n };\n}\n\n/** Fetch the number of active subscriptions. */\nexport async function getActiveSubscriptions(gql: GqlRunner): Promise<{ active: number }> {\n const data = await gql(GET_ACTIVE_SUBSCRIPTIONS_STATE);\n const active = data?.tActiveSubscriptionsState?.active;\n if (typeof active !== 'number') {\n throw new Error('Unexpected response shape for tActiveSubscriptionsState');\n }\n return { active };\n}\n\n/** Fetch course details for the enrollment card by tCourseKey.\n * Sends the course key to Viax exactly as provided (e.g. HarvardX+CS50+X). */\nexport async function getCourseDetail(gql: GqlRunner, courseKey: string): Promise<CourseDetail | null> {\n const key = courseKey.trim();\n if (!key) return null;\n\n // Escape single quotes for the filter string only — do not alter `+` or other chars.\n const filter = `tCourseKey = '${key.replace(/'/g, \"''\")}'`;\n const data = await gql(GET_COURSE_DETAIL, { filter });\n const node = data?.filterTwouCourse?.edges?.[0]?.node;\n if (!node?.maId) return null;\n\n return {\n maId: node.maId,\n maName: node.maName ?? '',\n maDescription: node.maDescription ?? null,\n tShortDescription: node.tShortDescription ?? null,\n imageUrl: node.imageUrl ?? null,\n tCourseKey: node.tCourseKey ?? null,\n tBrandText: node.tBrandText ?? null,\n tPrimarySubjectArea: node.tPrimarySubjectArea ?? null,\n tLevelType: node.tLevelType ?? null,\n tLanguage: node.tLanguage ?? null,\n tPacingType: node.tPacingType?.code ?? null,\n tDurationLow: node.tDurationLow ?? null,\n tDurationHigh: node.tDurationHigh ?? null,\n tDurationUnit: node.tDurationUnit?.code ?? null,\n tEffortLow: node.tEffortLow ?? null,\n tEffortHigh: node.tEffortHigh ?? null,\n tEffortUnit: node.tEffortUnit?.code ?? null,\n tUrlCourse: node.tUrlCourse ?? null,\n tB2cSubscriptionInclusion: node.tB2cSubscriptionInclusion ?? null,\n tHasOfacRestrictions: node.tHasOfacRestrictions ?? null,\n tCatalogActive: node.tCatalogActive ?? null,\n };\n}\n"]}
1
+ {"version":3,"file":"bootstrapApi.js","sourceRoot":"","sources":["../../src/utils/bootstrapApi.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,8BAA8B,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE5J,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,SAAS,kBAAkB,CAAC,GAAW;IACrC,OAAO,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AACxC,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAgB,cAAc,CAAC,GAAc,EAAE,SAAiB;;;QACpE,MAAM,MAAM,GAAG,gCAAgC,SAAS,GAAG,CAAC;QAC5D,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,YAAY,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QACjD,MAAM,IAAI,GAA6B,MAAA,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,kBAAkB,0CAAE,KAAK,0CAAG,C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AI,CAAC,mBAAmB,mCAAI,IAAI;YACrD,UAAU,EAAE,MAAA,IAAI,CAAC,UAAU,mCAAI,IAAI;YACnC,SAAS,EAAE,MAAA,IAAI,CAAC,SAAS,mCAAI,IAAI;YACjC,WAAW,EAAE,MAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,mCAAI,IAAI;YAC3C,YAAY,EAAE,MAAA,IAAI,CAAC,YAAY,mCAAI,IAAI;YACvC,aAAa,EAAE,MAAA,IAAI,CAAC,aAAa,mCAAI,IAAI;YACzC,aAAa,EAAE,MAAA,MAAA,IAAI,CAAC,aAAa,0CAAE,IAAI,mCAAI,IAAI;YAC/C,UAAU,EAAE,MAAA,IAAI,CAAC,UAAU,mCAAI,IAAI;YACnC,WAAW,EAAE,MAAA,IAAI,CAAC,WAAW,mCAAI,IAAI;YACrC,WAAW,EAAE,MAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,mCAAI,IAAI;YAC3C,UAAU,EAAE,MAAA,IAAI,CAAC,UAAU,mCAAI,IAAI;YACnC,yBAAyB,EAAE,MAAA,IAAI,CAAC,yBAAyB,mCAAI,IAAI;YACjE,oBAAoB,EAAE,MAAA,IAAI,CAAC,oBAAoB,mCAAI,IAAI;YACvD,cAAc,EAAE,MAAA,IAAI,CAAC,cAAc,mCAAI,IAAI;SAC5C,CAAC;IACJ,CAAC;CAAA","sourcesContent":["/**\n * api/bootstrapApi.ts — fetch the runtime ids needed to create a cart.\n *\n * customerUid — looked up by the user's email from their viax party record.\n * salableUid — the product uid from getProduct(maId), used as biiSalable.\n * billingPlanUid — selected from filterCustomerBillingPlan by the caller.\n */\nimport { GET_CUSTOMER, GET_BILLING_PLANS, GET_PRODUCT, GET_ACTIVE_SUBSCRIPTIONS_STATE, GET_IS_CURRENT_USER_SUBSCRIBER, GET_COURSE_DETAIL } from './queries';\nimport type { GqlRunner, BillingPlansResult, BillingPlan, TwouCustomer, ProductInfo, CurrentUserSubscriberResult, CourseDetail } from '../types';\nimport { getSiteConfig } from '@openedx/frontend-base';\n\nfunction encodeCourseRunKey(key: string): string {\n return encodeURIComponent(key.trim());\n}\n\n/** Resolve the viax customer uid for the authenticated user by email. */\nexport async function getCustomerUid(gql: GqlRunner, userEmail: string): Promise<string> {\n const filter = `parParty.paContacts.email = '${userEmail}'`;\n const data = await gql(GET_CUSTOMER, { filter });\n const node: TwouCustomer | undefined = data?.filterTwouCustomer?.edges?.[0]?.node;\n if (!node?.uid) throw new Error(`No viax customer found for ${userEmail}. Ensure your account is linked.`);\n return node.uid;\n}\n\n/**\n * Fetch the TwouSubscriptionPlan uid to use as biiSalable in createTwouCart.\n * The maId is the product market-area identifier, e.g. \"TWOU-SUB-PLAN-001\".\n * The returned `uid` is passed as biiSalable when creating the cart.\n */\nexport async function getSalableUid(gql: GqlRunner, maId: string): Promise<ProductInfo> {\n const data = await gql(GET_PRODUCT, { maId });\n const product = data?.getProduct;\n if (!product?.uid) throw new Error(`Product \"${maId}\" not found.`);\n return {\n uid: product.uid,\n maName: product.maName ?? '',\n ownershipModels: (product.saOwnershipModels ?? []).map(\n (m: { uid: string, omName: string }) => ({ uid: m.uid, omName: m.omName }),\n ),\n };\n}\n\n/** Fetch all available customer billing plans. */\nexport async function getBillingPlans(gql: GqlRunner): Promise<BillingPlansResult> {\n const data = await gql(GET_BILLING_PLANS);\n const edges: {\n node: {\n uid: string,\n tStripePriceId: string,\n tStripeAmount?: { amount: string, units?: { code: string } },\n bipIsTemplate: boolean,\n bipOwnershipModel?: { uid: string, omName: string },\n },\n }[] = data?.filterCustomerBillingPlan?.edges ?? [];\n\n if (!edges.length) throw new Error('No billing plans found.');\n\n const plans: BillingPlan[] = edges.map(({ node }) => ({\n uid: node.uid,\n stripePriceId: node.tStripePriceId,\n amount: node.tStripeAmount?.amount ?? '0',\n currency: node.tStripeAmount?.units?.code ?? 'USD',\n isTemplate: node.bipIsTemplate,\n ownershipModel: {\n uid: node.bipOwnershipModel?.uid ?? '',\n omName: node.bipOwnershipModel?.omName ?? '',\n },\n }));\n\n return { plans };\n}\n\n/** Check whether the currently authenticated user already has an active subscription. */\nexport async function isCurrentUserSubscriber(gql: GqlRunner): Promise<CurrentUserSubscriberResult | null> {\n const data = await gql(GET_IS_CURRENT_USER_SUBSCRIBER);\n const result = data?.tIsCurrentUserSubscriber;\n if (!result) return null;\n return {\n isSubscriber: result.isSubscriber === true,\n subscriptionBiId: result.subscriptionBiId ?? null,\n status: result.status ?? null,\n subscriptionStartDate: result.subscriptionStartDate ?? null,\n currentPeriodEnd: result.currentPeriodEnd ?? null,\n };\n}\n\n/** Fetch the number of active subscriptions. */\nexport async function getActiveSubscriptions(gql: GqlRunner): Promise<{ active: number }> {\n const data = await gql(GET_ACTIVE_SUBSCRIPTIONS_STATE);\n const active = data?.tActiveSubscriptionsState?.active;\n if (typeof active !== 'number') {\n throw new Error('Unexpected response shape for tActiveSubscriptionsState');\n }\n return { active };\n}\n\n/** Fetch course details for the enrollment card by tCourseKey.\n * Sends the course key to Viax exactly as provided (e.g. HarvardX+CS50+X). */\nexport async function getCourseDetail(gql: GqlRunner, courseKey: string): Promise<CourseDetail | null> {\n const key = courseKey.trim();\n if (!key) return null;\n\n const encodedKey = encodeCourseRunKey(key);\n const siteConfig = getSiteConfig();\n const LMS_BASE_URL = siteConfig.lmsBaseUrl;\n\n // 1. Fetch resolved key from Partner REST API\n let resolvedCourseKey = key;\n try {\n const url = new URL(`${LMS_BASE_URL.replace(/\\/$/, '')}/api/subscription/course-runs`);\n url.search = `key=${encodedKey}`;\n\n const res = await fetch(url.toString(), {\n method: 'GET',\n headers: { Accept: 'application/json' },\n });\n\n if (res.ok) {\n const payload = await res.json();\n // Extract key from elements array as per Partner API response format\n const partnerCourseKey = payload?.elements?.[0]?.course;\n if (partnerCourseKey) {\n resolvedCourseKey = partnerCourseKey;\n }\n }\n } catch (error) {\n // If Partner API fails, fallback gracefully to the original key\n console.error('Failed to fetch course run key from Partner API:', error);\n }\n\n // Escape single quotes for the filter string only — do not alter `+` or other chars.\n const filter = `tCourseKey = '${resolvedCourseKey.replace(/'/g, \"''\")}'`;\n const data = await gql(GET_COURSE_DETAIL, { filter });\n const node = data?.filterTwouCourse?.edges?.[0]?.node;\n if (!node?.maId) return null;\n\n return {\n maId: node.maId,\n maName: node.maName ?? '',\n maDescription: node.maDescription ?? null,\n tShortDescription: node.tShortDescription ?? null,\n imageUrl: node.imageUrl ?? null,\n tCourseKey: node.tCourseKey ?? null,\n tBrandText: node.tBrandText ?? null,\n tPrimarySubjectArea: node.tPrimarySubjectArea ?? null,\n tLevelType: node.tLevelType ?? null,\n tLanguage: node.tLanguage ?? null,\n tPacingType: node.tPacingType?.code ?? null,\n tDurationLow: node.tDurationLow ?? null,\n tDurationHigh: node.tDurationHigh ?? null,\n tDurationUnit: node.tDurationUnit?.code ?? null,\n tEffortLow: node.tEffortLow ?? null,\n tEffortHigh: node.tEffortHigh ?? null,\n tEffortUnit: node.tEffortUnit?.code ?? null,\n tUrlCourse: node.tUrlCourse ?? null,\n tB2cSubscriptionInclusion: node.tB2cSubscriptionInclusion ?? null,\n tHasOfacRestrictions: node.tHasOfacRestrictions ?? null,\n tCatalogActive: node.tCatalogActive ?? null,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edx/frontend-app-subscription-checkout",
3
- "version": "1.23.0",
3
+ "version": "1.24.1",
4
4
  "description": "Subscription Checkout Frontend application",
5
5
  "repository": {
6
6
  "type": "git",