@dynamic-labs/client 0.0.0-exp20240808.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.
Files changed (99) hide show
  1. package/CHANGELOG.md +3746 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -0
  4. package/_virtual/_tslib.cjs +36 -0
  5. package/_virtual/_tslib.js +32 -0
  6. package/package.cjs +8 -0
  7. package/package.js +4 -0
  8. package/package.json +37 -0
  9. package/src/client/client.cjs +43 -0
  10. package/src/client/client.d.ts +29 -0
  11. package/src/client/client.js +38 -0
  12. package/src/client/core/core.cjs +50 -0
  13. package/src/client/core/core.d.ts +44 -0
  14. package/src/client/core/core.js +46 -0
  15. package/src/client/core/index.d.ts +1 -0
  16. package/src/client/core/modules/initializationModule/index.d.ts +1 -0
  17. package/src/client/core/modules/initializationModule/initializationModule.cjs +33 -0
  18. package/src/client/core/modules/initializationModule/initializationModule.d.ts +6 -0
  19. package/src/client/core/modules/initializationModule/initializationModule.js +29 -0
  20. package/src/client/core/modules/manifestModule/createPartialManifest/createPartialManifest.cjs +17 -0
  21. package/src/client/core/modules/manifestModule/createPartialManifest/createPartialManifest.d.ts +3 -0
  22. package/src/client/core/modules/manifestModule/createPartialManifest/createPartialManifest.js +13 -0
  23. package/src/client/core/modules/manifestModule/createPartialManifest/index.d.ts +1 -0
  24. package/src/client/core/modules/manifestModule/index.d.ts +1 -0
  25. package/src/client/core/modules/manifestModule/manifestModule.cjs +36 -0
  26. package/src/client/core/modules/manifestModule/manifestModule.d.ts +11 -0
  27. package/src/client/core/modules/manifestModule/manifestModule.js +32 -0
  28. package/src/client/core/modules/manifestModule/validateManifest/index.d.ts +1 -0
  29. package/src/client/core/modules/manifestModule/validateManifest/validateManifest.cjs +31 -0
  30. package/src/client/core/modules/manifestModule/validateManifest/validateManifest.d.ts +14 -0
  31. package/src/client/core/modules/manifestModule/validateManifest/validateManifest.js +26 -0
  32. package/src/client/index.d.ts +1 -0
  33. package/src/index.cjs +15 -0
  34. package/src/index.d.ts +9 -0
  35. package/src/index.js +4 -0
  36. package/src/modules/authModule/authModule.cjs +37 -0
  37. package/src/modules/authModule/authModule.d.ts +15 -0
  38. package/src/modules/authModule/authModule.js +33 -0
  39. package/src/modules/authModule/emailAuthModule/emailAuthModule.cjs +20 -0
  40. package/src/modules/authModule/emailAuthModule/emailAuthModule.d.ts +8 -0
  41. package/src/modules/authModule/emailAuthModule/emailAuthModule.js +16 -0
  42. package/src/modules/authModule/emailAuthModule/index.d.ts +1 -0
  43. package/src/modules/authModule/externalAuthModule/externalAuthModule.cjs +16 -0
  44. package/src/modules/authModule/externalAuthModule/externalAuthModule.d.ts +7 -0
  45. package/src/modules/authModule/externalAuthModule/externalAuthModule.js +12 -0
  46. package/src/modules/authModule/externalAuthModule/index.d.ts +1 -0
  47. package/src/modules/authModule/index.d.ts +1 -0
  48. package/src/modules/authModule/smsAuthModule/index.d.ts +1 -0
  49. package/src/modules/authModule/smsAuthModule/smsAuthModule.cjs +17 -0
  50. package/src/modules/authModule/smsAuthModule/smsAuthModule.d.ts +9 -0
  51. package/src/modules/authModule/smsAuthModule/smsAuthModule.js +13 -0
  52. package/src/modules/authModule/socialAuthModule/index.d.ts +1 -0
  53. package/src/modules/authModule/socialAuthModule/socialAuthModule.cjs +14 -0
  54. package/src/modules/authModule/socialAuthModule/socialAuthModule.d.ts +6 -0
  55. package/src/modules/authModule/socialAuthModule/socialAuthModule.js +10 -0
  56. package/src/modules/networksModule/index.d.ts +1 -0
  57. package/src/modules/networksModule/networksModule.cjs +18 -0
  58. package/src/modules/networksModule/networksModule.d.ts +3 -0
  59. package/src/modules/networksModule/networksModule.js +14 -0
  60. package/src/modules/sdkModule/index.d.ts +1 -0
  61. package/src/modules/sdkModule/sdkModule.cjs +24 -0
  62. package/src/modules/sdkModule/sdkModule.d.ts +6 -0
  63. package/src/modules/sdkModule/sdkModule.js +20 -0
  64. package/src/modules/userInterfaceModule/index.d.ts +1 -0
  65. package/src/modules/userInterfaceModule/userInterfaceModule.cjs +23 -0
  66. package/src/modules/userInterfaceModule/userInterfaceModule.d.ts +14 -0
  67. package/src/modules/userInterfaceModule/userInterfaceModule.js +19 -0
  68. package/src/modules/walletsModule/embeddedWalletsModule/embeddedWalletsModule.cjs +29 -0
  69. package/src/modules/walletsModule/embeddedWalletsModule/embeddedWalletsModule.d.ts +6 -0
  70. package/src/modules/walletsModule/embeddedWalletsModule/embeddedWalletsModule.js +25 -0
  71. package/src/modules/walletsModule/embeddedWalletsModule/index.d.ts +1 -0
  72. package/src/modules/walletsModule/index.d.ts +1 -0
  73. package/src/modules/walletsModule/walletsModule.cjs +32 -0
  74. package/src/modules/walletsModule/walletsModule.d.ts +12 -0
  75. package/src/modules/walletsModule/walletsModule.js +28 -0
  76. package/src/utils/Extendable/Extendable.cjs +29 -0
  77. package/src/utils/Extendable/Extendable.d.ts +25 -0
  78. package/src/utils/Extendable/Extendable.js +25 -0
  79. package/src/utils/Extendable/deepMerge/deepMergeInto.cjs +26 -0
  80. package/src/utils/Extendable/deepMerge/deepMergeInto.d.ts +6 -0
  81. package/src/utils/Extendable/deepMerge/deepMergeInto.js +22 -0
  82. package/src/utils/Extendable/deepMerge/index.d.ts +1 -0
  83. package/src/utils/Extendable/hasExtension/hasExtension.cjs +14 -0
  84. package/src/utils/Extendable/hasExtension/hasExtension.d.ts +9 -0
  85. package/src/utils/Extendable/hasExtension/hasExtension.js +10 -0
  86. package/src/utils/Extendable/hasExtension/index.d.ts +1 -0
  87. package/src/utils/Extendable/index.d.ts +1 -0
  88. package/src/utils/addProperty/addProperty.cjs +21 -0
  89. package/src/utils/addProperty/addProperty.d.ts +13 -0
  90. package/src/utils/addProperty/addProperty.js +17 -0
  91. package/src/utils/addProperty/index.d.ts +1 -0
  92. package/src/utils/logger/index.d.ts +1 -0
  93. package/src/utils/logger/logger.cjs +10 -0
  94. package/src/utils/logger/logger.d.ts +2 -0
  95. package/src/utils/logger/logger.js +6 -0
  96. package/src/utils/pickListenerActions/index.d.ts +1 -0
  97. package/src/utils/pickListenerActions/pickListenerActions.cjs +17 -0
  98. package/src/utils/pickListenerActions/pickListenerActions.d.ts +6 -0
  99. package/src/utils/pickListenerActions/pickListenerActions.js +13 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Dynamic Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Dynamic Client
2
+
3
+ Welcome to Dynamic's client!
@@ -0,0 +1,36 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+
21
+ function __awaiter(thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ }
30
+
31
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
32
+ var e = new Error(message);
33
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
34
+ };
35
+
36
+ exports.__awaiter = __awaiter;
@@ -0,0 +1,32 @@
1
+ 'use client'
2
+ /******************************************************************************
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.
15
+ ***************************************************************************** */
16
+
17
+ function __awaiter(thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ }
26
+
27
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
28
+ var e = new Error(message);
29
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
30
+ };
31
+
32
+ export { __awaiter };
package/package.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var version = "0.0.0-exp20240808.0";
7
+
8
+ exports.version = version;
package/package.js ADDED
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ var version = "0.0.0-exp20240808.0";
3
+
4
+ export { version };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@dynamic-labs/client",
3
+ "version": "0.0.0-exp20240808.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
7
+ "directory": "packages/client"
8
+ },
9
+ "description": "Core package for utilizing Dynamic's sdk",
10
+ "bugs": {
11
+ "url": "https://github.com/dynamic-labs/DynamicAuth/issues"
12
+ },
13
+ "homepage": "https://github.com/dynamic-labs/DynamicAuth/main/packages/client#readme",
14
+ "author": "Dynamic Labs, Inc.",
15
+ "license": "MIT",
16
+ "main": "./src/index.cjs",
17
+ "module": "./src/index.js",
18
+ "types": "./src/index.d.ts",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./src/index.d.ts",
23
+ "import": "./src/index.js",
24
+ "require": "./src/index.cjs"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "dependencies": {
29
+ "@dynamic-labs/message-transport": "0.0.0-exp20240808.0",
30
+ "@vue/reactivity": "3.4.21"
31
+ },
32
+ "peerDependencies": {
33
+ "@dynamic-labs/logger": "0.0.0-exp20240808.0",
34
+ "@dynamic-labs/types": "0.0.0-exp20240808.0",
35
+ "eventemitter3": "5.0.1"
36
+ }
37
+ }
@@ -0,0 +1,43 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var authModule = require('../modules/authModule/authModule.cjs');
7
+ var networksModule = require('../modules/networksModule/networksModule.cjs');
8
+ var sdkModule = require('../modules/sdkModule/sdkModule.cjs');
9
+ var userInterfaceModule = require('../modules/userInterfaceModule/userInterfaceModule.cjs');
10
+ var walletsModule = require('../modules/walletsModule/walletsModule.cjs');
11
+ var Extendable = require('../utils/Extendable/Extendable.cjs');
12
+ var core = require('./core/core.cjs');
13
+
14
+ const baseClientExtensionName = 'base';
15
+ /**
16
+ * Generates a basic client that allows interacting with Dynamic's SDK, which
17
+ * will be rendered inside a webview.
18
+ *
19
+ * It must be extended with the necessary Extensions that implement the services
20
+ * it will be used for.
21
+ */
22
+ const createClient = (props) => {
23
+ const core$1 = core.createCore(props);
24
+ const baseExtendable = new Extendable.Extendable(core$1);
25
+ return baseExtendable.extend(() => {
26
+ core$1.declaredExtensionNames.push(baseClientExtensionName);
27
+ return {
28
+ /** Module that gives access over authentication state, such as the auth token and user */
29
+ auth: authModule.createAuthModule(core$1),
30
+ /** Module that provides all the networks configured */
31
+ networks: networksModule.createNetworksModule(core$1),
32
+ /** Module that gives insight over the state of the SDK */
33
+ sdk: sdkModule.createSdkModule(core$1),
34
+ /** Module that provide access to UI features */
35
+ ui: userInterfaceModule.createUserInterfaceModule(core$1),
36
+ /** Module that provides access to user's wallets */
37
+ wallets: walletsModule.createWalletsModule(core$1),
38
+ };
39
+ });
40
+ };
41
+
42
+ exports.baseClientExtensionName = baseClientExtensionName;
43
+ exports.createClient = createClient;
@@ -0,0 +1,29 @@
1
+ import { Extendable } from '../utils/Extendable';
2
+ export declare const baseClientExtensionName = "base";
3
+ export type BaseClient = ReturnType<typeof createClient>;
4
+ export type ClientProps = {
5
+ environmentId: string;
6
+ apiBaseUrl?: string;
7
+ appName?: string;
8
+ appLogoUrl?: string;
9
+ cssOverrides?: string;
10
+ };
11
+ /**
12
+ * Generates a basic client that allows interacting with Dynamic's SDK, which
13
+ * will be rendered inside a webview.
14
+ *
15
+ * It must be extended with the necessary Extensions that implement the services
16
+ * it will be used for.
17
+ */
18
+ export declare const createClient: (props: ClientProps) => {
19
+ /** Module that gives access over authentication state, such as the auth token and user */
20
+ auth: import("../modules/authModule").AuthModule;
21
+ /** Module that provides all the networks configured */
22
+ networks: import("dist/packages/message-transport/src").StoreStateGetters<import("dist/packages/message-transport/src").NetworksModuleState> & Pick<import("eventemitter3").EventEmitter<import("dist/packages/message-transport/src").StoreStateEvents<import("dist/packages/message-transport/src").NetworksModuleState>, any>, "on" | "off" | "once">;
23
+ /** Module that gives insight over the state of the SDK */
24
+ sdk: import("../modules/sdkModule").SdkModule;
25
+ /** Module that provide access to UI features */
26
+ ui: import("../modules/userInterfaceModule/userInterfaceModule").UserInterfaceModule;
27
+ /** Module that provides access to user's wallets */
28
+ wallets: import("../modules/walletsModule").WalletsModule;
29
+ } & Extendable;
@@ -0,0 +1,38 @@
1
+ 'use client'
2
+ import { createAuthModule } from '../modules/authModule/authModule.js';
3
+ import { createNetworksModule } from '../modules/networksModule/networksModule.js';
4
+ import { createSdkModule } from '../modules/sdkModule/sdkModule.js';
5
+ import { createUserInterfaceModule } from '../modules/userInterfaceModule/userInterfaceModule.js';
6
+ import { createWalletsModule } from '../modules/walletsModule/walletsModule.js';
7
+ import { Extendable } from '../utils/Extendable/Extendable.js';
8
+ import { createCore } from './core/core.js';
9
+
10
+ const baseClientExtensionName = 'base';
11
+ /**
12
+ * Generates a basic client that allows interacting with Dynamic's SDK, which
13
+ * will be rendered inside a webview.
14
+ *
15
+ * It must be extended with the necessary Extensions that implement the services
16
+ * it will be used for.
17
+ */
18
+ const createClient = (props) => {
19
+ const core = createCore(props);
20
+ const baseExtendable = new Extendable(core);
21
+ return baseExtendable.extend(() => {
22
+ core.declaredExtensionNames.push(baseClientExtensionName);
23
+ return {
24
+ /** Module that gives access over authentication state, such as the auth token and user */
25
+ auth: createAuthModule(core),
26
+ /** Module that provides all the networks configured */
27
+ networks: createNetworksModule(core),
28
+ /** Module that gives insight over the state of the SDK */
29
+ sdk: createSdkModule(core),
30
+ /** Module that provide access to UI features */
31
+ ui: createUserInterfaceModule(core),
32
+ /** Module that provides access to user's wallets */
33
+ wallets: createWalletsModule(core),
34
+ };
35
+ });
36
+ };
37
+
38
+ export { baseClientExtensionName, createClient };
@@ -0,0 +1,50 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var messageTransport$1 = require('@dynamic-labs/message-transport');
7
+ var initializationModule = require('./modules/initializationModule/initializationModule.cjs');
8
+ var manifestModule = require('./modules/manifestModule/manifestModule.cjs');
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
+ });
49
+
50
+ exports.createCore = createCore;
@@ -0,0 +1,44 @@
1
+ import { ClientProps } from '../client';
2
+ /**
3
+ * Holds properties and methods used by client extensions, but that we don't
4
+ * want users to have access to.
5
+ */
6
+ export type Core = ReturnType<typeof createCore>;
7
+ export declare const createCore: (props: ClientProps) => {
8
+ /**
9
+ * Allows an extension to add its name to the list, such that
10
+ * other extensions are able to detect if it is present.
11
+ *
12
+ * Ex: ViemExtension adds "viem" to the list, and WagmiExtension later
13
+ * checks this list and throws an error if it doesn't find "viem" there.
14
+ */
15
+ declaredExtensionNames: string[];
16
+ /**
17
+ * SDK initialization module handles the initialization error
18
+ */
19
+ initialization: import("./modules/initializationModule/initializationModule").InitializationModule;
20
+ /**
21
+ * Manages the manifest of the host
22
+ */
23
+ manifest: {
24
+ setAppOrigin: (appOrigin: string) => string;
25
+ setPlatform: (platform: "browser" | "react-native" | "flutter") => "browser" | "react-native" | "flutter";
26
+ setRedirectUrl: (redirectUrl: string) => string;
27
+ };
28
+ /**
29
+ * Message transport that will be used to send and receive messages to the webview.
30
+ * Should preferably be used with createRequestChannel, rather than used directly.
31
+ *
32
+ * Note: Doesn't implement forwarding messages to/from webview yet.
33
+ * The user is expected to extend the client with an Extension that implements that.
34
+ */
35
+ messageTransport: {
36
+ 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
+ } & {
41
+ defaultOrigin: "webview" | "host";
42
+ emit: (message: import("@dynamic-labs/message-transport").MessageTransportDataOptionalOrigin) => void;
43
+ };
44
+ };
@@ -0,0 +1,46 @@
1
+ 'use client'
2
+ import { applyDefaultMessageOrigin, makeWaitForInitEvent, sdkHasLoadedEventName, createMessageTransport } from '@dynamic-labs/message-transport';
3
+ import { createInitializationModule } from './modules/initializationModule/initializationModule.js';
4
+ import { createManifestModule } from './modules/manifestModule/manifestModule.js';
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
+ });
45
+
46
+ export { createCore };
@@ -0,0 +1 @@
1
+ export * from './core';
@@ -0,0 +1 @@
1
+ export { createInitializationModule } from './initializationModule';
@@ -0,0 +1,33 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var reactivity = require('@vue/reactivity');
7
+ var messageTransport = require('@dynamic-labs/message-transport');
8
+ var logger = require('../../../../utils/logger/logger.cjs');
9
+
10
+ const createInitializationModule = (messageTransport$1) => {
11
+ const consoleRequestChannel = messageTransport.createRequestChannel(messageTransport$1);
12
+ const state = reactivity.reactive({
13
+ error: null,
14
+ });
15
+ consoleRequestChannel.handle('error', (serializedError, { severity }) => {
16
+ const error = messageTransport.parseErrorFromTransport(serializedError);
17
+ if (severity === 'fatal') {
18
+ state.error = error;
19
+ }
20
+ logger.logger.error(error);
21
+ });
22
+ return {
23
+ get error() {
24
+ return state.error;
25
+ },
26
+ set error(error) {
27
+ state.error = error;
28
+ logger.logger.error(state.error);
29
+ },
30
+ };
31
+ };
32
+
33
+ exports.createInitializationModule = createInitializationModule;
@@ -0,0 +1,6 @@
1
+ import { MessageTransportWithDefaultOrigin } from '@dynamic-labs/message-transport';
2
+ export type InitializationModule = {
3
+ get error(): Error | null;
4
+ set error(error: Error);
5
+ };
6
+ export declare const createInitializationModule: (messageTransport: MessageTransportWithDefaultOrigin) => InitializationModule;
@@ -0,0 +1,29 @@
1
+ 'use client'
2
+ import { reactive } from '@vue/reactivity';
3
+ import { createRequestChannel, parseErrorFromTransport } from '@dynamic-labs/message-transport';
4
+ import { logger } from '../../../../utils/logger/logger.js';
5
+
6
+ const createInitializationModule = (messageTransport) => {
7
+ const consoleRequestChannel = createRequestChannel(messageTransport);
8
+ const state = reactive({
9
+ error: null,
10
+ });
11
+ consoleRequestChannel.handle('error', (serializedError, { severity }) => {
12
+ const error = parseErrorFromTransport(serializedError);
13
+ if (severity === 'fatal') {
14
+ state.error = error;
15
+ }
16
+ logger.error(error);
17
+ });
18
+ return {
19
+ get error() {
20
+ return state.error;
21
+ },
22
+ set error(error) {
23
+ state.error = error;
24
+ logger.error(state.error);
25
+ },
26
+ };
27
+ };
28
+
29
+ export { createInitializationModule };
@@ -0,0 +1,17 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _package = require('../../../../../../package.cjs');
7
+
8
+ const createPartialManifest = ({ apiBaseUrl, environmentId, appLogoUrl, appName, cssOverrides, }) => ({
9
+ apiBaseUrl,
10
+ appLogoUrl,
11
+ appName,
12
+ clientVersion: _package.version,
13
+ cssOverrides,
14
+ environmentId,
15
+ });
16
+
17
+ exports.createPartialManifest = createPartialManifest;
@@ -0,0 +1,3 @@
1
+ import type { ClientManifest } from '@dynamic-labs/message-transport';
2
+ import { ClientProps } from '../../../../client';
3
+ export declare const createPartialManifest: ({ apiBaseUrl, environmentId, appLogoUrl, appName, cssOverrides, }: ClientProps) => Partial<ClientManifest>;
@@ -0,0 +1,13 @@
1
+ 'use client'
2
+ import { version } from '../../../../../../package.js';
3
+
4
+ const createPartialManifest = ({ apiBaseUrl, environmentId, appLogoUrl, appName, cssOverrides, }) => ({
5
+ apiBaseUrl,
6
+ appLogoUrl,
7
+ appName,
8
+ clientVersion: version,
9
+ cssOverrides,
10
+ environmentId,
11
+ });
12
+
13
+ export { createPartialManifest };
@@ -0,0 +1 @@
1
+ export * from './createPartialManifest';
@@ -0,0 +1 @@
1
+ export { createManifestModule } from './manifestModule';
@@ -0,0 +1,36 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
+ var messageTransport = require('@dynamic-labs/message-transport');
8
+ var logger = require('../../../../utils/logger/logger.cjs');
9
+ var createPartialManifest = require('./createPartialManifest/createPartialManifest.cjs');
10
+ var validateManifest = require('./validateManifest/validateManifest.cjs');
11
+
12
+ /**
13
+ * Manifest module handles the client manifest that will be requested by the webview
14
+ */
15
+ const createManifestModule = (props, messageTransport$1, initializationModule) => {
16
+ const requestChannel = messageTransport.createRequestChannel(messageTransport$1);
17
+ const manifest = createPartialManifest.createPartialManifest(props);
18
+ requestChannel.handle('manifest', () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
19
+ try {
20
+ return validateManifest.validateManifest(manifest);
21
+ }
22
+ catch (error) {
23
+ logger.logger.error(error);
24
+ if (error instanceof Error)
25
+ initializationModule.error = error;
26
+ throw error;
27
+ }
28
+ }));
29
+ return {
30
+ setAppOrigin: (appOrigin) => (manifest.appOrigin = appOrigin),
31
+ setPlatform: (platform) => (manifest.platform = platform),
32
+ setRedirectUrl: (redirectUrl) => (manifest.redirectUrl = redirectUrl),
33
+ };
34
+ };
35
+
36
+ exports.createManifestModule = createManifestModule;
@@ -0,0 +1,11 @@
1
+ import { ClientManifest, MessageTransportWithDefaultOrigin } from '@dynamic-labs/message-transport';
2
+ import { ClientProps } from '../../../client';
3
+ import { InitializationModule } from '../initializationModule/initializationModule';
4
+ /**
5
+ * Manifest module handles the client manifest that will be requested by the webview
6
+ */
7
+ export declare const createManifestModule: (props: ClientProps, messageTransport: MessageTransportWithDefaultOrigin, initializationModule: InitializationModule) => {
8
+ setAppOrigin: (appOrigin: string) => string;
9
+ setPlatform: (platform: ClientManifest['platform']) => "browser" | "react-native" | "flutter";
10
+ setRedirectUrl: (redirectUrl: string) => string;
11
+ };
@@ -0,0 +1,32 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
+ import { createRequestChannel } from '@dynamic-labs/message-transport';
4
+ import { logger } from '../../../../utils/logger/logger.js';
5
+ import { createPartialManifest } from './createPartialManifest/createPartialManifest.js';
6
+ import { validateManifest } from './validateManifest/validateManifest.js';
7
+
8
+ /**
9
+ * Manifest module handles the client manifest that will be requested by the webview
10
+ */
11
+ const createManifestModule = (props, messageTransport, initializationModule) => {
12
+ const requestChannel = createRequestChannel(messageTransport);
13
+ const manifest = createPartialManifest(props);
14
+ requestChannel.handle('manifest', () => __awaiter(void 0, void 0, void 0, function* () {
15
+ try {
16
+ return validateManifest(manifest);
17
+ }
18
+ catch (error) {
19
+ logger.error(error);
20
+ if (error instanceof Error)
21
+ initializationModule.error = error;
22
+ throw error;
23
+ }
24
+ }));
25
+ return {
26
+ setAppOrigin: (appOrigin) => (manifest.appOrigin = appOrigin),
27
+ setPlatform: (platform) => (manifest.platform = platform),
28
+ setRedirectUrl: (redirectUrl) => (manifest.redirectUrl = redirectUrl),
29
+ };
30
+ };
31
+
32
+ export { createManifestModule };
@@ -0,0 +1 @@
1
+ export * from './validateManifest';
@@ -0,0 +1,31 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * Maps each required field of the client manifest to an error message that explains
8
+ * what the customer can do if his app runs into the issue where this field is missing from his manifest.
9
+ */
10
+ const mandatoryFields = {
11
+ clientVersion: "We were unable to retrieve the Dynamic Client's version from your app. Please contact us about this.",
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.',
15
+ };
16
+ const validateManifest = (partialManifest) => {
17
+ /**
18
+ * If any of these fields are missing, we show the user an error message.
19
+ * You should map to each required field a description of what the user can do to fix this issue.
20
+ *
21
+ * And if you add a new required field to DynamicClient, TS will automatically force you to
22
+ * also include a description here :)
23
+ */
24
+ for (const [field, description] of Object.entries(mandatoryFields))
25
+ if (partialManifest[field] === undefined)
26
+ throw new Error(`Missing client manifest field "${field}": ${description}`);
27
+ return partialManifest;
28
+ };
29
+
30
+ exports.mandatoryFields = mandatoryFields;
31
+ exports.validateManifest = validateManifest;