@techstuff-dev/foundation-api-utils 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/lib/hooks/index.d.ts +0 -1
- package/dist/@types/lib/services/auth/index.d.ts +113 -113
- package/dist/@types/lib/services/auth/slice.d.ts +16 -16
- package/dist/@types/lib/services/content/index.d.ts +10 -10
- package/dist/@types/lib/services/payment/index.d.ts +5 -5
- package/dist/@types/lib/store/index.d.ts +0 -1
- package/dist/@types/lib/store/storage.d.ts +0 -1
- package/dist/@types/lib/types/index.interfaces.d.ts +33 -0
- package/dist/@types/lib/utils/dataFormat/index.d.ts +1 -2
- package/dist/index.esm.js +15 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +14 -8
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
|
@@ -35,24 +35,24 @@ export declare const authSlice: import("@reduxjs/toolkit").Slice<AuthState, {
|
|
|
35
35
|
details: {
|
|
36
36
|
subscription: any;
|
|
37
37
|
subscriptionDetails: any;
|
|
38
|
-
userSub?: string
|
|
39
|
-
uuid?: string
|
|
40
|
-
firstName?: string
|
|
41
|
-
lastName?: string
|
|
42
|
-
userEmail?: string
|
|
43
|
-
picture?: string
|
|
44
|
-
termsAccepted?: string
|
|
45
|
-
dateOfBirth?: string
|
|
46
|
-
contactPreference?: boolean
|
|
47
|
-
password?: string
|
|
48
|
-
passwordConfirm?: string
|
|
49
|
-
agency?: boolean
|
|
38
|
+
userSub?: string;
|
|
39
|
+
uuid?: string;
|
|
40
|
+
firstName?: string;
|
|
41
|
+
lastName?: string;
|
|
42
|
+
userEmail?: string;
|
|
43
|
+
picture?: string;
|
|
44
|
+
termsAccepted?: string;
|
|
45
|
+
dateOfBirth?: string;
|
|
46
|
+
contactPreference?: boolean;
|
|
47
|
+
password?: string;
|
|
48
|
+
passwordConfirm?: string;
|
|
49
|
+
agency?: boolean;
|
|
50
50
|
};
|
|
51
51
|
accessToken?: string | undefined;
|
|
52
52
|
idToken?: string | undefined;
|
|
53
53
|
refreshToken?: string | undefined;
|
|
54
54
|
expires?: number | undefined;
|
|
55
|
-
accessTokenExpiry?: number | null | undefined;
|
|
55
|
+
accessTokenExpiry?: (number | null) | undefined;
|
|
56
56
|
email?: string | undefined;
|
|
57
57
|
info?: import("immer").WritableDraft<import("../../types/index.interfaces").Info> | undefined;
|
|
58
58
|
sub?: string | undefined;
|
|
@@ -96,7 +96,7 @@ export declare const authSlice: import("@reduxjs/toolkit").Slice<AuthState, {
|
|
|
96
96
|
amount: number;
|
|
97
97
|
interval: string;
|
|
98
98
|
currency: string;
|
|
99
|
-
cancelAt?: number
|
|
99
|
+
cancelAt?: number;
|
|
100
100
|
planID: string;
|
|
101
101
|
planDescription: string;
|
|
102
102
|
paymentDetails: {
|
|
@@ -179,7 +179,7 @@ export declare const isAuthenticated: import("reselect").Selector<{
|
|
|
179
179
|
amount: number;
|
|
180
180
|
interval: string;
|
|
181
181
|
currency: string;
|
|
182
|
-
cancelAt?: number
|
|
182
|
+
cancelAt?: number;
|
|
183
183
|
planID: string;
|
|
184
184
|
planDescription: string;
|
|
185
185
|
paymentDetails: {
|
|
@@ -195,7 +195,7 @@ export declare const isAuthenticated: import("reselect").Selector<{
|
|
|
195
195
|
amount: number;
|
|
196
196
|
interval: string;
|
|
197
197
|
currency: string;
|
|
198
|
-
cancelAt?: number
|
|
198
|
+
cancelAt?: number;
|
|
199
199
|
planID: string;
|
|
200
200
|
planDescription: string;
|
|
201
201
|
paymentDetails: {
|
|
@@ -65,10 +65,10 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
|
|
|
65
65
|
}, "error">>)>> & {
|
|
66
66
|
status: import("@reduxjs/toolkit/query").QueryStatus;
|
|
67
67
|
}>(arg: DataArgs | typeof import("@reduxjs/toolkit/query").skipToken, options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & {
|
|
68
|
-
skip?: boolean
|
|
69
|
-
refetchOnMountOrArgChange?:
|
|
68
|
+
skip?: boolean;
|
|
69
|
+
refetchOnMountOrArgChange?: boolean | number;
|
|
70
70
|
} & {
|
|
71
|
-
skip?: boolean
|
|
71
|
+
skip?: boolean;
|
|
72
72
|
selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
|
|
73
73
|
status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
|
|
74
74
|
originalArgs?: undefined;
|
|
@@ -197,7 +197,7 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
|
|
|
197
197
|
}, "error">>)>> & {
|
|
198
198
|
status: import("@reduxjs/toolkit/query").QueryStatus;
|
|
199
199
|
}>(options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & Omit<{
|
|
200
|
-
skip?: boolean
|
|
200
|
+
skip?: boolean;
|
|
201
201
|
selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
|
|
202
202
|
status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
|
|
203
203
|
originalArgs?: undefined;
|
|
@@ -261,7 +261,7 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
|
|
|
261
261
|
}, "error">>)>> & {
|
|
262
262
|
status: import("@reduxjs/toolkit/query").QueryStatus;
|
|
263
263
|
}) => R) | undefined;
|
|
264
|
-
}, "skip">) | undefined) => [(arg: DataArgs, preferCacheValue?: boolean
|
|
264
|
+
}, "skip">) | undefined) => [(arg: DataArgs, preferCacheValue?: boolean) => import("@reduxjs/toolkit/query").QueryActionCreatorResult<import("@reduxjs/toolkit/query").QueryDefinition<DataArgs, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, "Data" | "Workout", ESDataTypes, "contentApi">>, [R][R extends any ? 0 : never], {
|
|
265
265
|
lastArg: DataArgs;
|
|
266
266
|
}], useGetDataByIdQuery: <R extends Record<string, any> = import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
|
|
267
267
|
status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
|
|
@@ -326,10 +326,10 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
|
|
|
326
326
|
}, "error">>)>> & {
|
|
327
327
|
status: import("@reduxjs/toolkit/query").QueryStatus;
|
|
328
328
|
}>(arg: IdArg | typeof import("@reduxjs/toolkit/query").skipToken, options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & {
|
|
329
|
-
skip?: boolean
|
|
330
|
-
refetchOnMountOrArgChange?:
|
|
329
|
+
skip?: boolean;
|
|
330
|
+
refetchOnMountOrArgChange?: boolean | number;
|
|
331
331
|
} & {
|
|
332
|
-
skip?: boolean
|
|
332
|
+
skip?: boolean;
|
|
333
333
|
selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
|
|
334
334
|
status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
|
|
335
335
|
originalArgs?: undefined;
|
|
@@ -458,7 +458,7 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
|
|
|
458
458
|
}, "error">>)>> & {
|
|
459
459
|
status: import("@reduxjs/toolkit/query").QueryStatus;
|
|
460
460
|
}>(options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & Omit<{
|
|
461
|
-
skip?: boolean
|
|
461
|
+
skip?: boolean;
|
|
462
462
|
selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
|
|
463
463
|
status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
|
|
464
464
|
originalArgs?: undefined;
|
|
@@ -522,6 +522,6 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
|
|
|
522
522
|
}, "error">>)>> & {
|
|
523
523
|
status: import("@reduxjs/toolkit/query").QueryStatus;
|
|
524
524
|
}) => R) | undefined;
|
|
525
|
-
}, "skip">) | undefined) => [(arg: IdArg, preferCacheValue?: boolean
|
|
525
|
+
}, "skip">) | undefined) => [(arg: IdArg, preferCacheValue?: boolean) => import("@reduxjs/toolkit/query").QueryActionCreatorResult<import("@reduxjs/toolkit/query").QueryDefinition<IdArg, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, "Data" | "Workout", ESDataTypes, "contentApi">>, [R][R extends any ? 0 : never], {
|
|
526
526
|
lastArg: IdArg;
|
|
527
527
|
}];
|
|
@@ -68,10 +68,10 @@ export declare const useCheckUserSubscriptionQuery: <R extends Record<string, an
|
|
|
68
68
|
}, "error">>)>> & {
|
|
69
69
|
status: import("@reduxjs/toolkit/query").QueryStatus;
|
|
70
70
|
}>(arg: UserSubRequest | typeof import("@reduxjs/toolkit/query").skipToken, options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & {
|
|
71
|
-
skip?: boolean
|
|
72
|
-
refetchOnMountOrArgChange?:
|
|
71
|
+
skip?: boolean;
|
|
72
|
+
refetchOnMountOrArgChange?: boolean | number;
|
|
73
73
|
} & {
|
|
74
|
-
skip?: boolean
|
|
74
|
+
skip?: boolean;
|
|
75
75
|
selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
|
|
76
76
|
status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
|
|
77
77
|
originalArgs?: undefined;
|
|
@@ -200,7 +200,7 @@ export declare const useCheckUserSubscriptionQuery: <R extends Record<string, an
|
|
|
200
200
|
}, "error">>)>> & {
|
|
201
201
|
status: import("@reduxjs/toolkit/query").QueryStatus;
|
|
202
202
|
}>(options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & Omit<{
|
|
203
|
-
skip?: boolean
|
|
203
|
+
skip?: boolean;
|
|
204
204
|
selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
|
|
205
205
|
status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
|
|
206
206
|
originalArgs?: undefined;
|
|
@@ -264,6 +264,6 @@ export declare const useCheckUserSubscriptionQuery: <R extends Record<string, an
|
|
|
264
264
|
}, "error">>)>> & {
|
|
265
265
|
status: import("@reduxjs/toolkit/query").QueryStatus;
|
|
266
266
|
}) => R) | undefined;
|
|
267
|
-
}, "skip">) | undefined) => [(arg: UserSubRequest, preferCacheValue?: boolean
|
|
267
|
+
}, "skip">) | undefined) => [(arg: UserSubRequest, preferCacheValue?: boolean) => import("@reduxjs/toolkit/query").QueryActionCreatorResult<import("@reduxjs/toolkit/query").QueryDefinition<UserSubRequest, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, "UserSubscription", UserSubResponse, "paymentApi">>, [R][R extends any ? 0 : never], {
|
|
268
268
|
lastArg: UserSubRequest;
|
|
269
269
|
}];
|
|
@@ -318,3 +318,36 @@ export interface PaymentResponse {
|
|
|
318
318
|
metadata: {};
|
|
319
319
|
type: string;
|
|
320
320
|
}
|
|
321
|
+
export interface DecodedIdToken {
|
|
322
|
+
at_hash: string;
|
|
323
|
+
sub: string;
|
|
324
|
+
'cognito:groups': string[];
|
|
325
|
+
email_verified: boolean;
|
|
326
|
+
iss: string;
|
|
327
|
+
'cognito:username': string;
|
|
328
|
+
given_name: string;
|
|
329
|
+
nonce: string;
|
|
330
|
+
aud: string;
|
|
331
|
+
identities: {
|
|
332
|
+
userId: string;
|
|
333
|
+
providerName: string;
|
|
334
|
+
providerType: string;
|
|
335
|
+
issuer: string;
|
|
336
|
+
primary: string;
|
|
337
|
+
dateCreated: string;
|
|
338
|
+
}[];
|
|
339
|
+
token_use: string;
|
|
340
|
+
auth_time: number;
|
|
341
|
+
name: string;
|
|
342
|
+
exp: number;
|
|
343
|
+
iat: number;
|
|
344
|
+
family_name: string;
|
|
345
|
+
email: string;
|
|
346
|
+
birthdate?: string;
|
|
347
|
+
picture?: string;
|
|
348
|
+
}
|
|
349
|
+
export interface SocialTokens {
|
|
350
|
+
accessToken: string;
|
|
351
|
+
idToken: string;
|
|
352
|
+
refreshToken: string;
|
|
353
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AuthSession } from '@aws-amplify/core';
|
|
2
1
|
import { User } from '../../types/index.interfaces';
|
|
3
2
|
export declare const formatUserPayload: (payload: UserPayload) => {
|
|
4
3
|
userEmail: string;
|
|
@@ -109,4 +108,4 @@ export declare function formatSchedule(data: ESSchedule[]): Schedule[];
|
|
|
109
108
|
export declare function formatChallenges(data: ESChallenge[]): Challenge[];
|
|
110
109
|
export declare function formatChallengeDays(data: ESChallengeDay[]): ChallengeDay[];
|
|
111
110
|
export declare function formatSecondsToISO8601Duration(seconds?: number): string;
|
|
112
|
-
export declare function formatAuthSession(session:
|
|
111
|
+
export declare function formatAuthSession(session: any): User;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fetchBaseQuery, createApi } from '@reduxjs/toolkit/query/react';
|
|
2
|
-
import {
|
|
2
|
+
import { Auth } from '@aws-amplify/auth';
|
|
3
3
|
import { jwtDecode } from 'jwt-decode';
|
|
4
4
|
import { createSlice, combineSlices, configureStore } from '@reduxjs/toolkit';
|
|
5
5
|
import { useSelector, useDispatch, useStore } from 'react-redux';
|
|
@@ -565,6 +565,7 @@ function formatSecondsToISO8601Duration(seconds) {
|
|
|
565
565
|
}
|
|
566
566
|
function formatAuthSession(session) {
|
|
567
567
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28;
|
|
568
|
+
console.log('formatAuthSession session', session);
|
|
568
569
|
return {
|
|
569
570
|
accessToken: (_a = session === null || session === void 0 ? void 0 : session.tokens) === null || _a === void 0 ? void 0 : _a.accessToken.toString(),
|
|
570
571
|
idToken: (_c = (_b = session === null || session === void 0 ? void 0 : session.tokens) === null || _b === void 0 ? void 0 : _b.idToken) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
@@ -625,17 +626,19 @@ var APP_ES_AUTH = ((_f = process.env) === null || _f === void 0 ? void 0 : _f.NE
|
|
|
625
626
|
var authDataBaseQuery = fetchBaseQuery({
|
|
626
627
|
baseUrl: API_AUTH_PREFIX,
|
|
627
628
|
prepareHeaders: function (headers_1, _a) { return __awaiter(void 0, [headers_1, _a], void 0, function (headers, _b) {
|
|
628
|
-
var
|
|
629
|
+
var session, idToken, accessToken;
|
|
629
630
|
return __generator(this, function (_c) {
|
|
630
631
|
switch (_c.label) {
|
|
631
632
|
case 0:
|
|
632
633
|
headers.set('Content-Type', 'application/json');
|
|
633
|
-
return [4 /*yield*/,
|
|
634
|
+
return [4 /*yield*/, Auth.currentSession()];
|
|
634
635
|
case 1:
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
636
|
+
session = _c.sent();
|
|
637
|
+
idToken = session.getIdToken().getJwtToken();
|
|
638
|
+
accessToken = session.getAccessToken().getJwtToken();
|
|
639
|
+
if (accessToken && idToken) {
|
|
640
|
+
headers.set('accesstoken', accessToken);
|
|
641
|
+
headers.set('idtoken', idToken);
|
|
639
642
|
// headers.set('refreshtoken', tokens.refreshToken);
|
|
640
643
|
}
|
|
641
644
|
return [2 /*return*/, headers];
|
|
@@ -656,9 +659,12 @@ var authDataBaseQueryWithReauth = function (args, api, extraOptions) { return __
|
|
|
656
659
|
case 1:
|
|
657
660
|
result = _b.sent();
|
|
658
661
|
if (!(((_a = result === null || result === void 0 ? void 0 : result.error) === null || _a === void 0 ? void 0 : _a.status) === 401)) return [3 /*break*/, 6];
|
|
659
|
-
return [4 /*yield*/,
|
|
662
|
+
return [4 /*yield*/, Auth.currentAuthenticatedUser({
|
|
663
|
+
bypassCache: true, // Ensures that the user is refreshed from the server
|
|
664
|
+
})];
|
|
660
665
|
case 2:
|
|
661
666
|
authSession = _b.sent();
|
|
667
|
+
console.log('Session successfully refreshed:', authSession);
|
|
662
668
|
user = formatAuthSession(authSession);
|
|
663
669
|
api.dispatch(setCredentials(user));
|
|
664
670
|
if (!(authSession === null || authSession === void 0 ? void 0 : authSession.tokens)) return [3 /*break*/, 4];
|
|
@@ -669,7 +675,7 @@ var authDataBaseQueryWithReauth = function (args, api, extraOptions) { return __
|
|
|
669
675
|
return [3 /*break*/, 6];
|
|
670
676
|
case 4:
|
|
671
677
|
// TODO; require full data reset?
|
|
672
|
-
return [4 /*yield*/, signOut()];
|
|
678
|
+
return [4 /*yield*/, Auth.signOut()];
|
|
673
679
|
case 5:
|
|
674
680
|
// TODO; require full data reset?
|
|
675
681
|
_b.sent();
|