@coorpacademy/app-review 0.0.13 → 0.0.14-alpha.3

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.
Files changed (105) hide show
  1. package/es/actions/courses.d.ts +7 -0
  2. package/es/actions/courses.d.ts.map +1 -0
  3. package/es/actions/courses.js +5 -0
  4. package/es/actions/index.d.ts +6 -0
  5. package/es/actions/index.d.ts.map +1 -1
  6. package/es/actions/index.js +2 -0
  7. package/es/actions/navigation.d.ts +7 -0
  8. package/es/actions/navigation.d.ts.map +1 -1
  9. package/es/actions/navigation.js +5 -0
  10. package/es/actions/token.d.ts +7 -0
  11. package/es/actions/token.d.ts.map +1 -0
  12. package/es/actions/token.js +5 -0
  13. package/es/configure-store.d.ts +11 -3
  14. package/es/configure-store.d.ts.map +1 -1
  15. package/es/configure-store.js +4 -2
  16. package/es/index.d.ts +9 -3
  17. package/es/index.d.ts.map +1 -1
  18. package/es/index.js +4 -4
  19. package/es/middlewares/on-start-app.d.ts +7 -0
  20. package/es/middlewares/on-start-app.d.ts.map +1 -0
  21. package/es/middlewares/on-start-app.js +17 -0
  22. package/es/reducers/courses.d.ts +6 -0
  23. package/es/reducers/courses.d.ts.map +1 -0
  24. package/es/reducers/courses.js +14 -0
  25. package/es/reducers/index.d.ts +2 -0
  26. package/es/reducers/index.d.ts.map +1 -1
  27. package/es/reducers/index.js +5 -1
  28. package/es/reducers/navigation.d.ts.map +1 -1
  29. package/es/reducers/navigation.js +3 -0
  30. package/es/reducers/token.d.ts +7 -0
  31. package/es/reducers/token.d.ts.map +1 -0
  32. package/es/reducers/token.js +16 -0
  33. package/es/services/fetch-demo.d.ts +6 -0
  34. package/es/services/fetch-demo.d.ts.map +1 -0
  35. package/es/services/fetch-demo.js +25 -0
  36. package/es/services/fetch-demo.test.d.ts +2 -0
  37. package/es/services/fetch-demo.test.d.ts.map +1 -0
  38. package/es/services/fetch-demo.test.js +13 -0
  39. package/es/services/fetch-responses.d.ts +20 -0
  40. package/es/services/fetch-responses.d.ts.map +1 -0
  41. package/es/services/fetch-responses.js +33 -0
  42. package/es/services/fetch.test.d.ts +10 -0
  43. package/es/services/fetch.test.d.ts.map +1 -0
  44. package/es/services/fetch.test.js +12 -0
  45. package/lib/actions/courses.d.ts +7 -0
  46. package/lib/actions/courses.d.ts.map +1 -0
  47. package/lib/actions/courses.js +9 -0
  48. package/lib/actions/index.d.ts +6 -0
  49. package/lib/actions/index.d.ts.map +1 -1
  50. package/lib/actions/index.js +2 -0
  51. package/lib/actions/navigation.d.ts +7 -0
  52. package/lib/actions/navigation.d.ts.map +1 -1
  53. package/lib/actions/navigation.js +7 -1
  54. package/lib/actions/token.d.ts +7 -0
  55. package/lib/actions/token.d.ts.map +1 -0
  56. package/lib/actions/token.js +9 -0
  57. package/lib/configure-store.d.ts +11 -3
  58. package/lib/configure-store.d.ts.map +1 -1
  59. package/lib/configure-store.js +4 -2
  60. package/lib/index.d.ts +9 -3
  61. package/lib/index.d.ts.map +1 -1
  62. package/lib/index.js +3 -3
  63. package/lib/middlewares/on-start-app.d.ts +7 -0
  64. package/lib/middlewares/on-start-app.d.ts.map +1 -0
  65. package/lib/middlewares/on-start-app.js +22 -0
  66. package/lib/reducers/courses.d.ts +6 -0
  67. package/lib/reducers/courses.d.ts.map +1 -0
  68. package/lib/reducers/courses.js +27 -0
  69. package/lib/reducers/index.d.ts +2 -0
  70. package/lib/reducers/index.d.ts.map +1 -1
  71. package/lib/reducers/index.js +5 -1
  72. package/lib/reducers/navigation.d.ts.map +1 -1
  73. package/lib/reducers/navigation.js +3 -0
  74. package/lib/reducers/token.d.ts +7 -0
  75. package/lib/reducers/token.d.ts.map +1 -0
  76. package/lib/reducers/token.js +21 -0
  77. package/lib/services/fetch-demo.d.ts +6 -0
  78. package/lib/services/fetch-demo.d.ts.map +1 -0
  79. package/lib/services/fetch-demo.js +75 -0
  80. package/lib/services/fetch-demo.test.d.ts +2 -0
  81. package/lib/services/fetch-demo.test.d.ts.map +1 -0
  82. package/lib/services/fetch-demo.test.js +60 -0
  83. package/lib/services/fetch-responses.d.ts +20 -0
  84. package/lib/services/fetch-responses.d.ts.map +1 -0
  85. package/lib/services/fetch-responses.js +118 -0
  86. package/lib/services/fetch.test.d.ts +10 -0
  87. package/lib/services/fetch.test.d.ts.map +1 -0
  88. package/lib/services/fetch.test.js +31 -0
  89. package/package.json +8 -3
  90. package/readme.md +23 -0
  91. package/src/actions/courses.ts +11 -0
  92. package/src/actions/index.ts +8 -0
  93. package/src/actions/navigation.ts +12 -0
  94. package/src/actions/token.ts +11 -0
  95. package/src/configure-store.ts +15 -2
  96. package/src/index.tsx +12 -3
  97. package/src/middlewares/on-start-app.ts +30 -0
  98. package/src/reducers/courses.ts +22 -0
  99. package/src/reducers/index.ts +6 -1
  100. package/src/reducers/navigation.ts +9 -1
  101. package/src/reducers/token.ts +26 -0
  102. package/src/services/fetch-demo.test.ts +15 -0
  103. package/src/services/fetch-demo.ts +49 -0
  104. package/src/services/fetch-responses.ts +53 -0
  105. package/src/services/fetch.test.ts +26 -0
@@ -1,6 +1,14 @@
1
- export default function configureStore(services: any): import("redux").Store<import("redux").EmptyObject & {
2
- navigation: import("./reducers/navigation").State;
1
+ import { State as NavigationState } from './reducers/navigation';
2
+ import { State as TokenState } from './reducers/token';
3
+ export default function configureStore(): import("redux").Store<import("redux").EmptyObject & {
4
+ courses: import("./reducers/courses").State;
5
+ navigation: NavigationState;
6
+ token: string;
3
7
  }, import("redux").AnyAction> & {
4
- dispatch: unknown;
8
+ dispatch: {};
9
+ };
10
+ export declare type StoreState = {
11
+ navigation: NavigationState;
12
+ token: TokenState;
5
13
  };
6
14
  //# sourceMappingURL=configure-store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"configure-store.d.ts","sourceRoot":"","sources":["../src/configure-store.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,QAAQ,KAAA;;;;EAc9C"}
1
+ {"version":3,"file":"configure-store.d.ts","sourceRoot":"","sources":["../src/configure-store.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,IAAI,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAC,KAAK,IAAI,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAOrD,MAAM,CAAC,OAAO,UAAU,cAAc;;;;;;EAcrC;AAID,oBAAY,UAAU,GAAG;IACvB,UAAU,EAAE,eAAe,CAAC;IAC5B,KAAK,EAAE,UAAU,CAAC;CACnB,CAAC"}
@@ -4,8 +4,10 @@ var redux_1 = require("redux");
4
4
  var redux_thunk_1 = require("redux-thunk");
5
5
  var redux_devtools_extension_1 = require("redux-devtools-extension");
6
6
  var reducers_1 = require("./reducers");
7
+ var on_start_app_1 = require("./middlewares/on-start-app");
7
8
  var preloadedState = undefined;
8
- function configureStore(services) {
9
+ // -----------------------------------------------------------------------------
10
+ function configureStore() {
9
11
  var _compose = process.env.NODE_ENV !== 'production'
10
12
  ? (0, redux_devtools_extension_1.composeWithDevTools)({
11
13
  name: 'app-review',
@@ -13,7 +15,7 @@ function configureStore(services) {
13
15
  traceLimit: 25
14
16
  })
15
17
  : redux_1.compose;
16
- var enhancer = _compose((0, redux_1.applyMiddleware)(redux_thunk_1.default));
18
+ var enhancer = _compose((0, redux_1.applyMiddleware)(redux_thunk_1.default, on_start_app_1.default));
17
19
  var store = (0, redux_1.createStore)(reducers_1.default, preloadedState, enhancer);
18
20
  return store;
19
21
  }
package/lib/index.d.ts CHANGED
@@ -1,5 +1,11 @@
1
- declare const AppRevision: ({ services }: {
2
- services: any;
3
- }) => JSX.Element;
1
+ declare const AppRevision: ({ options }: Props) => JSX.Element;
2
+ declare type Props = {
3
+ options: AppOptions;
4
+ };
5
+ export declare type AppOptions = {
6
+ token: string;
7
+ theme?: any;
8
+ translations?: any;
9
+ };
4
10
  export default AppRevision;
5
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAmBA,QAAA,MAAM,WAAW;;iBAehB,CAAC;AAIF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAmBA,QAAA,MAAM,WAAW,gBAAe,KAAK,gBAgBpC,CAAC;AAIF,aAAK,KAAK,GAAG;IAAC,OAAO,EAAE,UAAU,CAAA;CAAC,CAAC;AAEnC,oBAAY,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB,CAAC;AAEF,eAAe,WAAW,CAAC"}
package/lib/index.js CHANGED
@@ -25,10 +25,11 @@ var mapDispatchToProps = { navigateTo: navigation_1.navigateTo, navigateBack: na
25
25
  var App = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(root_view_1.default);
26
26
  // -----------------------------------------------------------------------------
27
27
  var AppRevision = function (_a) {
28
- var services = _a.services;
28
+ var options = _a.options;
29
29
  var _b = (0, react_1.useState)(null), store = _b[0], setStore = _b[1];
30
30
  (0, react_1.useEffect)(function () {
31
- var store = (0, configure_store_1.default)(services);
31
+ var store = (0, configure_store_1.default)();
32
+ store.dispatch((0, navigation_1.startApp)(options));
32
33
  setStore(store);
33
34
  }, []);
34
35
  if (!store)
@@ -36,5 +37,4 @@ var AppRevision = function (_a) {
36
37
  return (react_1.default.createElement(react_redux_1.Provider, { store: store },
37
38
  react_1.default.createElement(App, null)));
38
39
  };
39
- // -----------------------------------------------------------------------------
40
40
  exports.default = AppRevision;
@@ -0,0 +1,7 @@
1
+ import type { Middleware } from 'redux';
2
+ import { Dispatch } from 'redux';
3
+ import { Action } from '../actions';
4
+ import { StoreState } from '../configure-store';
5
+ declare const onStartApp: Middleware<{}, StoreState, Dispatch<Action>>;
6
+ export default onStartApp;
7
+ //# sourceMappingURL=on-start-app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"on-start-app.d.ts","sourceRoot":"","sources":["../../src/middlewares/on-start-app.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACtC,OAAO,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAC,MAAM,EAAwC,MAAM,YAAY,CAAC;AACzE,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAG9C,QAAA,MAAM,UAAU,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,CAmB5D,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var actions_1 = require("../actions");
4
+ var fetch_demo_1 = require("../services/fetch-demo");
5
+ var onStartApp = function (_a) {
6
+ var dispatch = _a.dispatch;
7
+ return function (next) { return function (action) {
8
+ if (action.type === actions_1.START_APP) {
9
+ var token = action.payload.token;
10
+ dispatch((0, actions_1.storeToken)(token));
11
+ // --------------
12
+ // demo service
13
+ var language = 'fr';
14
+ var universalRef = 'dis_xxx15';
15
+ (0, fetch_demo_1.default)(token, language, universalRef).then(function (course) {
16
+ dispatch((0, actions_1.receivedCourse)(course));
17
+ });
18
+ }
19
+ return next(action);
20
+ }; };
21
+ };
22
+ exports.default = onStartApp;
@@ -0,0 +1,6 @@
1
+ import { $RECEIVED_COURSE } from '../actions';
2
+ export declare type State = Array<any>;
3
+ export declare const initialState: State;
4
+ declare const reducer: (state: State, action: $RECEIVED_COURSE) => State;
5
+ export default reducer;
6
+ //# sourceMappingURL=courses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"courses.d.ts","sourceRoot":"","sources":["../../src/reducers/courses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAkB,MAAM,YAAY,CAAC;AAI7D,oBAAY,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;AAC/B,eAAO,MAAM,YAAY,EAAE,KAAU,CAAC;AAItC,QAAA,MAAM,OAAO,yBAAyC,gBAAgB,UAQrE,CAAC;AAIF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.initialState = void 0;
13
+ var actions_1 = require("../actions");
14
+ exports.initialState = [];
15
+ // -----------------------------------------------------------------------------
16
+ var reducer = function (state, action) {
17
+ if (state === void 0) { state = exports.initialState; }
18
+ switch (action.type) {
19
+ case actions_1.RECEIVED_COURSE: {
20
+ return __spreadArray(__spreadArray([], state, true), [action.payload], false);
21
+ }
22
+ default:
23
+ return state;
24
+ }
25
+ };
26
+ // -----------------------------------------------------------------------------
27
+ exports.default = reducer;
@@ -1,5 +1,7 @@
1
1
  declare const rootReducer: import("redux").Reducer<import("redux").CombinedState<{
2
+ courses: import("./courses").State;
2
3
  navigation: import("./navigation").State;
4
+ token: string;
3
5
  }>, import("redux").AnyAction>;
4
6
  export default rootReducer;
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reducers/index.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,WAAW;;8BAEf,CAAC;AAEH,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reducers/index.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,WAAW;;;;8BAIf,CAAC;AAEH,eAAe,WAAW,CAAC"}
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var redux_1 = require("redux");
4
+ var courses_1 = require("./courses");
4
5
  var navigation_1 = require("./navigation");
6
+ var token_1 = require("./token");
5
7
  var rootReducer = (0, redux_1.combineReducers)({
6
- navigation: navigation_1.default
8
+ courses: courses_1.default,
9
+ navigation: navigation_1.default,
10
+ token: token_1.default
7
11
  });
8
12
  exports.default = rootReducer;
@@ -1 +1 @@
1
- {"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/reducers/navigation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAE,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAExE,oBAAY,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAElC,eAAO,MAAM,YAAY,EAAE,KAAgB,CAAC;AAE5C,QAAA,MAAM,OAAO,yBAAyC,YAAY,GAAG,cAAc,UAalF,CAAC;AAEF,eAAO,MAAM,kBAAkB,wBAAkE,CAAC;AAClG,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/reducers/navigation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAE,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAIxE,oBAAY,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAClC,eAAO,MAAM,YAAY,EAAE,KAAgB,CAAC;AAI5C,QAAA,MAAM,OAAO,yBAAyC,YAAY,GAAG,cAAc,UAalF,CAAC;AAIF,eAAO,MAAM,kBAAkB,wBAAkE,CAAC;AAIlG,eAAe,OAAO,CAAC"}
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getCurrentViewName = exports.initialState = void 0;
13
13
  var navigation_1 = require("../actions/navigation");
14
14
  exports.initialState = ['home'];
15
+ // -----------------------------------------------------------------------------
15
16
  var reducer = function (state, action) {
16
17
  if (state === void 0) { state = exports.initialState; }
17
18
  switch (action.type) {
@@ -27,6 +28,8 @@ var reducer = function (state, action) {
27
28
  return state;
28
29
  }
29
30
  };
31
+ // -----------------------------------------------------------------------------
30
32
  var getCurrentViewName = function (appState) { return appState.navigation[appState.navigation.length - 1]; };
31
33
  exports.getCurrentViewName = getCurrentViewName;
34
+ // -----------------------------------------------------------------------------
32
35
  exports.default = reducer;
@@ -0,0 +1,7 @@
1
+ import { $STORE_TOKEN } from '../actions';
2
+ export declare type State = string;
3
+ export declare const initialState: State;
4
+ declare const reducer: (state: State, action: $STORE_TOKEN) => State;
5
+ export declare const getToken: (appState: any) => any;
6
+ export default reducer;
7
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/reducers/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAc,MAAM,YAAY,CAAC;AAIrD,oBAAY,KAAK,GAAG,MAAM,CAAC;AAC3B,eAAO,MAAM,YAAY,EAAE,KAAY,CAAC;AAIxC,QAAA,MAAM,OAAO,UAAW,KAAK,UAAyB,YAAY,KAAG,KAQpE,CAAC;AAIF,eAAO,MAAM,QAAQ,wBAA6B,CAAC;AAInD,eAAe,OAAO,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getToken = exports.initialState = void 0;
4
+ var actions_1 = require("../actions");
5
+ exports.initialState = null;
6
+ // -----------------------------------------------------------------------------
7
+ var reducer = function (state, action) {
8
+ if (state === void 0) { state = exports.initialState; }
9
+ switch (action.type) {
10
+ case actions_1.STORE_TOKEN: {
11
+ return action.payload;
12
+ }
13
+ default:
14
+ return state;
15
+ }
16
+ };
17
+ // -----------------------------------------------------------------------------
18
+ var getToken = function (appState) { return appState.token; };
19
+ exports.getToken = getToken;
20
+ // -----------------------------------------------------------------------------
21
+ exports.default = reducer;
@@ -0,0 +1,6 @@
1
+ import { Fetch } from './fetch-responses';
2
+ declare const fetchCourse: (fetch: Fetch) => (token: any, language: any, universalRef: any) => Promise<any>;
3
+ export { fetchCourse };
4
+ declare const _default: (token: any, language: any, universalRef: any) => Promise<any>;
5
+ export default _default;
6
+ //# sourceMappingURL=fetch-demo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-demo.d.ts","sourceRoot":"","sources":["../../src/services/fetch-demo.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAS,MAAM,mBAAmB,CAAC;AA4BhD,QAAA,MAAM,WAAW,UAAW,KAAK,mEAchC,CAAC;AAIF,OAAO,EAAC,WAAW,EAAC,CAAC;;AACrB,wBAAkC"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.fetchCourse = void 0;
40
+ var jwt_decode_1 = require("jwt-decode");
41
+ var fetch_responses_1 = require("./fetch-responses");
42
+ var buildUrlQueryParams = function (params) {
43
+ return Object.keys(params)
44
+ .map(function (key) {
45
+ var value = params[key].toString();
46
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
47
+ })
48
+ .join('&');
49
+ };
50
+ // -----------------------------------------------------------------------------
51
+ var fetchCourse = function (fetch) { return function (token, language, universalRef) { return __awaiter(void 0, void 0, void 0, function () {
52
+ var jwt, query, response, hits;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ jwt = (0, jwt_decode_1.default)(token);
57
+ query = {
58
+ type: 'course',
59
+ universalRef: universalRef,
60
+ lang: language
61
+ };
62
+ return [4 /*yield*/, fetch("".concat(jwt.host, "/api/v2/contents?").concat(buildUrlQueryParams(query)), {
63
+ headers: { authorization: token }
64
+ })];
65
+ case 1:
66
+ response = _a.sent();
67
+ return [4 /*yield*/, (0, fetch_responses_1.toJSON)(response)];
68
+ case 2:
69
+ hits = (_a.sent()).hits;
70
+ return [2 /*return*/, hits === null || hits === void 0 ? void 0 : hits[0]];
71
+ }
72
+ });
73
+ }); }; };
74
+ exports.fetchCourse = fetchCourse;
75
+ exports.default = fetchCourse(fetch);
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fetch-demo.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-demo.test.d.ts","sourceRoot":"","sources":["../../src/services/fetch-demo.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var ava_1 = require("ava");
40
+ var fetch_demo_js_1 = require("./fetch-demo.js");
41
+ var fetch_test_1 = require("./fetch.test");
42
+ var dotenv_1 = require("dotenv");
43
+ dotenv_1.default.config();
44
+ (0, ava_1.default)('should fetch a demo course with mobile-staging dev token', function (t) { return __awaiter(void 0, void 0, void 0, function () {
45
+ var token, language, universalRef, fetchCourse, course;
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0:
49
+ token = 'foo';
50
+ language = 'fr';
51
+ universalRef = 'bar';
52
+ fetchCourse = (0, fetch_demo_js_1.fetchCourse)((0, fetch_test_1.okJSONResponse)({ title: 'Digital IQ test' }));
53
+ return [4 /*yield*/, fetchCourse(token, language, universalRef)];
54
+ case 1:
55
+ course = _a.sent();
56
+ t.is(course.title, 'Digital IQs test');
57
+ return [2 /*return*/];
58
+ }
59
+ });
60
+ }); });
@@ -0,0 +1,20 @@
1
+ export declare type Response = {
2
+ ok: boolean;
3
+ status: number;
4
+ statusText: string;
5
+ json: () => Promise<unknown>;
6
+ text: () => Promise<string>;
7
+ };
8
+ export declare type Fetch = (url?: string, options?: {
9
+ headers: {
10
+ authorization: string;
11
+ };
12
+ }) => Promise<Response>;
13
+ export declare class ResponseError extends Error {
14
+ statusCode: number;
15
+ constructor(status: number, statusText: string, body?: string);
16
+ }
17
+ export declare const toJSON: (response: Response) => Promise<unknown>;
18
+ export declare const toText: (response: Response) => Promise<string>;
19
+ export declare const toVoid: (response: Response) => Promise<void>;
20
+ //# sourceMappingURL=fetch-responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-responses.d.ts","sourceRoot":"","sources":["../../src/services/fetch-responses.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ,GAAG;IACrB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC;AAEF,oBAAY,KAAK,GAAG,CAClB,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IAAC,OAAO,EAAE;QAAC,aAAa,EAAE,MAAM,CAAA;KAAC,CAAA;CAAC,KACzC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB,qBAAa,aAAc,SAAQ,KAAK;IAC/B,UAAU,EAAE,MAAM,CAAC;gBAEP,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,SAAK;CAKjE;AAED,eAAO,MAAM,MAAM,aAAoB,QAAQ,KAAG,QAAQ,OAAO,CAWhE,CAAC;AAEF,eAAO,MAAM,MAAM,aAAoB,QAAQ,KAAG,QAAQ,MAAM,CAQ/D,CAAC;AAEF,eAAO,MAAM,MAAM,aAAoB,QAAQ,KAAG,QAAQ,IAAI,CAM7D,CAAC"}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.toVoid = exports.toText = exports.toJSON = exports.ResponseError = void 0;
55
+ var ResponseError = /** @class */ (function (_super) {
56
+ __extends(ResponseError, _super);
57
+ function ResponseError(status, statusText, body) {
58
+ if (body === void 0) { body = ''; }
59
+ var _this = _super.call(this, "".concat(statusText, " ").concat(body).trim()) || this;
60
+ _this.name = 'ResponseError';
61
+ _this.statusCode = status;
62
+ return _this;
63
+ }
64
+ return ResponseError;
65
+ }(Error));
66
+ exports.ResponseError = ResponseError;
67
+ var toJSON = function (response) { return __awaiter(void 0, void 0, void 0, function () {
68
+ var body, err_1;
69
+ return __generator(this, function (_a) {
70
+ switch (_a.label) {
71
+ case 0:
72
+ if (!!response.ok) return [3 /*break*/, 2];
73
+ return [4 /*yield*/, response.text()];
74
+ case 1:
75
+ body = _a.sent();
76
+ throw new ResponseError(response.status, response.statusText, body);
77
+ case 2:
78
+ _a.trys.push([2, 4, , 5]);
79
+ return [4 /*yield*/, response.json()];
80
+ case 3: return [2 /*return*/, _a.sent()];
81
+ case 4:
82
+ err_1 = _a.sent();
83
+ throw new ResponseError(response.status, response.statusText);
84
+ case 5: return [2 /*return*/];
85
+ }
86
+ });
87
+ }); };
88
+ exports.toJSON = toJSON;
89
+ var toText = function (response) { return __awaiter(void 0, void 0, void 0, function () {
90
+ var body;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0: return [4 /*yield*/, response.text()];
94
+ case 1:
95
+ body = _a.sent();
96
+ if (!response.ok) {
97
+ throw new ResponseError(response.status, response.statusText, body);
98
+ }
99
+ return [2 /*return*/, body];
100
+ }
101
+ });
102
+ }); };
103
+ exports.toText = toText;
104
+ var toVoid = function (response) { return __awaiter(void 0, void 0, void 0, function () {
105
+ var body;
106
+ return __generator(this, function (_a) {
107
+ switch (_a.label) {
108
+ case 0:
109
+ if (!!response.ok) return [3 /*break*/, 2];
110
+ return [4 /*yield*/, response.text()];
111
+ case 1:
112
+ body = _a.sent();
113
+ throw new ResponseError(response.status, response.statusText, body);
114
+ case 2: return [2 /*return*/];
115
+ }
116
+ });
117
+ }); };
118
+ exports.toVoid = toVoid;
@@ -0,0 +1,10 @@
1
+ import { Response } from './fetch-responses.js';
2
+ export declare const toResponse: (status: number, statusText: string, body: string) => Promise<Response>;
3
+ declare type FetchFunction = () => Promise<Response>;
4
+ export declare const okJSONResponse: (body: unknown) => FetchFunction;
5
+ export declare const internalServerErrorJSONResponse: (body: unknown) => FetchFunction;
6
+ export declare const notFoundJSONResponse: (body: unknown) => FetchFunction;
7
+ export declare const okTextResponse: (body: string) => FetchFunction;
8
+ export declare const internalServerErrorTextResponse: (body: string) => FetchFunction;
9
+ export {};
10
+ //# sourceMappingURL=fetch.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.test.d.ts","sourceRoot":"","sources":["../../src/services/fetch.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C,eAAO,MAAM,UAAU,WAAY,MAAM,cAAc,MAAM,QAAQ,MAAM,KAAG,QAAQ,QAAQ,CAO1F,CAAC;AAEL,aAAK,aAAa,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE7C,eAAO,MAAM,cAAc,SAAU,OAAO,KAAG,aACF,CAAC;AAE9C,eAAO,MAAM,+BAA+B,SAAU,OAAO,KAAG,aACF,CAAC;AAE/D,eAAO,MAAM,oBAAoB,SAAU,OAAO,KAAG,aACD,CAAC;AAErD,eAAO,MAAM,cAAc,SAAU,MAAM,KAAG,aAAkD,CAAC;AAEjG,eAAO,MAAM,+BAA+B,SAAU,MAAM,KAAG,aACjB,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.internalServerErrorTextResponse = exports.okTextResponse = exports.notFoundJSONResponse = exports.internalServerErrorJSONResponse = exports.okJSONResponse = exports.toResponse = void 0;
4
+ var toResponse = function (status, statusText, body) {
5
+ return Promise.resolve({
6
+ ok: status < 400,
7
+ status: status,
8
+ statusText: statusText,
9
+ json: function () { return Promise.resolve(body).then(JSON.parse); },
10
+ text: function () { return Promise.resolve(body); }
11
+ });
12
+ };
13
+ exports.toResponse = toResponse;
14
+ var okJSONResponse = function (body) { return function () {
15
+ return (0, exports.toResponse)(200, 'OK', JSON.stringify(body));
16
+ }; };
17
+ exports.okJSONResponse = okJSONResponse;
18
+ var internalServerErrorJSONResponse = function (body) { return function () {
19
+ return (0, exports.toResponse)(500, 'InternalServerError', JSON.stringify(body));
20
+ }; };
21
+ exports.internalServerErrorJSONResponse = internalServerErrorJSONResponse;
22
+ var notFoundJSONResponse = function (body) { return function () {
23
+ return (0, exports.toResponse)(404, 'Not Found', JSON.stringify(body));
24
+ }; };
25
+ exports.notFoundJSONResponse = notFoundJSONResponse;
26
+ var okTextResponse = function (body) { return function () { return (0, exports.toResponse)(200, 'OK', body); }; };
27
+ exports.okTextResponse = okTextResponse;
28
+ var internalServerErrorTextResponse = function (body) { return function () {
29
+ return (0, exports.toResponse)(500, 'InternalServerError', body);
30
+ }; };
31
+ exports.internalServerErrorTextResponse = internalServerErrorTextResponse;