@dynamic-labs/client 2.0.0-alpha.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,35 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+
20
+ function __awaiter(thisArg, _arguments, P, generator) {
21
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
+ return new (P || (P = Promise))(function (resolve, reject) {
23
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
27
+ });
28
+ }
29
+
30
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
31
+ var e = new Error(message);
32
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
33
+ };
34
+
35
+ exports.__awaiter = __awaiter;
@@ -0,0 +1,31 @@
1
+ /******************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+
16
+ function __awaiter(thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ }
25
+
26
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
27
+ var e = new Error(message);
28
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
29
+ };
30
+
31
+ export { __awaiter };
package/package.cjs ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var version = "2.0.0-alpha.26";
6
+
7
+ exports.version = version;
package/package.js ADDED
@@ -0,0 +1,3 @@
1
+ var version = "2.0.0-alpha.26";
2
+
3
+ export { version };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@dynamic-labs/client",
3
+ "version": "2.0.0-alpha.26",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/dynamic-labs/DynamicAuth.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
+ "peerDependencies": {
29
+ "@dynamic-labs/message-transport": "2.0.0-alpha.26"
30
+ }
31
+ }
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var sdkModule = require('../modules/sdkModule/sdkModule.cjs');
6
+ var Extendable = require('../utils/Extendable/Extendable.cjs');
7
+ var core = require('./core/core.cjs');
8
+
9
+ /**
10
+ * Generates a basic client that allows interacting with Dynamic's SDK, which
11
+ * will be rendered inside a webview.
12
+ *
13
+ * It must be extended with the necessary Extensions that implement the services
14
+ * it will be used for.
15
+ */
16
+ const createClient = (props) => {
17
+ const core$1 = core.createCore();
18
+ const baseExtendable = new Extendable.Extendable(core$1);
19
+ return baseExtendable.extend(() => ({
20
+ /** Module that gives insight over the state of the SDK */
21
+ sdk: sdkModule.createSdkModule(core$1, props),
22
+ }));
23
+ };
24
+
25
+ exports.createClient = createClient;
@@ -0,0 +1,22 @@
1
+ import { Extendable } from '../utils/Extendable';
2
+ export type BaseClient = ReturnType<typeof createClient>;
3
+ export type ClientProps = {
4
+ environmentId: string;
5
+ apiBaseUrl?: string;
6
+ appName?: string;
7
+ appLogoUrl?: string;
8
+ cssOverrides?: string;
9
+ };
10
+ /**
11
+ * Generates a basic client that allows interacting with Dynamic's SDK, which
12
+ * will be rendered inside a webview.
13
+ *
14
+ * It must be extended with the necessary Extensions that implement the services
15
+ * it will be used for.
16
+ */
17
+ export declare const createClient: (props: ClientProps) => {
18
+ /** Module that gives insight over the state of the SDK */
19
+ sdk: {
20
+ readonly loaded: boolean;
21
+ };
22
+ } & Extendable;
@@ -0,0 +1,21 @@
1
+ import { createSdkModule } from '../modules/sdkModule/sdkModule.js';
2
+ import { Extendable } from '../utils/Extendable/Extendable.js';
3
+ import { createCore } from './core/core.js';
4
+
5
+ /**
6
+ * Generates a basic client that allows interacting with Dynamic's SDK, which
7
+ * will be rendered inside a webview.
8
+ *
9
+ * It must be extended with the necessary Extensions that implement the services
10
+ * it will be used for.
11
+ */
12
+ const createClient = (props) => {
13
+ const core = createCore();
14
+ const baseExtendable = new Extendable(core);
15
+ return baseExtendable.extend(() => ({
16
+ /** Module that gives insight over the state of the SDK */
17
+ sdk: createSdkModule(core, props),
18
+ }));
19
+ };
20
+
21
+ export { createClient };
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var messageTransport = require('@dynamic-labs/message-transport');
6
+
7
+ const createCore = () => ({
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: [],
16
+ /**
17
+ * Message transport that will be used to send and receive messages to the webview.
18
+ * Should preferably be used with createRequestChannel, rather than used directly.
19
+ *
20
+ * Note: Doesn't implement forwarding messages to/from webview yet.
21
+ * The user is expected to extend the client with an Extension that implements that.
22
+ */
23
+ messageTransport: messageTransport.applyDefaultMessageOrigin({
24
+ defaultOrigin: 'host',
25
+ messageTransport: messageTransport.makeWaitForInitEvent({
26
+ bypassBlockIf: (message) => message.origin === 'webview',
27
+ initializeMessageType: messageTransport.sdkHasLoadedEventName,
28
+ messageTransport: messageTransport.createMessageTransport(),
29
+ }),
30
+ }),
31
+ });
32
+
33
+ exports.createCore = createCore;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Holds properties and methods used by client extensions, but that we don't
3
+ * want users to have access to.
4
+ */
5
+ export type Core = ReturnType<typeof createCore>;
6
+ export declare const createCore: () => {
7
+ /**
8
+ * Allows an extension to add its name to the list, such that
9
+ * other extensions are able to detect if it is present.
10
+ *
11
+ * Ex: ViemExtension adds "viem" to the list, and WagmiExtension later
12
+ * checks this list and throws an error if it doesn't find "viem" there.
13
+ */
14
+ declaredExtensionNames: string[];
15
+ /**
16
+ * Message transport that will be used to send and receive messages to the webview.
17
+ * Should preferably be used with createRequestChannel, rather than used directly.
18
+ *
19
+ * Note: Doesn't implement forwarding messages to/from webview yet.
20
+ * The user is expected to extend the client with an Extension that implements that.
21
+ */
22
+ messageTransport: {
23
+ unblock: () => void;
24
+ emit: (message: import("@dynamic-labs/message-transport").MessageTransportData) => void;
25
+ off: (callback: import("@dynamic-labs/message-transport").MessageTransportCallback) => void;
26
+ on: (callback: import("@dynamic-labs/message-transport").MessageTransportCallback) => void;
27
+ } & {
28
+ defaultOrigin: "host" | "webview";
29
+ emit: (message: import("@dynamic-labs/message-transport").MessageTransportDataOptionalOrigin) => void;
30
+ };
31
+ };
@@ -0,0 +1,29 @@
1
+ import { applyDefaultMessageOrigin, makeWaitForInitEvent, sdkHasLoadedEventName, createMessageTransport } from '@dynamic-labs/message-transport';
2
+
3
+ const createCore = () => ({
4
+ /**
5
+ * Allows an extension to add its name to the list, such that
6
+ * other extensions are able to detect if it is present.
7
+ *
8
+ * Ex: ViemExtension adds "viem" to the list, and WagmiExtension later
9
+ * checks this list and throws an error if it doesn't find "viem" there.
10
+ */
11
+ declaredExtensionNames: [],
12
+ /**
13
+ * Message transport that will be used to send and receive messages to the webview.
14
+ * Should preferably be used with createRequestChannel, rather than used directly.
15
+ *
16
+ * Note: Doesn't implement forwarding messages to/from webview yet.
17
+ * The user is expected to extend the client with an Extension that implements that.
18
+ */
19
+ messageTransport: applyDefaultMessageOrigin({
20
+ defaultOrigin: 'host',
21
+ messageTransport: makeWaitForInitEvent({
22
+ bypassBlockIf: (message) => message.origin === 'webview',
23
+ initializeMessageType: sdkHasLoadedEventName,
24
+ messageTransport: createMessageTransport(),
25
+ }),
26
+ }),
27
+ });
28
+
29
+ export { createCore };
@@ -0,0 +1 @@
1
+ export * from './core';
@@ -0,0 +1 @@
1
+ export * from './client';
package/src/index.cjs ADDED
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Extendable = require('./utils/Extendable/Extendable.cjs');
6
+ var client = require('./client/client.cjs');
7
+
8
+
9
+
10
+ exports.Extendable = Extendable.Extendable;
11
+ exports.createClient = client.createClient;
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { type Core } from './client/core';
2
+ export { Extendable, type Extension } from './utils/Extendable';
3
+ export { createClient, type BaseClient, type ClientProps } from './client';
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Extendable } from './utils/Extendable/Extendable.js';
2
+ export { createClient } from './client/client.js';
@@ -0,0 +1 @@
1
+ export * from './sdkModule';
@@ -0,0 +1 @@
1
+ export * from './manifest';
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _package = require('../../../../package.cjs');
6
+
7
+ const createManifest = ({ apiBaseUrl, environmentId, appLogoUrl, appName, cssOverrides, }) => ({
8
+ apiBaseUrl,
9
+ appLogoUrl,
10
+ appName,
11
+ clientVersion: _package.version,
12
+ cssOverrides,
13
+ environmentId,
14
+ });
15
+
16
+ exports.createManifest = createManifest;
@@ -0,0 +1,3 @@
1
+ import type { ClientManifest } from '@dynamic-labs/message-transport';
2
+ import type { ClientProps } from '../../../client';
3
+ export declare const createManifest: ({ apiBaseUrl, environmentId, appLogoUrl, appName, cssOverrides, }: ClientProps) => ClientManifest;
@@ -0,0 +1,12 @@
1
+ import { version } from '../../../../package.js';
2
+
3
+ const createManifest = ({ apiBaseUrl, environmentId, appLogoUrl, appName, cssOverrides, }) => ({
4
+ apiBaseUrl,
5
+ appLogoUrl,
6
+ appName,
7
+ clientVersion: version,
8
+ cssOverrides,
9
+ environmentId,
10
+ });
11
+
12
+ export { createManifest };
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../../_virtual/_tslib.cjs');
6
+ var messageTransport = require('@dynamic-labs/message-transport');
7
+ var manifest = require('./manifest/manifest.cjs');
8
+
9
+ const createSdkModule = (core, props) => {
10
+ const requestChannel = messageTransport.createRequestChannel(core.messageTransport);
11
+ const state = {
12
+ loaded: false,
13
+ };
14
+ requestChannel.handle('manifest', () => _tslib.__awaiter(void 0, void 0, void 0, function* () { return manifest.createManifest(props); }));
15
+ // This will soon have to change. After we implement th store abstraction
16
+ // in the message transport package, we should use it here.
17
+ requestChannel.handle('loaded', () => (state.loaded = true));
18
+ return {
19
+ get loaded() {
20
+ return state.loaded;
21
+ },
22
+ };
23
+ };
24
+
25
+ exports.createSdkModule = createSdkModule;
@@ -0,0 +1,5 @@
1
+ import type { ClientProps } from '../../client';
2
+ import { Core } from '../../client/core';
3
+ export declare const createSdkModule: (core: Core, props: ClientProps) => {
4
+ readonly loaded: boolean;
5
+ };
@@ -0,0 +1,21 @@
1
+ import { __awaiter } from '../../../_virtual/_tslib.js';
2
+ import { createRequestChannel } from '@dynamic-labs/message-transport';
3
+ import { createManifest } from './manifest/manifest.js';
4
+
5
+ const createSdkModule = (core, props) => {
6
+ const requestChannel = createRequestChannel(core.messageTransport);
7
+ const state = {
8
+ loaded: false,
9
+ };
10
+ requestChannel.handle('manifest', () => __awaiter(void 0, void 0, void 0, function* () { return createManifest(props); }));
11
+ // This will soon have to change. After we implement th store abstraction
12
+ // in the message transport package, we should use it here.
13
+ requestChannel.handle('loaded', () => (state.loaded = true));
14
+ return {
15
+ get loaded() {
16
+ return state.loaded;
17
+ },
18
+ };
19
+ };
20
+
21
+ export { createSdkModule };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ // Class here is necessary to have access to "this" keyword
6
+ /**
7
+ * An object that can be extended.
8
+ *
9
+ * To extend here means to add or replace the existing properties of this object,
10
+ * as well as kicking off any related procedures. Like a structure on which you can
11
+ * attach lego bricks.
12
+ *
13
+ * Ex: a { movie: "Up" } object can be extended by adding an audienceScore
14
+ * property to it, and kicking off an api call that will constantly update this property from
15
+ * an IMDb api.
16
+ */
17
+ class Extendable {
18
+ constructor(core) {
19
+ this.core = core;
20
+ }
21
+ extend(extension) {
22
+ return Object.assign(this, extension(this, this.core));
23
+ }
24
+ }
25
+
26
+ exports.Extendable = Extendable;
@@ -0,0 +1,25 @@
1
+ import { Core } from '../../client/core';
2
+ /**
3
+ * Allows extending properties and methods of an Extendable
4
+ */
5
+ export type Extension<T extends Record<string, unknown>> = (
6
+ /** The extendable object to which this extension will be applied */
7
+ extendable: Extendable,
8
+ /** An object with internal properties and methods not publicly accessible */
9
+ core: Core) => T;
10
+ /**
11
+ * An object that can be extended.
12
+ *
13
+ * To extend here means to add or replace the existing properties of this object,
14
+ * as well as kicking off any related procedures. Like a structure on which you can
15
+ * attach lego bricks.
16
+ *
17
+ * Ex: a { movie: "Up" } object can be extended by adding an audienceScore
18
+ * property to it, and kicking off an api call that will constantly update this property from
19
+ * an IMDb api.
20
+ */
21
+ export declare class Extendable {
22
+ private readonly core;
23
+ constructor(core: Core);
24
+ extend<T extends Record<string, unknown>>(extension: Extension<T>): T & typeof this;
25
+ }
@@ -0,0 +1,22 @@
1
+ // Class here is necessary to have access to "this" keyword
2
+ /**
3
+ * An object that can be extended.
4
+ *
5
+ * To extend here means to add or replace the existing properties of this object,
6
+ * as well as kicking off any related procedures. Like a structure on which you can
7
+ * attach lego bricks.
8
+ *
9
+ * Ex: a { movie: "Up" } object can be extended by adding an audienceScore
10
+ * property to it, and kicking off an api call that will constantly update this property from
11
+ * an IMDb api.
12
+ */
13
+ class Extendable {
14
+ constructor(core) {
15
+ this.core = core;
16
+ }
17
+ extend(extension) {
18
+ return Object.assign(this, extension(this, this.core));
19
+ }
20
+ }
21
+
22
+ export { Extendable };
@@ -0,0 +1,9 @@
1
+ import { Extendable } from '..';
2
+ import { Core } from '../../..';
3
+ /**
4
+ * This method allows safely type casting an Extendable object to include an extension type.
5
+ *
6
+ * It assumes you are checking if the target extension has declared its name to the core,
7
+ * and if that name is found in core's declaredExtensionNames, it will complete the type cast.
8
+ */
9
+ export declare const hasExtension: <T>(extendable: Extendable, core: Core, extensionName: string) => extendable is Extendable & T;
@@ -0,0 +1 @@
1
+ export * from './Extendable';