@cratis/arc 22.14.2 → 22.16.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/cjs/identity/IdentityProvider.js +3 -3
- package/dist/cjs/identity/IdentityProvider.js.map +1 -1
- package/dist/cjs/identity/deserializeIdentityDetails.js +70 -0
- package/dist/cjs/identity/deserializeIdentityDetails.js.map +1 -0
- package/dist/cjs/identity/index.js +2 -0
- package/dist/cjs/identity/index.js.map +1 -1
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/esm/identity/IdentityProvider.js +3 -3
- package/dist/esm/identity/IdentityProvider.js.map +1 -1
- package/dist/esm/identity/deserializeIdentityDetails.d.ts +3 -0
- package/dist/esm/identity/deserializeIdentityDetails.d.ts.map +1 -0
- package/dist/esm/identity/deserializeIdentityDetails.js +68 -0
- package/dist/esm/identity/deserializeIdentityDetails.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_a_details_type_that_declares_no_fields.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_a_details_type_that_declares_no_fields.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_a_details_type_that_declares_no_fields.js +36 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_a_details_type_that_declares_no_fields.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_type_safe_details.js +18 -4
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_type_safe_details.js.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_type_safe_details.js +18 -4
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_type_safe_details.js.map +1 -1
- package/dist/esm/identity/index.d.ts +1 -0
- package/dist/esm/identity/index.d.ts.map +1 -1
- package/dist/esm/identity/index.js +1 -0
- package/dist/esm/identity/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/identity/IdentityProvider.ts +4 -3
- package/identity/deserializeIdentityDetails.ts +79 -0
- package/identity/for_IdentityProvider/when_getting_current/with_a_details_type_that_declares_no_fields.ts +48 -0
- package/identity/for_IdentityProvider/when_getting_current/with_type_safe_details.ts +17 -8
- package/identity/for_IdentityProvider/when_refreshing/with_type_safe_details.ts +16 -7
- package/identity/index.ts +1 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var fundamentals = require('@cratis/fundamentals');
|
|
4
3
|
var IIdentityProvider = require('./IIdentityProvider.js');
|
|
4
|
+
var deserializeIdentityDetails = require('./deserializeIdentityDetails.js');
|
|
5
5
|
var Globals = require('../Globals.js');
|
|
6
6
|
var UrlHelpers = require('../UrlHelpers.js');
|
|
7
7
|
var joinPaths = require('../joinPaths.js');
|
|
@@ -43,7 +43,7 @@ var joinPaths = require('../joinPaths.js');
|
|
|
43
43
|
if (cookie.length == 2) {
|
|
44
44
|
const json = atob(cookie[1]);
|
|
45
45
|
const result = JSON.parse(json);
|
|
46
|
-
const details =
|
|
46
|
+
const details = deserializeIdentityDetails.deserializeIdentityDetails(type, result.details);
|
|
47
47
|
return {
|
|
48
48
|
id: result.id,
|
|
49
49
|
name: result.name,
|
|
@@ -75,7 +75,7 @@ var joinPaths = require('../joinPaths.js');
|
|
|
75
75
|
return IdentityProvider.notSet(type);
|
|
76
76
|
}
|
|
77
77
|
const result = await response.json();
|
|
78
|
-
const details =
|
|
78
|
+
const details = deserializeIdentityDetails.deserializeIdentityDetails(type, result.details);
|
|
79
79
|
return {
|
|
80
80
|
id: result.id,
|
|
81
81
|
name: result.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { IIdentityProvider } from './IIdentityProvider';\nimport { IIdentity } from './IIdentity';\nimport { IdentityProviderResult } from './IdentityProviderResult';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { joinPaths } from '../joinPaths';\n\n/**\n * Represents an implementation of {@link IIdentityProvider}.\n*/\nexport class IdentityProvider extends IIdentityProvider {\n\n static readonly CookieName = '.cratis-identity';\n static httpHeadersCallback: GetHttpHeaders | undefined;\n static apiBasePath: string = '';\n static origin: string = '';\n\n /**\n * Sets the HTTP headers callback.\n * @param callback Callback to set.\n */\n static setHttpHeadersCallback(callback: GetHttpHeaders): void {\n IdentityProvider.httpHeadersCallback = callback;\n }\n\n /**\n * Sets the API base path.\n * @param apiBasePath API base path to set.\n */\n static setApiBasePath(apiBasePath: string): void {\n IdentityProvider.apiBasePath = apiBasePath;\n }\n\n /**\n * Sets the origin.\n * @param origin Origin to set.\n */\n static setOrigin(origin: string): void {\n IdentityProvider.origin = origin;\n }\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @param type Optional constructor for the details type to enable type-safe deserialization.\n * @returns The current identity as {@link IIdentity}.\n * @remarks The `extends object` constraint is required for compatibility with JsonSerializer.deserializeFromInstance().\n */\n static async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n const cookie = this.getCookie();\n if (cookie.length == 2) {\n const json = atob(cookie[1]);\n const result = JSON.parse(json) as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n } as IIdentity<TDetails>;\n } else {\n const identity = await this.refresh<TDetails>(type);\n return identity;\n }\n }\n\n /** @inheritdoc */\n async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n return IdentityProvider.getCurrent<TDetails>(type);\n }\n\n static async refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n IdentityProvider.clearIdentityCookie();\n const origin = IdentityProvider.origin || Globals.origin || '';\n const apiBasePath = IdentityProvider.apiBasePath || Globals.apiBasePath || '';\n const route = joinPaths(apiBasePath, '/.cratis/me');\n const url = UrlHelpers.createUrlFrom(origin, apiBasePath, route);\n const response = await fetch(\n url, {\n method: 'GET',\n headers: IdentityProvider.httpHeadersCallback?.() ?? {}\n });\n\n if (!response.ok) {\n return IdentityProvider.notSet(type);\n }\n\n const result = await response.json() as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static notSet<TDetails extends object = object>(type?: Constructor<TDetails>): IIdentity<TDetails> {\n return {\n id: '',\n name: '',\n roles: [],\n details: {} as TDetails,\n isSet: false,\n isInRole: () => false,\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static getCookie() {\n if (typeof document === 'undefined') return [];\n const decoded = decodeURIComponent(document.cookie);\n const cookies = decoded.split(';').map(_ => _.trim());\n const cookie = cookies.find(_ => _.indexOf(`${IdentityProvider.CookieName}=`) == 0);\n if (cookie) {\n const keyValue = cookie.split('=');\n return [keyValue[0].trim(), keyValue[1].trim()];\n }\n return [];\n }\n\n /**\n * Clears the identity cookie used by Arc to cache the current identity.\n * Call this when the user logs out to ensure subsequent requests and WebSocket\n * connections do not carry stale credentials.\n */\n static clearIdentityCookie(): void {\n if (typeof document === 'undefined') return;\n document.cookie = `${IdentityProvider.CookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;\n }\n}\n"],"names":["IdentityProvider","IIdentityProvider","CookieName","httpHeadersCallback","apiBasePath","origin","setHttpHeadersCallback","callback","setApiBasePath","setOrigin","getCurrent","type","cookie","getCookie","length","json","atob","result","JSON","parse","details","JsonSerializer","deserializeFromInstance","id","name","roles","isSet","isInRole","role","includes","refresh","identity","clearIdentityCookie","Globals","route","joinPaths","url","UrlHelpers","createUrlFrom","response","fetch","method","headers","ok","notSet","document","decoded","decodeURIComponent","cookies","split","map","_","trim","find","indexOf","keyValue"],"mappings":";;;;;;;;AAAA;AACA;AAWA;;AAEA,GACO,MAAMA,gBAAAA,SAAyBC,mCAAAA,CAAAA;AAElC,IAAA,OAAgBC,aAAa,kBAAA;AAC7B,IAAA,OAAOC,mBAAAA;AACP,IAAA,OAAOC,cAAsB,EAAA;AAC7B,IAAA,OAAOC,SAAiB,EAAA;AAExB;;;QAIA,OAAOC,sBAAAA,CAAuBC,QAAwB,EAAQ;AAC1DP,QAAAA,gBAAAA,CAAiBG,mBAAmB,GAAGI,QAAAA;AAC3C,IAAA;AAEA;;;QAIA,OAAOC,cAAAA,CAAeJ,WAAmB,EAAQ;AAC7CJ,QAAAA,gBAAAA,CAAiBI,WAAW,GAAGA,WAAAA;AACnC,IAAA;AAEA;;;QAIA,OAAOK,SAAAA,CAAUJ,MAAc,EAAQ;AACnCL,QAAAA,gBAAAA,CAAiBK,MAAM,GAAGA,MAAAA;AAC9B,IAAA;AAEA;;;;;QAMA,aAAaK,UAAAA,CAA6CC,IAA4B,EAAgC;QAClH,MAAMC,MAAAA,GAAS,IAAI,CAACC,SAAS,EAAA;QAC7B,IAAID,MAAAA,CAAOE,MAAM,IAAI,CAAA,EAAG;AACpB,YAAA,MAAMC,IAAAA,GAAOC,IAAAA,CAAKJ,MAAM,CAAC,CAAA,CAAE,CAAA;YAC3B,MAAMK,MAAAA,GAASC,IAAAA,CAAKC,KAAK,CAACJ,IAAAA,CAAAA;YAC1B,MAAMK,OAAAA,GAAUT,IAAAA,GAAOU,2BAAAA,CAAeC,uBAAuB,CAACX,MAAMM,MAAAA,CAAOG,OAAO,CAAA,GAAIH,MAAA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AMC,OAAAA,GAAUC,kBAAAA,CAAmBF,QAAAA,CAASjC,MAAM,CAAA;QAClD,MAAMoC,OAAAA,GAAUF,OAAAA,CAAQG,KAAK,CAAC,GAAA,CAAA,CAAKC,GAAG,CAACC,CAAAA,CAAAA,GAAKA,CAAAA,CAAEC,IAAI,EAAA,CAAA;AAClD,QAAA,MAAMxC,MAAAA,GAASoC,OAAAA,CAAQK,IAAI,CAACF,CAAAA,CAAAA,GAAKA,CAAAA,CAAEG,OAAO,CAAC,GAAGtD,gBAAAA,CAAiBE,UAAU,CAAC,CAAC,CAAC,CAAA,IAAK,CAAA,CAAA;AACjF,QAAA,IAAIU,MAAAA,EAAQ;YACR,MAAM2C,QAAAA,GAAW3C,MAAAA,CAAOqC,KAAK,CAAC,GAAA,CAAA;YAC9B,OAAO;gBAACM,QAAQ,CAAC,CAAA,CAAE,CAACH,IAAI,EAAA;gBAAIG,QAAQ,CAAC,CAAA,CAAE,CAACH,IAAI;AAAG,aAAA;AACnD,QAAA;AACA,QAAA,OAAO,EAAE;AACb,IAAA;AAEA;;;;AAIC,QACD,OAAOpB,mBAAAA,GAA4B;QAC/B,IAAI,OAAOa,aAAa,WAAA,EAAa;AACrCA,QAAAA,QAAAA,CAASjC,MAAM,GAAG,CAAA,EAAGZ,iBAAiBE,UAAU,CAAC,uCAAuC,CAAC;AAC7F,IAAA;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from '@cratis/fundamentals';\nimport { IIdentityProvider } from './IIdentityProvider';\nimport { IIdentity } from './IIdentity';\nimport { IdentityProviderResult } from './IdentityProviderResult';\nimport { deserializeIdentityDetails } from './deserializeIdentityDetails';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { joinPaths } from '../joinPaths';\n\n/**\n * Represents an implementation of {@link IIdentityProvider}.\n*/\nexport class IdentityProvider extends IIdentityProvider {\n\n static readonly CookieName = '.cratis-identity';\n static httpHeadersCallback: GetHttpHeaders | undefined;\n static apiBasePath: string = '';\n static origin: string = '';\n\n /**\n * Sets the HTTP headers callback.\n * @param callback Callback to set.\n */\n static setHttpHeadersCallback(callback: GetHttpHeaders): void {\n IdentityProvider.httpHeadersCallback = callback;\n }\n\n /**\n * Sets the API base path.\n * @param apiBasePath API base path to set.\n */\n static setApiBasePath(apiBasePath: string): void {\n IdentityProvider.apiBasePath = apiBasePath;\n }\n\n /**\n * Sets the origin.\n * @param origin Origin to set.\n */\n static setOrigin(origin: string): void {\n IdentityProvider.origin = origin;\n }\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @param type Optional constructor for the details type to enable type-safe deserialization.\n * @returns The current identity as {@link IIdentity}.\n * @remarks The `extends object` constraint is required for compatibility with JsonSerializer.deserializeFromInstance().\n */\n static async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n const cookie = this.getCookie();\n if (cookie.length == 2) {\n const json = atob(cookie[1]);\n const result = JSON.parse(json) as IdentityProviderResult;\n const details = deserializeIdentityDetails(type, result.details);\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n } as IIdentity<TDetails>;\n } else {\n const identity = await this.refresh<TDetails>(type);\n return identity;\n }\n }\n\n /** @inheritdoc */\n async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n return IdentityProvider.getCurrent<TDetails>(type);\n }\n\n static async refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n IdentityProvider.clearIdentityCookie();\n const origin = IdentityProvider.origin || Globals.origin || '';\n const apiBasePath = IdentityProvider.apiBasePath || Globals.apiBasePath || '';\n const route = joinPaths(apiBasePath, '/.cratis/me');\n const url = UrlHelpers.createUrlFrom(origin, apiBasePath, route);\n const response = await fetch(\n url, {\n method: 'GET',\n headers: IdentityProvider.httpHeadersCallback?.() ?? {}\n });\n\n if (!response.ok) {\n return IdentityProvider.notSet(type);\n }\n\n const result = await response.json() as IdentityProviderResult;\n const details = deserializeIdentityDetails(type, result.details);\n\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static notSet<TDetails extends object = object>(type?: Constructor<TDetails>): IIdentity<TDetails> {\n return {\n id: '',\n name: '',\n roles: [],\n details: {} as TDetails,\n isSet: false,\n isInRole: () => false,\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static getCookie() {\n if (typeof document === 'undefined') return [];\n const decoded = decodeURIComponent(document.cookie);\n const cookies = decoded.split(';').map(_ => _.trim());\n const cookie = cookies.find(_ => _.indexOf(`${IdentityProvider.CookieName}=`) == 0);\n if (cookie) {\n const keyValue = cookie.split('=');\n return [keyValue[0].trim(), keyValue[1].trim()];\n }\n return [];\n }\n\n /**\n * Clears the identity cookie used by Arc to cache the current identity.\n * Call this when the user logs out to ensure subsequent requests and WebSocket\n * connections do not carry stale credentials.\n */\n static clearIdentityCookie(): void {\n if (typeof document === 'undefined') return;\n document.cookie = `${IdentityProvider.CookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;\n }\n}\n"],"names":["IdentityProvider","IIdentityProvider","CookieName","httpHeadersCallback","apiBasePath","origin","setHttpHeadersCallback","callback","setApiBasePath","setOrigin","getCurrent","type","cookie","getCookie","length","json","atob","result","JSON","parse","details","deserializeIdentityDetails","id","name","roles","isSet","isInRole","role","includes","refresh","identity","clearIdentityCookie","Globals","route","joinPaths","url","UrlHelpers","createUrlFrom","response","fetch","method","headers","ok","notSet","document","decoded","decodeURIComponent","c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G,OAAO,CAAC,GAAGrD,gBAAAA,CAAiBE,UAAU,CAAC,CAAC,CAAC,CAAA,IAAK,CAAA,CAAA;AACjF,QAAA,IAAIU,MAAAA,EAAQ;YACR,MAAM0C,QAAAA,GAAW1C,MAAAA,CAAOoC,KAAK,CAAC,GAAA,CAAA;YAC9B,OAAO;gBAACM,QAAQ,CAAC,CAAA,CAAE,CAACH,IAAI,EAAA;gBAAIG,QAAQ,CAAC,CAAA,CAAE,CAACH,IAAI;AAAG,aAAA;AACnD,QAAA;AACA,QAAA,OAAO,EAAE;AACb,IAAA;AAEA;;;;AAIC,QACD,OAAOpB,mBAAAA,GAA4B;QAC/B,IAAI,OAAOa,aAAa,WAAA,EAAa;AACrCA,QAAAA,QAAAA,CAAShC,MAAM,GAAG,CAAA,EAAGZ,iBAAiBE,UAAU,CAAC,uCAAuC,CAAC;AAC7F,IAAA;AACJ;;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fundamentals = require('@cratis/fundamentals');
|
|
4
|
+
|
|
5
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
6
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
7
|
+
/*
|
|
8
|
+
* ⚠️ deserializeIdentityDetails is exported deliberately, unlike deserializeQueryModel in
|
|
9
|
+
* ../queries/deserializeQueryModel.ts.
|
|
10
|
+
*
|
|
11
|
+
* JsonSerializer's converter registry is module state, and a consumer package can easily resolve a
|
|
12
|
+
* different physical copy of @cratis/fundamentals than this one - which is why deserializeQueryModel
|
|
13
|
+
* stays package-private. Identity details are different: @cratis/arc.react's useIdentity() needs to
|
|
14
|
+
* apply the exact same deserialization as this package's own IdentityProvider, for a payload that may
|
|
15
|
+
* already be flowing through this package's IdentityProvider/IIdentity. Exporting the function itself
|
|
16
|
+
* - rather than having @cratis/arc.react re-implement the same logic against its own copy of
|
|
17
|
+
* @cratis/fundamentals - guarantees every identity details value is deserialized through this one
|
|
18
|
+
* physical JsonSerializer/Fields, regardless of which package's copy of @cratis/fundamentals the
|
|
19
|
+
* caller resolved.
|
|
20
|
+
*/ /**
|
|
21
|
+
* Determines whether a details type is a JavaScript primitive wrapper rather than a real,
|
|
22
|
+
* `@field`-decorated model.
|
|
23
|
+
* @param {Constructor} type The details type to check.
|
|
24
|
+
* @returns {boolean} True when the type is a primitive wrapper.
|
|
25
|
+
*/ function isPrimitiveDetailsType(type) {
|
|
26
|
+
return type === String || type === Number || type === Boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Deserializes identity details into their strongly-typed shape, guarding every way that doing so
|
|
30
|
+
* would otherwise crash or silently destroy the payload.
|
|
31
|
+
* @param {Constructor | undefined} type The details type to deserialize into, or `undefined` to leave
|
|
32
|
+
* the payload untouched.
|
|
33
|
+
* @param {unknown} details The raw details payload - parsed JSON from the identity cookie or the
|
|
34
|
+
* `/.cratis/me` endpoint.
|
|
35
|
+
* @returns {unknown} The deserialized instance, or `details` unchanged when deserializing it would be
|
|
36
|
+
* unsafe, pointless, or has already been done.
|
|
37
|
+
* @remarks
|
|
38
|
+
* {@link JsonSerializer.deserializeFromInstance} assumes a well-formed object and a target type
|
|
39
|
+
* carrying `@field` metadata - neither is guaranteed here:
|
|
40
|
+
* - No type means there is nothing to deserialize into.
|
|
41
|
+
* - A `null`/`undefined`/non-object payload would make `deserializeFromInstance`'s internal
|
|
42
|
+
* `instance[field.name]` lookup throw.
|
|
43
|
+
* - A payload that is already an instance of the target type has already been deserialized -
|
|
44
|
+
* deserializing it again is destructive, not merely wasteful: it can throw on a nested temporal
|
|
45
|
+
* value and double-wraps a concept (`{ value: { value: '...' } }`).
|
|
46
|
+
* - `Object` and the primitive wrapper types (`String`, `Number`, `Boolean`) are not real,
|
|
47
|
+
* `@field`-decorated models; deserializing into them would discard the payload.
|
|
48
|
+
* - A type with no `@field`-decorated members deserializes to an empty instance, silently discarding
|
|
49
|
+
* the payload. That is worse than leaving the payload alone, so this warns and passes it through
|
|
50
|
+
* instead - preserving data beats a hard crash for anyone upgrading with an undecorated type.
|
|
51
|
+
*/ function deserializeIdentityDetails(type, details) {
|
|
52
|
+
if (!type || type === Object || isPrimitiveDetailsType(type)) {
|
|
53
|
+
return details;
|
|
54
|
+
}
|
|
55
|
+
if (details === null || details === undefined || typeof details !== 'object') {
|
|
56
|
+
return details;
|
|
57
|
+
}
|
|
58
|
+
if (details instanceof type) {
|
|
59
|
+
return details;
|
|
60
|
+
}
|
|
61
|
+
const fields = fundamentals.Fields.getFieldsForType(type);
|
|
62
|
+
if (fields.length === 0) {
|
|
63
|
+
console.warn(`Identity details type '${type.name}' has no @field-decorated members. Deserializing into ` + 'it would discard the payload and return an empty instance, so the raw payload is being ' + 'passed through instead. Add @field decorators for every property that should be ' + 'populated, or omit the details type to receive the raw payload as-is.');
|
|
64
|
+
return details;
|
|
65
|
+
}
|
|
66
|
+
return fundamentals.JsonSerializer.deserializeFromInstance(type, details);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.deserializeIdentityDetails = deserializeIdentityDetails;
|
|
70
|
+
//# sourceMappingURL=deserializeIdentityDetails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deserializeIdentityDetails.js","sources":["../../../identity/deserializeIdentityDetails.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor, Fields, JsonSerializer } from '@cratis/fundamentals';\n\n/*\n * ⚠️ deserializeIdentityDetails is exported deliberately, unlike deserializeQueryModel in\n * ../queries/deserializeQueryModel.ts.\n *\n * JsonSerializer's converter registry is module state, and a consumer package can easily resolve a\n * different physical copy of @cratis/fundamentals than this one - which is why deserializeQueryModel\n * stays package-private. Identity details are different: @cratis/arc.react's useIdentity() needs to\n * apply the exact same deserialization as this package's own IdentityProvider, for a payload that may\n * already be flowing through this package's IdentityProvider/IIdentity. Exporting the function itself\n * - rather than having @cratis/arc.react re-implement the same logic against its own copy of\n * @cratis/fundamentals - guarantees every identity details value is deserialized through this one\n * physical JsonSerializer/Fields, regardless of which package's copy of @cratis/fundamentals the\n * caller resolved.\n */\n\n/**\n * Determines whether a details type is a JavaScript primitive wrapper rather than a real,\n * `@field`-decorated model.\n * @param {Constructor} type The details type to check.\n * @returns {boolean} True when the type is a primitive wrapper.\n */\nfunction isPrimitiveDetailsType(type: Constructor): boolean {\n return type === String || type === Number || type === Boolean;\n}\n\n/**\n * Deserializes identity details into their strongly-typed shape, guarding every way that doing so\n * would otherwise crash or silently destroy the payload.\n * @param {Constructor | undefined} type The details type to deserialize into, or `undefined` to leave\n * the payload untouched.\n * @param {unknown} details The raw details payload - parsed JSON from the identity cookie or the\n * `/.cratis/me` endpoint.\n * @returns {unknown} The deserialized instance, or `details` unchanged when deserializing it would be\n * unsafe, pointless, or has already been done.\n * @remarks\n * {@link JsonSerializer.deserializeFromInstance} assumes a well-formed object and a target type\n * carrying `@field` metadata - neither is guaranteed here:\n * - No type means there is nothing to deserialize into.\n * - A `null`/`undefined`/non-object payload would make `deserializeFromInstance`'s internal\n * `instance[field.name]` lookup throw.\n * - A payload that is already an instance of the target type has already been deserialized -\n * deserializing it again is destructive, not merely wasteful: it can throw on a nested temporal\n * value and double-wraps a concept (`{ value: { value: '...' } }`).\n * - `Object` and the primitive wrapper types (`String`, `Number`, `Boolean`) are not real,\n * `@field`-decorated models; deserializing into them would discard the payload.\n * - A type with no `@field`-decorated members deserializes to an empty instance, silently discarding\n * the payload. That is worse than leaving the payload alone, so this warns and passes it through\n * instead - preserving data beats a hard crash for anyone upgrading with an undecorated type.\n */\nexport function deserializeIdentityDetails(type: Constructor | undefined, details: unknown): unknown {\n if (!type || type === Object || isPrimitiveDetailsType(type)) {\n return details;\n }\n\n if (details === null || details === undefined || typeof details !== 'object') {\n return details;\n }\n\n if (details instanceof type) {\n return details;\n }\n\n const fields = Fields.getFieldsForType(type);\n if (fields.length === 0) {\n console.warn(\n `Identity details type '${type.name}' has no @field-decorated members. Deserializing into ` +\n 'it would discard the payload and return an empty instance, so the raw payload is being ' +\n 'passed through instead. Add @field decorators for every property that should be ' +\n 'populated, or omit the details type to receive the raw payload as-is.');\n return details;\n }\n\n return JsonSerializer.deserializeFromInstance(type as Constructor<object>, details);\n}\n"],"names":["isPrimitiveDetailsType","type","String","Number","Boolean","deserializeIdentityDetails","details","Object","undefined","fields","Fields","getFieldsForType","length","console","warn","name","JsonSerializer","deserializeFromInstance"],"mappings":";;;;AAAA;AACA;AAIA;;;;;;;;;;;;;;;;;;IAqBA,SAASA,uBAAuBC,IAAiB,EAAA;AAC7C,IAAA,OAAOA,IAAAA,KAASC,MAAAA,IAAUD,IAAAA,KAASE,MAAAA,IAAUF,IAAAA,KAASG,OAAAA;AAC1D;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBC,IACM,SAASC,0BAAAA,CAA2BJ,IAA6B,EAAEK,OAAgB,EAAA;AACtF,IAAA,IAAI,CAACL,IAAAA,IAAQA,IAAAA,KAASM,MAAAA,IAAUP,uBAAuBC,IAAAA,CAAAA,EAAO;QAC1D,OAAOK,OAAAA;AACX,IAAA;AAEA,IAAA,IAAIA,YAAY,IAAA,IAAQA,OAAAA,KAAYE,SAAAA,IAAa,OAAOF,YAAY,QAAA,EAAU;QAC1E,OAAOA,OAAAA;AACX,IAAA;AAEA,IAAA,IAAIA,mBAAmBL,IAAAA,EAAM;QACzB,OAAOK,OAAAA;AACX,IAAA;IAEA,MAAMG,MAAAA,GAASC,mBAAAA,CAAOC,gBAAgB,CAACV,IAAAA,CAAAA;IACvC,IAAIQ,MAAAA,CAAOG,MAAM,KAAK,CAAA,EAAG;AACrBC,QAAAA,OAAAA,CAAQC,IAAI,CACR,CAAC,uBAAuB,EAAEb,IAAAA,CAAKc,IAAI,CAAC,sDAAsD,CAAC,GAC3F,yFAAA,GACA,kFAAA,GACA,uEAAA,CAAA;QACJ,OAAOT,OAAAA;AACX,IAAA;IAEA,OAAOU,2BAAAA,CAAeC,uBAAuB,CAAChB,IAAAA,EAA6BK,OAAAA,CAAAA;AAC/E;;"}
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var IdentityProvider = require('./IdentityProvider.js');
|
|
4
4
|
var IIdentityProvider = require('./IIdentityProvider.js');
|
|
5
|
+
var deserializeIdentityDetails = require('./deserializeIdentityDetails.js');
|
|
5
6
|
|
|
6
7
|
// Copyright (c) Cratis. All rights reserved.
|
|
7
8
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
8
9
|
|
|
9
10
|
exports.IdentityProvider = IdentityProvider.IdentityProvider;
|
|
10
11
|
exports.IIdentityProvider = IIdentityProvider.IIdentityProvider;
|
|
12
|
+
exports.deserializeIdentityDetails = deserializeIdentityDetails.deserializeIdentityDetails;
|
|
11
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../identity/index.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nexport * from './IdentityProvider';\nexport * from './IdentityProviderResult';\nexport * from './IIdentityProvider';\nexport * from './IIdentity';\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../identity/index.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nexport * from './IdentityProvider';\nexport * from './IdentityProviderResult';\nexport * from './IIdentityProvider';\nexport * from './IIdentity';\nexport * from './deserializeIdentityDetails';\n"],"names":[],"mappings":";;;;;;AAAA;AACA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityProvider.d.ts","sourceRoot":"","sources":["../../../identity/IdentityProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"IdentityProvider.d.ts","sourceRoot":"","sources":["../../../identity/Ident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BAAmB,IAAI,IAAI,CAGjC;CACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { JsonSerializer } from '@cratis/fundamentals';
|
|
2
1
|
import { IIdentityProvider } from './IIdentityProvider.js';
|
|
2
|
+
import { deserializeIdentityDetails } from './deserializeIdentityDetails.js';
|
|
3
3
|
import { Globals } from '../Globals.js';
|
|
4
4
|
import { UrlHelpers } from '../UrlHelpers.js';
|
|
5
5
|
import { joinPaths } from '../joinPaths.js';
|
|
@@ -41,7 +41,7 @@ import { joinPaths } from '../joinPaths.js';
|
|
|
41
41
|
if (cookie.length == 2) {
|
|
42
42
|
const json = atob(cookie[1]);
|
|
43
43
|
const result = JSON.parse(json);
|
|
44
|
-
const details =
|
|
44
|
+
const details = deserializeIdentityDetails(type, result.details);
|
|
45
45
|
return {
|
|
46
46
|
id: result.id,
|
|
47
47
|
name: result.name,
|
|
@@ -73,7 +73,7 @@ import { joinPaths } from '../joinPaths.js';
|
|
|
73
73
|
return IdentityProvider.notSet(type);
|
|
74
74
|
}
|
|
75
75
|
const result = await response.json();
|
|
76
|
-
const details =
|
|
76
|
+
const details = deserializeIdentityDetails(type, result.details);
|
|
77
77
|
return {
|
|
78
78
|
id: result.id,
|
|
79
79
|
name: result.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { IIdentityProvider } from './IIdentityProvider';\nimport { IIdentity } from './IIdentity';\nimport { IdentityProviderResult } from './IdentityProviderResult';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { joinPaths } from '../joinPaths';\n\n/**\n * Represents an implementation of {@link IIdentityProvider}.\n*/\nexport class IdentityProvider extends IIdentityProvider {\n\n static readonly CookieName = '.cratis-identity';\n static httpHeadersCallback: GetHttpHeaders | undefined;\n static apiBasePath: string = '';\n static origin: string = '';\n\n /**\n * Sets the HTTP headers callback.\n * @param callback Callback to set.\n */\n static setHttpHeadersCallback(callback: GetHttpHeaders): void {\n IdentityProvider.httpHeadersCallback = callback;\n }\n\n /**\n * Sets the API base path.\n * @param apiBasePath API base path to set.\n */\n static setApiBasePath(apiBasePath: string): void {\n IdentityProvider.apiBasePath = apiBasePath;\n }\n\n /**\n * Sets the origin.\n * @param origin Origin to set.\n */\n static setOrigin(origin: string): void {\n IdentityProvider.origin = origin;\n }\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @param type Optional constructor for the details type to enable type-safe deserialization.\n * @returns The current identity as {@link IIdentity}.\n * @remarks The `extends object` constraint is required for compatibility with JsonSerializer.deserializeFromInstance().\n */\n static async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n const cookie = this.getCookie();\n if (cookie.length == 2) {\n const json = atob(cookie[1]);\n const result = JSON.parse(json) as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n } as IIdentity<TDetails>;\n } else {\n const identity = await this.refresh<TDetails>(type);\n return identity;\n }\n }\n\n /** @inheritdoc */\n async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n return IdentityProvider.getCurrent<TDetails>(type);\n }\n\n static async refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n IdentityProvider.clearIdentityCookie();\n const origin = IdentityProvider.origin || Globals.origin || '';\n const apiBasePath = IdentityProvider.apiBasePath || Globals.apiBasePath || '';\n const route = joinPaths(apiBasePath, '/.cratis/me');\n const url = UrlHelpers.createUrlFrom(origin, apiBasePath, route);\n const response = await fetch(\n url, {\n method: 'GET',\n headers: IdentityProvider.httpHeadersCallback?.() ?? {}\n });\n\n if (!response.ok) {\n return IdentityProvider.notSet(type);\n }\n\n const result = await response.json() as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static notSet<TDetails extends object = object>(type?: Constructor<TDetails>): IIdentity<TDetails> {\n return {\n id: '',\n name: '',\n roles: [],\n details: {} as TDetails,\n isSet: false,\n isInRole: () => false,\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static getCookie() {\n if (typeof document === 'undefined') return [];\n const decoded = decodeURIComponent(document.cookie);\n const cookies = decoded.split(';').map(_ => _.trim());\n const cookie = cookies.find(_ => _.indexOf(`${IdentityProvider.CookieName}=`) == 0);\n if (cookie) {\n const keyValue = cookie.split('=');\n return [keyValue[0].trim(), keyValue[1].trim()];\n }\n return [];\n }\n\n /**\n * Clears the identity cookie used by Arc to cache the current identity.\n * Call this when the user logs out to ensure subsequent requests and WebSocket\n * connections do not carry stale credentials.\n */\n static clearIdentityCookie(): void {\n if (typeof document === 'undefined') return;\n document.cookie = `${IdentityProvider.CookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;\n }\n}\n"],"names":["IdentityProvider","IIdentityProvider","CookieName","httpHeadersCallback","apiBasePath","origin","setHttpHeadersCallback","callback","setApiBasePath","setOrigin","getCurrent","type","cookie","getCookie","length","json","atob","result","JSON","parse","details","JsonSerializer","deserializeFromInstance","id","name","roles","isSet","isInRole","role","includes","refresh","identity","clearIdentityCookie","Globals","route","joinPaths","url","UrlHelpers","createUrlFrom","response","fetch","method","headers","ok","notSet","document","decoded","decodeURIComponent","cookies","split","map","_","trim","find","indexOf","keyValue"],"mappings":";;;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,CAACF,CAAAA,CAAAA,GAAKA,CAAAA,CAAEG,OAAO,CAAC,GAAGtD,gBAAAA,CAAiBE,UAAU,CAAC,CAAC,CAAC,CAAA,IAAK,CAAA,CAAA;AACjF,QAAA,IAAIU,MAAAA,EAAQ;YACR,MAAM2C,QAAAA,GAAW3C,MAAAA,CAAOqC,KAAK,CAAC,GAAA,CAAA;YAC9B,OAAO;gBAACM,QAAQ,CAAC,CAAA,CAAE,CAACH,IAAI,EAAA;gBAAIG,QAAQ,CAAC,CAAA,CAAE,CAACH,IAAI;AAAG,aAAA;AACnD,QAAA;AACA,QAAA,OAAO,EAAE;AACb,IAAA;AAEA;;;;AAIC,QACD,OAAOpB,mBAAAA,GAA4B;QAC/B,IAAI,OAAOa,aAAa,WAAA,EAAa;AACrCA,QAAAA,QAAAA,CAASjC,MAAM,GAAG,CAAA,EAAGZ,iBAAiBE,UAAU,CAAC,uCAAuC,CAAC;AAC7F,IAAA;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor } from '@cratis/fundamentals';\nimport { IIdentityProvider } from './IIdentityProvider';\nimport { IIdentity } from './IIdentity';\nimport { IdentityProviderResult } from './IdentityProviderResult';\nimport { deserializeIdentityDetails } from './deserializeIdentityDetails';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { joinPaths } from '../joinPaths';\n\n/**\n * Represents an implementation of {@link IIdentityProvider}.\n*/\nexport class IdentityProvider extends IIdentityProvider {\n\n static readonly CookieName = '.cratis-identity';\n static httpHeadersCallback: GetHttpHeaders | undefined;\n static apiBasePath: string = '';\n static origin: string = '';\n\n /**\n * Sets the HTTP headers callback.\n * @param callback Callback to set.\n */\n static setHttpHeadersCallback(callback: GetHttpHeaders): void {\n IdentityProvider.httpHeadersCallback = callback;\n }\n\n /**\n * Sets the API base path.\n * @param apiBasePath API base path to set.\n */\n static setApiBasePath(apiBasePath: string): void {\n IdentityProvider.apiBasePath = apiBasePath;\n }\n\n /**\n * Sets the origin.\n * @param origin Origin to set.\n */\n static setOrigin(origin: string): void {\n IdentityProvider.origin = origin;\n }\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @param type Optional constructor for the details type to enable type-safe deserialization.\n * @returns The current identity as {@link IIdentity}.\n * @remarks The `extends object` constraint is required for compatibility with JsonSerializer.deserializeFromInstance().\n */\n static async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n const cookie = this.getCookie();\n if (cookie.length == 2) {\n const json = atob(cookie[1]);\n const result = JSON.parse(json) as IdentityProviderResult;\n const details = deserializeIdentityDetails(type, result.details);\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n } as IIdentity<TDetails>;\n } else {\n const identity = await this.refresh<TDetails>(type);\n return identity;\n }\n }\n\n /** @inheritdoc */\n async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n return IdentityProvider.getCurrent<TDetails>(type);\n }\n\n static async refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n IdentityProvider.clearIdentityCookie();\n const origin = IdentityProvider.origin || Globals.origin || '';\n const apiBasePath = IdentityProvider.apiBasePath || Globals.apiBasePath || '';\n const route = joinPaths(apiBasePath, '/.cratis/me');\n const url = UrlHelpers.createUrlFrom(origin, apiBasePath, route);\n const response = await fetch(\n url, {\n method: 'GET',\n headers: IdentityProvider.httpHeadersCallback?.() ?? {}\n });\n\n if (!response.ok) {\n return IdentityProvider.notSet(type);\n }\n\n const result = await response.json() as IdentityProviderResult;\n const details = deserializeIdentityDetails(type, result.details);\n\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static notSet<TDetails extends object = object>(type?: Constructor<TDetails>): IIdentity<TDetails> {\n return {\n id: '',\n name: '',\n roles: [],\n details: {} as TDetails,\n isSet: false,\n isInRole: () => false,\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static getCookie() {\n if (typeof document === 'undefined') return [];\n const decoded = decodeURIComponent(document.cookie);\n const cookies = decoded.split(';').map(_ => _.trim());\n const cookie = cookies.find(_ => _.indexOf(`${IdentityProvider.CookieName}=`) == 0);\n if (cookie) {\n const keyValue = cookie.split('=');\n return [keyValue[0].trim(), keyValue[1].trim()];\n }\n return [];\n }\n\n /**\n * Clears the identity cookie used by Arc to cache the current identity.\n * Call this when the user logs out to ensure subsequent requests and WebSocket\n * connections do not carry stale credentials.\n */\n static clearIdentityCookie(): void {\n if (typeof document === 'undefined') return;\n document.cookie = `${IdentityProvider.CookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;\n }\n}\n"],"names":["IdentityProvider","IIdentityProvider","CookieName","httpHeadersCallback","apiBasePath","origin","setHttpHeadersCallback","callback","setApiBasePath","setOrigin","getCurrent","type","cookie","getCookie","length","json","atob","result","JSON","parse","details","deserializeIdentityDetails","id","name","roles","isSet","isInRole","role","includes","refresh","identity","clearIdentityCookie","Globals","route","joinPaths","url","UrlHelpers","createUrlFrom","response","fetch","method","headers","ok","notSet","document","decoded","decodeURIComponent","cookies","split","map","_","trim","find","indexOf","keyValue"],"mappings":";;;;;;AAAA;AACA;AAYA;;AAEA,GACO,MAAMA,gBAAAA,SAAyBC,iBAAAA,CAAAA;AAElC,IAAA,OAAgBC,aAAa,kBAAA;AAC7B,IAAA,OAAOC,mBAAAA;AACP,IAAA,OAAOC,cAAsB,EAAA;AAC7B,IAAA,OAAOC,SAAiB,EAAA;AAExB;;;QAIA,OAA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QAAQ,CAAC,CAAA,CAAE,CAACH,IAAI;AAAG,aAAA;AACnD,QAAA;AACA,QAAA,OAAO,EAAE;AACb,IAAA;AAEA;;;;AAIC,QACD,OAAOpB,mBAAAA,GAA4B;QAC/B,IAAI,OAAOa,aAAa,WAAA,EAAa;AACrCA,QAAAA,QAAAA,CAAShC,MAAM,GAAG,CAAA,EAAGZ,iBAAiBE,UAAU,CAAC,uCAAuC,CAAC;AAC7F,IAAA;AACJ;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deserializeIdentityDetails.d.ts","sourceRoot":"","sources":["../../../identity/deserializeIdentityDetails.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAA0B,MAAM,sBAAsB,CAAC;AAmD3E,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,WAAW,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAwBnG"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Fields, JsonSerializer } from '@cratis/fundamentals';
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
4
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
|
+
/*
|
|
6
|
+
* ⚠️ deserializeIdentityDetails is exported deliberately, unlike deserializeQueryModel in
|
|
7
|
+
* ../queries/deserializeQueryModel.ts.
|
|
8
|
+
*
|
|
9
|
+
* JsonSerializer's converter registry is module state, and a consumer package can easily resolve a
|
|
10
|
+
* different physical copy of @cratis/fundamentals than this one - which is why deserializeQueryModel
|
|
11
|
+
* stays package-private. Identity details are different: @cratis/arc.react's useIdentity() needs to
|
|
12
|
+
* apply the exact same deserialization as this package's own IdentityProvider, for a payload that may
|
|
13
|
+
* already be flowing through this package's IdentityProvider/IIdentity. Exporting the function itself
|
|
14
|
+
* - rather than having @cratis/arc.react re-implement the same logic against its own copy of
|
|
15
|
+
* @cratis/fundamentals - guarantees every identity details value is deserialized through this one
|
|
16
|
+
* physical JsonSerializer/Fields, regardless of which package's copy of @cratis/fundamentals the
|
|
17
|
+
* caller resolved.
|
|
18
|
+
*/ /**
|
|
19
|
+
* Determines whether a details type is a JavaScript primitive wrapper rather than a real,
|
|
20
|
+
* `@field`-decorated model.
|
|
21
|
+
* @param {Constructor} type The details type to check.
|
|
22
|
+
* @returns {boolean} True when the type is a primitive wrapper.
|
|
23
|
+
*/ function isPrimitiveDetailsType(type) {
|
|
24
|
+
return type === String || type === Number || type === Boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Deserializes identity details into their strongly-typed shape, guarding every way that doing so
|
|
28
|
+
* would otherwise crash or silently destroy the payload.
|
|
29
|
+
* @param {Constructor | undefined} type The details type to deserialize into, or `undefined` to leave
|
|
30
|
+
* the payload untouched.
|
|
31
|
+
* @param {unknown} details The raw details payload - parsed JSON from the identity cookie or the
|
|
32
|
+
* `/.cratis/me` endpoint.
|
|
33
|
+
* @returns {unknown} The deserialized instance, or `details` unchanged when deserializing it would be
|
|
34
|
+
* unsafe, pointless, or has already been done.
|
|
35
|
+
* @remarks
|
|
36
|
+
* {@link JsonSerializer.deserializeFromInstance} assumes a well-formed object and a target type
|
|
37
|
+
* carrying `@field` metadata - neither is guaranteed here:
|
|
38
|
+
* - No type means there is nothing to deserialize into.
|
|
39
|
+
* - A `null`/`undefined`/non-object payload would make `deserializeFromInstance`'s internal
|
|
40
|
+
* `instance[field.name]` lookup throw.
|
|
41
|
+
* - A payload that is already an instance of the target type has already been deserialized -
|
|
42
|
+
* deserializing it again is destructive, not merely wasteful: it can throw on a nested temporal
|
|
43
|
+
* value and double-wraps a concept (`{ value: { value: '...' } }`).
|
|
44
|
+
* - `Object` and the primitive wrapper types (`String`, `Number`, `Boolean`) are not real,
|
|
45
|
+
* `@field`-decorated models; deserializing into them would discard the payload.
|
|
46
|
+
* - A type with no `@field`-decorated members deserializes to an empty instance, silently discarding
|
|
47
|
+
* the payload. That is worse than leaving the payload alone, so this warns and passes it through
|
|
48
|
+
* instead - preserving data beats a hard crash for anyone upgrading with an undecorated type.
|
|
49
|
+
*/ function deserializeIdentityDetails(type, details) {
|
|
50
|
+
if (!type || type === Object || isPrimitiveDetailsType(type)) {
|
|
51
|
+
return details;
|
|
52
|
+
}
|
|
53
|
+
if (details === null || details === undefined || typeof details !== 'object') {
|
|
54
|
+
return details;
|
|
55
|
+
}
|
|
56
|
+
if (details instanceof type) {
|
|
57
|
+
return details;
|
|
58
|
+
}
|
|
59
|
+
const fields = Fields.getFieldsForType(type);
|
|
60
|
+
if (fields.length === 0) {
|
|
61
|
+
console.warn(`Identity details type '${type.name}' has no @field-decorated members. Deserializing into ` + 'it would discard the payload and return an empty instance, so the raw payload is being ' + 'passed through instead. Add @field decorators for every property that should be ' + 'populated, or omit the details type to receive the raw payload as-is.');
|
|
62
|
+
return details;
|
|
63
|
+
}
|
|
64
|
+
return JsonSerializer.deserializeFromInstance(type, details);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { deserializeIdentityDetails };
|
|
68
|
+
//# sourceMappingURL=deserializeIdentityDetails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deserializeIdentityDetails.js","sources":["../../../identity/deserializeIdentityDetails.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor, Fields, JsonSerializer } from '@cratis/fundamentals';\n\n/*\n * ⚠️ deserializeIdentityDetails is exported deliberately, unlike deserializeQueryModel in\n * ../queries/deserializeQueryModel.ts.\n *\n * JsonSerializer's converter registry is module state, and a consumer package can easily resolve a\n * different physical copy of @cratis/fundamentals than this one - which is why deserializeQueryModel\n * stays package-private. Identity details are different: @cratis/arc.react's useIdentity() needs to\n * apply the exact same deserialization as this package's own IdentityProvider, for a payload that may\n * already be flowing through this package's IdentityProvider/IIdentity. Exporting the function itself\n * - rather than having @cratis/arc.react re-implement the same logic against its own copy of\n * @cratis/fundamentals - guarantees every identity details value is deserialized through this one\n * physical JsonSerializer/Fields, regardless of which package's copy of @cratis/fundamentals the\n * caller resolved.\n */\n\n/**\n * Determines whether a details type is a JavaScript primitive wrapper rather than a real,\n * `@field`-decorated model.\n * @param {Constructor} type The details type to check.\n * @returns {boolean} True when the type is a primitive wrapper.\n */\nfunction isPrimitiveDetailsType(type: Constructor): boolean {\n return type === String || type === Number || type === Boolean;\n}\n\n/**\n * Deserializes identity details into their strongly-typed shape, guarding every way that doing so\n * would otherwise crash or silently destroy the payload.\n * @param {Constructor | undefined} type The details type to deserialize into, or `undefined` to leave\n * the payload untouched.\n * @param {unknown} details The raw details payload - parsed JSON from the identity cookie or the\n * `/.cratis/me` endpoint.\n * @returns {unknown} The deserialized instance, or `details` unchanged when deserializing it would be\n * unsafe, pointless, or has already been done.\n * @remarks\n * {@link JsonSerializer.deserializeFromInstance} assumes a well-formed object and a target type\n * carrying `@field` metadata - neither is guaranteed here:\n * - No type means there is nothing to deserialize into.\n * - A `null`/`undefined`/non-object payload would make `deserializeFromInstance`'s internal\n * `instance[field.name]` lookup throw.\n * - A payload that is already an instance of the target type has already been deserialized -\n * deserializing it again is destructive, not merely wasteful: it can throw on a nested temporal\n * value and double-wraps a concept (`{ value: { value: '...' } }`).\n * - `Object` and the primitive wrapper types (`String`, `Number`, `Boolean`) are not real,\n * `@field`-decorated models; deserializing into them would discard the payload.\n * - A type with no `@field`-decorated members deserializes to an empty instance, silently discarding\n * the payload. That is worse than leaving the payload alone, so this warns and passes it through\n * instead - preserving data beats a hard crash for anyone upgrading with an undecorated type.\n */\nexport function deserializeIdentityDetails(type: Constructor | undefined, details: unknown): unknown {\n if (!type || type === Object || isPrimitiveDetailsType(type)) {\n return details;\n }\n\n if (details === null || details === undefined || typeof details !== 'object') {\n return details;\n }\n\n if (details instanceof type) {\n return details;\n }\n\n const fields = Fields.getFieldsForType(type);\n if (fields.length === 0) {\n console.warn(\n `Identity details type '${type.name}' has no @field-decorated members. Deserializing into ` +\n 'it would discard the payload and return an empty instance, so the raw payload is being ' +\n 'passed through instead. Add @field decorators for every property that should be ' +\n 'populated, or omit the details type to receive the raw payload as-is.');\n return details;\n }\n\n return JsonSerializer.deserializeFromInstance(type as Constructor<object>, details);\n}\n"],"names":["isPrimitiveDetailsType","type","String","Number","Boolean","deserializeIdentityDetails","details","Object","undefined","fields","Fields","getFieldsForType","length","console","warn","name","JsonSerializer","deserializeFromInstance"],"mappings":";;AAAA;AACA;AAIA;;;;;;;;;;;;;;;;;;IAqBA,SAASA,uBAAuBC,IAAiB,EAAA;AAC7C,IAAA,OAAOA,IAAAA,KAASC,MAAAA,IAAUD,IAAAA,KAASE,MAAAA,IAAUF,IAAAA,KAASG,OAAAA;AAC1D;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBC,IACM,SAASC,0BAAAA,CAA2BJ,IAA6B,EAAEK,OAAgB,EAAA;AACtF,IAAA,IAAI,CAACL,IAAAA,IAAQA,IAAAA,KAASM,MAAAA,IAAUP,uBAAuBC,IAAAA,CAAAA,EAAO;QAC1D,OAAOK,OAAAA;AACX,IAAA;AAEA,IAAA,IAAIA,YAAY,IAAA,IAAQA,OAAAA,KAAYE,SAAAA,IAAa,OAAOF,YAAY,QAAA,EAAU;QAC1E,OAAOA,OAAAA;AACX,IAAA;AAEA,IAAA,IAAIA,mBAAmBL,IAAAA,EAAM;QACzB,OAAOK,OAAAA;AACX,IAAA;IAEA,MAAMG,MAAAA,GAASC,MAAAA,CAAOC,gBAAgB,CAACV,IAAAA,CAAAA;IACvC,IAAIQ,MAAAA,CAAOG,MAAM,KAAK,CAAA,EAAG;AACrBC,QAAAA,OAAAA,CAAQC,IAAI,CACR,CAAC,uBAAuB,EAAEb,IAAAA,CAAKc,IAAI,CAAC,sDAAsD,CAAC,GAC3F,yFAAA,GACA,kFAAA,GACA,uEAAA,CAAA;QACJ,OAAOT,OAAAA;AACX,IAAA;IAEA,OAAOU,cAAAA,CAAeC,uBAAuB,CAAChB,IAAAA,EAA6BK,OAAAA,CAAAA;AAC/E;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_a_details_type_that_declares_no_fields.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_getting_current/with_a_details_type_that_declares_no_fields.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IdentityProvider } from '../../IdentityProvider';
|
|
2
|
+
import { an_identity_provider } from '../given/an_identity_provider';
|
|
3
|
+
import { given } from '../../../given';
|
|
4
|
+
class UndecoratedDetails {
|
|
5
|
+
userId;
|
|
6
|
+
role;
|
|
7
|
+
}
|
|
8
|
+
describe('when getting current with a details type that declares no fields', given(an_identity_provider, () => {
|
|
9
|
+
let originalConsoleWarn;
|
|
10
|
+
let result;
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
originalConsoleWarn = console.warn;
|
|
13
|
+
console.warn = () => { };
|
|
14
|
+
const identityData = {
|
|
15
|
+
id: 'test-user-id',
|
|
16
|
+
name: 'Test User',
|
|
17
|
+
details: {
|
|
18
|
+
userId: 'u-1',
|
|
19
|
+
role: 'admin'
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const encodedData = btoa(JSON.stringify(identityData));
|
|
23
|
+
global.document.cookie = `.cratis-identity=${encodedData}`;
|
|
24
|
+
const identity = await IdentityProvider.getCurrent(UndecoratedDetails);
|
|
25
|
+
result = { details: identity.details };
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => { console.warn = originalConsoleWarn; });
|
|
28
|
+
it('should hand back the payload untouched', () => {
|
|
29
|
+
result.details.userId.should.equal('u-1');
|
|
30
|
+
result.details.role.should.equal('admin');
|
|
31
|
+
});
|
|
32
|
+
it('should not blank the details', () => {
|
|
33
|
+
result.details.should.not.be.instanceOf(UndecoratedDetails);
|
|
34
|
+
});
|
|
35
|
+
}));
|
|
36
|
+
//# sourceMappingURL=with_a_details_type_that_declares_no_fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with_a_details_type_that_declares_no_fields.js","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_getting_current/with_a_details_type_that_declares_no_fields.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAIvC,MAAM,kBAAkB;IACpB,MAAM,CAAU;IAChB,IAAI,CAAU;CACjB;AAED,QAAQ,CAAC,kEAAkE,EAAE,KAAK,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAC1G,IAAI,mBAAwC,CAAC;IAC7C,IAAI,MAAuC,CAAC;IAE5C,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;QACnC,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,GAAgC,CAAC,CAAC;QAEtD,MAAM,YAAY,GAAG;YACjB,EAAE,EAAE,cAAc;YAClB,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE;gBACL,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,OAAO;aAChB;SACJ,CAAC;QACF,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;QACtD,MAA4C,CAAC,QAAS,CAAC,MAAM,GAAG,oBAAoB,WAAW,EAAE,CAAC;QAEnG,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;QACvE,MAAM,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;IAEzD,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAC7C,MAAM,CAAC,OAAyC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5E,MAAM,CAAC,OAAuC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACpC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_type_safe_details.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { field, Guid } from '@cratis/fundamentals';
|
|
2
3
|
import { IdentityProvider } from '../../IdentityProvider';
|
|
3
4
|
import { an_identity_provider } from '../given/an_identity_provider';
|
|
4
5
|
import { given } from '../../../given';
|
|
5
6
|
class TestDetails {
|
|
6
|
-
userId
|
|
7
|
-
role
|
|
7
|
+
userId;
|
|
8
|
+
role;
|
|
8
9
|
}
|
|
10
|
+
__decorate([
|
|
11
|
+
field(Guid),
|
|
12
|
+
__metadata("design:type", Guid)
|
|
13
|
+
], TestDetails.prototype, "userId", void 0);
|
|
14
|
+
__decorate([
|
|
15
|
+
field(String),
|
|
16
|
+
__metadata("design:type", String)
|
|
17
|
+
], TestDetails.prototype, "role", void 0);
|
|
9
18
|
describe('when getting current with type safe details', given(an_identity_provider, () => {
|
|
10
19
|
let result;
|
|
20
|
+
let testGuid;
|
|
11
21
|
beforeEach(async () => {
|
|
12
|
-
|
|
22
|
+
testGuid = Guid.create();
|
|
13
23
|
const identityData = {
|
|
14
24
|
id: 'test-user-id',
|
|
15
25
|
name: 'Test User',
|
|
@@ -30,5 +40,9 @@ describe('when getting current with type safe details', given(an_identity_provid
|
|
|
30
40
|
it('should deserialize details with proper types', () => {
|
|
31
41
|
result.details.userId.should.be.instanceOf(Guid);
|
|
32
42
|
});
|
|
43
|
+
it('should carry over the value the server sent', () => {
|
|
44
|
+
result.details.userId.toString().should.equal(testGuid.toString());
|
|
45
|
+
result.details.role.should.equal('admin');
|
|
46
|
+
});
|
|
33
47
|
}));
|
|
34
48
|
//# sourceMappingURL=with_type_safe_details.js.map
|
package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_type_safe_details.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with_type_safe_details.js","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_getting_current/with_type_safe_details.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"with_type_safe_details.js","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_getting_current/with_type_safe_details.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,MAAM,WAAW;IAEb,MAAM,CAAQ;IAGd,IAAI,CAAU;CACjB;AAJG;IADC,KAAK,CAAC,IAAI,CAAC;8BACH,IAAI;2CAAC;AAGd;IADC,KAAK,CAAC,MAAM,CAAC;;yCACA;AAGlB,QAAQ,CAAC,6CAA6C,EAAE,KAAK,CAAC,oBAAoB,EAAE,GAAG,EAAE;IACrF,IAAI,MAA0D,CAAC;IAC/D,IAAI,QAAc,CAAC;IAEnB,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAGzB,MAAM,YAAY,GAAG;YACjB,EAAE,EAAE,cAAc;YAClB,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE;gBACL,MAAM,EAAE,QAAQ,CAAC,QAAQ,EAAE;gBAC3B,IAAI,EAAE,OAAO;aAChB;SACJ,CAAC;QACF,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;QACtD,MAA4C,CAAC,QAAS,CAAC,MAAM,GAAG,oBAAoB,WAAW,EAAE,CAAC;QAEnG,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAChE,MAAM,GAAG;YACL,EAAE,EAAE,QAAQ,CAAC,EAAE;YACf,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,OAAO,EAAE,QAAQ,CAAC,OAAO;SAC5B,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACpD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACnD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { field, Guid } from '@cratis/fundamentals';
|
|
2
3
|
import { IdentityProvider } from '../../IdentityProvider';
|
|
3
4
|
import { an_identity_provider } from '../given/an_identity_provider';
|
|
4
5
|
import { given } from '../../../given';
|
|
5
6
|
class TestDetails {
|
|
6
|
-
userId
|
|
7
|
-
role
|
|
7
|
+
userId;
|
|
8
|
+
role;
|
|
8
9
|
}
|
|
10
|
+
__decorate([
|
|
11
|
+
field(Guid),
|
|
12
|
+
__metadata("design:type", Guid)
|
|
13
|
+
], TestDetails.prototype, "userId", void 0);
|
|
14
|
+
__decorate([
|
|
15
|
+
field(String),
|
|
16
|
+
__metadata("design:type", String)
|
|
17
|
+
], TestDetails.prototype, "role", void 0);
|
|
9
18
|
describe('when refreshing with type safe details', given(an_identity_provider, context => {
|
|
10
19
|
let result;
|
|
20
|
+
let testGuid;
|
|
11
21
|
beforeEach(async () => {
|
|
12
|
-
|
|
22
|
+
testGuid = Guid.create();
|
|
13
23
|
context.fetchStub.resolves({
|
|
14
24
|
ok: true,
|
|
15
25
|
json: async () => ({
|
|
@@ -31,5 +41,9 @@ describe('when refreshing with type safe details', given(an_identity_provider, c
|
|
|
31
41
|
it('should deserialize details with proper types', () => {
|
|
32
42
|
result.details.userId.should.be.instanceOf(Guid);
|
|
33
43
|
});
|
|
44
|
+
it('should carry over the value the server sent', () => {
|
|
45
|
+
result.details.userId.toString().should.equal(testGuid.toString());
|
|
46
|
+
result.details.role.should.equal('admin');
|
|
47
|
+
});
|
|
34
48
|
}));
|
|
35
49
|
//# sourceMappingURL=with_type_safe_details.js.map
|
package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_type_safe_details.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with_type_safe_details.js","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refreshing/with_type_safe_details.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"with_type_safe_details.js","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_refreshing/with_type_safe_details.ts"],"names":[],"mappings":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CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACnD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../identity/index.ts"],"names":[],"mappings":"AAGA,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../identity/index.ts"],"names":[],"mappings":"AAGA,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { IdentityProvider } from './IdentityProvider.js';
|
|
2
2
|
export { IIdentityProvider } from './IIdentityProvider.js';
|
|
3
|
+
export { deserializeIdentityDetails } from './deserializeIdentityDetails.js';
|
|
3
4
|
|
|
4
5
|
// Copyright (c) Cratis. All rights reserved.
|
|
5
6
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../identity/index.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nexport * from './IdentityProvider';\nexport * from './IdentityProviderResult';\nexport * from './IIdentityProvider';\nexport * from './IIdentity';\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../identity/index.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nexport * from './IdentityProvider';\nexport * from './IdentityProviderResult';\nexport * from './IIdentityProvider';\nexport * from './IIdentity';\nexport * from './deserializeIdentityDetails';\n"],"names":[],"mappings":";;;;AAAA;AACA"}
|