@contello/extension 7.8.2-next.1725544122
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/channel.d.ts +32 -0
- package/dist/client.d.ts +30 -0
- package/dist/custom-property.d.ts +18 -0
- package/dist/dialog-ref.d.ts +27 -0
- package/dist/dialog.d.ts +8 -0
- package/dist/extension.d.ts +14 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +255 -0
- package/dist/index.umd.cjs +1 -0
- package/dist/methods.d.ts +95 -0
- package/dist/types.d.ts +8 -0
- package/dist/url-parser.d.ts +6 -0
- package/dist/utils.d.ts +5 -0
- package/package.json +38 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ExtensionEventPayload, ExtensionEvent } from './types';
|
|
2
|
+
import { ContelloMethods } from './methods';
|
|
3
|
+
export type Handler<REQ, RES> = (msg: REQ) => RES | Promise<RES>;
|
|
4
|
+
export declare class ExtensionChannel<OWN extends ContelloMethods, REMOTE extends ContelloMethods> {
|
|
5
|
+
private params;
|
|
6
|
+
handlers: Map<any, any>;
|
|
7
|
+
listeners: Map<string, Handler<any, any>>;
|
|
8
|
+
private targetWindow;
|
|
9
|
+
private channelId;
|
|
10
|
+
private targetOrigin;
|
|
11
|
+
private isParent;
|
|
12
|
+
constructor(params: {
|
|
13
|
+
debug: boolean;
|
|
14
|
+
});
|
|
15
|
+
populateChannelId(): string;
|
|
16
|
+
connectParent(targetOrigin: string, channelId: string): void;
|
|
17
|
+
connectChild(targetWindow: Window): void;
|
|
18
|
+
getChannelId(): string;
|
|
19
|
+
getIsDebug(): boolean;
|
|
20
|
+
getTargetOrigin(): string;
|
|
21
|
+
getTargetWindow(): Window;
|
|
22
|
+
private connect;
|
|
23
|
+
disconnect(): void;
|
|
24
|
+
private handler;
|
|
25
|
+
respond(request: ExtensionEvent, payload: ExtensionEventPayload): void;
|
|
26
|
+
respondError(request: ExtensionEvent, error: any): void;
|
|
27
|
+
on<M extends keyof OWN>(method: M, handler: Handler<OWN[M][0], OWN[M][1]>): void;
|
|
28
|
+
call<M extends keyof REMOTE>(method: M, message?: REMOTE[M][0]): Promise<REMOTE[M][1]>;
|
|
29
|
+
send(data: ExtensionEvent): void;
|
|
30
|
+
private createChannelId;
|
|
31
|
+
private createRequestId;
|
|
32
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ContelloClientChildMethods, ContelloClientParentMethods } from './methods';
|
|
2
|
+
import { ExtensionChannel } from './channel';
|
|
3
|
+
import { ContelloDialogRef, ContelloDialogOptions } from './dialog-ref';
|
|
4
|
+
export declare class ContelloClient<D, O extends ContelloClientChildMethods, R extends ContelloClientParentMethods> {
|
|
5
|
+
protected channel: ExtensionChannel<O, R>;
|
|
6
|
+
protected applicationId: string;
|
|
7
|
+
private resizeObserver?;
|
|
8
|
+
private targetOrigin;
|
|
9
|
+
data?: D;
|
|
10
|
+
private dialogs;
|
|
11
|
+
constructor(targetOrigin: string, channelId: string, applicationId: string, debug: boolean);
|
|
12
|
+
connect(): Promise<void>;
|
|
13
|
+
ready(): Promise<R["ready"][1]>;
|
|
14
|
+
getAuthToken(): Promise<string>;
|
|
15
|
+
createApplicationUrl(): string;
|
|
16
|
+
createSingletonEntityUrl(referenceName: string): string;
|
|
17
|
+
createEntityUrl(referenceName: string, entityId?: string): string;
|
|
18
|
+
createExtensionUrl(referenceName: string, params?: {
|
|
19
|
+
path?: string[];
|
|
20
|
+
query?: {
|
|
21
|
+
[prop: string]: string;
|
|
22
|
+
};
|
|
23
|
+
}): string;
|
|
24
|
+
navigate(url: string): Promise<R["navigate"][1]>;
|
|
25
|
+
displayNotification(type: 'success' | 'error', message: string): Promise<R["displayNotification"][1]>;
|
|
26
|
+
openDialog<D, T>(options: ContelloDialogOptions<D>): ContelloDialogRef<D, T>;
|
|
27
|
+
private listenForResize;
|
|
28
|
+
private getWindowHeight;
|
|
29
|
+
private getDialogController;
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ContelloCustomPropertyChildMethods, ContelloCustomPropertyParentMethods } from './methods';
|
|
2
|
+
import { ContelloClient } from './client';
|
|
3
|
+
export type ContelloCustomPropertyValidator = (value: any) => boolean;
|
|
4
|
+
export interface ContelloCustomPropertyOptions {
|
|
5
|
+
trustedOrigins: string[];
|
|
6
|
+
validator?: () => boolean;
|
|
7
|
+
newValue?: (value: any) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare class ContelloCustomProperty extends ContelloClient<void, ContelloCustomPropertyChildMethods, ContelloCustomPropertyParentMethods> {
|
|
10
|
+
static connect(options: ContelloCustomPropertyOptions): Promise<ContelloCustomProperty>;
|
|
11
|
+
validate: () => boolean;
|
|
12
|
+
newValue: (value: string) => void;
|
|
13
|
+
constructor(targetOrigin: string, channelId: string, applicationId: string, debug: boolean);
|
|
14
|
+
getValue(): Promise<string>;
|
|
15
|
+
setValue(value: string): Promise<void>;
|
|
16
|
+
getValueByPath(path: string): Promise<any>;
|
|
17
|
+
setValueByPath(path: string, value: any): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ExtensionChannel } from './channel';
|
|
2
|
+
import { Deferred } from './utils';
|
|
3
|
+
export interface ContelloDialogParams<D, T> {
|
|
4
|
+
channel: ExtensionChannel<any, any>;
|
|
5
|
+
options: ContelloDialogOptions<D>;
|
|
6
|
+
controller: {
|
|
7
|
+
connected: Deferred<void>;
|
|
8
|
+
ready: Deferred<void>;
|
|
9
|
+
complete: Deferred<T>;
|
|
10
|
+
close: () => void;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface ContelloDialogOptions<D> {
|
|
14
|
+
url: string;
|
|
15
|
+
width?: number;
|
|
16
|
+
data?: D;
|
|
17
|
+
}
|
|
18
|
+
export declare class ContelloDialogRef<D, T> {
|
|
19
|
+
private _id?;
|
|
20
|
+
readonly open: Promise<void>;
|
|
21
|
+
readonly connected: Promise<void>;
|
|
22
|
+
readonly ready: Promise<void>;
|
|
23
|
+
readonly complete: Promise<T>;
|
|
24
|
+
readonly close: () => void;
|
|
25
|
+
constructor({ channel, options, controller }: ContelloDialogParams<D, T>);
|
|
26
|
+
get id(): string | undefined;
|
|
27
|
+
}
|
package/dist/dialog.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ContelloClient } from './client';
|
|
2
|
+
export declare class ContelloDialog<D, T> extends ContelloClient<D, any, any> {
|
|
3
|
+
static connect<D, T>({ trustedOrigins }: {
|
|
4
|
+
trustedOrigins: string[];
|
|
5
|
+
}): Promise<ContelloDialog<D, T>>;
|
|
6
|
+
constructor(targetOrigin: string, channelId: string, applicationId: string, debug: boolean);
|
|
7
|
+
close(value?: T): Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ContelloClient } from './client';
|
|
2
|
+
import { ContelloExtensionBreadcrumb, ContelloExtensionChildMethods, ContelloExtensionParentMethods } from './methods';
|
|
3
|
+
export interface ContelloExtensionOptions {
|
|
4
|
+
trustedOrigins: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare class ContelloExtension extends ContelloClient<void, ContelloExtensionChildMethods, ContelloExtensionParentMethods> {
|
|
7
|
+
static connect({ trustedOrigins }: ContelloExtensionOptions): Promise<ContelloExtension>;
|
|
8
|
+
constructor(targetOrigin: string, channelId: string, applicationId: string, debug: boolean);
|
|
9
|
+
getUrlData(): Promise<{
|
|
10
|
+
path: import("./methods").ContelloExtensionPath;
|
|
11
|
+
query: import("./methods").ContelloExtensionQuery;
|
|
12
|
+
}>;
|
|
13
|
+
setBreadcrumbs(breadcrumbs: ContelloExtensionBreadcrumb[]): Promise<void>;
|
|
14
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ContelloCustomProperty } from './custom-property';
|
|
2
|
+
export { ContelloDialogRef } from './dialog-ref';
|
|
3
|
+
export { ContelloDialog } from './dialog';
|
|
4
|
+
export { ContelloExtension } from './extension';
|
|
5
|
+
export { ExtensionChannel } from './channel';
|
|
6
|
+
export * from './methods';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
var w = Object.defineProperty;
|
|
2
|
+
var I = (l, e, t) => e in l ? w(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
|
|
3
|
+
var a = (l, e, t) => (I(l, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
let m = 0, y = 0;
|
|
5
|
+
class v {
|
|
6
|
+
constructor(e) {
|
|
7
|
+
a(this, "handlers", /* @__PURE__ */ new Map());
|
|
8
|
+
a(this, "listeners", /* @__PURE__ */ new Map());
|
|
9
|
+
a(this, "targetWindow");
|
|
10
|
+
a(this, "channelId");
|
|
11
|
+
a(this, "targetOrigin");
|
|
12
|
+
a(this, "isParent");
|
|
13
|
+
a(this, "handler", (e) => {
|
|
14
|
+
var t;
|
|
15
|
+
if (e.data.channelId === this.channelId && (this.targetOrigin === "*" || e.origin === this.targetOrigin)) {
|
|
16
|
+
const { channelId: n, requestId: i, method: r } = e.data;
|
|
17
|
+
n === this.channelId && (this.params.debug && console.log(this.isParent ? "Parent received" : "Child received", e.data), this.handlers.has(i) ? this.handlers.get(i)(e.data) : this.listeners.has(r) && Promise.resolve(
|
|
18
|
+
(t = this.listeners.get(r)) == null ? void 0 : t(e.data.payload)
|
|
19
|
+
).then((s) => this.respond(e.data, s)).catch((s) => this.respondError(e.data, s)));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
this.params = e;
|
|
23
|
+
}
|
|
24
|
+
populateChannelId() {
|
|
25
|
+
return this.channelId || (this.channelId = this.createChannelId()), this.channelId;
|
|
26
|
+
}
|
|
27
|
+
connectParent(e, t) {
|
|
28
|
+
this.channelId = t, this.targetOrigin = e, this.targetWindow = window.parent, this.isParent = !1, this.connect();
|
|
29
|
+
}
|
|
30
|
+
connectChild(e) {
|
|
31
|
+
this.populateChannelId(), this.targetWindow = e, this.targetOrigin = "*", this.isParent = !0, this.connect();
|
|
32
|
+
}
|
|
33
|
+
getChannelId() {
|
|
34
|
+
return this.channelId;
|
|
35
|
+
}
|
|
36
|
+
getIsDebug() {
|
|
37
|
+
return this.params.debug;
|
|
38
|
+
}
|
|
39
|
+
getTargetOrigin() {
|
|
40
|
+
return this.targetOrigin;
|
|
41
|
+
}
|
|
42
|
+
getTargetWindow() {
|
|
43
|
+
return this.targetWindow;
|
|
44
|
+
}
|
|
45
|
+
connect() {
|
|
46
|
+
window.addEventListener("message", this.handler);
|
|
47
|
+
}
|
|
48
|
+
disconnect() {
|
|
49
|
+
window.removeEventListener("message", this.handler);
|
|
50
|
+
}
|
|
51
|
+
respond(e, t) {
|
|
52
|
+
this.send({ channelId: e.channelId, requestId: e.requestId, method: e.method, payload: t });
|
|
53
|
+
}
|
|
54
|
+
respondError(e, t) {
|
|
55
|
+
this.send({ channelId: e.channelId, requestId: e.requestId, method: e.method, error: t });
|
|
56
|
+
}
|
|
57
|
+
on(e, t) {
|
|
58
|
+
this.listeners.set(e, t);
|
|
59
|
+
}
|
|
60
|
+
call(e, t) {
|
|
61
|
+
return new Promise((n, i) => {
|
|
62
|
+
const r = this.createRequestId();
|
|
63
|
+
this.send({ channelId: this.channelId, requestId: r, method: e, payload: t }), this.handlers.set(r, (s) => {
|
|
64
|
+
if (this.handlers.delete(r), s.error)
|
|
65
|
+
return i(s.error);
|
|
66
|
+
n(s.payload);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
send(e) {
|
|
71
|
+
var t;
|
|
72
|
+
(t = this.targetWindow) == null || t.postMessage(e, this.targetOrigin);
|
|
73
|
+
}
|
|
74
|
+
createChannelId() {
|
|
75
|
+
return `contello-channel-${++m}-${Math.random().toString(36).substring(2)}`;
|
|
76
|
+
}
|
|
77
|
+
createRequestId() {
|
|
78
|
+
return `${this.isParent ? "parent" : "child"}-request-${++y}-${Math.random().toString(36).substring(2)}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
class f {
|
|
82
|
+
constructor({ channel: e, options: t, controller: n }) {
|
|
83
|
+
a(this, "_id");
|
|
84
|
+
a(this, "open");
|
|
85
|
+
a(this, "connected");
|
|
86
|
+
a(this, "ready");
|
|
87
|
+
a(this, "complete");
|
|
88
|
+
a(this, "close");
|
|
89
|
+
this.open = e.call("openDialog", t).then(({ id: i }) => this._id = i), this.connected = n.connected.promise, this.ready = n.ready.promise, this.complete = n.complete.promise, this.close = n.close;
|
|
90
|
+
}
|
|
91
|
+
get id() {
|
|
92
|
+
return this._id;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
class c {
|
|
96
|
+
constructor() {
|
|
97
|
+
a(this, "resolve");
|
|
98
|
+
a(this, "reject");
|
|
99
|
+
a(this, "promise", new Promise((e, t) => {
|
|
100
|
+
this.resolve = e, this.reject = t;
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
class h {
|
|
105
|
+
constructor(e, t, n, i) {
|
|
106
|
+
a(this, "channel");
|
|
107
|
+
a(this, "applicationId");
|
|
108
|
+
a(this, "resizeObserver");
|
|
109
|
+
a(this, "targetOrigin");
|
|
110
|
+
a(this, "data");
|
|
111
|
+
a(this, "dialogs", /* @__PURE__ */ new Map());
|
|
112
|
+
this.channel = new v({ debug: i }), this.channel.connectParent(e, t), this.applicationId = n, this.targetOrigin = e;
|
|
113
|
+
}
|
|
114
|
+
connect() {
|
|
115
|
+
return this.channel.call("connect").then(({ data: e }) => {
|
|
116
|
+
this.channel.on("dialogConnect", ({ id: t }) => {
|
|
117
|
+
var n;
|
|
118
|
+
return (n = this.getDialogController(t)) == null ? void 0 : n.connected.resolve();
|
|
119
|
+
}), this.channel.on("dialogReady", ({ id: t }) => {
|
|
120
|
+
var n;
|
|
121
|
+
return (n = this.getDialogController(t)) == null ? void 0 : n.ready.resolve();
|
|
122
|
+
}), this.channel.on("dialogComplete", ({ id: t, value: n }) => {
|
|
123
|
+
var i;
|
|
124
|
+
return (i = this.getDialogController(t)) == null ? void 0 : i.complete.resolve(n);
|
|
125
|
+
}), this.data = e;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
ready() {
|
|
129
|
+
return this.listenForResize(), this.channel.call("ready", { height: this.getWindowHeight() });
|
|
130
|
+
}
|
|
131
|
+
getAuthToken() {
|
|
132
|
+
return this.channel.call("getAuthToken").then(({ token: e }) => e);
|
|
133
|
+
}
|
|
134
|
+
createApplicationUrl() {
|
|
135
|
+
return `${this.targetOrigin}/ui/applications/${this.applicationId}`;
|
|
136
|
+
}
|
|
137
|
+
createSingletonEntityUrl(e) {
|
|
138
|
+
return `${this.createApplicationUrl()}/entities/${e}`;
|
|
139
|
+
}
|
|
140
|
+
createEntityUrl(e, t) {
|
|
141
|
+
return `${this.createApplicationUrl()}/entities/${e}/${t}`;
|
|
142
|
+
}
|
|
143
|
+
createExtensionUrl(e, t) {
|
|
144
|
+
var r;
|
|
145
|
+
const n = ((r = t == null ? void 0 : t.path) == null ? void 0 : r.join("/")) || "", i = new URLSearchParams((t == null ? void 0 : t.query) || {}).toString();
|
|
146
|
+
return `${this.createApplicationUrl()}/extensions/${e}${n ? `/${n}` : ""}${i ? `?${i}` : ""}`;
|
|
147
|
+
}
|
|
148
|
+
navigate(e) {
|
|
149
|
+
return this.channel.call("navigate", { url: e });
|
|
150
|
+
}
|
|
151
|
+
displayNotification(e, t) {
|
|
152
|
+
return this.channel.call("displayNotification", { type: e, message: t });
|
|
153
|
+
}
|
|
154
|
+
openDialog(e) {
|
|
155
|
+
const t = {
|
|
156
|
+
connected: new c(),
|
|
157
|
+
ready: new c(),
|
|
158
|
+
complete: new c(),
|
|
159
|
+
close: () => {
|
|
160
|
+
if (!this.channel)
|
|
161
|
+
throw new Error("The channel is not yet initialized");
|
|
162
|
+
this.channel.call("closeDialog", { id: n.id }), this.dialogs.delete(n);
|
|
163
|
+
}
|
|
164
|
+
}, n = new f({ channel: this.channel, options: e, controller: t });
|
|
165
|
+
return this.dialogs.set(n, t), n.complete.then(() => this.dialogs.delete(n)), n;
|
|
166
|
+
}
|
|
167
|
+
listenForResize() {
|
|
168
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
169
|
+
this.channel.call("resize", { height: this.getWindowHeight() });
|
|
170
|
+
}), this.resizeObserver.observe(document.documentElement);
|
|
171
|
+
}
|
|
172
|
+
getWindowHeight() {
|
|
173
|
+
return Math.max(
|
|
174
|
+
document.body.scrollHeight,
|
|
175
|
+
document.body.offsetHeight,
|
|
176
|
+
document.body.clientHeight
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
getDialogController(e) {
|
|
180
|
+
const t = Array.from(this.dialogs.keys()).find((n) => n.id === e);
|
|
181
|
+
if (t)
|
|
182
|
+
return this.dialogs.get(t);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function d(l) {
|
|
186
|
+
const e = new URL(location.href), t = e.searchParams.get("channelId"), n = e.searchParams.get("origin"), i = e.searchParams.get("applicationId"), r = e.searchParams.get("debug") === "true";
|
|
187
|
+
if (!t || !n || !i)
|
|
188
|
+
throw new Error("Missing required URL parameters");
|
|
189
|
+
if (!(l != null && l.length))
|
|
190
|
+
throw new Error("No trusted origins provided");
|
|
191
|
+
if (!l.includes(n))
|
|
192
|
+
throw new Error(`Origin ${n} is not trusted`);
|
|
193
|
+
return { channelId: t, targetOrigin: n, applicationId: i, debug: r };
|
|
194
|
+
}
|
|
195
|
+
class g extends h {
|
|
196
|
+
constructor(t, n, i, r) {
|
|
197
|
+
super(t, n, i, r);
|
|
198
|
+
a(this, "validate", () => !0);
|
|
199
|
+
a(this, "newValue", () => null);
|
|
200
|
+
this.channel.on("validate", async () => ({ valid: await Promise.resolve(this.validate()) })), this.channel.on("newValue", async (s) => {
|
|
201
|
+
await Promise.resolve(this.newValue(s.value));
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
static connect(t) {
|
|
205
|
+
const { targetOrigin: n, channelId: i, applicationId: r, debug: s } = d(t.trustedOrigins), o = new g(n, i, r, s);
|
|
206
|
+
return o.validate = t.validator || (() => !0), o.newValue = t.newValue || (() => null), o.connect().then(() => o);
|
|
207
|
+
}
|
|
208
|
+
async getValue() {
|
|
209
|
+
return (await this.channel.call("getValue")).value;
|
|
210
|
+
}
|
|
211
|
+
async setValue(t) {
|
|
212
|
+
const n = await Promise.resolve(this.validate());
|
|
213
|
+
return await this.channel.call("setValue", { value: t, valid: n });
|
|
214
|
+
}
|
|
215
|
+
async getValueByPath(t) {
|
|
216
|
+
return (await this.channel.call("getValueByPath", { path: t })).value;
|
|
217
|
+
}
|
|
218
|
+
async setValueByPath(t, n) {
|
|
219
|
+
return this.channel.call("setValueByPath", { value: n, path: t });
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
class u extends h {
|
|
223
|
+
static connect({ trustedOrigins: e }) {
|
|
224
|
+
const { targetOrigin: t, channelId: n, applicationId: i, debug: r } = d(e), s = new u(t, n, i, r);
|
|
225
|
+
return s.connect().then(() => s);
|
|
226
|
+
}
|
|
227
|
+
constructor(e, t, n, i) {
|
|
228
|
+
super(e, t, n, i);
|
|
229
|
+
}
|
|
230
|
+
close(e) {
|
|
231
|
+
return this.channel.call("complete", { value: e });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
class p extends h {
|
|
235
|
+
static connect({ trustedOrigins: e }) {
|
|
236
|
+
const { targetOrigin: t, channelId: n, applicationId: i, debug: r } = d(e), s = new p(t, n, i, r);
|
|
237
|
+
return s.connect().then(() => s);
|
|
238
|
+
}
|
|
239
|
+
constructor(e, t, n, i) {
|
|
240
|
+
super(e, t, n, i);
|
|
241
|
+
}
|
|
242
|
+
getUrlData() {
|
|
243
|
+
return this.channel.call("getUrlData");
|
|
244
|
+
}
|
|
245
|
+
setBreadcrumbs(e) {
|
|
246
|
+
return this.channel.call("setBreadcrumbs", { breadcrumbs: e });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
export {
|
|
250
|
+
g as ContelloCustomProperty,
|
|
251
|
+
u as ContelloDialog,
|
|
252
|
+
f as ContelloDialogRef,
|
|
253
|
+
p as ContelloExtension,
|
|
254
|
+
v as ExtensionChannel
|
|
255
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(l,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.ContelloExtension={}))})(this,function(l){"use strict";var v=Object.defineProperty;var P=(l,o,h)=>o in l?v(l,o,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[o]=h;var a=(l,o,h)=>(P(l,typeof o!="symbol"?o+"":o,h),h);let o=0,h=0;class y{constructor(e){a(this,"handlers",new Map);a(this,"listeners",new Map);a(this,"targetWindow");a(this,"channelId");a(this,"targetOrigin");a(this,"isParent");a(this,"handler",e=>{var t;if(e.data.channelId===this.channelId&&(this.targetOrigin==="*"||e.origin===this.targetOrigin)){const{channelId:n,requestId:i,method:r}=e.data;n===this.channelId&&(this.params.debug&&console.log(this.isParent?"Parent received":"Child received",e.data),this.handlers.has(i)?this.handlers.get(i)(e.data):this.listeners.has(r)&&Promise.resolve((t=this.listeners.get(r))==null?void 0:t(e.data.payload)).then(s=>this.respond(e.data,s)).catch(s=>this.respondError(e.data,s)))}});this.params=e}populateChannelId(){return this.channelId||(this.channelId=this.createChannelId()),this.channelId}connectParent(e,t){this.channelId=t,this.targetOrigin=e,this.targetWindow=window.parent,this.isParent=!1,this.connect()}connectChild(e){this.populateChannelId(),this.targetWindow=e,this.targetOrigin="*",this.isParent=!0,this.connect()}getChannelId(){return this.channelId}getIsDebug(){return this.params.debug}getTargetOrigin(){return this.targetOrigin}getTargetWindow(){return this.targetWindow}connect(){window.addEventListener("message",this.handler)}disconnect(){window.removeEventListener("message",this.handler)}respond(e,t){this.send({channelId:e.channelId,requestId:e.requestId,method:e.method,payload:t})}respondError(e,t){this.send({channelId:e.channelId,requestId:e.requestId,method:e.method,error:t})}on(e,t){this.listeners.set(e,t)}call(e,t){return new Promise((n,i)=>{const r=this.createRequestId();this.send({channelId:this.channelId,requestId:r,method:e,payload:t}),this.handlers.set(r,s=>{if(this.handlers.delete(r),s.error)return i(s.error);n(s.payload)})})}send(e){var t;(t=this.targetWindow)==null||t.postMessage(e,this.targetOrigin)}createChannelId(){return`contello-channel-${++o}-${Math.random().toString(36).substring(2)}`}createRequestId(){return`${this.isParent?"parent":"child"}-request-${++h}-${Math.random().toString(36).substring(2)}`}}class f{constructor({channel:e,options:t,controller:n}){a(this,"_id");a(this,"open");a(this,"connected");a(this,"ready");a(this,"complete");a(this,"close");this.open=e.call("openDialog",t).then(({id:i})=>this._id=i),this.connected=n.connected.promise,this.ready=n.ready.promise,this.complete=n.complete.promise,this.close=n.close}get id(){return this._id}}class g{constructor(){a(this,"resolve");a(this,"reject");a(this,"promise",new Promise((e,t)=>{this.resolve=e,this.reject=t}))}}class u{constructor(e,t,n,i){a(this,"channel");a(this,"applicationId");a(this,"resizeObserver");a(this,"targetOrigin");a(this,"data");a(this,"dialogs",new Map);this.channel=new y({debug:i}),this.channel.connectParent(e,t),this.applicationId=n,this.targetOrigin=e}connect(){return this.channel.call("connect").then(({data:e})=>{this.channel.on("dialogConnect",({id:t})=>{var n;return(n=this.getDialogController(t))==null?void 0:n.connected.resolve()}),this.channel.on("dialogReady",({id:t})=>{var n;return(n=this.getDialogController(t))==null?void 0:n.ready.resolve()}),this.channel.on("dialogComplete",({id:t,value:n})=>{var i;return(i=this.getDialogController(t))==null?void 0:i.complete.resolve(n)}),this.data=e})}ready(){return this.listenForResize(),this.channel.call("ready",{height:this.getWindowHeight()})}getAuthToken(){return this.channel.call("getAuthToken").then(({token:e})=>e)}createApplicationUrl(){return`${this.targetOrigin}/ui/applications/${this.applicationId}`}createSingletonEntityUrl(e){return`${this.createApplicationUrl()}/entities/${e}`}createEntityUrl(e,t){return`${this.createApplicationUrl()}/entities/${e}/${t}`}createExtensionUrl(e,t){var r;const n=((r=t==null?void 0:t.path)==null?void 0:r.join("/"))||"",i=new URLSearchParams((t==null?void 0:t.query)||{}).toString();return`${this.createApplicationUrl()}/extensions/${e}${n?`/${n}`:""}${i?`?${i}`:""}`}navigate(e){return this.channel.call("navigate",{url:e})}displayNotification(e,t){return this.channel.call("displayNotification",{type:e,message:t})}openDialog(e){const t={connected:new g,ready:new g,complete:new g,close:()=>{if(!this.channel)throw new Error("The channel is not yet initialized");this.channel.call("closeDialog",{id:n.id}),this.dialogs.delete(n)}},n=new f({channel:this.channel,options:e,controller:t});return this.dialogs.set(n,t),n.complete.then(()=>this.dialogs.delete(n)),n}listenForResize(){this.resizeObserver=new ResizeObserver(()=>{this.channel.call("resize",{height:this.getWindowHeight()})}),this.resizeObserver.observe(document.documentElement)}getWindowHeight(){return Math.max(document.body.scrollHeight,document.body.offsetHeight,document.body.clientHeight)}getDialogController(e){const t=Array.from(this.dialogs.keys()).find(n=>n.id===e);if(t)return this.dialogs.get(t)}}function p(c){const e=new URL(location.href),t=e.searchParams.get("channelId"),n=e.searchParams.get("origin"),i=e.searchParams.get("applicationId"),r=e.searchParams.get("debug")==="true";if(!t||!n||!i)throw new Error("Missing required URL parameters");if(!(c!=null&&c.length))throw new Error("No trusted origins provided");if(!c.includes(n))throw new Error(`Origin ${n} is not trusted`);return{channelId:t,targetOrigin:n,applicationId:i,debug:r}}class w extends u{constructor(t,n,i,r){super(t,n,i,r);a(this,"validate",()=>!0);a(this,"newValue",()=>null);this.channel.on("validate",async()=>({valid:await Promise.resolve(this.validate())})),this.channel.on("newValue",async s=>{await Promise.resolve(this.newValue(s.value))})}static connect(t){const{targetOrigin:n,channelId:i,applicationId:r,debug:s}=p(t.trustedOrigins),d=new w(n,i,r,s);return d.validate=t.validator||(()=>!0),d.newValue=t.newValue||(()=>null),d.connect().then(()=>d)}async getValue(){return(await this.channel.call("getValue")).value}async setValue(t){const n=await Promise.resolve(this.validate());return await this.channel.call("setValue",{value:t,valid:n})}async getValueByPath(t){return(await this.channel.call("getValueByPath",{path:t})).value}async setValueByPath(t,n){return this.channel.call("setValueByPath",{value:n,path:t})}}class I extends u{static connect({trustedOrigins:e}){const{targetOrigin:t,channelId:n,applicationId:i,debug:r}=p(e),s=new I(t,n,i,r);return s.connect().then(()=>s)}constructor(e,t,n,i){super(e,t,n,i)}close(e){return this.channel.call("complete",{value:e})}}class m extends u{static connect({trustedOrigins:e}){const{targetOrigin:t,channelId:n,applicationId:i,debug:r}=p(e),s=new m(t,n,i,r);return s.connect().then(()=>s)}constructor(e,t,n,i){super(e,t,n,i)}getUrlData(){return this.channel.call("getUrlData")}setBreadcrumbs(e){return this.channel.call("setBreadcrumbs",{breadcrumbs:e})}}l.ContelloCustomProperty=w,l.ContelloDialog=I,l.ContelloDialogRef=f,l.ContelloExtension=m,l.ExtensionChannel=y,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export interface ContelloMethods {
|
|
2
|
+
[prop: string]: [unknown, unknown];
|
|
3
|
+
}
|
|
4
|
+
export interface ContelloClientParentMethods extends ContelloMethods {
|
|
5
|
+
connect: [void, {
|
|
6
|
+
connected: boolean;
|
|
7
|
+
data: any;
|
|
8
|
+
}];
|
|
9
|
+
resize: [{
|
|
10
|
+
height: number;
|
|
11
|
+
}, void];
|
|
12
|
+
ready: [{
|
|
13
|
+
height: number;
|
|
14
|
+
}, void];
|
|
15
|
+
getAuthToken: [void, {
|
|
16
|
+
token: string;
|
|
17
|
+
}];
|
|
18
|
+
navigate: [{
|
|
19
|
+
url: string;
|
|
20
|
+
}, void];
|
|
21
|
+
displayNotification: [{
|
|
22
|
+
message: string;
|
|
23
|
+
type: 'success' | 'error';
|
|
24
|
+
}, void];
|
|
25
|
+
openDialog: [{
|
|
26
|
+
url: string;
|
|
27
|
+
width: number;
|
|
28
|
+
data: any;
|
|
29
|
+
}, {
|
|
30
|
+
id: string;
|
|
31
|
+
}];
|
|
32
|
+
closeDialog: [{
|
|
33
|
+
id: string;
|
|
34
|
+
}, void];
|
|
35
|
+
complete: [{
|
|
36
|
+
value: any;
|
|
37
|
+
}, void];
|
|
38
|
+
}
|
|
39
|
+
export interface ContelloCustomPropertyParentMethods extends ContelloClientParentMethods {
|
|
40
|
+
getValue: [void, {
|
|
41
|
+
value: string;
|
|
42
|
+
}];
|
|
43
|
+
setValue: [{
|
|
44
|
+
value: string;
|
|
45
|
+
valid: boolean;
|
|
46
|
+
}, void];
|
|
47
|
+
getValueByPath: [{
|
|
48
|
+
path: string;
|
|
49
|
+
}, {
|
|
50
|
+
value: any;
|
|
51
|
+
}];
|
|
52
|
+
setValueByPath: [{
|
|
53
|
+
path: string;
|
|
54
|
+
value: any;
|
|
55
|
+
}, void];
|
|
56
|
+
}
|
|
57
|
+
export type ContelloExtensionPath = string[];
|
|
58
|
+
export interface ContelloExtensionQuery {
|
|
59
|
+
[prop: string]: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ContelloExtensionBreadcrumb {
|
|
62
|
+
label: string;
|
|
63
|
+
url?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ContelloExtensionParentMethods extends ContelloClientParentMethods {
|
|
66
|
+
getUrlData: [void, {
|
|
67
|
+
path: ContelloExtensionPath;
|
|
68
|
+
query: ContelloExtensionQuery;
|
|
69
|
+
}];
|
|
70
|
+
setBreadcrumbs: [{
|
|
71
|
+
breadcrumbs: ContelloExtensionBreadcrumb[];
|
|
72
|
+
}, void];
|
|
73
|
+
}
|
|
74
|
+
export interface ContelloClientChildMethods extends ContelloMethods {
|
|
75
|
+
dialogConnect: [{
|
|
76
|
+
id: string;
|
|
77
|
+
}, void];
|
|
78
|
+
dialogReady: [{
|
|
79
|
+
id: string;
|
|
80
|
+
}, void];
|
|
81
|
+
dialogComplete: [{
|
|
82
|
+
id: string;
|
|
83
|
+
value: any;
|
|
84
|
+
}, void];
|
|
85
|
+
}
|
|
86
|
+
export interface ContelloCustomPropertyChildMethods extends ContelloClientChildMethods {
|
|
87
|
+
validate: [void, {
|
|
88
|
+
valid: boolean;
|
|
89
|
+
}];
|
|
90
|
+
newValue: [{
|
|
91
|
+
value: string;
|
|
92
|
+
}, void];
|
|
93
|
+
}
|
|
94
|
+
export interface ContelloExtensionChildMethods extends ContelloClientChildMethods {
|
|
95
|
+
}
|
package/dist/types.d.ts
ADDED
package/dist/utils.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contello/extension",
|
|
3
|
+
"description": "Contello extension library",
|
|
4
|
+
"types": "./dist/index.d.ts",
|
|
5
|
+
"author": "admin@entwico.com",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.umd.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"start": "vite build --watch",
|
|
19
|
+
"build": "vite build",
|
|
20
|
+
"clear": "rm -rf dist",
|
|
21
|
+
"patch": "node ci/patcher.js",
|
|
22
|
+
"lint": "eslint src/**/*.ts"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
26
|
+
"@typescript-eslint/parser": "^5.53.0",
|
|
27
|
+
"eslint": "^8.21.0",
|
|
28
|
+
"npm-run-all": "^4.1.5",
|
|
29
|
+
"vite": "^4.1.4",
|
|
30
|
+
"vite-plugin-dts": "^2.0.0-beta.3",
|
|
31
|
+
"typescript": "^4.9.3"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"registry": "https://registry.npmjs.org"
|
|
36
|
+
},
|
|
37
|
+
"version": "7.8.2-next.1725544122"
|
|
38
|
+
}
|