@zeniai/client-epic-state 5.0.31 → 5.0.32-betaRD1
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/lib/entity/tenant/clearAllEpic.d.ts +2 -1
- package/lib/entity/tenant/clearAllEpic.js +2 -0
- package/lib/entity/transaction/payloadTypes/transactionLinePayload.js +1 -1
- package/lib/epic.d.ts +2 -1
- package/lib/epic.js +2 -1
- package/lib/esm/entity/tenant/clearAllEpic.js +2 -0
- package/lib/esm/entity/transaction/payloadTypes/transactionLinePayload.js +1 -1
- package/lib/esm/epic.js +2 -1
- package/lib/esm/index.js +4 -0
- package/lib/esm/reducer.js +3 -0
- package/lib/esm/view/zeniOAuthView/epics/approveOAuthConsentEpic.js +40 -0
- package/lib/esm/view/zeniOAuthView/zeniOAuthParamsParser.js +41 -0
- package/lib/esm/view/zeniOAuthView/zeniOAuthReducer.js +49 -0
- package/lib/esm/view/zeniOAuthView/zeniOAuthSelector.js +3 -0
- package/lib/esm/view/zeniOAuthView/zeniOAuthState.js +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +16 -4
- package/lib/reducer.d.ts +3 -0
- package/lib/reducer.js +3 -0
- package/lib/tsconfig.typecheck.tsbuildinfo +1 -1
- package/lib/view/zeniOAuthView/epics/approveOAuthConsentEpic.d.ts +14 -0
- package/lib/view/zeniOAuthView/epics/approveOAuthConsentEpic.js +44 -0
- package/lib/view/zeniOAuthView/zeniOAuthParamsParser.d.ts +16 -0
- package/lib/view/zeniOAuthView/zeniOAuthParamsParser.js +44 -0
- package/lib/view/zeniOAuthView/zeniOAuthReducer.d.ts +29 -0
- package/lib/view/zeniOAuthView/zeniOAuthReducer.js +53 -0
- package/lib/view/zeniOAuthView/zeniOAuthSelector.d.ts +5 -0
- package/lib/view/zeniOAuthView/zeniOAuthSelector.js +9 -0
- package/lib/view/zeniOAuthView/zeniOAuthState.d.ts +4 -0
- package/lib/view/zeniOAuthView/zeniOAuthState.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { RootState } from '../../../reducer';
|
|
3
|
+
import { ZeniAPI } from '../../../zeniAPI';
|
|
4
|
+
import { approveOAuthConsent, approveOAuthConsentFailure, approveOAuthConsentSuccess } from '../zeniOAuthReducer';
|
|
5
|
+
export type ActionType = ReturnType<typeof approveOAuthConsent> | ReturnType<typeof approveOAuthConsentSuccess> | ReturnType<typeof approveOAuthConsentFailure>;
|
|
6
|
+
export declare const approveOAuthConsentEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => import("rxjs").Observable<{
|
|
7
|
+
payload: {
|
|
8
|
+
redirectUrl: string;
|
|
9
|
+
};
|
|
10
|
+
type: "zeniOAuthView/approveOAuthConsentSuccess";
|
|
11
|
+
} | {
|
|
12
|
+
payload: import("../../../responsePayload").ZeniAPIStatus<Record<string, unknown>>;
|
|
13
|
+
type: "zeniOAuthView/approveOAuthConsentFailure";
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.approveOAuthConsentEpic = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const responsePayload_1 = require("../../../responsePayload");
|
|
7
|
+
const zeniOAuthReducer_1 = require("../zeniOAuthReducer");
|
|
8
|
+
const approveOAuthConsentEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(zeniOAuthReducer_1.approveOAuthConsent.match), (0, operators_1.switchMap)((action) => {
|
|
9
|
+
const { userId, zeniSessionId, tenantId, clientId, redirectUri, codeChallenge, codeChallengeMethod, state, responseType, } = action.payload;
|
|
10
|
+
const authHeaders = {
|
|
11
|
+
'zeni-user-id': userId,
|
|
12
|
+
'zeni-tenant-id': tenantId,
|
|
13
|
+
};
|
|
14
|
+
if (zeniSessionId != null) {
|
|
15
|
+
authHeaders['zeni-session-id'] = zeniSessionId;
|
|
16
|
+
}
|
|
17
|
+
return zeniAPI
|
|
18
|
+
.postJSON(`${zeniAPI.apiEndPoints.authMicroServiceBaseUrl}/oauth/authorize/approve`, {
|
|
19
|
+
client_id: clientId,
|
|
20
|
+
redirect_uri: redirectUri,
|
|
21
|
+
code_challenge: codeChallenge,
|
|
22
|
+
code_challenge_method: codeChallengeMethod,
|
|
23
|
+
state,
|
|
24
|
+
response_type: responseType,
|
|
25
|
+
tenant_id: tenantId,
|
|
26
|
+
}, authHeaders)
|
|
27
|
+
.pipe((0, operators_1.concatMap)((response) => (0, rxjs_1.from)(response.json()).pipe((0, operators_1.mergeMap)((responseJson) => {
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
const errBody = responseJson;
|
|
30
|
+
const errorMessage = errBody?.error ??
|
|
31
|
+
errBody?.message ??
|
|
32
|
+
errBody?.status?.message ??
|
|
33
|
+
`Authorization failed (${response.status})`;
|
|
34
|
+
return (0, rxjs_1.of)((0, zeniOAuthReducer_1.approveOAuthConsentFailure)((0, responsePayload_1.createZeniAPIStatus)(errorMessage)));
|
|
35
|
+
}
|
|
36
|
+
const body = responseJson;
|
|
37
|
+
const redirectUrl = body?.redirect_url ?? body?.data?.redirect_url;
|
|
38
|
+
if (redirectUrl == null || redirectUrl === '') {
|
|
39
|
+
return (0, rxjs_1.of)((0, zeniOAuthReducer_1.approveOAuthConsentFailure)((0, responsePayload_1.createZeniAPIStatus)('No redirect URL returned from authorization server')));
|
|
40
|
+
}
|
|
41
|
+
return (0, rxjs_1.of)((0, zeniOAuthReducer_1.approveOAuthConsentSuccess)({ redirectUrl }));
|
|
42
|
+
}))), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, zeniOAuthReducer_1.approveOAuthConsentFailure)((0, responsePayload_1.createZeniAPIStatus)('OAuth approve request failed: ' + JSON.stringify(error))))));
|
|
43
|
+
}));
|
|
44
|
+
exports.approveOAuthConsentEpic = approveOAuthConsentEpic;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface OAuthParams {
|
|
2
|
+
clientId: string;
|
|
3
|
+
codeChallenge: string;
|
|
4
|
+
codeChallengeMethod: string;
|
|
5
|
+
redirectUri: string;
|
|
6
|
+
responseType: string;
|
|
7
|
+
state: string;
|
|
8
|
+
}
|
|
9
|
+
export type ParseOAuthParamsResult = {
|
|
10
|
+
error: null;
|
|
11
|
+
params: OAuthParams;
|
|
12
|
+
} | {
|
|
13
|
+
error: string;
|
|
14
|
+
params: null;
|
|
15
|
+
};
|
|
16
|
+
export declare function parseOAuthParams(search: string): ParseOAuthParamsResult;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseOAuthParams = parseOAuthParams;
|
|
4
|
+
function parseOAuthParams(search) {
|
|
5
|
+
const searchParams = new URLSearchParams(search);
|
|
6
|
+
const clientId = searchParams.get('client_id');
|
|
7
|
+
const redirectUri = searchParams.get('redirect_uri');
|
|
8
|
+
const codeChallenge = searchParams.get('code_challenge');
|
|
9
|
+
const codeChallengeMethod = searchParams.get('code_challenge_method') ?? 'S256';
|
|
10
|
+
const state = searchParams.get('state');
|
|
11
|
+
const responseType = searchParams.get('response_type') ?? 'code';
|
|
12
|
+
if (clientId == null || clientId === '') {
|
|
13
|
+
return { params: null, error: 'Missing client_id parameter' };
|
|
14
|
+
}
|
|
15
|
+
if (redirectUri == null || redirectUri === '') {
|
|
16
|
+
return { params: null, error: 'Missing redirect_uri parameter' };
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
void new URL(redirectUri);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return { params: null, error: 'Invalid redirect_uri parameter' };
|
|
23
|
+
}
|
|
24
|
+
if (codeChallenge == null || codeChallenge === '') {
|
|
25
|
+
return {
|
|
26
|
+
params: null,
|
|
27
|
+
error: 'Missing code_challenge parameter (PKCE required)',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (state == null || state === '') {
|
|
31
|
+
return { params: null, error: 'Missing state parameter' };
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
params: {
|
|
35
|
+
clientId,
|
|
36
|
+
redirectUri,
|
|
37
|
+
codeChallenge,
|
|
38
|
+
codeChallengeMethod,
|
|
39
|
+
state,
|
|
40
|
+
responseType,
|
|
41
|
+
},
|
|
42
|
+
error: null,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ZeniAPIStatus } from '../../responsePayload';
|
|
2
|
+
import { ZeniOAuthViewState } from './zeniOAuthState';
|
|
3
|
+
export declare const initialState: ZeniOAuthViewState;
|
|
4
|
+
export interface ApproveOAuthConsentPayload {
|
|
5
|
+
clientId: string;
|
|
6
|
+
codeChallenge: string;
|
|
7
|
+
codeChallengeMethod: string;
|
|
8
|
+
redirectUri: string;
|
|
9
|
+
responseType: string;
|
|
10
|
+
state: string;
|
|
11
|
+
tenantId: string;
|
|
12
|
+
userId: string;
|
|
13
|
+
zeniSessionId: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
export declare const approveOAuthConsent: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[userId: string, zeniSessionId: string | undefined, tenantId: string, clientId: string, redirectUri: string, codeChallenge: string, codeChallengeMethod: string, state: string, responseType: string], {
|
|
16
|
+
userId: string;
|
|
17
|
+
zeniSessionId: string | undefined;
|
|
18
|
+
tenantId: string;
|
|
19
|
+
clientId: string;
|
|
20
|
+
redirectUri: string;
|
|
21
|
+
codeChallenge: string;
|
|
22
|
+
codeChallengeMethod: string;
|
|
23
|
+
state: string;
|
|
24
|
+
responseType: string;
|
|
25
|
+
}, "zeniOAuthView/approveOAuthConsent", never, never>, approveOAuthConsentSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
26
|
+
redirectUrl: string;
|
|
27
|
+
}, "zeniOAuthView/approveOAuthConsentSuccess">, approveOAuthConsentFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "zeniOAuthView/approveOAuthConsentFailure">, clearZeniOAuthView: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"zeniOAuthView/clearZeniOAuthView">;
|
|
28
|
+
declare const _default: import("redux").Reducer<ZeniOAuthViewState>;
|
|
29
|
+
export default _default;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.clearZeniOAuthView = exports.approveOAuthConsentFailure = exports.approveOAuthConsentSuccess = exports.approveOAuthConsent = exports.initialState = void 0;
|
|
5
|
+
const toolkit_1 = require("@reduxjs/toolkit");
|
|
6
|
+
exports.initialState = {
|
|
7
|
+
fetchState: 'Not-Started',
|
|
8
|
+
error: undefined,
|
|
9
|
+
approveRedirectUrl: undefined,
|
|
10
|
+
};
|
|
11
|
+
const zeniOAuthView = (0, toolkit_1.createSlice)({
|
|
12
|
+
name: 'zeniOAuthView',
|
|
13
|
+
initialState: exports.initialState,
|
|
14
|
+
reducers: {
|
|
15
|
+
approveOAuthConsent: {
|
|
16
|
+
prepare(userId, zeniSessionId, tenantId, clientId, redirectUri, codeChallenge, codeChallengeMethod, state, responseType) {
|
|
17
|
+
return {
|
|
18
|
+
payload: {
|
|
19
|
+
userId,
|
|
20
|
+
zeniSessionId,
|
|
21
|
+
tenantId,
|
|
22
|
+
clientId,
|
|
23
|
+
redirectUri,
|
|
24
|
+
codeChallenge,
|
|
25
|
+
codeChallengeMethod,
|
|
26
|
+
state,
|
|
27
|
+
responseType,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
reducer(draft) {
|
|
32
|
+
draft.fetchState = 'In-Progress';
|
|
33
|
+
draft.error = undefined;
|
|
34
|
+
draft.approveRedirectUrl = undefined;
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
approveOAuthConsentSuccess(draft, action) {
|
|
38
|
+
draft.fetchState = 'Completed';
|
|
39
|
+
draft.error = undefined;
|
|
40
|
+
draft.approveRedirectUrl = action.payload.redirectUrl;
|
|
41
|
+
},
|
|
42
|
+
approveOAuthConsentFailure(draft, action) {
|
|
43
|
+
draft.fetchState = 'Error';
|
|
44
|
+
draft.error = action.payload;
|
|
45
|
+
draft.approveRedirectUrl = undefined;
|
|
46
|
+
},
|
|
47
|
+
clearZeniOAuthView() {
|
|
48
|
+
return exports.initialState;
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
_a = zeniOAuthView.actions, exports.approveOAuthConsent = _a.approveOAuthConsent, exports.approveOAuthConsentSuccess = _a.approveOAuthConsentSuccess, exports.approveOAuthConsentFailure = _a.approveOAuthConsentFailure, exports.clearZeniOAuthView = _a.clearZeniOAuthView;
|
|
53
|
+
exports.default = zeniOAuthView.reducer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RootState } from '../../reducer';
|
|
2
|
+
import { FetchState } from '../../commonStateTypes/common';
|
|
3
|
+
export declare const getZeniOAuthApproveFetchState: (state: RootState) => FetchState;
|
|
4
|
+
export declare const getZeniOAuthApproveRedirectUrl: (state: RootState) => string | undefined;
|
|
5
|
+
export declare const getZeniOAuthApproveError: (state: RootState) => string | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getZeniOAuthApproveError = exports.getZeniOAuthApproveRedirectUrl = exports.getZeniOAuthApproveFetchState = void 0;
|
|
4
|
+
const getZeniOAuthApproveFetchState = (state) => state.zeniOAuthViewState.fetchState;
|
|
5
|
+
exports.getZeniOAuthApproveFetchState = getZeniOAuthApproveFetchState;
|
|
6
|
+
const getZeniOAuthApproveRedirectUrl = (state) => state.zeniOAuthViewState.approveRedirectUrl;
|
|
7
|
+
exports.getZeniOAuthApproveRedirectUrl = getZeniOAuthApproveRedirectUrl;
|
|
8
|
+
const getZeniOAuthApproveError = (state) => state.zeniOAuthViewState.error?.message ?? null;
|
|
9
|
+
exports.getZeniOAuthApproveError = getZeniOAuthApproveError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.32-betaRD1",
|
|
4
4
|
"description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|