@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 CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.0.1-alpha.5 (2025-06-04)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - support server side rendering ([#92](https://github.com/dynamic-labs/dynamic-sdk/pull/92))
6
+
1
7
  ## 0.0.1-alpha.4 (2025-05-28)
2
8
 
3
9
  ### 🚀 Features
package/getClient.cjs.js CHANGED
@@ -68,7 +68,7 @@ function _extends() {
68
68
  return _extends.apply(this, arguments);
69
69
  }
70
70
 
71
- var version = "0.0.1-alpha.4";
71
+ var version = "0.0.1-alpha.5";
72
72
  var dependencies = {
73
73
  "@dynamic-labs/sdk-api-core": "0.0.630"};
74
74
 
package/getClient.esm.js CHANGED
@@ -66,7 +66,7 @@ function _extends() {
66
66
  return _extends.apply(this, arguments);
67
67
  }
68
68
 
69
- var version = "0.0.1-alpha.4";
69
+ var version = "0.0.1-alpha.5";
70
70
  var dependencies = {
71
71
  "@dynamic-labs/sdk-api-core": "0.0.630"};
72
72
 
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
- */ // eslint-disable-next-line no-restricted-globals -- this is the abstraction for fetch
335
- const createWebFetch = ()=>window.fetch;
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
- const createDynamicClient = (config)=>{
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 autoInitialize = (_config_autoInitialize = config.autoInitialize) != null ? _config_autoInitialize : true;
548
- if (autoInitialize) {
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
- */ // eslint-disable-next-line no-restricted-globals -- this is the abstraction for fetch
334
- const createWebFetch = ()=>window.fetch;
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
- const createDynamicClient = (config)=>{
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 autoInitialize = (_config_autoInitialize = config.autoInitialize) != null ? _config_autoInitialize : true;
547
- if (autoInitialize) {
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs-sdk/client",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.1-alpha.5",
4
4
  "type": "module",
5
5
  "main": "./index.esm.js",
6
6
  "module": "./index.esm.js",
@@ -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":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEnE,eAAO,MAAM,mBAAmB,WACtB,mBAAmB,KAC1B,aA4BF,CAAC"}
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,5 @@
1
+ import { BaseError } from './base/BaseError';
2
+ export declare class UnavailableInServerSideError extends BaseError {
3
+ constructor(unavailableFeature: string);
4
+ }
5
+ //# sourceMappingURL=UnavailableInServerSideError.d.ts.map
@@ -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":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC;;GAEG;AAEH,eAAO,MAAM,cAAc,QAAO,KAAqB,CAAC"}
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":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAAO,YAK1C,CAAC"}
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,2 @@
1
+ export { isServerSideRendering } from './isServerSideRendering';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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,5 @@
1
+ /**
2
+ * Indicates if the code is running in a server-side environment.
3
+ */
4
+ export declare const isServerSideRendering: () => boolean;
5
+ //# sourceMappingURL=isServerSideRendering.d.ts.map
@@ -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"}