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