@edx/frontend-app-subscription-checkout 1.0.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/LICENSE +661 -0
- package/README.rst +235 -0
- package/dist/Main.d.ts +3 -0
- package/dist/Main.js +15 -0
- package/dist/Main.js.map +1 -0
- package/dist/app.d.ts +3 -0
- package/dist/app.js +13 -0
- package/dist/app.js.map +1 -0
- package/dist/checkoutPage/CheckoutPage.d.ts +3 -0
- package/dist/checkoutPage/CheckoutPage.js +30 -0
- package/dist/checkoutPage/CheckoutPage.js.map +1 -0
- package/dist/components/BrandMarks/BrandMarks.d.ts +3 -0
- package/dist/components/BrandMarks/BrandMarks.js +9 -0
- package/dist/components/BrandMarks/BrandMarks.js.map +1 -0
- package/dist/components/CartSummary/CartSummary.d.ts +21 -0
- package/dist/components/CartSummary/CartSummary.js +30 -0
- package/dist/components/CartSummary/CartSummary.js.map +1 -0
- package/dist/components/CartSummary/Messages.d.ts +73 -0
- package/dist/components/CartSummary/Messages.js +76 -0
- package/dist/components/CartSummary/Messages.js.map +1 -0
- package/dist/components/Checkout/Checkout.d.ts +4 -0
- package/dist/components/Checkout/Checkout.js +40 -0
- package/dist/components/Checkout/Checkout.js.map +1 -0
- package/dist/components/CheckoutGate/CheckoutGate.d.ts +7 -0
- package/dist/components/CheckoutGate/CheckoutGate.js +35 -0
- package/dist/components/CheckoutGate/CheckoutGate.js.map +1 -0
- package/dist/components/CourseEnrollmentCard/CourseEnrollmentCard.d.ts +9 -0
- package/dist/components/CourseEnrollmentCard/CourseEnrollmentCard.js +31 -0
- package/dist/components/CourseEnrollmentCard/CourseEnrollmentCard.js.map +1 -0
- package/dist/components/CourseEnrollmentCard/Messages.d.ts +33 -0
- package/dist/components/CourseEnrollmentCard/Messages.js +35 -0
- package/dist/components/CourseEnrollmentCard/Messages.js.map +1 -0
- package/dist/components/EdxUnlimitedBanner/EdxUnlimitedBanner.d.ts +13 -0
- package/dist/components/EdxUnlimitedBanner/EdxUnlimitedBanner.js +11 -0
- package/dist/components/EdxUnlimitedBanner/EdxUnlimitedBanner.js.map +1 -0
- package/dist/components/EnrollmentSummary/EnrollmentSummary.d.ts +15 -0
- package/dist/components/EnrollmentSummary/EnrollmentSummary.js +21 -0
- package/dist/components/EnrollmentSummary/EnrollmentSummary.js.map +1 -0
- package/dist/components/EnrollmentSummary/Messages.d.ts +33 -0
- package/dist/components/EnrollmentSummary/Messages.js +35 -0
- package/dist/components/EnrollmentSummary/Messages.js.map +1 -0
- package/dist/components/PaymentFields/PaymentFields.d.ts +9 -0
- package/dist/components/PaymentFields/PaymentFields.js +7 -0
- package/dist/components/PaymentFields/PaymentFields.js.map +1 -0
- package/dist/components/PaymentForm/Messages.d.ts +88 -0
- package/dist/components/PaymentForm/Messages.js +95 -0
- package/dist/components/PaymentForm/Messages.js.map +1 -0
- package/dist/components/PaymentForm/PaymentForm.d.ts +21 -0
- package/dist/components/PaymentForm/PaymentForm.js +69 -0
- package/dist/components/PaymentForm/PaymentForm.js.map +1 -0
- package/dist/components/StatusScreens/Messages.d.ts +103 -0
- package/dist/components/StatusScreens/Messages.js +108 -0
- package/dist/components/StatusScreens/Messages.js.map +1 -0
- package/dist/components/StatusScreens/StatusScreens.d.ts +23 -0
- package/dist/components/StatusScreens/StatusScreens.js +25 -0
- package/dist/components/StatusScreens/StatusScreens.js.map +1 -0
- package/dist/constants.d.ts +59 -0
- package/dist/constants.js +276 -0
- package/dist/constants.js.map +1 -0
- package/dist/data/hooks/keys.d.ts +14 -0
- package/dist/data/hooks/keys.js +15 -0
- package/dist/data/hooks/keys.js.map +1 -0
- package/dist/data/hooks/useCheckout.d.ts +57 -0
- package/dist/data/hooks/useCheckout.js +249 -0
- package/dist/data/hooks/useCheckout.js.map +1 -0
- package/dist/data/hooks/useCheckoutGate.d.ts +15 -0
- package/dist/data/hooks/useCheckoutGate.js +39 -0
- package/dist/data/hooks/useCheckoutGate.js.map +1 -0
- package/dist/data/hooks/useCheckoutMutations.d.ts +16 -0
- package/dist/data/hooks/useCheckoutMutations.js +131 -0
- package/dist/data/hooks/useCheckoutMutations.js.map +1 -0
- package/dist/data/hooks/useCheckoutQueries.d.ts +30 -0
- package/dist/data/hooks/useCheckoutQueries.js +97 -0
- package/dist/data/hooks/useCheckoutQueries.js.map +1 -0
- package/dist/data/services/subs/urls.d.ts +2 -0
- package/dist/data/services/subs/urls.js +4 -0
- package/dist/data/services/subs/urls.js.map +1 -0
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/messages.d.ts +8 -0
- package/dist/messages.js +10 -0
- package/dist/messages.js.map +1 -0
- package/dist/routes.d.ts +18 -0
- package/dist/routes.js +67 -0
- package/dist/routes.js.map +1 -0
- package/dist/slots/ExampleSlot/ExampleSlot.d.ts +3 -0
- package/dist/slots/ExampleSlot/ExampleSlot.js +6 -0
- package/dist/slots/ExampleSlot/ExampleSlot.js.map +1 -0
- package/dist/slots.d.ts +3 -0
- package/dist/slots.js +7 -0
- package/dist/slots.js.map +1 -0
- package/dist/style.scss +14 -0
- package/dist/styles/components/brandMarks.scss +54 -0
- package/dist/styles/components/cartSummary.scss +18 -0
- package/dist/styles/components/checkout.scss +29 -0
- package/dist/styles/components/checkoutStepper.scss +9 -0
- package/dist/styles/components/courseEnrollmentCard.scss +38 -0
- package/dist/styles/components/edxUnlimitedBanner.scss +138 -0
- package/dist/styles/components/enrollmentSummary.scss +13 -0
- package/dist/styles/components/paymentFields.scss +15 -0
- package/dist/styles/components/paymentForm.scss +105 -0
- package/dist/styles/components/statusScreens.scss +29 -0
- package/dist/styles/components/successScreen.scss +0 -0
- package/dist/types.d.ts +222 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/auth.d.ts +7 -0
- package/dist/utils/auth.js +28 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/billingDetails.d.ts +30 -0
- package/dist/utils/billingDetails.js +47 -0
- package/dist/utils/billingDetails.js.map +1 -0
- package/dist/utils/bootstrapApi.d.ts +20 -0
- package/dist/utils/bootstrapApi.js +142 -0
- package/dist/utils/bootstrapApi.js.map +1 -0
- package/dist/utils/cartApi.d.ts +16 -0
- package/dist/utils/cartApi.js +118 -0
- package/dist/utils/cartApi.js.map +1 -0
- package/dist/utils/checkout.d.ts +6 -0
- package/dist/utils/checkout.js +28 -0
- package/dist/utils/checkout.js.map +1 -0
- package/dist/utils/fetchActiveSubscriptions.d.ts +4 -0
- package/dist/utils/fetchActiveSubscriptions.js +36 -0
- package/dist/utils/fetchActiveSubscriptions.js.map +1 -0
- package/dist/utils/fetchBillingPlans.d.ts +2 -0
- package/dist/utils/fetchBillingPlans.js +48 -0
- package/dist/utils/fetchBillingPlans.js.map +1 -0
- package/dist/utils/graphqlClient.d.ts +16 -0
- package/dist/utils/graphqlClient.js +39 -0
- package/dist/utils/graphqlClient.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/provision.d.ts +25 -0
- package/dist/utils/provision.js +95 -0
- package/dist/utils/provision.js.map +1 -0
- package/dist/utils/queries.d.ts +35 -0
- package/dist/utils/queries.js +168 -0
- package/dist/utils/queries.js.map +1 -0
- package/dist/utils/stripe.d.ts +7 -0
- package/dist/utils/stripe.js +43 -0
- package/dist/utils/stripe.js.map +1 -0
- package/dist/widgets/ExampleHeader/app.d.ts +3 -0
- package/dist/widgets/ExampleHeader/app.js +19 -0
- package/dist/widgets/ExampleHeader/app.js.map +1 -0
- package/dist/widgets/ExampleHeader/index.d.ts +1 -0
- package/dist/widgets/ExampleHeader/index.js +2 -0
- package/dist/widgets/ExampleHeader/index.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* api/billingPlans.ts — fetch billing plans without authentication.
|
|
12
|
+
* Called on component mount to show prices before the user clicks Place order.
|
|
13
|
+
*/
|
|
14
|
+
import { GET_BILLING_PLANS } from './queries';
|
|
15
|
+
export function fetchBillingPlans(apiUrl) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
var _a, _b, _c, _d, _e;
|
|
18
|
+
const res = yield fetch(apiUrl, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: { 'Content-Type': 'application/json' },
|
|
21
|
+
body: JSON.stringify({ query: GET_BILLING_PLANS }),
|
|
22
|
+
});
|
|
23
|
+
if (!res.ok)
|
|
24
|
+
throw new Error(`Failed to fetch billing plans (${res.status})`);
|
|
25
|
+
const json = yield res.json();
|
|
26
|
+
if ((_a = json.errors) === null || _a === void 0 ? void 0 : _a.length)
|
|
27
|
+
throw new Error(((_b = json.errors[0]) === null || _b === void 0 ? void 0 : _b.message) || 'GraphQL error');
|
|
28
|
+
const edges = (_e = (_d = (_c = json.data) === null || _c === void 0 ? void 0 : _c.filterCustomerBillingPlan) === null || _d === void 0 ? void 0 : _d.edges) !== null && _e !== void 0 ? _e : [];
|
|
29
|
+
const plans = edges.map(({ node }) => {
|
|
30
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
31
|
+
return ({
|
|
32
|
+
uid: node.uid,
|
|
33
|
+
stripePriceId: node.tStripePriceId,
|
|
34
|
+
amount: (_b = (_a = node.tStripeAmount) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : '0',
|
|
35
|
+
currency: (_e = (_d = (_c = node.tStripeAmount) === null || _c === void 0 ? void 0 : _c.units) === null || _d === void 0 ? void 0 : _d.code) !== null && _e !== void 0 ? _e : 'USD',
|
|
36
|
+
isTemplate: node.bipIsTemplate,
|
|
37
|
+
ownershipModel: {
|
|
38
|
+
uid: (_g = (_f = node.bipOwnershipModel) === null || _f === void 0 ? void 0 : _f.uid) !== null && _g !== void 0 ? _g : '',
|
|
39
|
+
omName: (_j = (_h = node.bipOwnershipModel) === null || _h === void 0 ? void 0 : _h.omName) !== null && _j !== void 0 ? _j : '',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
if (!plans.length)
|
|
44
|
+
throw new Error('No billing plans found.');
|
|
45
|
+
return { plans };
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=fetchBillingPlans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchBillingPlans.js","sourceRoot":"","sources":["../../src/utils/fetchBillingPlans.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;GAGG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9C,MAAM,UAAgB,iBAAiB,CAAC,MAAc;;;QACpD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE;YAC9B,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;SACnD,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QAE9E,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,IAAI,MAAA,IAAI,CAAC,MAAM,0CAAE,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,CAAA,MAAA,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,0CAAE,OAAO,KAAI,eAAe,CAAC,CAAC;QAErF,MAAM,KAAK,GAQL,MAAA,MAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,yBAAyB,0CAAE,KAAK,mCAAI,EAAE,CAAC;QAExD,MAAM,KAAK,GAAkB,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;;YAAC,OAAA,CAAC;gBACpD,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,aAAa,EAAE,IAAI,CAAC,cAAc;gBAClC,MAAM,EAAE,MAAA,MAAA,IAAI,CAAC,aAAa,0CAAE,MAAM,mCAAI,GAAG;gBACzC,QAAQ,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,aAAa,0CAAE,KAAK,0CAAE,IAAI,mCAAI,KAAK;gBAClD,UAAU,EAAE,IAAI,CAAC,aAAa;gBAC9B,cAAc,EAAE;oBACd,GAAG,EAAE,MAAA,MAAA,IAAI,CAAC,iBAAiB,0CAAE,GAAG,mCAAI,EAAE;oBACtC,MAAM,EAAE,MAAA,MAAA,IAAI,CAAC,iBAAiB,0CAAE,MAAM,mCAAI,EAAE;iBAC7C;aACF,CAAC,CAAA;SAAA,CAAC,CAAC;QAEJ,IAAI,CAAC,KAAK,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC9D,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;CAAA","sourcesContent":["/**\n * api/billingPlans.ts — fetch billing plans without authentication.\n * Called on component mount to show prices before the user clicks Place order.\n */\nimport { GET_BILLING_PLANS } from './queries';\nimport type { BillingPlan, BillingPlansResult } from '../types';\n\nexport async function fetchBillingPlans(apiUrl: string): Promise<BillingPlansResult> {\n const res = await fetch(apiUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ query: GET_BILLING_PLANS }),\n });\n\n if (!res.ok) throw new Error(`Failed to fetch billing plans (${res.status})`);\n\n const json = await res.json();\n if (json.errors?.length) throw new Error(json.errors[0]?.message || 'GraphQL error');\n\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 }[] = json.data?.filterCustomerBillingPlan?.edges ?? [];\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 if (!plans.length) throw new Error('No billing plans found.');\n return { plans };\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api/graphqlClient.ts — authed GraphQL client.
|
|
3
|
+
*
|
|
4
|
+
* No token is required at construction. Call setToken(viaxToken) after
|
|
5
|
+
* GET /edx-session returns — typically on checkout page mount.
|
|
6
|
+
*
|
|
7
|
+
* On 401 the token is cleared and the request fails — the mutation will
|
|
8
|
+
* surface the error and the user can retry.
|
|
9
|
+
*/
|
|
10
|
+
import type { GqlRunner } from '../types';
|
|
11
|
+
export declare function createGqlClient({ apiUrl }: {
|
|
12
|
+
apiUrl: string;
|
|
13
|
+
}): {
|
|
14
|
+
gql: GqlRunner;
|
|
15
|
+
setToken: (token: string) => void;
|
|
16
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export function createGqlClient({ apiUrl }) {
|
|
11
|
+
if (!apiUrl)
|
|
12
|
+
throw new Error('createGqlClient: apiUrl is required');
|
|
13
|
+
let token = null;
|
|
14
|
+
const setToken = (raw) => {
|
|
15
|
+
token = raw.startsWith('Bearer ') ? raw : `Bearer ${raw}`;
|
|
16
|
+
};
|
|
17
|
+
const gql = (query_1, variables_1, ...args_1) => __awaiter(this, [query_1, variables_1, ...args_1], void 0, function* (query, variables, retry = false) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
if (!token)
|
|
20
|
+
throw new Error('No viax token available. Please try placing your order again.');
|
|
21
|
+
const res = yield fetch(apiUrl, {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
headers: { 'Content-Type': 'application/json', Authorization: token },
|
|
24
|
+
body: JSON.stringify({ query, variables }),
|
|
25
|
+
});
|
|
26
|
+
if (res.status === 401 && !retry) {
|
|
27
|
+
token = null;
|
|
28
|
+
throw new Error('Session expired. Please try placing your order again.');
|
|
29
|
+
}
|
|
30
|
+
const json = yield res.json();
|
|
31
|
+
if ((_a = json.errors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
32
|
+
const msg = ((_b = json.errors[0]) === null || _b === void 0 ? void 0 : _b.message) || 'GraphQL error';
|
|
33
|
+
throw new Error(msg);
|
|
34
|
+
}
|
|
35
|
+
return json.data;
|
|
36
|
+
});
|
|
37
|
+
return { gql, setToken };
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=graphqlClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphqlClient.js","sourceRoot":"","sources":["../../src/utils/graphqlClient.ts"],"names":[],"mappings":";;;;;;;;;AAiBA,MAAM,UAAU,eAAe,CAC7B,EAAE,MAAM,EAAsB;IAE9B,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAEpE,IAAI,KAAK,GAAkB,IAAI,CAAC;IAEhC,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAQ,EAAE;QACrC,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,EAAE,CAAC;IAC5D,CAAC,CAAC;IAEF,MAAM,GAAG,GAAc,kCAAwC,EAAE,uEAAnC,KAAK,EAAE,SAAS,EAAE,KAAK,GAAG,KAAK;;QAC3D,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;QAE7F,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE;YAC9B,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,KAAK,EAAE;YACrE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;SAC3C,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YACjC,KAAK,GAAG,IAAI,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC3E,CAAC;QAED,MAAM,IAAI,GAAgB,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC3C,IAAI,MAAA,IAAI,CAAC,MAAM,0CAAE,MAAM,EAAE,CAAC;YACxB,MAAM,GAAG,GAAG,CAAA,MAAA,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,0CAAE,OAAO,KAAI,eAAe,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC,CAAA,CAAC;IAEF,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * api/graphqlClient.ts — authed GraphQL client.\n *\n * No token is required at construction. Call setToken(viaxToken) after\n * GET /edx-session returns — typically on checkout page mount.\n *\n * On 401 the token is cleared and the request fails — the mutation will\n * surface the error and the user can retry.\n */\nimport type { GqlRunner } from '../types';\n\ninterface GqlResponse {\n\n data?: any,\n errors?: { message?: string }[],\n}\n\nexport function createGqlClient(\n { apiUrl }: { apiUrl: string },\n): { gql: GqlRunner, setToken: (token: string) => void } {\n if (!apiUrl) throw new Error('createGqlClient: apiUrl is required');\n\n let token: string | null = null;\n\n const setToken = (raw: string): void => {\n token = raw.startsWith('Bearer ') ? raw : `Bearer ${raw}`;\n };\n\n const gql: GqlRunner = async (query, variables, retry = false) => {\n if (!token) throw new Error('No viax token available. Please try placing your order again.');\n\n const res = await fetch(apiUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', Authorization: token },\n body: JSON.stringify({ query, variables }),\n });\n\n if (res.status === 401 && !retry) {\n token = null;\n throw new Error('Session expired. Please try placing your order again.');\n }\n\n const json: GqlResponse = await res.json();\n if (json.errors?.length) {\n const msg = json.errors[0]?.message || 'GraphQL error';\n throw new Error(msg);\n }\n return json.data;\n };\n\n return { gql, setToken };\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function formatTrialDate(date) {
|
|
2
|
+
return date.toLocaleDateString('en-US', {
|
|
3
|
+
month: 'long',
|
|
4
|
+
day: 'numeric',
|
|
5
|
+
year: 'numeric',
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export function getTrialDateRange(trialStart, trialEnd, trialDays = 7) {
|
|
9
|
+
const today = new Date();
|
|
10
|
+
const endDate = new Date(today);
|
|
11
|
+
endDate.setDate(today.getDate() + trialDays);
|
|
12
|
+
return {
|
|
13
|
+
displayStart: trialStart !== null && trialStart !== void 0 ? trialStart : formatTrialDate(today),
|
|
14
|
+
displayEnd: trialEnd !== null && trialEnd !== void 0 ? trialEnd : formatTrialDate(endDate),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,IAAU;IACxC,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE;QACtC,KAAK,EAAE,MAAM;QACb,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;KAChB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,UAA0B,EAC1B,QAAwB,EACxB,SAAS,GAAG,CAAC;IAEb,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;IACzB,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC;IAE7C,OAAO;QACL,YAAY,EAAE,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,eAAe,CAAC,KAAK,CAAC;QAClD,UAAU,EAAE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,eAAe,CAAC,OAAO,CAAC;KACjD,CAAC;AACJ,CAAC","sourcesContent":["import { TrialDateRange } from '@src/types';\n\nexport function formatTrialDate(date: Date): string {\n return date.toLocaleDateString('en-US', {\n month: 'long',\n day: 'numeric',\n year: 'numeric',\n });\n}\n\nexport function getTrialDateRange(\n trialStart?: string | null,\n trialEnd?: string | null,\n trialDays = 7,\n): TrialDateRange {\n const today = new Date();\n const endDate = new Date(today);\n endDate.setDate(today.getDate() + trialDays);\n\n return {\n displayStart: trialStart ?? formatTrialDate(today),\n displayEnd: trialEnd ?? formatTrialDate(endDate),\n };\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api/provision.ts — exchange the edX session for a viax token.
|
|
3
|
+
*
|
|
4
|
+
* {LMS_BASE_URL}/api/edx-session
|
|
5
|
+
* The LMS reads the edX JWT from browser cookies, exchanges it with viax,
|
|
6
|
+
* and returns a per-user token for authenticated API calls.
|
|
7
|
+
*
|
|
8
|
+
* Dev uses POST with a hardcoded JWT payload (local LMS cookie exchange is
|
|
9
|
+
* unavailable). Stage and prod use GET and rely on the browser session cookies.
|
|
10
|
+
*/
|
|
11
|
+
export interface EdxSessionResult {
|
|
12
|
+
viaxToken: string;
|
|
13
|
+
customerUid: string;
|
|
14
|
+
partyUid?: string;
|
|
15
|
+
edxUserId?: string;
|
|
16
|
+
username?: string;
|
|
17
|
+
email?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fetch the ISO 3166-1 alpha-2 country code from the user's edX account profile.
|
|
21
|
+
* Returns null if the request fails or the field is absent.
|
|
22
|
+
*/
|
|
23
|
+
export declare function fetchUserCountry(lmsBaseUrl: string, username: string): Promise<string | null>;
|
|
24
|
+
/** Exchange the learner's edX session (cookies) for a viax token. */
|
|
25
|
+
export declare function fetchEdxSession(sessionUrl: string): Promise<EdxSessionResult>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api/provision.ts — exchange the edX session for a viax token.
|
|
3
|
+
*
|
|
4
|
+
* {LMS_BASE_URL}/api/edx-session
|
|
5
|
+
* The LMS reads the edX JWT from browser cookies, exchanges it with viax,
|
|
6
|
+
* and returns a per-user token for authenticated API calls.
|
|
7
|
+
*
|
|
8
|
+
* Dev uses POST with a hardcoded JWT payload (local LMS cookie exchange is
|
|
9
|
+
* unavailable). Stage and prod use GET and rely on the browser session cookies.
|
|
10
|
+
*/
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
import { EnvironmentTypes, getSiteConfig } from '@openedx/frontend-base';
|
|
21
|
+
/** Hardcoded edX JWT used only for local/dev checkout against stage Viax. */
|
|
22
|
+
const DEV_SESSION_BODY = {
|
|
23
|
+
payload: 'eyJhbGciOiJSUzUxMiIsImtpZCI6Imxtc3N0YWdlMDAyIiwidHlwIjoiSldUIn0.eyJhdWQiOiJJbmtvY3VqTGlreXVjc0Vkd2lXYXRkZWJyRWFja21ldkxha0R1aWZLb29zaGtha1dvdyIsImV4cCI6MTc4NTQzNzY5OSwiZ3JhbnRfdHlwZSI6InBhc3N3b3JkIiwiaWF0IjoxNzg1NDM0MDk5LCJpc3MiOiJodHRwczovL2NvdXJzZXMuc3RhZ2UuZWR4Lm9yZy9vYXV0aDIiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJhZGV2Z2FuLXk2aDgiLCJzY29wZXMiOlsidXNlcl9pZCIsImVtYWlsIiwicHJvZmlsZSJdLCJ2ZXJzaW9uIjoiMS4yLjAiLCJzdWIiOiI1YmNkYWJiZmQ2N2RhYmQ4NGRiZDg5MTg1MGJlNjI4MiIsImZpbHRlcnMiOlsidXNlcjptZSJdLCJpc19yZXN0cmljdGVkIjpmYWxzZSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ1c2VyX2lkIjo1Mjg0NTIwLCJlbWFpbCI6ImFkZXZnYW5AdmlheC5pbyIsIm5hbWUiOiJBa2FzaCBEZXZnYW4iLCJmYW1pbHlfbmFtZSI6IkRldmdhbiIsImdpdmVuX25hbWUiOiJBa2FzaCIsImFkbWluaXN0cmF0b3IiOmZhbHNlLCJzdXBlcnVzZXIiOmZhbHNlfQ',
|
|
24
|
+
signature: 'WmF18TMf3ai8ioG2JWXMHfBZZyCrdqPBHAA_zuXKGJwn1v4pu7mLJdDO16jSxnj-a8wseQQQacOEveZxCBV0C28HGvGpN1Fp80hX86IJOETdSZbGEOSBQpjLzpyTcgG14Mg80oS3qf30Z7NMSuOGak9qYDtp3Bouf_K-Y4-y5ZLDTKjKeirXAoCKkvGKESVBaaNtuXk8hv5mQ0oEDqZ0cFDFAHZE_zvXcMZoAuezBwwWlP0W60RWS70OtYaatmqraQ18WeM6UqG7ZYMTHX7nNJER5MsAyfB0HvwuLFbfnW6PggTxgTE8i4A5vvK_nduP_URB9Em7o2Gtm1pP4fxJJA'
|
|
25
|
+
};
|
|
26
|
+
function parseSessionResponse(data) {
|
|
27
|
+
var _a, _b, _c, _d;
|
|
28
|
+
const viaxToken = ((_c = (_b = (_a = data.viaxToken) !== null && _a !== void 0 ? _a : data.token) !== null && _b !== void 0 ? _b : data.access_token) !== null && _c !== void 0 ? _c : data.accessToken);
|
|
29
|
+
const customerUid = ((_d = data.customerUid) !== null && _d !== void 0 ? _d : data.customer_uid);
|
|
30
|
+
if (!viaxToken)
|
|
31
|
+
throw new Error('Session response missing viax token.');
|
|
32
|
+
if (!customerUid)
|
|
33
|
+
throw new Error('Session response missing customerUid.');
|
|
34
|
+
return {
|
|
35
|
+
viaxToken,
|
|
36
|
+
customerUid,
|
|
37
|
+
partyUid: data.partyUid,
|
|
38
|
+
edxUserId: data.edxUserId,
|
|
39
|
+
username: data.username,
|
|
40
|
+
email: data.email,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Fetch the ISO 3166-1 alpha-2 country code from the user's edX account profile.
|
|
45
|
+
* Returns null if the request fails or the field is absent.
|
|
46
|
+
*/
|
|
47
|
+
export function fetchUserCountry(lmsBaseUrl, username) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
try {
|
|
50
|
+
const res = yield fetch(`${lmsBaseUrl}/api/user/v1/accounts/${encodeURIComponent(username)}`, {
|
|
51
|
+
credentials: 'include',
|
|
52
|
+
});
|
|
53
|
+
if (!res.ok)
|
|
54
|
+
return null;
|
|
55
|
+
const data = yield res.json();
|
|
56
|
+
return typeof data.country === 'string' && data.country ? data.country : null;
|
|
57
|
+
}
|
|
58
|
+
catch (_a) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function isDevelopment() {
|
|
64
|
+
return getSiteConfig().environment === EnvironmentTypes.DEVELOPMENT;
|
|
65
|
+
}
|
|
66
|
+
/** Exchange the learner's edX session (cookies) for a viax token. */
|
|
67
|
+
export function fetchEdxSession(sessionUrl) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const headers = { Accept: 'application/json' };
|
|
70
|
+
let res;
|
|
71
|
+
if (isDevelopment()) {
|
|
72
|
+
res = yield fetch(sessionUrl, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
credentials: 'include',
|
|
75
|
+
headers: Object.assign(Object.assign({}, headers), { 'Content-Type': 'application/json' }),
|
|
76
|
+
body: JSON.stringify(DEV_SESSION_BODY),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
res = yield fetch(sessionUrl, {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
credentials: 'include',
|
|
83
|
+
headers,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (!res.ok) {
|
|
87
|
+
throw new Error(`Failed to establish checkout session (${res.status}). Please log into edX and try again.`);
|
|
88
|
+
}
|
|
89
|
+
const data = yield res.json();
|
|
90
|
+
if (data.error)
|
|
91
|
+
throw new Error(String(data.error));
|
|
92
|
+
return parseSessionResponse(data);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=provision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision.js","sourceRoot":"","sources":["../../src/utils/provision.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;;;;;;;;;;AAEH,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAWzE,6EAA6E;AAC7E,MAAM,gBAAgB,GAAG;IACvB,OAAO,EAAE,gvBAAgvB;IACzvB,SAAS,EAAE,wVAAwV;CACpW,CAAC;AACF,SAAS,oBAAoB,CAAC,IAA6B;;IACzD,MAAM,SAAS,GAAG,CAChB,MAAA,MAAA,MAAA,IAAI,CAAC,SAAS,mCAAI,IAAI,CAAC,KAAK,mCAAI,IAAI,CAAC,YAAY,mCAAI,IAAI,CAAC,WAAW,CAChD,CAAC;IACxB,MAAM,WAAW,GAAG,CAAC,MAAA,IAAI,CAAC,WAAW,mCAAI,IAAI,CAAC,YAAY,CAAuB,CAAC;IAElF,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACxE,IAAI,CAAC,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAE3E,OAAO;QACL,SAAS;QACT,WAAW;QACX,QAAQ,EAAE,IAAI,CAAC,QAA8B;QAC7C,SAAS,EAAE,IAAI,CAAC,SAA+B;QAC/C,QAAQ,EAAE,IAAI,CAAC,QAA8B;QAC7C,KAAK,EAAE,IAAI,CAAC,KAA2B;KACxC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAgB,gBAAgB,CAAC,UAAkB,EAAE,QAAgB;;QACzE,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,UAAU,yBAAyB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,EAAE;gBAC5F,WAAW,EAAE,SAAS;aACvB,CAAC,CAAC;YACH,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,OAAO,IAAI,CAAC;YACzB,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAA6B,CAAC;YACzD,OAAO,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;QAChF,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CAAA;AAED,SAAS,aAAa;IACpB,OAAO,aAAa,EAAE,CAAC,WAAW,KAAK,gBAAgB,CAAC,WAAW,CAAC;AACtE,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAgB,eAAe,CAAC,UAAkB;;QACtD,MAAM,OAAO,GAA2B,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;QAEvE,IAAI,GAAa,CAAC;QAClB,IAAI,aAAa,EAAE,EAAE,CAAC;YACpB,GAAG,GAAG,MAAM,KAAK,CAAC,UAAU,EAAE;gBAC5B,MAAM,EAAE,MAAM;gBACd,WAAW,EAAE,SAAS;gBACtB,OAAO,kCACF,OAAO,KACV,cAAc,EAAE,kBAAkB,GACnC;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;aACvC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,MAAM,KAAK,CAAC,UAAU,EAAE;gBAC5B,MAAM,EAAE,MAAM;gBACd,WAAW,EAAE,SAAS;gBACtB,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACb,yCAAyC,GAAG,CAAC,MAAM,uCAAuC,CAC3F,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAkD,CAAC;QAC9E,IAAI,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAEpD,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CAAA","sourcesContent":["/**\n * api/provision.ts — exchange the edX session for a viax token.\n *\n * {LMS_BASE_URL}/api/edx-session\n * The LMS reads the edX JWT from browser cookies, exchanges it with viax,\n * and returns a per-user token for authenticated API calls.\n *\n * Dev uses POST with a hardcoded JWT payload (local LMS cookie exchange is\n * unavailable). Stage and prod use GET and rely on the browser session cookies.\n */\n\nimport { EnvironmentTypes, getSiteConfig } from '@openedx/frontend-base';\n\nexport interface EdxSessionResult {\n viaxToken: string, // raw JWT — add 'Bearer ' prefix before use\n customerUid: string,\n partyUid?: string,\n edxUserId?: string,\n username?: string,\n email?: string,\n}\n\n/** Hardcoded edX JWT used only for local/dev checkout against stage Viax. */\nconst DEV_SESSION_BODY = {\n payload: 'eyJhbGciOiJSUzUxMiIsImtpZCI6Imxtc3N0YWdlMDAyIiwidHlwIjoiSldUIn0.eyJhdWQiOiJJbmtvY3VqTGlreXVjc0Vkd2lXYXRkZWJyRWFja21ldkxha0R1aWZLb29zaGtha1dvdyIsImV4cCI6MTc4NTQzNzY5OSwiZ3JhbnRfdHlwZSI6InBhc3N3b3JkIiwiaWF0IjoxNzg1NDM0MDk5LCJpc3MiOiJodHRwczovL2NvdXJzZXMuc3RhZ2UuZWR4Lm9yZy9vYXV0aDIiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJhZGV2Z2FuLXk2aDgiLCJzY29wZXMiOlsidXNlcl9pZCIsImVtYWlsIiwicHJvZmlsZSJdLCJ2ZXJzaW9uIjoiMS4yLjAiLCJzdWIiOiI1YmNkYWJiZmQ2N2RhYmQ4NGRiZDg5MTg1MGJlNjI4MiIsImZpbHRlcnMiOlsidXNlcjptZSJdLCJpc19yZXN0cmljdGVkIjpmYWxzZSwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ1c2VyX2lkIjo1Mjg0NTIwLCJlbWFpbCI6ImFkZXZnYW5AdmlheC5pbyIsIm5hbWUiOiJBa2FzaCBEZXZnYW4iLCJmYW1pbHlfbmFtZSI6IkRldmdhbiIsImdpdmVuX25hbWUiOiJBa2FzaCIsImFkbWluaXN0cmF0b3IiOmZhbHNlLCJzdXBlcnVzZXIiOmZhbHNlfQ',\n signature: 'WmF18TMf3ai8ioG2JWXMHfBZZyCrdqPBHAA_zuXKGJwn1v4pu7mLJdDO16jSxnj-a8wseQQQacOEveZxCBV0C28HGvGpN1Fp80hX86IJOETdSZbGEOSBQpjLzpyTcgG14Mg80oS3qf30Z7NMSuOGak9qYDtp3Bouf_K-Y4-y5ZLDTKjKeirXAoCKkvGKESVBaaNtuXk8hv5mQ0oEDqZ0cFDFAHZE_zvXcMZoAuezBwwWlP0W60RWS70OtYaatmqraQ18WeM6UqG7ZYMTHX7nNJER5MsAyfB0HvwuLFbfnW6PggTxgTE8i4A5vvK_nduP_URB9Em7o2Gtm1pP4fxJJA'\n};\nfunction parseSessionResponse(data: Record<string, unknown>): EdxSessionResult {\n const viaxToken = (\n data.viaxToken ?? data.token ?? data.access_token ?? data.accessToken\n ) as string | undefined;\n const customerUid = (data.customerUid ?? data.customer_uid) as string | undefined;\n\n if (!viaxToken) throw new Error('Session response missing viax token.');\n if (!customerUid) throw new Error('Session response missing customerUid.');\n\n return {\n viaxToken,\n customerUid,\n partyUid: data.partyUid as string | undefined,\n edxUserId: data.edxUserId as string | undefined,\n username: data.username as string | undefined,\n email: data.email as string | undefined,\n };\n}\n\n/**\n * Fetch the ISO 3166-1 alpha-2 country code from the user's edX account profile.\n * Returns null if the request fails or the field is absent.\n */\nexport async function fetchUserCountry(lmsBaseUrl: string, username: string): Promise<string | null> {\n try {\n const res = await fetch(`${lmsBaseUrl}/api/user/v1/accounts/${encodeURIComponent(username)}`, {\n credentials: 'include',\n });\n if (!res.ok) return null;\n const data = await res.json() as Record<string, unknown>;\n return typeof data.country === 'string' && data.country ? data.country : null;\n } catch {\n return null;\n }\n}\n\nfunction isDevelopment(): boolean {\n return getSiteConfig().environment === EnvironmentTypes.DEVELOPMENT;\n}\n\n/** Exchange the learner's edX session (cookies) for a viax token. */\nexport async function fetchEdxSession(sessionUrl: string): Promise<EdxSessionResult> {\n const headers: Record<string, string> = { Accept: 'application/json' };\n\n let res: Response;\n if (isDevelopment()) {\n res = await fetch(sessionUrl, {\n method: 'POST',\n credentials: 'include',\n headers: {\n ...headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(DEV_SESSION_BODY),\n });\n } else {\n res = await fetch(sessionUrl, {\n method: 'POST',\n credentials: 'include',\n headers,\n });\n }\n\n if (!res.ok) {\n throw new Error(\n `Failed to establish checkout session (${res.status}). Please log into edX and try again.`,\n );\n }\n\n const data = await res.json() as Record<string, unknown> & { error?: string };\n if (data.error) throw new Error(String(data.error));\n\n return parseSessionResponse(data);\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api/queries.ts — GraphQL documents for the checkout flow.
|
|
3
|
+
* Kept as plain strings so they can be reused, logged, or tested in isolation.
|
|
4
|
+
*
|
|
5
|
+
* Mutation reference (from API doc):
|
|
6
|
+
* updateTwouCustomer — toggle Stripe test clock on/off
|
|
7
|
+
* createTwouCart — user proceeds to payment
|
|
8
|
+
* updateTwouCartItem — attach billing plan / payment method to cart
|
|
9
|
+
* updateTwouCart — persist auto-renewal consent (SUBS-228)
|
|
10
|
+
* startBusinessProcessableTransition — place order
|
|
11
|
+
* updateTwouCartItem — retry: attach new payment method
|
|
12
|
+
*/
|
|
13
|
+
/** Creates a new cart during checkout. */
|
|
14
|
+
export declare const CREATE_CART = "mutation CreateCart($input: TwouCartInput!) {\n createTwouCart(input: $input) { biId uid }\n}";
|
|
15
|
+
/** Updates a cart item — attach billing plan / payment method. */
|
|
16
|
+
export declare const UPDATE_CART_ITEM = "mutation UpdateCartItem($input: TwouCartItemInput!) {\n updateTwouCartItem(input: $input) { uid }\n}";
|
|
17
|
+
/** Persists auto-renewal consent fields on the TwouCart BI (SUBS-228). */
|
|
18
|
+
export declare const UPDATE_CART = "mutation UpdateCart($input: TwouCartInput!) {\n updateTwouCart(input: $input) { uid }\n}";
|
|
19
|
+
/** Triggers the backend workflow to place the order. */
|
|
20
|
+
export declare const PLACE_ORDER = "mutation PlaceOrder($input: StartBusinessProcessableTransitionInput!) {\n startBusinessProcessableTransition(input: $input) { uid bpStatus { code } }\n}";
|
|
21
|
+
export declare const GET_CART_ITEM = "query GetCartItem($biId: String!) {\n getBusinessInteraction(biId: $biId) {\n uid\n hiConsistsOf { ... on TwouCartItem { uid } }\n }\n}";
|
|
22
|
+
export declare const GET_CART_STATUS = "query GetCartStatus($biId: String!) {\n getBusinessInteraction(biId: $biId) {\n bpStatus { code }\n hiConsistsOf { ... on TwouCartItem { tStripeSubscriptionId } }\n ... on TwouCart {\n cmComments { edges { node { comText } } }\n }\n }\n}";
|
|
23
|
+
export declare const FIND_SUBSCRIPTION = "query FindSubscription($filter: String!) {\n filterTwouSubscription(_first: 1, _filter: $filter) {\n edges {\n node {\n biId\n tTrialStart\n tTrialEnd\n tRenewalType\n hiConsistsOf {\n ... on TwouSubscriptionItem {\n paybBillingPlan {\n tStripePriceId\n bipOwnershipModel { omName }\n }\n paybPayment {\n ... on TwouStripePayment {\n tStripePaymentMethodId\n tPaymentMethodLast4\n tPaymentMethodBrand\n }\n }\n }\n }\n }\n }\n }\n}";
|
|
24
|
+
/** Fetch the viax customer uid by email using filterTwouCustomer. */
|
|
25
|
+
export declare const GET_CUSTOMER = "query GetCustomer($filter: String!) {\n filterTwouCustomer(_first: 1, _filter: $filter) {\n edges {\n node {\n uid\n parId\n parParty {\n paName\n paContacts {\n edges {\n node {\n ... on EmailAddressContactMedium {\n email\n }\n }\n }\n }\n ... on Individual {\n indFirstName\n indLastName\n }\n }\n }\n }\n }\n}";
|
|
26
|
+
/** Fetch the TwouSubscriptionPlan uid to use as biiSalable in createTwouCart. */
|
|
27
|
+
export declare const GET_PRODUCT = "query GetProduct($maId: String!) {\n getProduct(maId: $maId) {\n maName\n uid\n ... on TwouSubscriptionPlan {\n saOwnershipModels {\n uid\n omName\n }\n }\n }\n}";
|
|
28
|
+
export declare const GET_BILLING_PLANS = "query GetBillingPlans {\n filterCustomerBillingPlan(_first: 10) {\n edges {\n node {\n uid\n tStripePriceId\n tStripeAmount {\n amount\n units { code }\n }\n bipIsTemplate\n bipOwnershipModel { uid omName }\n }\n }\n }\n}";
|
|
29
|
+
/** Fetch the number of active subscriptions — unauthenticated. */
|
|
30
|
+
export declare const GET_ACTIVE_SUBSCRIPTIONS_STATE = "query activeSubscriptions {\n tActiveSubscriptionsState\n}";
|
|
31
|
+
/** Check whether the currently authenticated user already has an active subscription.
|
|
32
|
+
* tIsCurrentUserSubscriber is a JSON scalar — returns the full object, no subfield selection allowed. */
|
|
33
|
+
export declare const GET_IS_CURRENT_USER_SUBSCRIBER = "query IsCurrentUserSubscriber {\n tIsCurrentUserSubscriber\n}";
|
|
34
|
+
/** Fetch a course for the enrollment card when ?course_run_key= is present. */
|
|
35
|
+
export declare const GET_COURSE_DETAIL = "query CourseDetail($filter: String!) {\n filterTwouCourse(_first: 1, _filter: $filter) {\n edges {\n node {\n maId\n maName\n maDescription\n tShortDescription\n imageUrl\n tCourseKey\n tBrandText\n tPrimarySubjectArea\n tLevelType\n tLanguage\n tPacingType { code }\n tDurationLow\n tDurationHigh\n tDurationUnit { code }\n tEffortLow\n tEffortHigh\n tEffortUnit { code }\n tUrlCourse\n tB2cSubscriptionInclusion\n tHasOfacRestrictions\n tCatalogActive\n }\n }\n }\n}";
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api/queries.ts — GraphQL documents for the checkout flow.
|
|
3
|
+
* Kept as plain strings so they can be reused, logged, or tested in isolation.
|
|
4
|
+
*
|
|
5
|
+
* Mutation reference (from API doc):
|
|
6
|
+
* updateTwouCustomer — toggle Stripe test clock on/off
|
|
7
|
+
* createTwouCart — user proceeds to payment
|
|
8
|
+
* updateTwouCartItem — attach billing plan / payment method to cart
|
|
9
|
+
* updateTwouCart — persist auto-renewal consent (SUBS-228)
|
|
10
|
+
* startBusinessProcessableTransition — place order
|
|
11
|
+
* updateTwouCartItem — retry: attach new payment method
|
|
12
|
+
*/
|
|
13
|
+
// ─── Mutations ────────────────────────────────────────────────────────────────
|
|
14
|
+
/** Creates a new cart during checkout. */
|
|
15
|
+
export const CREATE_CART = `mutation CreateCart($input: TwouCartInput!) {
|
|
16
|
+
createTwouCart(input: $input) { biId uid }
|
|
17
|
+
}`;
|
|
18
|
+
/** Updates a cart item — attach billing plan / payment method. */
|
|
19
|
+
export const UPDATE_CART_ITEM = `mutation UpdateCartItem($input: TwouCartItemInput!) {
|
|
20
|
+
updateTwouCartItem(input: $input) { uid }
|
|
21
|
+
}`;
|
|
22
|
+
/** Persists auto-renewal consent fields on the TwouCart BI (SUBS-228). */
|
|
23
|
+
export const UPDATE_CART = `mutation UpdateCart($input: TwouCartInput!) {
|
|
24
|
+
updateTwouCart(input: $input) { uid }
|
|
25
|
+
}`;
|
|
26
|
+
/** Triggers the backend workflow to place the order. */
|
|
27
|
+
export const PLACE_ORDER = `mutation PlaceOrder($input: StartBusinessProcessableTransitionInput!) {
|
|
28
|
+
startBusinessProcessableTransition(input: $input) { uid bpStatus { code } }
|
|
29
|
+
}`;
|
|
30
|
+
// ─── Queries ──────────────────────────────────────────────────────────────────
|
|
31
|
+
export const GET_CART_ITEM = `query GetCartItem($biId: String!) {
|
|
32
|
+
getBusinessInteraction(biId: $biId) {
|
|
33
|
+
uid
|
|
34
|
+
hiConsistsOf { ... on TwouCartItem { uid } }
|
|
35
|
+
}
|
|
36
|
+
}`;
|
|
37
|
+
export const GET_CART_STATUS = `query GetCartStatus($biId: String!) {
|
|
38
|
+
getBusinessInteraction(biId: $biId) {
|
|
39
|
+
bpStatus { code }
|
|
40
|
+
hiConsistsOf { ... on TwouCartItem { tStripeSubscriptionId } }
|
|
41
|
+
... on TwouCart {
|
|
42
|
+
cmComments { edges { node { comText } } }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}`;
|
|
46
|
+
export const FIND_SUBSCRIPTION = `query FindSubscription($filter: String!) {
|
|
47
|
+
filterTwouSubscription(_first: 1, _filter: $filter) {
|
|
48
|
+
edges {
|
|
49
|
+
node {
|
|
50
|
+
biId
|
|
51
|
+
tTrialStart
|
|
52
|
+
tTrialEnd
|
|
53
|
+
tRenewalType
|
|
54
|
+
hiConsistsOf {
|
|
55
|
+
... on TwouSubscriptionItem {
|
|
56
|
+
paybBillingPlan {
|
|
57
|
+
tStripePriceId
|
|
58
|
+
bipOwnershipModel { omName }
|
|
59
|
+
}
|
|
60
|
+
paybPayment {
|
|
61
|
+
... on TwouStripePayment {
|
|
62
|
+
tStripePaymentMethodId
|
|
63
|
+
tPaymentMethodLast4
|
|
64
|
+
tPaymentMethodBrand
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}`;
|
|
73
|
+
/** Fetch the viax customer uid by email using filterTwouCustomer. */
|
|
74
|
+
export const GET_CUSTOMER = `query GetCustomer($filter: String!) {
|
|
75
|
+
filterTwouCustomer(_first: 1, _filter: $filter) {
|
|
76
|
+
edges {
|
|
77
|
+
node {
|
|
78
|
+
uid
|
|
79
|
+
parId
|
|
80
|
+
parParty {
|
|
81
|
+
paName
|
|
82
|
+
paContacts {
|
|
83
|
+
edges {
|
|
84
|
+
node {
|
|
85
|
+
... on EmailAddressContactMedium {
|
|
86
|
+
email
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
... on Individual {
|
|
92
|
+
indFirstName
|
|
93
|
+
indLastName
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}`;
|
|
100
|
+
/** Fetch the TwouSubscriptionPlan uid to use as biiSalable in createTwouCart. */
|
|
101
|
+
export const GET_PRODUCT = `query GetProduct($maId: String!) {
|
|
102
|
+
getProduct(maId: $maId) {
|
|
103
|
+
maName
|
|
104
|
+
uid
|
|
105
|
+
... on TwouSubscriptionPlan {
|
|
106
|
+
saOwnershipModels {
|
|
107
|
+
uid
|
|
108
|
+
omName
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}`;
|
|
113
|
+
export const GET_BILLING_PLANS = `query GetBillingPlans {
|
|
114
|
+
filterCustomerBillingPlan(_first: 10) {
|
|
115
|
+
edges {
|
|
116
|
+
node {
|
|
117
|
+
uid
|
|
118
|
+
tStripePriceId
|
|
119
|
+
tStripeAmount {
|
|
120
|
+
amount
|
|
121
|
+
units { code }
|
|
122
|
+
}
|
|
123
|
+
bipIsTemplate
|
|
124
|
+
bipOwnershipModel { uid omName }
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}`;
|
|
129
|
+
/** Fetch the number of active subscriptions — unauthenticated. */
|
|
130
|
+
export const GET_ACTIVE_SUBSCRIPTIONS_STATE = `query activeSubscriptions {
|
|
131
|
+
tActiveSubscriptionsState
|
|
132
|
+
}`;
|
|
133
|
+
/** Check whether the currently authenticated user already has an active subscription.
|
|
134
|
+
* tIsCurrentUserSubscriber is a JSON scalar — returns the full object, no subfield selection allowed. */
|
|
135
|
+
export const GET_IS_CURRENT_USER_SUBSCRIBER = `query IsCurrentUserSubscriber {
|
|
136
|
+
tIsCurrentUserSubscriber
|
|
137
|
+
}`;
|
|
138
|
+
/** Fetch a course for the enrollment card when ?course_run_key= is present. */
|
|
139
|
+
export const GET_COURSE_DETAIL = `query CourseDetail($filter: String!) {
|
|
140
|
+
filterTwouCourse(_first: 1, _filter: $filter) {
|
|
141
|
+
edges {
|
|
142
|
+
node {
|
|
143
|
+
maId
|
|
144
|
+
maName
|
|
145
|
+
maDescription
|
|
146
|
+
tShortDescription
|
|
147
|
+
imageUrl
|
|
148
|
+
tCourseKey
|
|
149
|
+
tBrandText
|
|
150
|
+
tPrimarySubjectArea
|
|
151
|
+
tLevelType
|
|
152
|
+
tLanguage
|
|
153
|
+
tPacingType { code }
|
|
154
|
+
tDurationLow
|
|
155
|
+
tDurationHigh
|
|
156
|
+
tDurationUnit { code }
|
|
157
|
+
tEffortLow
|
|
158
|
+
tEffortHigh
|
|
159
|
+
tEffortUnit { code }
|
|
160
|
+
tUrlCourse
|
|
161
|
+
tB2cSubscriptionInclusion
|
|
162
|
+
tHasOfacRestrictions
|
|
163
|
+
tCatalogActive
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}`;
|
|
168
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/utils/queries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,iFAAiF;AAEjF,0CAA0C;AAC1C,MAAM,CAAC,MAAM,WAAW,GAAG;;EAEzB,CAAC;AAEH,kEAAkE;AAClE,MAAM,CAAC,MAAM,gBAAgB,GAAG;;EAE9B,CAAC;AAEH,0EAA0E;AAC1E,MAAM,CAAC,MAAM,WAAW,GAAG;;EAEzB,CAAC;AAEH,wDAAwD;AACxD,MAAM,CAAC,MAAM,WAAW,GAAG;;EAEzB,CAAC;AAEH,iFAAiF;AAEjF,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;EAK3B,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;EAQ7B,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;EA0B/B,CAAC;AAEH,qEAAqE;AACrE,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;EAyB1B,CAAC;AAEH,iFAAiF;AACjF,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;EAWzB,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;EAe/B,CAAC;AAEH,kEAAkE;AAClE,MAAM,CAAC,MAAM,8BAA8B,GAAG;;EAE5C,CAAC;AAEH;0GAC0G;AAC1G,MAAM,CAAC,MAAM,8BAA8B,GAAG;;EAE5C,CAAC;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4B/B,CAAC","sourcesContent":["/**\n * api/queries.ts — GraphQL documents for the checkout flow.\n * Kept as plain strings so they can be reused, logged, or tested in isolation.\n *\n * Mutation reference (from API doc):\n * updateTwouCustomer — toggle Stripe test clock on/off\n * createTwouCart — user proceeds to payment\n * updateTwouCartItem — attach billing plan / payment method to cart\n * updateTwouCart — persist auto-renewal consent (SUBS-228)\n * startBusinessProcessableTransition — place order\n * updateTwouCartItem — retry: attach new payment method\n */\n\n// ─── Mutations ────────────────────────────────────────────────────────────────\n\n/** Creates a new cart during checkout. */\nexport const CREATE_CART = `mutation CreateCart($input: TwouCartInput!) {\n createTwouCart(input: $input) { biId uid }\n}`;\n\n/** Updates a cart item — attach billing plan / payment method. */\nexport const UPDATE_CART_ITEM = `mutation UpdateCartItem($input: TwouCartItemInput!) {\n updateTwouCartItem(input: $input) { uid }\n}`;\n\n/** Persists auto-renewal consent fields on the TwouCart BI (SUBS-228). */\nexport const UPDATE_CART = `mutation UpdateCart($input: TwouCartInput!) {\n updateTwouCart(input: $input) { uid }\n}`;\n\n/** Triggers the backend workflow to place the order. */\nexport const PLACE_ORDER = `mutation PlaceOrder($input: StartBusinessProcessableTransitionInput!) {\n startBusinessProcessableTransition(input: $input) { uid bpStatus { code } }\n}`;\n\n// ─── Queries ──────────────────────────────────────────────────────────────────\n\nexport const GET_CART_ITEM = `query GetCartItem($biId: String!) {\n getBusinessInteraction(biId: $biId) {\n uid\n hiConsistsOf { ... on TwouCartItem { uid } }\n }\n}`;\n\nexport const GET_CART_STATUS = `query GetCartStatus($biId: String!) {\n getBusinessInteraction(biId: $biId) {\n bpStatus { code }\n hiConsistsOf { ... on TwouCartItem { tStripeSubscriptionId } }\n ... on TwouCart {\n cmComments { edges { node { comText } } }\n }\n }\n}`;\n\nexport const FIND_SUBSCRIPTION = `query FindSubscription($filter: String!) {\n filterTwouSubscription(_first: 1, _filter: $filter) {\n edges {\n node {\n biId\n tTrialStart\n tTrialEnd\n tRenewalType\n hiConsistsOf {\n ... on TwouSubscriptionItem {\n paybBillingPlan {\n tStripePriceId\n bipOwnershipModel { omName }\n }\n paybPayment {\n ... on TwouStripePayment {\n tStripePaymentMethodId\n tPaymentMethodLast4\n tPaymentMethodBrand\n }\n }\n }\n }\n }\n }\n }\n}`;\n\n/** Fetch the viax customer uid by email using filterTwouCustomer. */\nexport const GET_CUSTOMER = `query GetCustomer($filter: String!) {\n filterTwouCustomer(_first: 1, _filter: $filter) {\n edges {\n node {\n uid\n parId\n parParty {\n paName\n paContacts {\n edges {\n node {\n ... on EmailAddressContactMedium {\n email\n }\n }\n }\n }\n ... on Individual {\n indFirstName\n indLastName\n }\n }\n }\n }\n }\n}`;\n\n/** Fetch the TwouSubscriptionPlan uid to use as biiSalable in createTwouCart. */\nexport const GET_PRODUCT = `query GetProduct($maId: String!) {\n getProduct(maId: $maId) {\n maName\n uid\n ... on TwouSubscriptionPlan {\n saOwnershipModels {\n uid\n omName\n }\n }\n }\n}`;\n\nexport const GET_BILLING_PLANS = `query GetBillingPlans {\n filterCustomerBillingPlan(_first: 10) {\n edges {\n node {\n uid\n tStripePriceId\n tStripeAmount {\n amount\n units { code }\n }\n bipIsTemplate\n bipOwnershipModel { uid omName }\n }\n }\n }\n}`;\n\n/** Fetch the number of active subscriptions — unauthenticated. */\nexport const GET_ACTIVE_SUBSCRIPTIONS_STATE = `query activeSubscriptions {\n tActiveSubscriptionsState\n}`;\n\n/** Check whether the currently authenticated user already has an active subscription.\n * tIsCurrentUserSubscriber is a JSON scalar — returns the full object, no subfield selection allowed. */\nexport const GET_IS_CURRENT_USER_SUBSCRIBER = `query IsCurrentUserSubscriber {\n tIsCurrentUserSubscriber\n}`;\n\n/** Fetch a course for the enrollment card when ?course_run_key= is present. */\nexport const GET_COURSE_DETAIL = `query CourseDetail($filter: String!) {\n filterTwouCourse(_first: 1, _filter: $filter) {\n edges {\n node {\n maId\n maName\n maDescription\n tShortDescription\n imageUrl\n tCourseKey\n tBrandText\n tPrimarySubjectArea\n tLevelType\n tLanguage\n tPacingType { code }\n tDurationLow\n tDurationHigh\n tDurationUnit { code }\n tEffortLow\n tEffortHigh\n tEffortUnit { code }\n tUrlCourse\n tB2cSubscriptionInclusion\n tHasOfacRestrictions\n tCatalogActive\n }\n }\n }\n}`;\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api/stripe.ts — load Stripe.js and return a Stripe instance.
|
|
3
|
+
* Injects the script tag if needed. In an MFE you may prefer
|
|
4
|
+
* `@stripe/stripe-js`'s loadStripe(); swap this out if so.
|
|
5
|
+
*/
|
|
6
|
+
import type { StripeLike } from '../types';
|
|
7
|
+
export declare function loadStripe(publishableKey: string): Promise<StripeLike>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
let stripeLoadingPromise = null;
|
|
2
|
+
export function loadStripe(publishableKey) {
|
|
3
|
+
if (typeof window === 'undefined') {
|
|
4
|
+
return Promise.reject(new Error('Stripe.js requires a browser environment'));
|
|
5
|
+
}
|
|
6
|
+
if (window.Stripe)
|
|
7
|
+
return Promise.resolve(window.Stripe(publishableKey));
|
|
8
|
+
if (!stripeLoadingPromise) {
|
|
9
|
+
stripeLoadingPromise = new Promise((resolve, reject) => {
|
|
10
|
+
const fail = (err) => {
|
|
11
|
+
stripeLoadingPromise = null;
|
|
12
|
+
reject(err);
|
|
13
|
+
};
|
|
14
|
+
const done = () => {
|
|
15
|
+
if (window.Stripe)
|
|
16
|
+
resolve();
|
|
17
|
+
else
|
|
18
|
+
fail(new Error('Stripe.js loaded but window.Stripe is missing'));
|
|
19
|
+
};
|
|
20
|
+
const existing = document.querySelector('script[src^="https://js.stripe.com/v3"]');
|
|
21
|
+
if (existing) {
|
|
22
|
+
if (window.Stripe) {
|
|
23
|
+
resolve();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
existing.addEventListener('load', done, { once: true });
|
|
27
|
+
existing.addEventListener('error', () => fail(new Error('Failed to load Stripe.js')), { once: true });
|
|
28
|
+
// Race: load may have completed between querySelector and addEventListener.
|
|
29
|
+
if (window.Stripe)
|
|
30
|
+
resolve();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const s = document.createElement('script');
|
|
34
|
+
s.src = 'https://js.stripe.com/v3/';
|
|
35
|
+
s.async = true;
|
|
36
|
+
s.onload = done;
|
|
37
|
+
s.onerror = () => fail(new Error('Failed to load Stripe.js'));
|
|
38
|
+
document.head.appendChild(s);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return stripeLoadingPromise.then(() => window.Stripe(publishableKey));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=stripe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../src/utils/stripe.ts"],"names":[],"mappings":"AAOA,IAAI,oBAAoB,GAAyB,IAAI,CAAC;AAEtD,MAAM,UAAU,UAAU,CAAC,cAAsB;IAC/C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC,CAAC;IAC/E,CAAC;IACD,IAAI,MAAM,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;IACzE,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,oBAAoB,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3D,MAAM,IAAI,GAAG,CAAC,GAAU,EAAE,EAAE;gBAC1B,oBAAoB,GAAG,IAAI,CAAC;gBAC5B,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC,CAAC;YAEF,MAAM,IAAI,GAAG,GAAG,EAAE;gBAChB,IAAI,MAAM,CAAC,MAAM;oBAAE,OAAO,EAAE,CAAC;;oBACxB,IAAI,CAAC,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC,CAAC;YACxE,CAAC,CAAC;YAEF,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,yCAAyC,CAAC,CAAC;YACnF,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;oBAClB,OAAO,EAAE,CAAC;oBACV,OAAO;gBACT,CAAC;gBACD,QAAQ,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBACxD,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBACtG,4EAA4E;gBAC5E,IAAI,MAAM,CAAC,MAAM;oBAAE,OAAO,EAAE,CAAC;gBAC7B,OAAO;YACT,CAAC;YAED,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC3C,CAAC,CAAC,GAAG,GAAG,2BAA2B,CAAC;YACpC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC;YACf,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC;YAChB,CAAC,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;YAC9D,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,oBAAoB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAO,CAAC,cAAc,CAAC,CAAC,CAAC;AACzE,CAAC","sourcesContent":["/**\n * api/stripe.ts — load Stripe.js and return a Stripe instance.\n * Injects the script tag if needed. In an MFE you may prefer\n * `@stripe/stripe-js`'s loadStripe(); swap this out if so.\n */\nimport type { StripeLike } from '../types';\n\nlet stripeLoadingPromise: Promise<void> | null = null;\n\nexport function loadStripe(publishableKey: string): Promise<StripeLike> {\n if (typeof window === 'undefined') {\n return Promise.reject(new Error('Stripe.js requires a browser environment'));\n }\n if (window.Stripe) return Promise.resolve(window.Stripe(publishableKey));\n if (!stripeLoadingPromise) {\n stripeLoadingPromise = new Promise<void>((resolve, reject) => {\n const fail = (err: Error) => {\n stripeLoadingPromise = null;\n reject(err);\n };\n\n const done = () => {\n if (window.Stripe) resolve();\n else fail(new Error('Stripe.js loaded but window.Stripe is missing'));\n };\n\n const existing = document.querySelector('script[src^=\"https://js.stripe.com/v3\"]');\n if (existing) {\n if (window.Stripe) {\n resolve();\n return;\n }\n existing.addEventListener('load', done, { once: true });\n existing.addEventListener('error', () => fail(new Error('Failed to load Stripe.js')), { once: true });\n // Race: load may have completed between querySelector and addEventListener.\n if (window.Stripe) resolve();\n return;\n }\n\n const s = document.createElement('script');\n s.src = 'https://js.stripe.com/v3/';\n s.async = true;\n s.onload = done;\n s.onerror = () => fail(new Error('Failed to load Stripe.js'));\n document.head.appendChild(s);\n });\n }\n return stripeLoadingPromise.then(() => window.Stripe!(publishableKey));\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { LinkMenuItem, WidgetOperationTypes, } from '@openedx/frontend-base';
|
|
3
|
+
import { subscriptionCheckoutRole } from '../../constants';
|
|
4
|
+
const app = {
|
|
5
|
+
appId: 'org.openedx.frontend.app.template.exampleHeader',
|
|
6
|
+
slots: [
|
|
7
|
+
{
|
|
8
|
+
slotId: 'org.openedx.frontend.slot.header.primaryLinks.v1',
|
|
9
|
+
id: 'org.openedx.frontend.widget.template.exampleHeaderLink.v1',
|
|
10
|
+
op: WidgetOperationTypes.APPEND,
|
|
11
|
+
element: (_jsx(LinkMenuItem, { label: "Example Menu", role: subscriptionCheckoutRole, variant: "navLink" })),
|
|
12
|
+
condition: {
|
|
13
|
+
active: [subscriptionCheckoutRole],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
export default app;
|
|
19
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/widgets/ExampleHeader/app.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,YAAY,EACZ,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,MAAM,GAAG,GAAQ;IACf,KAAK,EAAE,iDAAiD;IACxD,KAAK,EAAE;QACL;YACE,MAAM,EAAE,kDAAkD;YAC1D,EAAE,EAAE,2DAA2D;YAC/D,EAAE,EAAE,oBAAoB,CAAC,MAAM;YAC/B,OAAO,EAAE,CACP,KAAC,YAAY,IACX,KAAK,EAAC,cAAc,EACpB,IAAI,EAAE,wBAAwB,EAC9B,OAAO,EAAC,SAAS,GACjB,CACH;YACD,SAAS,EAAE;gBACT,MAAM,EAAE,CAAC,wBAAwB,CAAC;aACnC;SACF;KACF;CACF,CAAC;AAEF,eAAe,GAAG,CAAC","sourcesContent":["import {\n App,\n LinkMenuItem,\n WidgetOperationTypes,\n} from '@openedx/frontend-base';\n\nimport { subscriptionCheckoutRole } from '../../constants';\n\nconst app: App = {\n appId: 'org.openedx.frontend.app.template.exampleHeader',\n slots: [\n {\n slotId: 'org.openedx.frontend.slot.header.primaryLinks.v1',\n id: 'org.openedx.frontend.widget.template.exampleHeaderLink.v1',\n op: WidgetOperationTypes.APPEND,\n element: (\n <LinkMenuItem\n label=\"Example Menu\"\n role={subscriptionCheckoutRole}\n variant=\"navLink\"\n />\n ),\n condition: {\n active: [subscriptionCheckoutRole],\n },\n },\n ],\n};\n\nexport default app;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as exampleHeaderApp } from './app';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/widgets/ExampleHeader/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,OAAO,CAAC","sourcesContent":["export { default as exampleHeaderApp } from './app';\n"]}
|