@aravinthan_p/appnest-app-sdk-utils 0.0.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/appnestFunctions/appnestFunctions.MD +163 -0
- package/appnestFunctions/dbFunction/db.MD +161 -0
- package/appnestFunctions/dbFunction/db.js +624 -0
- package/appnestFunctions/fileFunction/file.MD +57 -0
- package/appnestFunctions/fileFunction/file.js +114 -0
- package/appnestFunctions/httpFunction/http.MD +147 -0
- package/appnestFunctions/httpFunction/http.js +118 -0
- package/appnestFunctions/index.js +26 -0
- package/appnestFunctions/nextFunction/next.MD +56 -0
- package/appnestFunctions/nextFunction/next.js +60 -0
- package/appnestFunctions/scheduleFunction/schedule.MD +140 -0
- package/appnestFunctions/scheduleFunction/schedule.js +212 -0
- package/appnestFunctions/utils/apiConstants.js +75 -0
- package/appnestFunctions/utils/axiosWrapper.js +80 -0
- package/appnestFunctions/utils/contextWrapper.js +12 -0
- package/appnestSDK.MD +0 -0
- package/appnestUtils/ResultData.js +3 -0
- package/index.js +7 -0
- package/package.json +10 -0
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
const { getParentLayerConfigObject, getTraceId } = require('../utils/contextWrapper');
|
|
2
|
+
const { makeSparrowAppAPICall } = require('../utils/axiosWrapper');
|
|
3
|
+
const { DB_API } = require('../utils/apiConstants');
|
|
4
|
+
|
|
5
|
+
const validateKey = ({ key }) => {
|
|
6
|
+
try {
|
|
7
|
+
if (typeof key !== 'string') {
|
|
8
|
+
throw new Error('Key must be a string');
|
|
9
|
+
}
|
|
10
|
+
if (key.length === 0) {
|
|
11
|
+
throw new Error('Key must be a non-empty string');
|
|
12
|
+
}
|
|
13
|
+
if (key.length > 1000) {
|
|
14
|
+
throw new Error('Key must be less than 1000 characters');
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error("$Db - validateKey - error:", JSON.stringify(error));
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const validateValue = ({ value, dataType }) => {
|
|
24
|
+
try {
|
|
25
|
+
if (dataType === 'STRING') {
|
|
26
|
+
if (typeof value !== 'string') {
|
|
27
|
+
throw new Error('Value must be a string');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (dataType === 'LIST') {
|
|
31
|
+
if (!Array.isArray(value)) {
|
|
32
|
+
throw new Error('Value must be an array');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (dataType === 'MAP') {
|
|
36
|
+
const isPlainObject = typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
37
|
+
if (!isPlainObject) {
|
|
38
|
+
throw new Error('Value must be an object');
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const jsonString = JSON.stringify(value);
|
|
42
|
+
const parsed = JSON.parse(jsonString);
|
|
43
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
44
|
+
throw new Error('Value must be a valid JSON object');
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error("$Db - validateValue - error:", JSON.stringify(error));
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (dataType === 'NUMBER') {
|
|
52
|
+
if (typeof value !== 'number') {
|
|
53
|
+
throw new Error('Value must be a number');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (dataType === 'BOOLEAN') {
|
|
57
|
+
if (typeof value !== 'boolean') {
|
|
58
|
+
throw new Error('Value must be a boolean');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error("$Db - validateValue - error:", JSON.stringify(error));
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const get = async ({ key }) => {
|
|
70
|
+
try {
|
|
71
|
+
validateKey({ key });
|
|
72
|
+
const apiPayload = {
|
|
73
|
+
key,
|
|
74
|
+
dataType: 'STRING',
|
|
75
|
+
operationType: 'get',
|
|
76
|
+
}
|
|
77
|
+
return await dbAPIWrapper({ apiPayload });
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error("$Db - get - error:", JSON.stringify(error));
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const create = async ({ key }) => {
|
|
86
|
+
try {
|
|
87
|
+
validateKey({ key });
|
|
88
|
+
validateValue({ value, dataType: 'STRING' });
|
|
89
|
+
const apiPayload = {
|
|
90
|
+
key,
|
|
91
|
+
dataType: 'STRING',
|
|
92
|
+
operationType: 'create',
|
|
93
|
+
}
|
|
94
|
+
return await dbAPIWrapper({ apiPayload });
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("$Db - create - error:", JSON.stringify(error));
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const update = async ({ key, value }) => {
|
|
102
|
+
try {
|
|
103
|
+
validateKey({ key });
|
|
104
|
+
validateValue({ value, dataType: 'STRING' });
|
|
105
|
+
const apiPayload = {
|
|
106
|
+
key,
|
|
107
|
+
dataType: 'STRING',
|
|
108
|
+
operationType: 'update',
|
|
109
|
+
}
|
|
110
|
+
return await dbAPIWrapper({ apiPayload });
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error("$Db - update - error:", JSON.stringify(error));
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const deleteOperation = async ({ key }) => {
|
|
118
|
+
try {
|
|
119
|
+
validateKey({ key });
|
|
120
|
+
const apiPayload = {
|
|
121
|
+
key,
|
|
122
|
+
dataType: 'STRING',
|
|
123
|
+
operationType: 'delete',
|
|
124
|
+
}
|
|
125
|
+
return await dbAPIWrapper({ apiPayload });
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error("$Db - deleteOperation - error:", JSON.stringify(error));
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const stringGet = async ({ key }) => {
|
|
134
|
+
try {
|
|
135
|
+
validateKey({ key });
|
|
136
|
+
const apiPayload = {
|
|
137
|
+
key,
|
|
138
|
+
dataType: 'STRING',
|
|
139
|
+
operationType: 'get',
|
|
140
|
+
}
|
|
141
|
+
return await dbAPIWrapper({ apiPayload });
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.error("$Db - stringGet - error:", JSON.stringify(error));
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const stringCreate = async ({ key, value }) => {
|
|
149
|
+
try {
|
|
150
|
+
validateKey({ key });
|
|
151
|
+
validateValue({ value, dataType: 'STRING' });
|
|
152
|
+
const apiPayload = {
|
|
153
|
+
key,
|
|
154
|
+
dataType: 'STRING',
|
|
155
|
+
operationType: 'set',
|
|
156
|
+
operationMeta: {
|
|
157
|
+
value,
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return await dbAPIWrapper({ apiPayload });
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error("$Db - stringSet - error:", JSON.stringify(error));
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const stringUpdate = async ({ key, value }) => {
|
|
168
|
+
try {
|
|
169
|
+
validateKey({ key });
|
|
170
|
+
validateValue({ value, dataType: 'STRING' });
|
|
171
|
+
const apiPayload = {
|
|
172
|
+
key,
|
|
173
|
+
dataType: 'STRING',
|
|
174
|
+
operationType: 'update',
|
|
175
|
+
}
|
|
176
|
+
return await dbAPIWrapper({ apiPayload });
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error("$Db - stringUpdate - error:", JSON.stringify(error));
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const stringDelete = async ({ key }) => {
|
|
184
|
+
try {
|
|
185
|
+
validateKey({ key });
|
|
186
|
+
const apiPayload = {
|
|
187
|
+
key,
|
|
188
|
+
dataType: 'STRING',
|
|
189
|
+
operationType: 'delete',
|
|
190
|
+
}
|
|
191
|
+
return await dbAPIWrapper({ apiPayload });
|
|
192
|
+
} catch (error) {
|
|
193
|
+
console.error("$Db - stringDelete - error:", JSON.stringify(error));
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const string = {
|
|
199
|
+
get: stringGet,
|
|
200
|
+
create: stringCreate,
|
|
201
|
+
update: stringUpdate,
|
|
202
|
+
delete: stringDelete,
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const numberGet = async ({ key }) => {
|
|
206
|
+
try {
|
|
207
|
+
validateKey({ key });
|
|
208
|
+
const apiPayload = {
|
|
209
|
+
key,
|
|
210
|
+
dataType: 'NUMBER',
|
|
211
|
+
operationType: 'get',
|
|
212
|
+
}
|
|
213
|
+
return await dbAPIWrapper({ apiPayload });
|
|
214
|
+
} catch (error) {
|
|
215
|
+
console.error("$Db - numberGet - error:", JSON.stringify(error));
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const numberCreate = async ({ key, value }) => {
|
|
221
|
+
try {
|
|
222
|
+
validateKey({ key });
|
|
223
|
+
validateValue({ value, dataType: 'NUMBER' });
|
|
224
|
+
const apiPayload = {
|
|
225
|
+
key,
|
|
226
|
+
dataType: 'NUMBER',
|
|
227
|
+
operationType: 'create',
|
|
228
|
+
}
|
|
229
|
+
return await dbAPIWrapper({ apiPayload });
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
console.error("$Db - numberCreate - error:", JSON.stringify(error));
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const numberUpdate = async ({ key, value }) => {
|
|
238
|
+
try {
|
|
239
|
+
validateKey({ key });
|
|
240
|
+
validateValue({ value, dataType: 'NUMBER' });
|
|
241
|
+
const apiPayload = {
|
|
242
|
+
key,
|
|
243
|
+
dataType: 'NUMBER',
|
|
244
|
+
operationType: 'update',
|
|
245
|
+
}
|
|
246
|
+
return await dbAPIWrapper({ apiPayload });
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
console.error("$Db - numberUpdate - error:", JSON.stringify(error));
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const numberDelete = async ({ key }) => {
|
|
255
|
+
try {
|
|
256
|
+
validateKey({ key });
|
|
257
|
+
const apiPayload = {
|
|
258
|
+
key,
|
|
259
|
+
dataType: 'NUMBER',
|
|
260
|
+
operationType: 'delete',
|
|
261
|
+
}
|
|
262
|
+
return await dbAPIWrapper({ apiPayload });
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
console.error("$Db - numberDelete - error:", JSON.stringify(error));
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const numberIncrement = async ({ key }) => {
|
|
271
|
+
try {
|
|
272
|
+
validateKey({ key });
|
|
273
|
+
const apiPayload = {
|
|
274
|
+
key,
|
|
275
|
+
dataType: 'NUMBER',
|
|
276
|
+
operationType: 'increment',
|
|
277
|
+
}
|
|
278
|
+
return await dbAPIWrapper({ apiPayload });
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
console.error("$Db - numberIncrement - error:", JSON.stringify(error));
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const numberDecrement = async ({ key }) => {
|
|
287
|
+
try {
|
|
288
|
+
validateKey({ key });
|
|
289
|
+
const apiPayload = {
|
|
290
|
+
key,
|
|
291
|
+
dataType: 'NUMBER',
|
|
292
|
+
operationType: 'decrement',
|
|
293
|
+
}
|
|
294
|
+
return await dbAPIWrapper({ apiPayload });
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
console.error("$Db - numberDecrement - error:", JSON.stringify(error));
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const number = {
|
|
303
|
+
get: numberGet,
|
|
304
|
+
create: numberCreate,
|
|
305
|
+
update: numberUpdate,
|
|
306
|
+
delete: numberDelete,
|
|
307
|
+
increment: numberIncrement,
|
|
308
|
+
decrement: numberDecrement,
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const listGet = async ({ key }) => {
|
|
312
|
+
try {
|
|
313
|
+
validateKey({ key });
|
|
314
|
+
const apiPayload = {
|
|
315
|
+
key,
|
|
316
|
+
dataType: 'LIST',
|
|
317
|
+
operationType: 'get',
|
|
318
|
+
}
|
|
319
|
+
return await dbAPIWrapper({ apiPayload });
|
|
320
|
+
} catch (error) {
|
|
321
|
+
console.error("$Db - listGet - error:", JSON.stringify(error));
|
|
322
|
+
throw error;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const listCreate = async ({ key, value }) => {
|
|
327
|
+
try {
|
|
328
|
+
validateKey({ key });
|
|
329
|
+
validateValue({ value, dataType: 'LIST' });
|
|
330
|
+
const apiPayload = {
|
|
331
|
+
key,
|
|
332
|
+
dataType: 'LIST',
|
|
333
|
+
operationType: 'create',
|
|
334
|
+
}
|
|
335
|
+
return await dbAPIWrapper({ apiPayload });
|
|
336
|
+
} catch (error) {
|
|
337
|
+
console.error("$Db - listCreate - error:", JSON.stringify(error));
|
|
338
|
+
throw error;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const listUpdate = async ({ key, value }) => {
|
|
343
|
+
try {
|
|
344
|
+
validateKey({ key });
|
|
345
|
+
validateValue({ value, dataType: 'LIST' });
|
|
346
|
+
const apiPayload = {
|
|
347
|
+
key,
|
|
348
|
+
dataType: 'LIST',
|
|
349
|
+
operationType: 'update',
|
|
350
|
+
}
|
|
351
|
+
return await dbAPIWrapper({ apiPayload });
|
|
352
|
+
} catch (error) {
|
|
353
|
+
console.error("$Db - listUpdate - error:", JSON.stringify(error));
|
|
354
|
+
throw error;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
const listAppend = async ({ key, value }) => {
|
|
360
|
+
try {
|
|
361
|
+
validateKey({ key });
|
|
362
|
+
validateValue({ value, dataType: 'LIST' });
|
|
363
|
+
const apiPayload = {
|
|
364
|
+
key,
|
|
365
|
+
dataType: 'LIST',
|
|
366
|
+
operationType: 'append',
|
|
367
|
+
}
|
|
368
|
+
return await dbAPIWrapper({ apiPayload });
|
|
369
|
+
} catch (error) {
|
|
370
|
+
console.error("$Db - listAppend - error:", JSON.stringify(error));
|
|
371
|
+
throw error;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const listPrepend = async ({ key, value }) => {
|
|
376
|
+
try {
|
|
377
|
+
validateKey({ key });
|
|
378
|
+
validateValue({ value, dataType: 'LIST' });
|
|
379
|
+
const apiPayload = {
|
|
380
|
+
key,
|
|
381
|
+
dataType: 'LIST',
|
|
382
|
+
operationType: 'prepend',
|
|
383
|
+
}
|
|
384
|
+
return await dbAPIWrapper({ apiPayload });
|
|
385
|
+
} catch (error) {
|
|
386
|
+
console.error("$Db - listPrepend - error:", JSON.stringify(error));
|
|
387
|
+
throw error;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const listUpdateItemAtIndex = async ({ key, value, index }) => {
|
|
392
|
+
try {
|
|
393
|
+
validateKey({ key });
|
|
394
|
+
validateValue({ value, dataType: 'LIST' });
|
|
395
|
+
const apiPayload = {
|
|
396
|
+
key,
|
|
397
|
+
dataType: 'LIST',
|
|
398
|
+
operationType: 'updateItemAtIndex',
|
|
399
|
+
}
|
|
400
|
+
return await dbAPIWrapper({ apiPayload });
|
|
401
|
+
} catch (error) {
|
|
402
|
+
console.error("$Db - listUpdateItemAtIndex - error:", JSON.stringify(error));
|
|
403
|
+
throw error;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const listRemoveItemAtIndex = async ({ key, index }) => {
|
|
408
|
+
try {
|
|
409
|
+
validateKey({ key });
|
|
410
|
+
const apiPayload = {
|
|
411
|
+
key,
|
|
412
|
+
dataType: 'LIST',
|
|
413
|
+
operationType: 'removeItemAtIndex',
|
|
414
|
+
}
|
|
415
|
+
return await dbAPIWrapper({ apiPayload });
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
console.error("$Db - listRemoveItemAtIndex - error:", JSON.stringify(error));
|
|
419
|
+
throw error;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const list = {
|
|
424
|
+
get: listGet,
|
|
425
|
+
create: listCreate,
|
|
426
|
+
update: listUpdate,
|
|
427
|
+
append: listAppend,
|
|
428
|
+
prepend: listPrepend,
|
|
429
|
+
updateItemAtIndex: listUpdateItemAtIndex,
|
|
430
|
+
removeItemAtIndex: listRemoveItemAtIndex,
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
const mapGet = async ({ key }) => {
|
|
435
|
+
try {
|
|
436
|
+
validateKey({ key });
|
|
437
|
+
const apiPayload = {
|
|
438
|
+
key,
|
|
439
|
+
dataType: 'MAP',
|
|
440
|
+
operationType: 'get',
|
|
441
|
+
}
|
|
442
|
+
return await dbAPIWrapper({ apiPayload });
|
|
443
|
+
} catch (error) {
|
|
444
|
+
console.error("$Db - mapGet - error:", JSON.stringify(error));
|
|
445
|
+
throw error;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const mapCreate = async ({ key, value }) => {
|
|
450
|
+
try {
|
|
451
|
+
validateKey({ key });
|
|
452
|
+
validateValue({ value, dataType: 'MAP' });
|
|
453
|
+
if (typeof value !== 'object') {
|
|
454
|
+
throw new Error('Value must be an object');
|
|
455
|
+
}
|
|
456
|
+
const apiPayload = {
|
|
457
|
+
key,
|
|
458
|
+
dataType: 'MAP',
|
|
459
|
+
operationType: 'create',
|
|
460
|
+
operationMeta: {
|
|
461
|
+
value,
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
console.log("$Db - mapCreate - apiPayload:", JSON.stringify(apiPayload));
|
|
465
|
+
return await dbAPIWrapper({ apiPayload });
|
|
466
|
+
} catch (error) {
|
|
467
|
+
console.error("$Db - mapCreate - error:", JSON.stringify(error));
|
|
468
|
+
throw error;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const mapUpdate = async ({ key, value }) => {
|
|
473
|
+
try {
|
|
474
|
+
validateKey({ key });
|
|
475
|
+
validateValue({ value, dataType: 'MAP' });
|
|
476
|
+
const apiPayload = {
|
|
477
|
+
key,
|
|
478
|
+
dataType: 'MAP',
|
|
479
|
+
operationType: 'update',
|
|
480
|
+
}
|
|
481
|
+
return await dbAPIWrapper({ apiPayload });
|
|
482
|
+
} catch (error) {
|
|
483
|
+
console.error("$Db - mapUpdate - error:", JSON.stringify(error));
|
|
484
|
+
throw error;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const mapDelete = async ({ key }) => {
|
|
489
|
+
try {
|
|
490
|
+
validateKey({ key });
|
|
491
|
+
const apiPayload = {
|
|
492
|
+
key,
|
|
493
|
+
dataType: 'MAP',
|
|
494
|
+
operationType: 'delete',
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
catch (error) {
|
|
498
|
+
console.error("$Db - mapDelete - error:", JSON.stringify(error));
|
|
499
|
+
throw error;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const map = {
|
|
504
|
+
get: mapGet,
|
|
505
|
+
create: mapCreate,
|
|
506
|
+
update: mapUpdate,
|
|
507
|
+
delete: mapDelete,
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
const booleanGet = async ({ key }) => {
|
|
512
|
+
try {
|
|
513
|
+
validateKey({ key });
|
|
514
|
+
validateValue({ value, dataType: 'BOOLEAN' });
|
|
515
|
+
const apiPayload = {
|
|
516
|
+
key,
|
|
517
|
+
dataType: 'BOOLEAN',
|
|
518
|
+
operationType: 'get',
|
|
519
|
+
}
|
|
520
|
+
return await dbAPIWrapper({ apiPayload });
|
|
521
|
+
} catch (error) {
|
|
522
|
+
console.error("$Db - booleanGet - error:", JSON.stringify(error));
|
|
523
|
+
throw error;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const booleanCreate = async ({ key, value }) => {
|
|
528
|
+
try {
|
|
529
|
+
validateKey({ key });
|
|
530
|
+
validateValue({ value, dataType: 'BOOLEAN' });
|
|
531
|
+
const apiPayload = {
|
|
532
|
+
key,
|
|
533
|
+
dataType: 'BOOLEAN',
|
|
534
|
+
operationType: 'create',
|
|
535
|
+
operationMeta: {
|
|
536
|
+
value,
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
console.log("$Db - booleanCreate - apiPayload:", JSON.stringify(apiPayload));
|
|
540
|
+
return await dbAPIWrapper({ apiPayload });
|
|
541
|
+
} catch (error) {
|
|
542
|
+
console.error("$Db - booleanCreate - error:", JSON.stringify(error));
|
|
543
|
+
throw error;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const booleanUpdate = async ({ key, value }) => {
|
|
548
|
+
try {
|
|
549
|
+
validateKey({ key });
|
|
550
|
+
validateValue({ value, dataType: 'BOOLEAN' });
|
|
551
|
+
const apiPayload = {
|
|
552
|
+
key,
|
|
553
|
+
dataType: 'BOOLEAN',
|
|
554
|
+
operationType: 'update',
|
|
555
|
+
}
|
|
556
|
+
return await dbAPIWrapper({ apiPayload });
|
|
557
|
+
} catch (error) {
|
|
558
|
+
console.error("$Db - booleanUpdate - error:", JSON.stringify(error));
|
|
559
|
+
throw error;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const booleanDelete = async ({ key }) => {
|
|
564
|
+
try {
|
|
565
|
+
validateKey({ key });
|
|
566
|
+
const apiPayload = {
|
|
567
|
+
key,
|
|
568
|
+
dataType: 'BOOLEAN',
|
|
569
|
+
operationType: 'delete',
|
|
570
|
+
}
|
|
571
|
+
return await dbAPIWrapper({ apiPayload });
|
|
572
|
+
}
|
|
573
|
+
catch (error) {
|
|
574
|
+
console.error("$Db - booleanDelete - error:", JSON.stringify(error));
|
|
575
|
+
throw error;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const boolean = {
|
|
580
|
+
get: booleanGet,
|
|
581
|
+
create: booleanCreate,
|
|
582
|
+
update: booleanUpdate,
|
|
583
|
+
delete: booleanDelete,
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
const dbAPIWrapper = async ({ apiPayload }) => {
|
|
588
|
+
try {
|
|
589
|
+
const parentLayerConfigObject = getParentLayerConfigObject();
|
|
590
|
+
const requestBody = {
|
|
591
|
+
userInstalledId: parentLayerConfigObject.userInstalledId,
|
|
592
|
+
...apiPayload
|
|
593
|
+
};
|
|
594
|
+
console.log("$Db - dbAPIWrapper - requestBody:", JSON.stringify(requestBody));
|
|
595
|
+
const response = await makeSparrowAppAPICall({
|
|
596
|
+
method: DB_API.COMMON.method,
|
|
597
|
+
endpoint: DB_API.COMMON.endpoint,
|
|
598
|
+
requestBody
|
|
599
|
+
});
|
|
600
|
+
console.log("$Db - dbAPIWrapper - response:", JSON.stringify(response));
|
|
601
|
+
return { data: response?.data, status: response?.status };
|
|
602
|
+
} catch (error) {
|
|
603
|
+
console.error("$Db - dbAPIWrapper - error:", JSON.stringify(error));
|
|
604
|
+
throw error;
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
const $db = {
|
|
611
|
+
get,
|
|
612
|
+
create,
|
|
613
|
+
update,
|
|
614
|
+
delete: deleteOperation,
|
|
615
|
+
string,
|
|
616
|
+
number,
|
|
617
|
+
list,
|
|
618
|
+
map,
|
|
619
|
+
boolean,
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
module.exports = {
|
|
623
|
+
$db
|
|
624
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# $file — File Storage SDK
|
|
2
|
+
|
|
3
|
+
The `$file` module provides file storage helpers: signed URLs for upload/download, delete, list, and existence check.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Import / Usage
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
const { $file } = require('<path-to-sdk>/appnestFunctions');
|
|
11
|
+
// or
|
|
12
|
+
const { $file } = require('appnest-app-sdk-utils');
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Common Parameters
|
|
18
|
+
|
|
19
|
+
| Parameter | Type | Required | Default | Description |
|
|
20
|
+
|------------|--------|----------|----------|--------------------|
|
|
21
|
+
| path | string | yes | — | File key/path |
|
|
22
|
+
| visibility | string | no | `PUBLIC` | `PUBLIC` or `PRIVATE` |
|
|
23
|
+
|
|
24
|
+
**Return shape:** `Promise<{ data, status }>` unless noted.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## API
|
|
29
|
+
|
|
30
|
+
| Method | Signature | Description |
|
|
31
|
+
|---------------|-----------|-------------|
|
|
32
|
+
| getUploadUrl | `$file.getUploadUrl({ path, visibility })` | Get a signed URL for uploading a file. |
|
|
33
|
+
| getDownloadUrl| `$file.getDownloadUrl({ path, visibility })` | Get a signed URL for reading/downloading a file. |
|
|
34
|
+
| delete | `$file.delete({ path, visibility })` | Delete a file at the given path. |
|
|
35
|
+
| list | `$file.list({ path, visibility })` | List objects under the given path. |
|
|
36
|
+
| exists | `$file.exists({ path, visibility })` | Check if a file exists at the path. |
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Examples
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
// Get upload URL (default PUBLIC)
|
|
44
|
+
const upload = await $file.getUploadUrl({ path: 'reports/2026-02-09.csv' });
|
|
45
|
+
|
|
46
|
+
// Get download URL (private)
|
|
47
|
+
const read = await $file.getDownloadUrl({ path: 'reports/2026-02-09.csv', visibility: 'PRIVATE' });
|
|
48
|
+
|
|
49
|
+
// Delete file
|
|
50
|
+
await $file.delete({ path: 'reports/old.csv' });
|
|
51
|
+
|
|
52
|
+
// List files under prefix
|
|
53
|
+
const listResult = await $file.list({ path: 'reports/' });
|
|
54
|
+
|
|
55
|
+
// Check existence
|
|
56
|
+
const existsResult = await $file.exists({ path: 'reports/2026-02-09.csv' });
|
|
57
|
+
```
|