@kissflow/lowcode-client-sdk 1.0.12-beta.1 → 1.0.13-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/README.md CHANGED
@@ -54,6 +54,9 @@ let resp = await kf.api(url, config)
54
54
  - [3. Application](#3-application)
55
55
  - [4. Page](#4-page)
56
56
  - [5. Component](#5-component)
57
+ - [Standard Component methods](#standard-component-methods)
58
+ - [Component Specific methods](#component-specific-methods)
59
+ - [Tab](#521-tab-component)
57
60
  - [6. Popup](#6-popup)
58
61
  - [7. Formatter](#7-formatter)
59
62
 
@@ -345,26 +348,40 @@ kf.app.page.openPopup("popupId", { inputParam1: "value" });
345
348
  ```
346
349
 
347
350
  ### 5) Component
348
-
351
+ #### getComponent(id)
352
+ Parameter: Component's Id
353
+ Returns: Component class instance
349
354
  ```js
350
355
  const component = await kf.app.page.getComponent(componentId);
351
356
  ```
352
- By using component instance we can invoke following methods.
353
-
354
- ##### Refresh a component
357
+ ##### Standard Component Methods
355
358
  ```js
356
- component.refresh();
359
+ component.refresh(); // Refreshes the component
360
+ component.hide(); // Hides the component
361
+ component.show(); // Shows the component if it's been hidden previously
357
362
  ```
363
+ ##### Component Specific Methods
358
364
 
359
- ##### Show a component
365
+
366
+ ##### 5.2.0) Component onMount
367
+ Component onMount takes in callBack function as argument.
368
+ > ##### Note: Any component specific methods that are used on Page load must be called inside component's onMount event.
369
+ Parameter: function
360
370
  ```js
361
- componentName.show();
371
+ component.onMount(() => {
372
+ // function logic goes here... For eg.
373
+ // component.setActiveTab(2)
374
+ })
362
375
  ```
363
-
364
- ##### Hide a component
376
+ ##### 5.2.1) Tab component
377
+ ##### 1) setActiveTab
378
+ Sets specified tab as active.
379
+ Parameter: Tabs' Number (Starts from 1 to N)
365
380
  ```js
366
- component.hide();
381
+ component.setActiveTab(2) // sets 2nd tab as active one
367
382
  ```
383
+
384
+
368
385
  ### 6) Popup
369
386
  `kf.app.page.popup` returns the active popup instance opened inside the page and its id can be accessed via `kf.app.page.popup._id`
370
387
  And `kf.app.page.getPopup(id)` returns this popup class instance.
@@ -376,7 +393,7 @@ let value = await kf.app.page.popup.getParameter("parameterId"); // for retreivi
376
393
  Get all popup parameters
377
394
  ```js
378
395
  let allParams = await kf.app.page.popup.getAllParameters();
379
- // returns an object
396
+ // Returns an object
380
397
  {
381
398
  parameterName: "Sample value",
382
399
  parameterName2: "Sample value 2"
@@ -441,4 +458,3 @@ let value = await kf.formatter.toBoolean("no");
441
458
  let value = await kf.formatter.toBoolean("0");
442
459
  let value = await kf.formatter.toBoolean("false");
443
460
  ```
444
-
@@ -0,0 +1,420 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __accessCheck = (obj, member, msg) => {
21
+ if (!member.has(obj))
22
+ throw TypeError("Cannot " + msg);
23
+ };
24
+ var __privateGet = (obj, member, getter) => {
25
+ __accessCheck(obj, member, "read from private field");
26
+ return getter ? getter.call(obj) : member.get(obj);
27
+ };
28
+ var __privateAdd = (obj, member, value) => {
29
+ if (member.has(obj))
30
+ throw TypeError("Cannot add the same private member more than once");
31
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
32
+ };
33
+ var __privateSet = (obj, member, value, setter) => {
34
+ __accessCheck(obj, member, "write to private field");
35
+ setter ? setter.call(obj, value) : member.set(obj, value);
36
+ return value;
37
+ };
38
+ var _listeners, _csrfToken;
39
+ let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
40
+ byte &= 63;
41
+ if (byte < 36) {
42
+ id += byte.toString(36);
43
+ } else if (byte < 62) {
44
+ id += (byte - 26).toString(36).toUpperCase();
45
+ } else if (byte > 62) {
46
+ id += "-";
47
+ } else {
48
+ id += "_";
49
+ }
50
+ return id;
51
+ }, "");
52
+ const LISTENER_CMDS = {
53
+ API: "API",
54
+ GET_CONTEXT: "GET_CONTEXT",
55
+ RETURN: "RETURN",
56
+ GET_FORM_FIELD: "GET_FORM_FIELD",
57
+ UPDATE_FORM: "UPDATE_FORM",
58
+ GET_TABLE: "GET_TABLE",
59
+ GET_TABLE_ROW: "GET_TABLE_ROW",
60
+ ADD_TABLE_ROW: "ADD_TABLE_ROW",
61
+ DELETE_TABLE_ROW: "DELETE_TABLE_ROW",
62
+ TO_JSON: "TO_JSON",
63
+ GET_TABLE_ROWS: "GET_TABLE_ROWS",
64
+ MESSAGE: "MESSAGE",
65
+ CONFIRM: "CONFIRM",
66
+ ALERT: "ALERT",
67
+ REDIRECT: "REDIRECT",
68
+ OPEN_PAGE: "OPEN_PAGE",
69
+ FORMAT_DATE: "FORMAT_DATE",
70
+ FORMAT_DATE_TIME: "FORMAT_DATE_TIME",
71
+ FORMAT_NUMBER: "FORMAT_NUMBER",
72
+ FORMAT_CURRENCY: "FORMAT_CURRENCY",
73
+ FORMAT_BOOLEAN: "FORMAT_BOOLEAN",
74
+ GET_APP_VARIABLE: "GET_APP_VARIABLE",
75
+ SET_APP_VARIABLE: "SET_APP_VARIABLE",
76
+ GET_PAGE_VARIABLE: "GET_PAGE_VARIABLE",
77
+ SET_PAGE_VARIABLE: "SET_PAGE_VARIABLE",
78
+ GET_PAGE_PARAMS: "GET_PAGE_PARAMS",
79
+ GET_ALL_PAGE_PARAMS: "GET_ALL_PAGE_PARAMS",
80
+ PAGE_ON_CLOSE: "PAGE_ON_CLOSE",
81
+ OPEN_POPUP: "OPEN_POPUP",
82
+ GET_POPUP_PARAMS: "GET_POPUP_PARAMS",
83
+ GET_ALL_POPUP_PARAMS: "GET_ALL_POPUP_PARAMS",
84
+ CLOSE_POPUP: "CLOSE_POPUP",
85
+ COMPONENT_GET: "COMPONENT_GET",
86
+ COMPONENT_REFRESH: "COMPONENT_REFRESH",
87
+ COMPONENT_SHOW: "COMPONENT_SHOW",
88
+ COMPONENT_HIDE: "COMPONENT_HIDE",
89
+ COMPONENT_ADD_EVENT_LISTENER: "COMPONENT_ADD_EVENT_LISTENER",
90
+ CC_INITIALIZE: "CC_INITIALIZE",
91
+ CC_WATCH_PARAMS: "CC_WATCH_PARAMS",
92
+ WINDOW_NDEF_READER_NEW: "WINDOW_NDEF_READER_NEW",
93
+ WINDOW_NDEF_READER_SCAN: "WINDOW_NDEF_READER_SCAN",
94
+ WINDOW_NDEF_READER_WRITE: "WINDOW_NDEF_READER_WRITE",
95
+ WINDOW_NDEF_READER_ADD_EVENT_LISTENER: "WINDOW_NDEF_READER_ADD_EVENT_LISTENER",
96
+ WINDOW_NDEF_READER_MAKE_READONLY: "WINDOW_NDEF_READER_MAKE_READONLY",
97
+ WINDOW_NDEF_READER_ABORT_SCAN: "WINDOW_NDEF_READER_ABORT_SCAN"
98
+ };
99
+ function generateId(prefix = "lcncsdk") {
100
+ return `${prefix}-${nanoid()}`;
101
+ }
102
+ const globalInstances = {};
103
+ function postMessage(args) {
104
+ if (globalThis.parent && globalThis.parent !== globalThis) {
105
+ globalThis.parent.postMessage(args, "*");
106
+ } else {
107
+ globalThis.postMessage(args);
108
+ }
109
+ }
110
+ function onMessage(event) {
111
+ if (event.origin !== globalThis.location.origin) {
112
+ const data = event.data;
113
+ if (data == null ? void 0 : data.isEvent) {
114
+ const { target, eventParams, eventName, eventConfig = {} } = data;
115
+ let targetInstance = globalInstances[target];
116
+ targetInstance._dispatchEvent(eventName, eventParams);
117
+ if (eventConfig.once) {
118
+ targetInstance._removeEventListener(eventName);
119
+ }
120
+ return;
121
+ }
122
+ let { _req: req, resp } = data;
123
+ if (req == null ? void 0 : req._id) {
124
+ let targetInstance = globalInstances[req._id];
125
+ targetInstance._dispatchMessageEvents(req, resp);
126
+ }
127
+ }
128
+ }
129
+ globalThis.addEventListener("message", onMessage);
130
+ class EventBase {
131
+ constructor() {
132
+ __privateAdd(this, _listeners, void 0);
133
+ __privateSet(this, _listeners, {});
134
+ }
135
+ _addEventListener(eventName, callBack) {
136
+ var _a;
137
+ __privateGet(this, _listeners)[eventName] = ((_a = __privateGet(this, _listeners)) == null ? void 0 : _a[eventName]) || [];
138
+ __privateGet(this, _listeners)[eventName].push(callBack);
139
+ }
140
+ _removeEventListener(eventName, callBack) {
141
+ if (callBack) {
142
+ let index = __privateGet(this, _listeners)[eventName].findIndex(callBack);
143
+ index > -1 && __privateGet(this, _listeners)[eventName].splice(index, 1);
144
+ return;
145
+ }
146
+ Reflect.deleteProperty(__privateGet(this, _listeners), eventName);
147
+ }
148
+ _dispatchEvent(eventName, eventParams) {
149
+ if (Array.isArray(__privateGet(this, _listeners)[eventName])) {
150
+ __privateGet(this, _listeners)[eventName].forEach((callBack) => callBack(eventParams));
151
+ return true;
152
+ }
153
+ return false;
154
+ }
155
+ _dispatchMessageEvents(req, resp) {
156
+ let target = req._id;
157
+ if (Array.isArray(__privateGet(this, _listeners)[target])) {
158
+ __privateGet(this, _listeners)[target].forEach((listener) => {
159
+ try {
160
+ if (resp && Object.keys(resp).length === 1 && req.command !== LISTENER_CMDS.API) {
161
+ listener(Object.values(resp)[0]);
162
+ } else {
163
+ listener(resp);
164
+ }
165
+ } catch (err) {
166
+ console.error("Message callback error: ", err);
167
+ }
168
+ });
169
+ this._removeEventListener(target);
170
+ }
171
+ }
172
+ }
173
+ _listeners = new WeakMap();
174
+ class BaseSDK extends EventBase {
175
+ _postMessageAsync(command, args, hasCallBack, callBack) {
176
+ return new Promise((resolve, reject) => {
177
+ const _id = generateId(command.toLowerCase());
178
+ postMessage(__spreadValues({ _id, command }, args));
179
+ globalInstances[_id] = this;
180
+ this._addEventListener(_id, async (data) => {
181
+ if (data == null ? void 0 : data.errorMessage) {
182
+ reject(data);
183
+ } else {
184
+ if (hasCallBack && callBack) {
185
+ data = await callBack(data);
186
+ }
187
+ resolve(data);
188
+ }
189
+ });
190
+ });
191
+ }
192
+ _postMessage(command, args, callBack) {
193
+ const _id = generateId(command.toLowerCase());
194
+ postMessage(__spreadValues({ _id, command }, args));
195
+ if (callBack) {
196
+ this._addEventListener(args.eventName, callBack);
197
+ }
198
+ }
199
+ }
200
+ class Form extends BaseSDK {
201
+ constructor(instanceId) {
202
+ super();
203
+ this.type = "Form";
204
+ this.instanceId = instanceId;
205
+ }
206
+ toJSON() {
207
+ return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
208
+ instanceId: this.instanceId
209
+ });
210
+ }
211
+ getField(fieldId) {
212
+ return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
213
+ instanceId: this.instanceId,
214
+ fieldId
215
+ });
216
+ }
217
+ updateField(args) {
218
+ return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
219
+ data: args
220
+ });
221
+ }
222
+ getTable(tableId) {
223
+ return new Table(this.instanceId, tableId);
224
+ }
225
+ }
226
+ class Table extends BaseSDK {
227
+ constructor(instanceId, tableId) {
228
+ super();
229
+ this.tableId = tableId;
230
+ this.instanceId = instanceId;
231
+ }
232
+ toJSON() {
233
+ return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
234
+ tableId: this.tableId
235
+ });
236
+ }
237
+ getRows() {
238
+ return this._postMessageAsync(LISTENER_CMDS.GET_TABLE_ROWS, { tableId: this.tableId }, true, (data) => {
239
+ return data.map((row) => new TableForm(this.instanceId, this.tableId, row.id));
240
+ });
241
+ }
242
+ getRow(rowId) {
243
+ return new TableForm(this.instanceId, this.tableId, rowId);
244
+ }
245
+ addRow(rowObject) {
246
+ return this._postMessageAsync(LISTENER_CMDS.ADD_TABLE_ROW, {
247
+ tableId: this.tableId,
248
+ rowObject
249
+ });
250
+ }
251
+ deleteRow(rowId) {
252
+ return this._postMessageAsync(LISTENER_CMDS.DELETE_TABLE_ROW, {
253
+ tableId: this.tableId,
254
+ rowId
255
+ });
256
+ }
257
+ }
258
+ class TableForm extends BaseSDK {
259
+ constructor(instanceId, tableId, rowId) {
260
+ super();
261
+ this.instanceId = instanceId;
262
+ this.type = "TabelForm";
263
+ this.tableId = tableId;
264
+ this.rowId = rowId;
265
+ }
266
+ getParent() {
267
+ return new Form(this.instanceId);
268
+ }
269
+ toJSON() {
270
+ return this._postMessageAsync(LISTENER_CMDS.TO_JSON, {
271
+ tableId: this.tableId,
272
+ rowId: this.rowId
273
+ });
274
+ }
275
+ getField(fieldId) {
276
+ return this._postMessageAsync(LISTENER_CMDS.GET_FORM_FIELD, {
277
+ instanceId: this.instanceId,
278
+ tableId: this.tableId,
279
+ rowId: this.rowId,
280
+ fieldId
281
+ });
282
+ }
283
+ updateField(args) {
284
+ return this._postMessageAsync(LISTENER_CMDS.UPDATE_FORM, {
285
+ instanceId: this.instanceId,
286
+ tableId: this.tableId,
287
+ rowId: this.rowId,
288
+ data: args
289
+ });
290
+ }
291
+ }
292
+ class Client extends BaseSDK {
293
+ showInfo(message) {
294
+ return super._postMessageAsync(LISTENER_CMDS.MESSAGE, { message });
295
+ }
296
+ showConfirm(args) {
297
+ return super._postMessageAsync(LISTENER_CMDS.CONFIRM, {
298
+ data: {
299
+ title: args.title,
300
+ content: args.content,
301
+ okText: args.okText || "Ok",
302
+ cancelText: args.cancelText || "Cancel"
303
+ }
304
+ });
305
+ }
306
+ redirect(url) {
307
+ return super._postMessageAsync(LISTENER_CMDS.REDIRECT, { url });
308
+ }
309
+ }
310
+ class Formatter extends BaseSDK {
311
+ toDate(date) {
312
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE, {
313
+ date
314
+ });
315
+ }
316
+ toDateTime(date) {
317
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_DATE_TIME, {
318
+ date
319
+ });
320
+ }
321
+ toNumber(value) {
322
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_NUMBER, {
323
+ value
324
+ });
325
+ }
326
+ toCurrency(value, currencyCode) {
327
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_CURRENCY, {
328
+ value,
329
+ currencyCode
330
+ });
331
+ }
332
+ toBoolean(value) {
333
+ return this._postMessageAsync(LISTENER_CMDS.FORMAT_BOOLEAN, {
334
+ value
335
+ });
336
+ }
337
+ }
338
+ class NDEFReader extends BaseSDK {
339
+ constructor() {
340
+ super();
341
+ this.id = generateId(LISTENER_CMDS.WINDOW_NDEF_READER_NEW);
342
+ globalInstances[this.id] = this;
343
+ this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_NEW, {
344
+ id: this.id,
345
+ operation: "new"
346
+ }, (data) => {
347
+ });
348
+ }
349
+ scan() {
350
+ return new Promise((resolve, reject) => {
351
+ this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_SCAN, { id: this.id, operation: "scan" }, ({ data, err }) => {
352
+ console.log("scan data from main window ", data);
353
+ resolve(data);
354
+ });
355
+ });
356
+ }
357
+ write(data) {
358
+ return new Promise((resolve, reject) => {
359
+ this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_WRITE, { id: this.id, operation: "write", data }, ({ data: data2, err }) => {
360
+ });
361
+ });
362
+ }
363
+ addEventListener(eventName, cb) {
364
+ this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_ADD_EVENT_LISTENER, {
365
+ id: this.id,
366
+ operation: "addEventListener",
367
+ eventName
368
+ }, () => {
369
+ });
370
+ }
371
+ makeReadOnly() {
372
+ return new Promise((resolve, reject) => {
373
+ this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_MAKE_READONLY, { id: this.id, operation: "makeReadOnly" }, ({ data, err }) => {
374
+ });
375
+ });
376
+ }
377
+ abortScan() {
378
+ return new Promise((resolve, reject) => {
379
+ this._postMessage(LISTENER_CMDS.WINDOW_NDEF_READER_ABORT_SCAN, { id: this.id, operation: "abortScan" }, ({ data, err }) => {
380
+ });
381
+ });
382
+ }
383
+ }
384
+ const window = {
385
+ NDEFReader
386
+ };
387
+ class NocodeSDK extends BaseSDK {
388
+ constructor(props) {
389
+ super();
390
+ __privateAdd(this, _csrfToken, void 0);
391
+ if (props.tableId && props.tableRowId) {
392
+ this.context = new TableForm(props.formInstanceId, props.tableId, props.tableRowId);
393
+ } else if (props.formInstanceId) {
394
+ this.context = new Form(props.formInstanceId);
395
+ }
396
+ this.client = new Client();
397
+ this.formatter = new Formatter();
398
+ this.user = props.user;
399
+ this.account = props.account;
400
+ __privateSet(this, _csrfToken, props.csrfToken);
401
+ }
402
+ async api(url, args) {
403
+ const response = await globalThis.fetch(url, __spreadProps(__spreadValues({}, args), {
404
+ headers: __spreadProps(__spreadValues({}, (args == null ? void 0 : args.headers) || {}), {
405
+ "X-Csrf-Token": __privateGet(this, _csrfToken)
406
+ })
407
+ }));
408
+ const contentType = response.headers.get("content-type");
409
+ if (contentType && contentType.includes("application/json")) {
410
+ return await response.json();
411
+ } else {
412
+ return response;
413
+ }
414
+ }
415
+ }
416
+ _csrfToken = new WeakMap();
417
+ function initSDK(config) {
418
+ return new NocodeSDK(config);
419
+ }
420
+ export { initSDK as default, window };
File without changes
@@ -0,0 +1,292 @@
1
+ declare module "core/constants" {
2
+ export const LISTENER_CMDS: {
3
+ API: string;
4
+ GET_CONTEXT: string;
5
+ RETURN: string;
6
+ GET_FORM_FIELD: string;
7
+ UPDATE_FORM: string;
8
+ GET_TABLE: string;
9
+ GET_TABLE_ROW: string;
10
+ ADD_TABLE_ROW: string;
11
+ DELETE_TABLE_ROW: string;
12
+ TO_JSON: string;
13
+ GET_TABLE_ROWS: string;
14
+ MESSAGE: string;
15
+ CONFIRM: string;
16
+ ALERT: string;
17
+ REDIRECT: string;
18
+ OPEN_PAGE: string;
19
+ FORMAT_DATE: string;
20
+ FORMAT_DATE_TIME: string;
21
+ FORMAT_NUMBER: string;
22
+ FORMAT_CURRENCY: string;
23
+ FORMAT_BOOLEAN: string;
24
+ GET_APP_VARIABLE: string;
25
+ SET_APP_VARIABLE: string;
26
+ GET_PAGE_VARIABLE: string;
27
+ SET_PAGE_VARIABLE: string;
28
+ GET_PAGE_PARAMS: string;
29
+ GET_ALL_PAGE_PARAMS: string;
30
+ PAGE_ON_CLOSE: string;
31
+ OPEN_POPUP: string;
32
+ GET_POPUP_PARAMS: string;
33
+ GET_ALL_POPUP_PARAMS: string;
34
+ CLOSE_POPUP: string;
35
+ COMPONENT_GET: string;
36
+ COMPONENT_REFRESH: string;
37
+ COMPONENT_SHOW: string;
38
+ COMPONENT_HIDE: string;
39
+ COMPONENT_ADD_EVENT_LISTENER: string;
40
+ CC_INITIALIZE: string;
41
+ CC_WATCH_PARAMS: 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
+ CC_ON_PARAMS_CHANGE: string;
52
+ };
53
+ export const DEFAULTS: {
54
+ POPUP_ID: string;
55
+ };
56
+ }
57
+ declare module "core/index" {
58
+ export function generateId(prefix?: string): string;
59
+ export const globalInstances: {};
60
+ export class EventBase {
61
+ #private;
62
+ constructor();
63
+ _addEventListener(eventName: string, callBack: Function): void;
64
+ _removeEventListener(eventName: string, callBack?: any): void;
65
+ _dispatchEvent(eventName: string, eventParams: object): boolean;
66
+ _dispatchMessageEvents(req: any, resp: any): void;
67
+ }
68
+ export class BaseSDK extends EventBase {
69
+ _postMessageAsync(command: string, args: any, hasCallBack?: boolean, callBack?: (data: any) => {}): object | string | any;
70
+ _postMessage(command: string, args: any, callBack?: any): void;
71
+ }
72
+ export * from "core/constants";
73
+ }
74
+ declare module "form/index" {
75
+ import { BaseSDK } from "core/index";
76
+ export class Form extends BaseSDK {
77
+ private instanceId;
78
+ type: string;
79
+ constructor(instanceId: string);
80
+ toJSON(): any;
81
+ getField(fieldId: string): any;
82
+ updateField(args: object): any;
83
+ getTable(tableId: string): Table;
84
+ }
85
+ class Table extends BaseSDK {
86
+ private tableId;
87
+ private instanceId;
88
+ constructor(instanceId: string, tableId: string);
89
+ toJSON(): any;
90
+ getRows(): TableForm[];
91
+ getRow(rowId: string): TableForm;
92
+ addRow(rowObject: object): any;
93
+ deleteRow(rowId: string): any;
94
+ }
95
+ export class TableForm extends BaseSDK {
96
+ private instanceId;
97
+ private tableId;
98
+ private rowId;
99
+ type: string;
100
+ constructor(instanceId: string, tableId: string, rowId: string);
101
+ getParent(): Form;
102
+ toJSON(): any;
103
+ getField(fieldId: string): any;
104
+ updateField(args: object): any;
105
+ }
106
+ }
107
+ declare module "utils/client" {
108
+ import { BaseSDK } from "core/index";
109
+ export class Client extends BaseSDK {
110
+ showInfo(message: string): any;
111
+ showConfirm(args: {
112
+ title: string;
113
+ content: string;
114
+ okText: string;
115
+ cancelText: string;
116
+ }): any;
117
+ redirect(url: string): any;
118
+ }
119
+ }
120
+ declare module "utils/formatter" {
121
+ import { BaseSDK } from "core/index";
122
+ export class Formatter extends BaseSDK {
123
+ toDate(date: string): any;
124
+ toDateTime(date: string): any;
125
+ toNumber(value: string): any;
126
+ toCurrency(value: string, currencyCode: string): any;
127
+ toBoolean(value: string): any;
128
+ }
129
+ }
130
+ declare module "utils/index" {
131
+ export * from "utils/client";
132
+ export * from "utils/formatter";
133
+ }
134
+ declare module "window/NDEFReader" {
135
+ import { BaseSDK } from "core/index";
136
+ export class NDEFReader extends BaseSDK {
137
+ id: string;
138
+ constructor();
139
+ scan(): Promise<unknown>;
140
+ write(data: any): Promise<unknown>;
141
+ addEventListener(eventName: string, cb: Function): void;
142
+ makeReadOnly(): Promise<unknown>;
143
+ abortScan(): Promise<unknown>;
144
+ }
145
+ }
146
+ declare module "window/index" {
147
+ import { NDEFReader } from "window/NDEFReader";
148
+ export const window: {
149
+ NDEFReader: typeof NDEFReader;
150
+ };
151
+ }
152
+ declare module "types/external" {
153
+ export type userObject = {
154
+ _id: string;
155
+ Name: string;
156
+ Email: string;
157
+ UserType: string;
158
+ Role: string;
159
+ };
160
+ export type accountObject = {
161
+ _id: string;
162
+ };
163
+ export type environmentObject = {
164
+ isMobile: boolean;
165
+ };
166
+ }
167
+ declare module "types/internal" {
168
+ import { userObject, accountObject, environmentObject } from "types/external";
169
+ export interface SDKContext {
170
+ formInstanceId: string;
171
+ tableId: string;
172
+ tableRowId: string;
173
+ componentId: string;
174
+ componentMethods?: componentMethodsType[];
175
+ appId: string;
176
+ pageId: string;
177
+ popupId: string;
178
+ user: userObject;
179
+ account: accountObject;
180
+ csrfToken: string;
181
+ envDetails: environmentObject;
182
+ }
183
+ export interface componentMethodsType {
184
+ name: string;
185
+ returnType?: string;
186
+ parameters?: string[];
187
+ }
188
+ export interface ComponentProps {
189
+ componentId: string;
190
+ componentMethods?: componentMethodsType[];
191
+ }
192
+ export interface AppContext {
193
+ appId: string;
194
+ pageId: string;
195
+ }
196
+ export interface PageContext {
197
+ pageId: string;
198
+ }
199
+ export interface PopupContext {
200
+ popupId?: string;
201
+ }
202
+ }
203
+ declare module "nocode" {
204
+ import { BaseSDK } from "core/index";
205
+ import { Form, TableForm } from "form/index";
206
+ import { Client, Formatter } from "utils/index";
207
+ import { window } from "window/index";
208
+ import { SDKContext } from "types/internal";
209
+ import { userObject, accountObject } from "types/external";
210
+ class NocodeSDK extends BaseSDK {
211
+ #private;
212
+ context: Form | TableForm;
213
+ client: Client;
214
+ formatter: Formatter;
215
+ user: userObject;
216
+ account: accountObject;
217
+ constructor(props: SDKContext);
218
+ api(url: string, args?: {
219
+ headers: object;
220
+ }): Promise<any>;
221
+ }
222
+ function initSDK(config: SDKContext): NocodeSDK;
223
+ export { window, initSDK as default };
224
+ }
225
+ declare module "app/component" {
226
+ import { BaseSDK } from "core/index";
227
+ import { ComponentProps } from "types/internal";
228
+ export class Component extends BaseSDK {
229
+ #private;
230
+ _id: string;
231
+ type: string;
232
+ constructor(props: ComponentProps);
233
+ onMount(callback: Function): void;
234
+ refresh(): any;
235
+ show(): any;
236
+ hide(): any;
237
+ }
238
+ export class CustomComponent extends BaseSDK {
239
+ type: string;
240
+ _id: string;
241
+ constructor(id: any);
242
+ watchParams(callBack: (data: any) => any): void;
243
+ }
244
+ }
245
+ declare module "app/popup" {
246
+ import { BaseSDK } from "core/index";
247
+ import { Component } from "app/component";
248
+ import { PopupContext } from "types/internal";
249
+ export class Popup extends BaseSDK {
250
+ _id: string;
251
+ type: string;
252
+ constructor(props: PopupContext);
253
+ getParameter(key: string): any;
254
+ getAllParameters(): any;
255
+ close(): any;
256
+ getComponent(componentId: string): Component;
257
+ }
258
+ }
259
+ declare module "app/page" {
260
+ import { BaseSDK } from "core/index";
261
+ import { Component } from "app/component";
262
+ import { Popup } from "app/popup";
263
+ import { PageContext } from "types/internal";
264
+ export class Page extends BaseSDK {
265
+ _id: string;
266
+ popup: Popup;
267
+ type: string;
268
+ constructor(props: PageContext);
269
+ getParameter(key: string): any;
270
+ getAllParameters(): any;
271
+ getVariable(key: string): any;
272
+ setVariable(key: string, value: any): any;
273
+ openPopup(popupId: string, popupParams: object): any;
274
+ getComponent(componentId: string): Component;
275
+ }
276
+ }
277
+ declare module "app/index" {
278
+ import { BaseSDK } from "core/index";
279
+ import { Page } from "app/page";
280
+ import { AppContext } from "types/internal";
281
+ export class Application extends BaseSDK {
282
+ page: Page;
283
+ _id: string;
284
+ constructor(props: AppContext);
285
+ getVariable(key: string): any;
286
+ setVariable(key: string | object, value?: any): any;
287
+ openPage(pageId: string, pageParams: object): any;
288
+ }
289
+ export * from "app/component";
290
+ export { Page };
291
+ export * from "app/popup";
292
+ }
@@ -0,0 +1,64 @@
1
+
2
+ declare class Form {
3
+ type: string
4
+ toJSON(): any;
5
+ getField(fieldId: string): any;
6
+ updateField(args: object): any;
7
+ getTable(tableId: string): Table;
8
+ }
9
+ declare class Table {
10
+ toJSON(): any;
11
+ getRows(): TableForm[];
12
+ getRow(rowId: string): TableForm;
13
+ addRow(rowObject: object): any;
14
+ deleteRow(rowId: string): any;
15
+ }
16
+ declare class TableForm {
17
+ type: string
18
+ getParent(): Form;
19
+ toJSON(): any;
20
+ getField(fieldId: string): any;
21
+ updateField(args: object): any;
22
+ }
23
+ declare class Client {
24
+ showInfo(message: string): any;
25
+ showConfirm(args: {
26
+ title: string;
27
+ content: string;
28
+ okText: string;
29
+ cancelText: string;
30
+ }): any;
31
+ redirect(url: string): any;
32
+ }
33
+ declare class Formatter {
34
+ toDate(date: string): any;
35
+ toDateTime(date: string): any;
36
+ toNumber(value: string): any;
37
+ toCurrency(value: string, currencyCode: string): any;
38
+ toBoolean(value: string): any;
39
+ }
40
+ declare class kf {
41
+ static context: Form
42
+ static client: Client
43
+ static formatter: Formatter
44
+ static user: userObject
45
+ static account: accountObject
46
+ api(url: string, args?: {
47
+ headers: object;
48
+ }): Promise<any>;
49
+ }
50
+ declare type userObject = {
51
+ _id: string;
52
+ Name: string;
53
+ Email: string;
54
+ UserType: string;
55
+ Role: string;
56
+ };
57
+
58
+ declare type accountObject = {
59
+ _id: string;
60
+ };
61
+
62
+ declare type environmentObject = {
63
+ isMobile: boolean
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kissflow/lowcode-client-sdk",
3
- "version": "1.0.12-beta.1",
3
+ "version": "1.0.13-beta",
4
4
  "description": "JavaScript SDK for developing over the Kissflow lowcode platform",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -14,7 +14,7 @@
14
14
  "require": "./dist/kfsdk.umd.js"
15
15
  },
16
16
  "./lowcode": {
17
- "import": "./dist/kfworkersdk.es.js"
17
+ "import": "./dist/kf.lowcodeworkersdk.es.js"
18
18
  }
19
19
  },
20
20
  "repository": {
@@ -29,20 +29,12 @@
29
29
  },
30
30
  "homepage": "https://github.com/kissflow/lcnc-sdk-js#readme",
31
31
  "devDependencies": {
32
- "html-webpack-plugin": "^5.3.1",
33
- "http-server": "^0.12.3",
34
- "ts-loader": "^9.2.5",
32
+ "ts-file-parser": "0.0.21",
35
33
  "typescript": "^4.3.5",
36
- "vite": "^2.9.8",
37
- "webpack": "^5.52.1",
38
- "webpack-cli": "^4.8.0",
39
- "webpack-dev-server": "^3.11.2"
34
+ "vite": "^2.9.8"
40
35
  },
41
36
  "dependencies": {
42
- "@lingui/cli": "^3.13.3",
43
- "@lingui/react": "^2",
44
- "nanoid": "^3.1.30",
45
- "ts-file-parser": "0.0.21"
37
+ "nanoid": "^3.1.30"
46
38
  },
47
39
  "scripts": {
48
40
  "start": "vite serve",