@coorpacademy/app-review 0.0.13 → 0.0.14-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/actions/navigation.d.ts +7 -0
- package/es/actions/navigation.d.ts.map +1 -1
- package/es/actions/navigation.js +5 -0
- package/es/configure-store.d.ts +2 -1
- package/es/configure-store.d.ts.map +1 -1
- package/es/configure-store.js +1 -1
- package/es/index.d.ts +7 -3
- package/es/index.d.ts.map +1 -1
- package/es/index.js +4 -4
- package/es/reducers/index.d.ts +1 -0
- package/es/reducers/index.d.ts.map +1 -1
- package/es/reducers/index.js +3 -1
- package/es/reducers/navigation.d.ts.map +1 -1
- package/es/reducers/navigation.js +3 -0
- package/es/reducers/token.d.ts +7 -0
- package/es/reducers/token.d.ts.map +1 -0
- package/es/reducers/token.js +16 -0
- package/es/services/fetch-demo.d.ts +3 -0
- package/es/services/fetch-demo.d.ts.map +1 -0
- package/es/services/fetch-demo.js +24 -0
- package/es/services/fetch-demo.test.d.ts +2 -0
- package/es/services/fetch-demo.test.d.ts.map +1 -0
- package/es/services/fetch-demo.test.js +11 -0
- package/lib/actions/navigation.d.ts +7 -0
- package/lib/actions/navigation.d.ts.map +1 -1
- package/lib/actions/navigation.js +7 -1
- package/lib/configure-store.d.ts +2 -1
- package/lib/configure-store.d.ts.map +1 -1
- package/lib/configure-store.js +1 -1
- package/lib/index.d.ts +7 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -3
- package/lib/reducers/index.d.ts +1 -0
- package/lib/reducers/index.d.ts.map +1 -1
- package/lib/reducers/index.js +3 -1
- package/lib/reducers/navigation.d.ts.map +1 -1
- package/lib/reducers/navigation.js +3 -0
- package/lib/reducers/token.d.ts +7 -0
- package/lib/reducers/token.d.ts.map +1 -0
- package/lib/reducers/token.js +21 -0
- package/lib/services/fetch-demo.d.ts +3 -0
- package/lib/services/fetch-demo.d.ts.map +1 -0
- package/lib/services/fetch-demo.js +74 -0
- package/lib/services/fetch-demo.test.d.ts +2 -0
- package/lib/services/fetch-demo.test.d.ts.map +1 -0
- package/lib/services/fetch-demo.test.js +58 -0
- package/package.json +9 -4
- package/readme.md +21 -0
- package/src/actions/navigation.ts +12 -0
- package/src/configure-store.ts +1 -1
- package/src/index.tsx +10 -3
- package/src/reducers/index.ts +3 -1
- package/src/reducers/navigation.ts +9 -1
- package/src/reducers/token.ts +27 -0
- package/src/services/fetch-demo.test.ts +13 -0
- package/src/services/fetch-demo.ts +48 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ActionCreator } from 'redux';
|
|
2
|
+
import { AppOptions } from '..';
|
|
2
3
|
export declare const NAVIGATE_TO = "@@navigation/NAVIGATE_TO";
|
|
3
4
|
export declare const NAVIGATE_BACK = "@@navigation/NAVIGATE_BACK";
|
|
5
|
+
export declare const START_APP = "@@navigation/START_APP";
|
|
4
6
|
export declare type $NAVIGATE_TO = {
|
|
5
7
|
type: '@@navigation/NAVIGATE_TO';
|
|
6
8
|
payload: string;
|
|
@@ -8,6 +10,11 @@ export declare type $NAVIGATE_TO = {
|
|
|
8
10
|
export declare type $NAVIGATE_BACK = {
|
|
9
11
|
type: '@@navigation/NAVIGATE_BACK';
|
|
10
12
|
};
|
|
13
|
+
export declare type $START_APP = {
|
|
14
|
+
type: '@@navigation/START_APP';
|
|
15
|
+
payload: AppOptions;
|
|
16
|
+
};
|
|
11
17
|
export declare const navigateTo: ActionCreator<$NAVIGATE_TO>;
|
|
12
18
|
export declare const navigateBack: ActionCreator<$NAVIGATE_BACK>;
|
|
19
|
+
export declare const startApp: (options: AppOptions) => $START_APP;
|
|
13
20
|
//# sourceMappingURL=navigation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/actions/navigation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/actions/navigation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AACpC,OAAO,EAAC,UAAU,EAAC,MAAM,IAAI,CAAC;AAE9B,eAAO,MAAM,WAAW,6BAA6B,CAAC;AACtD,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAC1D,eAAO,MAAM,SAAS,2BAA2B,CAAC;AAElD,oBAAY,YAAY,GAAG;IACzB,IAAI,EAAE,0BAA0B,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,oBAAY,cAAc,GAAG;IAC3B,IAAI,EAAE,4BAA4B,CAAC;CACpC,CAAC;AAEF,oBAAY,UAAU,GAAG;IACvB,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,aAAa,CAAC,YAAY,CAGjD,CAAC;AAEH,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC,cAAc,CAErD,CAAC;AAEH,eAAO,MAAM,QAAQ,YAAa,UAAU,KAAG,UAG7C,CAAC"}
|
package/es/actions/navigation.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const NAVIGATE_TO = '@@navigation/NAVIGATE_TO';
|
|
2
2
|
export const NAVIGATE_BACK = '@@navigation/NAVIGATE_BACK';
|
|
3
|
+
export const START_APP = '@@navigation/START_APP';
|
|
3
4
|
export const navigateTo = (newPath) => ({
|
|
4
5
|
type: NAVIGATE_TO,
|
|
5
6
|
payload: newPath
|
|
@@ -7,3 +8,7 @@ export const navigateTo = (newPath) => ({
|
|
|
7
8
|
export const navigateBack = () => ({
|
|
8
9
|
type: NAVIGATE_BACK
|
|
9
10
|
});
|
|
11
|
+
export const startApp = (options) => ({
|
|
12
|
+
type: START_APP,
|
|
13
|
+
payload: options
|
|
14
|
+
});
|
package/es/configure-store.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export default function configureStore(
|
|
1
|
+
export default function configureStore(): import("redux").Store<import("redux").EmptyObject & {
|
|
2
2
|
navigation: import("./reducers/navigation").State;
|
|
3
|
+
token: string;
|
|
3
4
|
}, import("redux").AnyAction> & {
|
|
4
5
|
dispatch: unknown;
|
|
5
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure-store.d.ts","sourceRoot":"","sources":["../src/configure-store.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,UAAU,cAAc
|
|
1
|
+
{"version":3,"file":"configure-store.d.ts","sourceRoot":"","sources":["../src/configure-store.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,UAAU,cAAc;;;;;EAcrC"}
|
package/es/configure-store.js
CHANGED
|
@@ -3,7 +3,7 @@ import thunk from 'redux-thunk';
|
|
|
3
3
|
import { composeWithDevTools } from 'redux-devtools-extension';
|
|
4
4
|
import rootReducer from './reducers';
|
|
5
5
|
const preloadedState = undefined;
|
|
6
|
-
export default function configureStore(
|
|
6
|
+
export default function configureStore() {
|
|
7
7
|
const _compose = process.env.NODE_ENV !== 'production'
|
|
8
8
|
? composeWithDevTools({
|
|
9
9
|
name: 'app-review',
|
package/es/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
declare const AppRevision: ({
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
};
|
|
4
8
|
export default AppRevision;
|
|
5
9
|
//# sourceMappingURL=index.d.ts.map
|
package/es/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAmBA,QAAA,MAAM,WAAW
|
|
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;CACf,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/es/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
|
|
|
2
2
|
import { connect, Provider } from 'react-redux';
|
|
3
3
|
import AppReviewRootView from '@coorpacademy/components/es/template/app-review/root-view/root-view';
|
|
4
4
|
import configureStore from './configure-store';
|
|
5
|
-
import { navigateTo, navigateBack } from './actions/navigation';
|
|
5
|
+
import { navigateTo, navigateBack, startApp } from './actions/navigation';
|
|
6
6
|
import { getCurrentViewName } from './reducers/navigation';
|
|
7
7
|
// -----------------------------------------------------------------------------
|
|
8
8
|
const mapStateToProps = (state, ownProps) => {
|
|
@@ -11,10 +11,11 @@ const mapStateToProps = (state, ownProps) => {
|
|
|
11
11
|
const mapDispatchToProps = { navigateTo, navigateBack };
|
|
12
12
|
const App = connect(mapStateToProps, mapDispatchToProps)(AppReviewRootView);
|
|
13
13
|
// -----------------------------------------------------------------------------
|
|
14
|
-
const AppRevision = ({
|
|
14
|
+
const AppRevision = ({ options }) => {
|
|
15
15
|
const [store, setStore] = useState(null);
|
|
16
16
|
useEffect(() => {
|
|
17
|
-
const store = configureStore(
|
|
17
|
+
const store = configureStore();
|
|
18
|
+
store.dispatch(startApp(options));
|
|
18
19
|
setStore(store);
|
|
19
20
|
}, []);
|
|
20
21
|
if (!store)
|
|
@@ -22,5 +23,4 @@ const AppRevision = ({ services }) => {
|
|
|
22
23
|
return (React.createElement(Provider, { store: store },
|
|
23
24
|
React.createElement(App, null)));
|
|
24
25
|
};
|
|
25
|
-
// -----------------------------------------------------------------------------
|
|
26
26
|
export default AppRevision;
|
package/es/reducers/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reducers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reducers/index.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,WAAW;;;8BAGf,CAAC;AAEH,eAAe,WAAW,CAAC"}
|
package/es/reducers/index.js
CHANGED
|
@@ -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;
|
|
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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NAVIGATE_BACK, NAVIGATE_TO } from '../actions/navigation';
|
|
2
2
|
export const initialState = ['home'];
|
|
3
|
+
// -----------------------------------------------------------------------------
|
|
3
4
|
const reducer = (state = initialState, action) => {
|
|
4
5
|
switch (action.type) {
|
|
5
6
|
case NAVIGATE_TO: {
|
|
@@ -14,5 +15,7 @@ const reducer = (state = initialState, action) => {
|
|
|
14
15
|
return state;
|
|
15
16
|
}
|
|
16
17
|
};
|
|
18
|
+
// -----------------------------------------------------------------------------
|
|
17
19
|
export const getCurrentViewName = appState => appState.navigation[appState.navigation.length - 1];
|
|
20
|
+
// -----------------------------------------------------------------------------
|
|
18
21
|
export default reducer;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { $START_APP } from '../actions/navigation';
|
|
2
|
+
export declare type State = string;
|
|
3
|
+
export declare const initialState: State;
|
|
4
|
+
declare const reducer: (state: State, action: $START_APP) => 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":"AACA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAItD,oBAAY,KAAK,GAAG,MAAM,CAAC;AAC3B,eAAO,MAAM,YAAY,EAAE,KAAY,CAAC;AAIxC,QAAA,MAAM,OAAO,UAAW,KAAK,UAAyB,UAAU,KAAG,KAQlE,CAAC;AAIF,eAAO,MAAM,QAAQ,wBAA6B,CAAC;AAInD,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { START_APP } from '../actions/navigation';
|
|
2
|
+
export const initialState = null;
|
|
3
|
+
// -----------------------------------------------------------------------------
|
|
4
|
+
const reducer = (state = initialState, action) => {
|
|
5
|
+
switch (action.type) {
|
|
6
|
+
case START_APP: {
|
|
7
|
+
return action.payload.token;
|
|
8
|
+
}
|
|
9
|
+
default:
|
|
10
|
+
return state;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
// -----------------------------------------------------------------------------
|
|
14
|
+
export const getToken = appState => appState.token;
|
|
15
|
+
// -----------------------------------------------------------------------------
|
|
16
|
+
export default reducer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-demo.d.ts","sourceRoot":"","sources":["../../src/services/fetch-demo.ts"],"names":[],"mappings":"AA6BA,QAAA,MAAM,WAAW,gEAchB,CAAC;AAIF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fetch from 'cross-fetch';
|
|
2
|
+
import decode from 'jwt-decode';
|
|
3
|
+
const buildUrlQueryParams = (params) => Object.keys(params)
|
|
4
|
+
.map(key => {
|
|
5
|
+
const value = params[key].toString();
|
|
6
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
7
|
+
})
|
|
8
|
+
.join('&');
|
|
9
|
+
// -----------------------------------------------------------------------------
|
|
10
|
+
const fetchCourse = async (token, language, universalRef) => {
|
|
11
|
+
const jwt = decode(token);
|
|
12
|
+
const query = {
|
|
13
|
+
type: 'course',
|
|
14
|
+
universalRef,
|
|
15
|
+
lang: language
|
|
16
|
+
};
|
|
17
|
+
const response = await fetch(`${jwt.host}/api/v2/contents?${buildUrlQueryParams(query)}`, {
|
|
18
|
+
headers: { authorization: token }
|
|
19
|
+
});
|
|
20
|
+
const { hits } = await response.json();
|
|
21
|
+
return hits?.[0];
|
|
22
|
+
};
|
|
23
|
+
// -----------------------------------------------------------------------------
|
|
24
|
+
export default fetchCourse;
|
|
@@ -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,11 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import fetchCourse from './fetch-demo.js';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
dotenv.config();
|
|
5
|
+
test('should fetch a demo course with mobile-staging dev token', async (t) => {
|
|
6
|
+
const token = process.env.API_TEST_TOKEN;
|
|
7
|
+
const language = 'fr';
|
|
8
|
+
const universalRef = 'dis_NkAPG3m4U';
|
|
9
|
+
const course = await fetchCourse(token, language, universalRef);
|
|
10
|
+
t.is(course.title, 'March-ing towards a greener tomorrow');
|
|
11
|
+
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ActionCreator } from 'redux';
|
|
2
|
+
import { AppOptions } from '..';
|
|
2
3
|
export declare const NAVIGATE_TO = "@@navigation/NAVIGATE_TO";
|
|
3
4
|
export declare const NAVIGATE_BACK = "@@navigation/NAVIGATE_BACK";
|
|
5
|
+
export declare const START_APP = "@@navigation/START_APP";
|
|
4
6
|
export declare type $NAVIGATE_TO = {
|
|
5
7
|
type: '@@navigation/NAVIGATE_TO';
|
|
6
8
|
payload: string;
|
|
@@ -8,6 +10,11 @@ export declare type $NAVIGATE_TO = {
|
|
|
8
10
|
export declare type $NAVIGATE_BACK = {
|
|
9
11
|
type: '@@navigation/NAVIGATE_BACK';
|
|
10
12
|
};
|
|
13
|
+
export declare type $START_APP = {
|
|
14
|
+
type: '@@navigation/START_APP';
|
|
15
|
+
payload: AppOptions;
|
|
16
|
+
};
|
|
11
17
|
export declare const navigateTo: ActionCreator<$NAVIGATE_TO>;
|
|
12
18
|
export declare const navigateBack: ActionCreator<$NAVIGATE_BACK>;
|
|
19
|
+
export declare const startApp: (options: AppOptions) => $START_APP;
|
|
13
20
|
//# sourceMappingURL=navigation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/actions/navigation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/actions/navigation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AACpC,OAAO,EAAC,UAAU,EAAC,MAAM,IAAI,CAAC;AAE9B,eAAO,MAAM,WAAW,6BAA6B,CAAC;AACtD,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAC1D,eAAO,MAAM,SAAS,2BAA2B,CAAC;AAElD,oBAAY,YAAY,GAAG;IACzB,IAAI,EAAE,0BAA0B,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,oBAAY,cAAc,GAAG;IAC3B,IAAI,EAAE,4BAA4B,CAAC;CACpC,CAAC;AAEF,oBAAY,UAAU,GAAG;IACvB,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,aAAa,CAAC,YAAY,CAGjD,CAAC;AAEH,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC,cAAc,CAErD,CAAC;AAEH,eAAO,MAAM,QAAQ,YAAa,UAAU,KAAG,UAG7C,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.navigateBack = exports.navigateTo = exports.NAVIGATE_BACK = exports.NAVIGATE_TO = void 0;
|
|
3
|
+
exports.startApp = exports.navigateBack = exports.navigateTo = exports.START_APP = exports.NAVIGATE_BACK = exports.NAVIGATE_TO = void 0;
|
|
4
4
|
exports.NAVIGATE_TO = '@@navigation/NAVIGATE_TO';
|
|
5
5
|
exports.NAVIGATE_BACK = '@@navigation/NAVIGATE_BACK';
|
|
6
|
+
exports.START_APP = '@@navigation/START_APP';
|
|
6
7
|
var navigateTo = function (newPath) { return ({
|
|
7
8
|
type: exports.NAVIGATE_TO,
|
|
8
9
|
payload: newPath
|
|
@@ -12,3 +13,8 @@ var navigateBack = function () { return ({
|
|
|
12
13
|
type: exports.NAVIGATE_BACK
|
|
13
14
|
}); };
|
|
14
15
|
exports.navigateBack = navigateBack;
|
|
16
|
+
var startApp = function (options) { return ({
|
|
17
|
+
type: exports.START_APP,
|
|
18
|
+
payload: options
|
|
19
|
+
}); };
|
|
20
|
+
exports.startApp = startApp;
|
package/lib/configure-store.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export default function configureStore(
|
|
1
|
+
export default function configureStore(): import("redux").Store<import("redux").EmptyObject & {
|
|
2
2
|
navigation: import("./reducers/navigation").State;
|
|
3
|
+
token: string;
|
|
3
4
|
}, import("redux").AnyAction> & {
|
|
4
5
|
dispatch: unknown;
|
|
5
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure-store.d.ts","sourceRoot":"","sources":["../src/configure-store.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,UAAU,cAAc
|
|
1
|
+
{"version":3,"file":"configure-store.d.ts","sourceRoot":"","sources":["../src/configure-store.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO,UAAU,cAAc;;;;;EAcrC"}
|
package/lib/configure-store.js
CHANGED
|
@@ -5,7 +5,7 @@ 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
7
|
var preloadedState = undefined;
|
|
8
|
-
function configureStore(
|
|
8
|
+
function configureStore() {
|
|
9
9
|
var _compose = process.env.NODE_ENV !== 'production'
|
|
10
10
|
? (0, redux_devtools_extension_1.composeWithDevTools)({
|
|
11
11
|
name: 'app-review',
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
declare const AppRevision: ({
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
};
|
|
4
8
|
export default AppRevision;
|
|
5
9
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAmBA,QAAA,MAAM,WAAW
|
|
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;CACf,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
|
|
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)(
|
|
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;
|
package/lib/reducers/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reducers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reducers/index.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,WAAW;;;8BAGf,CAAC;AAEH,eAAe,WAAW,CAAC"}
|
package/lib/reducers/index.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var redux_1 = require("redux");
|
|
4
4
|
var navigation_1 = require("./navigation");
|
|
5
|
+
var token_1 = require("./token");
|
|
5
6
|
var rootReducer = (0, redux_1.combineReducers)({
|
|
6
|
-
navigation: navigation_1.default
|
|
7
|
+
navigation: navigation_1.default,
|
|
8
|
+
token: token_1.default
|
|
7
9
|
});
|
|
8
10
|
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;
|
|
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 type { $START_APP } from '../actions/navigation';
|
|
2
|
+
export declare type State = string;
|
|
3
|
+
export declare const initialState: State;
|
|
4
|
+
declare const reducer: (state: State, action: $START_APP) => 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":"AACA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAItD,oBAAY,KAAK,GAAG,MAAM,CAAC;AAC3B,eAAO,MAAM,YAAY,EAAE,KAAY,CAAC;AAIxC,QAAA,MAAM,OAAO,UAAW,KAAK,UAAyB,UAAU,KAAG,KAQlE,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 navigation_1 = require("../actions/navigation");
|
|
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 navigation_1.START_APP: {
|
|
11
|
+
return action.payload.token;
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-demo.d.ts","sourceRoot":"","sources":["../../src/services/fetch-demo.ts"],"names":[],"mappings":"AA6BA,QAAA,MAAM,WAAW,gEAchB,CAAC;AAIF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 cross_fetch_1 = require("cross-fetch");
|
|
40
|
+
var jwt_decode_1 = require("jwt-decode");
|
|
41
|
+
var buildUrlQueryParams = function (params) {
|
|
42
|
+
return Object.keys(params)
|
|
43
|
+
.map(function (key) {
|
|
44
|
+
var value = params[key].toString();
|
|
45
|
+
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
|
|
46
|
+
})
|
|
47
|
+
.join('&');
|
|
48
|
+
};
|
|
49
|
+
// -----------------------------------------------------------------------------
|
|
50
|
+
var fetchCourse = function (token, language, universalRef) { return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
+
var jwt, query, response, hits;
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0:
|
|
55
|
+
jwt = (0, jwt_decode_1.default)(token);
|
|
56
|
+
query = {
|
|
57
|
+
type: 'course',
|
|
58
|
+
universalRef: universalRef,
|
|
59
|
+
lang: language
|
|
60
|
+
};
|
|
61
|
+
return [4 /*yield*/, (0, cross_fetch_1.default)("".concat(jwt.host, "/api/v2/contents?").concat(buildUrlQueryParams(query)), {
|
|
62
|
+
headers: { authorization: token }
|
|
63
|
+
})];
|
|
64
|
+
case 1:
|
|
65
|
+
response = _a.sent();
|
|
66
|
+
return [4 /*yield*/, response.json()];
|
|
67
|
+
case 2:
|
|
68
|
+
hits = (_a.sent()).hits;
|
|
69
|
+
return [2 /*return*/, hits === null || hits === void 0 ? void 0 : hits[0]];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}); };
|
|
73
|
+
// -----------------------------------------------------------------------------
|
|
74
|
+
exports.default = fetchCourse;
|
|
@@ -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,58 @@
|
|
|
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 dotenv_1 = require("dotenv");
|
|
42
|
+
dotenv_1.default.config();
|
|
43
|
+
(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 () {
|
|
44
|
+
var token, language, universalRef, course;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
token = process.env.API_TEST_TOKEN;
|
|
49
|
+
language = 'fr';
|
|
50
|
+
universalRef = 'dis_NkAPG3m4U';
|
|
51
|
+
return [4 /*yield*/, (0, fetch_demo_js_1.default)(token, language, universalRef)];
|
|
52
|
+
case 1:
|
|
53
|
+
course = _a.sent();
|
|
54
|
+
t.is(course.title, 'March-ing towards a greener tomorrow');
|
|
55
|
+
return [2 /*return*/];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}); });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coorpacademy/app-review",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14-alpha.1+043eda124",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"clean:commonjs": "rm -rf lib",
|
|
18
18
|
"clean:es": "rm -rf es",
|
|
19
19
|
"clean": "concurrently \"npm run clean:commonjs\" \"npm run clean:es\"",
|
|
20
|
-
"test:unit": "
|
|
20
|
+
"test:unit": "ava --config ava.config.cjs"
|
|
21
21
|
},
|
|
22
22
|
"author": "CoorpAcademy",
|
|
23
23
|
"files": [
|
|
@@ -36,17 +36,22 @@
|
|
|
36
36
|
"./package.json": "./package.json"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@coorpacademy/components": "10.19.
|
|
39
|
+
"@coorpacademy/components": "10.19.6-alpha.1+043eda124",
|
|
40
|
+
"cross-fetch": "^3.1.5",
|
|
41
|
+
"jwt-decode": "^3.1.2",
|
|
40
42
|
"react": "^17.0.2",
|
|
41
43
|
"react-native": "0.68.1",
|
|
42
44
|
"react-redux": "^8.0.1",
|
|
43
45
|
"redux": "^4.2.0"
|
|
44
46
|
},
|
|
45
47
|
"devDependencies": {
|
|
48
|
+
"@ava/typescript": "^3.0.1",
|
|
46
49
|
"@storybook/react-native": "^5.3.25",
|
|
50
|
+
"ava": "^4.2.0",
|
|
47
51
|
"chalk": "^5.0.1",
|
|
48
52
|
"concurrently": "^5.2.0",
|
|
49
53
|
"connect-history-api-fallback": "^1.6.0",
|
|
54
|
+
"dotenv": "^16.0.1",
|
|
50
55
|
"esbuild": "^0.14.39",
|
|
51
56
|
"esbuild-css-modules-plugin": "^2.2.16",
|
|
52
57
|
"esbuild-plugin-svgr": "^1.0.1",
|
|
@@ -55,5 +60,5 @@
|
|
|
55
60
|
"redux-devtools-extension": "^2.13.9",
|
|
56
61
|
"typescript": "^4.6.4"
|
|
57
62
|
},
|
|
58
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "043eda1241ca74e6287fdee59cf7479a5cf4f2e6"
|
|
59
64
|
}
|
package/readme.md
CHANGED
|
@@ -14,6 +14,22 @@ npm run static
|
|
|
14
14
|
|
|
15
15
|
(This script is generated by lerna to publish the static web app)
|
|
16
16
|
|
|
17
|
+
## unit tests
|
|
18
|
+
|
|
19
|
+
(requirements: duplicate `.env.sample` to `.env` and ask for the tokens)
|
|
20
|
+
|
|
21
|
+
Open a terminal and run a compilation in watch mode:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm run build:es -- --watch
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Now open a 2nd terminal and run ava in watch mode:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npx ava --watch
|
|
31
|
+
```
|
|
32
|
+
|
|
17
33
|
## dependencies notes
|
|
18
34
|
|
|
19
35
|
`react-native` must be the same version on this package and the rootApp
|
|
@@ -25,3 +41,8 @@ npm run static
|
|
|
25
41
|
### tmp notes
|
|
26
42
|
|
|
27
43
|
export: <https://stackoverflow.com/a/70020984/959219>
|
|
44
|
+
|
|
45
|
+
css modules:
|
|
46
|
+
|
|
47
|
+
- <https://github.com/evanw/esbuild/issues/20>
|
|
48
|
+
- <https://github.com/indooorsman/esbuild-css-modules-plugin/issues/35>
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {ActionCreator} from 'redux';
|
|
2
|
+
import {AppOptions} from '..';
|
|
2
3
|
|
|
3
4
|
export const NAVIGATE_TO = '@@navigation/NAVIGATE_TO';
|
|
4
5
|
export const NAVIGATE_BACK = '@@navigation/NAVIGATE_BACK';
|
|
6
|
+
export const START_APP = '@@navigation/START_APP';
|
|
5
7
|
|
|
6
8
|
export type $NAVIGATE_TO = {
|
|
7
9
|
type: '@@navigation/NAVIGATE_TO';
|
|
@@ -12,6 +14,11 @@ export type $NAVIGATE_BACK = {
|
|
|
12
14
|
type: '@@navigation/NAVIGATE_BACK';
|
|
13
15
|
};
|
|
14
16
|
|
|
17
|
+
export type $START_APP = {
|
|
18
|
+
type: '@@navigation/START_APP';
|
|
19
|
+
payload: AppOptions;
|
|
20
|
+
};
|
|
21
|
+
|
|
15
22
|
export const navigateTo: ActionCreator<$NAVIGATE_TO> = (newPath: string) => ({
|
|
16
23
|
type: NAVIGATE_TO,
|
|
17
24
|
payload: newPath
|
|
@@ -20,3 +27,8 @@ export const navigateTo: ActionCreator<$NAVIGATE_TO> = (newPath: string) => ({
|
|
|
20
27
|
export const navigateBack: ActionCreator<$NAVIGATE_BACK> = () => ({
|
|
21
28
|
type: NAVIGATE_BACK
|
|
22
29
|
});
|
|
30
|
+
|
|
31
|
+
export const startApp = (options: AppOptions): $START_APP => ({
|
|
32
|
+
type: START_APP,
|
|
33
|
+
payload: options
|
|
34
|
+
});
|
package/src/configure-store.ts
CHANGED
package/src/index.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import {connect, Provider} from 'react-redux';
|
|
|
3
3
|
import AppReviewRootView from '@coorpacademy/components/es/template/app-review/root-view/root-view';
|
|
4
4
|
|
|
5
5
|
import configureStore from './configure-store';
|
|
6
|
-
import {navigateTo, navigateBack} from './actions/navigation';
|
|
6
|
+
import {navigateTo, navigateBack, startApp} from './actions/navigation';
|
|
7
7
|
import {getCurrentViewName} from './reducers/navigation';
|
|
8
8
|
|
|
9
9
|
// -----------------------------------------------------------------------------
|
|
@@ -17,11 +17,12 @@ const App = connect(mapStateToProps, mapDispatchToProps)(AppReviewRootView);
|
|
|
17
17
|
|
|
18
18
|
// -----------------------------------------------------------------------------
|
|
19
19
|
|
|
20
|
-
const AppRevision = ({
|
|
20
|
+
const AppRevision = ({options}: Props) => {
|
|
21
21
|
const [store, setStore] = useState(null);
|
|
22
22
|
|
|
23
23
|
useEffect(() => {
|
|
24
|
-
const store = configureStore(
|
|
24
|
+
const store = configureStore();
|
|
25
|
+
store.dispatch(startApp(options));
|
|
25
26
|
setStore(store);
|
|
26
27
|
}, []);
|
|
27
28
|
|
|
@@ -36,4 +37,10 @@ const AppRevision = ({services}) => {
|
|
|
36
37
|
|
|
37
38
|
// -----------------------------------------------------------------------------
|
|
38
39
|
|
|
40
|
+
type Props = {options: AppOptions};
|
|
41
|
+
|
|
42
|
+
export type AppOptions = {
|
|
43
|
+
token: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
39
46
|
export default AppRevision;
|
package/src/reducers/index.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {NAVIGATE_BACK, NAVIGATE_TO} from '../actions/navigation';
|
|
2
2
|
import type {$NAVIGATE_TO, $NAVIGATE_BACK} from '../actions/navigation';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// -----------------------------------------------------------------------------
|
|
5
5
|
|
|
6
|
+
export type State = Array<string>;
|
|
6
7
|
export const initialState: State = ['home'];
|
|
7
8
|
|
|
9
|
+
// -----------------------------------------------------------------------------
|
|
10
|
+
|
|
8
11
|
const reducer = (state: State = initialState, action: $NAVIGATE_TO | $NAVIGATE_BACK): State => {
|
|
9
12
|
switch (action.type) {
|
|
10
13
|
case NAVIGATE_TO: {
|
|
@@ -20,5 +23,10 @@ const reducer = (state: State = initialState, action: $NAVIGATE_TO | $NAVIGATE_B
|
|
|
20
23
|
}
|
|
21
24
|
};
|
|
22
25
|
|
|
26
|
+
// -----------------------------------------------------------------------------
|
|
27
|
+
|
|
23
28
|
export const getCurrentViewName = appState => appState.navigation[appState.navigation.length - 1];
|
|
29
|
+
|
|
30
|
+
// -----------------------------------------------------------------------------
|
|
31
|
+
|
|
24
32
|
export default reducer;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {START_APP} from '../actions/navigation';
|
|
2
|
+
import type {$START_APP} from '../actions/navigation';
|
|
3
|
+
|
|
4
|
+
// -----------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
export type State = string;
|
|
7
|
+
export const initialState: State = null;
|
|
8
|
+
|
|
9
|
+
// -----------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const reducer = (state: State = initialState, action: $START_APP): State => {
|
|
12
|
+
switch (action.type) {
|
|
13
|
+
case START_APP: {
|
|
14
|
+
return action.payload.token;
|
|
15
|
+
}
|
|
16
|
+
default:
|
|
17
|
+
return state;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// -----------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
export const getToken = appState => appState.token;
|
|
24
|
+
|
|
25
|
+
// -----------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
export default reducer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import fetchCourse from './fetch-demo.js';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
dotenv.config();
|
|
5
|
+
|
|
6
|
+
test('should fetch a demo course with mobile-staging dev token', async t => {
|
|
7
|
+
const token = process.env.API_TEST_TOKEN;
|
|
8
|
+
const language = 'fr';
|
|
9
|
+
const universalRef = 'dis_NkAPG3m4U';
|
|
10
|
+
|
|
11
|
+
const course = await fetchCourse(token, language, universalRef);
|
|
12
|
+
t.is(course.title, 'March-ing towards a greener tomorrow');
|
|
13
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fetch from 'cross-fetch';
|
|
2
|
+
import decode from 'jwt-decode';
|
|
3
|
+
|
|
4
|
+
// -----------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
type JWT = {
|
|
7
|
+
exp: number;
|
|
8
|
+
iat: number;
|
|
9
|
+
grants: unknown;
|
|
10
|
+
iss: string;
|
|
11
|
+
user: string;
|
|
12
|
+
usage: string;
|
|
13
|
+
host: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type QueryParams = {
|
|
17
|
+
[key: string]: string | number | boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const buildUrlQueryParams = (params: QueryParams) =>
|
|
21
|
+
Object.keys(params)
|
|
22
|
+
.map(key => {
|
|
23
|
+
const value = params[key].toString();
|
|
24
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
25
|
+
})
|
|
26
|
+
.join('&');
|
|
27
|
+
|
|
28
|
+
// -----------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
const fetchCourse = async (token, language, universalRef) => {
|
|
31
|
+
const jwt: JWT = decode(token);
|
|
32
|
+
const query = {
|
|
33
|
+
type: 'course',
|
|
34
|
+
universalRef,
|
|
35
|
+
lang: language
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const response = await fetch(`${jwt.host}/api/v2/contents?${buildUrlQueryParams(query)}`, {
|
|
39
|
+
headers: {authorization: token}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const {hits} = await response.json();
|
|
43
|
+
return hits?.[0];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// -----------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
export default fetchCourse;
|