@octostar/platform-api 0.5.19 → 0.5.20
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/dist/factory.js +1 -1
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/LiveContextAPI.d.ts +27 -0
- package/dist/lib/LiveContextAPI.d.ts.map +1 -0
- package/dist/lib/LiveContextAPI.js +120 -0
- package/dist/lib/LiveContextAPI.js.map +1 -0
- package/dist/octostar-platform-api.js +293 -9
- package/package.json +4 -3
package/dist/factory.js
CHANGED
package/dist/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AAMxC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,SAAS,GAAG,CAAC,MAAc,EAAW,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC;AAExE,SAAS,iBAAiB,CACxB,SAAiB,EACjB,gBAAwB,MAAM,EAC9B,KAAK,GAAG,CAAC;IAET,0CAA0C;IAC1C,IAAI,OAAsC,CAAC;IAC3C,IAAI,CAAC;QACH,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,+BAA+B;QAC/B,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,C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B,CAAI,QAAsC,CAAC,CAAC;QAE1E,OAAO,iBAAiB,CAAI,GAAG,EAAE;YAC/B,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CACT,gEAAgE,KAAK,EAAE,EACvE,CAAC,CACF,CAAC;QACF,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAI,KAAiB,EAAK,EAAE,CACpE,IAAI,KAAK,CACP,EAAE,EACF;IACE,GAAG,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CACpB,IAAI,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE;QAClB,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;KACrE,CAAC;CACL,CACG,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LiveContext, LiveContextListener, LiveContextAPISetParams, DefaultLiveContextData } from '@octostar/platform-types';
|
|
2
|
+
export declare class LiveContextAPI<ContextData extends DefaultLiveContextData = DefaultLiveContextData> implements LiveContext<ContextData> {
|
|
3
|
+
private contextData;
|
|
4
|
+
private listeners;
|
|
5
|
+
private postRobotListener;
|
|
6
|
+
private type;
|
|
7
|
+
private channelId;
|
|
8
|
+
private iframeChannelAttr;
|
|
9
|
+
readonly id: string;
|
|
10
|
+
constructor(contextData: ContextData);
|
|
11
|
+
private connectPostRobot;
|
|
12
|
+
private getConnectId;
|
|
13
|
+
private getTargetWindow;
|
|
14
|
+
private setContextAndNotify;
|
|
15
|
+
private getPostRobotEventName;
|
|
16
|
+
private sendContextUpdate;
|
|
17
|
+
getContext(): ContextData;
|
|
18
|
+
setContext(context: LiveContextAPISetParams<ContextData>): Promise<void>;
|
|
19
|
+
subscribeToChanges(contextListener: LiveContextListener<ContextData>): string;
|
|
20
|
+
subscribeToChanges(id: string, contextListener: LiveContextListener<ContextData>): string;
|
|
21
|
+
unsubscribeFromChanges(id: string): void;
|
|
22
|
+
addContextListener<ContextDataToConnect extends DefaultLiveContextData>(LiveContextAPItoConnect: LiveContextAPI<ContextDataToConnect>, mapContext?: (context: ContextDataToConnect) => ContextData): () => void;
|
|
23
|
+
removeContextListener<ContextDataToConnect extends DefaultLiveContextData>(idOrContextAPI: LiveContextAPI<ContextDataToConnect> | string): void;
|
|
24
|
+
connect(): string;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=LiveContextAPI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveContextAPI.d.ts","sourceRoot":"","sources":["../../src/lib/LiveContextAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAMlC,qBAAa,cAAc,CAAC,WAAW,SAAS,sBAAsB,GAAG,sBAAsB,CAAE,YAAW,WAAW,CAAC,WAAW,CAAC;IAElI,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,SAAS,CAAwD;IACzE,OAAO,CAAC,iBAAiB,CAAgD;IACzE,OAAO,CAAC,IAAI,CAAsB;IAClC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,iBAAiB,CAAkC;IAC3D,QAAQ,CAAC,EAAE,SAAY;gBAEX,WAAW,EAAE,WAAW;YAOtB,gBAAgB;IAc9B,OAAO,CAAC,YAAY;YAIN,eAAe;IAyB7B,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,qBAAqB;YAIf,iBAAiB;IAU/B,UAAU;IAIJ,UAAU,CAAC,OAAO,EAAE,uBAAuB,CAAC,WAAW,CAAC;IAK9D,kBAAkB,CAAC,eAAe,EAAE,mBAAmB,CAAC,WAAW,CAAC,GAAG,MAAM;IAE7E,kBAAkB,CAChB,EAAE,EAAE,MAAM,EACV,eAAe,EAAE,mBAAmB,CAAC,WAAW,CAAC,GAChD,MAAM;IAsBT,sBAAsB,CAAC,EAAE,EAAE,MAAM;IAIjC,kBAAkB,CAAC,oBAAoB,SAAS,sBAAsB,EAAE,uBAAuB,EAAE,cAAc,CAAC,oBAAoB,CAAC,EAAE,UAAU,GAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,WAA4D,GAAG,MAAM,IAAI;IAc/P,qBAAqB,CAAC,oBAAoB,SAAS,sBAAsB,EAAE,cAAc,EAAE,cAAc,CAAC,oBAAoB,CAAC,GAAG,MAAM;IAKvI,OAAO;IAMR,OAAO;CAGR"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
import * as postRobot from 'post-robot';
|
|
3
|
+
const CONTEXT_UPDATE_EVENT = 'context-update';
|
|
4
|
+
export class LiveContextAPI {
|
|
5
|
+
constructor(contextData) {
|
|
6
|
+
this.listeners = {};
|
|
7
|
+
this.iframeChannelAttr = 'data-octostar-iframe-channel';
|
|
8
|
+
this.id = uuidv4();
|
|
9
|
+
this.contextData = contextData;
|
|
10
|
+
const iframeChannelId = window.frameElement?.getAttribute(this.iframeChannelAttr);
|
|
11
|
+
this.channelId = iframeChannelId || uuidv4();
|
|
12
|
+
this.type = iframeChannelId ? 'iframe' : 'parent';
|
|
13
|
+
}
|
|
14
|
+
async connectPostRobot() {
|
|
15
|
+
const targetWindow = await this.getTargetWindow();
|
|
16
|
+
const postRobotEventName = this.getPostRobotEventName(this.channelId);
|
|
17
|
+
this.postRobotListener = (postRobot.on(postRobotEventName, { window: targetWindow }, (event) => {
|
|
18
|
+
if (event.data.type === 'init') {
|
|
19
|
+
this.setContext((context) => ({ ...context, ...event.data.context }));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.setContextAndNotify((context) => ({ ...context, ...event.data.context }));
|
|
23
|
+
}
|
|
24
|
+
return Promise.resolve();
|
|
25
|
+
}));
|
|
26
|
+
await this.sendContextUpdate(true);
|
|
27
|
+
}
|
|
28
|
+
getConnectId(contextAPI) {
|
|
29
|
+
return `ContextAPI-${contextAPI.id}`;
|
|
30
|
+
}
|
|
31
|
+
async getTargetWindow() {
|
|
32
|
+
if (this.type === 'iframe' && window.top) {
|
|
33
|
+
return window.top;
|
|
34
|
+
}
|
|
35
|
+
const iframe = document.querySelector(`iframe[${this.iframeChannelAttr}='${this.channelId}']`);
|
|
36
|
+
if (iframe?.contentWindow) {
|
|
37
|
+
return iframe.contentWindow;
|
|
38
|
+
}
|
|
39
|
+
// Wait for the iframe to appear in the DOM
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
const observer = new MutationObserver(() => {
|
|
42
|
+
const iframe = document.querySelector(`iframe[${this.iframeChannelAttr}='${this.channelId}']`);
|
|
43
|
+
if (iframe?.contentWindow) {
|
|
44
|
+
observer.disconnect();
|
|
45
|
+
resolve(iframe.contentWindow);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
// Start observing
|
|
49
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
setContextAndNotify(context) {
|
|
53
|
+
if (typeof context === 'function') {
|
|
54
|
+
this.contextData = context(this.contextData);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.contextData = context;
|
|
58
|
+
}
|
|
59
|
+
Object.values(this.listeners).forEach(listener => listener(this.contextData));
|
|
60
|
+
}
|
|
61
|
+
getPostRobotEventName(channelId) {
|
|
62
|
+
return `${channelId}-${CONTEXT_UPDATE_EVENT}`;
|
|
63
|
+
}
|
|
64
|
+
async sendContextUpdate(isInit = false) {
|
|
65
|
+
try {
|
|
66
|
+
const targetWindow = await this.getTargetWindow();
|
|
67
|
+
postRobot.send(targetWindow, this.getPostRobotEventName(this.channelId), { context: this.contextData, ...(isInit && { type: 'init' }) });
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// Silently ignore any errors during context update
|
|
71
|
+
console.debug('Failed to send context update:', error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
getContext() {
|
|
75
|
+
return this.contextData;
|
|
76
|
+
}
|
|
77
|
+
async setContext(context) {
|
|
78
|
+
this.setContextAndNotify(context);
|
|
79
|
+
await this.sendContextUpdate();
|
|
80
|
+
}
|
|
81
|
+
subscribeToChanges(idOrContextListener, contextListenerOrNothing) {
|
|
82
|
+
const id = typeof idOrContextListener === 'string' ? idOrContextListener : uuidv4();
|
|
83
|
+
const contextListener = typeof idOrContextListener === 'function'
|
|
84
|
+
? idOrContextListener
|
|
85
|
+
: contextListenerOrNothing;
|
|
86
|
+
if (!contextListener) {
|
|
87
|
+
const error = new Error('Context listener is required');
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
this.listeners[id] = contextListener;
|
|
91
|
+
return id;
|
|
92
|
+
}
|
|
93
|
+
unsubscribeFromChanges(id) {
|
|
94
|
+
delete this.listeners[id];
|
|
95
|
+
}
|
|
96
|
+
addContextListener(LiveContextAPItoConnect, mapContext = (context) => context) {
|
|
97
|
+
// Merge the new context with existing context
|
|
98
|
+
this.setContext((currentContext) => ({ ...currentContext, ...mapContext(LiveContextAPItoConnect.getContext()) }));
|
|
99
|
+
// Subscribe to changes if id is provided
|
|
100
|
+
const subscriptionId = this.getConnectId(LiveContextAPItoConnect);
|
|
101
|
+
LiveContextAPItoConnect.subscribeToChanges(subscriptionId, (updatedContext) => {
|
|
102
|
+
this.setContext((currentContext) => ({ ...currentContext, ...mapContext(updatedContext) }));
|
|
103
|
+
});
|
|
104
|
+
// Return a callback function that unsubscribes
|
|
105
|
+
return () => this.unsubscribeFromChanges(subscriptionId);
|
|
106
|
+
}
|
|
107
|
+
removeContextListener(idOrContextAPI) {
|
|
108
|
+
const id = typeof idOrContextAPI === 'string' ? idOrContextAPI : this.getConnectId(idOrContextAPI);
|
|
109
|
+
this.unsubscribeFromChanges(id);
|
|
110
|
+
}
|
|
111
|
+
connect() {
|
|
112
|
+
const channelId = this.channelId;
|
|
113
|
+
this.connectPostRobot();
|
|
114
|
+
return channelId;
|
|
115
|
+
}
|
|
116
|
+
destroy() {
|
|
117
|
+
this.postRobotListener?.cancel();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=LiveContextAPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveContextAPI.js","sourceRoot":"","sources":["../../src/lib/LiveContextAPI.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AAExC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAE9C,MAAM,OAAO,cAAc;IAUzB,YAAY,WAAwB;QAP5B,cAAS,GAAqD,EAAE,CAAC;QAIjE,sBAAiB,GAAG,8BAA8B,CAAC;QAClD,OAAE,GAAG,MAAM,EAAE,CAAC;QAGrB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,MAAM,eAAe,GAAG,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAClF,IAAI,CAAC,SAAS,GAAG,eAAe,IAAI,MAAM,EAAE,CAAC;QAC7C,IAAI,CAAC,IAAI,GA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480
|
value: true
|
|
6481
6481
|
});
|
|
6482
6482
|
exports.forwardCallsToFutureObject = exports.createRemoteApiHandle = void 0;
|
|
6483
|
-
var
|
|
6483
|
+
var postRobot = _interopRequireWildcard(require("post-robot"));
|
|
6484
6484
|
var _utils = require("./utils");
|
|
6485
6485
|
var _constants = require("./constants");
|
|
6486
|
-
function
|
|
6486
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
6487
6487
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof Symbol ? Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return Object.defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = Object.getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(l); function g(t) { ["next", "throw", "return"].forEach(function (r) { c(t, r, function (t) { return this._invoke(r, t); }); }); } function AsyncIterator(t, r) { function e(o, i, a, u) { var c = s(t[o], t, i); if ("throw" !== c.type) { var h = c.arg, f = h.value; return f && "object" == _typeof(f) && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) { e("next", t, a, u); }, function (t) { e("throw", t, a, u); }) : r.resolve(f).then(function (t) { h.value = t, a(h); }, function (t) { return e("throw", t, a, u); }); } u(c.arg); } var o; c(this, "_invoke", function (t, n) { function i() { return new r(function (r, o) { e(t, n, r, o); }); } return o = o ? o.then(i, i) : i(); }, !0); } function d(r, e) { var n = e.method, o = r.i[n]; if (o === t) return e.delegate = null, "throw" === n && r.i["return"] && (e.method = "return", e.arg = t, d(r, e), "throw" === e.method) || "return" !== n && (e.method = "throw", e.arg = new TypeError("The iterator does not provide a '" + n + "' method")), f; var i = s(o, r.i, e.arg); if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f; var a = i.arg; return a ? a.done ? (e[r.r] = a.value, e.next = r.n, "return" !== e.method && (e.method = "next", e.arg = t), e.delegate = null, f) : a : (e.method = "throw", e.arg = new TypeError("iterator result is not an object"), e.delegate = null, f); } function w(t) { this.tryEntries.push(t); } function m(r) { var e = r[4] || {}; e.type = "normal", e.arg = t, r[4] = e; } function Context(t) { this.tryEntries = [[-1]], t.forEach(w, this), this.reset(!0); } function x(r) { if (null != r) { var e = r[i]; if (e) return e.call(r); if ("function" == typeof r.next) return r; if (!isNaN(r.length)) { var o = -1, a = function e() { for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e; return e.value = t, e.done = !0, e; }; return a.next = a; } } throw new TypeError(_typeof(r) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) { var r = "function" == typeof t && t.constructor; return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name)); }, r.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = Object.create(v), t; }, r.awrap = function (t) { return { __await: t }; }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () { return this; }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(h(t, e, n, o), i); return r.isGeneratorFunction(e) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, g(v), c(v, u, "Generator"), c(v, i, function () { return this; }), c(v, "toString", function () { return "[object Generator]"; }), r.keys = function (t) { var r = Object(t), e = []; for (var n in r) e.unshift(n); return function t() { for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t; return t.done = !0, t; }; }, r.values = x, Context.prototype = { constructor: Context, reset: function reset(r) { if (this.prev = this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(m), !r) for (var e in this) "t" === e.charAt(0) && n.call(this, e) && !isNaN(+e.slice(1)) && (this[e] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0][4]; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(r) { if (this.done) throw r; var e = this; function n(t) { a.type = "throw", a.arg = r, e.next = t; } for (var o = e.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i[4], u = this.prev, c = i[1], h = i[2]; if (-1 === i[0]) return n("end"), !1; if (!c && !h) throw Error("try statement without catch or finally"); if (null != i[0] && i[0] <= u) { if (u < c) return this.method = "next", this.arg = t, n(c), !0; if (u < h) return n(h), !1; } } }, abrupt: function abrupt(t, r) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var n = this.tryEntries[e]; if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) { var o = n; break; } } o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null); var i = o ? o[4] : {}; return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i); }, complete: function complete(t, r) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && r && (this.next = r), f; }, finish: function finish(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[2] === t) return this.complete(e[4], e[3]), m(e), f; } }, "catch": function _catch(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[0] === t) { var n = e[4]; if ("throw" === n.type) { var o = n.arg; m(e); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(r, e, n) { return this.delegate = { i: x(r), r: e, n: n }, "next" === this.method && (this.arg = t), f; } }, r; }
|
|
6488
6488
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
6489
6489
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
@@ -6643,7 +6643,7 @@ var createRemoteApiHandle = exports.createRemoteApiHandle = /*#__PURE__*/functio
|
|
|
6643
6643
|
_context.prev = 5;
|
|
6644
6644
|
_context.next = 8;
|
|
6645
6645
|
return (0, _utils.retry)(function () {
|
|
6646
|
-
return
|
|
6646
|
+
return postRobot.send(octostarWindow, topic, params);
|
|
6647
6647
|
}, {
|
|
6648
6648
|
maxAttempts: 5,
|
|
6649
6649
|
retryInterval: 2000
|
|
@@ -6684,7 +6684,7 @@ var forwardCallsToFutureObject = exports.forwardCallsToFutureObject = function f
|
|
|
6684
6684
|
});
|
|
6685
6685
|
};
|
|
6686
6686
|
|
|
6687
|
-
},{"./constants":33,"./utils":
|
|
6687
|
+
},{"./constants":33,"./utils":44,"post-robot":5}],35:[function(require,module,exports){
|
|
6688
6688
|
"use strict";
|
|
6689
6689
|
|
|
6690
6690
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -6800,8 +6800,19 @@ Object.keys(_userWorkspace).forEach(function (key) {
|
|
|
6800
6800
|
}
|
|
6801
6801
|
});
|
|
6802
6802
|
});
|
|
6803
|
+
var _LiveContextAPI = require("./lib/LiveContextAPI");
|
|
6804
|
+
Object.keys(_LiveContextAPI).forEach(function (key) {
|
|
6805
|
+
if (key === "default" || key === "__esModule") return;
|
|
6806
|
+
if (key in exports && exports[key] === _LiveContextAPI[key]) return;
|
|
6807
|
+
Object.defineProperty(exports, key, {
|
|
6808
|
+
enumerable: true,
|
|
6809
|
+
get: function get() {
|
|
6810
|
+
return _LiveContextAPI[key];
|
|
6811
|
+
}
|
|
6812
|
+
});
|
|
6813
|
+
});
|
|
6803
6814
|
|
|
6804
|
-
},{"./apis":22,"./components":32,"./constants":33,"./lib/AIClientImpl":36,"./lib/JWTProvider":38,"./lib/
|
|
6815
|
+
},{"./apis":22,"./components":32,"./constants":33,"./lib/AIClientImpl":36,"./lib/JWTProvider":38,"./lib/LiveContextAPI":39,"./lib/Proxy":40,"./lib/userWorkspace":41,"./permissions":42,"./types":43,"./utils":44}],36:[function(require,module,exports){
|
|
6805
6816
|
"use strict";
|
|
6806
6817
|
|
|
6807
6818
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -7137,6 +7148,279 @@ var JWTProvider = exports.JWTProvider = /*#__PURE__*/function () {
|
|
|
7137
7148
|
},{}],39:[function(require,module,exports){
|
|
7138
7149
|
"use strict";
|
|
7139
7150
|
|
|
7151
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7152
|
+
value: true
|
|
7153
|
+
});
|
|
7154
|
+
exports.LiveContextAPI = void 0;
|
|
7155
|
+
var _uuid = require("uuid");
|
|
7156
|
+
var postRobot = _interopRequireWildcard(require("post-robot"));
|
|
7157
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
7158
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
7159
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof Symbol ? Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return Object.defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = Object.getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(l); function g(t) { ["next", "throw", "return"].forEach(function (r) { c(t, r, function (t) { return this._invoke(r, t); }); }); } function AsyncIterator(t, r) { function e(o, i, a, u) { var c = s(t[o], t, i); if ("throw" !== c.type) { var h = c.arg, f = h.value; return f && "object" == _typeof(f) && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) { e("next", t, a, u); }, function (t) { e("throw", t, a, u); }) : r.resolve(f).then(function (t) { h.value = t, a(h); }, function (t) { return e("throw", t, a, u); }); } u(c.arg); } var o; c(this, "_invoke", function (t, n) { function i() { return new r(function (r, o) { e(t, n, r, o); }); } return o = o ? o.then(i, i) : i(); }, !0); } function d(r, e) { var n = e.method, o = r.i[n]; if (o === t) return e.delegate = null, "throw" === n && r.i["return"] && (e.method = "return", e.arg = t, d(r, e), "throw" === e.method) || "return" !== n && (e.method = "throw", e.arg = new TypeError("The iterator does not provide a '" + n + "' method")), f; var i = s(o, r.i, e.arg); if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f; var a = i.arg; return a ? a.done ? (e[r.r] = a.value, e.next = r.n, "return" !== e.method && (e.method = "next", e.arg = t), e.delegate = null, f) : a : (e.method = "throw", e.arg = new TypeError("iterator result is not an object"), e.delegate = null, f); } function w(t) { this.tryEntries.push(t); } function m(r) { var e = r[4] || {}; e.type = "normal", e.arg = t, r[4] = e; } function Context(t) { this.tryEntries = [[-1]], t.forEach(w, this), this.reset(!0); } function x(r) { if (null != r) { var e = r[i]; if (e) return e.call(r); if ("function" == typeof r.next) return r; if (!isNaN(r.length)) { var o = -1, a = function e() { for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e; return e.value = t, e.done = !0, e; }; return a.next = a; } } throw new TypeError(_typeof(r) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) { var r = "function" == typeof t && t.constructor; return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name)); }, r.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = Object.create(v), t; }, r.awrap = function (t) { return { __await: t }; }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () { return this; }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(h(t, e, n, o), i); return r.isGeneratorFunction(e) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, g(v), c(v, u, "Generator"), c(v, i, function () { return this; }), c(v, "toString", function () { return "[object Generator]"; }), r.keys = function (t) { var r = Object(t), e = []; for (var n in r) e.unshift(n); return function t() { for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t; return t.done = !0, t; }; }, r.values = x, Context.prototype = { constructor: Context, reset: function reset(r) { if (this.prev = this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(m), !r) for (var e in this) "t" === e.charAt(0) && n.call(this, e) && !isNaN(+e.slice(1)) && (this[e] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0][4]; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(r) { if (this.done) throw r; var e = this; function n(t) { a.type = "throw", a.arg = r, e.next = t; } for (var o = e.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i[4], u = this.prev, c = i[1], h = i[2]; if (-1 === i[0]) return n("end"), !1; if (!c && !h) throw Error("try statement without catch or finally"); if (null != i[0] && i[0] <= u) { if (u < c) return this.method = "next", this.arg = t, n(c), !0; if (u < h) return n(h), !1; } } }, abrupt: function abrupt(t, r) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var n = this.tryEntries[e]; if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) { var o = n; break; } } o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null); var i = o ? o[4] : {}; return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i); }, complete: function complete(t, r) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && r && (this.next = r), f; }, finish: function finish(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[2] === t) return this.complete(e[4], e[3]), m(e), f; } }, "catch": function _catch(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[0] === t) { var n = e[4]; if ("throw" === n.type) { var o = n.arg; m(e); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(r, e, n) { return this.delegate = { i: x(r), r: e, n: n }, "next" === this.method && (this.arg = t), f; } }, r; }
|
|
7160
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7161
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7162
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
7163
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
7164
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
7165
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
7166
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
7167
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
7168
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
7169
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7170
|
+
var CONTEXT_UPDATE_EVENT = 'context-update';
|
|
7171
|
+
var LiveContextAPI = exports.LiveContextAPI = /*#__PURE__*/function () {
|
|
7172
|
+
function LiveContextAPI(contextData) {
|
|
7173
|
+
var _window$frameElement;
|
|
7174
|
+
_classCallCheck(this, LiveContextAPI);
|
|
7175
|
+
this.listeners = {};
|
|
7176
|
+
this.iframeChannelAttr = 'data-octostar-iframe-channel';
|
|
7177
|
+
this.id = (0, _uuid.v4)();
|
|
7178
|
+
this.contextData = contextData;
|
|
7179
|
+
var iframeChannelId = (_window$frameElement = window.frameElement) === null || _window$frameElement === void 0 ? void 0 : _window$frameElement.getAttribute(this.iframeChannelAttr);
|
|
7180
|
+
this.channelId = iframeChannelId || (0, _uuid.v4)();
|
|
7181
|
+
this.type = iframeChannelId ? 'iframe' : 'parent';
|
|
7182
|
+
}
|
|
7183
|
+
return _createClass(LiveContextAPI, [{
|
|
7184
|
+
key: "connectPostRobot",
|
|
7185
|
+
value: function () {
|
|
7186
|
+
var _connectPostRobot = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
7187
|
+
var _this = this;
|
|
7188
|
+
var targetWindow, postRobotEventName;
|
|
7189
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
7190
|
+
while (1) switch (_context.prev = _context.next) {
|
|
7191
|
+
case 0:
|
|
7192
|
+
_context.next = 2;
|
|
7193
|
+
return this.getTargetWindow();
|
|
7194
|
+
case 2:
|
|
7195
|
+
targetWindow = _context.sent;
|
|
7196
|
+
postRobotEventName = this.getPostRobotEventName(this.channelId);
|
|
7197
|
+
this.postRobotListener = postRobot.on(postRobotEventName, {
|
|
7198
|
+
window: targetWindow
|
|
7199
|
+
}, function (event) {
|
|
7200
|
+
if (event.data.type === 'init') {
|
|
7201
|
+
_this.setContext(function (context) {
|
|
7202
|
+
return _objectSpread(_objectSpread({}, context), event.data.context);
|
|
7203
|
+
});
|
|
7204
|
+
} else {
|
|
7205
|
+
_this.setContextAndNotify(function (context) {
|
|
7206
|
+
return _objectSpread(_objectSpread({}, context), event.data.context);
|
|
7207
|
+
});
|
|
7208
|
+
}
|
|
7209
|
+
return Promise.resolve();
|
|
7210
|
+
});
|
|
7211
|
+
_context.next = 7;
|
|
7212
|
+
return this.sendContextUpdate(true);
|
|
7213
|
+
case 7:
|
|
7214
|
+
case "end":
|
|
7215
|
+
return _context.stop();
|
|
7216
|
+
}
|
|
7217
|
+
}, _callee, this);
|
|
7218
|
+
}));
|
|
7219
|
+
function connectPostRobot() {
|
|
7220
|
+
return _connectPostRobot.apply(this, arguments);
|
|
7221
|
+
}
|
|
7222
|
+
return connectPostRobot;
|
|
7223
|
+
}()
|
|
7224
|
+
}, {
|
|
7225
|
+
key: "getConnectId",
|
|
7226
|
+
value: function getConnectId(contextAPI) {
|
|
7227
|
+
return "ContextAPI-".concat(contextAPI.id);
|
|
7228
|
+
}
|
|
7229
|
+
}, {
|
|
7230
|
+
key: "getTargetWindow",
|
|
7231
|
+
value: function () {
|
|
7232
|
+
var _getTargetWindow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
7233
|
+
var _this2 = this;
|
|
7234
|
+
var iframe;
|
|
7235
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
7236
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
7237
|
+
case 0:
|
|
7238
|
+
if (!(this.type === 'iframe' && window.top)) {
|
|
7239
|
+
_context2.next = 2;
|
|
7240
|
+
break;
|
|
7241
|
+
}
|
|
7242
|
+
return _context2.abrupt("return", window.top);
|
|
7243
|
+
case 2:
|
|
7244
|
+
iframe = document.querySelector("iframe[".concat(this.iframeChannelAttr, "='").concat(this.channelId, "']"));
|
|
7245
|
+
if (!(iframe !== null && iframe !== void 0 && iframe.contentWindow)) {
|
|
7246
|
+
_context2.next = 5;
|
|
7247
|
+
break;
|
|
7248
|
+
}
|
|
7249
|
+
return _context2.abrupt("return", iframe.contentWindow);
|
|
7250
|
+
case 5:
|
|
7251
|
+
return _context2.abrupt("return", new Promise(function (resolve) {
|
|
7252
|
+
var observer = new MutationObserver(function () {
|
|
7253
|
+
var iframe = document.querySelector("iframe[".concat(_this2.iframeChannelAttr, "='").concat(_this2.channelId, "']"));
|
|
7254
|
+
if (iframe !== null && iframe !== void 0 && iframe.contentWindow) {
|
|
7255
|
+
observer.disconnect();
|
|
7256
|
+
resolve(iframe.contentWindow);
|
|
7257
|
+
}
|
|
7258
|
+
});
|
|
7259
|
+
// Start observing
|
|
7260
|
+
observer.observe(document.body, {
|
|
7261
|
+
childList: true,
|
|
7262
|
+
subtree: true
|
|
7263
|
+
});
|
|
7264
|
+
}));
|
|
7265
|
+
case 6:
|
|
7266
|
+
case "end":
|
|
7267
|
+
return _context2.stop();
|
|
7268
|
+
}
|
|
7269
|
+
}, _callee2, this);
|
|
7270
|
+
}));
|
|
7271
|
+
function getTargetWindow() {
|
|
7272
|
+
return _getTargetWindow.apply(this, arguments);
|
|
7273
|
+
}
|
|
7274
|
+
return getTargetWindow;
|
|
7275
|
+
}()
|
|
7276
|
+
}, {
|
|
7277
|
+
key: "setContextAndNotify",
|
|
7278
|
+
value: function setContextAndNotify(context) {
|
|
7279
|
+
var _this3 = this;
|
|
7280
|
+
if (typeof context === 'function') {
|
|
7281
|
+
this.contextData = context(this.contextData);
|
|
7282
|
+
} else {
|
|
7283
|
+
this.contextData = context;
|
|
7284
|
+
}
|
|
7285
|
+
Object.values(this.listeners).forEach(function (listener) {
|
|
7286
|
+
return listener(_this3.contextData);
|
|
7287
|
+
});
|
|
7288
|
+
}
|
|
7289
|
+
}, {
|
|
7290
|
+
key: "getPostRobotEventName",
|
|
7291
|
+
value: function getPostRobotEventName(channelId) {
|
|
7292
|
+
return "".concat(channelId, "-").concat(CONTEXT_UPDATE_EVENT);
|
|
7293
|
+
}
|
|
7294
|
+
}, {
|
|
7295
|
+
key: "sendContextUpdate",
|
|
7296
|
+
value: function () {
|
|
7297
|
+
var _sendContextUpdate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
7298
|
+
var isInit,
|
|
7299
|
+
targetWindow,
|
|
7300
|
+
_args3 = arguments;
|
|
7301
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
7302
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
7303
|
+
case 0:
|
|
7304
|
+
isInit = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : false;
|
|
7305
|
+
_context3.prev = 1;
|
|
7306
|
+
_context3.next = 4;
|
|
7307
|
+
return this.getTargetWindow();
|
|
7308
|
+
case 4:
|
|
7309
|
+
targetWindow = _context3.sent;
|
|
7310
|
+
postRobot.send(targetWindow, this.getPostRobotEventName(this.channelId), _objectSpread({
|
|
7311
|
+
context: this.contextData
|
|
7312
|
+
}, isInit && {
|
|
7313
|
+
type: 'init'
|
|
7314
|
+
}));
|
|
7315
|
+
_context3.next = 11;
|
|
7316
|
+
break;
|
|
7317
|
+
case 8:
|
|
7318
|
+
_context3.prev = 8;
|
|
7319
|
+
_context3.t0 = _context3["catch"](1);
|
|
7320
|
+
// Silently ignore any errors during context update
|
|
7321
|
+
console.debug('Failed to send context update:', _context3.t0);
|
|
7322
|
+
case 11:
|
|
7323
|
+
case "end":
|
|
7324
|
+
return _context3.stop();
|
|
7325
|
+
}
|
|
7326
|
+
}, _callee3, this, [[1, 8]]);
|
|
7327
|
+
}));
|
|
7328
|
+
function sendContextUpdate() {
|
|
7329
|
+
return _sendContextUpdate.apply(this, arguments);
|
|
7330
|
+
}
|
|
7331
|
+
return sendContextUpdate;
|
|
7332
|
+
}()
|
|
7333
|
+
}, {
|
|
7334
|
+
key: "getContext",
|
|
7335
|
+
value: function getContext() {
|
|
7336
|
+
return this.contextData;
|
|
7337
|
+
}
|
|
7338
|
+
}, {
|
|
7339
|
+
key: "setContext",
|
|
7340
|
+
value: function () {
|
|
7341
|
+
var _setContext = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(context) {
|
|
7342
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
7343
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
7344
|
+
case 0:
|
|
7345
|
+
this.setContextAndNotify(context);
|
|
7346
|
+
_context4.next = 3;
|
|
7347
|
+
return this.sendContextUpdate();
|
|
7348
|
+
case 3:
|
|
7349
|
+
case "end":
|
|
7350
|
+
return _context4.stop();
|
|
7351
|
+
}
|
|
7352
|
+
}, _callee4, this);
|
|
7353
|
+
}));
|
|
7354
|
+
function setContext(_x) {
|
|
7355
|
+
return _setContext.apply(this, arguments);
|
|
7356
|
+
}
|
|
7357
|
+
return setContext;
|
|
7358
|
+
}()
|
|
7359
|
+
}, {
|
|
7360
|
+
key: "subscribeToChanges",
|
|
7361
|
+
value: function subscribeToChanges(idOrContextListener, contextListenerOrNothing) {
|
|
7362
|
+
var id = typeof idOrContextListener === 'string' ? idOrContextListener : (0, _uuid.v4)();
|
|
7363
|
+
var contextListener = typeof idOrContextListener === 'function' ? idOrContextListener : contextListenerOrNothing;
|
|
7364
|
+
if (!contextListener) {
|
|
7365
|
+
var error = new Error('Context listener is required');
|
|
7366
|
+
throw error;
|
|
7367
|
+
}
|
|
7368
|
+
this.listeners[id] = contextListener;
|
|
7369
|
+
return id;
|
|
7370
|
+
}
|
|
7371
|
+
}, {
|
|
7372
|
+
key: "unsubscribeFromChanges",
|
|
7373
|
+
value: function unsubscribeFromChanges(id) {
|
|
7374
|
+
delete this.listeners[id];
|
|
7375
|
+
}
|
|
7376
|
+
}, {
|
|
7377
|
+
key: "addContextListener",
|
|
7378
|
+
value: function addContextListener(LiveContextAPItoConnect) {
|
|
7379
|
+
var _this4 = this;
|
|
7380
|
+
var mapContext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (context) {
|
|
7381
|
+
return context;
|
|
7382
|
+
};
|
|
7383
|
+
// Merge the new context with existing context
|
|
7384
|
+
this.setContext(function (currentContext) {
|
|
7385
|
+
return _objectSpread(_objectSpread({}, currentContext), mapContext(LiveContextAPItoConnect.getContext()));
|
|
7386
|
+
});
|
|
7387
|
+
// Subscribe to changes if id is provided
|
|
7388
|
+
var subscriptionId = this.getConnectId(LiveContextAPItoConnect);
|
|
7389
|
+
LiveContextAPItoConnect.subscribeToChanges(subscriptionId, function (updatedContext) {
|
|
7390
|
+
_this4.setContext(function (currentContext) {
|
|
7391
|
+
return _objectSpread(_objectSpread({}, currentContext), mapContext(updatedContext));
|
|
7392
|
+
});
|
|
7393
|
+
});
|
|
7394
|
+
// Return a callback function that unsubscribes
|
|
7395
|
+
return function () {
|
|
7396
|
+
return _this4.unsubscribeFromChanges(subscriptionId);
|
|
7397
|
+
};
|
|
7398
|
+
}
|
|
7399
|
+
}, {
|
|
7400
|
+
key: "removeContextListener",
|
|
7401
|
+
value: function removeContextListener(idOrContextAPI) {
|
|
7402
|
+
var id = typeof idOrContextAPI === 'string' ? idOrContextAPI : this.getConnectId(idOrContextAPI);
|
|
7403
|
+
this.unsubscribeFromChanges(id);
|
|
7404
|
+
}
|
|
7405
|
+
}, {
|
|
7406
|
+
key: "connect",
|
|
7407
|
+
value: function connect() {
|
|
7408
|
+
var channelId = this.channelId;
|
|
7409
|
+
this.connectPostRobot();
|
|
7410
|
+
return channelId;
|
|
7411
|
+
}
|
|
7412
|
+
}, {
|
|
7413
|
+
key: "destroy",
|
|
7414
|
+
value: function destroy() {
|
|
7415
|
+
var _this$postRobotListen;
|
|
7416
|
+
(_this$postRobotListen = this.postRobotListener) === null || _this$postRobotListen === void 0 || _this$postRobotListen.cancel();
|
|
7417
|
+
}
|
|
7418
|
+
}]);
|
|
7419
|
+
}();
|
|
7420
|
+
|
|
7421
|
+
},{"post-robot":5,"uuid":6}],40:[function(require,module,exports){
|
|
7422
|
+
"use strict";
|
|
7423
|
+
|
|
7140
7424
|
Object.defineProperty(exports, "__esModule", {
|
|
7141
7425
|
value: true
|
|
7142
7426
|
});
|
|
@@ -7169,7 +7453,7 @@ var makeProxy = exports.makeProxy = function makeProxy(obj) {
|
|
|
7169
7453
|
return proxyObj;
|
|
7170
7454
|
};
|
|
7171
7455
|
|
|
7172
|
-
},{}],
|
|
7456
|
+
},{}],41:[function(require,module,exports){
|
|
7173
7457
|
"use strict";
|
|
7174
7458
|
|
|
7175
7459
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
@@ -7222,7 +7506,7 @@ var getOrCreateUsersPrivateWorkspaceRecord = exports.getOrCreateUsersPrivateWork
|
|
|
7222
7506
|
};
|
|
7223
7507
|
}();
|
|
7224
7508
|
|
|
7225
|
-
},{"uuid":6}],
|
|
7509
|
+
},{"uuid":6}],42:[function(require,module,exports){
|
|
7226
7510
|
"use strict";
|
|
7227
7511
|
|
|
7228
7512
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -7247,14 +7531,14 @@ var ONTOLOGY_PERMISSION_GROUP = exports.ONTOLOGY_PERMISSION_GROUP = 'octostar:on
|
|
|
7247
7531
|
var ALL_PERMISSIONS = exports.ALL_PERMISSIONS = 'all';
|
|
7248
7532
|
var ALL_PERMISSIONS_ARRAY = exports.ALL_PERMISSIONS_ARRAY = [ALL_PERMISSIONS];
|
|
7249
7533
|
|
|
7250
|
-
},{}],
|
|
7534
|
+
},{}],43:[function(require,module,exports){
|
|
7251
7535
|
"use strict";
|
|
7252
7536
|
|
|
7253
7537
|
Object.defineProperty(exports, "__esModule", {
|
|
7254
7538
|
value: true
|
|
7255
7539
|
});
|
|
7256
7540
|
|
|
7257
|
-
},{}],
|
|
7541
|
+
},{}],44:[function(require,module,exports){
|
|
7258
7542
|
"use strict";
|
|
7259
7543
|
|
|
7260
7544
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octostar/platform-api",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.20",
|
|
4
4
|
"description": "Provides access to the API exposed by Octostar platform to an application run in an iframe",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"octostar",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"module": "dist/index.js",
|
|
29
29
|
"types": "dist/index.d.ts",
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@types/post-robot": "^10.0.6",
|
|
31
32
|
"@types/uuid": "^9.0.2",
|
|
32
33
|
"post-robot": "^10.0.46",
|
|
33
34
|
"uuid": "^9.0.0"
|
|
@@ -38,10 +39,10 @@
|
|
|
38
39
|
"rimraf": "^5.0.5",
|
|
39
40
|
"tsup": "^8.4.0",
|
|
40
41
|
"typescript": "^5.8.2",
|
|
41
|
-
"@octostar/platform-types": "0.5.
|
|
42
|
+
"@octostar/platform-types": "0.5.24"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
|
-
"@octostar/platform-types": "^0.5.
|
|
45
|
+
"@octostar/platform-types": "^0.5.24"
|
|
45
46
|
},
|
|
46
47
|
"publishConfig": {
|
|
47
48
|
"access": "public"
|