@integry/sdk 4.6.1 → 4.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@integry/sdk",
3
- "version": "4.6.1",
3
+ "version": "4.6.3",
4
4
  "description": "Integry SDK",
5
5
  "main": "dist/umd/index.umd.js",
6
6
  "module": "dist/esm/index.csm.js",
@@ -1,5 +1,5 @@
1
1
  import { html } from 'htm/preact';
2
- import { useState } from 'preact/hooks';
2
+ import { useState, useEffect } from 'preact/hooks';
3
3
  import { Input } from '@/components/Input';
4
4
  import { TextArea } from '@/components/TextArea';
5
5
  import { CheckboxGroup } from '@/components/CheckboxGroup';
@@ -107,7 +107,9 @@ const ObjectField = (props: ObjectFieldProps) => {
107
107
  activityOutputDataRaw,
108
108
  objectValue,
109
109
  } = props;
110
- const [objectArray, setObjectArray] = useState<FieldObject[]>([{}]); // Start with one empty object in the array
110
+ const [objectArray, setObjectArray] = useState<FieldObject[]>(
111
+ Array.isArray(objectValue) ? objectValue : [{}],
112
+ ); // Start with one empty object in the array
111
113
  const [showAddMoreOption, setShowAddMoreOption] = useState(true);
112
114
  const [objectHasFields, setObjectHasFields] = useState(true);
113
115
 
@@ -158,6 +160,21 @@ const ObjectField = (props: ObjectFieldProps) => {
158
160
  );
159
161
  }
160
162
 
163
+ useEffect(() => {
164
+ let objectValueCopy = objectValue;
165
+ if (typeof objectValue === 'string' && objectValue.length > 0) {
166
+ // if default value was sent as a strinfiyed object
167
+ objectValueCopy = JSON.parse(objectValue);
168
+ }
169
+ if (objectValueCopy) {
170
+ if (Array.isArray(objectValueCopy)) {
171
+ setObjectArray(objectValueCopy);
172
+ } else {
173
+ setObjectArray([objectValueCopy]);
174
+ }
175
+ }
176
+ }, [objectValue]);
177
+
161
178
  // Method to handle field changes for each object in the array
162
179
  const handleFieldChange = (
163
180
  index: number,
@@ -280,7 +297,9 @@ const ObjectField = (props: ObjectFieldProps) => {
280
297
  activityOutputData=${activityOutputData}
281
298
  activityOutputDataRaw=${activityOutputDataRaw}
282
299
  description="${fieldDetails.meta.description_for_users}"
283
- value=${(objectArray[objectIndex] || {})[fieldName] || ''}
300
+ value=${(objectArray[objectIndex] || {})[
301
+ fieldDetails?.meta?.machine_name || ''
302
+ ] || ''}
284
303
  placeholder="${placeholder}"
285
304
  onChange=${(val: any) => {
286
305
  const valueReceived =
@@ -186,6 +186,34 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
186
186
  return requiredFieldsWithValues;
187
187
  };
188
188
 
189
+ makeTagSourceFunctionBody = (
190
+ obj: any,
191
+ sourceData: any,
192
+ sourceStepName: string,
193
+ ): any => {
194
+ if (typeof obj === 'string') {
195
+ return obj.replace(
196
+ new RegExp(`{[^}]*\\.${sourceStepName}\\.([a-zA-Z0-9_]+)}`, 'g'),
197
+ (_, key) => sourceData[key] ?? `{${sourceStepName}.${key}}`, // Preserve if not found
198
+ );
199
+ }
200
+ if (Array.isArray(obj)) {
201
+ return obj.map((item) =>
202
+ this.makeTagSourceFunctionBody(item, sourceData, sourceStepName),
203
+ );
204
+ }
205
+ if (typeof obj === 'object' && obj !== null) {
206
+ return Object.fromEntries(
207
+ Object.entries(obj).map(([key, value]) => [
208
+ key,
209
+ this.makeTagSourceFunctionBody(value, sourceData, sourceStepName),
210
+ ]),
211
+ );
212
+ }
213
+
214
+ return obj; // Default return for non-string, non-object, non-array types
215
+ };
216
+
189
217
  refreshRootStepData = async (callback?: any) => {
190
218
  const triggerStep = this.props.genericData.stepWithActivityOutput;
191
219
  if (triggerStep) {
@@ -247,8 +275,20 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
247
275
  const isFunctionSource = stepTagsSource.activity_output_url.includes(
248
276
  'functions/',
249
277
  );
278
+ const tagSourceFunctionInvocationDetails =
279
+ stepTagsSource.tag_source_function_invocation_details;
280
+ const tagSourceFunctionBody =
281
+ isFunctionSource && tagSourceFunctionInvocationDetails
282
+ ? this.makeTagSourceFunctionBody(
283
+ tagSourceFunctionInvocationDetails.body,
284
+ sourceStepData,
285
+ stepTagsSource.form_step_machine_name,
286
+ )
287
+ : {};
250
288
  const callDynamicDataEndpointMethod = isFunctionSource
251
- ? 'POST'
289
+ ? tagSourceFunctionInvocationDetails
290
+ ? tagSourceFunctionInvocationDetails.method
291
+ : 'POST'
252
292
  : 'GET';
253
293
 
254
294
  props.apiHandler
@@ -262,6 +302,7 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
262
302
  {
263
303
  authorization_id: `${props.stepMapping[stepIdOfSourceStep].selectedAuthId}`,
264
304
  ...sourceStepData,
305
+ ...tagSourceFunctionBody,
265
306
  },
266
307
  callDynamicDataEndpointMethod,
267
308
  )