@dynamic-labs/client 4.0.0-alpha.5 → 4.0.0-alpha.50

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +460 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +7 -14
  5. package/src/client/client.cjs +2 -0
  6. package/src/client/client.d.ts +1 -1
  7. package/src/client/client.js +2 -0
  8. package/src/client/core/core.cjs +42 -40
  9. package/src/client/core/core.d.ts +5 -4
  10. package/src/client/core/core.js +41 -39
  11. package/src/client/core/modules/initializationModule/initializationModule.cjs +19 -4
  12. package/src/client/core/modules/initializationModule/initializationModule.js +19 -4
  13. package/src/client/core/modules/manifestModule/manifestModule.cjs +4 -4
  14. package/src/client/core/modules/manifestModule/validateManifest/validateManifest.cjs +2 -2
  15. package/src/client/core/modules/manifestModule/validateManifest/validateManifest.js +2 -2
  16. package/src/index.cjs +3 -1
  17. package/src/index.d.ts +1 -1
  18. package/src/index.js +4 -0
  19. package/src/modules/authModule/authModule.cjs +8 -1
  20. package/src/modules/authModule/authModule.d.ts +8 -3
  21. package/src/modules/authModule/authModule.js +9 -2
  22. package/src/modules/authModule/emailAuthModule/emailAuthModule.cjs +7 -2
  23. package/src/modules/authModule/emailAuthModule/emailAuthModule.d.ts +3 -2
  24. package/src/modules/authModule/emailAuthModule/emailAuthModule.js +8 -3
  25. package/src/modules/authModule/smsAuthModule/smsAuthModule.cjs +7 -2
  26. package/src/modules/authModule/smsAuthModule/smsAuthModule.d.ts +3 -2
  27. package/src/modules/authModule/smsAuthModule/smsAuthModule.js +8 -3
  28. package/src/modules/networksModule/networksModule.d.ts +1 -1
  29. package/src/modules/sdkModule/sdkModule.cjs +6 -1
  30. package/src/modules/sdkModule/sdkModule.d.ts +6 -2
  31. package/src/modules/sdkModule/sdkModule.js +6 -1
  32. package/src/modules/userInterfaceModule/userInterfaceModule.cjs +7 -2
  33. package/src/modules/userInterfaceModule/userInterfaceModule.d.ts +5 -2
  34. package/src/modules/userInterfaceModule/userInterfaceModule.js +8 -3
  35. package/src/modules/walletsModule/accountAbstractionModule/accountAbstractionModule.cjs +17 -0
  36. package/src/modules/walletsModule/accountAbstractionModule/accountAbstractionModule.d.ts +14 -0
  37. package/src/modules/walletsModule/accountAbstractionModule/accountAbstractionModule.js +13 -0
  38. package/src/modules/walletsModule/accountAbstractionModule/index.d.ts +1 -0
  39. package/src/modules/walletsModule/createWalletListenerMethods/createWalletListenerMethods.cjs +31 -0
  40. package/src/modules/walletsModule/createWalletListenerMethods/createWalletListenerMethods.d.ts +8 -0
  41. package/src/modules/walletsModule/createWalletListenerMethods/createWalletListenerMethods.js +27 -0
  42. package/src/modules/walletsModule/createWalletListenerMethods/index.d.ts +1 -0
  43. package/src/modules/walletsModule/embeddedWalletsModule/embeddedWalletsModule.cjs +1 -1
  44. package/src/modules/walletsModule/embeddedWalletsModule/embeddedWalletsModule.d.ts +6 -3
  45. package/src/modules/walletsModule/embeddedWalletsModule/embeddedWalletsModule.js +2 -2
  46. package/src/modules/walletsModule/walletsModule.cjs +19 -1
  47. package/src/modules/walletsModule/walletsModule.d.ts +14 -3
  48. package/src/modules/walletsModule/walletsModule.js +20 -2
  49. package/src/types.d.ts +2 -0
  50. package/src/utils/pickListenerActions/pickListenerActions.cjs +9 -3
  51. package/src/utils/pickListenerActions/pickListenerActions.d.ts +2 -1
  52. package/src/utils/pickListenerActions/pickListenerActions.js +9 -3
  53. package/src/utils/setupFetchHandler/index.d.ts +1 -0
  54. package/src/utils/setupFetchHandler/setupFetchHandler.cjs +24 -0
  55. package/src/utils/setupFetchHandler/setupFetchHandler.d.ts +2 -0
  56. package/src/utils/setupFetchHandler/setupFetchHandler.js +20 -0
@@ -3,48 +3,50 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var messageTransport$1 = require('@dynamic-labs/message-transport');
6
+ var messageTransport = require('@dynamic-labs/message-transport');
7
7
  var initializationModule = require('./modules/initializationModule/initializationModule.cjs');
8
8
  var manifestModule = require('./modules/manifestModule/manifestModule.cjs');
9
9
 
10
- const messageTransport = messageTransport$1.applyDefaultMessageOrigin({
11
- defaultOrigin: 'host',
12
- messageTransport: messageTransport$1.makeWaitForInitEvent({
13
- bypassBlockIf: (message) => message.origin === 'webview',
14
- initializeMessageType: messageTransport$1.sdkHasLoadedEventName,
15
- messageTransport: messageTransport$1.createMessageTransport(),
16
- }),
17
- });
18
- // Uncomment this to easily debug incoming/outgoing messages to webview
19
- // messageTransport.on((message) =>
20
- // console.log('message', JSON.stringify(message, null, 2)),
21
- // );
22
- const initialization = initializationModule.createInitializationModule(messageTransport);
23
- const createCore = (props) => ({
24
- /**
25
- * Allows an extension to add its name to the list, such that
26
- * other extensions are able to detect if it is present.
27
- *
28
- * Ex: ViemExtension adds "viem" to the list, and WagmiExtension later
29
- * checks this list and throws an error if it doesn't find "viem" there.
30
- */
31
- declaredExtensionNames: [],
32
- /**
33
- * SDK initialization module handles the initialization error
34
- */
35
- initialization,
36
- /**
37
- * Manages the manifest of the host
38
- */
39
- manifest: manifestModule.createManifestModule(props, messageTransport, initialization),
40
- /**
41
- * Message transport that will be used to send and receive messages to the webview.
42
- * Should preferably be used with createRequestChannel, rather than used directly.
43
- *
44
- * Note: Doesn't implement forwarding messages to/from webview yet.
45
- * The user is expected to extend the client with an Extension that implements that.
46
- */
47
- messageTransport,
48
- });
10
+ const createCore = (props) => {
11
+ const messageTransport$1 = messageTransport.applyDefaultMessageOrigin({
12
+ defaultOrigin: 'host',
13
+ messageTransport: messageTransport.makeWaitForInitEvent({
14
+ bypassBlockIf: (message) => message.origin === 'webview',
15
+ initializeMessageType: messageTransport.sdkHasLoadedEventName,
16
+ messageTransport: messageTransport.createMessageTransport(),
17
+ }),
18
+ });
19
+ // Uncomment this to easily debug incoming/outgoing messages to webview
20
+ // messageTransport.on((message) =>
21
+ // console.log('message', JSON.stringify(message, null, 2)),
22
+ // );
23
+ const initialization = initializationModule.createInitializationModule(messageTransport$1);
24
+ return {
25
+ /**
26
+ * Allows an extension to add its name to the list, such that
27
+ * other extensions are able to detect if it is present.
28
+ *
29
+ * Ex: ViemExtension adds "viem" to the list, and WagmiExtension later
30
+ * checks this list and throws an error if it doesn't find "viem" there.
31
+ */
32
+ declaredExtensionNames: [],
33
+ /**
34
+ * SDK initialization module handles the initialization error
35
+ */
36
+ initialization,
37
+ /**
38
+ * Manages the manifest of the host
39
+ */
40
+ manifest: manifestModule.createManifestModule(props, messageTransport$1, initialization),
41
+ /**
42
+ * Message transport that will be used to send and receive messages to the webview.
43
+ * Should preferably be used with createRequestChannel, rather than used directly.
44
+ *
45
+ * Note: Doesn't implement forwarding messages to/from webview yet.
46
+ * The user is expected to extend the client with an Extension that implements that.
47
+ */
48
+ messageTransport: messageTransport$1,
49
+ };
50
+ };
49
51
 
50
52
  exports.createCore = createCore;
@@ -32,11 +32,12 @@ export declare const createCore: (props: ClientProps) => {
32
32
  * Note: Doesn't implement forwarding messages to/from webview yet.
33
33
  * The user is expected to extend the client with an Extension that implements that.
34
34
  */
35
- messageTransport: {
35
+ messageTransport: import("@dynamic-labs/message-transport").MessageTransport & {
36
+ emit: (message: import("@dynamic-labs/message-transport").MessageTransportData, options?: {
37
+ onEmit?: VoidFunction | undefined;
38
+ } | undefined) => void;
36
39
  unblock: () => void;
37
- emit: (message: import("@dynamic-labs/message-transport").MessageTransportData) => void;
38
- off: (callback: import("@dynamic-labs/message-transport").MessageTransportCallback) => void;
39
- on: (callback: import("@dynamic-labs/message-transport").MessageTransportCallback) => void;
40
+ isBlocked: () => boolean;
40
41
  } & {
41
42
  defaultOrigin: "webview" | "host";
42
43
  emit: (message: import("@dynamic-labs/message-transport").MessageTransportDataOptionalOrigin) => void;
@@ -3,44 +3,46 @@ import { applyDefaultMessageOrigin, makeWaitForInitEvent, sdkHasLoadedEventName,
3
3
  import { createInitializationModule } from './modules/initializationModule/initializationModule.js';
4
4
  import { createManifestModule } from './modules/manifestModule/manifestModule.js';
5
5
 
6
- const messageTransport = applyDefaultMessageOrigin({
7
- defaultOrigin: 'host',
8
- messageTransport: makeWaitForInitEvent({
9
- bypassBlockIf: (message) => message.origin === 'webview',
10
- initializeMessageType: sdkHasLoadedEventName,
11
- messageTransport: createMessageTransport(),
12
- }),
13
- });
14
- // Uncomment this to easily debug incoming/outgoing messages to webview
15
- // messageTransport.on((message) =>
16
- // console.log('message', JSON.stringify(message, null, 2)),
17
- // );
18
- const initialization = createInitializationModule(messageTransport);
19
- const createCore = (props) => ({
20
- /**
21
- * Allows an extension to add its name to the list, such that
22
- * other extensions are able to detect if it is present.
23
- *
24
- * Ex: ViemExtension adds "viem" to the list, and WagmiExtension later
25
- * checks this list and throws an error if it doesn't find "viem" there.
26
- */
27
- declaredExtensionNames: [],
28
- /**
29
- * SDK initialization module handles the initialization error
30
- */
31
- initialization,
32
- /**
33
- * Manages the manifest of the host
34
- */
35
- manifest: createManifestModule(props, messageTransport, initialization),
36
- /**
37
- * Message transport that will be used to send and receive messages to the webview.
38
- * Should preferably be used with createRequestChannel, rather than used directly.
39
- *
40
- * Note: Doesn't implement forwarding messages to/from webview yet.
41
- * The user is expected to extend the client with an Extension that implements that.
42
- */
43
- messageTransport,
44
- });
6
+ const createCore = (props) => {
7
+ const messageTransport = applyDefaultMessageOrigin({
8
+ defaultOrigin: 'host',
9
+ messageTransport: makeWaitForInitEvent({
10
+ bypassBlockIf: (message) => message.origin === 'webview',
11
+ initializeMessageType: sdkHasLoadedEventName,
12
+ messageTransport: createMessageTransport(),
13
+ }),
14
+ });
15
+ // Uncomment this to easily debug incoming/outgoing messages to webview
16
+ // messageTransport.on((message) =>
17
+ // console.log('message', JSON.stringify(message, null, 2)),
18
+ // );
19
+ const initialization = createInitializationModule(messageTransport);
20
+ return {
21
+ /**
22
+ * Allows an extension to add its name to the list, such that
23
+ * other extensions are able to detect if it is present.
24
+ *
25
+ * Ex: ViemExtension adds "viem" to the list, and WagmiExtension later
26
+ * checks this list and throws an error if it doesn't find "viem" there.
27
+ */
28
+ declaredExtensionNames: [],
29
+ /**
30
+ * SDK initialization module handles the initialization error
31
+ */
32
+ initialization,
33
+ /**
34
+ * Manages the manifest of the host
35
+ */
36
+ manifest: createManifestModule(props, messageTransport, initialization),
37
+ /**
38
+ * Message transport that will be used to send and receive messages to the webview.
39
+ * Should preferably be used with createRequestChannel, rather than used directly.
40
+ *
41
+ * Note: Doesn't implement forwarding messages to/from webview yet.
42
+ * The user is expected to extend the client with an Extension that implements that.
43
+ */
44
+ messageTransport,
45
+ };
46
+ };
45
47
 
46
48
  export { createCore };
@@ -12,15 +12,30 @@ const createInitializationModule = (messageTransport$1) => {
12
12
  const state = reactivity.reactive({
13
13
  error: null,
14
14
  });
15
+ /**
16
+ * Uses regular console.error to log the errors
17
+ * so we dont send the error to the backend twice
18
+ */
15
19
  consoleRequestChannel.handle('error', (serializedError, { severity }) => {
16
20
  const error = messageTransport.parseErrorFromTransport(serializedError);
21
+ if (Array.isArray(error)) {
22
+ // Log each item individually because the expo console fails to log complex objects
23
+ // So this way if one item is complex, it doesn't hide the others
24
+ // eslint-disable-next-line no-console
25
+ for (const item of error)
26
+ console.error(item);
27
+ if (severity === 'fatal') {
28
+ state.error = new Error('Unknown error occurred, check your console for more details');
29
+ }
30
+ return;
31
+ }
17
32
  if (severity === 'fatal') {
18
33
  state.error = error;
19
34
  }
20
- /**
21
- * Uses regular console.error to log the error
22
- * so we dont send the error to the backend twice
23
- */
35
+ // We also log the message individually in case the error object fails to be logged by the expo console
36
+ // eslint-disable-next-line no-console
37
+ if (error.message)
38
+ console.error(error.message);
24
39
  // eslint-disable-next-line no-console
25
40
  console.error(error);
26
41
  });
@@ -8,15 +8,30 @@ const createInitializationModule = (messageTransport) => {
8
8
  const state = reactive({
9
9
  error: null,
10
10
  });
11
+ /**
12
+ * Uses regular console.error to log the errors
13
+ * so we dont send the error to the backend twice
14
+ */
11
15
  consoleRequestChannel.handle('error', (serializedError, { severity }) => {
12
16
  const error = parseErrorFromTransport(serializedError);
17
+ if (Array.isArray(error)) {
18
+ // Log each item individually because the expo console fails to log complex objects
19
+ // So this way if one item is complex, it doesn't hide the others
20
+ // eslint-disable-next-line no-console
21
+ for (const item of error)
22
+ console.error(item);
23
+ if (severity === 'fatal') {
24
+ state.error = new Error('Unknown error occurred, check your console for more details');
25
+ }
26
+ return;
27
+ }
13
28
  if (severity === 'fatal') {
14
29
  state.error = error;
15
30
  }
16
- /**
17
- * Uses regular console.error to log the error
18
- * so we dont send the error to the backend twice
19
- */
31
+ // We also log the message individually in case the error object fails to be logged by the expo console
32
+ // eslint-disable-next-line no-console
33
+ if (error.message)
34
+ console.error(error.message);
20
35
  // eslint-disable-next-line no-console
21
36
  console.error(error);
22
37
  });
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
7
  var messageTransport = require('@dynamic-labs/message-transport');
8
- var logger = require('@dynamic-labs/logger');
9
- var logger$1 = require('../../../../utils/logger/logger.cjs');
8
+ var logger$1 = require('@dynamic-labs/logger');
9
+ var logger = require('../../../../utils/logger/logger.cjs');
10
10
  var createPartialManifest = require('./createPartialManifest/createPartialManifest.cjs');
11
11
  var validateManifest = require('./validateManifest/validateManifest.cjs');
12
12
 
@@ -21,7 +21,7 @@ const createManifestModule = (props, messageTransport$1, initializationModule) =
21
21
  return validateManifest.validateManifest(manifest);
22
22
  }
23
23
  catch (error) {
24
- logger$1.logger.error(error);
24
+ logger.logger.error(error);
25
25
  if (error instanceof Error)
26
26
  initializationModule.error = error;
27
27
  throw error;
@@ -30,7 +30,7 @@ const createManifestModule = (props, messageTransport$1, initializationModule) =
30
30
  return {
31
31
  setAppOrigin: (appOrigin) => (manifest.appOrigin = appOrigin),
32
32
  setPlatform: (platform) => {
33
- logger.Logger.globalMetaData.set('platform', platform);
33
+ logger$1.Logger.globalMetaData.set('platform', platform);
34
34
  manifest.platform = platform;
35
35
  },
36
36
  setRedirectUrl: (redirectUrl) => (manifest.redirectUrl = redirectUrl),
@@ -10,8 +10,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
10
10
  const mandatoryFields = {
11
11
  clientVersion: "We were unable to retrieve the Dynamic Client's version from your app. Please contact us about this.",
12
12
  environmentId: 'You must provide an environment id to the Dynamic Client.',
13
- platform: 'Missing platform specific extension, like BrowserExtension or ReactNativeExtension. See how to setup Dynamic Client in our docs for help.',
14
- redirectUrl: 'Missing platform specific extension, like BrowserExtension or ReactNativeExtension. See how to setup Dynamic Client in our docs for help.',
13
+ platform: 'Missing platform specific extension, like WebExtension or ReactNativeExtension. See how to setup Dynamic Client in our docs for help.',
14
+ redirectUrl: 'Missing platform specific extension, like WebExtension or ReactNativeExtension. See how to setup Dynamic Client in our docs for help.',
15
15
  };
16
16
  const validateManifest = (partialManifest) => {
17
17
  /**
@@ -6,8 +6,8 @@
6
6
  const mandatoryFields = {
7
7
  clientVersion: "We were unable to retrieve the Dynamic Client's version from your app. Please contact us about this.",
8
8
  environmentId: 'You must provide an environment id to the Dynamic Client.',
9
- platform: 'Missing platform specific extension, like BrowserExtension or ReactNativeExtension. See how to setup Dynamic Client in our docs for help.',
10
- redirectUrl: 'Missing platform specific extension, like BrowserExtension or ReactNativeExtension. See how to setup Dynamic Client in our docs for help.',
9
+ platform: 'Missing platform specific extension, like WebExtension or ReactNativeExtension. See how to setup Dynamic Client in our docs for help.',
10
+ redirectUrl: 'Missing platform specific extension, like WebExtension or ReactNativeExtension. See how to setup Dynamic Client in our docs for help.',
11
11
  };
12
12
  const validateManifest = (partialManifest) => {
13
13
  /**
package/src/index.cjs CHANGED
@@ -3,11 +3,13 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
+ var assertPackageVersion = require('@dynamic-labs/assert-package-version');
7
+ var _package = require('../package.cjs');
6
8
  var Extendable = require('./utils/Extendable/Extendable.cjs');
7
9
  var hasExtension = require('./utils/Extendable/hasExtension/hasExtension.cjs');
8
10
  var client = require('./client/client.cjs');
9
11
 
10
-
12
+ assertPackageVersion.assertPackageVersion('@dynamic-labs/client', _package.version);
11
13
 
12
14
  exports.Extendable = Extendable.Extendable;
13
15
  exports.hasExtension = hasExtension.hasExtension;
package/src/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type { SocialProvider } from '@dynamic-labs/message-transport';
2
- export type { BaseWallet as Wallet } from '@dynamic-labs/types';
3
2
  export { type Core } from './client/core';
3
+ export type { Wallet } from './types';
4
4
  export { Extendable, type Extension } from './utils/Extendable';
5
5
  export { hasExtension } from './utils/Extendable/hasExtension';
6
6
  export { createClient, type BaseClient, type ClientProps, baseClientExtensionName, } from './client';
package/src/index.js CHANGED
@@ -1,4 +1,8 @@
1
1
  'use client'
2
+ import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
3
+ import { version } from '../package.js';
2
4
  export { Extendable } from './utils/Extendable/Extendable.js';
3
5
  export { hasExtension } from './utils/Extendable/hasExtension/hasExtension.js';
4
6
  export { baseClientExtensionName, createClient } from './client/client.js';
7
+
8
+ assertPackageVersion('@dynamic-labs/client', version);
@@ -10,6 +10,7 @@ var externalAuthModule = require('./externalAuthModule/externalAuthModule.cjs');
10
10
  var smsAuthModule = require('./smsAuthModule/smsAuthModule.cjs');
11
11
  var socialAuthModule = require('./socialAuthModule/socialAuthModule.cjs');
12
12
 
13
+ const defaultAuthenticatedUserHandler = () => Promise.resolve();
13
14
  const createAuthModule = (core) => {
14
15
  const store = messageTransport.createStore({
15
16
  initialState: {
@@ -20,15 +21,21 @@ const createAuthModule = (core) => {
20
21
  messageTransport: core.messageTransport,
21
22
  });
22
23
  const messageEvents = messageTransport.createEventEmitterForMessages({
24
+ eventNames: messageTransport.authEventNames,
23
25
  initialEventEmitter: store.eventEmitter,
24
- key: 'auth',
25
26
  messageTransport: core.messageTransport,
26
27
  });
27
28
  const requestChannel = messageTransport.createRequestChannel(core.messageTransport);
29
+ const handlers = {
30
+ userAuthenticated: defaultAuthenticatedUserHandler,
31
+ };
32
+ requestChannel.handle('handleAuthenticatedUser', ({ user }) => handlers.userAuthenticated(user));
28
33
  return Object.assign(store.getters, pickListenerActions.pickListenerActions(messageEvents), {
34
+ clearHandler: () => (handlers.userAuthenticated = defaultAuthenticatedUserHandler),
29
35
  email: emailAuthModule.createEmailAuthModule(core),
30
36
  external: externalAuthModule.createExternalAuthModule(core),
31
37
  logout: () => requestChannel.request('logout'),
38
+ setHandler: (_, handler) => (handlers.userAuthenticated = handler),
32
39
  sms: smsAuthModule.createSmsAuthModule(core),
33
40
  social: socialAuthModule.createSocialAuthModule(core),
34
41
  });
@@ -1,15 +1,20 @@
1
- import { AuthModuleMessages, AuthModuleState, StoreEventListeners } from '@dynamic-labs/message-transport';
1
+ import { AuthModuleMessages, AuthModuleState, StoreEventListeners, PickedEventListeners, authEventNames } from '@dynamic-labs/message-transport';
2
+ import { UserProfile } from '@dynamic-labs/types';
2
3
  import { Core } from '../../client/core';
3
4
  import { EmailAuthModule } from './emailAuthModule';
4
5
  import { ExternalAuthModule } from './externalAuthModule';
5
6
  import { SmsAuthModule } from './smsAuthModule';
6
7
  import { SocialAuthModule } from './socialAuthModule';
7
- type PublicAuthModuleMessages = Pick<AuthModuleMessages, 'logout'>;
8
- export type AuthModule = AuthModuleState & StoreEventListeners<AuthModuleState> & PublicAuthModuleMessages & {
8
+ type PublicAuthModuleMessages = Pick<AuthModuleMessages, typeof authEventNames[number]>;
9
+ export type AuthModule = AuthModuleState & StoreEventListeners<AuthModuleState> & PickedEventListeners<PublicAuthModuleMessages> & {
9
10
  sms: SmsAuthModule;
10
11
  email: EmailAuthModule;
11
12
  social: SocialAuthModule;
12
13
  external: ExternalAuthModule;
14
+ logout: AuthModuleMessages['logout'];
15
+ setHandler: (name: 'userAuthenticated', handler: AuthenticatedUserHandler) => void;
16
+ clearHandler: (name: 'userAuthenticated') => void;
13
17
  };
18
+ type AuthenticatedUserHandler = (user: UserProfile) => Promise<void>;
14
19
  export declare const createAuthModule: (core: Core) => AuthModule;
15
20
  export {};
@@ -1,11 +1,12 @@
1
1
  'use client'
2
- import { createStore, createEventEmitterForMessages, createRequestChannel } from '@dynamic-labs/message-transport';
2
+ import { createStore, createEventEmitterForMessages, authEventNames, createRequestChannel } from '@dynamic-labs/message-transport';
3
3
  import { pickListenerActions } from '../../utils/pickListenerActions/pickListenerActions.js';
4
4
  import { createEmailAuthModule } from './emailAuthModule/emailAuthModule.js';
5
5
  import { createExternalAuthModule } from './externalAuthModule/externalAuthModule.js';
6
6
  import { createSmsAuthModule } from './smsAuthModule/smsAuthModule.js';
7
7
  import { createSocialAuthModule } from './socialAuthModule/socialAuthModule.js';
8
8
 
9
+ const defaultAuthenticatedUserHandler = () => Promise.resolve();
9
10
  const createAuthModule = (core) => {
10
11
  const store = createStore({
11
12
  initialState: {
@@ -16,15 +17,21 @@ const createAuthModule = (core) => {
16
17
  messageTransport: core.messageTransport,
17
18
  });
18
19
  const messageEvents = createEventEmitterForMessages({
20
+ eventNames: authEventNames,
19
21
  initialEventEmitter: store.eventEmitter,
20
- key: 'auth',
21
22
  messageTransport: core.messageTransport,
22
23
  });
23
24
  const requestChannel = createRequestChannel(core.messageTransport);
25
+ const handlers = {
26
+ userAuthenticated: defaultAuthenticatedUserHandler,
27
+ };
28
+ requestChannel.handle('handleAuthenticatedUser', ({ user }) => handlers.userAuthenticated(user));
24
29
  return Object.assign(store.getters, pickListenerActions(messageEvents), {
30
+ clearHandler: () => (handlers.userAuthenticated = defaultAuthenticatedUserHandler),
25
31
  email: createEmailAuthModule(core),
26
32
  external: createExternalAuthModule(core),
27
33
  logout: () => requestChannel.request('logout'),
34
+ setHandler: (_, handler) => (handlers.userAuthenticated = handler),
28
35
  sms: createSmsAuthModule(core),
29
36
  social: createSocialAuthModule(core),
30
37
  });
@@ -4,17 +4,22 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var messageTransport = require('@dynamic-labs/message-transport');
7
+ var pickListenerActions = require('../../../utils/pickListenerActions/pickListenerActions.cjs');
7
8
 
8
9
  const createEmailAuthModule = (core) => {
9
10
  const requestChannel = messageTransport.createRequestChannel(core.messageTransport);
10
- return {
11
+ const messageEvents = messageTransport.createEventEmitterForMessages({
12
+ eventNames: messageTransport.emailEventNames,
13
+ messageTransport: core.messageTransport,
14
+ });
15
+ return Object.assign(pickListenerActions.pickListenerActions(messageEvents), {
11
16
  resendOTP: () => requestChannel.request('resendOTP'),
12
17
  sendOTP: (email) => requestChannel.request('sendOTP', {
13
18
  destination: 'email',
14
19
  target: email,
15
20
  }),
16
21
  verifyOTP: (token) => requestChannel.request('verifyOTP', token),
17
- };
22
+ });
18
23
  };
19
24
 
20
25
  exports.createEmailAuthModule = createEmailAuthModule;
@@ -1,8 +1,9 @@
1
- import { OtpMessages } from '@dynamic-labs/message-transport';
1
+ import { OtpMessages, PickedEventListeners, emailEventNames } from '@dynamic-labs/message-transport';
2
2
  import { Core } from '../../../client/core';
3
- export type EmailAuthModule = {
3
+ export type EmailAuthModule = PickedEventListeners<PublicEmailAuthMessages> & {
4
4
  resendOTP: OtpMessages['resendOTP'];
5
5
  sendOTP: (email: string) => Promise<void>;
6
6
  verifyOTP: OtpMessages['verifyOTP'];
7
7
  };
8
+ export type PublicEmailAuthMessages = Pick<OtpMessages, typeof emailEventNames[number]>;
8
9
  export declare const createEmailAuthModule: (core: Core) => EmailAuthModule;
@@ -1,16 +1,21 @@
1
1
  'use client'
2
- import { createRequestChannel } from '@dynamic-labs/message-transport';
2
+ import { createRequestChannel, createEventEmitterForMessages, emailEventNames } from '@dynamic-labs/message-transport';
3
+ import { pickListenerActions } from '../../../utils/pickListenerActions/pickListenerActions.js';
3
4
 
4
5
  const createEmailAuthModule = (core) => {
5
6
  const requestChannel = createRequestChannel(core.messageTransport);
6
- return {
7
+ const messageEvents = createEventEmitterForMessages({
8
+ eventNames: emailEventNames,
9
+ messageTransport: core.messageTransport,
10
+ });
11
+ return Object.assign(pickListenerActions(messageEvents), {
7
12
  resendOTP: () => requestChannel.request('resendOTP'),
8
13
  sendOTP: (email) => requestChannel.request('sendOTP', {
9
14
  destination: 'email',
10
15
  target: email,
11
16
  }),
12
17
  verifyOTP: (token) => requestChannel.request('verifyOTP', token),
13
- };
18
+ });
14
19
  };
15
20
 
16
21
  export { createEmailAuthModule };
@@ -4,14 +4,19 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var messageTransport = require('@dynamic-labs/message-transport');
7
+ var pickListenerActions = require('../../../utils/pickListenerActions/pickListenerActions.cjs');
7
8
 
8
9
  const createSmsAuthModule = (core) => {
9
10
  const requestChannel = messageTransport.createRequestChannel(core.messageTransport);
10
- return {
11
+ const messageEvents = messageTransport.createEventEmitterForMessages({
12
+ eventNames: messageTransport.smsEventNames,
13
+ messageTransport: core.messageTransport,
14
+ });
15
+ return Object.assign(pickListenerActions.pickListenerActions(messageEvents), {
11
16
  resendOTP: () => requestChannel.request('resendOTP'),
12
17
  sendOTP: (phone) => requestChannel.request('sendOTP', { destination: 'sms', target: phone }),
13
18
  verifyOTP: (token) => requestChannel.request('verifyOTP', token),
14
- };
19
+ });
15
20
  };
16
21
 
17
22
  exports.createSmsAuthModule = createSmsAuthModule;
@@ -1,9 +1,10 @@
1
1
  import { PhoneData } from '@dynamic-labs/types';
2
- import { OtpMessages } from '@dynamic-labs/message-transport';
2
+ import { OtpMessages, PickedEventListeners, smsEventNames } from '@dynamic-labs/message-transport';
3
3
  import { Core } from '../../../client/core';
4
- export type SmsAuthModule = {
4
+ export type SmsAuthModule = PickedEventListeners<PublicSmsAuthMessages> & {
5
5
  resendOTP: OtpMessages['resendOTP'];
6
6
  sendOTP: (phone: PhoneData) => Promise<void>;
7
7
  verifyOTP: OtpMessages['verifyOTP'];
8
8
  };
9
+ export type PublicSmsAuthMessages = Pick<OtpMessages, typeof smsEventNames[number]>;
9
10
  export declare const createSmsAuthModule: (core: Core) => SmsAuthModule;
@@ -1,13 +1,18 @@
1
1
  'use client'
2
- import { createRequestChannel } from '@dynamic-labs/message-transport';
2
+ import { createRequestChannel, createEventEmitterForMessages, smsEventNames } from '@dynamic-labs/message-transport';
3
+ import { pickListenerActions } from '../../../utils/pickListenerActions/pickListenerActions.js';
3
4
 
4
5
  const createSmsAuthModule = (core) => {
5
6
  const requestChannel = createRequestChannel(core.messageTransport);
6
- return {
7
+ const messageEvents = createEventEmitterForMessages({
8
+ eventNames: smsEventNames,
9
+ messageTransport: core.messageTransport,
10
+ });
11
+ return Object.assign(pickListenerActions(messageEvents), {
7
12
  resendOTP: () => requestChannel.request('resendOTP'),
8
13
  sendOTP: (phone) => requestChannel.request('sendOTP', { destination: 'sms', target: phone }),
9
14
  verifyOTP: (token) => requestChannel.request('verifyOTP', token),
10
- };
15
+ });
11
16
  };
12
17
 
13
18
  export { createSmsAuthModule };
@@ -1,3 +1,3 @@
1
1
  import { NetworksModuleState } from '@dynamic-labs/message-transport';
2
2
  import { Core } from '../../client/core';
3
- export declare const createNetworksModule: (core: Core) => import("@dynamic-labs/message-transport").StoreStateGetters<NetworksModuleState> & Pick<import("eventemitter3").EventEmitter<import("@dynamic-labs/message-transport").StoreStateEvents<NetworksModuleState>, any>, "on" | "off" | "once">;
3
+ export declare const createNetworksModule: (core: Core) => import("@dynamic-labs/message-transport").StoreStateGetters<NetworksModuleState> & import("@dynamic-labs/message-transport").PickedEventListeners<import("@dynamic-labs/message-transport").StoreStateEvents<NetworksModuleState>>;
@@ -3,6 +3,7 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
+ var reactivity = require('@vue/reactivity');
6
7
  var messageTransport = require('@dynamic-labs/message-transport');
7
8
  var pickListenerActions = require('../../utils/pickListenerActions/pickListenerActions.cjs');
8
9
  var addProperty = require('../../utils/addProperty/addProperty.cjs');
@@ -15,7 +16,11 @@ const createSdkModule = (core) => {
15
16
  key: 'sdk',
16
17
  messageTransport: core.messageTransport,
17
18
  });
18
- const baseModule = Object.assign(store.getters, pickListenerActions.pickListenerActions(store.eventEmitter));
19
+ const eventEmitter = store.eventEmitter;
20
+ const baseModule = Object.assign(store.getters, pickListenerActions.pickListenerActions(eventEmitter));
21
+ reactivity.effect(() => core.initialization.error, {
22
+ scheduler: () => eventEmitter.emit('error', core.initialization.error),
23
+ });
19
24
  return addProperty.addProperty(baseModule, 'error', {
20
25
  get: () => core.initialization.error,
21
26
  });
@@ -1,6 +1,10 @@
1
- import { SdkModuleState, StoreEventListeners } from '@dynamic-labs/message-transport';
1
+ import { PickedEventListeners, SdkModuleState, StoreEventListeners } from '@dynamic-labs/message-transport';
2
2
  import { Core } from '../../client/core';
3
- export type SdkModule = SdkModuleState & StoreEventListeners<SdkModuleState> & {
3
+ type ErrorEvent = {
4
+ error: (error: Error | null) => void;
5
+ };
6
+ export type SdkModule = SdkModuleState & StoreEventListeners<SdkModuleState> & PickedEventListeners<ErrorEvent> & {
4
7
  readonly error: Error | null;
5
8
  };
6
9
  export declare const createSdkModule: (core: Core) => SdkModule;
10
+ export {};