@zeniai/client-epic-state 5.0.32-betaRD3 → 5.0.33-betaRR0
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 +20 -3
- package/lib/init.d.ts +4 -3
- package/lib/init.js +20 -3
- package/package.json +1 -1
- package/lib/tsconfig.typecheck.tsbuildinfo +0 -1
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;
|
|
@@ -27,7 +26,15 @@ let isPusherInitialized = false;
|
|
|
27
26
|
/**
|
|
28
27
|
* Call initializePusher before using pusher in web-app
|
|
29
28
|
*/
|
|
30
|
-
export function initializePusher(pusherClientSecret, options, headers, reInitialize = false) {
|
|
29
|
+
export async 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 *importing* it on the server crashes.
|
|
33
|
+
// Bail out early on SSR/Node so the dynamic import below never executes.
|
|
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,18 @@ export function initializePusher(pusherClientSecret, options, headers, reInitial
|
|
|
38
45
|
console.warn(`Already initialized pusher`);
|
|
39
46
|
return pusher;
|
|
40
47
|
}
|
|
48
|
+
// Dynamic import so the browser-only bundle is loaded only when this
|
|
49
|
+
// function actually runs (browser path). Works in both build outputs:
|
|
50
|
+
// • ESM (lib/esm): preserved as native `import()` → Vite/Rollup code-split
|
|
51
|
+
// • CJS (lib): TypeScript lowers to `Promise.resolve().then(() => require(...))`
|
|
52
|
+
// The pusher-js UMD wrapper does `module.exports = factory()` for CJS, so
|
|
53
|
+
// the module result is the Pusher class directly. Some bundlers wrap CJS in
|
|
54
|
+
// `{ default: ... }` for ESM interop — fall back to the module itself when
|
|
55
|
+
// `.default` is absent.
|
|
56
|
+
const pusherModule = (await import('pusher-js/with-encryption'));
|
|
57
|
+
const PusherConstructor = 'default' in pusherModule ? pusherModule.default : pusherModule;
|
|
41
58
|
const endpoint = `${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/notifications/push_notification/auth`;
|
|
42
|
-
pusher = new
|
|
59
|
+
pusher = new PusherConstructor(pusherClientSecret, {
|
|
43
60
|
...options,
|
|
44
61
|
channelAuthorization: {
|
|
45
62
|
endpoint,
|
package/lib/init.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import Pusher
|
|
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
|
|
@@ -25,7 +26,7 @@ export declare function initializePusher(pusherClientSecret: ID, options: Option
|
|
|
25
26
|
sessionId: ID;
|
|
26
27
|
tenantId: ID;
|
|
27
28
|
userId: ID;
|
|
28
|
-
}, reInitialize?: boolean): Pusher | undefined
|
|
29
|
+
}, reInitialize?: boolean): Promise<Pusher | undefined>;
|
|
29
30
|
export declare function disconnectPusher(): void;
|
|
30
31
|
export { pusher };
|
|
31
32
|
export { injectFeatureModules, injectFeatureEpics } from './configureStore';
|
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;
|
|
@@ -71,7 +70,15 @@ let isPusherInitialized = false;
|
|
|
71
70
|
/**
|
|
72
71
|
* Call initializePusher before using pusher in web-app
|
|
73
72
|
*/
|
|
74
|
-
function initializePusher(pusherClientSecret, options, headers, reInitialize = false) {
|
|
73
|
+
async 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 *importing* it on the server crashes.
|
|
77
|
+
// Bail out early on SSR/Node so the dynamic import below never executes.
|
|
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,18 @@ function initializePusher(pusherClientSecret, options, headers, reInitialize = f
|
|
|
82
89
|
console.warn(`Already initialized pusher`);
|
|
83
90
|
return pusher;
|
|
84
91
|
}
|
|
92
|
+
// Dynamic import so the browser-only bundle is loaded only when this
|
|
93
|
+
// function actually runs (browser path). Works in both build outputs:
|
|
94
|
+
// • ESM (lib/esm): preserved as native `import()` → Vite/Rollup code-split
|
|
95
|
+
// • CJS (lib): TypeScript lowers to `Promise.resolve().then(() => require(...))`
|
|
96
|
+
// The pusher-js UMD wrapper does `module.exports = factory()` for CJS, so
|
|
97
|
+
// the module result is the Pusher class directly. Some bundlers wrap CJS in
|
|
98
|
+
// `{ default: ... }` for ESM interop — fall back to the module itself when
|
|
99
|
+
// `.default` is absent.
|
|
100
|
+
const pusherModule = (await Promise.resolve().then(() => __importStar(require('pusher-js/with-encryption'))));
|
|
101
|
+
const PusherConstructor = 'default' in pusherModule ? pusherModule.default : pusherModule;
|
|
85
102
|
const endpoint = `${exports.zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/notifications/push_notification/auth`;
|
|
86
|
-
exports.pusher = pusher = new
|
|
103
|
+
exports.pusher = pusher = new PusherConstructor(pusherClientSecret, {
|
|
87
104
|
...options,
|
|
88
105
|
channelAuthorization: {
|
|
89
106
|
endpoint,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.33-betaRR0",
|
|
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",
|