@kissflow/lowcode-client-sdk 1.0.22 → 1.0.24-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -71,9 +71,47 @@ declare module "core/index" {
71
71
  export class BaseSDK extends EventBase {
72
72
  _postMessageAsync(command: string, args: any, hasCallBack?: boolean, callBack?: (data: any) => {}): object | string | any;
73
73
  _postMessage(command: string, args: any, callBack?: any): void;
74
+ _postMessageSync(command: string, args: any): any;
74
75
  }
75
76
  export * from "core/constants";
76
77
  }
78
+ declare module "utils/client" {
79
+ import { BaseSDK } from "core/index";
80
+ export class Client extends BaseSDK {
81
+ showInfo(message: string): any;
82
+ showConfirm(args: {
83
+ title: string;
84
+ content: string;
85
+ okText: string;
86
+ cancelText: string;
87
+ }): any;
88
+ redirect(url: string): any;
89
+ }
90
+ }
91
+ declare module "utils/formatter" {
92
+ import { BaseSDK } from "core/index";
93
+ export class Formatter extends BaseSDK {
94
+ toDate(date: string): any;
95
+ toDateTime(date: string): any;
96
+ toNumber(value: string): any;
97
+ toCurrency(value: string, currencyCode: string): any;
98
+ toBoolean(value: string): any;
99
+ }
100
+ }
101
+ declare module "utils/index" {
102
+ export * from "utils/client";
103
+ export * from "utils/formatter";
104
+ export const isObject: (value: any) => boolean;
105
+ }
106
+ declare module "core/proxy" {
107
+ export class CreateProxy {
108
+ path: string[];
109
+ parent: object;
110
+ constructor(parent: object, target?: {}, path?: any[]);
111
+ get(target: object, property: string): any;
112
+ set(target: object, property: string, value: any, reciever: any): any;
113
+ }
114
+ }
77
115
  declare module "types/external" {
78
116
  export type userObject = {
79
117
  _id: string;
@@ -167,14 +205,20 @@ declare module "app/page" {
167
205
  _id: string;
168
206
  popup: Popup;
169
207
  type: string;
208
+ variable: PageVariable;
170
209
  constructor(props: PageContext);
171
210
  getParameter(key: string): any;
172
211
  getAllParameters(): any;
173
212
  getVariable(key: string): any;
174
- setVariable(key: string, value: any): any;
213
+ setVariable(key: string | object, value: any): any;
175
214
  openPopup(popupId: string, popupParams: object): any;
176
215
  getComponent(componentId: string): Component;
177
216
  }
217
+ class PageVariable extends BaseSDK {
218
+ constructor();
219
+ get(key: any, path: any): any;
220
+ set(key: any, value: any, path: any): any;
221
+ }
178
222
  }
179
223
  declare module "app/decisiontable" {
180
224
  import { BaseSDK } from "core/index";
@@ -200,6 +244,7 @@ declare module "app/index" {
200
244
  import { Dataform } from "app/dataform";
201
245
  export class Application extends BaseSDK {
202
246
  page: Page;
247
+ variable: AppVariable;
203
248
  _id: string;
204
249
  constructor(props: AppContext);
205
250
  getVariable(key: string): any;
@@ -208,37 +253,15 @@ declare module "app/index" {
208
253
  getDecisionTable(flowId: string): DecisionTable;
209
254
  getDataform(flowId: string): Dataform;
210
255
  }
256
+ class AppVariable extends BaseSDK {
257
+ constructor();
258
+ get(key: any, path: any): any;
259
+ set(key: any, value: any, path: any): any;
260
+ }
211
261
  export * from "app/component";
212
262
  export { Page };
213
263
  export * from "app/popup";
214
264
  }
215
- declare module "utils/client" {
216
- import { BaseSDK } from "core/index";
217
- export class Client extends BaseSDK {
218
- showInfo(message: string): any;
219
- showConfirm(args: {
220
- title: string;
221
- content: string;
222
- okText: string;
223
- cancelText: string;
224
- }): any;
225
- redirect(url: string): any;
226
- }
227
- }
228
- declare module "utils/formatter" {
229
- import { BaseSDK } from "core/index";
230
- export class Formatter extends BaseSDK {
231
- toDate(date: string): any;
232
- toDateTime(date: string): any;
233
- toNumber(value: string): any;
234
- toCurrency(value: string, currencyCode: string): any;
235
- toBoolean(value: string): any;
236
- }
237
- }
238
- declare module "utils/index" {
239
- export * from "utils/client";
240
- export * from "utils/formatter";
241
- }
242
265
  declare module "index" {
243
266
  import { BaseSDK } from "core/index";
244
267
  import { Application, Page, CustomComponent } from "app/index";
@@ -20,7 +20,7 @@ var __privateMethod = (obj, member, method) => {
20
20
  __accessCheck(obj, member, "access private method");
21
21
  return method;
22
22
  };
23
- var _listeners, _registerComponentAPIs, registerComponentAPIs_fn, _csrfToken;
23
+ var _listeners, _textEncoder, _textDecoder, _registerComponentAPIs, registerComponentAPIs_fn, _csrfToken;
24
24
  let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
25
25
  byte &= 63;
26
26
  if (byte < 36) {
@@ -95,6 +95,16 @@ function generateId(prefix = "lcncsdk") {
95
95
  return `${prefix}-${nanoid()}`;
96
96
  }
97
97
  const globalInstances = {};
98
+ function processResponse(req, resp) {
99
+ if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
100
+ let value = Object.values(resp)[0];
101
+ if (value === "undefined")
102
+ return void 0;
103
+ return value;
104
+ } else {
105
+ return resp;
106
+ }
107
+ }
98
108
  function postMessage(args) {
99
109
  if (globalThis.parent && globalThis.parent !== globalThis) {
100
110
  globalThis.parent.postMessage(args, "*");
@@ -154,11 +164,8 @@ class EventBase {
154
164
  if (Array.isArray(__privateGet(this, _listeners)[target])) {
155
165
  __privateGet(this, _listeners)[target].forEach((listener) => {
156
166
  try {
157
- if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
158
- listener(Object.values(resp)[0]);
159
- } else {
160
- listener(resp);
161
- }
167
+ let processedResp = processResponse(req, resp);
168
+ listener(processedResp);
162
169
  } catch (err) {
163
170
  console.error("Message callback error: ", err);
164
171
  }
@@ -193,7 +200,66 @@ class BaseSDK extends EventBase {
193
200
  this._addEventListener(args.eventName, callBack);
194
201
  }
195
202
  }
203
+ _postMessageSync(command, args) {
204
+ let intialValue = 0;
205
+ const _id = generateId(command.toLowerCase());
206
+ let data = { _id, command, ...args };
207
+ let atomics = new AtomicsHandler();
208
+ atomics.reset();
209
+ atomics.store(0, intialValue);
210
+ atomics.encodeData(1, data);
211
+ postMessage(atomics.sab);
212
+ atomics.wait(0, intialValue, 1e4);
213
+ let decodedData = atomics.decodeData();
214
+ let { _req: req, resp } = decodedData;
215
+ let processedResp = processResponse(req, resp);
216
+ if (processedResp == null ? void 0 : processedResp.isError) {
217
+ throw new Error(`Error: ${JSON.stringify(processedResp, null, 2)}`);
218
+ }
219
+ return processedResp;
220
+ }
221
+ }
222
+ let sharedArrayBufferInstance;
223
+ class AtomicsHandler {
224
+ constructor() {
225
+ __privateAdd(this, _textEncoder, void 0);
226
+ __privateAdd(this, _textDecoder, void 0);
227
+ __privateSet(this, _textEncoder, new TextEncoder());
228
+ __privateSet(this, _textDecoder, new TextDecoder());
229
+ sharedArrayBufferInstance = sharedArrayBufferInstance || new SharedArrayBuffer(1024 * 1024);
230
+ this.sab = sharedArrayBufferInstance;
231
+ this.int32Array = new Int32Array(this.sab);
232
+ }
233
+ load(index = 0) {
234
+ return Atomics.load(this.int32Array, index);
235
+ }
236
+ store(index = 0, data) {
237
+ return Atomics.store(this.int32Array, index, data);
238
+ }
239
+ reset() {
240
+ return this.int32Array.fill(0);
241
+ }
242
+ notify(index = 0, count = 1) {
243
+ return Atomics.notify(this.int32Array, index, count);
244
+ }
245
+ wait(index, value, timeout) {
246
+ return Atomics.wait(this.int32Array, index, value, timeout);
247
+ }
248
+ encodeData(index = 0, data) {
249
+ const replacer = (key, value) => value === void 0 ? "undefined" : value;
250
+ let string = JSON.stringify(data, replacer);
251
+ let encodedData = __privateGet(this, _textEncoder).encode(string);
252
+ this.int32Array.set(encodedData, index);
253
+ return this.int32Array;
254
+ }
255
+ decodeData() {
256
+ let uInt8Array = new Uint8Array(this.int32Array);
257
+ let string = __privateGet(this, _textDecoder).decode(uInt8Array).replaceAll(/\x00/g, "");
258
+ return JSON.parse(string);
259
+ }
196
260
  }
261
+ _textEncoder = new WeakMap();
262
+ _textDecoder = new WeakMap();
197
263
  class Form extends BaseSDK {
198
264
  constructor(instanceId) {
199
265
  super();
@@ -351,6 +417,28 @@ class Formatter extends BaseSDK {
351
417
  });
352
418
  }
353
419
  }
420
+ const isObject = (value) => value !== null && typeof value === "object";
421
+ class CreateProxy {
422
+ constructor(parent, target = {}, path = []) {
423
+ this.parent = parent;
424
+ this.path = path;
425
+ return new Proxy(target, this);
426
+ }
427
+ get(target, property) {
428
+ let value = this.parent.get(property, this.path);
429
+ if (isObject(value)) {
430
+ return new CreateProxy(this.parent, value, [...this.path, property]);
431
+ }
432
+ return value;
433
+ }
434
+ set(target, property, value, reciever) {
435
+ let updatedValue = this.parent.set(property, value, this.path);
436
+ if (isObject(updatedValue)) {
437
+ return new CreateProxy(this.parent, updatedValue, [...this.path, property]);
438
+ }
439
+ return updatedValue;
440
+ }
441
+ }
354
442
  class Component extends BaseSDK {
355
443
  constructor(props) {
356
444
  super();
@@ -449,6 +537,7 @@ class Page extends BaseSDK {
449
537
  this.type = "Page";
450
538
  this.popup = new Popup({});
451
539
  this._id = props.pageId;
540
+ this.variable = new PageVariable();
452
541
  }
453
542
  getParameter(key) {
454
543
  return this._postMessageAsync(LISTENER_CMDS.GET_PAGE_PARAMS, {
@@ -486,6 +575,27 @@ class Page extends BaseSDK {
486
575
  );
487
576
  }
488
577
  }
578
+ class PageVariable extends BaseSDK {
579
+ constructor() {
580
+ super();
581
+ return new CreateProxy(this);
582
+ }
583
+ get(key, path) {
584
+ let args = {
585
+ key,
586
+ path
587
+ };
588
+ return this._postMessageSync(LISTENER_CMDS.GET_PAGE_VARIABLE, args);
589
+ }
590
+ set(key, value, path) {
591
+ let args = {
592
+ key,
593
+ value,
594
+ path
595
+ };
596
+ return this._postMessageSync(LISTENER_CMDS.SET_PAGE_VARIABLE, args);
597
+ }
598
+ }
489
599
  class DecisionTable extends BaseSDK {
490
600
  constructor(flowId) {
491
601
  super();
@@ -515,6 +625,7 @@ class Application extends BaseSDK {
515
625
  super();
516
626
  this._id = props.appId;
517
627
  this.page = new Page(props);
628
+ this.variable = new AppVariable();
518
629
  }
519
630
  getVariable(key) {
520
631
  return this._postMessageAsync(LISTENER_CMDS.GET_APP_VARIABLE, {
@@ -540,6 +651,27 @@ class Application extends BaseSDK {
540
651
  return new Dataform(flowId);
541
652
  }
542
653
  }
654
+ class AppVariable extends BaseSDK {
655
+ constructor() {
656
+ super();
657
+ return new CreateProxy(this);
658
+ }
659
+ get(key, path) {
660
+ let args = {
661
+ key,
662
+ path
663
+ };
664
+ return this._postMessageSync(LISTENER_CMDS.GET_APP_VARIABLE, args);
665
+ }
666
+ set(key, value, path) {
667
+ let args = {
668
+ key,
669
+ value,
670
+ path
671
+ };
672
+ return this._postMessageSync(LISTENER_CMDS.SET_APP_VARIABLE, args);
673
+ }
674
+ }
543
675
  class NDEFReader extends BaseSDK {
544
676
  constructor() {
545
677
  super();
@@ -16,7 +16,7 @@ var __privateSet = (obj, member, value, setter) => {
16
16
  setter ? setter.call(obj, value) : member.set(obj, value);
17
17
  return value;
18
18
  };
19
- var _listeners, _csrfToken;
19
+ var _listeners, _textEncoder, _textDecoder, _csrfToken;
20
20
  let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
21
21
  byte &= 63;
22
22
  if (byte < 36) {
@@ -84,6 +84,16 @@ function generateId(prefix = "lcncsdk") {
84
84
  return `${prefix}-${nanoid()}`;
85
85
  }
86
86
  const globalInstances = {};
87
+ function processResponse(req, resp) {
88
+ if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
89
+ let value = Object.values(resp)[0];
90
+ if (value === "undefined")
91
+ return void 0;
92
+ return value;
93
+ } else {
94
+ return resp;
95
+ }
96
+ }
87
97
  function postMessage(args) {
88
98
  if (globalThis.parent && globalThis.parent !== globalThis) {
89
99
  globalThis.parent.postMessage(args, "*");
@@ -143,11 +153,8 @@ class EventBase {
143
153
  if (Array.isArray(__privateGet(this, _listeners)[target])) {
144
154
  __privateGet(this, _listeners)[target].forEach((listener) => {
145
155
  try {
146
- if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
147
- listener(Object.values(resp)[0]);
148
- } else {
149
- listener(resp);
150
- }
156
+ let processedResp = processResponse(req, resp);
157
+ listener(processedResp);
151
158
  } catch (err) {
152
159
  console.error("Message callback error: ", err);
153
160
  }
@@ -182,7 +189,66 @@ class BaseSDK extends EventBase {
182
189
  this._addEventListener(args.eventName, callBack);
183
190
  }
184
191
  }
192
+ _postMessageSync(command, args) {
193
+ let intialValue = 0;
194
+ const _id = generateId(command.toLowerCase());
195
+ let data = { _id, command, ...args };
196
+ let atomics = new AtomicsHandler();
197
+ atomics.reset();
198
+ atomics.store(0, intialValue);
199
+ atomics.encodeData(1, data);
200
+ postMessage(atomics.sab);
201
+ atomics.wait(0, intialValue, 1e4);
202
+ let decodedData = atomics.decodeData();
203
+ let { _req: req, resp } = decodedData;
204
+ let processedResp = processResponse(req, resp);
205
+ if (processedResp == null ? void 0 : processedResp.isError) {
206
+ throw new Error(`Error: ${JSON.stringify(processedResp, null, 2)}`);
207
+ }
208
+ return processedResp;
209
+ }
210
+ }
211
+ let sharedArrayBufferInstance;
212
+ class AtomicsHandler {
213
+ constructor() {
214
+ __privateAdd(this, _textEncoder, void 0);
215
+ __privateAdd(this, _textDecoder, void 0);
216
+ __privateSet(this, _textEncoder, new TextEncoder());
217
+ __privateSet(this, _textDecoder, new TextDecoder());
218
+ sharedArrayBufferInstance = sharedArrayBufferInstance || new SharedArrayBuffer(1024 * 1024);
219
+ this.sab = sharedArrayBufferInstance;
220
+ this.int32Array = new Int32Array(this.sab);
221
+ }
222
+ load(index = 0) {
223
+ return Atomics.load(this.int32Array, index);
224
+ }
225
+ store(index = 0, data) {
226
+ return Atomics.store(this.int32Array, index, data);
227
+ }
228
+ reset() {
229
+ return this.int32Array.fill(0);
230
+ }
231
+ notify(index = 0, count = 1) {
232
+ return Atomics.notify(this.int32Array, index, count);
233
+ }
234
+ wait(index, value, timeout) {
235
+ return Atomics.wait(this.int32Array, index, value, timeout);
236
+ }
237
+ encodeData(index = 0, data) {
238
+ const replacer = (key, value) => value === void 0 ? "undefined" : value;
239
+ let string = JSON.stringify(data, replacer);
240
+ let encodedData = __privateGet(this, _textEncoder).encode(string);
241
+ this.int32Array.set(encodedData, index);
242
+ return this.int32Array;
243
+ }
244
+ decodeData() {
245
+ let uInt8Array = new Uint8Array(this.int32Array);
246
+ let string = __privateGet(this, _textDecoder).decode(uInt8Array).replaceAll(/\x00/g, "");
247
+ return JSON.parse(string);
248
+ }
185
249
  }
250
+ _textEncoder = new WeakMap();
251
+ _textDecoder = new WeakMap();
186
252
  class Form extends BaseSDK {
187
253
  constructor(instanceId) {
188
254
  super();