@go-mondo/identity-sdk 0.0.2-beta.82 → 0.0.2-beta.83
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/.release-please-manifest.json +1 -1
- package/.tsbuildinfo/cjs.json +1 -1
- package/.tsbuildinfo/esm.json +1 -1
- package/CHANGELOG.md +7 -0
- package/dist/cjs/activity/resources.js +1 -1
- package/dist/cjs/activity/resources.test.js +5 -5
- package/dist/cjs/app/authorization/resources.js +2 -2
- package/dist/cjs/app/oauth/resources.js +2 -2
- package/dist/cjs/app/oidc/resources.js +4 -4
- package/dist/cjs/app/registration/resources.js +2 -2
- package/dist/cjs/app/registration/resources.test.js +5 -5
- package/dist/cjs/app/resources.js +5 -5
- package/dist/cjs/app/resources.test.js +5 -5
- package/dist/cjs/app/saml/resources.js +4 -4
- package/dist/cjs/association/resources.js +3 -3
- package/dist/cjs/authentication/sessions/resources.js +2 -2
- package/dist/cjs/authentication/settings/resources.js +2 -2
- package/dist/cjs/authentication/strategies/resources.js +5 -5
- package/dist/cjs/authorization/permissions/resources.js +5 -5
- package/dist/cjs/authorization/roles/resources.js +5 -5
- package/dist/cjs/common/index.d.ts +1 -0
- package/dist/cjs/common/index.d.ts.map +1 -1
- package/dist/cjs/common/resources/authorization.d.ts +18 -1
- package/dist/cjs/common/resources/authorization.d.ts.map +1 -1
- package/dist/cjs/common/resources/authorization.js +6 -0
- package/dist/cjs/common/resources/init.d.ts +5 -5
- package/dist/cjs/common/resources/init.d.ts.map +1 -1
- package/dist/cjs/common/resources/init.js +20 -14
- package/dist/cjs/common/resources/init.test.js +55 -31
- package/dist/cjs/common/resources/operations.d.ts +7 -7
- package/dist/cjs/common/resources/operations.d.ts.map +1 -1
- package/dist/cjs/common/resources/operations.js +35 -19
- package/dist/cjs/common/resources/operations.test.js +32 -2
- package/dist/cjs/customer/users/resources.js +5 -5
- package/dist/esm/activity/resources.js +1 -1
- package/dist/esm/activity/resources.test.js +5 -5
- package/dist/esm/app/authorization/resources.js +2 -2
- package/dist/esm/app/oauth/resources.js +2 -2
- package/dist/esm/app/oidc/resources.js +4 -4
- package/dist/esm/app/registration/resources.js +2 -2
- package/dist/esm/app/registration/resources.test.js +5 -5
- package/dist/esm/app/resources.js +5 -5
- package/dist/esm/app/resources.test.js +5 -5
- package/dist/esm/app/saml/resources.js +4 -4
- package/dist/esm/association/resources.js +3 -3
- package/dist/esm/authentication/sessions/resources.js +2 -2
- package/dist/esm/authentication/settings/resources.js +2 -2
- package/dist/esm/authentication/strategies/resources.js +5 -5
- package/dist/esm/authorization/permissions/resources.js +5 -5
- package/dist/esm/authorization/roles/resources.js +5 -5
- package/dist/esm/common/index.d.ts +1 -0
- package/dist/esm/common/index.d.ts.map +1 -1
- package/dist/esm/common/resources/authorization.d.ts +18 -1
- package/dist/esm/common/resources/authorization.d.ts.map +1 -1
- package/dist/esm/common/resources/authorization.js +5 -1
- package/dist/esm/common/resources/init.d.ts +5 -5
- package/dist/esm/common/resources/init.d.ts.map +1 -1
- package/dist/esm/common/resources/init.js +20 -14
- package/dist/esm/common/resources/init.test.js +56 -32
- package/dist/esm/common/resources/operations.d.ts +7 -7
- package/dist/esm/common/resources/operations.d.ts.map +1 -1
- package/dist/esm/common/resources/operations.js +35 -19
- package/dist/esm/common/resources/operations.test.js +32 -2
- package/dist/esm/customer/users/resources.js +5 -5
- package/package.json +1 -1
|
@@ -27,14 +27,14 @@ export class SAMLResources {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
export async function getSAML(instance, appId) {
|
|
30
|
-
return SAMLSchema.parse(await getItemWithAuthorization(new URL(SAMLResources.buildPath(appId), instance.config.host), instance.
|
|
30
|
+
return SAMLSchema.parse(await getItemWithAuthorization(new URL(SAMLResources.buildPath(appId), instance.config.host), instance.authorize));
|
|
31
31
|
}
|
|
32
32
|
export async function insertSAML(instance, appId, item) {
|
|
33
|
-
return SAMLSchema.parse(await postItemWithAuthorization(new URL(SAMLResources.buildPath(appId), instance.config.host), instance.
|
|
33
|
+
return SAMLSchema.parse(await postItemWithAuthorization(new URL(SAMLResources.buildPath(appId), instance.config.host), instance.authorize, item ? InsertSAMLPayloadSchema.parse(item) : undefined));
|
|
34
34
|
}
|
|
35
35
|
export async function updateSAML(instance, appId, item) {
|
|
36
|
-
return SAMLSchema.parse(await patchItemWithAuthorization(new URL(SAMLResources.buildPath(appId), instance.config.host), instance.
|
|
36
|
+
return SAMLSchema.parse(await patchItemWithAuthorization(new URL(SAMLResources.buildPath(appId), instance.config.host), instance.authorize, UpdateSAMLPayloadSchema.parse(item)));
|
|
37
37
|
}
|
|
38
38
|
export async function deleteSAML(instance, appId) {
|
|
39
|
-
return SAMLSchema.parse(await deleteItemWithAuthorization(new URL(SAMLResources.buildPath(appId), instance.config.host), instance.
|
|
39
|
+
return SAMLSchema.parse(await deleteItemWithAuthorization(new URL(SAMLResources.buildPath(appId), instance.config.host), instance.authorize));
|
|
40
40
|
}
|
|
@@ -32,11 +32,11 @@ export class AssociationResources {
|
|
|
32
32
|
}
|
|
33
33
|
export async function listAssociations(instance, id, options, pagination) {
|
|
34
34
|
const url = addPaginationToURL(new URL(AssociationResources.buildListingPath(id, options), instance.config.host), pagination);
|
|
35
|
-
return PaginationCollectionSchema(AssociationSchema).parse(await getItemWithAuthorization(url, instance.
|
|
35
|
+
return PaginationCollectionSchema(AssociationSchema).parse(await getItemWithAuthorization(url, instance.authorize));
|
|
36
36
|
}
|
|
37
37
|
export async function upsertAssociation(instance, fromId, toId, item) {
|
|
38
|
-
return AssociationSchema.parse(await putItemWithAuthorization(new URL(AssociationResources.buildPath(fromId, toId), instance.config.host), instance.
|
|
38
|
+
return AssociationSchema.parse(await putItemWithAuthorization(new URL(AssociationResources.buildPath(fromId, toId), instance.config.host), instance.authorize, item ? UpsertAssociationPayloadSchema.parse(item) : undefined));
|
|
39
39
|
}
|
|
40
40
|
export async function deleteAssociation(instance, fromId, toId) {
|
|
41
|
-
return AssociationSchema.parse(await deleteItemWithAuthorization(new URL(AssociationResources.buildPath(fromId, toId), instance.config.host), instance.
|
|
41
|
+
return AssociationSchema.parse(await deleteItemWithAuthorization(new URL(AssociationResources.buildPath(fromId, toId), instance.config.host), instance.authorize));
|
|
42
42
|
}
|
|
@@ -30,8 +30,8 @@ export class SessionResources {
|
|
|
30
30
|
}
|
|
31
31
|
export async function listSessions(instance, options, pagination) {
|
|
32
32
|
const url = addPaginationToURL(new URL(SessionResources.buildListingPath(options), instance.config.host), pagination);
|
|
33
|
-
return PaginationCollectionSchema(SessionSchema).parse(await getItemWithAuthorization(url, instance.
|
|
33
|
+
return PaginationCollectionSchema(SessionSchema).parse(await getItemWithAuthorization(url, instance.authorize));
|
|
34
34
|
}
|
|
35
35
|
export async function deleteSession(instance, id) {
|
|
36
|
-
return SessionSchema.parse(await deleteItemWithAuthorization(new URL(SessionResources.buildPath(id), instance.config.host), instance.
|
|
36
|
+
return SessionSchema.parse(await deleteItemWithAuthorization(new URL(SessionResources.buildPath(id), instance.config.host), instance.authorize));
|
|
37
37
|
}
|
|
@@ -18,8 +18,8 @@ export class SettingsResources {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
export async function getSettings(instance) {
|
|
21
|
-
return SettingsSchema.parse(await getItemWithAuthorization(new URL(SettingsResources.buildPath(), instance.config.host), instance.
|
|
21
|
+
return SettingsSchema.parse(await getItemWithAuthorization(new URL(SettingsResources.buildPath(), instance.config.host), instance.authorize));
|
|
22
22
|
}
|
|
23
23
|
export async function upsertSettings(instance, item) {
|
|
24
|
-
return SettingsSchema.parse(await postItemWithAuthorization(new URL(SettingsResources.buildPath(), instance.config.host), instance.
|
|
24
|
+
return SettingsSchema.parse(await postItemWithAuthorization(new URL(SettingsResources.buildPath(), instance.config.host), instance.authorize, UpsertSettingsPayloadSchema.parse(item)));
|
|
25
25
|
}
|
|
@@ -33,17 +33,17 @@ export class StrategyResources {
|
|
|
33
33
|
}
|
|
34
34
|
export async function listStrategies(instance, pagination) {
|
|
35
35
|
const url = addPaginationToURL(new URL(StrategyResources.buildPath(), instance.config.host), pagination);
|
|
36
|
-
return PaginationCollectionSchema(StrategySchema).parse(await getItemWithAuthorization(url, instance.
|
|
36
|
+
return PaginationCollectionSchema(StrategySchema).parse(await getItemWithAuthorization(url, instance.authorize));
|
|
37
37
|
}
|
|
38
38
|
export async function getStrategy(instance, id) {
|
|
39
|
-
return StrategySchema.parse(await getItemWithAuthorization(new URL(StrategyResources.buildItemPath(id), instance.config.host), instance.
|
|
39
|
+
return StrategySchema.parse(await getItemWithAuthorization(new URL(StrategyResources.buildItemPath(id), instance.config.host), instance.authorize));
|
|
40
40
|
}
|
|
41
41
|
export async function insertStrategy(instance, item) {
|
|
42
|
-
return StrategySchema.parse(await postItemWithAuthorization(new URL(StrategyResources.buildPath(), instance.config.host), instance.
|
|
42
|
+
return StrategySchema.parse(await postItemWithAuthorization(new URL(StrategyResources.buildPath(), instance.config.host), instance.authorize, InsertStrategyPayloadSchema.parse(item)));
|
|
43
43
|
}
|
|
44
44
|
export async function updateStrategy(instance, id, item) {
|
|
45
|
-
return StrategySchema.parse(await patchItemWithAuthorization(new URL(StrategyResources.buildItemPath(id), instance.config.host), instance.
|
|
45
|
+
return StrategySchema.parse(await patchItemWithAuthorization(new URL(StrategyResources.buildItemPath(id), instance.config.host), instance.authorize, UpdateStrategyPayloadSchema.parse(item)));
|
|
46
46
|
}
|
|
47
47
|
export async function deleteStrategy(instance, id) {
|
|
48
|
-
return StrategySchema.parse(await deleteItemWithAuthorization(new URL(StrategyResources.buildItemPath(id), instance.config.host), instance.
|
|
48
|
+
return StrategySchema.parse(await deleteItemWithAuthorization(new URL(StrategyResources.buildItemPath(id), instance.config.host), instance.authorize));
|
|
49
49
|
}
|
|
@@ -32,17 +32,17 @@ export class PermissionResources {
|
|
|
32
32
|
}
|
|
33
33
|
export async function listPermissions(instance, pagination) {
|
|
34
34
|
const url = addPaginationToURL(new URL(PermissionResources.buildPath(), instance.config.host), pagination);
|
|
35
|
-
return PaginationCollectionSchema(PermissionSchema).parse(await getItemWithAuthorization(url, instance.
|
|
35
|
+
return PaginationCollectionSchema(PermissionSchema).parse(await getItemWithAuthorization(url, instance.authorize));
|
|
36
36
|
}
|
|
37
37
|
export async function getPermission(instance, id) {
|
|
38
|
-
return PermissionSchema.parse(await getItemWithAuthorization(new URL(PermissionResources.buildPath(id), instance.config.host), instance.
|
|
38
|
+
return PermissionSchema.parse(await getItemWithAuthorization(new URL(PermissionResources.buildPath(id), instance.config.host), instance.authorize));
|
|
39
39
|
}
|
|
40
40
|
export async function insertPermission(instance, item) {
|
|
41
|
-
return PermissionSchema.parse(await postItemWithAuthorization(new URL(PermissionResources.buildPath(), instance.config.host), instance.
|
|
41
|
+
return PermissionSchema.parse(await postItemWithAuthorization(new URL(PermissionResources.buildPath(), instance.config.host), instance.authorize, InsertPermissionPayloadSchema.parse(item)));
|
|
42
42
|
}
|
|
43
43
|
export async function updatePermission(instance, id, item) {
|
|
44
|
-
return PermissionSchema.parse(await patchItemWithAuthorization(new URL(PermissionResources.buildPath(id), instance.config.host), instance.
|
|
44
|
+
return PermissionSchema.parse(await patchItemWithAuthorization(new URL(PermissionResources.buildPath(id), instance.config.host), instance.authorize, UpdatePermissionPayloadSchema.parse(item)));
|
|
45
45
|
}
|
|
46
46
|
export async function deletePermission(instance, id) {
|
|
47
|
-
return PermissionSchema.parse(await deleteItemWithAuthorization(new URL(PermissionResources.buildPath(id), instance.config.host), instance.
|
|
47
|
+
return PermissionSchema.parse(await deleteItemWithAuthorization(new URL(PermissionResources.buildPath(id), instance.config.host), instance.authorize));
|
|
48
48
|
}
|
|
@@ -32,17 +32,17 @@ export class RoleResources {
|
|
|
32
32
|
}
|
|
33
33
|
export async function listRoles(instance, pagination) {
|
|
34
34
|
const url = addPaginationToURL(new URL(RoleResources.buildPath(), instance.config.host), pagination);
|
|
35
|
-
return PaginationCollectionSchema(RoleSchema).parse(await getItemWithAuthorization(url, instance.
|
|
35
|
+
return PaginationCollectionSchema(RoleSchema).parse(await getItemWithAuthorization(url, instance.authorize));
|
|
36
36
|
}
|
|
37
37
|
export async function getRole(instance, id) {
|
|
38
|
-
return RoleSchema.parse(await getItemWithAuthorization(new URL(RoleResources.buildPath(id), instance.config.host), instance.
|
|
38
|
+
return RoleSchema.parse(await getItemWithAuthorization(new URL(RoleResources.buildPath(id), instance.config.host), instance.authorize));
|
|
39
39
|
}
|
|
40
40
|
export async function insertRole(instance, item) {
|
|
41
|
-
return RoleSchema.parse(await postItemWithAuthorization(new URL(RoleResources.buildPath(), instance.config.host), instance.
|
|
41
|
+
return RoleSchema.parse(await postItemWithAuthorization(new URL(RoleResources.buildPath(), instance.config.host), instance.authorize, InsertRolePayloadSchema.parse(item)));
|
|
42
42
|
}
|
|
43
43
|
export async function updateRole(instance, id, item) {
|
|
44
|
-
return RoleSchema.parse(await patchItemWithAuthorization(new URL(RoleResources.buildPath(id), instance.config.host), instance.
|
|
44
|
+
return RoleSchema.parse(await patchItemWithAuthorization(new URL(RoleResources.buildPath(id), instance.config.host), instance.authorize, UpdateRolePayloadSchema.parse(item)));
|
|
45
45
|
}
|
|
46
46
|
export async function deleteRole(instance, id) {
|
|
47
|
-
return RoleSchema.parse(await deleteItemWithAuthorization(new URL(RoleResources.buildPath(id), instance.config.host), instance.
|
|
47
|
+
return RoleSchema.parse(await deleteItemWithAuthorization(new URL(RoleResources.buildPath(id), instance.config.host), instance.authorize));
|
|
48
48
|
}
|
|
@@ -2,6 +2,7 @@ import { MondoIdentity } from './resources/init.js';
|
|
|
2
2
|
export { defaultMutationRequestHeaders, defaultRequestHeaders, responseToHttpError, toHttpError, } from './resources/utils.js';
|
|
3
3
|
export * from './errors/http.js';
|
|
4
4
|
export * from './errors/validation.js';
|
|
5
|
+
export type { Authorizer } from './resources/authorization.js';
|
|
5
6
|
export * from './schema/schema.js';
|
|
6
7
|
export default MondoIdentity;
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,EACrB,mBAAmB,EACnB,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAE9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,oBAAoB,CAAC;AAEnC,eAAe,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,EACrB,mBAAmB,EACnB,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAE9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AAEvC,YAAY,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,cAAc,oBAAoB,CAAC;AAEnC,eAAe,aAAa,CAAC"}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type AuthorizeOptions = {
|
|
2
|
+
/** Force a credential refresh before authorizing the request. */
|
|
3
|
+
refresh?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type AccessToken = string | {
|
|
6
|
+
accessToken: string;
|
|
7
|
+
expiresAt?: number;
|
|
8
|
+
scope?: string;
|
|
9
|
+
type?: string;
|
|
10
|
+
};
|
|
11
|
+
export type AccessTokenProvider = (options?: AuthorizeOptions) => AccessToken | Promise<AccessToken>;
|
|
12
|
+
/**
|
|
13
|
+
* Authorizer function type that adds authentication to requests.
|
|
14
|
+
* Takes a RequestInit object and returns it with authorization headers added.
|
|
15
|
+
* Async authorization can refresh credentials before the outbound API request.
|
|
16
|
+
*/
|
|
17
|
+
export type Authorizer = (request: RequestInit, options?: AuthorizeOptions) => RequestInit | Promise<RequestInit>;
|
|
18
|
+
export declare function getAccessTokenValue(accessToken: AccessToken): string;
|
|
2
19
|
//# sourceMappingURL=authorization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../../../src/common/resources/authorization.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../../../src/common/resources/authorization.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iEAAiE;IACjE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB,MAAM,GACN;IACE,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,MAAM,MAAM,mBAAmB,GAAG,CAChC,OAAO,CAAC,EAAE,gBAAgB,KACvB,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAExC;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,CACvB,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,gBAAgB,KACvB,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAExC,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAIpE"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as z from 'zod/v4';
|
|
2
|
+
import { type AccessTokenProvider, type Authorizer } from './authorization.js';
|
|
2
3
|
declare const ConfigSchema: z.ZodObject<{
|
|
3
|
-
accessToken: z.ZodString
|
|
4
|
+
accessToken: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<AccessTokenProvider, AccessTokenProvider>]>;
|
|
4
5
|
host: z.ZodPipe<z.ZodDefault<z.ZodURL>, z.ZodTransform<URL, string>>;
|
|
5
6
|
}, z.core.$strip>;
|
|
6
7
|
export type ConfigProps = z.input<typeof ConfigSchema>;
|
|
7
8
|
export type Config = z.output<typeof ConfigSchema>;
|
|
8
9
|
export declare class MondoIdentity {
|
|
9
10
|
readonly config: Config;
|
|
11
|
+
readonly authorize: Authorizer;
|
|
10
12
|
constructor(config: ConfigProps);
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
get authorizer(): (request: RequestInit) => RequestInit;
|
|
13
|
+
/** The base URL for API requests. */
|
|
14
|
+
get baseUrl(): URL;
|
|
15
15
|
}
|
|
16
16
|
export {};
|
|
17
17
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/common/resources/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/common/resources/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAEhB,MAAM,oBAAoB,CAAC;AAmB5B,QAAA,MAAM,YAAY;;;iBAA0B,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACvD,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEnD,qBAAa,aAAa;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,SAAgB,SAAS,EAAE,UAAU,CAAC;gBAEnB,MAAM,EAAE,WAAW;IActC,qCAAqC;IACrC,IAAW,OAAO,IAAI,GAAG,CAExB;CACF"}
|
|
@@ -1,32 +1,38 @@
|
|
|
1
1
|
import * as z from 'zod/v4';
|
|
2
|
+
import { getAccessTokenValue, } from './authorization.js';
|
|
2
3
|
const BaseConfigSchema = z.object({
|
|
3
4
|
host: z
|
|
4
5
|
.url()
|
|
5
|
-
.default('https://
|
|
6
|
+
.default('https://api.mondoidentity.com')
|
|
6
7
|
.pipe(z.transform((v) => new URL(v))),
|
|
7
8
|
});
|
|
8
9
|
const AccessTokenConfigSchema = z.object({
|
|
9
10
|
...BaseConfigSchema.shape,
|
|
10
|
-
accessToken: z.
|
|
11
|
+
accessToken: z.union([
|
|
12
|
+
z.string().min(1),
|
|
13
|
+
z.custom((value) => typeof value === 'function', {
|
|
14
|
+
error: 'Access token must be a string or token provider function',
|
|
15
|
+
}),
|
|
16
|
+
]),
|
|
11
17
|
});
|
|
12
18
|
const ConfigSchema = AccessTokenConfigSchema;
|
|
13
19
|
export class MondoIdentity {
|
|
14
20
|
config;
|
|
21
|
+
authorize;
|
|
15
22
|
constructor(config) {
|
|
16
23
|
this.config = initConfig(config);
|
|
24
|
+
this.authorize = async (request, options) => {
|
|
25
|
+
const accessToken = typeof this.config.accessToken === 'function'
|
|
26
|
+
? await this.config.accessToken(options)
|
|
27
|
+
: this.config.accessToken;
|
|
28
|
+
request.headers = new Headers(request.headers);
|
|
29
|
+
request.headers.set('authorization', getAccessTokenValue(accessToken));
|
|
30
|
+
return request;
|
|
31
|
+
};
|
|
17
32
|
}
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
get authorizer() {
|
|
22
|
-
if (this.config.accessToken) {
|
|
23
|
-
return (request) => {
|
|
24
|
-
request.headers = new Headers(request.headers);
|
|
25
|
-
request.headers.append('authorization', this.config.accessToken);
|
|
26
|
-
return request;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
return (request) => request;
|
|
33
|
+
/** The base URL for API requests. */
|
|
34
|
+
get baseUrl() {
|
|
35
|
+
return this.config.host;
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
function initConfig(config) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
1
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
2
2
|
import { MondoIdentity } from './init.js';
|
|
3
3
|
describe('Common Resources - Init', () => {
|
|
4
4
|
describe('MondoIdentity class', () => {
|
|
@@ -18,7 +18,7 @@ describe('Common Resources - Init', () => {
|
|
|
18
18
|
};
|
|
19
19
|
const mondoIdentity = new MondoIdentity(config);
|
|
20
20
|
expect(mondoIdentity.config.accessToken).toBe('test-access-token');
|
|
21
|
-
expect(mondoIdentity.config.host.toString()).toBe('https://
|
|
21
|
+
expect(mondoIdentity.config.host.toString()).toBe('https://api.mondoidentity.com/');
|
|
22
22
|
});
|
|
23
23
|
test('should parse URL host correctly', () => {
|
|
24
24
|
const config = {
|
|
@@ -62,6 +62,11 @@ describe('Common Resources - Init', () => {
|
|
|
62
62
|
};
|
|
63
63
|
expect(() => new MondoIdentity(config)).toThrow('Invalid configuration');
|
|
64
64
|
});
|
|
65
|
+
test('should initialize with an access token provider', () => {
|
|
66
|
+
const accessToken = vi.fn(() => 'provided-token');
|
|
67
|
+
const mondoIdentity = new MondoIdentity({ accessToken });
|
|
68
|
+
expect(mondoIdentity.config.accessToken).toBe(accessToken);
|
|
69
|
+
});
|
|
65
70
|
});
|
|
66
71
|
describe('config property', () => {
|
|
67
72
|
test('should be readonly', () => {
|
|
@@ -85,29 +90,29 @@ describe('Common Resources - Init', () => {
|
|
|
85
90
|
expect(mondoIdentity.config.host.toString()).toBe(`${config.host}/`);
|
|
86
91
|
});
|
|
87
92
|
});
|
|
88
|
-
describe('
|
|
89
|
-
test('should return function that adds authorization header when access token is provided', () => {
|
|
93
|
+
describe('authorize property', () => {
|
|
94
|
+
test('should return function that adds authorization header when access token is provided', async () => {
|
|
90
95
|
const config = {
|
|
91
96
|
accessToken: 'bearer-token-123',
|
|
92
97
|
};
|
|
93
98
|
const mondoIdentity = new MondoIdentity(config);
|
|
94
|
-
const
|
|
95
|
-
expect(typeof
|
|
99
|
+
const authorize = mondoIdentity.authorize;
|
|
100
|
+
expect(typeof authorize).toBe('function');
|
|
96
101
|
const mockRequest = {
|
|
97
102
|
method: 'GET',
|
|
98
103
|
headers: {},
|
|
99
104
|
};
|
|
100
|
-
const authorizedRequest =
|
|
105
|
+
const authorizedRequest = await authorize(mockRequest);
|
|
101
106
|
expect(authorizedRequest.headers).toBeInstanceOf(Headers);
|
|
102
107
|
const headers = authorizedRequest.headers;
|
|
103
108
|
expect(headers.get('authorization')).toBe('bearer-token-123');
|
|
104
109
|
});
|
|
105
|
-
test('should preserve existing headers when adding authorization', () => {
|
|
110
|
+
test('should preserve existing headers when adding authorization', async () => {
|
|
106
111
|
const config = {
|
|
107
112
|
accessToken: 'test-token',
|
|
108
113
|
};
|
|
109
114
|
const mondoIdentity = new MondoIdentity(config);
|
|
110
|
-
const
|
|
115
|
+
const authorize = mondoIdentity.authorize;
|
|
111
116
|
const mockRequest = {
|
|
112
117
|
method: 'POST',
|
|
113
118
|
headers: {
|
|
@@ -115,18 +120,18 @@ describe('Common Resources - Init', () => {
|
|
|
115
120
|
'user-agent': 'test-client',
|
|
116
121
|
},
|
|
117
122
|
};
|
|
118
|
-
const authorizedRequest =
|
|
123
|
+
const authorizedRequest = await authorize(mockRequest);
|
|
119
124
|
const headers = authorizedRequest.headers;
|
|
120
125
|
expect(headers.get('authorization')).toBe('test-token');
|
|
121
126
|
expect(headers.get('content-type')).toBe('application/json');
|
|
122
127
|
expect(headers.get('user-agent')).toBe('test-client');
|
|
123
128
|
});
|
|
124
|
-
test('should handle Headers object as input', () => {
|
|
129
|
+
test('should handle Headers object as input', async () => {
|
|
125
130
|
const config = {
|
|
126
131
|
accessToken: 'header-token',
|
|
127
132
|
};
|
|
128
133
|
const mondoIdentity = new MondoIdentity(config);
|
|
129
|
-
const
|
|
134
|
+
const authorize = mondoIdentity.authorize;
|
|
130
135
|
const existingHeaders = new Headers({
|
|
131
136
|
accept: 'application/json',
|
|
132
137
|
});
|
|
@@ -134,67 +139,87 @@ describe('Common Resources - Init', () => {
|
|
|
134
139
|
method: 'GET',
|
|
135
140
|
headers: existingHeaders,
|
|
136
141
|
};
|
|
137
|
-
const authorizedRequest =
|
|
142
|
+
const authorizedRequest = await authorize(mockRequest);
|
|
138
143
|
const headers = authorizedRequest.headers;
|
|
139
144
|
expect(headers.get('authorization')).toBe('header-token');
|
|
140
145
|
expect(headers.get('accept')).toBe('application/json');
|
|
141
146
|
});
|
|
142
|
-
test('should handle undefined headers', () => {
|
|
147
|
+
test('should handle undefined headers', async () => {
|
|
143
148
|
const config = {
|
|
144
149
|
accessToken: 'undefined-headers-token',
|
|
145
150
|
};
|
|
146
151
|
const mondoIdentity = new MondoIdentity(config);
|
|
147
|
-
const
|
|
152
|
+
const authorize = mondoIdentity.authorize;
|
|
148
153
|
const mockRequest = {
|
|
149
154
|
method: 'GET',
|
|
150
155
|
// headers intentionally undefined
|
|
151
156
|
};
|
|
152
|
-
const authorizedRequest =
|
|
157
|
+
const authorizedRequest = await authorize(mockRequest);
|
|
153
158
|
const headers = authorizedRequest.headers;
|
|
154
159
|
expect(headers.get('authorization')).toBe('undefined-headers-token');
|
|
155
160
|
});
|
|
156
|
-
test('should return same request reference with modified headers', () => {
|
|
161
|
+
test('should return same request reference with modified headers', async () => {
|
|
157
162
|
const config = {
|
|
158
163
|
accessToken: 'reference-token',
|
|
159
164
|
};
|
|
160
165
|
const mondoIdentity = new MondoIdentity(config);
|
|
161
|
-
const
|
|
166
|
+
const authorize = mondoIdentity.authorize;
|
|
162
167
|
const mockRequest = {
|
|
163
168
|
method: 'PUT',
|
|
164
169
|
body: 'test-body',
|
|
165
170
|
};
|
|
166
|
-
const authorizedRequest =
|
|
171
|
+
const authorizedRequest = await authorize(mockRequest);
|
|
167
172
|
// Should be the same object reference
|
|
168
173
|
expect(authorizedRequest).toBe(mockRequest);
|
|
169
174
|
expect(authorizedRequest.method).toBe('PUT');
|
|
170
175
|
expect(authorizedRequest.body).toBe('test-body');
|
|
171
176
|
});
|
|
172
|
-
test('should
|
|
177
|
+
test('should expose a consistent function', async () => {
|
|
173
178
|
const config = {
|
|
174
179
|
accessToken: 'consistent-token',
|
|
175
180
|
};
|
|
176
181
|
const mondoIdentity = new MondoIdentity(config);
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
const authorizer2 = mondoIdentity.authorizer;
|
|
182
|
+
const authorize1 = mondoIdentity.authorize;
|
|
183
|
+
const authorize2 = mondoIdentity.authorize;
|
|
180
184
|
const mockRequest1 = { method: 'GET' };
|
|
181
185
|
const mockRequest2 = { method: 'POST' };
|
|
182
|
-
const result1 =
|
|
183
|
-
const result2 =
|
|
186
|
+
const result1 = await authorize1(mockRequest1);
|
|
187
|
+
const result2 = await authorize2(mockRequest2);
|
|
184
188
|
const headers1 = result1.headers;
|
|
185
189
|
const headers2 = result2.headers;
|
|
186
190
|
expect(headers1.get('authorization')).toBe('consistent-token');
|
|
187
191
|
expect(headers2.get('authorization')).toBe('consistent-token');
|
|
188
192
|
});
|
|
193
|
+
test('should resolve access token providers with authorize options', async () => {
|
|
194
|
+
const accessToken = vi.fn((options) => options?.refresh ? 'refreshed-token' : 'cached-token');
|
|
195
|
+
const mondoIdentity = new MondoIdentity({ accessToken });
|
|
196
|
+
const cachedRequest = await mondoIdentity.authorize({ method: 'GET' });
|
|
197
|
+
const refreshedRequest = await mondoIdentity.authorize({ method: 'GET' }, { refresh: true });
|
|
198
|
+
expect(accessToken).toHaveBeenNthCalledWith(1, undefined);
|
|
199
|
+
expect(accessToken).toHaveBeenNthCalledWith(2, { refresh: true });
|
|
200
|
+
expect(cachedRequest.headers.get('authorization')).toBe('cached-token');
|
|
201
|
+
expect(refreshedRequest.headers.get('authorization')).toBe('refreshed-token');
|
|
202
|
+
});
|
|
203
|
+
test('should use the accessToken value from provider token objects', async () => {
|
|
204
|
+
const accessToken = vi.fn(() => ({
|
|
205
|
+
accessToken: 'object-token',
|
|
206
|
+
expiresAt: Date.now() + 60_000,
|
|
207
|
+
scope: 'workspace:read',
|
|
208
|
+
type: 'Bearer',
|
|
209
|
+
}));
|
|
210
|
+
const mondoIdentity = new MondoIdentity({ accessToken });
|
|
211
|
+
const request = await mondoIdentity.authorize({ method: 'GET' });
|
|
212
|
+
expect(request.headers.get('authorization')).toBe('object-token');
|
|
213
|
+
});
|
|
189
214
|
});
|
|
190
215
|
describe('integration tests', () => {
|
|
191
|
-
test('should work with real-world configuration', () => {
|
|
216
|
+
test('should work with real-world configuration', async () => {
|
|
192
217
|
const config = {
|
|
193
218
|
accessToken: 'prod_12345abcdef67890',
|
|
194
219
|
host: 'https://api.mondoidentity.com/v1',
|
|
195
220
|
};
|
|
196
221
|
const mondoIdentity = new MondoIdentity(config);
|
|
197
|
-
const
|
|
222
|
+
const authorize = mondoIdentity.authorize;
|
|
198
223
|
// Test configuration
|
|
199
224
|
expect(mondoIdentity.config.accessToken).toBe('prod_12345abcdef67890');
|
|
200
225
|
expect(mondoIdentity.config.host).instanceOf(URL);
|
|
@@ -207,21 +232,20 @@ describe('Common Resources - Init', () => {
|
|
|
207
232
|
'user-agent': 'mondo-identity-sdk/1.0.0',
|
|
208
233
|
},
|
|
209
234
|
};
|
|
210
|
-
const authorizedRequest =
|
|
235
|
+
const authorizedRequest = await authorize(apiRequest);
|
|
211
236
|
const headers = authorizedRequest.headers;
|
|
212
237
|
expect(headers.get('authorization')).toBe('prod_12345abcdef67890');
|
|
213
238
|
expect(headers.get('accept')).toBe('application/json');
|
|
214
239
|
expect(headers.get('user-agent')).toBe('mondo-identity-sdk/1.0.0');
|
|
215
240
|
});
|
|
216
|
-
test('should handle edge cases gracefully', () => {
|
|
241
|
+
test('should handle edge cases gracefully', async () => {
|
|
217
242
|
const config = {
|
|
218
243
|
accessToken: 'edge-case-token-with-special-chars!@#$%^&*()',
|
|
219
244
|
host: 'https://localhost:3000',
|
|
220
245
|
};
|
|
221
246
|
const mondoIdentity = new MondoIdentity(config);
|
|
222
|
-
expect(() => {
|
|
223
|
-
const
|
|
224
|
-
const request = authorizer({ method: 'OPTIONS' });
|
|
247
|
+
await expect(async () => {
|
|
248
|
+
const request = await mondoIdentity.authorize({ method: 'OPTIONS' });
|
|
225
249
|
const headers = request.headers;
|
|
226
250
|
headers.get('authorization');
|
|
227
251
|
}).not.toThrow();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function listItemsWithAuthorization<Result>(url: URL,
|
|
3
|
-
export declare function getItemWithAuthorization<Result>(url: URL,
|
|
4
|
-
export declare function patchItemWithAuthorization<Result, Mutation>(url: URL,
|
|
5
|
-
export declare function putItemWithAuthorization<Result, Mutation>(url: URL,
|
|
6
|
-
export declare function postItemWithAuthorization<Result, Mutation>(url: URL,
|
|
7
|
-
export declare function deleteItemWithAuthorization<Result>(url: URL,
|
|
1
|
+
import type { Authorizer } from './authorization.js';
|
|
2
|
+
export declare function listItemsWithAuthorization<Result>(url: URL, authorizer: Authorizer): Promise<Result>;
|
|
3
|
+
export declare function getItemWithAuthorization<Result>(url: URL, authorizer: Authorizer): Promise<Result>;
|
|
4
|
+
export declare function patchItemWithAuthorization<Result, Mutation>(url: URL, authorizer: Authorizer, item: Mutation): Promise<Result>;
|
|
5
|
+
export declare function putItemWithAuthorization<Result, Mutation>(url: URL, authorizer: Authorizer, item: Mutation): Promise<Result>;
|
|
6
|
+
export declare function postItemWithAuthorization<Result, Mutation>(url: URL, authorizer: Authorizer, item?: Mutation): Promise<Result>;
|
|
7
|
+
export declare function deleteItemWithAuthorization<Result>(url: URL, authorizer: Authorizer): Promise<Result>;
|
|
8
8
|
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../../../src/common/resources/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../../../src/common/resources/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AASrD,wBAAsB,0BAA0B,CAAC,MAAM,EACrD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED,wBAAsB,wBAAwB,CAAC,MAAM,EACnD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED,wBAAsB,0BAA0B,CAAC,MAAM,EAAE,QAAQ,EAC/D,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED,wBAAsB,wBAAwB,CAAC,MAAM,EAAE,QAAQ,EAC7D,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,MAAM,CAAC,CAEjB;AA2BD,wBAAsB,yBAAyB,CAAC,MAAM,EAAE,QAAQ,EAC9D,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,IAAI,CAAC,EAAE,QAAQ,GACd,OAAO,CAAC,MAAM,CAAC,CAkBjB;AAED,wBAAsB,2BAA2B,CAAC,MAAM,EACtD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,MAAM,CAAC,CAiBjB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { defaultMutationRequestHeaders, defaultRequestHeaders, jsonBody, responseToHttpError, toHttpError, } from './utils.js';
|
|
2
|
-
export async function listItemsWithAuthorization(url,
|
|
2
|
+
export async function listItemsWithAuthorization(url, authorizer) {
|
|
3
3
|
try {
|
|
4
4
|
console.debug('List items', { url });
|
|
5
|
-
const response = await
|
|
5
|
+
const response = await fetchWithAuthorization(url, authorizer, {
|
|
6
6
|
method: 'GET',
|
|
7
7
|
headers: defaultRequestHeaders(),
|
|
8
|
-
})
|
|
8
|
+
});
|
|
9
9
|
if (response.ok) {
|
|
10
10
|
return await response.json();
|
|
11
11
|
}
|
|
@@ -15,13 +15,13 @@ export async function listItemsWithAuthorization(url, authorization) {
|
|
|
15
15
|
throw toHttpError(error);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
export async function getItemWithAuthorization(url,
|
|
18
|
+
export async function getItemWithAuthorization(url, authorizer) {
|
|
19
19
|
try {
|
|
20
20
|
console.debug('GET item', { url });
|
|
21
|
-
const response = await
|
|
21
|
+
const response = await fetchWithAuthorization(url, authorizer, {
|
|
22
22
|
method: 'GET',
|
|
23
23
|
headers: defaultRequestHeaders(),
|
|
24
|
-
})
|
|
24
|
+
});
|
|
25
25
|
if (response.ok) {
|
|
26
26
|
return await response.json();
|
|
27
27
|
}
|
|
@@ -31,20 +31,20 @@ export async function getItemWithAuthorization(url, authorization) {
|
|
|
31
31
|
throw toHttpError(error);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
export async function patchItemWithAuthorization(url,
|
|
35
|
-
return mutateItemWithAuthorization('PATCH', url,
|
|
34
|
+
export async function patchItemWithAuthorization(url, authorizer, item) {
|
|
35
|
+
return mutateItemWithAuthorization('PATCH', url, authorizer, item);
|
|
36
36
|
}
|
|
37
|
-
export async function putItemWithAuthorization(url,
|
|
38
|
-
return mutateItemWithAuthorization('PUT', url,
|
|
37
|
+
export async function putItemWithAuthorization(url, authorizer, item) {
|
|
38
|
+
return mutateItemWithAuthorization('PUT', url, authorizer, item);
|
|
39
39
|
}
|
|
40
|
-
async function mutateItemWithAuthorization(method, url,
|
|
40
|
+
async function mutateItemWithAuthorization(method, url, authorizer, item) {
|
|
41
41
|
try {
|
|
42
42
|
console.debug(`${method} item`, { url, item });
|
|
43
|
-
const response = await
|
|
43
|
+
const response = await fetchWithAuthorization(url, authorizer, {
|
|
44
44
|
method,
|
|
45
45
|
headers: defaultMutationRequestHeaders(),
|
|
46
46
|
body: JSON.stringify(item),
|
|
47
|
-
})
|
|
47
|
+
});
|
|
48
48
|
if (response.ok) {
|
|
49
49
|
return await response.json();
|
|
50
50
|
}
|
|
@@ -54,14 +54,14 @@ async function mutateItemWithAuthorization(method, url, authorization, item) {
|
|
|
54
54
|
throw toHttpError(error);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
export async function postItemWithAuthorization(url,
|
|
57
|
+
export async function postItemWithAuthorization(url, authorizer, item) {
|
|
58
58
|
try {
|
|
59
59
|
console.debug('POST item', { url, item });
|
|
60
|
-
const response = await
|
|
60
|
+
const response = await fetchWithAuthorization(url, authorizer, {
|
|
61
61
|
method: 'POST',
|
|
62
62
|
headers: defaultMutationRequestHeaders(),
|
|
63
63
|
body: item ? JSON.stringify(item) : undefined,
|
|
64
|
-
})
|
|
64
|
+
});
|
|
65
65
|
if (response.ok) {
|
|
66
66
|
return await response.json();
|
|
67
67
|
}
|
|
@@ -71,13 +71,13 @@ export async function postItemWithAuthorization(url, authorization, item) {
|
|
|
71
71
|
throw toHttpError(error);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
export async function deleteItemWithAuthorization(url,
|
|
74
|
+
export async function deleteItemWithAuthorization(url, authorizer) {
|
|
75
75
|
try {
|
|
76
76
|
console.debug('Delete item', { url });
|
|
77
|
-
const response = await
|
|
77
|
+
const response = await fetchWithAuthorization(url, authorizer, {
|
|
78
78
|
method: 'DELETE',
|
|
79
79
|
headers: defaultRequestHeaders(),
|
|
80
|
-
})
|
|
80
|
+
});
|
|
81
81
|
if (response.ok) {
|
|
82
82
|
return (await jsonBody(response));
|
|
83
83
|
}
|
|
@@ -87,3 +87,19 @@ export async function deleteItemWithAuthorization(url, authorization) {
|
|
|
87
87
|
throw toHttpError(error);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
+
async function fetchWithAuthorization(url, authorizer, request) {
|
|
91
|
+
const response = await fetch(url, await authorizer(cloneRequestInit(request)));
|
|
92
|
+
if (!isAuthorizationResponse(response)) {
|
|
93
|
+
return response;
|
|
94
|
+
}
|
|
95
|
+
return fetch(url, await authorizer(cloneRequestInit(request), { refresh: true }));
|
|
96
|
+
}
|
|
97
|
+
function isAuthorizationResponse(response) {
|
|
98
|
+
return [401, 403].includes(response.status);
|
|
99
|
+
}
|
|
100
|
+
function cloneRequestInit(request) {
|
|
101
|
+
return {
|
|
102
|
+
...request,
|
|
103
|
+
headers: new Headers(request.headers),
|
|
104
|
+
};
|
|
105
|
+
}
|