@kissflow/lowcode-client-sdk 1.0.8 → 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.
@@ -0,0 +1,290 @@
1
+ declare module "core/constants" {
2
+ export const LISTENER_CMDS: {
3
+ API: string;
4
+ PARAMS: string;
5
+ GET_CONTEXT: string;
6
+ RETURN: string;
7
+ GET_FORM_FIELD: string;
8
+ UPDATE_FORM: string;
9
+ GET_TABLE: string;
10
+ GET_TABLE_ROW: string;
11
+ ADD_TABLE_ROW: string;
12
+ DELETE_TABLE_ROW: string;
13
+ TO_JSON: string;
14
+ GET_TABLE_ROWS: string;
15
+ MESSAGE: string;
16
+ CONFIRM: string;
17
+ ALERT: string;
18
+ REDIRECT: string;
19
+ OPEN_PAGE: string;
20
+ FORMAT_DATE: string;
21
+ FORMAT_DATE_TIME: string;
22
+ FORMAT_NUMBER: string;
23
+ FORMAT_CURRENCY: string;
24
+ FORMAT_BOOLEAN: string;
25
+ GET_APP_VARIABLE: string;
26
+ SET_APP_VARIABLE: string;
27
+ GET_PAGE_VARIABLE: string;
28
+ SET_PAGE_VARIABLE: string;
29
+ GET_PAGE_PARAMS: string;
30
+ GET_ALL_PAGE_PARAMS: string;
31
+ PAGE_ON_CLOSE: string;
32
+ OPEN_POPUP: string;
33
+ GET_POPUP_PARAMS: string;
34
+ GET_ALL_POPUP_PARAMS: string;
35
+ CLOSE_POPUP: string;
36
+ COMPONENT_GET: string;
37
+ COMPONENT_REFRESH: string;
38
+ COMPONENT_SHOW: string;
39
+ COMPONENT_HIDE: string;
40
+ COMPONENT_ADD_EVENT_LISTENER: string;
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;
48
+ };
49
+ export const EVENT_TYPES: {
50
+ COMPONENT_ON_MOUNT: string;
51
+ };
52
+ export const DEFAULTS: {
53
+ POPUP_ID: string;
54
+ };
55
+ }
56
+ declare module "core/index" {
57
+ export function generateId(prefix?: string): string;
58
+ export const globalInstances: {};
59
+ export class EventBase {
60
+ #private;
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 {
68
+ _postMessageAsync(command: string, args: any, hasCallBack?: boolean, callBack?: (data: any) => {}): object | string | any;
69
+ _postMessage(command: string, args: any, callBack?: any): void;
70
+ }
71
+ export * from "core/constants";
72
+ }
73
+ declare module "types/external" {
74
+ export type userObject = {
75
+ _id: string;
76
+ Name: string;
77
+ Email: string;
78
+ UserType: string;
79
+ Role: string;
80
+ };
81
+ export type accountObject = {
82
+ _id: string;
83
+ };
84
+ export type environmentObject = {
85
+ isMobile: boolean;
86
+ };
87
+ }
88
+ declare module "types/internal" {
89
+ import { userObject, accountObject, environmentObject } from "types/external";
90
+ export interface SDKContext {
91
+ formInstanceId: string;
92
+ tableId: string;
93
+ tableRowId: string;
94
+ componentId: string;
95
+ componentMethods?: componentMethodsType[];
96
+ appId: string;
97
+ pageId: string;
98
+ popupId: string;
99
+ user: userObject;
100
+ account: accountObject;
101
+ csrfToken: string;
102
+ envDetails: environmentObject;
103
+ }
104
+ export interface componentMethodsType {
105
+ name: string;
106
+ returnType?: string;
107
+ parameters?: string[];
108
+ }
109
+ export interface ComponentProps {
110
+ componentId: string;
111
+ componentMethods?: componentMethodsType[];
112
+ }
113
+ export interface AppContext {
114
+ appId: string;
115
+ pageId: string;
116
+ }
117
+ export interface PageContext {
118
+ pageId: string;
119
+ }
120
+ export interface PopupContext {
121
+ popupId?: string;
122
+ }
123
+ }
124
+ declare module "app/component" {
125
+ import { BaseSDK } from "core/index";
126
+ import { ComponentProps } from "types/internal";
127
+ export class Component extends BaseSDK {
128
+ #private;
129
+ _id: string;
130
+ type: string;
131
+ constructor(props: ComponentProps);
132
+ onMount(callback: Function): void;
133
+ refresh(): any;
134
+ show(): any;
135
+ hide(): any;
136
+ }
137
+ export class CustomComponent extends BaseSDK {
138
+ type: string;
139
+ constructor();
140
+ watchParams(func: (data: any) => any): void;
141
+ }
142
+ }
143
+ declare module "app/popup" {
144
+ import { BaseSDK } from "core/index";
145
+ import { Component } from "app/component";
146
+ import { PopupContext } from "types/internal";
147
+ export class Popup extends BaseSDK {
148
+ _id: string;
149
+ type: string;
150
+ constructor(props: PopupContext);
151
+ getParameter(key: string): any;
152
+ getAllParameters(): any;
153
+ close(): any;
154
+ getComponent(componentId: string): Component;
155
+ }
156
+ }
157
+ declare module "app/page" {
158
+ import { BaseSDK } from "core/index";
159
+ import { Component } from "app/component";
160
+ import { Popup } from "app/popup";
161
+ import { PageContext } from "types/internal";
162
+ export class Page extends BaseSDK {
163
+ _id: string;
164
+ popup: Popup;
165
+ type: string;
166
+ constructor(props: PageContext);
167
+ getParameter(key: string): any;
168
+ getAllParameters(): any;
169
+ getVariable(key: string): any;
170
+ setVariable(key: string, value: any): any;
171
+ openPopup(popupId: string, popupParams: object): any;
172
+ getComponent(componentId: string): Component;
173
+ }
174
+ }
175
+ declare module "app/index" {
176
+ import { BaseSDK } from "core/index";
177
+ import { Page } from "app/page";
178
+ import { AppContext } from "types/internal";
179
+ export class Application extends BaseSDK {
180
+ page: Page;
181
+ _id: string;
182
+ constructor(props: AppContext);
183
+ getVariable(key: string): any;
184
+ setVariable(key: string | object, value?: any): any;
185
+ openPage(pageId: string, pageParams: object): any;
186
+ }
187
+ export * from "app/component";
188
+ export { Page };
189
+ export * from "app/popup";
190
+ }
191
+ declare module "utils/client" {
192
+ import { BaseSDK } from "core/index";
193
+ export class Client extends BaseSDK {
194
+ showInfo(message: string): any;
195
+ showConfirm(args: {
196
+ title: string;
197
+ content: string;
198
+ okText: string;
199
+ cancelText: string;
200
+ }): any;
201
+ redirect(url: string): any;
202
+ }
203
+ }
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";
242
+ export class Form extends BaseSDK {
243
+ private instanceId;
244
+ type: string;
245
+ constructor(instanceId: string);
246
+ toJSON(): any;
247
+ getField(fieldId: string): any;
248
+ updateField(args: object): any;
249
+ getTable(tableId: string): Table;
250
+ }
251
+ class Table extends BaseSDK {
252
+ private tableId;
253
+ private instanceId;
254
+ constructor(instanceId: string, tableId: string);
255
+ toJSON(): any;
256
+ getRows(): TableForm[];
257
+ getRow(rowId: string): TableForm;
258
+ addRow(rowObject: object): any;
259
+ deleteRow(rowId: string): any;
260
+ }
261
+ export class TableForm extends BaseSDK {
262
+ private instanceId;
263
+ private tableId;
264
+ private rowId;
265
+ type: string;
266
+ constructor(instanceId: string, tableId: string, rowId: string);
267
+ getParent(): Form;
268
+ toJSON(): any;
269
+ getField(fieldId: string): any;
270
+ updateField(args: object): any;
271
+ }
272
+ }
273
+ declare module "window/NDEFReader" {
274
+ import { BaseSDK } from "core/index";
275
+ export class NDEFReader extends BaseSDK {
276
+ id: string;
277
+ constructor();
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>;
283
+ }
284
+ }
285
+ declare module "window/index" {
286
+ import { NDEFReader } from "window/NDEFReader";
287
+ export const window: {
288
+ NDEFReader: typeof NDEFReader;
289
+ };
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 };