@edx/frontend-app-learner-dashboard 1.0.0 → 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.
@@ -4,5 +4,6 @@ export function baseAppUrl(url: any): any;
4
4
  export function learningMfeUrl(url: any): any;
5
5
  export function creditPurchaseUrl(courseId: any): string;
6
6
  export function creditRequestUrl(providerId: any): string;
7
+ export function getSubsInitApiUrl(): string;
7
8
  declare const _default: any;
8
9
  export default _default;
@@ -21,6 +21,7 @@ export const creditPurchaseUrl = (courseId) => {
21
21
  : `${config.ECOMMERCE_BASE_URL}/credit/checkout/${courseId}/`;
22
22
  };
23
23
  export const creditRequestUrl = (providerId) => `${getApiUrl()}/credit/v1/providers/${providerId}/request/`;
24
+ export const getSubsInitApiUrl = () => (`${getApiUrl()}/subscription/init/`);
24
25
  export default StrictDict({
25
26
  getApiUrl,
26
27
  baseAppUrl,
@@ -1 +1 @@
1
- {"version":3,"file":"urls.js","sourceRoot":"","sources":["../../../../src/data/services/lms/urls.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAErE,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU,CAAC;AAEpD,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC,UAAU,MAAM,CAAC,CAAC;AAErE,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAEjE,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,GAAG,UAAU,EAAE,QAAQ,CAAC;AAC5C,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,GAAG,UAAU,EAAE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E,wBAAwB,UAAU,WAAW,CAAC;AAE5G,eAAe,UAAU,CAAC;IACxB,SAAS;IACT,UAAU;IACV,cAAc;IACd,iBAAiB;IACjB,gBAAgB;IAChB,qBAAqB;IACrB,KAAK;IACL,aAAa;IACb,cAAc;IACd,WAAW;IACX,mBAAmB;CACpB,CAAC,CAAC","sourcesContent":["import { appId } from '../../../constants';\nimport { StrictDict } from '../../../utils';\n\nimport { getAppConfig, getSiteConfig } from '@openedx/frontend-base';\n\nconst getBaseUrl = () => getSiteConfig().lmsBaseUrl;\n\nexport const getApiUrl = () => (`${getSiteConfig().lmsBaseUrl}/api`);\n\nconst getInitApiUrl = () => (`${getApiUrl()}/learner_home/init`);\n\nconst event = () => `${getBaseUrl()}/event`;\nconst courseUnenroll = () => `${getBaseUrl()}/change_enrollment`;\nconst updateEmailSettings = () => `${getApiUrl()}/change_email_settings`;\nconst entitlementEnrollment = (uuid) => `${getApiUrl()}/entitlements/v1/entitlements/${uuid}/enrollments`;\n\n// if url is null or absolute, return it as is\nexport const updateUrl = (base, url) => ((url == null || url.startsWith('http://') || url.startsWith('https://')) ? url : `${base}${url}`);\n\nexport const baseAppUrl = (url) => updateUrl(getBaseUrl(), url);\nexport const learningMfeUrl = (url) => updateUrl(getAppConfig(appId).LEARNING_BASE_URL, url);\n\n// static view url\nconst programsUrl = () => baseAppUrl('/dashboard/programs');\n\nexport const creditPurchaseUrl = (courseId) => {\n const config = getAppConfig(appId);\n return config.CREDIT_PURCHASE_URL\n ? `${config.CREDIT_PURCHASE_URL}/${courseId}/`\n : `${config.ECOMMERCE_BASE_URL}/credit/checkout/${courseId}/`;\n};\nexport const creditRequestUrl = (providerId) => `${getApiUrl()}/credit/v1/providers/${providerId}/request/`;\n\nexport default StrictDict({\n getApiUrl,\n baseAppUrl,\n courseUnenroll,\n creditPurchaseUrl,\n creditRequestUrl,\n entitlementEnrollment,\n event,\n getInitApiUrl,\n learningMfeUrl,\n programsUrl,\n updateEmailSettings,\n});\n"]}
1
+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AAG,CAAC,CAAC;AAChE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;AAE7F,kBAAkB;AAClB,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,EAAE;IAC5C,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,MAAM,CAAC,mBAAmB;QAC/B,CAAC,CAAC,GAAG,MAAM,CAAC,mBAAmB,IAAI,QAAQ,GAAG;QAC9C,CAAC,CAAC,GAAG,MAAM,CAAC,kBAAkB,oBAAoB,QAAQ,GAAG,CAAC;AAClE,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,EAAE,CAAC,GAAG,SAAS,EAAE,wBAAwB,UAAU,WAAW,CAAC;AAE5G,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,SAAS,EAAE,qBAAqB,CAAC,CAAC;AAE7E,eAAe,UAAU,CAAC;IACxB,SAAS;IACT,UAAU;IACV,cAAc;IACd,iBAAiB;IACjB,gBAAgB;IAChB,qBAAqB;IACrB,KAAK;IACL,aAAa;IACb,cAAc;IACd,WAAW;IACX,mBAAmB;CACpB,CAAC,CAAC","sourcesContent":["import { appId } from '../../../constants';\nimport { StrictDict } from '../../../utils';\n\nimport { getAppConfig, getSiteConfig } from '@openedx/frontend-base';\n\nconst getBaseUrl = () => getSiteConfig().lmsBaseUrl;\n\nexport const getApiUrl = () => (`${getSiteConfig().lmsBaseUrl}/api`);\n\nconst getInitApiUrl = () => (`${getApiUrl()}/learner_home/init`);\n\nconst event = () => `${getBaseUrl()}/event`;\nconst courseUnenroll = () => `${getBaseUrl()}/change_enrollment`;\nconst updateEmailSettings = () => `${getApiUrl()}/change_email_settings`;\nconst entitlementEnrollment = (uuid) => `${getApiUrl()}/entitlements/v1/entitlements/${uuid}/enrollments`;\n\n// if url is null or absolute, return it as is\nexport const updateUrl = (base, url) => ((url == null || url.startsWith('http://') || url.startsWith('https://')) ? url : `${base}${url}`);\n\nexport const baseAppUrl = (url) => updateUrl(getBaseUrl(), url);\nexport const learningMfeUrl = (url) => updateUrl(getAppConfig(appId).LEARNING_BASE_URL, url);\n\n// static view url\nconst programsUrl = () => baseAppUrl('/dashboard/programs');\n\nexport const creditPurchaseUrl = (courseId) => {\n const config = getAppConfig(appId);\n return config.CREDIT_PURCHASE_URL\n ? `${config.CREDIT_PURCHASE_URL}/${courseId}/`\n : `${config.ECOMMERCE_BASE_URL}/credit/checkout/${courseId}/`;\n};\nexport const creditRequestUrl = (providerId) => `${getApiUrl()}/credit/v1/providers/${providerId}/request/`;\n\nexport const getSubsInitApiUrl = () => (`${getApiUrl()}/subscription/init/`);\n\nexport default StrictDict({\n getApiUrl,\n baseAppUrl,\n courseUnenroll,\n creditPurchaseUrl,\n creditRequestUrl,\n entitlementEnrollment,\n event,\n getInitApiUrl,\n learningMfeUrl,\n programsUrl,\n updateEmailSettings,\n});\n"]}
package/dist/routes.d.ts CHANGED
@@ -2,7 +2,7 @@ export default routes;
2
2
  declare const routes: {
3
3
  id: string;
4
4
  path: string;
5
- loader: typeof authenticatedLoader;
5
+ loader: (args: any) => Promise<null>;
6
6
  handle: {
7
7
  roles: string[];
8
8
  };
@@ -10,4 +10,3 @@ declare const routes: {
10
10
  Component: () => import("react/jsx-runtime").JSX.Element;
11
11
  }>;
12
12
  }[];
13
- import { authenticatedLoader } from '@openedx/frontend-base';
package/dist/routes.js CHANGED
@@ -7,13 +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, homeRole } from '@openedx/frontend-base';
10
+ import { authenticatedLoader, homeRole, getAuthenticatedHttpClient } from '@openedx/frontend-base';
11
+ import { redirect } from 'react-router-dom';
11
12
  import { dashboardRole } from './constants';
13
+ import { getSubsInitApiUrl } from './data/services/lms/urls';
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.userSubscription && data.userSubscription.isSubscriber) {
19
+ throw redirect('/subscription-learner-dashboard'); //redirect to subscription learner dashboard if user 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
+ return null; // keep the user on the current page 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
+ });
12
37
  const routes = [
13
38
  {
14
39
  id: 'org.openedx.frontend.route.learnerDashboard.main',
15
40
  path: '/learner-dashboard',
16
- loader: authenticatedLoader,
41
+ loader: protectedLoader,
17
42
  handle: {
18
43
  roles: [dashboardRole, homeRole]
19
44
  },
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.jsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,MAAM,GAAG;IACb;QACE,EAAE,EAAE,kDAAkD;QACtD,IAAI,EAAE,oBAAoB;QAC1B,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE;YACN,KAAK,EAAE,CAAC,aAAa,EAAE,QAAQ,CAAC;SACjC;QACK,IAAI;;gBACR,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,gDAAgD,CAAC,QAAQ,CAAC,CAAC;gBACvF,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;YACvC,CAAC;SAAA;KACF;CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import { authenticatedLoader, homeRole } from '@openedx/frontend-base';\nimport { dashboardRole } from './constants';\n\nconst routes = [\n {\n id: 'org.openedx.frontend.route.learnerDashboard.main',\n path: '/learner-dashboard',\n loader: authenticatedLoader,\n handle: {\n roles: [dashboardRole, homeRole]\n },\n async lazy () {\n const module = await import(/* webpackChunkName: \"learner-dashboard-main\" */ './Main');\n return { Component: module.default };\n },\n }\n];\n\nexport default routes;\n"]}
1
+ {"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.jsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,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,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC;YAChE,MAAM,QAAQ,CAAC,iCAAiC,CAAC,CAAC,CAAE,6EAA6E;QACnI,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,OAAO,IAAI,CAAC,CAAC,uDAAuD;IACtE,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,kDAAkD;QACtD,IAAI,EAAE,oBAAoB;QAC1B,MAAM,EAAE,eAAe;QACvB,MAAM,EAAE;YACN,KAAK,EAAE,CAAC,aAAa,EAAE,QAAQ,CAAC;SACjC;QACK,IAAI;;gBACR,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,gDAAgD,CAAC,QAAQ,CAAC,CAAC;gBACvF,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;YACvC,CAAC;SAAA;KACF;CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import { authenticatedLoader, homeRole, getAuthenticatedHttpClient } from '@openedx/frontend-base';\nimport { redirect } from 'react-router-dom';\n\nimport { dashboardRole } from './constants';\nimport { getSubsInitApiUrl } from './data/services/lms/urls';\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('/subscription-learner-dashboard'); //redirect to subscription learner dashboard if user 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 return null; // keep the user on the current page 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.learnerDashboard.main',\n path: '/learner-dashboard',\n loader: protectedLoader,\n handle: {\n roles: [dashboardRole, homeRole]\n },\n async lazy () {\n const module = await import(/* webpackChunkName: \"learner-dashboard-main\" */ './Main');\n return { Component: module.default };\n },\n }\n];\n\nexport default routes;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edx/frontend-app-learner-dashboard",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",