@aemforms/af-core 0.22.161 → 0.22.163

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.
@@ -2539,25 +2539,26 @@ class Container extends Scriptable {
2539
2539
  super.dispatch(action);
2540
2540
  }
2541
2541
  importData(dataModel) {
2542
- if (typeof this._data !== 'undefined' && this.type === 'array' && Array.isArray(dataModel)) {
2543
- const dataGroup = new DataGroup(this._data.$name, dataModel, this._data.$type, this._data.parent);
2544
- try {
2545
- this._data.parent?.$addDataNode(dataGroup.$name, dataGroup, true);
2546
- }
2547
- catch (e) {
2548
- this.form.logger.error(`unable to setItems for ${this.qualifiedName} : ${e}`);
2549
- return;
2550
- }
2551
- this._data = dataGroup;
2552
- this.syncDataAndFormModel(dataGroup);
2553
- const newLength = this.items.length;
2554
- for (let i = 0; i < newLength; i += 1) {
2555
- this._children[i].dispatch(new ExecuteRule());
2556
- }
2557
- }
2558
- else if (typeof this._data === 'undefined') {
2542
+ if (typeof this._data === 'undefined') {
2559
2543
  console.warn(`Data node is null, hence importData did not work for panel "${this.name}". Check if parent has a dataRef set to null.`);
2544
+ return;
2545
+ }
2546
+ const isArrayPanel = this.type === 'array' && Array.isArray(dataModel);
2547
+ const isObjectPanel = this.type === 'object' && typeof dataModel === 'object' && dataModel !== null && !Array.isArray(dataModel);
2548
+ if (!isArrayPanel && !isObjectPanel) {
2549
+ return;
2550
+ }
2551
+ const dataGroup = new DataGroup(this._data.$name, dataModel, this._data.$type, this._data.parent);
2552
+ try {
2553
+ this._data.parent?.$addDataNode(dataGroup.$name, dataGroup, true);
2560
2554
  }
2555
+ catch (e) {
2556
+ this.form.logger.error(`unable to importData for ${this.qualifiedName} : ${e}`);
2557
+ return;
2558
+ }
2559
+ this._data = dataGroup;
2560
+ this.syncDataAndFormModel(dataGroup);
2561
+ this._children.forEach((child) => child.dispatch(new ExecuteRule()));
2561
2562
  }
2562
2563
  syncDataAndFormModel(contextualDataModel) {
2563
2564
  const result = {
@@ -2935,6 +2936,9 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
2935
2936
  if (payload.body && payload.headers) {
2936
2937
  encryptOutput = { ...payload };
2937
2938
  headers = { ...payload.headers };
2939
+ if (payload.options && typeof payload.options === 'object') {
2940
+ Object.assign(requestOptions, payload.options);
2941
+ }
2938
2942
  payload = payload.body;
2939
2943
  cryptoMetadata = payload.cryptoMetadata;
2940
2944
  inputPayload = payload;
@@ -3227,6 +3231,47 @@ class FunctionRuntimeImpl {
3227
3231
  filesMap[qualifiedName] = field.serialize();
3228
3232
  }
3229
3233
  return filesMap;
3234
+ },
3235
+ setVariable: (variableName, variableValue, target) => {
3236
+ const args = [variableName, variableValue, target];
3237
+ return FunctionRuntimeImpl.getInstance().getFunctions().setVariable._func.call(undefined, args, data, interpreter);
3238
+ },
3239
+ getVariable: (variableName, target) => {
3240
+ const args = [variableName, target];
3241
+ return FunctionRuntimeImpl.getInstance().getFunctions().getVariable._func.call(undefined, args, data, interpreter);
3242
+ },
3243
+ request: async (options) => {
3244
+ const { url, method = 'GET', body: requestBody = {}, headers = { 'Content-Type': 'application/json' }, options: fetchOptions } = options;
3245
+ const funcs = FunctionRuntimeImpl.getInstance().getFunctions();
3246
+ const externalizedUrl = funcs.externalize._func.call(undefined, [url], data, interpreter);
3247
+ const random = Math.floor(Math.random() * 1000000);
3248
+ const now = Date.now();
3249
+ const internalSuccess = `custom:__internalSuccess_${random}_${now}`;
3250
+ const internalError = `custom:__internalError_${random}_${now}`;
3251
+ const encryptPayload = { body: requestBody, headers };
3252
+ if (fetchOptions) {
3253
+ encryptPayload.options = fetchOptions;
3254
+ }
3255
+ const payload = await funcs.encrypt._func.call(undefined, [encryptPayload], data, interpreter);
3256
+ const requestArgs = [externalizedUrl, method, payload, internalSuccess, internalError];
3257
+ const requestFn = funcs.requestWithRetry._func.call(undefined, requestArgs, data, interpreter);
3258
+ const response = await funcs.retryHandler._func.call(undefined, [requestFn], data, interpreter);
3259
+ const isSuccess = response?.status >= 200 && response?.status <= 299;
3260
+ if (isSuccess && response?.body) {
3261
+ const decryptedBody = await funcs.decrypt._func.call(undefined, [response.body, response.originalRequest], data, interpreter);
3262
+ return {
3263
+ ok: true,
3264
+ status: response.status,
3265
+ body: decryptedBody,
3266
+ headers: response.headers
3267
+ };
3268
+ }
3269
+ return {
3270
+ ok: isSuccess,
3271
+ status: response?.status,
3272
+ body: response?.body,
3273
+ headers: response?.headers
3274
+ };
3230
3275
  }
3231
3276
  }
3232
3277
  };
@@ -3550,6 +3595,13 @@ class FunctionRuntimeImpl {
3550
3595
  },
3551
3596
  _signature: []
3552
3597
  },
3598
+ externalize: {
3599
+ _func: (args, data, interpreter) => {
3600
+ const url = toString(args[0]);
3601
+ return url;
3602
+ },
3603
+ _signature: []
3604
+ },
3553
3605
  awaitFn: {
3554
3606
  _func: async (args, data, interpreter) => {
3555
3607
  const success = args[1];
@@ -67,6 +67,10 @@ declare class FunctionRuntimeImpl {
67
67
  _func: (args: Array<unknown>, data: unknown, interpreter: any) => any;
68
68
  _signature: never[];
69
69
  };
70
+ externalize: {
71
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => string;
72
+ _signature: never[];
73
+ };
70
74
  awaitFn: {
71
75
  _func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<{}>;
72
76
  _signature: never[];
package/lib/Container.js CHANGED
@@ -357,25 +357,26 @@ class Container extends Scriptable_1.default {
357
357
  }
358
358
  importData(dataModel) {
359
359
  var _a;
360
- if (typeof this._data !== 'undefined' && this.type === 'array' && Array.isArray(dataModel)) {
361
- const dataGroup = new DataGroup_1.default(this._data.$name, dataModel, this._data.$type, this._data.parent);
362
- try {
363
- (_a = this._data.parent) === null || _a === void 0 ? void 0 : _a.$addDataNode(dataGroup.$name, dataGroup, true);
364
- }
365
- catch (e) {
366
- this.form.logger.error(`unable to setItems for ${this.qualifiedName} : ${e}`);
367
- return;
368
- }
369
- this._data = dataGroup;
370
- this.syncDataAndFormModel(dataGroup);
371
- const newLength = this.items.length;
372
- for (let i = 0; i < newLength; i += 1) {
373
- this._children[i].dispatch(new Events_1.ExecuteRule());
374
- }
375
- }
376
- else if (typeof this._data === 'undefined') {
360
+ if (typeof this._data === 'undefined') {
377
361
  console.warn(`Data node is null, hence importData did not work for panel "${this.name}". Check if parent has a dataRef set to null.`);
362
+ return;
363
+ }
364
+ const isArrayPanel = this.type === 'array' && Array.isArray(dataModel);
365
+ const isObjectPanel = this.type === 'object' && typeof dataModel === 'object' && dataModel !== null && !Array.isArray(dataModel);
366
+ if (!isArrayPanel && !isObjectPanel) {
367
+ return;
368
+ }
369
+ const dataGroup = new DataGroup_1.default(this._data.$name, dataModel, this._data.$type, this._data.parent);
370
+ try {
371
+ (_a = this._data.parent) === null || _a === void 0 ? void 0 : _a.$addDataNode(dataGroup.$name, dataGroup, true);
372
+ }
373
+ catch (e) {
374
+ this.form.logger.error(`unable to importData for ${this.qualifiedName} : ${e}`);
375
+ return;
378
376
  }
377
+ this._data = dataGroup;
378
+ this.syncDataAndFormModel(dataGroup);
379
+ this._children.forEach((child) => child.dispatch(new Events_1.ExecuteRule()));
379
380
  }
380
381
  syncDataAndFormModel(contextualDataModel) {
381
382
  const result = {
@@ -67,6 +67,10 @@ declare class FunctionRuntimeImpl {
67
67
  _func: (args: Array<unknown>, data: unknown, interpreter: any) => any;
68
68
  _signature: never[];
69
69
  };
70
+ externalize: {
71
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => string;
72
+ _signature: never[];
73
+ };
70
74
  awaitFn: {
71
75
  _func: (args: Array<unknown>, data: unknown, interpreter: any) => Promise<{}>;
72
76
  _signature: never[];
@@ -50,6 +50,9 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
50
50
  if (payload.body && payload.headers) {
51
51
  encryptOutput = Object.assign({}, payload);
52
52
  headers = Object.assign({}, payload.headers);
53
+ if (payload.options && typeof payload.options === 'object') {
54
+ Object.assign(requestOptions, payload.options);
55
+ }
53
56
  payload = payload.body;
54
57
  cryptoMetadata = payload.cryptoMetadata;
55
58
  inputPayload = payload;
@@ -329,7 +332,48 @@ class FunctionRuntimeImpl {
329
332
  filesMap[qualifiedName] = field.serialize();
330
333
  }
331
334
  return filesMap;
332
- }
335
+ },
336
+ setVariable: (variableName, variableValue, target) => {
337
+ const args = [variableName, variableValue, target];
338
+ return FunctionRuntimeImpl.getInstance().getFunctions().setVariable._func.call(undefined, args, data, interpreter);
339
+ },
340
+ getVariable: (variableName, target) => {
341
+ const args = [variableName, target];
342
+ return FunctionRuntimeImpl.getInstance().getFunctions().getVariable._func.call(undefined, args, data, interpreter);
343
+ },
344
+ request: (options) => __awaiter(this, void 0, void 0, function* () {
345
+ const { url, method = 'GET', body: requestBody = {}, headers = { 'Content-Type': 'application/json' }, options: fetchOptions } = options;
346
+ const funcs = FunctionRuntimeImpl.getInstance().getFunctions();
347
+ const externalizedUrl = funcs.externalize._func.call(undefined, [url], data, interpreter);
348
+ const random = Math.floor(Math.random() * 1000000);
349
+ const now = Date.now();
350
+ const internalSuccess = `custom:__internalSuccess_${random}_${now}`;
351
+ const internalError = `custom:__internalError_${random}_${now}`;
352
+ const encryptPayload = { body: requestBody, headers };
353
+ if (fetchOptions) {
354
+ encryptPayload.options = fetchOptions;
355
+ }
356
+ const payload = yield funcs.encrypt._func.call(undefined, [encryptPayload], data, interpreter);
357
+ const requestArgs = [externalizedUrl, method, payload, internalSuccess, internalError];
358
+ const requestFn = funcs.requestWithRetry._func.call(undefined, requestArgs, data, interpreter);
359
+ const response = yield funcs.retryHandler._func.call(undefined, [requestFn], data, interpreter);
360
+ const isSuccess = (response === null || response === void 0 ? void 0 : response.status) >= 200 && (response === null || response === void 0 ? void 0 : response.status) <= 299;
361
+ if (isSuccess && (response === null || response === void 0 ? void 0 : response.body)) {
362
+ const decryptedBody = yield funcs.decrypt._func.call(undefined, [response.body, response.originalRequest], data, interpreter);
363
+ return {
364
+ ok: true,
365
+ status: response.status,
366
+ body: decryptedBody,
367
+ headers: response.headers
368
+ };
369
+ }
370
+ return {
371
+ ok: isSuccess,
372
+ status: response === null || response === void 0 ? void 0 : response.status,
373
+ body: response === null || response === void 0 ? void 0 : response.body,
374
+ headers: response === null || response === void 0 ? void 0 : response.headers
375
+ };
376
+ })
333
377
  }
334
378
  };
335
379
  return funcDef(...args, globals);
@@ -647,6 +691,13 @@ class FunctionRuntimeImpl {
647
691
  },
648
692
  _signature: []
649
693
  },
694
+ externalize: {
695
+ _func: (args, data, interpreter) => {
696
+ const url = toString(args[0]);
697
+ return url;
698
+ },
699
+ _signature: []
700
+ },
650
701
  awaitFn: {
651
702
  _func: (args, data, interpreter) => __awaiter(this, void 0, void 0, function* () {
652
703
  const success = args[1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.161",
3
+ "version": "0.22.163",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@adobe/json-formula": "0.1.50",
40
- "@aemforms/af-formatters": "^0.22.161"
40
+ "@aemforms/af-formatters": "^0.22.163"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",