@salesforce/emp-api 12.6.2 → 12.6.3-canary.999.2.1.gd0b2ab15
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/README.md +10 -0
- package/dist/api.d.ts +65 -43
- package/dist/api.d.ts.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +240 -214
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -61,6 +61,16 @@ removeListener();
|
|
|
61
61
|
- **`onError(callback)`** — Registers a listener for engine-level errors.
|
|
62
62
|
Per-channel and later transport failures surface here, not through the
|
|
63
63
|
`subscribe()` promise. Returns a function that removes this listener.
|
|
64
|
+
- **`isEmpEnabled()`** — Resolves `true` if this browsing context has
|
|
65
|
+
`Worker` support, `false` if it doesn't. Resolves `false`, never rejects,
|
|
66
|
+
if the streaming config can't be fetched for any reason.
|
|
67
|
+
- **`setDebugFlag(flag)`** — Passes `flag` through to the underlying engine
|
|
68
|
+
to enable/disable console diagnostics. **Inherited quirk:** if
|
|
69
|
+
`localStorage['emp.debugFlag']` was already `"true"` when the page
|
|
70
|
+
loaded, this becomes a no-op for the rest of that page session — even
|
|
71
|
+
`setDebugFlag(false)` won't turn it off until the page is reloaded with
|
|
72
|
+
that key cleared or changed. This call still best-effort writes `flag` to
|
|
73
|
+
that same `localStorage` key, so a future page load picks it up.
|
|
64
74
|
|
|
65
75
|
Messages delivered to `onMessage` are one of two shapes — a Platform Event
|
|
66
76
|
message, or a Change Data Capture message whose payload carries a
|
package/dist/api.d.ts
CHANGED
|
@@ -4,66 +4,88 @@ import { EmpSubscriptionHandle } from './vendor/emp.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Subscribes to a Platform Event or CDC channel.
|
|
6
6
|
*
|
|
7
|
-
* The returned Promise waits only on the one-time config fetch + engine
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* never through this Promise, and never after it has already resolved.
|
|
7
|
+
* The returned Promise waits only on the one-time config fetch + engine init,
|
|
8
|
+
* never on a `/meta/subscribe` ack: it resolves right after `Emp.init()` and
|
|
9
|
+
* the engine's synchronous `subscribe()`. It rejects only if config/init can't
|
|
10
|
+
* be obtained; per-channel and later transport failures surface through
|
|
11
|
+
* {@link onError} only, never through this Promise and never after it resolves.
|
|
13
12
|
*
|
|
14
|
-
* `channel`
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* `channel`/`replayId` pass through unvalidated; two calls on the same channel
|
|
14
|
+
* are independent handles. A failed ack (`successful !== true`) is routed to
|
|
15
|
+
* `onError` via this call's own `subscribeCallback` (not just the engine
|
|
16
|
+
* broadcast), so it survives an immediate empty-subscriptions teardown (see
|
|
17
|
+
* `dispatchError`).
|
|
17
18
|
*
|
|
18
|
-
* @param channel - A Platform Event or CDC channel
|
|
19
|
-
* @param replayId - `-1`
|
|
20
|
-
* retention window, or a numeric replay id.
|
|
19
|
+
* @param channel - A Platform Event or CDC channel, e.g. `/event/Foo__e`.
|
|
20
|
+
* @param replayId - `-1` (tip), `-2` (retention window), or a numeric replay id.
|
|
21
21
|
* @param onMessage - Invoked with each delivered message.
|
|
22
|
-
* @param getConfig - Injectable config seam
|
|
23
|
-
*
|
|
24
|
-
* part of the public interface — the barrel's exported `subscribe` omits
|
|
25
|
-
* this parameter.
|
|
26
|
-
*
|
|
27
|
-
* A failed subscribe ack (`successful !== true`) is also routed to
|
|
28
|
-
* `onError`'s listeners via this call's own `subscribeCallback`, not just
|
|
29
|
-
* the engine's broadcast — the ack is delivered before the engine's
|
|
30
|
-
* empty-subscriptions disconnect check runs, so it survives even when the
|
|
31
|
-
* connection is torn down immediately after (see `dispatchError`).
|
|
22
|
+
* @param getConfig - Injectable config seam (defaults to {@link getStreamingConfig});
|
|
23
|
+
* tests substitute a fake. Not part of the public `subscribe`.
|
|
32
24
|
*/
|
|
33
25
|
export declare function subscribe(channel: string, replayId: number, onMessage: (message: StreamingMessage) => void, getConfig?: GetStreamingConfig): Promise<Subscription>;
|
|
34
26
|
/**
|
|
35
|
-
* Unsubscribes a handle returned by {@link subscribe}.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
27
|
+
* Unsubscribes a handle returned by {@link subscribe}. Synchronous, returns
|
|
28
|
+
* nothing, and a silent no-op on an already-unsubscribed handle — v1 has no
|
|
29
|
+
* completion callback (the engine's unsubscribe callback is not a reliable
|
|
30
|
+
* per-handle ack).
|
|
39
31
|
*
|
|
40
32
|
* @param subscription - The handle returned by {@link subscribe}.
|
|
41
33
|
*/
|
|
42
34
|
export declare function unsubscribe(subscription: Subscription | EmpSubscriptionHandle): void;
|
|
43
35
|
/**
|
|
44
|
-
* Registers an error listener. Errors
|
|
45
|
-
*
|
|
46
|
-
* failure is a caller concern, not this package's.
|
|
36
|
+
* Registers an error listener. Errors pass through unfiltered — classifying
|
|
37
|
+
* transient blips vs. terminal failure is a caller concern.
|
|
47
38
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* so registering the exact same function reference more than once still
|
|
53
|
-
* gives each call its own removable registration — removing one doesn't
|
|
54
|
-
* touch another registration that happens to wrap the same callback.
|
|
39
|
+
* Each call wraps `callback` in a fresh closure, so the same function reference
|
|
40
|
+
* can be registered (and removed) more than once independently; the returned
|
|
41
|
+
* function splices out this one registration (the engine has no per-listener
|
|
42
|
+
* removal).
|
|
55
43
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* can still fire after `clearState()` — that is existing engine behavior,
|
|
60
|
-
* not something this package fixes.
|
|
44
|
+
* Inherited caveat: `clearState()` unsubscribes every active sub but does not
|
|
45
|
+
* clear this package's bookkeeping the way `unsubscribe()` does, so a message
|
|
46
|
+
* can still fire afterward — existing engine behavior, not fixed here.
|
|
61
47
|
*
|
|
62
48
|
* @param callback - Invoked with the engine's error/reply message.
|
|
63
|
-
* @returns A function that removes this listener
|
|
64
|
-
* is a no-op.
|
|
49
|
+
* @returns A function that removes this listener; calling it again is a no-op.
|
|
65
50
|
*/
|
|
66
51
|
export declare function onError(callback: (message: EmpErrorMessage) => void): () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Resolves whether this context can run the streaming engine — the inherited
|
|
54
|
+
* LEX capability check, not "SharedWorker join achieved".
|
|
55
|
+
*
|
|
56
|
+
* Two cheap checks resolve `false` **before** any config fetch, since the
|
|
57
|
+
* answer can't depend on config: the native-mobile container (`window.__nimbus`)
|
|
58
|
+
* and no `Worker` in scope (e.g. Node/SSR) — the engine's SharedWorker →
|
|
59
|
+
* leader-election → standalone cascade all need `Worker`, so that one check
|
|
60
|
+
* covers it.
|
|
61
|
+
*
|
|
62
|
+
* Otherwise it awaits the same coalesced `ensureInit` as `subscribe()`. Not a
|
|
63
|
+
* side-effect-free probe: `ensureInit` runs `Emp.init`, so on success the mode
|
|
64
|
+
* picker constructs the SharedWorker (or starts leader election) just as a real
|
|
65
|
+
* `subscribe()` would. Any config failure resolves `false` (not reject), and —
|
|
66
|
+
* like `subscribe()` — a terminal refusal keeps resolving `false` without
|
|
67
|
+
* refetching.
|
|
68
|
+
*
|
|
69
|
+
* @param getConfig - Injectable config seam (defaults to {@link getStreamingConfig});
|
|
70
|
+
* tests substitute a fake. Not part of the public `isEmpEnabled`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function isEmpEnabled(getConfig?: GetStreamingConfig): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Passes `flag` through to the vendored engine's `Emp.setDebugFlag`.
|
|
75
|
+
*
|
|
76
|
+
* **Inherited LEX latch:** the engine reads `localStorage['emp.debugFlag']`
|
|
77
|
+
* once at module load into a `const`. If it was `"true"` then, `setDebugFlag`
|
|
78
|
+
* is a permanent no-op for that page — passing `false` won't turn diagnostics
|
|
79
|
+
* off until the key is cleared and the page reloads. Engine behavior, not
|
|
80
|
+
* fixable without editing the vendored file.
|
|
81
|
+
*
|
|
82
|
+
* To persist intent forward, this also best-effort writes `flag` to
|
|
83
|
+
* `localStorage[DEBUG_FLAG_KEY]` (swallowing any failure), so a future page
|
|
84
|
+
* load re-latches from the most recent call.
|
|
85
|
+
*
|
|
86
|
+
* @param flag - true or false.
|
|
87
|
+
*/
|
|
88
|
+
export declare function setDebugFlag(flag: boolean): void;
|
|
67
89
|
/**
|
|
68
90
|
* Test-only escape hatch to reset the module-level init guard between test
|
|
69
91
|
* cases. Not part of the public barrel.
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAO,KAAK,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAO,KAAK,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAgJlE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,SAAS,CAC9B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,EAC9C,SAAS,GAAE,kBAAuC,GAChD,OAAO,CAAC,YAAY,CAAC,CAsBvB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,YAAY,GAAG,qBAAqB,GAAG,IAAI,CAEpF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,GAAG,MAAM,IAAI,CAUhF;AAYD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,YAAY,CACjC,SAAS,GAAE,kBAAuC,GAChD,OAAO,CAAC,OAAO,CAAC,CAclB;AASD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAOhD;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAK9C"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StreamingMessage, Subscription } from './types';
|
|
2
|
-
export { unsubscribe, onError } from './api';
|
|
2
|
+
export { unsubscribe, onError, setDebugFlag } from './api';
|
|
3
3
|
export { isChangeDataCaptureMessage } from './types';
|
|
4
4
|
export type { BayeuxFailure, ChangeDataCaptureMessage, ChangeEventHeader, EmpErrorMessage, PlatformEventMessage, StreamingConfig, StreamingMessage, Subscription, } from './types';
|
|
5
5
|
/**
|
|
@@ -9,4 +9,11 @@ export type { BayeuxFailure, ChangeDataCaptureMessage, ChangeEventHeader, EmpErr
|
|
|
9
9
|
* public interface.
|
|
10
10
|
*/
|
|
11
11
|
export declare function subscribe(channel: string, replayId: number, onMessage: (message: StreamingMessage) => void): Promise<Subscription>;
|
|
12
|
+
/**
|
|
13
|
+
* Resolves whether this browsing context can run the streaming engine at
|
|
14
|
+
* all. See {@link isEmpEnabledInternal} for full behavior. The config seam
|
|
15
|
+
* is an internal implementation detail used by tests — not part of the
|
|
16
|
+
* public interface.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isEmpEnabled(): Promise<boolean>;
|
|
12
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAeH,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AACrD,YAAY,EACX,aAAa,EACb,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,YAAY,GACZ,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,wBAAsB,SAAS,CAC9B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,GAC5C,OAAO,CAAC,YAAY,CAAC,CAEvB;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,CAErD"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { gql as
|
|
2
|
-
const
|
|
1
|
+
import { gql as Ke, createDataSDK as Be } from "@salesforce/platform-sdk";
|
|
2
|
+
const Ve = Ke`
|
|
3
3
|
query GetStreamingConfig {
|
|
4
4
|
uiapi {
|
|
5
5
|
platform {
|
|
@@ -11,12 +11,12 @@ const Ke = je`
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
`;
|
|
14
|
-
async function
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
14
|
+
async function ue() {
|
|
15
|
+
const n = await Be();
|
|
16
|
+
if (!n.graphql)
|
|
17
17
|
throw new Error("@salesforce/emp-api: GraphQL is not supported on this surface");
|
|
18
|
-
const a = await
|
|
19
|
-
query:
|
|
18
|
+
const a = await n.graphql.query({
|
|
19
|
+
query: Ve
|
|
20
20
|
}), l = a.data?.uiapi?.platform?.streamingConfig, d = l?.cometdUrl, b = l?.cometdWorkerJs;
|
|
21
21
|
if (a.errors?.length || !d || !b)
|
|
22
22
|
throw new Error(
|
|
@@ -24,124 +24,124 @@ async function Be() {
|
|
|
24
24
|
);
|
|
25
25
|
return { cometdUrl: d, cometdWorkerJs: b };
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const l = "emp.leaderElection", d = "emp.heartbeat", b = ["FOLLOWER", "CANDIDATE", "LEADER"], E = Date.now() + "_" +
|
|
29
|
-
let u = b[0], p = !1, s = 0, g = !1, f = null,
|
|
27
|
+
function Ye(n, a) {
|
|
28
|
+
const l = "emp.leaderElection", d = "emp.heartbeat", b = ["FOLLOWER", "CANDIDATE", "LEADER"], E = Date.now() + "_" + C(1, 1e4), y = 4e3, T = 6e3, _ = 3e3, S = 4e3;
|
|
29
|
+
let u = b[0], p = !1, s = 0, g = !1, f = null, w, L, O = !1;
|
|
30
30
|
const D = {};
|
|
31
31
|
D.heartBeat = () => {
|
|
32
|
-
const
|
|
33
|
-
return
|
|
32
|
+
const o = {};
|
|
33
|
+
return o.eventType = "heartbeat", o.leader = {
|
|
34
34
|
id: E,
|
|
35
35
|
candidateTime: f
|
|
36
|
-
},
|
|
36
|
+
}, o;
|
|
37
37
|
}, D.election = () => {
|
|
38
|
-
const
|
|
39
|
-
return
|
|
40
|
-
}, D.vote = (
|
|
38
|
+
const o = {};
|
|
39
|
+
return o.eventType = "election", o.candidateId = E, o.candidateTime = f, o;
|
|
40
|
+
}, D.vote = (o) => {
|
|
41
41
|
const i = {};
|
|
42
|
-
return i.eventType = "vote", i.candidateId =
|
|
42
|
+
return i.eventType = "vote", i.candidateId = o, i;
|
|
43
43
|
};
|
|
44
|
-
function h(...
|
|
45
|
-
O && window.console.log(...
|
|
44
|
+
function h(...o) {
|
|
45
|
+
O && window.console.log(...o);
|
|
46
46
|
}
|
|
47
|
-
function c(
|
|
48
|
-
return typeof
|
|
47
|
+
function c(o) {
|
|
48
|
+
return typeof o == "function";
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
return
|
|
50
|
+
function C(o, i) {
|
|
51
|
+
return o = Math.ceil(o), i = Math.floor(i), Math.floor(Math.random() * (i - o + 1)) + o;
|
|
52
52
|
}
|
|
53
|
-
function k(
|
|
54
|
-
|
|
53
|
+
function k(o) {
|
|
54
|
+
G(d, o);
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
56
|
+
function J(o) {
|
|
57
|
+
G(l, o);
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function G(o, i) {
|
|
60
60
|
i.time = Date.now();
|
|
61
|
-
const
|
|
62
|
-
window.localStorage.setItem(
|
|
61
|
+
const Y = JSON.stringify(i);
|
|
62
|
+
window.localStorage.setItem(o, Y);
|
|
63
63
|
}
|
|
64
|
-
function P(
|
|
65
|
-
c(a) && a(
|
|
64
|
+
function P(o) {
|
|
65
|
+
c(a) && a(o);
|
|
66
66
|
}
|
|
67
|
-
function j(
|
|
68
|
-
u === b[2] && f >
|
|
67
|
+
function j(o) {
|
|
68
|
+
u === b[2] && f > o.leader.candidateTime && (u = b[0], clearInterval(w), w = null), L !== o.leader.id && (L = o.leader.id, P({ leaderId: L })), g = !1, s = 0, p = !0;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
70
|
+
function K(o) {
|
|
71
|
+
o.candidateId === E && (s += 1, h("[EmpLe] Vote handler: received votes [" + s + "]"));
|
|
72
72
|
}
|
|
73
|
-
function N(
|
|
74
|
-
return
|
|
73
|
+
function N(o) {
|
|
74
|
+
return o === E;
|
|
75
75
|
}
|
|
76
|
-
function W(
|
|
76
|
+
function W(o) {
|
|
77
77
|
h("[EmpLe] Election handler");
|
|
78
|
-
const i =
|
|
78
|
+
const i = o.candidateId;
|
|
79
79
|
if (N(i)) {
|
|
80
80
|
h(
|
|
81
81
|
"[EmpLe] Event candidateId is same as Node Id. Ignore our own heartbeat message"
|
|
82
82
|
);
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
!
|
|
85
|
+
!B() && o.candidateTime < f && (u = b[0], h(
|
|
86
86
|
"[EmpLe] Election handler: Detected two candidates or leaders, becoming follower."
|
|
87
|
-
)),
|
|
87
|
+
)), A() && B() && (h("[EmpLe] Election handler: voted for [" + i + "]."), J(D.vote(i)), g = !0), p = !0;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function A() {
|
|
90
90
|
return !g;
|
|
91
91
|
}
|
|
92
|
-
function
|
|
92
|
+
function B() {
|
|
93
93
|
return u === b[0];
|
|
94
94
|
}
|
|
95
|
-
function
|
|
95
|
+
function R() {
|
|
96
96
|
window.setTimeout(() => {
|
|
97
|
-
p ? (p = !1,
|
|
98
|
-
},
|
|
97
|
+
p ? (p = !1, R()) : F();
|
|
98
|
+
}, C(y, T));
|
|
99
99
|
}
|
|
100
100
|
function v() {
|
|
101
101
|
window.setTimeout(() => {
|
|
102
102
|
h(
|
|
103
103
|
"[EmpLe] Election Timedout: heartbeat received=" + p
|
|
104
|
-
), p ? (p = !1,
|
|
104
|
+
), p ? (p = !1, R()) : s > 0 && u !== b[0] && (u = b[2], g = !1, h(
|
|
105
105
|
"[EmpLe] Yay I am the leader :" + E + " with [" + s + "] votes."
|
|
106
106
|
), X(), P({ leaderId: E }));
|
|
107
|
-
},
|
|
107
|
+
}, C(S, S));
|
|
108
108
|
}
|
|
109
109
|
function F() {
|
|
110
|
-
u = b[1], s = 0, p ?
|
|
110
|
+
u = b[1], s = 0, p ? R() : (s += 1, g = !0, f = Date.now(), J(D.election()), v());
|
|
111
111
|
}
|
|
112
112
|
function X() {
|
|
113
|
-
|
|
113
|
+
w = window.setInterval(() => {
|
|
114
114
|
k(D.heartBeat());
|
|
115
|
-
},
|
|
115
|
+
}, C(_, _));
|
|
116
116
|
}
|
|
117
117
|
function U() {
|
|
118
|
-
clearInterval(
|
|
118
|
+
clearInterval(w), w = null;
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function V(o) {
|
|
121
121
|
let i;
|
|
122
|
-
|
|
122
|
+
o.newValue && (o.key === l || o.key === d) && (i = JSON.parse(o.newValue)), i && i.eventType && (h("[EmpLe]", i), i.eventType === "heartbeat" && j(i), i.eventType === "vote" && K(i), i.eventType === "election" && W(i));
|
|
123
123
|
}
|
|
124
|
-
function
|
|
125
|
-
c(
|
|
124
|
+
function $() {
|
|
125
|
+
c(n) && n({ nodeId: E }), window.addEventListener("storage", V), R();
|
|
126
126
|
}
|
|
127
|
-
function
|
|
128
|
-
O =
|
|
127
|
+
function z(o) {
|
|
128
|
+
O = o;
|
|
129
129
|
}
|
|
130
130
|
function x() {
|
|
131
131
|
try {
|
|
132
132
|
h("[EmpLe] Stopping heartbeats..."), U(), h("[EmpLe] Successfully stopped heartbeats");
|
|
133
|
-
} catch (
|
|
134
|
-
h("[EmpLe] Failed to stop heartbeats. Reason = " +
|
|
133
|
+
} catch (o) {
|
|
134
|
+
h("[EmpLe] Failed to stop heartbeats. Reason = " + o);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
return {
|
|
138
|
-
start:
|
|
138
|
+
start: $,
|
|
139
139
|
stop: x,
|
|
140
|
-
setDebugFlag:
|
|
140
|
+
setDebugFlag: z
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
-
const
|
|
144
|
-
const
|
|
143
|
+
const H = (() => {
|
|
144
|
+
const n = "org.cometd.reload.fromLocalStorage", a = "emp.cometd", l = "emp.debugFlag", d = G(), b = D(), E = {
|
|
145
145
|
log: () => {
|
|
146
146
|
}
|
|
147
147
|
}, y = {
|
|
@@ -151,7 +151,7 @@ const Q = (() => {
|
|
|
151
151
|
};
|
|
152
152
|
let T, _, S = null;
|
|
153
153
|
const u = {}, p = {};
|
|
154
|
-
let s = null, g = null, f = null,
|
|
154
|
+
let s = null, g = null, f = null, w = null, L = {}, O = b;
|
|
155
155
|
function D() {
|
|
156
156
|
return d ? localStorage.getItem(l) === "true" : !1;
|
|
157
157
|
}
|
|
@@ -161,20 +161,20 @@ const Q = (() => {
|
|
|
161
161
|
function c() {
|
|
162
162
|
return h() ? window.console : E;
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function C(e) {
|
|
165
165
|
return typeof e == "function";
|
|
166
166
|
}
|
|
167
167
|
function k(e, t) {
|
|
168
|
-
Object.entries(e).forEach(([
|
|
169
|
-
t.length === 2 ? t(
|
|
168
|
+
Object.entries(e).forEach(([r, m]) => {
|
|
169
|
+
t.length === 2 ? t(r, m) : t(m);
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
|
-
function
|
|
172
|
+
function J() {
|
|
173
173
|
return !!navigator.userAgent.match(/ipad|iphone|ipod/i);
|
|
174
174
|
}
|
|
175
|
-
function
|
|
175
|
+
function G() {
|
|
176
176
|
try {
|
|
177
|
-
return
|
|
177
|
+
return K("key", { value: "emp.test" }), localStorage.removeItem("key"), !0;
|
|
178
178
|
} catch {
|
|
179
179
|
return !1;
|
|
180
180
|
}
|
|
@@ -186,10 +186,10 @@ const Q = (() => {
|
|
|
186
186
|
let e = "";
|
|
187
187
|
return f && (e = f), e + "_" + Date.now() + "_" + P(1, 1e4);
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function K(e, t) {
|
|
190
190
|
t.time = Date.now();
|
|
191
|
-
const
|
|
192
|
-
window.localStorage.setItem(e,
|
|
191
|
+
const r = JSON.stringify(t);
|
|
192
|
+
window.localStorage.setItem(e, r);
|
|
193
193
|
}
|
|
194
194
|
function N(e) {
|
|
195
195
|
if (!d) {
|
|
@@ -199,27 +199,27 @@ const Q = (() => {
|
|
|
199
199
|
);
|
|
200
200
|
return;
|
|
201
201
|
}
|
|
202
|
-
|
|
202
|
+
K(a, e);
|
|
203
203
|
}
|
|
204
204
|
function W(e) {
|
|
205
205
|
c().log("[Emp] toCometdWorker: ", e);
|
|
206
206
|
let t = s;
|
|
207
207
|
s ? (S === y.SHARED_WORKER && (t = s.port), t.postMessage(e)) : N(e);
|
|
208
208
|
}
|
|
209
|
-
function
|
|
209
|
+
function A(e) {
|
|
210
210
|
return !!u[e.id];
|
|
211
211
|
}
|
|
212
|
-
function
|
|
212
|
+
function B(e) {
|
|
213
213
|
return !!p[e.id];
|
|
214
214
|
}
|
|
215
|
-
function
|
|
215
|
+
function R(e) {
|
|
216
216
|
return !!L[e.id];
|
|
217
217
|
}
|
|
218
218
|
function v() {
|
|
219
|
-
return
|
|
219
|
+
return w === f;
|
|
220
220
|
}
|
|
221
221
|
function F() {
|
|
222
|
-
return !!
|
|
222
|
+
return !!w || s;
|
|
223
223
|
}
|
|
224
224
|
function X(e) {
|
|
225
225
|
return e.data.nodeId === f;
|
|
@@ -228,11 +228,11 @@ const Q = (() => {
|
|
|
228
228
|
const t = {};
|
|
229
229
|
return t.id = e.id, t.channel = e.channel, t.replayId = e.replayId, t;
|
|
230
230
|
}
|
|
231
|
-
function
|
|
231
|
+
function V(e) {
|
|
232
232
|
const t = {};
|
|
233
233
|
return t.id = e.id, t;
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function $() {
|
|
236
236
|
if (_) {
|
|
237
237
|
const e = {
|
|
238
238
|
eventType: "functionCall",
|
|
@@ -245,19 +245,19 @@ const Q = (() => {
|
|
|
245
245
|
c().log("[Emp] Init config, remote call with ", e), W(e);
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
-
function
|
|
248
|
+
function z() {
|
|
249
249
|
return {
|
|
250
250
|
subscriptions: u,
|
|
251
251
|
unsubscribes: p
|
|
252
252
|
};
|
|
253
253
|
}
|
|
254
254
|
function x(e) {
|
|
255
|
-
_ = e, T = _.paths.cometdWorkerJs, S =
|
|
255
|
+
_ = e, T = _.paths.cometdWorkerJs, S = Ae(), c().log(
|
|
256
256
|
"[Emp] Init config, the mode of operation is ",
|
|
257
257
|
S
|
|
258
|
-
), S === y.LEADER_ELECTION &&
|
|
258
|
+
), S === y.LEADER_ELECTION && Ge(), !F() && Object.keys(u).length > 0 && ee();
|
|
259
259
|
}
|
|
260
|
-
function
|
|
260
|
+
function o(e) {
|
|
261
261
|
b || (O = e, i());
|
|
262
262
|
}
|
|
263
263
|
function i() {
|
|
@@ -270,63 +270,63 @@ const Q = (() => {
|
|
|
270
270
|
}
|
|
271
271
|
}), g && g.setDebugFlag(O);
|
|
272
272
|
}
|
|
273
|
-
function
|
|
273
|
+
function Y(e) {
|
|
274
274
|
const t = {
|
|
275
275
|
eventType: "functionCall",
|
|
276
276
|
nodeId: f,
|
|
277
277
|
functionName: "addOnErrorListener",
|
|
278
278
|
functionParams: {
|
|
279
|
-
listener:
|
|
279
|
+
listener: V(e)
|
|
280
280
|
}
|
|
281
281
|
};
|
|
282
282
|
W(t);
|
|
283
283
|
}
|
|
284
284
|
function oe() {
|
|
285
|
-
k(L,
|
|
285
|
+
k(L, Y);
|
|
286
286
|
}
|
|
287
|
-
function
|
|
287
|
+
function pe(e) {
|
|
288
288
|
const t = {
|
|
289
289
|
eventType: "functionCall",
|
|
290
290
|
nodeId: f,
|
|
291
291
|
functionName: "removeOnErrorListener",
|
|
292
292
|
functionParams: {
|
|
293
|
-
listener:
|
|
293
|
+
listener: V(e)
|
|
294
294
|
}
|
|
295
295
|
};
|
|
296
296
|
W(t);
|
|
297
297
|
}
|
|
298
|
-
function
|
|
299
|
-
k(L,
|
|
298
|
+
function me() {
|
|
299
|
+
k(L, pe), L = {};
|
|
300
300
|
}
|
|
301
|
-
function
|
|
301
|
+
function Ee(e) {
|
|
302
302
|
const t = {};
|
|
303
|
-
t.id = j(), t.callback = e, L[t.id] = t, F() &&
|
|
303
|
+
t.id = j(), t.callback = e, L[t.id] = t, F() && Y(t);
|
|
304
304
|
}
|
|
305
305
|
function re() {
|
|
306
|
-
|
|
306
|
+
me(), Se();
|
|
307
307
|
}
|
|
308
|
-
function
|
|
309
|
-
k(u, (t,
|
|
310
|
-
|
|
308
|
+
function ge(e) {
|
|
309
|
+
k(u, (t, r) => {
|
|
310
|
+
r.channel === e && delete u[t];
|
|
311
311
|
});
|
|
312
312
|
}
|
|
313
|
-
function
|
|
314
|
-
k(p, (t,
|
|
315
|
-
|
|
313
|
+
function _e(e) {
|
|
314
|
+
k(p, (t, r) => {
|
|
315
|
+
r.channel === e && delete p[t];
|
|
316
316
|
});
|
|
317
317
|
}
|
|
318
|
-
function
|
|
319
|
-
const t = e.message,
|
|
320
|
-
|
|
318
|
+
function he(e) {
|
|
319
|
+
const t = e.message, r = JSON.parse(t);
|
|
320
|
+
r && (r.channel === "/meta/subscribe" || r.channel === "/meta/unsubscribe") && r.subscription && (ge(r.subscription), _e(r.subscription)), k(L, (m) => {
|
|
321
321
|
const I = m.callback;
|
|
322
|
-
|
|
322
|
+
C(I) && I(r);
|
|
323
323
|
});
|
|
324
324
|
}
|
|
325
325
|
function ie() {
|
|
326
326
|
if (_) {
|
|
327
327
|
const e = JSON.parse(JSON.stringify(_));
|
|
328
328
|
return d && (e.cometdState = window.localStorage.getItem(
|
|
329
|
-
|
|
329
|
+
n
|
|
330
330
|
)), e;
|
|
331
331
|
}
|
|
332
332
|
return {};
|
|
@@ -346,16 +346,16 @@ const Q = (() => {
|
|
|
346
346
|
function se() {
|
|
347
347
|
k(u, ae);
|
|
348
348
|
}
|
|
349
|
-
function
|
|
349
|
+
function Ie(e, t, r, m) {
|
|
350
350
|
const I = {}, q = j();
|
|
351
|
-
I.id = q, I.channel = e, I.replayId = t, I.callback =
|
|
352
|
-
const
|
|
353
|
-
return F() ? ae(I) : ee(),
|
|
351
|
+
I.id = q, I.channel = e, I.replayId = t, I.callback = r, C(m) && (I.subscribeCallback = m), u[q] = I;
|
|
352
|
+
const je = U(I);
|
|
353
|
+
return F() ? ae(I) : ee(), je;
|
|
354
354
|
}
|
|
355
|
-
function
|
|
355
|
+
function ye(e, t) {
|
|
356
356
|
if (e) {
|
|
357
|
-
const
|
|
358
|
-
|
|
357
|
+
const r = u[e.id];
|
|
358
|
+
r && (delete u[e.id], p[r.id] = r, r.unsubscribeCallback = t, ce(r));
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
function ce(e) {
|
|
@@ -369,19 +369,19 @@ const Q = (() => {
|
|
|
369
369
|
}
|
|
370
370
|
}, c().log("[Emp] unsubscribe with ", t), W(t));
|
|
371
371
|
}
|
|
372
|
-
function
|
|
372
|
+
function Se() {
|
|
373
373
|
k(u, ce);
|
|
374
374
|
}
|
|
375
|
-
function
|
|
376
|
-
let t,
|
|
377
|
-
e && e.subscription &&
|
|
375
|
+
function we(e) {
|
|
376
|
+
let t, r;
|
|
377
|
+
e && e.subscription && A(e.subscription) && (t = e.subscription.id, r = u[t], r.cometdSubscription = e.subscription.cometdSubscription);
|
|
378
378
|
}
|
|
379
|
-
function
|
|
380
|
-
let t,
|
|
381
|
-
e && e.message && (t = e.subscription.id,
|
|
379
|
+
function Le(e) {
|
|
380
|
+
let t, r, m;
|
|
381
|
+
e && e.message && (t = e.subscription.id, r = p[t], r && (m = r.unsubscribeCallback, t && (e.message.successful && delete p[t], c().log(
|
|
382
382
|
"[Emp] unsubscribe callback called for subscription",
|
|
383
|
-
|
|
384
|
-
),
|
|
383
|
+
r
|
|
384
|
+
), C(m) && m(e.message))));
|
|
385
385
|
const I = Object.keys(p).length, q = Object.keys(u).length;
|
|
386
386
|
c().log(
|
|
387
387
|
"[Emp] No. of unsubscribes = " + I + ", unsubscribes object:",
|
|
@@ -392,61 +392,61 @@ const Q = (() => {
|
|
|
392
392
|
);
|
|
393
393
|
}
|
|
394
394
|
function Ce(e) {
|
|
395
|
-
let t,
|
|
396
|
-
e && e.subscription && (t = e.subscription.id,
|
|
395
|
+
let t, r, m;
|
|
396
|
+
e && e.subscription && (t = e.subscription.id, r = u[t], m = e.message, r && r.callback && (ke(r, m), r.callback(m)));
|
|
397
397
|
}
|
|
398
|
-
function
|
|
398
|
+
function ke(e, t) {
|
|
399
399
|
t && t.data && t.data.event && t.data.event.replayId && (e.replayId = t.data.event.replayId);
|
|
400
400
|
}
|
|
401
|
-
function
|
|
402
|
-
let t,
|
|
403
|
-
e && e.subscription && (t = e.subscription.id,
|
|
401
|
+
function Te(e) {
|
|
402
|
+
let t, r, m;
|
|
403
|
+
e && e.subscription && (t = e.subscription.id, r = u[t], m = e.message, r && r.subscribeCallback && r.subscribeCallback(m));
|
|
404
404
|
}
|
|
405
|
-
function
|
|
405
|
+
function Oe() {
|
|
406
406
|
c().log("[Emp] Clearing state before unload..."), re();
|
|
407
407
|
}
|
|
408
|
-
function
|
|
408
|
+
function De(e) {
|
|
409
409
|
if (!d)
|
|
410
410
|
return;
|
|
411
411
|
let t = null;
|
|
412
|
-
e && e.params && (t = e.params.state, window.localStorage.setItem(
|
|
412
|
+
e && e.params && (t = e.params.state, window.localStorage.setItem(n, t), c().log("[Emp] Cometd state in main is " + t));
|
|
413
413
|
}
|
|
414
|
-
function
|
|
415
|
-
d && window.localStorage.removeItem(
|
|
414
|
+
function Ne() {
|
|
415
|
+
d && window.localStorage.removeItem(n);
|
|
416
416
|
}
|
|
417
|
-
function
|
|
418
|
-
c().log("[Emp] Terminating cometd worker..."), s && (S === y.LEADER_ELECTION &&
|
|
417
|
+
function We() {
|
|
418
|
+
c().log("[Emp] Terminating cometd worker..."), s && (S === y.LEADER_ELECTION && Pe(), S === y.SHARED_WORKER ? s.port.close() : s.terminate(), c().log("[Emp] Set cometdWorker to null"), s = null);
|
|
419
419
|
}
|
|
420
420
|
function Z(e) {
|
|
421
421
|
if (c().log("[Emp] fromCometdWorker: ", e), e && e.data) {
|
|
422
422
|
if (e.data.eventType === "functionCall")
|
|
423
423
|
switch (e.data.functionName) {
|
|
424
424
|
case "subscribeCallback": {
|
|
425
|
-
|
|
425
|
+
A(e.data.subscription) ? Te(e.data) : N(e.data);
|
|
426
426
|
return;
|
|
427
427
|
}
|
|
428
428
|
case "unsubscribeCallback": {
|
|
429
|
-
|
|
429
|
+
B(e.data.subscription) ? Le(e.data) : N(e.data);
|
|
430
430
|
return;
|
|
431
431
|
}
|
|
432
432
|
case "messageCallback": {
|
|
433
|
-
|
|
433
|
+
A(e.data.subscription) ? Ce(e.data) : N(e.data);
|
|
434
434
|
return;
|
|
435
435
|
}
|
|
436
436
|
case "onErrorCallback": {
|
|
437
|
-
|
|
437
|
+
R(e.data.listener) ? he(e.data) : N(e.data);
|
|
438
438
|
return;
|
|
439
439
|
}
|
|
440
440
|
case "saveCometdState": {
|
|
441
|
-
|
|
441
|
+
De(e.data);
|
|
442
442
|
return;
|
|
443
443
|
}
|
|
444
444
|
case "removeCometdState": {
|
|
445
|
-
|
|
445
|
+
Ne();
|
|
446
446
|
return;
|
|
447
447
|
}
|
|
448
448
|
case "terminateWorker": {
|
|
449
|
-
|
|
449
|
+
We();
|
|
450
450
|
return;
|
|
451
451
|
}
|
|
452
452
|
case "setDebugFlag":
|
|
@@ -456,16 +456,16 @@ const Q = (() => {
|
|
|
456
456
|
"[Emp] fromCometdWorker: No handler found for [" + e.data.functionName + "]."
|
|
457
457
|
);
|
|
458
458
|
}
|
|
459
|
-
e.data.eventType === "functionReturn" && e.data.functionName === "subscribe" && (
|
|
459
|
+
e.data.eventType === "functionReturn" && e.data.functionName === "subscribe" && (A(e.data.subscription) ? we(e.data) : N(e.data));
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
|
-
function
|
|
463
|
-
return !
|
|
462
|
+
function Ae() {
|
|
463
|
+
return !J() && ve() ? y.SHARED_WORKER : Re() ? y.LEADER_ELECTION : y.STANDALONE;
|
|
464
464
|
}
|
|
465
|
-
function
|
|
465
|
+
function Re() {
|
|
466
466
|
return d && !!window.Worker;
|
|
467
467
|
}
|
|
468
|
-
function
|
|
468
|
+
function ve() {
|
|
469
469
|
let e = T && "SharedWorker" in window;
|
|
470
470
|
if (e)
|
|
471
471
|
try {
|
|
@@ -479,77 +479,77 @@ const Q = (() => {
|
|
|
479
479
|
}
|
|
480
480
|
return e;
|
|
481
481
|
}
|
|
482
|
-
function
|
|
482
|
+
function Me() {
|
|
483
483
|
return !s && S === y.SHARED_WORKER;
|
|
484
484
|
}
|
|
485
|
-
function
|
|
485
|
+
function Fe() {
|
|
486
486
|
return !s && (v() || S === y.STANDALONE);
|
|
487
487
|
}
|
|
488
488
|
function ee() {
|
|
489
489
|
if (T) {
|
|
490
490
|
let e = !1;
|
|
491
|
-
|
|
491
|
+
Me() ? (c().log("[Emp] Create new SharedWorker"), s = new SharedWorker(T), s.port.addEventListener(
|
|
492
492
|
"message",
|
|
493
493
|
Z
|
|
494
|
-
), s.port.start(), e = !0) :
|
|
494
|
+
), s.port.start(), e = !0) : Fe() && (c().log("[Emp] Create new WebWorker"), s = new Worker(T), s.addEventListener("message", Z), e = !0), e && (c().log("[Emp] New Worker Created"), i(), $(), oe(), se());
|
|
495
495
|
}
|
|
496
496
|
}
|
|
497
|
-
function
|
|
498
|
-
f = e.nodeId,
|
|
497
|
+
function Ue(e) {
|
|
498
|
+
f = e.nodeId, C(_.onNodeIdInit) && _.onNodeIdInit(f);
|
|
499
499
|
}
|
|
500
|
-
function
|
|
501
|
-
|
|
500
|
+
function He(e) {
|
|
501
|
+
w !== e.leaderId && (w = e.leaderId, _.onLeaderChange && _.onLeaderChange(w === f), v() ? ee() : (se(), oe()));
|
|
502
502
|
}
|
|
503
|
-
function
|
|
503
|
+
function Je(e) {
|
|
504
504
|
const t = {};
|
|
505
|
-
let
|
|
506
|
-
e.newValue && e.key === a && (
|
|
505
|
+
let r;
|
|
506
|
+
e.newValue && e.key === a && (r = JSON.parse(e.newValue), t.data = r), r && r.eventType && (v() ? s ? s.postMessage(r) : c().log("[Emp] Cometd Worker is undefined!") : X(t) && Z(t));
|
|
507
507
|
}
|
|
508
|
-
function
|
|
509
|
-
g || (window.addEventListener("storage",
|
|
508
|
+
function Ge() {
|
|
509
|
+
g || (window.addEventListener("storage", Je), g = new Ye(Ue, He), g.setDebugFlag(O), g.start());
|
|
510
510
|
}
|
|
511
|
-
function
|
|
511
|
+
function Pe() {
|
|
512
512
|
g && v() && (c().log("[Emp] Stop sending heartbeats..."), g.stop(), c().log("[Emp] Leader stopped sending heartbeats"));
|
|
513
513
|
}
|
|
514
|
-
return window.addEventListener("unload",
|
|
514
|
+
return window.addEventListener("unload", Oe), {
|
|
515
515
|
init: x,
|
|
516
|
-
subscribe:
|
|
517
|
-
unsubscribe:
|
|
518
|
-
onError:
|
|
516
|
+
subscribe: Ie,
|
|
517
|
+
unsubscribe: ye,
|
|
518
|
+
onError: Ee,
|
|
519
519
|
clearState: re,
|
|
520
|
-
setDebugFlag:
|
|
521
|
-
getState:
|
|
520
|
+
setDebugFlag: o,
|
|
521
|
+
getState: z
|
|
522
522
|
};
|
|
523
523
|
})();
|
|
524
|
-
function
|
|
525
|
-
return typeof
|
|
524
|
+
function de(n) {
|
|
525
|
+
return typeof n == "object" && n !== null;
|
|
526
526
|
}
|
|
527
|
-
function qe(
|
|
528
|
-
if (typeof
|
|
527
|
+
function qe(n) {
|
|
528
|
+
if (typeof n != "object" || n === null)
|
|
529
529
|
return !1;
|
|
530
|
-
const a =
|
|
530
|
+
const a = n.data;
|
|
531
531
|
if (typeof a != "object" || a === null)
|
|
532
532
|
return !1;
|
|
533
533
|
const l = a.payload, d = a.event;
|
|
534
|
-
return typeof
|
|
534
|
+
return typeof n.channel == "string" && typeof l == "object" && l !== null && typeof d == "object" && d !== null;
|
|
535
535
|
}
|
|
536
536
|
let te = null;
|
|
537
|
-
function
|
|
538
|
-
return te || (te =
|
|
539
|
-
|
|
537
|
+
function fe(n) {
|
|
538
|
+
return te || (te = n().then((a) => {
|
|
539
|
+
H.init({
|
|
540
540
|
cometdUrl: a.cometdUrl,
|
|
541
541
|
paths: { cometdWorkerJs: a.cometdWorkerJs }
|
|
542
542
|
});
|
|
543
543
|
})), te;
|
|
544
544
|
}
|
|
545
|
-
const
|
|
545
|
+
const Q = [];
|
|
546
546
|
let le = !1;
|
|
547
547
|
const Qe = 2e3, Xe = 200, M = /* @__PURE__ */ new Map();
|
|
548
|
-
function
|
|
549
|
-
return
|
|
548
|
+
function $e(n) {
|
|
549
|
+
return de(n) ? n.id == null ? null : String(n.id) : null;
|
|
550
550
|
}
|
|
551
|
-
function ne(
|
|
552
|
-
const a =
|
|
551
|
+
function ne(n) {
|
|
552
|
+
const a = $e(n);
|
|
553
553
|
if (a !== null) {
|
|
554
554
|
const l = Date.now(), d = M.get(a);
|
|
555
555
|
if (d !== void 0 && l - d < Qe)
|
|
@@ -562,36 +562,36 @@ function ne(r) {
|
|
|
562
562
|
}
|
|
563
563
|
M.set(a, l);
|
|
564
564
|
}
|
|
565
|
-
for (const l of [...
|
|
565
|
+
for (const l of [...Q])
|
|
566
566
|
try {
|
|
567
|
-
l(
|
|
567
|
+
l(n);
|
|
568
568
|
} catch {
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
|
-
function
|
|
572
|
-
le || (le = !0,
|
|
571
|
+
function be() {
|
|
572
|
+
le || (le = !0, H.onError(ne));
|
|
573
573
|
}
|
|
574
|
-
function
|
|
575
|
-
return { id:
|
|
574
|
+
function ze(n) {
|
|
575
|
+
return { id: n.id, channel: n.channel, replayId: n.replayId };
|
|
576
576
|
}
|
|
577
|
-
function xe(
|
|
577
|
+
function xe(n) {
|
|
578
578
|
return {
|
|
579
|
-
id:
|
|
580
|
-
channel:
|
|
581
|
-
replayId:
|
|
582
|
-
unsubscribe: () => et(
|
|
579
|
+
id: n.id,
|
|
580
|
+
channel: n.channel,
|
|
581
|
+
replayId: n.replayId,
|
|
582
|
+
unsubscribe: () => et(n)
|
|
583
583
|
};
|
|
584
584
|
}
|
|
585
|
-
async function Ze(
|
|
586
|
-
await
|
|
587
|
-
const b =
|
|
588
|
-
|
|
585
|
+
async function Ze(n, a, l, d = ue) {
|
|
586
|
+
await fe(d), be();
|
|
587
|
+
const b = H.subscribe(
|
|
588
|
+
n,
|
|
589
589
|
a,
|
|
590
590
|
(E) => {
|
|
591
591
|
qe(E) && l(E);
|
|
592
592
|
},
|
|
593
593
|
(E) => {
|
|
594
|
-
if (!
|
|
594
|
+
if (!de(E)) {
|
|
595
595
|
ne({ successful: !1, error: "Invalid ack payload" });
|
|
596
596
|
return;
|
|
597
597
|
}
|
|
@@ -600,26 +600,52 @@ async function Ze(r, a, l, d = Be) {
|
|
|
600
600
|
);
|
|
601
601
|
return xe(b);
|
|
602
602
|
}
|
|
603
|
-
function et(
|
|
604
|
-
|
|
603
|
+
function et(n) {
|
|
604
|
+
H.unsubscribe(ze(n));
|
|
605
605
|
}
|
|
606
|
-
function
|
|
607
|
-
|
|
608
|
-
const a = (l) =>
|
|
609
|
-
return
|
|
610
|
-
const l =
|
|
611
|
-
l !== -1 &&
|
|
606
|
+
function it(n) {
|
|
607
|
+
be();
|
|
608
|
+
const a = (l) => n(l);
|
|
609
|
+
return Q.push(a), () => {
|
|
610
|
+
const l = Q.indexOf(a);
|
|
611
|
+
l !== -1 && Q.splice(l, 1);
|
|
612
612
|
};
|
|
613
613
|
}
|
|
614
|
-
function
|
|
615
|
-
return typeof
|
|
614
|
+
function tt() {
|
|
615
|
+
return typeof window < "u" && window.__nimbus != null;
|
|
616
|
+
}
|
|
617
|
+
async function nt(n = ue) {
|
|
618
|
+
if (tt() || typeof Worker > "u")
|
|
619
|
+
return !1;
|
|
620
|
+
try {
|
|
621
|
+
await fe(n);
|
|
622
|
+
} catch {
|
|
623
|
+
return !1;
|
|
624
|
+
}
|
|
625
|
+
return !0;
|
|
626
|
+
}
|
|
627
|
+
const ot = "emp.debugFlag";
|
|
628
|
+
function at(n) {
|
|
629
|
+
H.setDebugFlag(n);
|
|
630
|
+
try {
|
|
631
|
+
localStorage.setItem(ot, String(n));
|
|
632
|
+
} catch {
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
function st(n) {
|
|
636
|
+
return typeof n.data?.payload == "object" && n.data.payload !== null && "ChangeEventHeader" in n.data.payload;
|
|
637
|
+
}
|
|
638
|
+
async function ct(n, a, l) {
|
|
639
|
+
return Ze(n, a, l);
|
|
616
640
|
}
|
|
617
|
-
async function
|
|
618
|
-
return
|
|
641
|
+
async function lt() {
|
|
642
|
+
return nt();
|
|
619
643
|
}
|
|
620
644
|
export {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
645
|
+
st as isChangeDataCaptureMessage,
|
|
646
|
+
lt as isEmpEnabled,
|
|
647
|
+
it as onError,
|
|
648
|
+
at as setDebugFlag,
|
|
649
|
+
ct as subscribe,
|
|
624
650
|
et as unsubscribe
|
|
625
651
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/emp-api",
|
|
3
|
-
"version": "12.6.2",
|
|
3
|
+
"version": "12.6.3-canary.999.2.1.gd0b2ab15",
|
|
4
4
|
"description": "empApi-shaped wrapper for UI Bundles over the platform CometD/Bayeux streaming engine, so a UI Bundle can react to Platform Events and Change Data Capture (CDC) events without polling.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"type": "module",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"test:coverage": "vitest run --coverage"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@salesforce/platform-sdk": "^12.6.2"
|
|
31
|
+
"@salesforce/platform-sdk": "^12.6.3-canary.999.2.1.gd0b2ab15"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@salesforce/platform-sdk": "
|
|
34
|
+
"@salesforce/platform-sdk": "12.6.3-canary.999.2.1.gd0b2ab15",
|
|
35
35
|
"vite": "^7.3.5",
|
|
36
36
|
"vite-plugin-dts": "^4.5.4",
|
|
37
37
|
"vitest": "^4.0.6"
|