@kissflow/lowcode-client-sdk 1.0.9 → 1.0.12-beta

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,4 +1,4 @@
1
- declare module "constants" {
1
+ declare module "core/constants" {
2
2
  export const LISTENER_CMDS: {
3
3
  API: string;
4
4
  PARAMS: string;
@@ -33,30 +33,42 @@ declare module "constants" {
33
33
  GET_POPUP_PARAMS: string;
34
34
  GET_ALL_POPUP_PARAMS: string;
35
35
  CLOSE_POPUP: string;
36
- GET_COMPONENT: string;
36
+ COMPONENT_GET: string;
37
37
  COMPONENT_REFRESH: string;
38
38
  COMPONENT_SHOW: string;
39
39
  COMPONENT_HIDE: string;
40
+ COMPONENT_ADD_EVENT_LISTENER: string;
40
41
  INITIALIZE_CUST_COMP: string;
42
+ WINDOW_NDEF_READER_NEW: string;
43
+ WINDOW_NDEF_READER_SCAN: string;
44
+ WINDOW_NDEF_READER_WRITE: string;
45
+ WINDOW_NDEF_READER_ADD_EVENT_LISTENER: string;
46
+ WINDOW_NDEF_READER_MAKE_READONLY: string;
47
+ WINDOW_NDEF_READER_ABORT_SCAN: string;
41
48
  };
42
49
  export const EVENT_TYPES: {
43
- ON_CLOSE: string;
44
- POPUP_ON_CLOSE: string;
45
- ON_CHANGE: string;
46
- ON_LOAD: string;
50
+ COMPONENT_ON_MOUNT: string;
47
51
  };
48
52
  export const DEFAULTS: {
49
53
  POPUP_ID: string;
50
54
  };
51
55
  }
52
- declare module "base" {
53
- export class BaseSDK {
56
+ declare module "core/index" {
57
+ export function generateId(prefix?: string): string;
58
+ export const globalInstances: {};
59
+ export class EventBase {
54
60
  #private;
55
- constructor(props: any);
61
+ constructor();
62
+ _addEventListener(eventName: string, callBack: Function): void;
63
+ _removeEventListener(eventName: string, callBack?: any): void;
64
+ _dispatchEvent(eventName: string, eventParams: object): boolean;
65
+ _dispatchMessageEvents(req: any, resp: any): void;
66
+ }
67
+ export class BaseSDK extends EventBase {
56
68
  _postMessageAsync(command: string, args: any, hasCallBack?: boolean, callBack?: (data: any) => {}): object | string | any;
57
- _postMessage(command: string, func: (data: any) => {}, args?: {}): void;
58
- _registerEventListener(_id: string, eventType: string, callback: any): void;
69
+ _postMessage(command: string, args: any, callBack?: any): void;
59
70
  }
71
+ export * from "core/constants";
60
72
  }
61
73
  declare module "types/external" {
62
74
  export type userObject = {
@@ -69,29 +81,34 @@ declare module "types/external" {
69
81
  export type accountObject = {
70
82
  _id: string;
71
83
  };
84
+ export type environmentObject = {
85
+ isMobile: boolean;
86
+ };
72
87
  }
73
88
  declare module "types/internal" {
74
- import { userObject, accountObject } from "types/external";
89
+ import { userObject, accountObject, environmentObject } from "types/external";
75
90
  export interface SDKContext {
76
91
  formInstanceId: string;
77
92
  tableId: string;
78
93
  tableRowId: string;
79
94
  componentId: string;
80
- manifestMethods?: manifestMethodsType[];
95
+ componentMethods?: componentMethodsType[];
81
96
  appId: string;
82
97
  pageId: string;
83
98
  popupId: string;
84
99
  user: userObject;
85
100
  account: accountObject;
101
+ csrfToken: string;
102
+ envDetails: environmentObject;
86
103
  }
87
- export interface manifestMethodsType {
104
+ export interface componentMethodsType {
88
105
  name: string;
89
106
  returnType?: string;
90
107
  parameters?: string[];
91
108
  }
92
109
  export interface ComponentProps {
93
110
  componentId: string;
94
- manifestMethods?: manifestMethodsType[];
111
+ componentMethods?: componentMethodsType[];
95
112
  }
96
113
  export interface AppContext {
97
114
  appId: string;
@@ -104,13 +121,15 @@ declare module "types/internal" {
104
121
  popupId?: string;
105
122
  }
106
123
  }
107
- declare module "component" {
108
- import { BaseSDK } from "base";
124
+ declare module "app/component" {
125
+ import { BaseSDK } from "core/index";
109
126
  import { ComponentProps } from "types/internal";
110
127
  export class Component extends BaseSDK {
128
+ #private;
111
129
  _id: string;
112
130
  type: string;
113
131
  constructor(props: ComponentProps);
132
+ onMount(callback: Function): void;
114
133
  refresh(): any;
115
134
  show(): any;
116
135
  hide(): any;
@@ -121,9 +140,9 @@ declare module "component" {
121
140
  watchParams(func: (data: any) => any): void;
122
141
  }
123
142
  }
124
- declare module "popup" {
125
- import { Component } from "component";
126
- import { BaseSDK } from "base";
143
+ declare module "app/popup" {
144
+ import { BaseSDK } from "core/index";
145
+ import { Component } from "app/component";
127
146
  import { PopupContext } from "types/internal";
128
147
  export class Popup extends BaseSDK {
129
148
  _id: string;
@@ -135,10 +154,10 @@ declare module "popup" {
135
154
  getComponent(componentId: string): Component;
136
155
  }
137
156
  }
138
- declare module "page" {
139
- import { Component } from "component";
140
- import { BaseSDK } from "base";
141
- import { Popup } from "popup";
157
+ declare module "app/page" {
158
+ import { BaseSDK } from "core/index";
159
+ import { Component } from "app/component";
160
+ import { Popup } from "app/popup";
142
161
  import { PageContext } from "types/internal";
143
162
  export class Page extends BaseSDK {
144
163
  _id: string;
@@ -153,21 +172,24 @@ declare module "page" {
153
172
  getComponent(componentId: string): Component;
154
173
  }
155
174
  }
156
- declare module "app" {
157
- import { BaseSDK } from "base";
158
- import { Page } from "page";
175
+ declare module "app/index" {
176
+ import { BaseSDK } from "core/index";
177
+ import { Page } from "app/page";
159
178
  import { AppContext } from "types/internal";
160
179
  export class Application extends BaseSDK {
161
180
  page: Page;
162
181
  _id: string;
163
182
  constructor(props: AppContext);
164
183
  getVariable(key: string): any;
165
- setVariable(key: string | object, value: any): any;
184
+ setVariable(key: string | object, value?: any): any;
166
185
  openPage(pageId: string, pageParams: object): any;
167
186
  }
187
+ export * from "app/component";
188
+ export { Page };
189
+ export * from "app/popup";
168
190
  }
169
- declare module "client" {
170
- import { BaseSDK } from "base";
191
+ declare module "utils/client" {
192
+ import { BaseSDK } from "core/index";
171
193
  export class Client extends BaseSDK {
172
194
  showInfo(message: string): any;
173
195
  showConfirm(args: {
@@ -179,8 +201,44 @@ declare module "client" {
179
201
  redirect(url: string): any;
180
202
  }
181
203
  }
182
- declare module "form" {
183
- import { BaseSDK } from "base";
204
+ declare module "utils/formatter" {
205
+ import { BaseSDK } from "core/index";
206
+ export class Formatter extends BaseSDK {
207
+ toDate(date: string): any;
208
+ toDateTime(date: string): any;
209
+ toNumber(value: string): any;
210
+ toCurrency(value: string, currencyCode: string): any;
211
+ toBoolean(value: string): any;
212
+ }
213
+ }
214
+ declare module "utils/index" {
215
+ export * from "utils/client";
216
+ export * from "utils/formatter";
217
+ }
218
+ declare module "index" {
219
+ import { BaseSDK } from "core/index";
220
+ import { Application, Page, CustomComponent } from "app/index";
221
+ import { Client, Formatter } from "utils/index";
222
+ import { userObject, accountObject, environmentObject } from "types/external";
223
+ class CustomComponentSDK extends BaseSDK {
224
+ app: Application;
225
+ page: Page;
226
+ user: userObject;
227
+ account: accountObject;
228
+ context: CustomComponent;
229
+ client: Client;
230
+ formatter: Formatter;
231
+ env: environmentObject;
232
+ constructor();
233
+ api(url: string, args?: {}): string | object;
234
+ initialize(): any;
235
+ initialise(): any;
236
+ }
237
+ const _default: CustomComponentSDK;
238
+ export default _default;
239
+ }
240
+ declare module "form/index" {
241
+ import { BaseSDK } from "core/index";
184
242
  export class Form extends BaseSDK {
185
243
  private instanceId;
186
244
  type: string;
@@ -212,36 +270,21 @@ declare module "form" {
212
270
  updateField(args: object): any;
213
271
  }
214
272
  }
215
- declare module "formatter" {
216
- import { BaseSDK } from "base";
217
- export class Formatter extends BaseSDK {
218
- toDate(date: string): any;
219
- toDateTime(date: string): any;
220
- toNumber(value: string): any;
221
- toCurrency(value: string, currencyCode: string): any;
222
- toBoolean(value: string): any;
223
- }
224
- }
225
- declare module "index" {
226
- import { BaseSDK } from "base";
227
- import { Client } from "client";
228
- import { Formatter } from "formatter";
229
- import { Application } from "app";
230
- import { Page } from "page";
231
- import { CustomComponent } from "component";
232
- import { userObject, accountObject } from "types/external";
233
- class CustomComponentSDK extends BaseSDK {
234
- app: Application;
235
- page: Page;
236
- user: userObject;
237
- account: accountObject;
238
- context: CustomComponent;
239
- client: Client;
240
- formatter: Formatter;
273
+ declare module "window/NDEFReader" {
274
+ import { BaseSDK } from "core/index";
275
+ export class NDEFReader extends BaseSDK {
276
+ id: string;
241
277
  constructor();
242
- api(url: string, args?: {}): string | object;
243
- initialise(): any;
278
+ scan(): Promise<unknown>;
279
+ write(data: any): Promise<unknown>;
280
+ addEventListener(eventName: string, cb: Function): void;
281
+ makeReadOnly(): Promise<unknown>;
282
+ abortScan(): Promise<unknown>;
244
283
  }
245
- const _default: CustomComponentSDK;
246
- export default _default;
284
+ }
285
+ declare module "window/index" {
286
+ import { NDEFReader } from "window/NDEFReader";
287
+ export const window: {
288
+ NDEFReader: typeof NDEFReader;
289
+ };
247
290
  }
package/dist/kfsdk.es.js CHANGED
@@ -36,7 +36,7 @@ var __privateMethod = (obj, member, method) => {
36
36
  __accessCheck(obj, member, "access private method");
37
37
  return method;
38
38
  };
39
- var _listeners, _eventListeners, _addListener, addListener_fn, _appendEventListeners, appendEventListeners_fn, _checkEvents, checkEvents_fn, _onMessage, onMessage_fn;
39
+ var _listeners, _registerComponentAPIs, registerComponentAPIs_fn;
40
40
  let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
41
41
  byte &= 63;
42
42
  if (byte < 36) {
@@ -84,11 +84,21 @@ const LISTENER_CMDS = {
84
84
  GET_POPUP_PARAMS: "GET_POPUP_PARAMS",
85
85
  GET_ALL_POPUP_PARAMS: "GET_ALL_POPUP_PARAMS",
86
86
  CLOSE_POPUP: "CLOSE_POPUP",
87
- GET_COMPONENT: "GET_COMPONENT",
87
+ COMPONENT_GET: "COMPONENT_GET",
88
88
  COMPONENT_REFRESH: "COMPONENT_REFRESH",
89
89
  COMPONENT_SHOW: "COMPONENT_SHOW",
90
90
  COMPONENT_HIDE: "COMPONENT_HIDE",
91
- INITIALIZE_CUST_COMP: "INITIALIZE_CUST_COMP"
91
+ COMPONENT_ADD_EVENT_LISTENER: "COMPONENT_ADD_EVENT_LISTENER",
92
+ INITIALIZE_CUST_COMP: "INITIALIZE_CUST_COMP",
93
+ WINDOW_NDEF_READER_NEW: "WINDOW_NDEF_READER_NEW",
94
+ WINDOW_NDEF_READER_SCAN: "WINDOW_NDEF_READER_SCAN",
95
+ WINDOW_NDEF_READER_WRITE: "WINDOW_NDEF_READER_WRITE",
96
+ WINDOW_NDEF_READER_ADD_EVENT_LISTENER: "WINDOW_NDEF_READER_ADD_EVENT_LISTENER",
97
+ WINDOW_NDEF_READER_MAKE_READONLY: "WINDOW_NDEF_READER_MAKE_READONLY",
98
+ WINDOW_NDEF_READER_ABORT_SCAN: "WINDOW_NDEF_READER_ABORT_SCAN"
99
+ };
100
+ const EVENT_TYPES = {
101
+ COMPONENT_ON_MOUNT: "componentOnMount"
92
102
  };
93
103
  const DEFAULTS = {
94
104
  POPUP_ID: "ACTIVE_POP_UP"
@@ -96,30 +106,85 @@ const DEFAULTS = {
96
106
  function generateId(prefix = "lcncsdk") {
97
107
  return `${prefix}-${nanoid()}`;
98
108
  }
109
+ const globalInstances = {};
99
110
  function postMessage(args) {
100
- if (self.parent && self.parent !== self) {
101
- self.parent.postMessage(args, "*");
111
+ if (globalThis.parent && globalThis.parent !== globalThis) {
112
+ globalThis.parent.postMessage(args, "*");
102
113
  } else {
103
- self.postMessage(args);
114
+ globalThis.postMessage(args);
104
115
  }
105
116
  }
106
- class BaseSDK {
107
- constructor(props) {
108
- __privateAdd(this, _addListener);
109
- __privateAdd(this, _appendEventListeners);
110
- __privateAdd(this, _checkEvents);
111
- __privateAdd(this, _onMessage);
117
+ function onMessage(event) {
118
+ if (event.origin !== globalThis.location.origin) {
119
+ const data = event.data;
120
+ if (data == null ? void 0 : data.isEvent) {
121
+ const { target, eventParams, eventName, eventConfig = {} } = data;
122
+ let targetInstance = globalInstances[target];
123
+ targetInstance._dispatchEvent(eventName, eventParams);
124
+ if (eventConfig.once) {
125
+ targetInstance._removeEventListener(eventName);
126
+ }
127
+ return;
128
+ }
129
+ let { _req: req, resp } = data;
130
+ if (req == null ? void 0 : req._id) {
131
+ let targetInstance = globalInstances[req._id];
132
+ targetInstance._dispatchMessageEvents(req, resp);
133
+ }
134
+ }
135
+ }
136
+ globalThis.addEventListener("message", onMessage);
137
+ class EventBase {
138
+ constructor() {
112
139
  __privateAdd(this, _listeners, void 0);
113
- __privateAdd(this, _eventListeners, void 0);
114
140
  __privateSet(this, _listeners, {});
115
- __privateSet(this, _eventListeners, {});
116
- self.addEventListener("message", __privateMethod(this, _onMessage, onMessage_fn).bind(this), false);
117
141
  }
142
+ _addEventListener(eventName, callBack) {
143
+ var _a;
144
+ __privateGet(this, _listeners)[eventName] = ((_a = __privateGet(this, _listeners)) == null ? void 0 : _a[eventName]) || [];
145
+ __privateGet(this, _listeners)[eventName].push(callBack);
146
+ }
147
+ _removeEventListener(eventName, callBack) {
148
+ if (callBack) {
149
+ let index2 = __privateGet(this, _listeners)[eventName].findIndex(callBack);
150
+ index2 > -1 && __privateGet(this, _listeners)[eventName].splice(index2, 1);
151
+ return;
152
+ }
153
+ Reflect.deleteProperty(__privateGet(this, _listeners), eventName);
154
+ }
155
+ _dispatchEvent(eventName, eventParams) {
156
+ if (Array.isArray(__privateGet(this, _listeners)[eventName])) {
157
+ __privateGet(this, _listeners)[eventName].forEach((callBack) => callBack(eventParams));
158
+ return true;
159
+ }
160
+ return false;
161
+ }
162
+ _dispatchMessageEvents(req, resp) {
163
+ let target = req._id;
164
+ if (Array.isArray(__privateGet(this, _listeners)[target])) {
165
+ __privateGet(this, _listeners)[target].forEach((listener) => {
166
+ try {
167
+ if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
168
+ listener(Object.values(resp)[0]);
169
+ } else {
170
+ listener(resp);
171
+ }
172
+ } catch (err) {
173
+ console.error("Message callback error: ", err);
174
+ }
175
+ });
176
+ this._removeEventListener(target);
177
+ }
178
+ }
179
+ }
180
+ _listeners = new WeakMap();
181
+ class BaseSDK extends EventBase {
118
182
  _postMessageAsync(command, args, hasCallBack, callBack) {
119
183
  return new Promise((resolve, reject) => {
120
184
  const _id = generateId(command.toLowerCase());
121
185
  postMessage(__spreadValues({ _id, command }, args));
122
- __privateMethod(this, _addListener, addListener_fn).call(this, _id, async (data) => {
186
+ globalInstances[_id] = this;
187
+ this._addEventListener(_id, async (data) => {
123
188
  if (data == null ? void 0 : data.errorMessage) {
124
189
  reject(data);
125
190
  } else {
@@ -131,114 +196,31 @@ class BaseSDK {
131
196
  });
132
197
  });
133
198
  }
134
- _postMessage(command, func, args = {}) {
199
+ _postMessage(command, args, callBack) {
135
200
  const _id = generateId(command.toLowerCase());
136
201
  postMessage(__spreadValues({ _id, command }, args));
137
- __privateMethod(this, _addListener, addListener_fn).call(this, _id, (data) => func(data));
138
- }
139
- _registerEventListener(_id, eventType, callback) {
140
- __privateMethod(this, _appendEventListeners, appendEventListeners_fn).call(this, _id, eventType, callback);
141
- }
142
- }
143
- _listeners = new WeakMap();
144
- _eventListeners = new WeakMap();
145
- _addListener = new WeakSet();
146
- addListener_fn = function(_id, callback) {
147
- __privateGet(this, _listeners)[_id] = __privateGet(this, _listeners)[_id] || [];
148
- __privateGet(this, _listeners)[_id].push(callback);
149
- };
150
- _appendEventListeners = new WeakSet();
151
- appendEventListeners_fn = function(_id, eventType, callback) {
152
- if (!__privateGet(this, _eventListeners)[_id]) {
153
- __privateGet(this, _eventListeners)[_id] = {};
154
- }
155
- __privateGet(this, _eventListeners)[_id][eventType] = callback;
156
- };
157
- _checkEvents = new WeakSet();
158
- checkEvents_fn = function(data) {
159
- const { _id, eventType, eventParams } = data;
160
- if (!_id || !eventType)
161
- return;
162
- const eventListener = __privateGet(this, _eventListeners)[_id] || {};
163
- if (eventListener[eventType]) {
164
- eventListener[eventType](eventParams || {});
165
- }
166
- };
167
- _onMessage = new WeakSet();
168
- onMessage_fn = function(event) {
169
- if (event.origin !== self.location.origin) {
170
- const data = event.data;
171
- if (data.isEvent) {
172
- return __privateMethod(this, _checkEvents, checkEvents_fn).call(this, data);
173
- }
174
- const _req = (data == null ? void 0 : data._req) || {};
175
- let listeners = __privateGet(this, _listeners)[_req == null ? void 0 : _req._id] || [];
176
- if (listeners) {
177
- listeners.forEach((listener) => {
178
- try {
179
- if (data.resp && Object.keys(data.resp).length === 1 && _req.command !== LISTENER_CMDS.API) {
180
- listener(Object.values(data.resp)[0]);
181
- } else {
182
- listener(data.resp);
183
- }
184
- } catch (err) {
185
- console.error("Message callback error: ", err);
186
- }
187
- });
202
+ if (callBack) {
203
+ this._addEventListener(args.eventName, callBack);
188
204
  }
189
205
  }
190
- };
191
- class Client extends BaseSDK {
192
- showInfo(message) {
193
- return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
194
- }
195
- showConfirm(args) {
196
- return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
197
- data: {
198
- title: args.title,
199
- content: args.content,
200
- okText: args.okText || "Ok",
201
- cancelText: args.cancelText || "Cancel"
202
- }
203
- });
204
- }
205
- redirect(url) {
206
- return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
207
- }
208
- }
209
- class Formatter extends BaseSDK {
210
- toDate(date) {
211
- return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
212
- date
213
- });
214
- }
215
- toDateTime(date) {
216
- return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
217
- date
218
- });
219
- }
220
- toNumber(value) {
221
- return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
222
- value
223
- });
224
- }
225
- toCurrency(value, currencyCode) {
226
- return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
227
- value,
228
- currencyCode
229
- });
230
- }
231
- toBoolean(value) {
232
- return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
233
- value
234
- });
235
- }
236
206
  }
237
207
  class Component extends BaseSDK {
238
208
  constructor(props) {
239
- super({});
209
+ super();
210
+ __privateAdd(this, _registerComponentAPIs);
240
211
  this._id = props.componentId;
241
212
  this.type = "Component";
213
+ globalInstances[this._id] = this;
214
+ __privateMethod(this, _registerComponentAPIs, registerComponentAPIs_fn).call(this, props.componentMethods);
215
+ }
216
+ onMount(callback) {
217
+ this._postMessage(LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER, {
218
+ id: this._id,
219
+ eventName: EVENT_TYPES.COMPONENT_ON_MOUNT,
220
+ eventConfig: {
221
+ once: true
222
+ }
223
+ }, callback);
242
224
  }
243
225
  refresh() {
244
226
  return this._postMessageAsync(LISTENER_CMDS.COMPONENT_REFRESH, {
@@ -256,9 +238,28 @@ class Component extends BaseSDK {
256
238
  });
257
239
  }
258
240
  }
241
+ _registerComponentAPIs = new WeakSet();
242
+ registerComponentAPIs_fn = function(componentAPIs) {
243
+ componentAPIs == null ? void 0 : componentAPIs.forEach((Api) => {
244
+ this[Api.name] = (...args) => {
245
+ if (Api.type === "method") {
246
+ return this._postMessageAsync(`COMPONENT_${Api.name}`, {
247
+ id: this._id,
248
+ parameters: args
249
+ });
250
+ } else if (Api.type === "event") {
251
+ this._postMessage(LISTENER_CMDS.COMPONENT_ADD_EVENT_LISTENER, {
252
+ id: this._id,
253
+ eventName: Api.name,
254
+ eventConfig: args[1]
255
+ }, args[0]);
256
+ }
257
+ };
258
+ });
259
+ };
259
260
  class CustomComponent extends BaseSDK {
260
261
  constructor() {
261
- super({});
262
+ super();
262
263
  this.type = "CustomComponent";
263
264
  }
264
265
  watchParams(func) {
@@ -267,7 +268,7 @@ class CustomComponent extends BaseSDK {
267
268
  }
268
269
  class Popup extends BaseSDK {
269
270
  constructor(props) {
270
- super({});
271
+ super();
271
272
  this.type = "Popup";
272
273
  this._id = props.popupId || DEFAULTS.POPUP_ID;
273
274
  }
@@ -286,14 +287,14 @@ class Popup extends BaseSDK {
286
287
  return this._postMessageAsync(LISTENER_CMDS.CLOSE_POPUP, {});
287
288
  }
288
289
  getComponent(componentId) {
289
- return this._postMessageAsync(LISTENER_CMDS.GET_COMPONENT, { componentId }, true, (data) => {
290
+ return this._postMessageAsync(LISTENER_CMDS.COMPONENT_GET, { componentId }, true, (data) => {
290
291
  return new Component(data);
291
292
  });
292
293
  }
293
294
  }
294
295
  class Page extends BaseSDK {
295
296
  constructor(props) {
296
- super({});
297
+ super();
297
298
  this.type = "Page";
298
299
  this.popup = new Popup({});
299
300
  this._id = props.pageId;
@@ -326,14 +327,12 @@ class Page extends BaseSDK {
326
327
  });
327
328
  }
328
329
  getComponent(componentId) {
329
- return this._postMessageAsync(LISTENER_CMDS.GET_COMPONENT, { componentId }, true, (data) => {
330
- return new Component(data);
331
- });
330
+ return this._postMessageAsync(LISTENER_CMDS.COMPONENT_GET, { componentId }, true, (data) => new Component(data));
332
331
  }
333
332
  }
334
333
  class Application extends BaseSDK {
335
334
  constructor(props) {
336
- super({});
335
+ super();
337
336
  this._id = props.appId;
338
337
  this.page = new Page(props);
339
338
  }
@@ -355,25 +354,75 @@ class Application extends BaseSDK {
355
354
  });
356
355
  }
357
356
  }
357
+ class Client extends BaseSDK {
358
+ showInfo(message) {
359
+ return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
360
+ }
361
+ showConfirm(args) {
362
+ return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
363
+ data: {
364
+ title: args.title,
365
+ content: args.content,
366
+ okText: args.okText || "Ok",
367
+ cancelText: args.cancelText || "Cancel"
368
+ }
369
+ });
370
+ }
371
+ redirect(url) {
372
+ return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
373
+ }
374
+ }
375
+ class Formatter extends BaseSDK {
376
+ toDate(date) {
377
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
378
+ date
379
+ });
380
+ }
381
+ toDateTime(date) {
382
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
383
+ date
384
+ });
385
+ }
386
+ toNumber(value) {
387
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
388
+ value
389
+ });
390
+ }
391
+ toCurrency(value, currencyCode) {
392
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
393
+ value,
394
+ currencyCode
395
+ });
396
+ }
397
+ toBoolean(value) {
398
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
399
+ value
400
+ });
401
+ }
402
+ }
358
403
  class CustomComponentSDK extends BaseSDK {
359
404
  constructor() {
360
- super({});
405
+ super();
361
406
  }
362
407
  api(url, args = {}) {
363
408
  return this._postMessageAsync(LISTENER_CMDS.API, { url, args });
364
409
  }
365
- initialise() {
410
+ initialize() {
366
411
  return this._postMessageAsync(LISTENER_CMDS.INITIALIZE_CUST_COMP, {}, true, (data) => {
367
412
  this.app = new Application(data);
368
413
  this.page = new Page(data);
369
414
  this.context = new CustomComponent();
370
- this.client = new Client({});
371
- this.formatter = new Formatter({});
415
+ this.client = new Client();
416
+ this.formatter = new Formatter();
372
417
  this.user = data.user;
373
418
  this.account = data.account;
419
+ this.env = data.envDetails;
374
420
  return this;
375
421
  });
376
422
  }
423
+ initialise() {
424
+ return this.initialize();
425
+ }
377
426
  }
378
427
  var index = new CustomComponentSDK();
379
428
  export { index as default };