@octostar/platform-api 0.5.14 → 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,5 +1,5 @@
|
|
|
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
4
|
channelId?: string;
|
|
5
5
|
};
|
|
@@ -11,9 +11,10 @@ export declare class ContextAPI<ContextData extends Record<string, any>> impleme
|
|
|
11
11
|
private postRobotListener;
|
|
12
12
|
private internalChannelId;
|
|
13
13
|
private postRobotEventId;
|
|
14
|
-
constructor({ targetWindow, contextData, channelId }: ContextAPIConstructorParams<ContextData>);
|
|
14
|
+
constructor({ targetWindow, contextData, channelId, }: ContextAPIConstructorParams<ContextData>);
|
|
15
15
|
get channelId(): string | undefined;
|
|
16
16
|
set channelId(channelId: string | undefined);
|
|
17
|
+
listenToPostRobot(): void;
|
|
17
18
|
get context(): ContextData;
|
|
18
19
|
set context(context: ContextData);
|
|
19
20
|
getContext(): ContextData;
|
|
@@ -25,5 +26,4 @@ export declare class ContextAPI<ContextData extends Record<string, any>> impleme
|
|
|
25
26
|
unsubscribeFromChanges(id: string): void;
|
|
26
27
|
destroy(): void;
|
|
27
28
|
}
|
|
28
|
-
export {};
|
|
29
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/ContextA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;IAqBT,sBAAsB,CAAC,EAAE,EAAE,MAAM;IAIjC,OAAO;CAGR"}
|
package/dist/lib/ContextAPI.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
2
|
import postRobot from 'post-robot';
|
|
3
3
|
export class ContextAPI {
|
|
4
|
-
constructor({ targetWindow, contextData, channelId }) {
|
|
4
|
+
constructor({ targetWindow, contextData, channelId, }) {
|
|
5
5
|
this.contextData = contextData;
|
|
6
6
|
this.listeners = {};
|
|
7
7
|
this.id = uuidv4();
|
|
8
8
|
this.targetWindow = targetWindow;
|
|
9
9
|
this.channelId = channelId;
|
|
10
|
-
this.postRobotListener = postRobot.on(this.postRobotEventId, (event) => {
|
|
11
|
-
if (event.data.from !== this.id) {
|
|
12
|
-
this.contextData = { ...this.contextData, ...event.data.contextData };
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
10
|
}
|
|
16
11
|
get channelId() {
|
|
17
12
|
return this.internalChannelId;
|
|
@@ -20,7 +15,22 @@ export class ContextAPI {
|
|
|
20
15
|
this.internalChannelId = channelId;
|
|
21
16
|
if (channelId) {
|
|
22
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();
|
|
23
27
|
}
|
|
28
|
+
this.postRobotListener = postRobot.on(this.postRobotEventId, event => {
|
|
29
|
+
if (event.data.from !== this.id) {
|
|
30
|
+
this.contextData = { ...this.contextData, ...event.data.contextData };
|
|
31
|
+
}
|
|
32
|
+
return Promise.resolve();
|
|
33
|
+
});
|
|
24
34
|
}
|
|
25
35
|
get context() {
|
|
26
36
|
return this.contextData;
|
|
@@ -41,7 +51,7 @@ export class ContextAPI {
|
|
|
41
51
|
Object.values(this.listeners).forEach(listener => listener(this.context));
|
|
42
52
|
}
|
|
43
53
|
async syncContextToChannel() {
|
|
44
|
-
if (!this.targetWindow) {
|
|
54
|
+
if (!this.targetWindow || !this.postRobotEventId) {
|
|
45
55
|
return;
|
|
46
56
|
}
|
|
47
57
|
/** Try to exclude functions in the context */
|
|
@@ -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;QACnC,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,gBAAgB,GAAG,uBAAuB,SAAS,EAAE,CAAC;YAC3D,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,iBAAiB;QACf,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC3B,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,iBAAiB,EAA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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,7 +7094,6 @@ 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
7098
|
contextData = _ref.contextData,
|
|
7100
7099
|
channelId = _ref.channelId;
|
|
@@ -7104,11 +7103,6 @@ var ContextAPI = exports.ContextAPI = /*#__PURE__*/function () {
|
|
|
7104
7103
|
this.id = (0, _uuid.v4)();
|
|
7105
7104
|
this.targetWindow = targetWindow;
|
|
7106
7105
|
this.channelId = channelId;
|
|
7107
|
-
this.postRobotListener = _postRobot["default"].on(this.postRobotEventId, function (event) {
|
|
7108
|
-
if (event.data.from !== _this.id) {
|
|
7109
|
-
_this.contextData = _objectSpread(_objectSpread({}, _this.contextData), event.data.contextData);
|
|
7110
|
-
}
|
|
7111
|
-
});
|
|
7112
7106
|
}
|
|
7113
7107
|
return _createClass(ContextAPI, [{
|
|
7114
7108
|
key: "channelId",
|
|
@@ -7119,7 +7113,25 @@ var ContextAPI = exports.ContextAPI = /*#__PURE__*/function () {
|
|
|
7119
7113
|
this.internalChannelId = channelId;
|
|
7120
7114
|
if (channelId) {
|
|
7121
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();
|
|
7122
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
|
+
});
|
|
7123
7135
|
}
|
|
7124
7136
|
}, {
|
|
7125
7137
|
key: "context",
|
|
@@ -7156,7 +7168,7 @@ var ContextAPI = exports.ContextAPI = /*#__PURE__*/function () {
|
|
|
7156
7168
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
7157
7169
|
while (1) switch (_context.prev = _context.next) {
|
|
7158
7170
|
case 0:
|
|
7159
|
-
if (this.targetWindow) {
|
|
7171
|
+
if (!(!this.targetWindow || !this.postRobotEventId)) {
|
|
7160
7172
|
_context.next = 2;
|
|
7161
7173
|
break;
|
|
7162
7174
|
}
|
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"
|