@contello/extension 8.0.0 → 8.0.1

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 CHANGED
@@ -1,6 +1,15 @@
1
1
  import { ContelloClientChildMethods, ContelloClientParentMethods } from './methods';
2
2
  import { ExtensionChannel } from './channel';
3
3
  import { ContelloDialogRef, ContelloDialogOptions } from './dialog-ref';
4
+ type ContelloEntityDetailParams = {
5
+ mode: 'create';
6
+ } | {
7
+ mode: 'edit';
8
+ id: string;
9
+ } | {
10
+ mode: 'clone';
11
+ id: string;
12
+ };
4
13
  export declare class ContelloClient<D, O extends ContelloClientChildMethods, R extends ContelloClientParentMethods> {
5
14
  protected channel: ExtensionChannel<O, R>;
6
15
  protected projectId: string;
@@ -13,8 +22,13 @@ export declare class ContelloClient<D, O extends ContelloClientChildMethods, R e
13
22
  ready(): Promise<R["ready"][1]>;
14
23
  getAuthToken(): Promise<string>;
15
24
  createProjectUrl(): string;
25
+ private createEntityEntryUrl;
16
26
  createSingletonEntityUrl(referenceName: string): string;
17
- createEntityUrl(referenceName: string, entityId?: string): string;
27
+ createEntityDetailUrl(referenceName: string, params: ContelloEntityDetailParams): string;
28
+ /**
29
+ * @deprecated Use createEntityDetailUrl instead
30
+ */
31
+ createEntityUrl(referenceName: string, entityId: string): string;
18
32
  createExtensionUrl(referenceName: string, params?: {
19
33
  path?: string[];
20
34
  query?: {
@@ -28,3 +42,4 @@ export declare class ContelloClient<D, O extends ContelloClientChildMethods, R e
28
42
  private getWindowHeight;
29
43
  private getDialogController;
30
44
  }
45
+ export {};
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
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;
1
+ var p = Object.defineProperty;
2
+ var I = (l, e, t) => e in l ? p(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
3
  var i = (l, e, t) => (I(l, typeof e != "symbol" ? e + "" : e, t), t);
4
- let m = 0, y = 0;
5
- class P {
4
+ let y = 0, m = 0;
5
+ class v {
6
6
  constructor(e) {
7
7
  i(this, "handlers", /* @__PURE__ */ new Map());
8
8
  i(this, "listeners", /* @__PURE__ */ new Map());
@@ -72,13 +72,13 @@ class P {
72
72
  (t = this.targetWindow) == null || t.postMessage(e, this.targetOrigin);
73
73
  }
74
74
  createChannelId() {
75
- return `contello-channel-${++m}-${Math.random().toString(36).substring(2)}`;
75
+ return `contello-channel-${++y}-${Math.random().toString(36).substring(2)}`;
76
76
  }
77
77
  createRequestId() {
78
- return `${this.isParent ? "parent" : "child"}-request-${++y}-${Math.random().toString(36).substring(2)}`;
78
+ return `${this.isParent ? "parent" : "child"}-request-${++m}-${Math.random().toString(36).substring(2)}`;
79
79
  }
80
80
  }
81
- class v {
81
+ class P {
82
82
  constructor({ channel: e, options: t, controller: n }) {
83
83
  i(this, "_id");
84
84
  i(this, "open");
@@ -109,7 +109,7 @@ class h {
109
109
  i(this, "targetOrigin");
110
110
  i(this, "data");
111
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;
112
+ this.channel = new v({ 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 }) => {
@@ -134,11 +134,21 @@ class h {
134
134
  createProjectUrl() {
135
135
  return `${this.targetOrigin}/ui/projects/${this.projectId}`;
136
136
  }
137
- createSingletonEntityUrl(e) {
137
+ createEntityEntryUrl(e) {
138
138
  return `${this.createProjectUrl()}/entities/${e}`;
139
139
  }
140
+ createSingletonEntityUrl(e) {
141
+ return this.createEntityEntryUrl(e);
142
+ }
143
+ createEntityDetailUrl(e, t) {
144
+ const n = this.createEntityEntryUrl(e);
145
+ return t.mode === "create" ? `${n}/create` : `${n}/${t.mode}/${t.id}`;
146
+ }
147
+ /**
148
+ * @deprecated Use createEntityDetailUrl instead
149
+ */
140
150
  createEntityUrl(e, t) {
141
- return `${this.createProjectUrl()}/entities/${e}/${t}`;
151
+ return this.createEntityDetailUrl(e, { mode: "edit", id: t });
142
152
  }
143
153
  createExtensionUrl(e, t) {
144
154
  var a;
@@ -161,7 +171,7 @@ class h {
161
171
  throw new Error("The channel is not yet initialized");
162
172
  this.channel.call("closeDialog", { id: n.id }), this.dialogs.delete(n);
163
173
  }
164
- }, n = new v({ channel: this.channel, options: e, controller: t });
174
+ }, n = new P({ channel: this.channel, options: e, controller: t });
165
175
  return this.dialogs.set(n, t), n.complete.then(() => this.dialogs.delete(n)), n;
166
176
  }
167
177
  listenForResize() {
@@ -231,9 +241,9 @@ class u extends h {
231
241
  return this.channel.call("complete", { value: e });
232
242
  }
233
243
  }
234
- class p extends h {
244
+ class w extends h {
235
245
  static connect({ trustedOrigins: e }) {
236
- const { targetOrigin: t, channelId: n, applicationId: r, debug: a } = d(e), s = new p(t, n, r, a);
246
+ const { targetOrigin: t, channelId: n, applicationId: r, debug: a } = d(e), s = new w(t, n, r, a);
237
247
  return s.connect().then(() => s);
238
248
  }
239
249
  constructor(e, t, n, r) {
@@ -249,7 +259,7 @@ class p extends h {
249
259
  export {
250
260
  g as ContelloCustomProperty,
251
261
  u as ContelloDialog,
252
- v as ContelloDialogRef,
253
- p as ContelloExtension,
254
- P as ExtensionChannel
262
+ P as ContelloDialogRef,
263
+ w as ContelloExtension,
264
+ v as ExtensionChannel
255
265
  };
@@ -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 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"})});
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 m{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 m({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}`}createEntityEntryUrl(e){return`${this.createProjectUrl()}/entities/${e}`}createSingletonEntityUrl(e){return this.createEntityEntryUrl(e)}createEntityDetailUrl(e,t){const n=this.createEntityEntryUrl(e);return t.mode==="create"?`${n}/create`:`${n}/${t.mode}/${t.id}`}createEntityUrl(e,t){return this.createEntityDetailUrl(e,{mode:"edit",id: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 y extends u{static connect({trustedOrigins:e}){const{targetOrigin:t,channelId:n,applicationId:i,debug:a}=p(e),s=new y(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 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)}getUrlData(){return this.channel.call("getUrlData")}setBreadcrumbs(e){return this.channel.call("setBreadcrumbs",{breadcrumbs:e})}}l.ContelloCustomProperty=w,l.ContelloDialog=y,l.ContelloDialogRef=f,l.ContelloExtension=I,l.ExtensionChannel=m,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -34,5 +34,5 @@
34
34
  "access": "public",
35
35
  "registry": "https://registry.npmjs.org"
36
36
  },
37
- "version": "8.0.0"
37
+ "version": "8.0.1"
38
38
  }