@contello/extension 7.8.2 → 8.0.0
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/client.d.ts +3 -3
- package/dist/index.js +62 -62
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
package/dist/client.d.ts
CHANGED
|
@@ -3,16 +3,16 @@ import { ExtensionChannel } from './channel';
|
|
|
3
3
|
import { ContelloDialogRef, ContelloDialogOptions } from './dialog-ref';
|
|
4
4
|
export declare class ContelloClient<D, O extends ContelloClientChildMethods, R extends ContelloClientParentMethods> {
|
|
5
5
|
protected channel: ExtensionChannel<O, R>;
|
|
6
|
-
protected
|
|
6
|
+
protected projectId: string;
|
|
7
7
|
private resizeObserver?;
|
|
8
8
|
private targetOrigin;
|
|
9
9
|
data?: D;
|
|
10
10
|
private dialogs;
|
|
11
|
-
constructor(targetOrigin: string, channelId: string,
|
|
11
|
+
constructor(targetOrigin: string, channelId: string, projectId: string, debug: boolean);
|
|
12
12
|
connect(): Promise<void>;
|
|
13
13
|
ready(): Promise<R["ready"][1]>;
|
|
14
14
|
getAuthToken(): Promise<string>;
|
|
15
|
-
|
|
15
|
+
createProjectUrl(): string;
|
|
16
16
|
createSingletonEntityUrl(referenceName: string): string;
|
|
17
17
|
createEntityUrl(referenceName: string, entityId?: string): string;
|
|
18
18
|
createExtensionUrl(referenceName: string, params?: {
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
var w = Object.defineProperty;
|
|
2
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
|
|
3
|
+
var i = (l, e, t) => (I(l, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
4
|
let m = 0, y = 0;
|
|
5
|
-
class
|
|
5
|
+
class P {
|
|
6
6
|
constructor(e) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
i(this, "handlers", /* @__PURE__ */ new Map());
|
|
8
|
+
i(this, "listeners", /* @__PURE__ */ new Map());
|
|
9
|
+
i(this, "targetWindow");
|
|
10
|
+
i(this, "channelId");
|
|
11
|
+
i(this, "targetOrigin");
|
|
12
|
+
i(this, "isParent");
|
|
13
|
+
i(this, "handler", (e) => {
|
|
14
14
|
var t;
|
|
15
15
|
if (e.data.channelId === this.channelId && (this.targetOrigin === "*" || e.origin === this.targetOrigin)) {
|
|
16
|
-
const { channelId: n, requestId:
|
|
17
|
-
n === this.channelId && (this.params.debug && console.log(this.isParent ? "Parent received" : "Child received", e.data), this.handlers.has(
|
|
18
|
-
(t = this.listeners.get(
|
|
16
|
+
const { channelId: n, requestId: r, method: a } = e.data;
|
|
17
|
+
n === this.channelId && (this.params.debug && console.log(this.isParent ? "Parent received" : "Child received", e.data), this.handlers.has(r) ? this.handlers.get(r)(e.data) : this.listeners.has(a) && Promise.resolve(
|
|
18
|
+
(t = this.listeners.get(a)) == null ? void 0 : t(e.data.payload)
|
|
19
19
|
).then((s) => this.respond(e.data, s)).catch((s) => this.respondError(e.data, s)));
|
|
20
20
|
}
|
|
21
21
|
});
|
|
@@ -58,11 +58,11 @@ class v {
|
|
|
58
58
|
this.listeners.set(e, t);
|
|
59
59
|
}
|
|
60
60
|
call(e, t) {
|
|
61
|
-
return new Promise((n,
|
|
62
|
-
const
|
|
63
|
-
this.send({ channelId: this.channelId, requestId:
|
|
64
|
-
if (this.handlers.delete(
|
|
65
|
-
return
|
|
61
|
+
return new Promise((n, r) => {
|
|
62
|
+
const a = this.createRequestId();
|
|
63
|
+
this.send({ channelId: this.channelId, requestId: a, method: e, payload: t }), this.handlers.set(a, (s) => {
|
|
64
|
+
if (this.handlers.delete(a), s.error)
|
|
65
|
+
return r(s.error);
|
|
66
66
|
n(s.payload);
|
|
67
67
|
});
|
|
68
68
|
});
|
|
@@ -78,15 +78,15 @@ class v {
|
|
|
78
78
|
return `${this.isParent ? "parent" : "child"}-request-${++y}-${Math.random().toString(36).substring(2)}`;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
class
|
|
81
|
+
class v {
|
|
82
82
|
constructor({ channel: e, options: t, controller: n }) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.open = e.call("openDialog", t).then(({ id:
|
|
83
|
+
i(this, "_id");
|
|
84
|
+
i(this, "open");
|
|
85
|
+
i(this, "connected");
|
|
86
|
+
i(this, "ready");
|
|
87
|
+
i(this, "complete");
|
|
88
|
+
i(this, "close");
|
|
89
|
+
this.open = e.call("openDialog", t).then(({ id: r }) => this._id = r), this.connected = n.connected.promise, this.ready = n.ready.promise, this.complete = n.complete.promise, this.close = n.close;
|
|
90
90
|
}
|
|
91
91
|
get id() {
|
|
92
92
|
return this._id;
|
|
@@ -94,22 +94,22 @@ class f {
|
|
|
94
94
|
}
|
|
95
95
|
class c {
|
|
96
96
|
constructor() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
i(this, "resolve");
|
|
98
|
+
i(this, "reject");
|
|
99
|
+
i(this, "promise", new Promise((e, t) => {
|
|
100
100
|
this.resolve = e, this.reject = t;
|
|
101
101
|
}));
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
class h {
|
|
105
|
-
constructor(e, t, n,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this.channel = new
|
|
105
|
+
constructor(e, t, n, r) {
|
|
106
|
+
i(this, "channel");
|
|
107
|
+
i(this, "projectId");
|
|
108
|
+
i(this, "resizeObserver");
|
|
109
|
+
i(this, "targetOrigin");
|
|
110
|
+
i(this, "data");
|
|
111
|
+
i(this, "dialogs", /* @__PURE__ */ new Map());
|
|
112
|
+
this.channel = new P({ debug: r }), this.channel.connectParent(e, t), this.projectId = n, this.targetOrigin = e;
|
|
113
113
|
}
|
|
114
114
|
connect() {
|
|
115
115
|
return this.channel.call("connect").then(({ data: e }) => {
|
|
@@ -120,8 +120,8 @@ class h {
|
|
|
120
120
|
var n;
|
|
121
121
|
return (n = this.getDialogController(t)) == null ? void 0 : n.ready.resolve();
|
|
122
122
|
}), this.channel.on("dialogComplete", ({ id: t, value: n }) => {
|
|
123
|
-
var
|
|
124
|
-
return (
|
|
123
|
+
var r;
|
|
124
|
+
return (r = this.getDialogController(t)) == null ? void 0 : r.complete.resolve(n);
|
|
125
125
|
}), this.data = e;
|
|
126
126
|
});
|
|
127
127
|
}
|
|
@@ -131,19 +131,19 @@ class h {
|
|
|
131
131
|
getAuthToken() {
|
|
132
132
|
return this.channel.call("getAuthToken").then(({ token: e }) => e);
|
|
133
133
|
}
|
|
134
|
-
|
|
135
|
-
return `${this.targetOrigin}/ui/
|
|
134
|
+
createProjectUrl() {
|
|
135
|
+
return `${this.targetOrigin}/ui/projects/${this.projectId}`;
|
|
136
136
|
}
|
|
137
137
|
createSingletonEntityUrl(e) {
|
|
138
|
-
return `${this.
|
|
138
|
+
return `${this.createProjectUrl()}/entities/${e}`;
|
|
139
139
|
}
|
|
140
140
|
createEntityUrl(e, t) {
|
|
141
|
-
return `${this.
|
|
141
|
+
return `${this.createProjectUrl()}/entities/${e}/${t}`;
|
|
142
142
|
}
|
|
143
143
|
createExtensionUrl(e, t) {
|
|
144
|
-
var
|
|
145
|
-
const n = ((
|
|
146
|
-
return `${this.
|
|
144
|
+
var a;
|
|
145
|
+
const n = ((a = t == null ? void 0 : t.path) == null ? void 0 : a.join("/")) || "", r = new URLSearchParams((t == null ? void 0 : t.query) || {}).toString();
|
|
146
|
+
return `${this.createProjectUrl()}/extensions/${e}${n ? `/${n}` : ""}${r ? `?${r}` : ""}`;
|
|
147
147
|
}
|
|
148
148
|
navigate(e) {
|
|
149
149
|
return this.channel.call("navigate", { url: e });
|
|
@@ -161,7 +161,7 @@ class h {
|
|
|
161
161
|
throw new Error("The channel is not yet initialized");
|
|
162
162
|
this.channel.call("closeDialog", { id: n.id }), this.dialogs.delete(n);
|
|
163
163
|
}
|
|
164
|
-
}, n = new
|
|
164
|
+
}, n = new v({ channel: this.channel, options: e, controller: t });
|
|
165
165
|
return this.dialogs.set(n, t), n.complete.then(() => this.dialogs.delete(n)), n;
|
|
166
166
|
}
|
|
167
167
|
listenForResize() {
|
|
@@ -183,26 +183,26 @@ class h {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
function d(l) {
|
|
186
|
-
const e = new URL(location.href), t = e.searchParams.get("channelId"), n = e.searchParams.get("origin"),
|
|
187
|
-
if (!t || !n || !
|
|
186
|
+
const e = new URL(location.href), t = e.searchParams.get("channelId"), n = e.searchParams.get("origin"), r = e.searchParams.get("applicationId"), a = e.searchParams.get("debug") === "true";
|
|
187
|
+
if (!t || !n || !r)
|
|
188
188
|
throw new Error("Missing required URL parameters");
|
|
189
189
|
if (!(l != null && l.length))
|
|
190
190
|
throw new Error("No trusted origins provided");
|
|
191
191
|
if (!l.includes(n))
|
|
192
192
|
throw new Error(`Origin ${n} is not trusted`);
|
|
193
|
-
return { channelId: t, targetOrigin: n, applicationId:
|
|
193
|
+
return { channelId: t, targetOrigin: n, applicationId: r, debug: a };
|
|
194
194
|
}
|
|
195
195
|
class g extends h {
|
|
196
|
-
constructor(t, n,
|
|
197
|
-
super(t, n,
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
constructor(t, n, r, a) {
|
|
197
|
+
super(t, n, r, a);
|
|
198
|
+
i(this, "validate", () => !0);
|
|
199
|
+
i(this, "newValue", () => null);
|
|
200
200
|
this.channel.on("validate", async () => ({ valid: await Promise.resolve(this.validate()) })), this.channel.on("newValue", async (s) => {
|
|
201
201
|
await Promise.resolve(this.newValue(s.value));
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
204
|
static connect(t) {
|
|
205
|
-
const { targetOrigin: n, channelId:
|
|
205
|
+
const { targetOrigin: n, channelId: r, applicationId: a, debug: s } = d(t.trustedOrigins), o = new g(n, r, a, s);
|
|
206
206
|
return o.validate = t.validator || (() => !0), o.newValue = t.newValue || (() => null), o.connect().then(() => o);
|
|
207
207
|
}
|
|
208
208
|
async getValue() {
|
|
@@ -221,11 +221,11 @@ class g extends h {
|
|
|
221
221
|
}
|
|
222
222
|
class u extends h {
|
|
223
223
|
static connect({ trustedOrigins: e }) {
|
|
224
|
-
const { targetOrigin: t, channelId: n, applicationId:
|
|
224
|
+
const { targetOrigin: t, channelId: n, applicationId: r, debug: a } = d(e), s = new u(t, n, r, a);
|
|
225
225
|
return s.connect().then(() => s);
|
|
226
226
|
}
|
|
227
|
-
constructor(e, t, n,
|
|
228
|
-
super(e, t, n,
|
|
227
|
+
constructor(e, t, n, r) {
|
|
228
|
+
super(e, t, n, r);
|
|
229
229
|
}
|
|
230
230
|
close(e) {
|
|
231
231
|
return this.channel.call("complete", { value: e });
|
|
@@ -233,11 +233,11 @@ class u extends h {
|
|
|
233
233
|
}
|
|
234
234
|
class p extends h {
|
|
235
235
|
static connect({ trustedOrigins: e }) {
|
|
236
|
-
const { targetOrigin: t, channelId: n, applicationId:
|
|
236
|
+
const { targetOrigin: t, channelId: n, applicationId: r, debug: a } = d(e), s = new p(t, n, r, a);
|
|
237
237
|
return s.connect().then(() => s);
|
|
238
238
|
}
|
|
239
|
-
constructor(e, t, n,
|
|
240
|
-
super(e, t, n,
|
|
239
|
+
constructor(e, t, n, r) {
|
|
240
|
+
super(e, t, n, r);
|
|
241
241
|
}
|
|
242
242
|
getUrlData() {
|
|
243
243
|
return this.channel.call("getUrlData");
|
|
@@ -249,7 +249,7 @@ class p extends h {
|
|
|
249
249
|
export {
|
|
250
250
|
g as ContelloCustomProperty,
|
|
251
251
|
u as ContelloDialog,
|
|
252
|
-
|
|
252
|
+
v as ContelloDialogRef,
|
|
253
253
|
p as ContelloExtension,
|
|
254
|
-
|
|
254
|
+
P as ExtensionChannel
|
|
255
255
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +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
|
|
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 P=Object.defineProperty;var v=(l,o,h)=>o in l?P(l,o,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[o]=h;var r=(l,o,h)=>(v(l,typeof o!="symbol"?o+"":o,h),h);let o=0,h=0;class y{constructor(e){r(this,"handlers",new Map);r(this,"listeners",new Map);r(this,"targetWindow");r(this,"channelId");r(this,"targetOrigin");r(this,"isParent");r(this,"handler",e=>{var t;if(e.data.channelId===this.channelId&&(this.targetOrigin==="*"||e.origin===this.targetOrigin)){const{channelId:n,requestId:i,method:a}=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(a)&&Promise.resolve((t=this.listeners.get(a))==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 a=this.createRequestId();this.send({channelId:this.channelId,requestId:a,method:e,payload:t}),this.handlers.set(a,s=>{if(this.handlers.delete(a),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}){r(this,"_id");r(this,"open");r(this,"connected");r(this,"ready");r(this,"complete");r(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(){r(this,"resolve");r(this,"reject");r(this,"promise",new Promise((e,t)=>{this.resolve=e,this.reject=t}))}}class u{constructor(e,t,n,i){r(this,"channel");r(this,"projectId");r(this,"resizeObserver");r(this,"targetOrigin");r(this,"data");r(this,"dialogs",new Map);this.channel=new y({debug:i}),this.channel.connectParent(e,t),this.projectId=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)}createProjectUrl(){return`${this.targetOrigin}/ui/projects/${this.projectId}`}createSingletonEntityUrl(e){return`${this.createProjectUrl()}/entities/${e}`}createEntityUrl(e,t){return`${this.createProjectUrl()}/entities/${e}/${t}`}createExtensionUrl(e,t){var a;const n=((a=t==null?void 0:t.path)==null?void 0:a.join("/"))||"",i=new URLSearchParams((t==null?void 0:t.query)||{}).toString();return`${this.createProjectUrl()}/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"),a=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:a}}class w extends u{constructor(t,n,i,a){super(t,n,i,a);r(this,"validate",()=>!0);r(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:a,debug:s}=p(t.trustedOrigins),d=new w(n,i,a,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:a}=p(e),s=new I(t,n,i,a);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:a}=p(e),s=new m(t,n,i,a);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"})});
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"require": "./dist/index.umd.cjs"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"license": "
|
|
16
|
+
"license": "MIT",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"start": "vite build --watch",
|
|
19
19
|
"build": "vite build",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"access": "public",
|
|
35
35
|
"registry": "https://registry.npmjs.org"
|
|
36
36
|
},
|
|
37
|
-
"version": "
|
|
38
|
-
}
|
|
37
|
+
"version": "8.0.0"
|
|
38
|
+
}
|