@integry/sdk 4.5.3 → 4.5.5

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.
@@ -29,6 +29,7 @@ import NewMappingUI from '@/features/common/NewMappingUI';
29
29
  import { ObjectField } from '@/components/form';
30
30
  import { areParentValuesValid, getFieldLabelTags } from '@/utils/stepUtils';
31
31
  import ConfigureFieldWrapper from '@/components/ConfigureFieldWrapper';
32
+ import { notEmpty } from '@/types/utils';
32
33
  import {
33
34
  JSONToActivityOutputData,
34
35
  JSONToDynamicFieldData,
@@ -44,6 +45,7 @@ interface ActionFormPropsType extends StoreType {
44
45
  eventEmitter: EventEmitter<IntegrySDKEvents>;
45
46
  isReadOnly?: boolean;
46
47
  accountConnected: boolean;
48
+ selectedAuthId: string;
47
49
  }
48
50
 
49
51
  interface ActionFormStateType {
@@ -173,16 +175,27 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
173
175
  }
174
176
  }
175
177
 
178
+ const isFunctionSource = stepTagsSource.activity_output_url.includes(
179
+ 'functions/',
180
+ );
181
+ const callDynamicDataEndpointMethod = isFunctionSource
182
+ ? 'POST'
183
+ : 'GET';
184
+
176
185
  props.apiHandler
177
186
  .callDynamicDataEndpoint<
178
187
  {
179
188
  text: string;
180
189
  value: string;
181
190
  }[]
182
- >(new URL(stepTagsSource.activity_output_url), {
183
- authorization_id: `${props.stepMapping[stepIdOfSourceStep].selectedAuthId}`,
184
- ...sourceStepData,
185
- })
191
+ >(
192
+ new URL(stepTagsSource.activity_output_url),
193
+ {
194
+ authorization_id: `${props.stepMapping[stepIdOfSourceStep].selectedAuthId}`,
195
+ ...sourceStepData,
196
+ },
197
+ callDynamicDataEndpointMethod,
198
+ )
186
199
  .then((res) => {
187
200
  setState({
188
201
  loading: false,
@@ -190,15 +203,26 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
190
203
 
191
204
  let error = false;
192
205
  if (res) {
193
- props.setActivityOutputData({
194
- activityOutputData: stepTagsSource.loop_variable_name
195
- ? this.replaceContactPrefix(
196
- res,
197
- sourceStepKey,
198
- stepTagsSource,
199
- )
200
- : res,
201
- });
206
+ const functionResponse: any = res;
207
+
208
+ if (isFunctionSource && 'output' in functionResponse) {
209
+ this.setActivityOutputFromIntegryObjectOrRawActivityOutput(
210
+ functionResponse.output,
211
+ stepTagsSource,
212
+ sourceStepKey,
213
+ true,
214
+ );
215
+ } else {
216
+ props.setActivityOutputData({
217
+ activityOutputData: stepTagsSource.loop_variable_name
218
+ ? this.replaceContactPrefix(
219
+ res,
220
+ sourceStepKey,
221
+ stepTagsSource,
222
+ )
223
+ : res,
224
+ });
225
+ }
202
226
  } else {
203
227
  error = true;
204
228
  }
@@ -377,20 +401,26 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
377
401
  integryObject: any,
378
402
  stepTagsSource: any,
379
403
  sourceStepKey = '',
404
+ isFunctionSource = false,
380
405
  ) => {
381
406
  if (integryObject) {
382
407
  try {
383
- const parsedIntegryObject = JSON.parse(
384
- integryObject,
385
- ) as IncomingWebhookObject;
386
408
  let objectPaylaod = {};
387
- if (this.props.userConfig?.objects?.[parsedIntegryObject.name]) {
388
- objectPaylaod = this.props.userConfig?.objects?.[
389
- parsedIntegryObject.name
390
- ];
409
+ if (isFunctionSource) {
410
+ objectPaylaod = integryObject;
391
411
  } else {
392
- objectPaylaod = JSON.parse(parsedIntegryObject.payload);
412
+ const parsedIntegryObject = JSON.parse(
413
+ integryObject,
414
+ ) as IncomingWebhookObject;
415
+ if (this.props.userConfig?.objects?.[parsedIntegryObject.name]) {
416
+ objectPaylaod = this.props.userConfig?.objects?.[
417
+ parsedIntegryObject.name
418
+ ];
419
+ } else {
420
+ objectPaylaod = JSON.parse(parsedIntegryObject.payload);
421
+ }
393
422
  }
423
+
394
424
  const activityOutputData = JSONToActivityOutputData(
395
425
  objectPaylaod,
396
426
  '',
@@ -683,6 +713,9 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
683
713
  };
684
714
 
685
715
  private shouldShowStep = (field: TemplateField) => {
716
+ if (!this.props.showStepValidation) {
717
+ return true;
718
+ }
686
719
  const stepId = this.props.step.id;
687
720
  const stepObject = this.props.stepMapping && this.props.stepMapping[stepId];
688
721
 
@@ -728,13 +761,15 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
728
761
 
729
762
  private stepIsOfType = (fields: string[]) => {
730
763
  const stepId = this.props.step.id;
731
- const stepObject = this.props.stepMapping && this.props.stepMapping[stepId];
732
- return fields.indexOf(stepObject.step.activity.type) > -1;
764
+ const stepObject = (this.props.stepMapping &&
765
+ this.props.stepMapping[stepId]) || { step: this.props.step };
766
+ return fields.indexOf(stepObject.step.activity?.type) > -1;
733
767
  };
734
768
 
735
769
  private textFieldParentHasValues = (currentField: any) => {
736
770
  const stepId = this.props.step.id;
737
- const stepObject = this.props.stepMapping && this.props.stepMapping[stepId];
771
+ const stepObject = (this.props.stepMapping &&
772
+ this.props.stepMapping[stepId]) || { step: this.props.step };
738
773
 
739
774
  const anyVisibleFields = stepObject.step.template_fields.filter(
740
775
  (el) => el.is_visible,
@@ -1095,8 +1130,10 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
1095
1130
  isReadOnly,
1096
1131
  accountConnected,
1097
1132
  } = this.props;
1098
- const selectedStep = stepMapping[step.id] && stepMapping[step.id].step;
1099
- const selectedStepData = stepDataMapping && stepDataMapping[step.id];
1133
+ const selectedStep =
1134
+ (stepMapping[step.id] && stepMapping[step.id].step) || step;
1135
+ const selectedStepData =
1136
+ (stepDataMapping && stepDataMapping[step.id]) || {};
1100
1137
  const actionConfigPayload = {};
1101
1138
  // userConfig?.objects && genericData.directActionPayloadName
1102
1139
  // ? embedConfig?.objects[genericData.directActionPayloadName]
@@ -1106,9 +1143,9 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
1106
1143
  const activityOutputData =
1107
1144
  actionConfigPayload || this.props.activityOutputData || {};
1108
1145
  const noStepFields =
1109
- selectedStep.template_fields.length === 0 ||
1146
+ selectedStep.template_fields?.length === 0 ||
1110
1147
  (!(this.props.userConfig && this.props.userConfig.viewAsIU) &&
1111
- selectedStep.template_fields.filter((field) => field.is_visible)
1148
+ selectedStep.template_fields?.filter((field) => field.is_visible)
1112
1149
  .length === 0);
1113
1150
  return html`
1114
1151
  ${this.state.loading
@@ -1116,12 +1153,18 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
1116
1153
  : html`
1117
1154
  ${selectedStep
1118
1155
  ? html`
1119
- <div class=${styles.actionFormWrap}>
1156
+ <div
1157
+ class=${`${styles.actionFormWrap} ${
1158
+ this.props.selectedAuthId && this.props.accountConnected
1159
+ ? `${styles.actionFormWrapAutoWidth}`
1160
+ : ``
1161
+ }`}
1162
+ >
1120
1163
  ${noStepFields
1121
1164
  ? html`<span class=${styles.noStepFields}
1122
1165
  >There’s nothing to configure, please proceed.</span
1123
1166
  >`
1124
- : selectedStep.template_fields.map((el) => {
1167
+ : selectedStep.template_fields?.map((el) => {
1125
1168
  if (
1126
1169
  this.shouldShowStep(el) &&
1127
1170
  (el.activity_field || el.type === 'SECTION')
@@ -1211,11 +1254,15 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
1211
1254
  type=${el.activity_field?.type}
1212
1255
  selectedAuthId=${`${
1213
1256
  this.props.stepMapping[this.props.step.id]
1214
- ?.selectedAuthId || ''
1257
+ ?.selectedAuthId ||
1258
+ this.props.selectedAuthId ||
1259
+ ''
1215
1260
  }`}
1216
- disabled=${!this.props.stepMapping[
1217
- this.props.step.id
1218
- ]?.isAuthVerified}
1261
+ disabled=${
1262
+ !this.props.stepMapping[this.props.step.id]
1263
+ ?.isAuthVerified &&
1264
+ !this.props.accountConnected
1265
+ }
1219
1266
  sourceFlowData=${this.sourceFlowData(el)}
1220
1267
  sourceFlowIntegrataionInvocationUrl=${
1221
1268
  el.source_flow_integration_invocation_url
@@ -1309,9 +1356,16 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
1309
1356
  }
1310
1357
  placeholder=${this.getPlaceholder(el)}
1311
1358
  showStepValidation=${showStepValidation}
1312
- regex=${selectedStepData[el.id].regex}
1359
+ regex=${
1360
+ selectedStepData[el.id]
1361
+ ? selectedStepData[el.id].regex
1362
+ : ''
1363
+ }
1313
1364
  regexErrorMessage=${
1314
- selectedStepData[el.id].regexErrorMessage
1365
+ selectedStepData[el.id]
1366
+ ? selectedStepData[el.id]
1367
+ .regexErrorMessage
1368
+ : ''
1315
1369
  }
1316
1370
  isRequired=${el.is_required}
1317
1371
  isHidden=${el.is_hidden}
@@ -1421,10 +1475,15 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
1421
1475
  placeholder=${el.placeholder ||
1422
1476
  'Please enter a URL'}
1423
1477
  showStepValidation=${showStepValidation}
1424
- regex=${selectedStepData[el.id].regex}
1478
+ regex=${selectedStepData[el.id]
1479
+ ? selectedStepData[el.id].regex
1480
+ : ''}
1425
1481
  regexErrorMessage=${selectedStepData[
1426
1482
  el.id
1427
- ].regexErrorMessage}
1483
+ ]
1484
+ ? selectedStepData[el.id]
1485
+ .regexErrorMessage
1486
+ : ''}
1428
1487
  isRequired=${el.is_required}
1429
1488
  onChange=${(
1430
1489
  val: string,
@@ -1558,10 +1617,15 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
1558
1617
  placeholder=${el.placeholder ||
1559
1618
  el.activity_field?.placeholder ||
1560
1619
  'Please enter a value'}
1561
- regex=${selectedStepData[el.id].regex}
1620
+ regex=${selectedStepData[el.id]
1621
+ ? selectedStepData[el.id].regex
1622
+ : ''}
1562
1623
  regexErrorMessage=${selectedStepData[
1563
1624
  el.id
1564
- ].regexErrorMessage}
1625
+ ]
1626
+ ? selectedStepData[el.id]
1627
+ .regexErrorMessage
1628
+ : ''}
1565
1629
  showStepValidation=${showStepValidation}
1566
1630
  isRequired=${el.is_required}
1567
1631
  onChange=${(val: string) => {
@@ -1603,9 +1667,16 @@ class ActionForm extends Component<ActionFormPropsType, ActionFormStateType> {
1603
1667
  ''
1604
1668
  }
1605
1669
  placeholder=${this.getPlaceholder(el)}
1606
- regex=${selectedStepData[el.id].regex}
1670
+ regex=${
1671
+ selectedStepData[el.id].regex
1672
+ ? selectedStepData[el.id].regex
1673
+ : ''
1674
+ }
1607
1675
  regexErrorMessage=${
1608
- selectedStepData[el.id].regexErrorMessage
1676
+ selectedStepData[el.id]
1677
+ ? selectedStepData[el.id]
1678
+ .regexErrorMessage
1679
+ : ''
1609
1680
  }
1610
1681
  showStepValidation=${showStepValidation}
1611
1682
  isRequired=${el.is_required}
@@ -12,6 +12,11 @@
12
12
  .actionStepFieldWrap {
13
13
  // margin-bottom: 16px;
14
14
  }
15
+ .actionFormWrapAutoWidth {
16
+ margin-left: 24px;
17
+ margin-right: 24px;
18
+ width: auto;
19
+ }
15
20
 
16
21
  .unsupported {
17
22
  font-size: 12px;
package/src/index.ts CHANGED
@@ -41,6 +41,7 @@ import FlowSetupContainer from '@/features/containers/FlowSetupContainer';
41
41
  import MarketplaceContainer from '@/features/containers/MarketplaceContainer';
42
42
  import AppFlowContainer from '@/features/containers/AppFlowContainer';
43
43
  import MarketplaceAppsContainer from '@/features/containers/MarketplaceAppsContainer';
44
+ import ActionForm from '@/features/common/ActionForm';
44
45
 
45
46
  import FunctionForm from '@/features/common/FunctionForm';
46
47
  import { openPopupWindow } from '@/utils/popup';
@@ -1980,6 +1981,47 @@ export class IntegryJS {
1980
1981
  }
1981
1982
  };
1982
1983
 
1984
+ public renderFlowStep = (
1985
+ containerId: string,
1986
+ step: any,
1987
+ connectedAccountId: string,
1988
+ ) => {
1989
+ const target = document.getElementById(containerId);
1990
+
1991
+ if (target) {
1992
+ const store = createSDKStore();
1993
+ render(
1994
+ html`<div>
1995
+ <${AppContext.Provider}
1996
+ value=${{
1997
+ apiHandler: this.apiHandler,
1998
+ eventEmitter: this.eventEmitter,
1999
+ isPreviewMode: false,
2000
+ }}
2001
+ >
2002
+ <${Provider} store=${store} key=${this.getRandomFlowId(10)}>
2003
+ <${ActionForm}
2004
+ step=${step}
2005
+ stepType=${'CONFIGURE'}
2006
+ showStepValidation=${false}
2007
+ apiHandler=${this.apiHandler}
2008
+ eventEmitter=${this.eventEmitter}
2009
+ isReadOnly="${false}"
2010
+ selectedAuthId="${connectedAccountId}"
2011
+ accountConnected=${true}
2012
+ />
2013
+ <//>
2014
+ <//>
2015
+ </div>`,
2016
+ target,
2017
+ );
2018
+ } else {
2019
+ console.warn(
2020
+ `Integry SDK render target with id ${containerId} was not found`,
2021
+ );
2022
+ }
2023
+ };
2024
+
1983
2025
  public verifyAuthConfig = () =>
1984
2026
  this.apiHandler.verifyAuthConfig({
1985
2027
  deploymentId: this.config.deploymentId,
File without changes
@@ -517,10 +517,15 @@ export const actionFunctions = (storeSnapshot: Store<State>) => ({
517
517
  const { stepDataMapping, conditionalFieldMapping } = state;
518
518
  const element = stepDataMapping[stepId];
519
519
 
520
- const fieldsData = Object.keys(element).map((fieldId) => {
521
- const ele = element[Number(fieldId)];
522
- return ele;
523
- });
520
+ let fieldsData: any[] = [];
521
+ if (element) {
522
+ fieldsData = Object.keys(element).map((fieldId) => {
523
+ const ele = element[Number(fieldId)];
524
+ return ele;
525
+ });
526
+ } else {
527
+ fieldsData = [];
528
+ }
524
529
 
525
530
  const visibleFields = fieldsData.filter((el) => {
526
531
  // filter out hidden conditional fields
package/vitest.config.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { defineConfig } from 'vitest/config';
2
+ import path from 'path';
2
3
 
3
4
  export default defineConfig({
5
+ resolve: {
6
+ alias: {
7
+ '@': path.resolve(__dirname, './src'),
8
+ },
9
+ },
4
10
  test: {
5
11
  globals: true,
6
12
  environment: 'jsdom',