@zeniai/client-epic-state 5.0.31-betaML2 → 5.0.31-betaML3

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/lib/esm/init.js CHANGED
@@ -1,4 +1,3 @@
1
- import Pusher from 'pusher-js/with-encryption';
2
1
  import configureNewStore from './configureStore';
3
2
  import { ZeniAPIClient } from './zeniAPI';
4
3
  export let zeniAPI;
@@ -28,6 +27,14 @@ let isPusherInitialized = false;
28
27
  * Call initializePusher before using pusher in web-app
29
28
  */
30
29
  export function initializePusher(pusherClientSecret, options, headers, reInitialize = false) {
30
+ // Pusher subscribes/decrypts only make sense in the browser. `pusher-js/
31
+ // with-encryption` resolves to a browser-only bundle that references
32
+ // `window` at module init, so even *requiring* it on the server crashes.
33
+ // Bail out early on SSR/Node so loading this module never triggers that.
34
+ if (typeof window === 'undefined') {
35
+ console.warn(`initializePusher called on server-side; pusher-js/with-encryption is browser-only — skipping.`);
36
+ return undefined;
37
+ }
31
38
  if (Boolean(zeniAPI.userId) === false ||
32
39
  Boolean(zeniAPI.tenantId) === false ||
33
40
  !initialized) {
@@ -38,8 +45,16 @@ export function initializePusher(pusherClientSecret, options, headers, reInitial
38
45
  console.warn(`Already initialized pusher`);
39
46
  return pusher;
40
47
  }
48
+ // Lazy-require so the browser-only bundle is loaded only when this function
49
+ // actually runs (browser path). The pusher-js UMD wrapper does
50
+ // `module.exports = factory()` for CJS, so the require result is the
51
+ // Pusher class directly. Some bundlers wrap CJS in `{ default: ... }` for
52
+ // ESM interop — fall back to the module itself when `.default` is absent.
53
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
54
+ const pusherModule = require('pusher-js/with-encryption');
55
+ const PusherConstructor = 'default' in pusherModule ? pusherModule.default : pusherModule;
41
56
  const endpoint = `${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/notifications/push_notification/auth`;
42
- pusher = new Pusher(pusherClientSecret, {
57
+ pusher = new PusherConstructor(pusherClientSecret, {
43
58
  ...options,
44
59
  channelAuthorization: {
45
60
  endpoint,
package/lib/init.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import Pusher, { Options } from 'pusher-js/with-encryption';
1
+ import type Pusher from 'pusher-js/with-encryption';
2
+ import type { Options } from 'pusher-js/with-encryption';
2
3
  import { Store } from 'redux';
3
4
  import { ID } from './commonStateTypes/common';
4
5
  import { RootState } from './reducer';
@@ -6,7 +7,7 @@ import { RESTAPIEndpoints, ZeniAPI } from './zeniAPI';
6
7
  export type ZeniStore = Store<RootState>;
7
8
  export declare let zeniAPI: ZeniAPI;
8
9
  export declare let store: ZeniStore;
9
- declare let pusher: Pusher;
10
+ declare let pusher: Pusher | undefined;
10
11
  /**
11
12
  * Call initialize before using any of the functionalities in this module
12
13
  * Note: This version SHOULD BE used only in the client side. Not intended to be used
package/lib/init.js CHANGED
@@ -44,7 +44,6 @@ exports.updateZeniAPIClientConfig = updateZeniAPIClientConfig;
44
44
  exports.zeniAPIClientConfig = zeniAPIClientConfig;
45
45
  exports.initializeWithNewStore = initializeWithNewStore;
46
46
  exports.initialize3rdPartyExtensions = initialize3rdPartyExtensions;
47
- const with_encryption_1 = __importDefault(require("pusher-js/with-encryption"));
48
47
  const configureStore_1 = __importDefault(require("./configureStore"));
49
48
  const zeniAPI_1 = require("./zeniAPI");
50
49
  let pusher;
@@ -72,6 +71,14 @@ let isPusherInitialized = false;
72
71
  * Call initializePusher before using pusher in web-app
73
72
  */
74
73
  function initializePusher(pusherClientSecret, options, headers, reInitialize = false) {
74
+ // Pusher subscribes/decrypts only make sense in the browser. `pusher-js/
75
+ // with-encryption` resolves to a browser-only bundle that references
76
+ // `window` at module init, so even *requiring* it on the server crashes.
77
+ // Bail out early on SSR/Node so loading this module never triggers that.
78
+ if (typeof window === 'undefined') {
79
+ console.warn(`initializePusher called on server-side; pusher-js/with-encryption is browser-only — skipping.`);
80
+ return undefined;
81
+ }
75
82
  if (Boolean(exports.zeniAPI.userId) === false ||
76
83
  Boolean(exports.zeniAPI.tenantId) === false ||
77
84
  !initialized) {
@@ -82,8 +89,16 @@ function initializePusher(pusherClientSecret, options, headers, reInitialize = f
82
89
  console.warn(`Already initialized pusher`);
83
90
  return pusher;
84
91
  }
92
+ // Lazy-require so the browser-only bundle is loaded only when this function
93
+ // actually runs (browser path). The pusher-js UMD wrapper does
94
+ // `module.exports = factory()` for CJS, so the require result is the
95
+ // Pusher class directly. Some bundlers wrap CJS in `{ default: ... }` for
96
+ // ESM interop — fall back to the module itself when `.default` is absent.
97
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
98
+ const pusherModule = require('pusher-js/with-encryption');
99
+ const PusherConstructor = 'default' in pusherModule ? pusherModule.default : pusherModule;
85
100
  const endpoint = `${exports.zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/notifications/push_notification/auth`;
86
- exports.pusher = pusher = new with_encryption_1.default(pusherClientSecret, {
101
+ exports.pusher = pusher = new PusherConstructor(pusherClientSecret, {
87
102
  ...options,
88
103
  channelAuthorization: {
89
104
  endpoint,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.31-betaML2",
3
+ "version": "5.0.31-betaML3",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",