@dynamic-labs-sdk/client 0.0.1-alpha.4 → 0.0.1-alpha.5
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 +6 -0
- package/getClient.cjs.js +1 -1
- package/getClient.esm.js +1 -1
- package/index.cjs.js +39 -5
- package/index.esm.js +39 -5
- package/package.json +1 -1
- package/src/client/createDynamicClient/createDynamicClient.d.ts +11 -0
- package/src/client/createDynamicClient/createDynamicClient.d.ts.map +1 -1
- package/src/errors/UnavailableInServerSideError.d.ts +5 -0
- package/src/errors/UnavailableInServerSideError.d.ts.map +1 -0
- package/src/services/fetch/createWebFetch.d.ts.map +1 -1
- package/src/services/openDeeplink/createWebDeeplinkOpener/createWebDeeplinkOpener.d.ts.map +1 -1
- package/src/utils/isServerSideRendering/index.d.ts +2 -0
- package/src/utils/isServerSideRendering/index.d.ts.map +1 -0
- package/src/utils/isServerSideRendering/isServerSideRendering.d.ts +5 -0
- package/src/utils/isServerSideRendering/isServerSideRendering.d.ts.map +1 -0
package/CHANGELOG.md
CHANGED
package/getClient.cjs.js
CHANGED
package/getClient.esm.js
CHANGED
package/index.cjs.js
CHANGED
|
@@ -266,6 +266,11 @@ class ClientAlreadyInitializedError extends getClient.BaseError {
|
|
|
266
266
|
}
|
|
267
267
|
};
|
|
268
268
|
|
|
269
|
+
/**
|
|
270
|
+
* Indicates if the code is running in a server-side environment.
|
|
271
|
+
*/ // eslint-disable-next-line no-restricted-globals
|
|
272
|
+
const isServerSideRendering = ()=>typeof window === 'undefined';
|
|
273
|
+
|
|
269
274
|
const createDeferredPromise = ()=>{
|
|
270
275
|
let resolve;
|
|
271
276
|
let reject;
|
|
@@ -329,10 +334,26 @@ const createDeferredPromise = ()=>{
|
|
|
329
334
|
|
|
330
335
|
const createEventEmitter = ()=>new EventEmitter();
|
|
331
336
|
|
|
337
|
+
class UnavailableInServerSideError extends getClient.BaseError {
|
|
338
|
+
constructor(unavailableFeature){
|
|
339
|
+
super({
|
|
340
|
+
cause: null,
|
|
341
|
+
docsUrl: null,
|
|
342
|
+
name: 'UnavailableInServerSideError',
|
|
343
|
+
shortMessage: `This function is not available in server-side rendering: ${unavailableFeature}`
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
332
348
|
/**
|
|
333
349
|
* Creates a fetch instance that uses the native window.fetch API.
|
|
334
|
-
*/
|
|
335
|
-
|
|
350
|
+
*/ const createWebFetch = ()=>{
|
|
351
|
+
if (isServerSideRendering()) {
|
|
352
|
+
return ()=>Promise.reject(new UnavailableInServerSideError('createWebFetch'));
|
|
353
|
+
}
|
|
354
|
+
// eslint-disable-next-line no-restricted-globals -- this is the abstraction for fetch
|
|
355
|
+
return window.fetch;
|
|
356
|
+
};
|
|
336
357
|
|
|
337
358
|
/**
|
|
338
359
|
* Log levels and their corresponding numeric values
|
|
@@ -380,6 +401,9 @@ const defaultConsole = console;
|
|
|
380
401
|
/**
|
|
381
402
|
* Creates a deeplink opener that uses the native window.open API.
|
|
382
403
|
*/ const createWebDeeplinkOpener = ()=>{
|
|
404
|
+
if (isServerSideRendering()) {
|
|
405
|
+
return ()=>Promise.reject(new UnavailableInServerSideError('createWebDeeplinkOpener'));
|
|
406
|
+
}
|
|
383
407
|
return async (url)=>{
|
|
384
408
|
// eslint-disable-next-line no-restricted-globals -- this is the abstraction for opening a deeplink
|
|
385
409
|
window.open(url, '_blank');
|
|
@@ -524,7 +548,17 @@ const createObservableState = (getInitialState)=>{
|
|
|
524
548
|
};
|
|
525
549
|
};
|
|
526
550
|
|
|
527
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Creates a new DynamicClient instance.
|
|
553
|
+
*
|
|
554
|
+
* Notice the `autoInitialize` flag is true by default (unless you're running
|
|
555
|
+
* in SSR), so the client will be automatically initialized when created — if
|
|
556
|
+
* you want to manually initialize the client, you can set the `autoInitialize`
|
|
557
|
+
* flag to false and then later call the `initializeClient` function.
|
|
558
|
+
*
|
|
559
|
+
* Manually calling `initializeClient` also allows you to catch any potential
|
|
560
|
+
* errors that may occur during initialization.
|
|
561
|
+
*/ const createDynamicClient = (config)=>{
|
|
528
562
|
const core = createCore(config);
|
|
529
563
|
const client = {
|
|
530
564
|
get __core () {
|
|
@@ -544,8 +578,8 @@ const createDynamicClient = (config)=>{
|
|
|
544
578
|
}
|
|
545
579
|
};
|
|
546
580
|
var _config_autoInitialize;
|
|
547
|
-
const
|
|
548
|
-
if (
|
|
581
|
+
const shouldAutoInitialize = (_config_autoInitialize = config.autoInitialize) != null ? _config_autoInitialize : !isServerSideRendering();
|
|
582
|
+
if (shouldAutoInitialize) {
|
|
549
583
|
void initializeClient(client);
|
|
550
584
|
}
|
|
551
585
|
return client;
|
package/index.esm.js
CHANGED
|
@@ -265,6 +265,11 @@ class ClientAlreadyInitializedError extends BaseError {
|
|
|
265
265
|
}
|
|
266
266
|
};
|
|
267
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Indicates if the code is running in a server-side environment.
|
|
270
|
+
*/ // eslint-disable-next-line no-restricted-globals
|
|
271
|
+
const isServerSideRendering = ()=>typeof window === 'undefined';
|
|
272
|
+
|
|
268
273
|
const createDeferredPromise = ()=>{
|
|
269
274
|
let resolve;
|
|
270
275
|
let reject;
|
|
@@ -328,10 +333,26 @@ const createDeferredPromise = ()=>{
|
|
|
328
333
|
|
|
329
334
|
const createEventEmitter = ()=>new EventEmitter$1();
|
|
330
335
|
|
|
336
|
+
class UnavailableInServerSideError extends BaseError {
|
|
337
|
+
constructor(unavailableFeature){
|
|
338
|
+
super({
|
|
339
|
+
cause: null,
|
|
340
|
+
docsUrl: null,
|
|
341
|
+
name: 'UnavailableInServerSideError',
|
|
342
|
+
shortMessage: `This function is not available in server-side rendering: ${unavailableFeature}`
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
331
347
|
/**
|
|
332
348
|
* Creates a fetch instance that uses the native window.fetch API.
|
|
333
|
-
*/
|
|
334
|
-
|
|
349
|
+
*/ const createWebFetch = ()=>{
|
|
350
|
+
if (isServerSideRendering()) {
|
|
351
|
+
return ()=>Promise.reject(new UnavailableInServerSideError('createWebFetch'));
|
|
352
|
+
}
|
|
353
|
+
// eslint-disable-next-line no-restricted-globals -- this is the abstraction for fetch
|
|
354
|
+
return window.fetch;
|
|
355
|
+
};
|
|
335
356
|
|
|
336
357
|
/**
|
|
337
358
|
* Log levels and their corresponding numeric values
|
|
@@ -379,6 +400,9 @@ const defaultConsole = console;
|
|
|
379
400
|
/**
|
|
380
401
|
* Creates a deeplink opener that uses the native window.open API.
|
|
381
402
|
*/ const createWebDeeplinkOpener = ()=>{
|
|
403
|
+
if (isServerSideRendering()) {
|
|
404
|
+
return ()=>Promise.reject(new UnavailableInServerSideError('createWebDeeplinkOpener'));
|
|
405
|
+
}
|
|
382
406
|
return async (url)=>{
|
|
383
407
|
// eslint-disable-next-line no-restricted-globals -- this is the abstraction for opening a deeplink
|
|
384
408
|
window.open(url, '_blank');
|
|
@@ -523,7 +547,17 @@ const createObservableState = (getInitialState)=>{
|
|
|
523
547
|
};
|
|
524
548
|
};
|
|
525
549
|
|
|
526
|
-
|
|
550
|
+
/**
|
|
551
|
+
* Creates a new DynamicClient instance.
|
|
552
|
+
*
|
|
553
|
+
* Notice the `autoInitialize` flag is true by default (unless you're running
|
|
554
|
+
* in SSR), so the client will be automatically initialized when created — if
|
|
555
|
+
* you want to manually initialize the client, you can set the `autoInitialize`
|
|
556
|
+
* flag to false and then later call the `initializeClient` function.
|
|
557
|
+
*
|
|
558
|
+
* Manually calling `initializeClient` also allows you to catch any potential
|
|
559
|
+
* errors that may occur during initialization.
|
|
560
|
+
*/ const createDynamicClient = (config)=>{
|
|
527
561
|
const core = createCore(config);
|
|
528
562
|
const client = {
|
|
529
563
|
get __core () {
|
|
@@ -543,8 +577,8 @@ const createDynamicClient = (config)=>{
|
|
|
543
577
|
}
|
|
544
578
|
};
|
|
545
579
|
var _config_autoInitialize;
|
|
546
|
-
const
|
|
547
|
-
if (
|
|
580
|
+
const shouldAutoInitialize = (_config_autoInitialize = config.autoInitialize) != null ? _config_autoInitialize : !isServerSideRendering();
|
|
581
|
+
if (shouldAutoInitialize) {
|
|
548
582
|
void initializeClient(client);
|
|
549
583
|
}
|
|
550
584
|
return client;
|
package/package.json
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import type { DynamicClient, DynamicClientConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new DynamicClient instance.
|
|
4
|
+
*
|
|
5
|
+
* Notice the `autoInitialize` flag is true by default (unless you're running
|
|
6
|
+
* in SSR), so the client will be automatically initialized when created — if
|
|
7
|
+
* you want to manually initialize the client, you can set the `autoInitialize`
|
|
8
|
+
* flag to false and then later call the `initializeClient` function.
|
|
9
|
+
*
|
|
10
|
+
* Manually calling `initializeClient` also allows you to catch any potential
|
|
11
|
+
* errors that may occur during initialization.
|
|
12
|
+
*/
|
|
2
13
|
export declare const createDynamicClient: (config: DynamicClientConfig) => DynamicClient;
|
|
3
14
|
//# sourceMappingURL=createDynamicClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDynamicClient.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/client/createDynamicClient/createDynamicClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createDynamicClient.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/client/createDynamicClient/createDynamicClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEnE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,WACtB,mBAAmB,KAC1B,aA6BF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnavailableInServerSideError.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/errors/UnavailableInServerSideError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,qBAAa,4BAA6B,SAAQ,SAAS;gBAC7C,kBAAkB,EAAE,MAAM;CAQvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createWebFetch.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/services/fetch/createWebFetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createWebFetch.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/services/fetch/createWebFetch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,cAAc,QAAO,KAQjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createWebDeeplinkOpener.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/services/openDeeplink/createWebDeeplinkOpener/createWebDeeplinkOpener.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createWebDeeplinkOpener.d.ts","sourceRoot":"","sources":["../../../../../../../packages/client/src/services/openDeeplink/createWebDeeplinkOpener/createWebDeeplinkOpener.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAAO,YAY1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/utils/isServerSideRendering/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isServerSideRendering.d.ts","sourceRoot":"","sources":["../../../../../../packages/client/src/utils/isServerSideRendering/isServerSideRendering.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,qBAAqB,eAAsC,CAAC"}
|