@edx/frontend-app-subscription-manage 1.0.1 → 1.1.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.
@@ -0,0 +1,2 @@
1
+ export function getApiUrl(): string;
2
+ export function getSubsInitApiUrl(): string;
@@ -0,0 +1,4 @@
1
+ import { getSiteConfig } from '@openedx/frontend-base';
2
+ export const getApiUrl = () => (`${getSiteConfig().lmsBaseUrl}/api`);
3
+ export const getSubsInitApiUrl = () => (`${getApiUrl()}/subscription/init/`);
4
+ //# sourceMappingURL=urls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urls.js","sourceRoot":"","sources":["../../../../src/data/services/subs/urls.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC,UAAU,MAAM,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,SAAS,EAAE,qBAAqB,CAAC,CAAC","sourcesContent":["import { getSiteConfig } from '@openedx/frontend-base';\n\nexport const getApiUrl = () => (`${getSiteConfig().lmsBaseUrl}/api`);\n\nexport const getSubsInitApiUrl = () => (`${getApiUrl()}/subscription/init/`);\n"]}
package/dist/routes.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  declare const routes: {
2
2
  id: string;
3
3
  path: string;
4
+ loader: (args: any) => Promise<null>;
4
5
  handle: {
5
6
  roles: string[];
6
7
  };
package/dist/routes.js CHANGED
@@ -7,11 +7,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { authenticatedLoader, getAuthenticatedHttpClient } from '@openedx/frontend-base';
11
+ import { redirect } from 'react-router-dom';
12
+ import { getSubsInitApiUrl } from './data/services/subs/urls';
10
13
  import { subscriptionManageRole } from './constants';
14
+ // loader to check if the user has subscription access
15
+ const subscriptionAccessLoader = () => __awaiter(void 0, void 0, void 0, function* () {
16
+ try {
17
+ const { data } = yield getAuthenticatedHttpClient().get(getSubsInitApiUrl());
18
+ if (!(data === null || data === void 0 ? void 0 : data.userSubscription) || !data.userSubscription.isSubscriber) {
19
+ throw redirect('/learner-dashboard'); // redirect to learner dashboard if user does not have subscription access
20
+ }
21
+ return null;
22
+ }
23
+ catch (error) {
24
+ // Let redirect responses bubble up
25
+ if (error instanceof Response) {
26
+ throw error;
27
+ }
28
+ throw redirect('/learner-dashboard'); // redirect to learner dashboard if an error occurs
29
+ }
30
+ });
31
+ // composed loader that checks for authentication and subscription access
32
+ const protectedLoader = (args) => __awaiter(void 0, void 0, void 0, function* () {
33
+ yield authenticatedLoader(args);
34
+ yield subscriptionAccessLoader();
35
+ return null;
36
+ });
11
37
  const routes = [
12
38
  {
13
39
  id: 'org.openedx.frontend.route.subscription.manage.main',
14
40
  path: 'subscription-manage',
41
+ loader: protectedLoader,
15
42
  handle: {
16
43
  roles: [subscriptionManageRole],
17
44
  },
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,MAAM,GAAG;IACb;QACE,EAAE,EAAE,qDAAqD;QACzD,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE;YACN,KAAK,EAAE,CAAC,sBAAsB,CAAC;SAChC;QACK,IAAI;;gBACR,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,kDAAkD,CAAC,QAAQ,CAAC,CAAC;gBACzF,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;YACvC,CAAC;SAAA;QACD,QAAQ,EAAE;YACR;gBACE,KAAK,EAAE,IAAI;gBACL,IAAI;;wBACR,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qDAAqD,CAAC,uBAAuB,CAAC,CAAC;wBAC3G,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;oBACvC,CAAC;iBAAA;aACF;SACF;KACF;CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import { subscriptionManageRole } from './constants';\n\nconst routes = [\n {\n id: 'org.openedx.frontend.route.subscription.manage.main',\n path: 'subscription-manage',\n handle: {\n roles: [subscriptionManageRole],\n },\n async lazy() {\n const module = await import(/* webpackChunkName: \"subscription-manage-main\" */ './Main');\n return { Component: module.default };\n },\n children: [\n {\n index: true,\n async lazy() {\n const module = await import(/* webpackChunkName: \"subscription-manage-example\" */ './example/ExamplePage');\n return { Component: module.default };\n },\n },\n ],\n },\n];\n\nexport default routes;\n"]}
1
+ {"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,sDAAsD;AACtD,MAAM,wBAAwB,GAAG,GAAS,EAAE;IAC1C,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,0BAA0B,EAAE,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC;QAE7E,IAAI,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,gBAAgB,CAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC;YACnE,MAAM,QAAQ,CAAC,oBAAoB,CAAC,CAAC,CAAC,0EAA0E;QAClH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,mCAAmC;QACnC,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;YAC9B,MAAM,KAAK,CAAC;QACd,CAAC;QAED,MAAM,QAAQ,CAAC,oBAAoB,CAAC,CAAC,CAAC,mDAAmD;IAC3F,CAAC;AACH,CAAC,CAAA,CAAC;AAEF,yEAAyE;AACzE,MAAM,eAAe,GAAG,CAAO,IAAI,EAAE,EAAE;IACrC,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,wBAAwB,EAAE,CAAC;IAEjC,OAAO,IAAI,CAAC;AACd,CAAC,CAAA,CAAC;AAEF,MAAM,MAAM,GAAG;IACb;QACE,EAAE,EAAE,qDAAqD;QACzD,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE,eAAe;QACvB,MAAM,EAAE;YACN,KAAK,EAAE,CAAC,sBAAsB,CAAC;SAChC;QACK,IAAI;;gBACR,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,kDAAkD,CAAC,QAAQ,CAAC,CAAC;gBACzF,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;YACvC,CAAC;SAAA;QACD,QAAQ,EAAE;YACR;gBACE,KAAK,EAAE,IAAI;gBACL,IAAI;;wBACR,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qDAAqD,CAAC,uBAAuB,CAAC,CAAC;wBAC3G,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;oBACvC,CAAC;iBAAA;aACF;SACF;KACF;CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import { authenticatedLoader, getAuthenticatedHttpClient } from '@openedx/frontend-base';\nimport { redirect } from 'react-router-dom';\n\nimport { getSubsInitApiUrl } from './data/services/subs/urls';\nimport { subscriptionManageRole } from './constants';\n\n// loader to check if the user has subscription access\nconst subscriptionAccessLoader = async () => {\n try {\n const { data } = await getAuthenticatedHttpClient().get(getSubsInitApiUrl());\n\n if (!data?.userSubscription || !data.userSubscription.isSubscriber) {\n throw redirect('/learner-dashboard'); // redirect to learner dashboard if user does not have subscription access\n }\n\n return null;\n } catch (error) {\n // Let redirect responses bubble up\n if (error instanceof Response) {\n throw error;\n }\n\n throw redirect('/learner-dashboard'); // redirect to learner dashboard if an error occurs\n }\n};\n\n// composed loader that checks for authentication and subscription access\nconst protectedLoader = async (args) => {\n await authenticatedLoader(args);\n await subscriptionAccessLoader();\n\n return null;\n};\n\nconst routes = [\n {\n id: 'org.openedx.frontend.route.subscription.manage.main',\n path: 'subscription-manage',\n loader: protectedLoader,\n handle: {\n roles: [subscriptionManageRole],\n },\n async lazy() {\n const module = await import(/* webpackChunkName: \"subscription-manage-main\" */ './Main');\n return { Component: module.default };\n },\n children: [\n {\n index: true,\n async lazy() {\n const module = await import(/* webpackChunkName: \"subscription-manage-example\" */ './example/ExamplePage');\n return { Component: module.default };\n },\n },\n ],\n },\n];\n\nexport default routes;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edx/frontend-app-subscription-manage",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Subscription Manage Frontend application",
5
5
  "repository": {
6
6
  "type": "git",