@octostar/platform-api 0.5.12 → 0.5.13
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 +8 -9
- package/dist/lib/ContextAPI.d.ts.map +1 -1
- package/dist/lib/ContextAPI.js +19 -28
- package/dist/lib/ContextAPI.js.map +1 -1
- package/dist/lib/classInstanceToObject.d.ts +1 -1
- package/dist/lib/classInstanceToObject.d.ts.map +1 -1
- package/dist/lib/classInstanceToObject.js +39 -36
- package/dist/lib/classInstanceToObject.js.map +1 -1
- package/dist/octostar-platform-api.js +95 -87
- package/package.json +3 -3
package/dist/lib/ContextAPI.d.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { Context, ContextAPISetParams, ContextAPIStaticData, ContextListener } from '@octostar/platform-types';
|
|
2
|
-
type
|
|
3
|
-
|
|
2
|
+
type ContextAPIConstructorParams<ContextData extends Record<string, any>> = ContextAPIStaticData<ContextData> & {
|
|
3
|
+
targetWindow?: Window;
|
|
4
4
|
};
|
|
5
5
|
export declare class ContextAPI<ContextData extends Record<string, any>> implements Context<ContextData> {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
private contextData;
|
|
7
|
+
targetWindow: Window | undefined;
|
|
8
|
+
readonly id: string;
|
|
8
9
|
private listeners;
|
|
9
|
-
private
|
|
10
|
-
constructor({
|
|
10
|
+
private postRobotEventId;
|
|
11
|
+
constructor({ targetWindow, contextData }: ContextAPIConstructorParams<ContextData>);
|
|
11
12
|
get context(): ContextData;
|
|
12
13
|
set context(context: ContextData);
|
|
13
|
-
get channelId(): string | undefined;
|
|
14
|
-
set channelId(channelId: string | undefined);
|
|
15
14
|
getContext(): ContextData;
|
|
16
15
|
setContext(context: ContextAPISetParams<ContextData>): void;
|
|
17
16
|
notifyListeners(): void;
|
|
18
|
-
syncContextToChannel(): void
|
|
17
|
+
syncContextToChannel(): Promise<void>;
|
|
19
18
|
subscribeToChanges(contextListener: ContextListener<ContextData>): string;
|
|
20
19
|
subscribeToChanges(id: string, contextListener: ContextListener<ContextData>): string;
|
|
21
20
|
unsubscribeFromChanges(id: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextAPI.d.ts","sourceRoot":"","sources":["../../src/lib/ContextAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"ContextAPI.d.ts","sourceRoot":"","sources":["../../src/lib/ContextAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAK/G,KAAK,2BAA2B,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,oBAAoB,CAAC,WAAW,CAAC,GAAG;IAC9G,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,qBAAa,UAAU,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAE,YAAW,OAAO,CAAC,WAAW,CAAC;IAC9F,OAAO,CAAC,WAAW,CAAa;IAEzB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAExC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,OAAO,CAAC,SAAS,CAA+C;IAEhE,OAAO,CAAC,gBAAgB,CAAwB;gBAEpC,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,2BAA2B,CAAC,WAAW,CAAC;IAanF,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;CAGlC"}
|
package/dist/lib/ContextAPI.js
CHANGED
|
@@ -1,36 +1,26 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
-
import
|
|
2
|
+
import postRobot from 'post-robot';
|
|
3
3
|
export class ContextAPI {
|
|
4
|
-
constructor({
|
|
5
|
-
this.
|
|
4
|
+
constructor({ targetWindow, contextData }) {
|
|
5
|
+
this.postRobotEventId = 'context-api-update';
|
|
6
|
+
this.contextData = contextData;
|
|
6
7
|
this.listeners = {};
|
|
7
|
-
this.id =
|
|
8
|
-
this.
|
|
8
|
+
this.id = uuidv4();
|
|
9
|
+
this.targetWindow = targetWindow;
|
|
10
|
+
postRobot.on(this.postRobotEventId, (event) => {
|
|
11
|
+
if (event.data.from !== this.id) {
|
|
12
|
+
this.contextData = { ...this.contextData, ...event.data.contextData };
|
|
13
|
+
}
|
|
14
|
+
});
|
|
9
15
|
}
|
|
10
16
|
get context() {
|
|
11
|
-
return this.
|
|
17
|
+
return this.contextData;
|
|
12
18
|
}
|
|
13
19
|
set context(context) {
|
|
14
|
-
this.
|
|
20
|
+
this.contextData = context;
|
|
15
21
|
this.notifyListeners();
|
|
16
22
|
this.syncContextToChannel();
|
|
17
23
|
}
|
|
18
|
-
get channelId() {
|
|
19
|
-
return this.static_data.channelId;
|
|
20
|
-
}
|
|
21
|
-
set channelId(channelId) {
|
|
22
|
-
this.static_data.channelId = channelId;
|
|
23
|
-
const contextChannelId = this.static_data.channelId && `ContextAPI-${this.static_data.channelId}`;
|
|
24
|
-
if (!contextChannelId) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
this.channel = new BroadcastChannel(contextChannelId);
|
|
28
|
-
this.channel.onmessage = (event) => {
|
|
29
|
-
if (event.data.from !== this.id) {
|
|
30
|
-
this.static_data.context = event.data.context;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
24
|
getContext() {
|
|
35
25
|
return this.context;
|
|
36
26
|
}
|
|
@@ -41,14 +31,15 @@ export class ContextAPI {
|
|
|
41
31
|
notifyListeners() {
|
|
42
32
|
Object.values(this.listeners).forEach(listener => listener(this.context));
|
|
43
33
|
}
|
|
44
|
-
syncContextToChannel() {
|
|
45
|
-
if (!this.
|
|
34
|
+
async syncContextToChannel() {
|
|
35
|
+
if (!this.targetWindow) {
|
|
46
36
|
return;
|
|
47
37
|
}
|
|
48
|
-
|
|
49
|
-
this.
|
|
38
|
+
/** Try to exclude functions in the context */
|
|
39
|
+
// const context = classInstanceToObject(this.context);
|
|
40
|
+
await postRobot.send(this.targetWindow, this.postRobotEventId, {
|
|
50
41
|
from: this.id,
|
|
51
|
-
context,
|
|
42
|
+
context: this.context,
|
|
52
43
|
});
|
|
53
44
|
}
|
|
54
45
|
subscribeToChanges(idOrContextListener, contextListenerOrNothing) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextAPI.js","sourceRoot":"","sources":["../../src/lib/ContextAPI.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"ContextAPI.js","sourceRoot":"","sources":["../../src/lib/ContextAPI.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,SAAS,MAAM,YAAY,CAAC;AAMnC,MAAM,OAAO,UAAU;IAWrB,YAAY,EAAE,YAAY,EAAE,WAAW,EAA4C;QAF3E,qBAAgB,GAAG,oBAAoB,CAAC;QAG9C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,KAA2D,EAAE,EAAE;YAClG,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC;gBAChC,IAAI,CAAC,WAAW,GAAG,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACxE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,OAAO,CAAC,OAAoB;QAC9B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;QAE3B,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC9B,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,UAAU,CAAC,OAAyC;QAClD,IAAI,CAAC,OAAO;YACV,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACpE,CAAC;IAED,eAAe;QACb,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,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,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QAED,8CAA8C;QAC9C,uDAAuD;QAExD,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,gBAAgB,EAAE;YAC1D,IAAI,EAAE,IAAI,CAAC,EAAE;YACb,OAAO,EAAE,IAAI,CAAC,OAAO;SACxB,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;CACF"}
|
|
@@ -8,5 +8,5 @@ export declare const classInstanceToObject: <T extends {
|
|
|
8
8
|
}) => boolean;
|
|
9
9
|
};
|
|
10
10
|
methodWrappers?: { [K in keyof T]?: (fn: T[K], ...args: T[K] extends (...args: infer P) => any ? P : never) => T[K] extends (...args: any) => infer R ? R : never; };
|
|
11
|
-
}) =>
|
|
11
|
+
}) => Record<string, any>;
|
|
12
12
|
//# sourceMappingURL=classInstanceToObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classInstanceToObject.d.ts","sourceRoot":"","sources":["../../src/lib/classInstanceToObject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"classInstanceToObject.d.ts","sourceRoot":"","sources":["../../src/lib/classInstanceToObject.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EACpE,UAAU,CAAC,EACX,UAAU;IACR,OAAO,CAAC,EAAE;QACR,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC;KACvE,CAAC;IACF,cAAc,CAAC,EAAE,GACd,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CACf,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EACR,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,KACxD,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,GACxD,CAAC;CACH,KACA,MAAM,CAAC,MAAM,EAAE,GAAG,CAsCpB,CAAC"}
|
|
@@ -1,44 +1,47 @@
|
|
|
1
|
+
// Check if an object contains functions deeply
|
|
2
|
+
const containsDeepFunction = (obj) => {
|
|
3
|
+
if (obj === null || obj === undefined) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
if (typeof obj === 'function') {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (typeof obj !== 'object') {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(obj)) {
|
|
13
|
+
return obj.some(item => containsDeepFunction(item));
|
|
14
|
+
}
|
|
15
|
+
return Object.values(obj).some(value => containsDeepFunction(value));
|
|
16
|
+
};
|
|
1
17
|
export const classInstanceToObject = (instance, options) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// ...Object.getOwnPropertyNames(instance),
|
|
6
|
-
// ...Object.getOwnPropertyNames(prototype),
|
|
7
|
-
];
|
|
8
|
-
let currentClass = instance;
|
|
9
|
-
while (currentClass && currentClass !== Object) {
|
|
10
|
-
// console.log('current class', currentClass); // TODO: test if it omits the Object methods
|
|
11
|
-
properties.push(...Object.getOwnPropertyNames(currentClass));
|
|
12
|
-
currentClass = Object.getPrototypeOf(currentClass);
|
|
18
|
+
// Handle null or undefined
|
|
19
|
+
if (instance === null || instance === undefined) {
|
|
20
|
+
return instance;
|
|
13
21
|
}
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
// Handle primitive values
|
|
23
|
+
if (typeof instance !== 'object' || instance instanceof Date) {
|
|
24
|
+
return instance;
|
|
25
|
+
}
|
|
26
|
+
// Handle arrays
|
|
27
|
+
if (Array.isArray(instance)) {
|
|
28
|
+
return instance.map(item => classInstanceToObject(item, options));
|
|
29
|
+
}
|
|
30
|
+
// Handle objects
|
|
31
|
+
const obj = {};
|
|
32
|
+
// Get all own properties (data properties, not methods)
|
|
33
|
+
Object.keys(instance).forEach(key => {
|
|
34
|
+
const value = instance[key];
|
|
35
|
+
// Skip functions directly
|
|
36
|
+
if (typeof value === 'function') {
|
|
16
37
|
return;
|
|
17
38
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
? method.bind(instance)
|
|
22
|
-
: method;
|
|
23
|
-
if (options?.globals?.canCallAction) {
|
|
24
|
-
const originalMethod = method;
|
|
25
|
-
method = (...args) => {
|
|
26
|
-
const canCall = options.globals.canCallAction({
|
|
27
|
-
method: method.name,
|
|
28
|
-
class: instance.constructor.name,
|
|
29
|
-
});
|
|
30
|
-
if (!canCall) {
|
|
31
|
-
throw new Error(`No permissions for call: ${method.name}`); // TODO: consider usage of a specific permissions error
|
|
32
|
-
}
|
|
33
|
-
return originalMethod(...args);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (typeof options?.methodWrappers?.[property] === 'function') {
|
|
37
|
-
obj[property] = (...args) => options.methodWrappers[property](method, ...args);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
obj[property] = (...args) => method(...args);
|
|
39
|
+
// Skip properties that contain functions deeply
|
|
40
|
+
if (typeof value === 'object' && value !== null && containsDeepFunction(value)) {
|
|
41
|
+
return;
|
|
41
42
|
}
|
|
43
|
+
// Recursively convert nested objects
|
|
44
|
+
obj[key] = classInstanceToObject(value, options);
|
|
42
45
|
});
|
|
43
46
|
return obj;
|
|
44
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classInstanceToObject.js","sourceRoot":"","sources":["../../src/lib/classInstanceToObject.ts"],"names":[],"mappings":"AAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"classInstanceToObject.js","sourceRoot":"","sources":["../../src/lib/classInstanceToObject.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,oBAAoB,GAAG,CAAC,GAAQ,EAAW,EAAE;IACjD,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,QAAW,EACX,OAUC,EACoB,EAAE;IACvB,2BAA2B;IAC3B,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,QAAe,CAAC;IACzB,CAAC;IAED,0BAA0B;IAC1B,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,YAAY,IAAI,EAAE,CAAC;QAC7D,OAAO,QAAe,CAAC;IACzB,CAAC;IAED,gBAAgB;IAChB,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAQ,CAAC;IAC3E,CAAC;IAED,iBAAiB;IACjB,MAAM,GAAG,GAAwB,EAAE,CAAC;IAEpC,wDAAwD;IACxD,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAClC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAE5B,0BAA0B;QAC1B,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QAED,gDAAgD;QAChD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/E,OAAO;QACT,CAAC;QAED,qCAAqC;QACrC,GAAG,CAAC,GAAG,CAAC,GAAG,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -7078,11 +7078,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7078
7078
|
});
|
|
7079
7079
|
exports.ContextAPI = void 0;
|
|
7080
7080
|
var _uuid = require("uuid");
|
|
7081
|
-
var
|
|
7082
|
-
|
|
7081
|
+
var _postRobot = _interopRequireDefault(require("post-robot"));
|
|
7082
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
7083
7083
|
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); }
|
|
7084
|
-
function
|
|
7085
|
-
function
|
|
7084
|
+
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; }
|
|
7085
|
+
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); }
|
|
7086
|
+
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); }); }; }
|
|
7087
|
+
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; }
|
|
7088
|
+
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; }
|
|
7089
|
+
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; }
|
|
7086
7090
|
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
7087
7091
|
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); } }
|
|
7088
7092
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
@@ -7090,43 +7094,31 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
7090
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); }
|
|
7091
7095
|
var ContextAPI = exports.ContextAPI = /*#__PURE__*/function () {
|
|
7092
7096
|
function ContextAPI(_ref) {
|
|
7093
|
-
var
|
|
7094
|
-
|
|
7097
|
+
var _this = this;
|
|
7098
|
+
var targetWindow = _ref.targetWindow,
|
|
7099
|
+
contextData = _ref.contextData;
|
|
7095
7100
|
_classCallCheck(this, ContextAPI);
|
|
7096
|
-
this.
|
|
7101
|
+
this.postRobotEventId = 'context-api-update';
|
|
7102
|
+
this.contextData = contextData;
|
|
7097
7103
|
this.listeners = {};
|
|
7098
|
-
this.id =
|
|
7099
|
-
this.
|
|
7104
|
+
this.id = (0, _uuid.v4)();
|
|
7105
|
+
this.targetWindow = targetWindow;
|
|
7106
|
+
_postRobot["default"].on(this.postRobotEventId, function (event) {
|
|
7107
|
+
if (event.data.from !== _this.id) {
|
|
7108
|
+
_this.contextData = _objectSpread(_objectSpread({}, _this.contextData), event.data.contextData);
|
|
7109
|
+
}
|
|
7110
|
+
});
|
|
7100
7111
|
}
|
|
7101
7112
|
return _createClass(ContextAPI, [{
|
|
7102
7113
|
key: "context",
|
|
7103
7114
|
get: function get() {
|
|
7104
|
-
return this.
|
|
7115
|
+
return this.contextData;
|
|
7105
7116
|
},
|
|
7106
7117
|
set: function set(context) {
|
|
7107
|
-
this.
|
|
7118
|
+
this.contextData = context;
|
|
7108
7119
|
this.notifyListeners();
|
|
7109
7120
|
this.syncContextToChannel();
|
|
7110
7121
|
}
|
|
7111
|
-
}, {
|
|
7112
|
-
key: "channelId",
|
|
7113
|
-
get: function get() {
|
|
7114
|
-
return this.static_data.channelId;
|
|
7115
|
-
},
|
|
7116
|
-
set: function set(channelId) {
|
|
7117
|
-
var _this = this;
|
|
7118
|
-
this.static_data.channelId = channelId;
|
|
7119
|
-
var contextChannelId = this.static_data.channelId && "ContextAPI-".concat(this.static_data.channelId);
|
|
7120
|
-
if (!contextChannelId) {
|
|
7121
|
-
return;
|
|
7122
|
-
}
|
|
7123
|
-
this.channel = new BroadcastChannel(contextChannelId);
|
|
7124
|
-
this.channel.onmessage = function (event) {
|
|
7125
|
-
if (event.data.from !== _this.id) {
|
|
7126
|
-
_this.static_data.context = event.data.context;
|
|
7127
|
-
}
|
|
7128
|
-
};
|
|
7129
|
-
}
|
|
7130
7122
|
}, {
|
|
7131
7123
|
key: "getContext",
|
|
7132
7124
|
value: function getContext() {
|
|
@@ -7147,16 +7139,33 @@ var ContextAPI = exports.ContextAPI = /*#__PURE__*/function () {
|
|
|
7147
7139
|
}
|
|
7148
7140
|
}, {
|
|
7149
7141
|
key: "syncContextToChannel",
|
|
7150
|
-
value: function
|
|
7151
|
-
|
|
7152
|
-
return
|
|
7142
|
+
value: function () {
|
|
7143
|
+
var _syncContextToChannel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
7144
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
7145
|
+
while (1) switch (_context.prev = _context.next) {
|
|
7146
|
+
case 0:
|
|
7147
|
+
if (this.targetWindow) {
|
|
7148
|
+
_context.next = 2;
|
|
7149
|
+
break;
|
|
7150
|
+
}
|
|
7151
|
+
return _context.abrupt("return");
|
|
7152
|
+
case 2:
|
|
7153
|
+
_context.next = 4;
|
|
7154
|
+
return _postRobot["default"].send(this.targetWindow, this.postRobotEventId, {
|
|
7155
|
+
from: this.id,
|
|
7156
|
+
context: this.context
|
|
7157
|
+
});
|
|
7158
|
+
case 4:
|
|
7159
|
+
case "end":
|
|
7160
|
+
return _context.stop();
|
|
7161
|
+
}
|
|
7162
|
+
}, _callee, this);
|
|
7163
|
+
}));
|
|
7164
|
+
function syncContextToChannel() {
|
|
7165
|
+
return _syncContextToChannel.apply(this, arguments);
|
|
7153
7166
|
}
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
from: this.id,
|
|
7157
|
-
context: context
|
|
7158
|
-
});
|
|
7159
|
-
}
|
|
7167
|
+
return syncContextToChannel;
|
|
7168
|
+
}()
|
|
7160
7169
|
}, {
|
|
7161
7170
|
key: "subscribeToChanges",
|
|
7162
7171
|
value: function subscribeToChanges(idOrContextListener, contextListenerOrNothing) {
|
|
@@ -7176,7 +7185,7 @@ var ContextAPI = exports.ContextAPI = /*#__PURE__*/function () {
|
|
|
7176
7185
|
}]);
|
|
7177
7186
|
}();
|
|
7178
7187
|
|
|
7179
|
-
},{"
|
|
7188
|
+
},{"post-robot":5,"uuid":6}],39:[function(require,module,exports){
|
|
7180
7189
|
"use strict";
|
|
7181
7190
|
|
|
7182
7191
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -7304,58 +7313,57 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7304
7313
|
value: true
|
|
7305
7314
|
});
|
|
7306
7315
|
exports.classInstanceToObject = void 0;
|
|
7307
|
-
function
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7316
|
+
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); }
|
|
7317
|
+
// Check if an object contains functions deeply
|
|
7318
|
+
var containsDeepFunction = function containsDeepFunction(obj) {
|
|
7319
|
+
if (obj === null || obj === undefined) {
|
|
7320
|
+
return false;
|
|
7321
|
+
}
|
|
7322
|
+
if (typeof obj === 'function') {
|
|
7323
|
+
return true;
|
|
7324
|
+
}
|
|
7325
|
+
if (_typeof(obj) !== 'object') {
|
|
7326
|
+
return false;
|
|
7327
|
+
}
|
|
7328
|
+
if (Array.isArray(obj)) {
|
|
7329
|
+
return obj.some(function (item) {
|
|
7330
|
+
return containsDeepFunction(item);
|
|
7331
|
+
});
|
|
7332
|
+
}
|
|
7333
|
+
return Object.values(obj).some(function (value) {
|
|
7334
|
+
return containsDeepFunction(value);
|
|
7335
|
+
});
|
|
7336
|
+
};
|
|
7313
7337
|
var classInstanceToObject = exports.classInstanceToObject = function classInstanceToObject(instance, options) {
|
|
7338
|
+
// Handle null or undefined
|
|
7339
|
+
if (instance === null || instance === undefined) {
|
|
7340
|
+
return instance;
|
|
7341
|
+
}
|
|
7342
|
+
// Handle primitive values
|
|
7343
|
+
if (_typeof(instance) !== 'object' || instance instanceof Date) {
|
|
7344
|
+
return instance;
|
|
7345
|
+
}
|
|
7346
|
+
// Handle arrays
|
|
7347
|
+
if (Array.isArray(instance)) {
|
|
7348
|
+
return instance.map(function (item) {
|
|
7349
|
+
return classInstanceToObject(item, options);
|
|
7350
|
+
});
|
|
7351
|
+
}
|
|
7352
|
+
// Handle objects
|
|
7314
7353
|
var obj = {};
|
|
7315
|
-
//
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
//
|
|
7319
|
-
|
|
7320
|
-
var currentClass = instance;
|
|
7321
|
-
while (currentClass && currentClass !== Object) {
|
|
7322
|
-
// console.log('current class', currentClass); // TODO: test if it omits the Object methods
|
|
7323
|
-
properties.push.apply(properties, _toConsumableArray(Object.getOwnPropertyNames(currentClass)));
|
|
7324
|
-
currentClass = Object.getPrototypeOf(currentClass);
|
|
7325
|
-
}
|
|
7326
|
-
properties.forEach(function (property) {
|
|
7327
|
-
var _options$globals, _options$methodWrappe;
|
|
7328
|
-
if (['constructor'].includes(property)) {
|
|
7354
|
+
// Get all own properties (data properties, not methods)
|
|
7355
|
+
Object.keys(instance).forEach(function (key) {
|
|
7356
|
+
var value = instance[key];
|
|
7357
|
+
// Skip functions directly
|
|
7358
|
+
if (typeof value === 'function') {
|
|
7329
7359
|
return;
|
|
7330
7360
|
}
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
var originalMethod = _method;
|
|
7335
|
-
_method = function method() {
|
|
7336
|
-
var canCall = options.globals.canCallAction({
|
|
7337
|
-
method: _method.name,
|
|
7338
|
-
"class": instance.constructor.name
|
|
7339
|
-
});
|
|
7340
|
-
if (!canCall) {
|
|
7341
|
-
throw new Error("No permissions for call: ".concat(_method.name)); // TODO: consider usage of a specific permissions error
|
|
7342
|
-
}
|
|
7343
|
-
return originalMethod.apply(void 0, arguments);
|
|
7344
|
-
};
|
|
7345
|
-
}
|
|
7346
|
-
if (typeof (options === null || options === void 0 || (_options$methodWrappe = options.methodWrappers) === null || _options$methodWrappe === void 0 ? void 0 : _options$methodWrappe[property]) === 'function') {
|
|
7347
|
-
obj[property] = function () {
|
|
7348
|
-
var _options$methodWrappe2;
|
|
7349
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
7350
|
-
args[_key] = arguments[_key];
|
|
7351
|
-
}
|
|
7352
|
-
return (_options$methodWrappe2 = options.methodWrappers)[property].apply(_options$methodWrappe2, [_method].concat(args));
|
|
7353
|
-
};
|
|
7354
|
-
} else {
|
|
7355
|
-
obj[property] = function () {
|
|
7356
|
-
return _method.apply(void 0, arguments);
|
|
7357
|
-
};
|
|
7361
|
+
// Skip properties that contain functions deeply
|
|
7362
|
+
if (_typeof(value) === 'object' && value !== null && containsDeepFunction(value)) {
|
|
7363
|
+
return;
|
|
7358
7364
|
}
|
|
7365
|
+
// Recursively convert nested objects
|
|
7366
|
+
obj[key] = classInstanceToObject(value, options);
|
|
7359
7367
|
});
|
|
7360
7368
|
return obj;
|
|
7361
7369
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octostar/platform-api",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.13",
|
|
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.16"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@octostar/platform-types": "^0.5.
|
|
44
|
+
"@octostar/platform-types": "^0.5.16"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|