@octostar/platform-api 0.5.13 → 0.5.15
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/lib/ContextAPI.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { Context, ContextAPISetParams, ContextAPIStaticData, ContextListener } from '@octostar/platform-types';
|
|
2
|
-
type ContextAPIConstructorParams<ContextData extends Record<string, any>> = ContextAPIStaticData<ContextData> & {
|
|
2
|
+
export type ContextAPIConstructorParams<ContextData extends Record<string, any>> = ContextAPIStaticData<ContextData> & {
|
|
3
3
|
targetWindow?: Window;
|
|
4
|
+
channelId?: string;
|
|
4
5
|
};
|
|
5
6
|
export declare class ContextAPI<ContextData extends Record<string, any>> implements Context<ContextData> {
|
|
6
7
|
private contextData;
|
|
7
8
|
targetWindow: Window | undefined;
|
|
8
9
|
readonly id: string;
|
|
9
10
|
private listeners;
|
|
11
|
+
private postRobotListener;
|
|
12
|
+
private internalChannelId;
|
|
10
13
|
private postRobotEventId;
|
|
11
|
-
constructor({ targetWindow, contextData }: ContextAPIConstructorParams<ContextData>);
|
|
14
|
+
constructor({ targetWindow, contextData, channelId, }: ContextAPIConstructorParams<ContextData>);
|
|
15
|
+
get channelId(): string | undefined;
|
|
16
|
+
set channelId(channelId: string | undefined);
|
|
17
|
+
listenToPostRobot(): void;
|
|
12
18
|
get context(): ContextData;
|
|
13
19
|
set context(context: ContextData);
|
|
14
20
|
getContext(): ContextData;
|
|
@@ -18,6 +24,6 @@ export declare class ContextAPI<ContextData extends Record<string, any>> impleme
|
|
|
18
24
|
subscribeToChanges(contextListener: ContextListener<ContextData>): string;
|
|
19
25
|
subscribeToChanges(id: string, contextListener: ContextListener<ContextData>): string;
|
|
20
26
|
unsubscribeFromChanges(id: string): void;
|
|
27
|
+
destroy(): void;
|
|
21
28
|
}
|
|
22
|
-
export {};
|
|
23
29
|
//# sourceMappingURL=ContextAPI.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextAPI.d.ts","sourceRoot":"","sources":["../../src/lib/ContextAPI.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ContextAPI.d.ts","sourceRoot":"","sources":["../../src/lib/ContextAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAIlC,MAAM,MAAM,2BAA2B,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAC7E,oBAAoB,CAAC,WAAW,CAAC,GAAG;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEJ,qBAAa,UAAU,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAC7D,YAAW,OAAO,CAAC,WAAW,CAAC;IAE/B,OAAO,CAAC,WAAW,CAAc;IAE1B,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAExC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,OAAO,CAAC,SAAS,CAA+C;IAEhE,OAAO,CAAC,iBAAiB,CAAM;IAE/B,OAAO,CAAC,iBAAiB,CAAqB;IAE9C,OAAO,CAAC,gBAAgB,CAAqB;gBAEjC,EACV,YAAY,EACZ,WAAW,EACX,SAAS,GACV,EAAE,2BAA2B,CAAC,WAAW,CAAC;IAQ3C,IAAI,SAAS,IAIY,MAAM,GAAG,SAAS,CAF1C;IAED,IAAI,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAM1C;IAED,iBAAiB;IAgBjB,IAAI,OAAO,IAIU,WAAW,CAF/B;IAED,IAAI,OAAO,CAAC,OAAO,EAAE,WAAW,EAK/B;IAED,UAAU;IAIV,UAAU,CAAC,OAAO,EAAE,mBAAmB,CAAC,WAAW,CAAC;IAKpD,eAAe;IAIT,oBAAoB;IAc1B,kBAAkB,CAAC,eAAe,EAAE,eAAe,CAAC,WAAW,CAAC,GAAG,MAAM;IAEzE,kBAAkB,CAChB,EAAE,EAAE,MAAM,EACV,eAAe,EAAE,eAAe,CAAC,WAAW,CAAC,GAC5C,MAAM;IAqBT,sBAAsB,CAAC,EAAE,EAAE,MAAM;IAIjC,OAAO;CAGR"}
|
package/dist/lib/ContextAPI.js
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
2
|
import postRobot from 'post-robot';
|
|
3
3
|
export class ContextAPI {
|
|
4
|
-
constructor({ targetWindow, contextData }) {
|
|
5
|
-
this.postRobotEventId = 'context-api-update';
|
|
4
|
+
constructor({ targetWindow, contextData, channelId, }) {
|
|
6
5
|
this.contextData = contextData;
|
|
7
6
|
this.listeners = {};
|
|
8
7
|
this.id = uuidv4();
|
|
9
8
|
this.targetWindow = targetWindow;
|
|
10
|
-
|
|
9
|
+
this.channelId = channelId;
|
|
10
|
+
}
|
|
11
|
+
get channelId() {
|
|
12
|
+
return this.internalChannelId;
|
|
13
|
+
}
|
|
14
|
+
set channelId(channelId) {
|
|
15
|
+
this.internalChannelId = channelId;
|
|
16
|
+
if (channelId) {
|
|
17
|
+
this.postRobotEventId = `context-api-update::${channelId}`;
|
|
18
|
+
this.listenToPostRobot();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
listenToPostRobot() {
|
|
22
|
+
if (!this.postRobotEventId) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (this.postRobotListener) {
|
|
26
|
+
this.postRobotListener.cancel();
|
|
27
|
+
}
|
|
28
|
+
this.postRobotListener = postRobot.on(this.postRobotEventId, event => {
|
|
11
29
|
if (event.data.from !== this.id) {
|
|
12
30
|
this.contextData = { ...this.contextData, ...event.data.contextData };
|
|
13
31
|
}
|
|
32
|
+
return Promise.resolve();
|
|
14
33
|
});
|
|
15
34
|
}
|
|
16
35
|
get context() {
|
|
@@ -32,7 +51,7 @@ export class ContextAPI {
|
|
|
32
51
|
Object.values(this.listeners).forEach(listener => listener(this.context));
|
|
33
52
|
}
|
|
34
53
|
async syncContextToChannel() {
|
|
35
|
-
if (!this.targetWindow) {
|
|
54
|
+
if (!this.targetWindow || !this.postRobotEventId) {
|
|
36
55
|
return;
|
|
37
56
|
}
|
|
38
57
|
/** Try to exclude functions in the context */
|
|
@@ -56,5 +75,8 @@ export class ContextAPI {
|
|
|
56
75
|
unsubscribeFromChanges(id) {
|
|
57
76
|
delete this.listeners[id];
|
|
58
77
|
}
|
|
78
|
+
destroy() {
|
|
79
|
+
this.postRobotListener.cancel();
|
|
80
|
+
}
|
|
59
81
|
}
|
|
60
82
|
//# sourceMappingURL=ContextAPI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextAPI.js","sourceRoot":"","sources":["../../src/lib/ContextAPI.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContextAPI.js","sourceRoot":"","sources":["../../src/lib/ContextAPI.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,SAAS,MAAM,YAAY,CAAC;AAQnC,MAAM,OAAO,UAAU;IAiBrB,YAAY,EACV,YAAY,EACZ,WAAW,EACX,SAAS,GACgC;QACzC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED,IAAI,SAAS,CAAC,SAA6B;QACzC,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;Q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AAC,SAAS,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,KAAK,CAAC,oBAAoB;QACxB,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACjD,OAAO;QACT,CAAC;QAED,8CAA8C;QAC9C,uDAAuD;QAEvD,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,gBAAgB,EAAE;YAC7D,IAAI,EAAE,IAAI,CAAC,EAAE;YACb,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;IACL,CAAC;IASD,kBAAkB,CAChB,mBAA0D,EAC1D,wBAAuD;QAEvD,MAAM,EAAE,GACN,OAAO,mBAAmB,KAAK,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAC3E,MAAM,eAAe,GACnB,OAAO,mBAAmB,KAAK,UAAU;YACvC,CAAC,CAAC,mBAAmB;YACrB,CAAC,CAAC,wBAAwB,CAAC;QAE/B,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC;QACrC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,sBAAsB,CAAC,EAAU;QAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO;QACL,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -7094,22 +7094,46 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
7094
7094
|
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); }
|
|
7095
7095
|
var ContextAPI = exports.ContextAPI = /*#__PURE__*/function () {
|
|
7096
7096
|
function ContextAPI(_ref) {
|
|
7097
|
-
var _this = this;
|
|
7098
7097
|
var targetWindow = _ref.targetWindow,
|
|
7099
|
-
contextData = _ref.contextData
|
|
7098
|
+
contextData = _ref.contextData,
|
|
7099
|
+
channelId = _ref.channelId;
|
|
7100
7100
|
_classCallCheck(this, ContextAPI);
|
|
7101
|
-
this.postRobotEventId = 'context-api-update';
|
|
7102
7101
|
this.contextData = contextData;
|
|
7103
7102
|
this.listeners = {};
|
|
7104
7103
|
this.id = (0, _uuid.v4)();
|
|
7105
7104
|
this.targetWindow = targetWindow;
|
|
7106
|
-
|
|
7107
|
-
if (event.data.from !== _this.id) {
|
|
7108
|
-
_this.contextData = _objectSpread(_objectSpread({}, _this.contextData), event.data.contextData);
|
|
7109
|
-
}
|
|
7110
|
-
});
|
|
7105
|
+
this.channelId = channelId;
|
|
7111
7106
|
}
|
|
7112
7107
|
return _createClass(ContextAPI, [{
|
|
7108
|
+
key: "channelId",
|
|
7109
|
+
get: function get() {
|
|
7110
|
+
return this.internalChannelId;
|
|
7111
|
+
},
|
|
7112
|
+
set: function set(channelId) {
|
|
7113
|
+
this.internalChannelId = channelId;
|
|
7114
|
+
if (channelId) {
|
|
7115
|
+
this.postRobotEventId = "context-api-update::".concat(channelId);
|
|
7116
|
+
this.listenToPostRobot();
|
|
7117
|
+
}
|
|
7118
|
+
}
|
|
7119
|
+
}, {
|
|
7120
|
+
key: "listenToPostRobot",
|
|
7121
|
+
value: function listenToPostRobot() {
|
|
7122
|
+
var _this = this;
|
|
7123
|
+
if (!this.postRobotEventId) {
|
|
7124
|
+
return;
|
|
7125
|
+
}
|
|
7126
|
+
if (this.postRobotListener) {
|
|
7127
|
+
this.postRobotListener.cancel();
|
|
7128
|
+
}
|
|
7129
|
+
this.postRobotListener = _postRobot["default"].on(this.postRobotEventId, function (event) {
|
|
7130
|
+
if (event.data.from !== _this.id) {
|
|
7131
|
+
_this.contextData = _objectSpread(_objectSpread({}, _this.contextData), event.data.contextData);
|
|
7132
|
+
}
|
|
7133
|
+
return Promise.resolve();
|
|
7134
|
+
});
|
|
7135
|
+
}
|
|
7136
|
+
}, {
|
|
7113
7137
|
key: "context",
|
|
7114
7138
|
get: function get() {
|
|
7115
7139
|
return this.contextData;
|
|
@@ -7144,7 +7168,7 @@ var ContextAPI = exports.ContextAPI = /*#__PURE__*/function () {
|
|
|
7144
7168
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
7145
7169
|
while (1) switch (_context.prev = _context.next) {
|
|
7146
7170
|
case 0:
|
|
7147
|
-
if (this.targetWindow) {
|
|
7171
|
+
if (!(!this.targetWindow || !this.postRobotEventId)) {
|
|
7148
7172
|
_context.next = 2;
|
|
7149
7173
|
break;
|
|
7150
7174
|
}
|
|
@@ -7182,6 +7206,11 @@ var ContextAPI = exports.ContextAPI = /*#__PURE__*/function () {
|
|
|
7182
7206
|
value: function unsubscribeFromChanges(id) {
|
|
7183
7207
|
delete this.listeners[id];
|
|
7184
7208
|
}
|
|
7209
|
+
}, {
|
|
7210
|
+
key: "destroy",
|
|
7211
|
+
value: function destroy() {
|
|
7212
|
+
this.postRobotListener.cancel();
|
|
7213
|
+
}
|
|
7185
7214
|
}]);
|
|
7186
7215
|
}();
|
|
7187
7216
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octostar/platform-api",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.15",
|
|
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",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"rimraf": "^5.0.5",
|
|
39
39
|
"tsup": "^8.4.0",
|
|
40
40
|
"typescript": "^5.8.2",
|
|
41
|
-
"@octostar/platform-types": "0.5.
|
|
41
|
+
"@octostar/platform-types": "0.5.18"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@octostar/platform-types": "^0.5.
|
|
44
|
+
"@octostar/platform-types": "^0.5.18"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|