@techstuff-dev/foundation-api-utils 1.18.0 → 1.20.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/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 +34 -0
- package/dist/@types/lib/utils/dataFormat/index.d.ts +1 -2
- package/dist/index.esm.js +15 -27
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +15 -27
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/dist/@types/lib/services/auth/slice.d.ts +0 -212
|
@@ -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
|
}];
|
|
@@ -24,6 +24,7 @@ export type User = {
|
|
|
24
24
|
email?: string;
|
|
25
25
|
info?: Info;
|
|
26
26
|
sub?: string;
|
|
27
|
+
socialSignin?: boolean;
|
|
27
28
|
};
|
|
28
29
|
export type UserDetails = {
|
|
29
30
|
userSub?: string;
|
|
@@ -318,3 +319,36 @@ export interface PaymentResponse {
|
|
|
318
319
|
metadata: {};
|
|
319
320
|
type: string;
|
|
320
321
|
}
|
|
322
|
+
export interface DecodedIdToken {
|
|
323
|
+
at_hash: string;
|
|
324
|
+
sub: string;
|
|
325
|
+
'cognito:groups': string[];
|
|
326
|
+
email_verified: boolean;
|
|
327
|
+
iss: string;
|
|
328
|
+
'cognito:username': string;
|
|
329
|
+
given_name: string;
|
|
330
|
+
nonce: string;
|
|
331
|
+
aud: string;
|
|
332
|
+
identities: {
|
|
333
|
+
userId: string;
|
|
334
|
+
providerName: string;
|
|
335
|
+
providerType: string;
|
|
336
|
+
issuer: string;
|
|
337
|
+
primary: string;
|
|
338
|
+
dateCreated: string;
|
|
339
|
+
}[];
|
|
340
|
+
token_use: string;
|
|
341
|
+
auth_time: number;
|
|
342
|
+
name: string;
|
|
343
|
+
exp: number;
|
|
344
|
+
iat: number;
|
|
345
|
+
family_name: string;
|
|
346
|
+
email: string;
|
|
347
|
+
birthdate?: string;
|
|
348
|
+
picture?: string;
|
|
349
|
+
}
|
|
350
|
+
export interface SocialTokens {
|
|
351
|
+
accessToken: string;
|
|
352
|
+
idToken: string;
|
|
353
|
+
refreshToken: string;
|
|
354
|
+
}
|
|
@@ -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';
|
|
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();
|
|
@@ -1049,24 +1055,6 @@ var paymentApi = createApi({
|
|
|
1049
1055
|
sub: data.sub,
|
|
1050
1056
|
},
|
|
1051
1057
|
}); },
|
|
1052
|
-
// async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
|
1053
|
-
// try {
|
|
1054
|
-
// const response = await queryFulfilled;
|
|
1055
|
-
// const decoded = jwtDecode(response?.data?.idToken);
|
|
1056
|
-
// const profile = formatUserPayload(decoded as UserPayload);
|
|
1057
|
-
// const creds = {
|
|
1058
|
-
// accessToken: response?.data?.accessToken,
|
|
1059
|
-
// idToken: response?.data?.idToken,
|
|
1060
|
-
// refreshToken: response?.data?.refreshToken,
|
|
1061
|
-
// accessTokenExpiry: response?.data?.accessTokenExpiry,
|
|
1062
|
-
// details: { ...profile },
|
|
1063
|
-
// };
|
|
1064
|
-
// dispatch(setCredentials(creds));
|
|
1065
|
-
// } catch (err) {
|
|
1066
|
-
// // `onError` log out user.
|
|
1067
|
-
// dispatch(logout());
|
|
1068
|
-
// }
|
|
1069
|
-
// },
|
|
1070
1058
|
providesTags: ['UserSubscription'],
|
|
1071
1059
|
}),
|
|
1072
1060
|
}); },
|