@dynamic-labs/utils 1.4.12 → 1.4.14

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/CHANGELOG.md CHANGED
@@ -1,4 +1,17 @@
1
1
 
2
+ ### [1.4.14](https://github.com/dynamic-labs/DynamicAuth/compare/v1.4.13...v1.4.14) (2024-07-11)
3
+
4
+ ### [1.4.13](https://github.com/dynamic-labs/DynamicAuth/compare/v1.4.12...v1.4.13) (2024-06-05)
5
+
6
+ ### Features
7
+
8
+ * add the Starknet MetaMask snap to the available wallets
9
+
10
+ ### Bug Fixes
11
+
12
+ * bump @solana/web3.js containing new version of rpc-websockets ([#5864](https://github.com/dynamic-labs/DynamicAuth/issues/5864)) ([562ff9b](https://github.com/dynamic-labs/DynamicAuth/commit/562ff9b706c8be62812ace08bcaef96e26dcd841))
13
+ * wallet improvements
14
+
2
15
  ### [1.4.12](https://github.com/dynamic-labs/DynamicAuth/compare/v1.4.11...v1.4.12) (2024-05-22)
3
16
 
4
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/utils",
3
- "version": "1.4.12",
3
+ "version": "1.4.14",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -27,8 +27,9 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "tldts": "^6.0.16",
30
- "@dynamic-labs/logger": "1.4.12",
31
- "@dynamic-labs/types": "1.4.12"
30
+ "@dynamic-labs/logger": "1.4.14",
31
+ "@dynamic-labs/types": "1.4.14",
32
+ "stream": "0.0.2"
32
33
  },
33
34
  "peerDependencies": {
34
35
  "viem": "^1.19.13 || ^2.2.0"
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const isEip9693Event = (event) => event.type === 'eip6963:announceProvider' &&
6
+ event.detail !== undefined;
7
+ class Eip6963Provider {
8
+ constructor() {
9
+ this.providers = [];
10
+ }
11
+ registerProviders() {
12
+ if (typeof window === 'undefined') {
13
+ return;
14
+ }
15
+ window.addEventListener('eip6963:announceProvider', (event) => {
16
+ if (!isEip9693Event(event)) {
17
+ return;
18
+ }
19
+ this.providers.push(event.detail);
20
+ });
21
+ window.dispatchEvent(new Event('eip6963:requestProvider'));
22
+ }
23
+ }
24
+ class Eip6963ProviderSingleton {
25
+ constructor() {
26
+ this.eip6963Provider = new Eip6963Provider();
27
+ }
28
+ static get() {
29
+ var _a;
30
+ if (!((_a = Eip6963ProviderSingleton.instance) === null || _a === void 0 ? void 0 : _a.eip6963Provider)) {
31
+ Eip6963ProviderSingleton.instance = new Eip6963ProviderSingleton();
32
+ Eip6963ProviderSingleton.instance.eip6963Provider.registerProviders();
33
+ }
34
+ return Eip6963ProviderSingleton.instance.eip6963Provider;
35
+ }
36
+ }
37
+
38
+ exports.Eip6963Provider = Eip6963Provider;
39
+ exports.Eip6963ProviderSingleton = Eip6963ProviderSingleton;
@@ -0,0 +1,34 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { EventEmitter } from 'stream';
4
+ export type IEthereum = {
5
+ [key: string]: any;
6
+ providers?: object[];
7
+ request: <T extends string>(params: {
8
+ method: T;
9
+ } | object) => Promise<T extends 'eth_requestAccounts' ? [string] : object>;
10
+ } & EventEmitter;
11
+ /**
12
+ * Represents the assets needed to display a wallet
13
+ */
14
+ type Eip6963ProviderInfo = {
15
+ uuid: string;
16
+ name: string;
17
+ icon: string;
18
+ rdns: string;
19
+ };
20
+ type Eip6963ProviderDetail = {
21
+ info: Eip6963ProviderInfo;
22
+ provider: IEthereum;
23
+ };
24
+ export declare class Eip6963Provider {
25
+ providers: Eip6963ProviderDetail[];
26
+ registerProviders(): void;
27
+ }
28
+ export declare class Eip6963ProviderSingleton {
29
+ readonly eip6963Provider: Eip6963Provider;
30
+ private constructor();
31
+ private static instance;
32
+ static get(): Eip6963Provider;
33
+ }
34
+ export {};
@@ -0,0 +1,34 @@
1
+ const isEip9693Event = (event) => event.type === 'eip6963:announceProvider' &&
2
+ event.detail !== undefined;
3
+ class Eip6963Provider {
4
+ constructor() {
5
+ this.providers = [];
6
+ }
7
+ registerProviders() {
8
+ if (typeof window === 'undefined') {
9
+ return;
10
+ }
11
+ window.addEventListener('eip6963:announceProvider', (event) => {
12
+ if (!isEip9693Event(event)) {
13
+ return;
14
+ }
15
+ this.providers.push(event.detail);
16
+ });
17
+ window.dispatchEvent(new Event('eip6963:requestProvider'));
18
+ }
19
+ }
20
+ class Eip6963ProviderSingleton {
21
+ constructor() {
22
+ this.eip6963Provider = new Eip6963Provider();
23
+ }
24
+ static get() {
25
+ var _a;
26
+ if (!((_a = Eip6963ProviderSingleton.instance) === null || _a === void 0 ? void 0 : _a.eip6963Provider)) {
27
+ Eip6963ProviderSingleton.instance = new Eip6963ProviderSingleton();
28
+ Eip6963ProviderSingleton.instance.eip6963Provider.registerProviders();
29
+ }
30
+ return Eip6963ProviderSingleton.instance.eip6963Provider;
31
+ }
32
+ }
33
+
34
+ export { Eip6963Provider, Eip6963ProviderSingleton };
@@ -0,0 +1 @@
1
+ export * from './eip6963Provider';
package/src/index.cjs CHANGED
@@ -40,6 +40,8 @@ var handleMobileWalletRedirect = require('./handleMobileWalletRedirect/handleMob
40
40
  var uniq = require('./uniq/uniq.cjs');
41
41
  var getTLD = require('./getTLD/getTLD.cjs');
42
42
  var pipe = require('./pipe/pipe.cjs');
43
+ var eip6963Provider = require('./eip6963/eip6963Provider.cjs');
44
+ var template = require('./template/template.cjs');
43
45
 
44
46
 
45
47
 
@@ -95,3 +97,6 @@ exports.handleMobileWalletRedirect = handleMobileWalletRedirect.handleMobileWall
95
97
  exports.uniq = uniq.uniq;
96
98
  exports.getTLD = getTLD.getTLD;
97
99
  exports.pipe = pipe.pipe;
100
+ exports.Eip6963Provider = eip6963Provider.Eip6963Provider;
101
+ exports.Eip6963ProviderSingleton = eip6963Provider.Eip6963ProviderSingleton;
102
+ exports.template = template.template;
package/src/index.d.ts CHANGED
@@ -17,3 +17,5 @@ export * from './handleMobileWalletRedirect';
17
17
  export * from './uniq';
18
18
  export * from './getTLD';
19
19
  export * from './pipe';
20
+ export * from './eip6963';
21
+ export { template } from './template';
package/src/index.js CHANGED
@@ -36,3 +36,5 @@ export { handleMobileWalletRedirect } from './handleMobileWalletRedirect/handleM
36
36
  export { uniq } from './uniq/uniq.js';
37
37
  export { getTLD } from './getTLD/getTLD.js';
38
38
  export { pipe } from './pipe/pipe.js';
39
+ export { Eip6963Provider, Eip6963ProviderSingleton } from './eip6963/eip6963Provider.js';
40
+ export { template } from './template/template.js';
@@ -0,0 +1 @@
1
+ export { template } from './template';
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Creates a template function that replaces placeholders with corresponding values from a data object.
7
+ * @param {string} templateText - The template string containing placeholders in the form {{placeholder}}.
8
+ * @returns {(data) => string} - A function that replaces the placeholders with the values from the data object.
9
+ *
10
+ * @example
11
+ * // Basic usage
12
+ * const compiled = template('Test text {{placeholder}} value');
13
+ * console.log(compiled({ placeholder: 'test' })); // Output: 'Test text test value'
14
+ *
15
+ * @example
16
+ * // Multiple placeholders
17
+ * const compiled = template('Test text {{placeholder}} value {{placeholder2}}');
18
+ * console.log(compiled({ placeholder: 'test', placeholder2: 'test2' })); // Output: 'Test text test value test2'
19
+ */
20
+ const template = (templateText) => {
21
+ return (data) => templateText.replace(/{{(\w+?)}}/g, (match, key) => key in data ? data[key] : match);
22
+ };
23
+
24
+ exports.template = template;
@@ -0,0 +1,18 @@
1
+ type ExtractPlaceholders<T extends string> = T extends `${infer _Start}{{${infer Placeholder}}}${infer Rest}` ? Placeholder | ExtractPlaceholders<Rest> : never;
2
+ /**
3
+ * Creates a template function that replaces placeholders with corresponding values from a data object.
4
+ * @param {string} templateText - The template string containing placeholders in the form {{placeholder}}.
5
+ * @returns {(data) => string} - A function that replaces the placeholders with the values from the data object.
6
+ *
7
+ * @example
8
+ * // Basic usage
9
+ * const compiled = template('Test text {{placeholder}} value');
10
+ * console.log(compiled({ placeholder: 'test' })); // Output: 'Test text test value'
11
+ *
12
+ * @example
13
+ * // Multiple placeholders
14
+ * const compiled = template('Test text {{placeholder}} value {{placeholder2}}');
15
+ * console.log(compiled({ placeholder: 'test', placeholder2: 'test2' })); // Output: 'Test text test value test2'
16
+ */
17
+ export declare const template: <T extends string>(templateText: T) => (data: { [key in ExtractPlaceholders<T>]: string; }) => string;
18
+ export {};
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Creates a template function that replaces placeholders with corresponding values from a data object.
3
+ * @param {string} templateText - The template string containing placeholders in the form {{placeholder}}.
4
+ * @returns {(data) => string} - A function that replaces the placeholders with the values from the data object.
5
+ *
6
+ * @example
7
+ * // Basic usage
8
+ * const compiled = template('Test text {{placeholder}} value');
9
+ * console.log(compiled({ placeholder: 'test' })); // Output: 'Test text test value'
10
+ *
11
+ * @example
12
+ * // Multiple placeholders
13
+ * const compiled = template('Test text {{placeholder}} value {{placeholder2}}');
14
+ * console.log(compiled({ placeholder: 'test', placeholder2: 'test2' })); // Output: 'Test text test value test2'
15
+ */
16
+ const template = (templateText) => {
17
+ return (data) => templateText.replace(/{{(\w+?)}}/g, (match, key) => key in data ? data[key] : match);
18
+ };
19
+
20
+ export { template };