@ideem/zsm-client-sdk 2.8.1 → 2.9.1

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.
@@ -1,125 +1 @@
1
- import eventCoordinator from './EventCoordinator.js';
2
-
3
- class PasskeysPlusClient {
4
- constructor() {
5
- eventCoordinator.update('PasskeysPlus');
6
- this.passkeyAPI = (navigator?.credentials??null) || null;
7
- eventCoordinator.update('PasskeysPlus', 'READY');
8
- }
9
-
10
- /**
11
- * @name pkpSupported
12
- * @description Checks if the PasskeysPlus API is supported in the current browser.
13
- * @returns {boolean} True if supported, false otherwise.
14
- */
15
- pkpSupported = () => !!this.passkeyAPI && typeof this.passkeyAPI.create === 'function' && typeof this.passkeyAPI.get === 'function';
16
-
17
- /**
18
- * @name blockUnsupportedInvocation
19
- * @description Throws an error if the PasskeysPlus API is not supported in the current browser.
20
- * @returns {boolean} True if the invocation is supported, false otherwise.
21
- * @throws {Error} If the PasskeysPlus API is not supported.
22
- */
23
- blockUnsupportedInvocation = () => {
24
- if(!this.pkpSupported()) throw new Error(`[PK+ PasskeysPlus] :: blockUnsupportedInvocation :: This browser and/or device does not support the PasskeysPlus API!`);
25
- return true;
26
- }
27
-
28
- /**
29
- * @name b64ToArrayBuffer
30
- * @description Converts a base64url-encoded string to an ArrayBuffer.
31
- * @param {string} b64 The base64url-encoded string.
32
- * @returns {ArrayBuffer} The resulting ArrayBuffer.
33
- * @memberof PasskeysPlus
34
- */
35
- toArrayBuffer (b64) {
36
- if (typeof b64 !== 'string' || !/^[A-Za-z0-9\-_]+$/.test(b64)) throw new Error(`[PK+ PasskeysPlus] :: toArrayBuffer :: Invalid base64url string provided: ${b64}`);
37
- try {
38
- const str = atob(b64.replace(/-/g, '+').replace(/_/g, '/') + ('===='.slice(0, -b64.length % 4)))
39
- const bytes = new Uint8Array(str.length);
40
- for (let i = 0; i < str.length; i++) bytes[i] = str.charCodeAt(i);
41
- return bytes.buffer;
42
- } catch (e) {
43
- throw new Error(`[PK+ PasskeysPlus] :: toArrayBuffer :: Error converting base64url string to ArrayBuffer: ${e.message || e}`);
44
- }
45
- };
46
-
47
- /**
48
- * @name pkpCreatePasskeyCredential
49
- * @description Creates a passkey credential based on the provided public key.
50
- * @param {Object} publicKey The public key options for the passkey credential.
51
- * @param {string} userVerification Accepts "required", "preferred", "discouraged", to be passed into the Passkey ceremony.
52
- * @returns {Promise<Credential>} Resolves with the created passkey credential.
53
- * @throws {Error} The publicKey parameter was not provided or it was not an object.
54
- * @throws {Error} The structure of the publicKey parameter is invalid.
55
- * @throws {Error} The publicKey parameter's user ID was not an ArrayBuffer.
56
- * @throws {Error} The publicKey parameter's pubKeyCredParams was not an Array, was empty, or contained invalid entries.
57
- * @throws {Error} The publicKey parameter's authenticatorSelection was not an object (if provided).
58
- * @throws {Error} The publicKey parameter's authenticatorSelection.authenticatorAttachment was missing or not a valid value.
59
- * @throws {Error} The publicKey parameter's authenticatorSelection.requireResidentKey was missing or not a boolean.
60
- * @throws {Error} The publicKey parameter's authenticatorSelection.userVerification was missing or not a valid value.
61
- * @throws {Error} The publicKey parameter's timeout (if provided) was missing or not a positive number.
62
- * @throws {Error} The publicKey parameter's excludeCredentials must be an array and cannot be empty (if provided).
63
- * @throws {Error} The publicKey parameter's excludeCredentials (if provided) contained an entry that was not an ArrayBuffer.
64
- * @memberof PasskeysPlus
65
- */
66
- pkpCreatePasskeyCredential = async (publicKey, userVerification="preferred") => {
67
- if(!this.blockUnsupportedInvocation()) return false;
68
- if(publicKey?.authenticatorSelection) publicKey.authenticatorSelection.userVerification = userVerification;
69
- if(publicKey?.extensions?.credentialProtectionPolicy) delete publicKey.extensions.credentialProtectionPolicy;
70
- if(!publicKey || typeof publicKey !== 'object') throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid publicKey parameter provided: ${publicKey}! It must be an object. Received: ${publicKey}`);
71
- if(!publicKey?.challenge || !publicKey?.rp || !publicKey?.rp?.id || !publicKey?.rp?.name) throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid publicKey structure! It must contain challenge and rp properties with id and name. Received: ${publicKey}`);
72
- if(!publicKey?.user || !publicKey?.user?.id || !(publicKey?.user?.id instanceof ArrayBuffer)) throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid user ID in publicKey! It must be an ArrayBuffer. Received: ${publicKey?.user?.id}`);
73
- if(!publicKey?.pubKeyCredParams || !Array.isArray(publicKey?.pubKeyCredParams)
74
- || publicKey?.pubKeyCredParams?.length === 0) throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: pubKeyCredParams must be a non-empty array of public key credential parameters. Received: ${publicKey?.pubKeyCredParams}`);
75
- if(!publicKey?.authenticatorSelection || typeof publicKey?.authenticatorSelection !== 'object') throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid authenticatorSelection in publicKey! It must be an object. Received: ${publicKey?.authenticatorSelection} (${typeof publicKey?.authenticatorSelection})`);
76
- if(publicKey?.authenticatorSelection?.authenticatorAttachment
77
- && !['platform', 'cross-platform'].includes(publicKey?.authenticatorSelection?.authenticatorAttachment)) throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid authenticatorAttachment in authenticatorSelection! It must be either "platform" or "cross-platform". Received: ${publicKey?.authenticatorSelection?.authenticatorAttachment}`);
78
- if(publicKey?.authenticatorSelection?.requireResidentKey
79
- && typeof publicKey?.authenticatorSelection?.requireResidentKey !== 'boolean') throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid requireResidentKey in authenticatorSelection! It must be a boolean. Received: ${publicKey?.authenticatorSelection?.requireResidentKey} (${typeof publicKey?.authenticatorSelection?.requireResidentKey})`);
80
- if(publicKey?.authenticatorSelection?.userVerification
81
- && !['required', 'preferred', 'discouraged'].includes(publicKey?.authenticatorSelection?.userVerification)) throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid userVerification in authenticatorSelection! It must be one of "required", "preferred", or "discouraged". Received: ${publicKey?.authenticatorSelection?.userVerification}`);
82
- if(!publicKey?.timeout || typeof publicKey?.timeout !== 'number' || publicKey?.timeout <= 0) throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid timeout in publicKey! It must be a positive number. Received: ${publicKey?.timeout} (${typeof publicKey?.timeout})`);
83
- if(publicKey?.excludeCredentials && (!Array.isArray(publicKey?.excludeCredentials)
84
- || publicKey?.excludeCredentials?.length > 0 && !publicKey?.excludeCredentials[0].id)) throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid credential ID in excludeCredentials! It must be an ArrayBuffer. Received: ${publicKey?.excludeCredentials[0]?.id}`);
85
-
86
- publicKey.authenticatorSelection = {
87
- ...publicKey.authenticatorSelection,
88
- residentKey: "required", // was "discouraged"
89
- requireResidentKey: true, // was false
90
- }
91
- const pkpCredential = await this.passkeyAPI.create({ publicKey: {...publicKey, userVerification} });
92
-
93
- return pkpCredential;
94
- }
95
-
96
- /**
97
- * @name pkpGetPasskeyCredential
98
- * @description Retrieves a passkey credential based on the provided public key.
99
- * @param {Object} publicKey The public key options for the passkey credential.
100
- * @param {string} userVerification Accepts "required", "preferred", "discouraged", to be passed into the Passkey ceremony.
101
- * @returns {Promise<Credential>} Resolves with the passkey credential.
102
- * @throws {Error} The publicKey parameter was not provided or it was not an object.
103
- * @throws {Error} The structure of the publicKey parameter is invalid.
104
- * @throws {Error} The publicKey parameter's allowCredentials was not an array or was empty.
105
- * @throws {Error} The publicKey parameter's allowCredentials did not contain an ArrayBuffer.
106
- * @throws {Error} The publicKey parameter's user ID was missing or was not an ArrayBuffer.
107
- * @throws {Error} The publicKey parameter's rp was missing or was missing name and/or id.
108
- * @memberof PasskeysPlus
109
- */
110
- pkpGetPasskeyCredential = async (publicKey, userVerification="preferred") => {
111
- if(!this.blockUnsupportedInvocation()) return false;
112
- if(publicKey?.authenticatorSelection) publicKey.authenticatorSelection.userVerification = userVerification;
113
- if(!publicKey || typeof publicKey !== 'object') throw new Error(`[PK+ PasskeysPlus] :: pkpGetPasskeyCredential :: Invalid publicKey parameter provided!`);
114
- if(!publicKey?.challenge || !publicKey?.allowCredentials
115
- || !Array.isArray(publicKey?.allowCredentials)) throw new Error(`[PK+ PasskeysPlus] :: pkpGetPasskeyCredential :: Invalid publicKey structure provided! It must contain challenge and allowCredentials properties. Received: ${publicKey}`);
116
- if(publicKey?.allowCredentials?.length === 0) throw new Error(`[PK+ PasskeysPlus] :: pkpGetPasskeyCredential :: allowCredentials array must not be empty! It should contain at least one credential ID. Received: ${publicKey?.allowCredentials}`);
117
- const allIDsValid = publicKey?.allowCredentials.reduce((result, record)=>result && record?.id && (record.id instanceof ArrayBuffer || ArrayBuffer.isView(record.id)), true);
118
- if(!allIDsValid) throw new Error(`[PK+ PasskeysPlus] :: pkpGetPasskeyCredential :: Invalid credential ID in allowCredentials! It must be an ArrayBuffer. Received: ${publicKey?.allowCredentials[0]?.id}`);
119
- const pkpCredential = await this.passkeyAPI.get({ publicKey: {...publicKey, userVerification} });
120
-
121
- return pkpCredential;
122
- }
123
- }
124
-
125
- export default PasskeysPlusClient;
1
+ import e from"./EventCoordinator.js";export default class{constructor(){e.update("PasskeysPlus"),this.passkeyAPI=(navigator?.credentials??null)||null,e.update("PasskeysPlus","READY")}pkpSupported=()=>!!this.passkeyAPI&&"function"==typeof this.passkeyAPI.create&&"function"==typeof this.passkeyAPI.get;blockUnsupportedInvocation=()=>{if(!this.pkpSupported())throw new Error("[PK+ PasskeysPlus] :: blockUnsupportedInvocation :: This browser and/or device does not support the PasskeysPlus API!");return!0};toArrayBuffer(e){if("string"!=typeof e||!/^[A-Za-z0-9\-_]+$/.test(e))throw new Error(`[PK+ PasskeysPlus] :: toArrayBuffer :: Invalid base64url string provided: ${e}`);try{const t=atob(e.replace(/-/g,"+").replace(/_/g,"/")+"====".slice(0,-e.length%4)),r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=t.charCodeAt(e);return r.buffer}catch(e){throw new Error(`[PK+ PasskeysPlus] :: toArrayBuffer :: Error converting base64url string to ArrayBuffer: ${e.message||e}`)}}pkpCreatePasskeyCredential=async(e,t="preferred")=>{if(!this.blockUnsupportedInvocation())return!1;if(e?.authenticatorSelection&&(e.authenticatorSelection.userVerification=t),e?.extensions?.credentialProtectionPolicy&&delete e.extensions.credentialProtectionPolicy,!e||"object"!=typeof e)throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid publicKey parameter provided: ${e}! It must be an object. Received: ${e}`);if(!(e?.challenge&&e?.rp&&e?.rp?.id&&e?.rp?.name))throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid publicKey structure! It must contain challenge and rp properties with id and name. Received: ${e}`);if(!(e?.user&&e?.user?.id&&e?.user?.id instanceof ArrayBuffer))throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid user ID in publicKey! It must be an ArrayBuffer. Received: ${e?.user?.id}`);if(!e?.pubKeyCredParams||!Array.isArray(e?.pubKeyCredParams)||0===e?.pubKeyCredParams?.length)throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: pubKeyCredParams must be a non-empty array of public key credential parameters. Received: ${e?.pubKeyCredParams}`);if(!e?.authenticatorSelection||"object"!=typeof e?.authenticatorSelection)throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid authenticatorSelection in publicKey! It must be an object. Received: ${e?.authenticatorSelection} (${typeof e?.authenticatorSelection})`);if(e?.authenticatorSelection?.authenticatorAttachment&&!["platform","cross-platform"].includes(e?.authenticatorSelection?.authenticatorAttachment))throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid authenticatorAttachment in authenticatorSelection! It must be either "platform" or "cross-platform". Received: ${e?.authenticatorSelection?.authenticatorAttachment}`);if(e?.authenticatorSelection?.requireResidentKey&&"boolean"!=typeof e?.authenticatorSelection?.requireResidentKey)throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid requireResidentKey in authenticatorSelection! It must be a boolean. Received: ${e?.authenticatorSelection?.requireResidentKey} (${typeof e?.authenticatorSelection?.requireResidentKey})`);if(e?.authenticatorSelection?.userVerification&&!["required","preferred","discouraged"].includes(e?.authenticatorSelection?.userVerification))throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid userVerification in authenticatorSelection! It must be one of "required", "preferred", or "discouraged". Received: ${e?.authenticatorSelection?.userVerification}`);if(!e?.timeout||"number"!=typeof e?.timeout||e?.timeout<=0)throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid timeout in publicKey! It must be a positive number. Received: ${e?.timeout} (${typeof e?.timeout})`);if(e?.excludeCredentials&&(!Array.isArray(e?.excludeCredentials)||e?.excludeCredentials?.length>0&&!e?.excludeCredentials[0].id))throw new Error(`[PK+ PasskeysPlus] :: pkpCreatePasskeyCredential :: Invalid credential ID in excludeCredentials! It must be an ArrayBuffer. Received: ${e?.excludeCredentials[0]?.id}`);return await this.passkeyAPI.create({publicKey:{...e,userVerification:t}})};pkpGetPasskeyCredential=async(e,t="preferred")=>{if(!this.blockUnsupportedInvocation())return!1;if(e?.authenticatorSelection&&(e.authenticatorSelection.userVerification=t),!e||"object"!=typeof e)throw new Error("[PK+ PasskeysPlus] :: pkpGetPasskeyCredential :: Invalid publicKey parameter provided!");if(!e?.challenge||!e?.allowCredentials||!Array.isArray(e?.allowCredentials))throw new Error(`[PK+ PasskeysPlus] :: pkpGetPasskeyCredential :: Invalid publicKey structure provided! It must contain challenge and allowCredentials properties. Received: ${e}`);if(0===e?.allowCredentials?.length)throw new Error(`[PK+ PasskeysPlus] :: pkpGetPasskeyCredential :: allowCredentials array must not be empty! It should contain at least one credential ID. Received: ${e?.allowCredentials}`);const r=e?.allowCredentials.reduce((e,t)=>e&&t?.id&&(t.id instanceof ArrayBuffer||ArrayBuffer.isView(t.id)),!0);if(!r)throw new Error(`[PK+ PasskeysPlus] :: pkpGetPasskeyCredential :: Invalid credential ID in allowCredentials! It must be an ArrayBuffer. Received: ${e?.allowCredentials[0]?.id}`);return await this.passkeyAPI.get({publicKey:{...e,userVerification:t}})}}
package/PluginManager.js CHANGED
@@ -1,112 +1 @@
1
- class PluginManager {
2
- constructor() {
3
- this._sdkClassMap = new Map(); // Map of SDK class names to their implementations
4
- this._classCorpus = new Map(); // Map of plugin identities to their class maps
5
- this._status = 'INITIALIZED'; // Indicates the current status of the plugin manager (INITIALIZED, SEEDED, FROZEN)
6
- }
7
- /**
8
- * Returns whether the plugin manager is frozen.
9
- * @returns {boolean} True if the plugin manager is frozen, false otherwise.
10
- */
11
- get isFrozen() {
12
- return this._status === 'FROZEN';
13
- }
14
-
15
- /**
16
- * @name classes
17
- * @description Retrieves the SDK class associated with the given class description.
18
- * @param {string} classDesc The name of the class to retrieve.
19
- * @returns {Function} The SDK class associated with the given name.
20
- * @throws {Error} If the classDesc is not provided
21
- * @throws {Error} If no class is registered for the given name.
22
- */
23
- classes (classDesc) {
24
- if(this._status === 'INITIALIZED') throw new Error('[zsmPluginManager] :: classes :: collection accessor cannot be referenced before SOME classes are registered!');
25
- if(!classDesc || typeof classDesc !== 'string') throw new Error(`[zsmPluginManager] :: classes :: collection accessor requires a valid class description (received ${typeof classDesc}: ${classDesc})!`);
26
- classDesc = classDesc.toUpperCase();
27
- if(!this.isFrozen){
28
- console.warn('[zsmPluginManager] :: Freezing the plugin manager as the first class has been preemptively requested. No further plugins can be registered after this point.\nIf you feel you received this message unexpectedly, please ensure all plugins are imported before initializing (`new UMFAClient()` or `new FIDO2Client()`) a client.');
29
- this.freezePlugins();
30
- }
31
- if(!this._sdkClassMap.has(classDesc)) throw new Error(`[zsmPluginManager] :: classes :: No SDK class registered for: ${classDesc}`);
32
- return this._sdkClassMap.get(classDesc);
33
- }
34
-
35
- /**
36
- * @name seedClassMap
37
- * @description Seeds the class map with initial values.
38
- * @param {Object<string, Object>} registeredObj The key-value pairs to seed the class map with.
39
- * @returns {Map<string, Function>} A Map containing the seeded class definitions
40
- */
41
- seedClassMap(registeredObj) {
42
- const constructedMap = new Map();
43
- for (const [classDesc, ctor] of Object.entries(registeredObj.classDefs || {})) {
44
- if(ctor) constructedMap.set(classDesc.toUpperCase(), ctor);
45
- }
46
- return constructedMap;
47
- }
48
-
49
- /**
50
- * @name registerPlugin
51
- * @description Registers a plugin with the plugin manager.
52
- * @param {string} pluginIdentity The unique identity of the plugin.
53
- * @param {Object<string, Function>} classObj The class map for the plugin.
54
- * @throws {Error} Throws an error if the plugin manager is frozen.
55
- */
56
- registerPlugin(pluginIdentity, classObj){
57
- if (this.isFrozen) throw new Error('[zsmPluginManager] :: registerPlugin :: Cannot register plugin: PlugInManager is frozen!\nThis typically occurs when a plugin is imported after a client - UMFAClient or FIDO2Client - has already been initialized.\nMake sure to import all plugins before initializing (`new UMFAClient()` or `new FIDO2Client()`) a client.');
58
- if (!pluginIdentity || typeof classObj !== 'object' || classObj == null) throw new Error('[zsmPluginManager] :: registerPlugin :: pluginIdentity and class map object required');
59
-
60
- this._status = 'SEEDED';
61
-
62
- this._classCorpus.set(pluginIdentity.toUpperCase(), classObj);
63
- console.info(`[zsmPluginManager] :: PluginManager :: Registered plugin "${pluginIdentity}".`);
64
- return true;
65
- }
66
-
67
- /**
68
- * @name freezePlugins
69
- * @description Freezes the plugin manager, preventing further modifications.
70
- */
71
- freezePlugins(){
72
- if (this.isFrozen) return; // If the plugin manager is already frozen, bail.
73
-
74
- // Below is the plug-in precedence resolution logic. As new plugins are registered, they may override core classes.
75
- // As new plugins are DEVELOPED, they may introduce new classes or modify existing ones, and their extension/override logic must be declared below.
76
-
77
- // [CORE PACKAGE] Default all of the active classes to the "core" classes (set below this declaration)
78
- const core = this._classCorpus.get('CORE');
79
- if (!core) throw new Error('[zsmPluginManager] :: freezePlugins :: Core not registered before freeze');
80
-
81
- const constructedMap = this.seedClassMap(core); // returns Map
82
-
83
- // [PASSKEYS+ PLUGIN PACKAGE] If the "PASSKEYS+" plugin is registered, supersede the core classes with the passkeys classes
84
- if(this._classCorpus.has('PASSKEYS+')) {
85
- const passkeysMap = this._classCorpus.get('PASSKEYS+');
86
- if (passkeysMap?.classDefs) for (const [k,v] of Object.entries(passkeysMap.classDefs)) constructedMap.set(k.toUpperCase(), v);
87
- }
88
-
89
- // Apply class decorators (wrappers) AFTER overlays, if present in any of the registrations
90
- const postConstructDecorators = [...this._classCorpus.values()].filter(entry => entry.mode === 'DECORATOR');
91
- if (postConstructDecorators.length) {
92
- for (const modifier of postConstructDecorators) {
93
- let { classDesc, postModFn } = modifier;
94
- if (typeof postModFn !== 'function') throw new Error('[zsmPluginManager] :: freezePlugins :: Decorator must contain a valid function (received ' + typeof postModFn + ')');
95
-
96
- const baseCtor = constructedMap.get(classDesc.toUpperCase());
97
- if (typeof baseCtor !== 'function') throw new Error(`[zsmPluginManager] :: freezePlugins :: Decorator targets unknown class "${classDesc}"`);
98
-
99
- const decorated = postModFn(baseCtor);
100
- if (typeof decorated !== 'function') throw new Error('[zsmPluginManager] :: freezePlugins :: Decorator must return a constructor (received ' + typeof decorated + ')');
101
- constructedMap.set(classDesc.toUpperCase(), decorated);
102
- }
103
- }
104
-
105
- this._sdkClassMap = constructedMap;
106
- this._status = 'FROZEN';
107
- }
108
- }
109
-
110
- const pluginManager = new PluginManager()
111
-
112
- export { pluginManager as zsmPluginManager };
1
+ const e=new class{constructor(){this._sdkClassMap=new Map,this._classCorpus=new Map,this._status="INITIALIZED"}get isFrozen(){return"FROZEN"===this._status}classes(e){if("INITIALIZED"===this._status)throw new Error("[zsmPluginManager] :: classes :: collection accessor cannot be referenced before SOME classes are registered!");if(!e||"string"!=typeof e)throw new Error(`[zsmPluginManager] :: classes :: collection accessor requires a valid class description (received ${typeof e}: ${e})!`);if(e=e.toUpperCase(),this.isFrozen||(console.warn("[zsmPluginManager] :: Freezing the plugin manager as the first class has been preemptively requested. No further plugins can be registered after this point.\nIf you feel you received this message unexpectedly, please ensure all plugins are imported before initializing (`new UMFAClient()` or `new FIDO2Client()`) a client."),this.freezePlugins()),!this._sdkClassMap.has(e))throw new Error(`[zsmPluginManager] :: classes :: No SDK class registered for: ${e}`);return this._sdkClassMap.get(e)}seedClassMap(e){const s=new Map;for(const[r,t]of Object.entries(e.classDefs||{}))t&&s.set(r.toUpperCase(),t);return s}registerPlugin(e,s){if(this.isFrozen)throw new Error("[zsmPluginManager] :: registerPlugin :: Cannot register plugin: PlugInManager is frozen!\nThis typically occurs when a plugin is imported after a client - UMFAClient or FIDO2Client - has already been initialized.\nMake sure to import all plugins before initializing (`new UMFAClient()` or `new FIDO2Client()`) a client.");if(!e||"object"!=typeof s||null==s)throw new Error("[zsmPluginManager] :: registerPlugin :: pluginIdentity and class map object required");return this._status="SEEDED",this._classCorpus.set(e.toUpperCase(),s),console.info(`[zsmPluginManager] :: PluginManager :: Registered plugin "${e}".`),!0}freezePlugins(){if(this.isFrozen)return;const e=this._classCorpus.get("CORE");if(!e)throw new Error("[zsmPluginManager] :: freezePlugins :: Core not registered before freeze");const s=this.seedClassMap(e);if(this._classCorpus.has("PASSKEYS+")){const e=this._classCorpus.get("PASSKEYS+");if(e?.classDefs)for(const[r,t]of Object.entries(e.classDefs))s.set(r.toUpperCase(),t)}const r=[...this._classCorpus.values()].filter(e=>"DECORATOR"===e.mode);if(r.length)for(const e of r){let{classDesc:r,postModFn:t}=e;if("function"!=typeof t)throw new Error("[zsmPluginManager] :: freezePlugins :: Decorator must contain a valid function (received "+typeof t+")");const n=s.get(r.toUpperCase());if("function"!=typeof n)throw new Error(`[zsmPluginManager] :: freezePlugins :: Decorator targets unknown class "${r}"`);const i=t(n);if("function"!=typeof i)throw new Error("[zsmPluginManager] :: freezePlugins :: Decorator must return a constructor (received "+typeof i+")");s.set(r.toUpperCase(),i)}this._sdkClassMap=s,this._status="FROZEN"}};export{e as zsmPluginManager};
package/RelyingParty.js CHANGED
@@ -1,15 +1 @@
1
- import eventCoordinator from './EventCoordinator.js';
2
- import RelyingPartyBase from './RelyingPartyBase.js';
3
-
4
- eventCoordinator.update('RelyingParty');
5
-
6
- //## BEGIN RelyingParty ===================================================================================================================================
7
- class RelyingParty extends RelyingPartyBase {
8
- constructor(host, apiKey, applicationID, appEnvironment, usePasskeys) {
9
- super(host, apiKey, applicationID, appEnvironment, (usePasskeys != 'undefined' && usePasskeys != undefined && usePasskeys))
10
- eventCoordinator.update('RelyingParty', 'READY');
11
- }
12
- }
13
- //## END RelyingParty =====================================================================================================================================
14
-
15
- export default RelyingParty;
1
+ import e from"./EventCoordinator.js";import t from"./RelyingPartyBase.js";e.update("RelyingParty");export default class extends t{constructor(t,r,n,o,a){super(t,r,n,o,"undefined"!=a&&null!=a&&a),e.update("RelyingParty","READY")}}