@zapier/zapier-sdk 0.10.0 → 0.11.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -5
  3. package/dist/index.cjs +130 -15
  4. package/dist/index.d.mts +121 -15
  5. package/dist/index.mjs +130 -15
  6. package/dist/plugins/listInputFields/index.d.ts +4 -4
  7. package/dist/plugins/listInputFields/index.d.ts.map +1 -1
  8. package/dist/plugins/listInputFields/index.js +61 -7
  9. package/dist/plugins/listInputFields/schemas.d.ts +3 -3
  10. package/dist/plugins/listInputFields/schemas.d.ts.map +1 -1
  11. package/dist/resolvers/inputFieldKey.d.ts.map +1 -1
  12. package/dist/resolvers/inputFieldKey.js +25 -1
  13. package/dist/resolvers/inputs.d.ts +12 -8
  14. package/dist/resolvers/inputs.d.ts.map +1 -1
  15. package/dist/resolvers/inputs.js +23 -4
  16. package/dist/schemas/Field.d.ts +109 -1
  17. package/dist/schemas/Field.d.ts.map +1 -1
  18. package/dist/schemas/Field.js +41 -2
  19. package/dist/types/domain.d.ts +17 -1
  20. package/dist/types/domain.d.ts.map +1 -1
  21. package/dist/utils/string-utils.d.ts +12 -0
  22. package/dist/utils/string-utils.d.ts.map +1 -0
  23. package/dist/utils/string-utils.js +23 -0
  24. package/dist/utils/string-utils.test.d.ts +2 -0
  25. package/dist/utils/string-utils.test.d.ts.map +1 -0
  26. package/dist/utils/string-utils.test.js +36 -0
  27. package/package.json +1 -1
  28. package/src/plugins/listInputFields/index.ts +73 -13
  29. package/src/plugins/listInputFields/schemas.ts +6 -3
  30. package/src/resolvers/inputFieldKey.ts +33 -1
  31. package/src/resolvers/inputs.ts +38 -12
  32. package/src/schemas/Field.ts +75 -5
  33. package/src/types/domain.ts +24 -1
  34. package/src/utils/string-utils.test.ts +45 -0
  35. package/src/utils/string-utils.ts +26 -0
  36. package/tsconfig.tsbuildinfo +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listInputFields/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EACL,qBAAqB,EACrB,KAAK,sBAAsB,EAE5B,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AA0GxE,MAAM,WAAW,6BAA6B;IAC5C,eAAe,EAAE,CAAC,OAAO,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC;QAC7D,IAAI,EAAE,cAAc,EAAE,CAAC;KACxB,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,cAAc,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAC/D,KAAK,IAAI,aAAa,CAAC,cAAc,CAAC,CAAC;KACxC,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,eAAe,EAAE;gBACf,WAAW,EAAE,OAAO,qBAAqB,CAAC;aAC3C,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,qBAAqB,EAAE,MAAM,CACxC,UAAU,CAAC,oBAAoB,CAAC,EAAE,yBAAyB;AAC3D;IACE,GAAG,EAAE,SAAS,CAAC;IACf,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,EAAE,2DAA2D;AAC9D,6BAA6B,CAqF9B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/listInputFields/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,aAAa,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,qBAAqB,EACrB,KAAK,sBAAsB,EAE5B,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAmKxE,MAAM,WAAW,6BAA6B;IAC5C,eAAe,EAAE,CAAC,OAAO,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC;QAC7D,IAAI,EAAE,aAAa,EAAE,CAAC;KACvB,CAAC,GACA,aAAa,CAAC;QAAE,IAAI,EAAE,aAAa,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAC9D,KAAK,IAAI,aAAa,CAAC,cAAc,GAAG,aAAa,GAAG,YAAY,CAAC,CAAC;KACvE,CAAC;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,eAAe,EAAE;gBACf,WAAW,EAAE,OAAO,qBAAqB,CAAC;aAC3C,CAAC;SACH,CAAC;KACH,CAAC;CACH;AAED,eAAO,MAAM,qBAAqB,EAAE,MAAM,CACxC,UAAU,CAAC,oBAAoB,CAAC,EAAE,yBAAyB;AAC3D;IACE,GAAG,EAAE,SAAS,CAAC;IACf,4BAA4B,EAAE,4BAA4B,CAAC;CAC5D,EAAE,2DAA2D;AAC9D,6BAA6B,CAmF9B,CAAC"}
@@ -2,7 +2,8 @@ import { ListInputFieldsSchema, } from "./schemas";
2
2
  import { ZapierConfigurationError, ZapierApiError } from "../../types/errors";
3
3
  import { createPaginatedFunction } from "../../utils/function-utils";
4
4
  import { appKeyResolver, actionTypeResolver, actionKeyResolver, authenticationIdResolver, inputsAllOptionalResolver, } from "../../resolvers";
5
- import { InputFieldItemSchema } from "../../schemas/Field";
5
+ import { RootFieldItemSchema } from "../../schemas/Field";
6
+ import { toTitleCase } from "../../utils/string-utils";
6
7
  // Enums for input field transformation
7
8
  var InputFieldType;
8
9
  (function (InputFieldType) {
@@ -74,7 +75,7 @@ function getItemsTypeFromNeed(need) {
74
75
  function transformNeedToInputFieldItem(need) {
75
76
  const itemsType = getItemsTypeFromNeed(need);
76
77
  return {
77
- // Only the final computed/mapped fields that are in InputFieldItemSchema
78
+ type: "input_field",
78
79
  key: need.key,
79
80
  default_value: need.default || "",
80
81
  depends_on: need.depends_on || [],
@@ -88,6 +89,59 @@ function transformNeedToInputFieldItem(need) {
88
89
  items: itemsType ? { type: itemsType } : undefined,
89
90
  };
90
91
  }
92
+ // Transform Need to InfoFieldItem (for copy fields)
93
+ function transformNeedToInfoFieldItem(need) {
94
+ return {
95
+ type: "info_field",
96
+ key: need.key,
97
+ description: need.help_text || "",
98
+ title: need.label,
99
+ };
100
+ }
101
+ // Transform needs to fields (similar to partnerapi compute_root_fieldset_from_needs)
102
+ function transformNeedsToFields(needs) {
103
+ const rootFields = [];
104
+ const fieldsetMap = new Map();
105
+ for (const need of needs) {
106
+ if (need.computed) {
107
+ // Computed needs (i.e zap_id for CodeAPI steps) are not shown by the
108
+ // editor, hide them here too.
109
+ continue;
110
+ }
111
+ // If parent_key is set, we need to ensure that a corresponding
112
+ // fieldset exists, since we'll be adding this need to that fieldset
113
+ if (need.parent_key) {
114
+ let fieldset = fieldsetMap.get(need.parent_key);
115
+ if (!fieldset) {
116
+ fieldset = {
117
+ type: "fieldset",
118
+ key: need.parent_key,
119
+ title: toTitleCase(need.parent_key),
120
+ fields: [],
121
+ };
122
+ fieldsetMap.set(need.parent_key, fieldset);
123
+ rootFields.push(fieldset);
124
+ }
125
+ // Add field to fieldset
126
+ if (need.type === "copy" && need.help_text) {
127
+ fieldset.fields.push(transformNeedToInfoFieldItem(need));
128
+ }
129
+ else {
130
+ fieldset.fields.push(transformNeedToInputFieldItem(need));
131
+ }
132
+ }
133
+ else {
134
+ // Add field to root
135
+ if (need.type === "copy" && need.help_text) {
136
+ rootFields.push(transformNeedToInfoFieldItem(need));
137
+ }
138
+ else {
139
+ rootFields.push(transformNeedToInputFieldItem(need));
140
+ }
141
+ }
142
+ }
143
+ return rootFields;
144
+ }
91
145
  export const listInputFieldsPlugin = ({ context }) => {
92
146
  const listInputFields = createPaginatedFunction(async function listInputFieldsPage(options) {
93
147
  // Note: This function ignores pageSize and cursor since it's not actually paginated internally
@@ -114,10 +168,10 @@ export const listInputFieldsPlugin = ({ context }) => {
114
168
  if (!needsData.success) {
115
169
  throw new ZapierApiError(`Failed to get action fields: ${needsData.errors?.join(", ") || "Unknown error"}`);
116
170
  }
117
- // Transform Need objects to InputFieldItem objects
118
- const inputFields = (needsData.needs || []).map(transformNeedToInputFieldItem);
171
+ // Transform Need objects to Root Fieldset with proper nesting
172
+ const rootFieldset = transformNeedsToFields(needsData.needs || []);
119
173
  return {
120
- data: inputFields,
174
+ data: rootFieldset,
121
175
  nextCursor: undefined, // No pagination needed since we return all input fields
122
176
  };
123
177
  }, ListInputFieldsSchema);
@@ -128,9 +182,9 @@ export const listInputFieldsPlugin = ({ context }) => {
128
182
  listInputFields: {
129
183
  categories: ["action"],
130
184
  type: "list",
131
- itemType: "InputField",
185
+ itemType: "RootFieldItem",
132
186
  inputSchema: ListInputFieldsSchema,
133
- outputSchema: InputFieldItemSchema,
187
+ outputSchema: RootFieldItemSchema,
134
188
  resolvers: {
135
189
  appKey: appKeyResolver,
136
190
  actionType: actionTypeResolver,
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import type { InputFieldItem } from "../../types/domain";
2
+ import type { RootFieldItem } from "../../types/domain";
3
3
  import type { PaginatedSdkFunction } from "../../types/functions";
4
4
  import type { ZapierConfigurationError, ZapierApiError, ZapierAuthenticationError, ZapierAppNotFoundError, ZapierValidationError, ZapierUnknownError } from "../../types/errors";
5
5
  export declare const ListInputFieldsSchema: z.ZodObject<{
@@ -32,10 +32,10 @@ export declare const ListInputFieldsSchema: z.ZodObject<{
32
32
  export type ListInputFieldsOptions = z.infer<typeof ListInputFieldsSchema>;
33
33
  export type ListInputFieldsError = ZapierConfigurationError | ZapierApiError | ZapierAuthenticationError | ZapierAppNotFoundError | ZapierValidationError | ZapierUnknownError;
34
34
  export interface ListInputFieldsPage {
35
- data: InputFieldItem[];
35
+ data: RootFieldItem[];
36
36
  nextCursor?: string;
37
37
  }
38
38
  export interface ListInputFieldsSdkFunction {
39
- listInputFields: PaginatedSdkFunction<ListInputFieldsOptions, InputFieldItem>;
39
+ listInputFields: PaginatedSdkFunction<ListInputFieldsOptions, RootFieldItem[]>;
40
40
  }
41
41
  //# sourceMappingURL=schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/listInputFields/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EACV,wBAAwB,EACxB,cAAc,EACd,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBgC,CAAC;AAGnE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAG3E,MAAM,MAAM,oBAAoB,GAC5B,wBAAwB,GACxB,cAAc,GACd,yBAAyB,GACzB,sBAAsB,GACtB,qBAAqB,GACrB,kBAAkB,CAAC;AAGvB,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,cAAc,EAAE,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAGD,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,oBAAoB,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAC;CAC/E"}
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/plugins/listInputFields/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EACV,wBAAwB,EACxB,cAAc,EACd,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBgC,CAAC;AAGnE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAG3E,MAAM,MAAM,oBAAoB,GAC5B,wBAAwB,GACxB,cAAc,GACd,yBAAyB,GACzB,sBAAsB,GACtB,qBAAqB,GACrB,kBAAkB,CAAC;AAGvB,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAGD,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,oBAAoB,CACnC,sBAAsB,EACtB,aAAa,EAAE,CAChB,CAAC;CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"inputFieldKey.d.ts","sourceRoot":"","sources":["../../src/resolvers/inputFieldKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,eAAO,MAAM,qBAAqB,EAAE,eAAe,CACjD,cAAc,EACd;IACE,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAyBF,CAAC"}
1
+ {"version":3,"file":"inputFieldKey.d.ts","sourceRoot":"","sources":["../../src/resolvers/inputFieldKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAiC9D,eAAO,MAAM,qBAAqB,EAAE,eAAe,CACjD,cAAc,EACd;IACE,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CA0BF,CAAC"}
@@ -1,3 +1,26 @@
1
+ /**
2
+ * Helper function to flatten fieldsets into a flat array of input fields.
3
+ * Used to extract all input fields from nested fieldset structure for field selection.
4
+ */
5
+ function flattenRootFieldset(rootFieldset) {
6
+ const result = [];
7
+ function processItem(item) {
8
+ if (item.type === "input_field") {
9
+ result.push(item);
10
+ }
11
+ else if (item.type === "fieldset") {
12
+ // Recursively process fields in the fieldset
13
+ for (const field of item.fields) {
14
+ processItem(field);
15
+ }
16
+ }
17
+ // Skip info fields as they're not input fields
18
+ }
19
+ for (const item of rootFieldset) {
20
+ processItem(item);
21
+ }
22
+ return result;
23
+ }
1
24
  export const inputFieldKeyResolver = {
2
25
  type: "dynamic",
3
26
  depends: ["appKey", "actionKey", "actionType", "authenticationId"],
@@ -9,7 +32,8 @@ export const inputFieldKeyResolver = {
9
32
  authenticationId: resolvedParams.authenticationId,
10
33
  inputs: resolvedParams.inputs, // Pass along currently resolved inputs
11
34
  });
12
- return fieldsResponse.data;
35
+ // Flatten the fieldset structure for field selection
36
+ return flattenRootFieldset(fieldsResponse.data);
13
37
  },
14
38
  prompt: (fields) => ({
15
39
  type: "list",
@@ -1,12 +1,16 @@
1
- import type { FieldsResolver } from "../utils/schema-utils";
2
1
  import type { ActionTypeProperty } from "../types/properties";
3
- type InputsResolver = FieldsResolver<{
4
- appKey: string;
5
- actionKey: string;
6
- actionType: ActionTypeProperty;
7
- authenticationId: number;
8
- inputs?: Record<string, unknown>;
9
- }>;
2
+ import type { RootFieldItem } from "../types/domain";
3
+ type InputsResolver = {
4
+ type: "fields";
5
+ depends: readonly string[];
6
+ fetch: (sdk: any, resolvedParams: {
7
+ appKey: string;
8
+ actionKey: string;
9
+ actionType: ActionTypeProperty;
10
+ authenticationId: number;
11
+ inputs?: Record<string, unknown>;
12
+ }) => Promise<RootFieldItem[]>;
13
+ };
10
14
  export declare const inputsResolver: InputsResolver;
11
15
  export declare const inputsAllOptionalResolver: InputsResolver;
12
16
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/resolvers/inputs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,KAAK,cAAc,GAAG,cAAc,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC,CAAC;AAEH,eAAO,MAAM,cAAc,EAAE,cAa5B,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,cAgBvC,CAAC"}
1
+ {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/resolvers/inputs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAuBrD,KAAK,cAAc,GAAG;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,CACL,GAAG,EAAE,GAAG,EACR,cAAc,EAAE;QACd,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,kBAAkB,CAAC;QAC/B,gBAAgB,EAAE,MAAM,CAAC;QACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAClC,KACE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;CAC/B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,cAa5B,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,cAcvC,CAAC"}
@@ -1,3 +1,24 @@
1
+ // Helper function to recursively make all input fields optional while preserving structure
2
+ function makeFieldsOptional(fields) {
3
+ return fields.map((field) => {
4
+ if (field.type === "input_field") {
5
+ return {
6
+ ...field,
7
+ is_required: false,
8
+ };
9
+ }
10
+ else if (field.type === "fieldset") {
11
+ return {
12
+ ...field,
13
+ fields: makeFieldsOptional(field.fields),
14
+ };
15
+ }
16
+ else {
17
+ // Info fields remain unchanged
18
+ return field;
19
+ }
20
+ });
21
+ }
1
22
  export const inputsResolver = {
2
23
  type: "fields",
3
24
  depends: ["appKey", "actionKey", "actionType", "authenticationId"],
@@ -23,9 +44,7 @@ export const inputsAllOptionalResolver = {
23
44
  authenticationId: resolvedParams.authenticationId,
24
45
  inputs: resolvedParams.inputs, // Pass along currently resolved inputs
25
46
  });
26
- return fieldsResponse.data.map((field) => ({
27
- ...field,
28
- is_required: false,
29
- }));
47
+ // Return nested structure with all fields marked as optional.
48
+ return makeFieldsOptional(fieldsResponse.data);
30
49
  },
31
50
  };
@@ -1,6 +1,18 @@
1
1
  import { z } from "zod";
2
+ export declare const BaseFieldItemSchema: z.ZodObject<{
3
+ type: z.ZodString;
4
+ key: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ type: string;
7
+ key: string;
8
+ }, {
9
+ type: string;
10
+ key: string;
11
+ }>;
2
12
  export declare const InputFieldItemSchema: z.ZodObject<{
3
13
  key: z.ZodString;
14
+ } & {
15
+ type: z.ZodLiteral<"input_field">;
4
16
  default_value: z.ZodString;
5
17
  depends_on: z.ZodArray<z.ZodString, "many">;
6
18
  description: z.ZodString;
@@ -18,6 +30,7 @@ export declare const InputFieldItemSchema: z.ZodObject<{
18
30
  type: string;
19
31
  }>>;
20
32
  }, "strip", z.ZodTypeAny, {
33
+ type: "input_field";
21
34
  key: string;
22
35
  depends_on: string[];
23
36
  placeholder: string;
@@ -32,6 +45,7 @@ export declare const InputFieldItemSchema: z.ZodObject<{
32
45
  type: string;
33
46
  } | undefined;
34
47
  }, {
48
+ type: "input_field";
35
49
  key: string;
36
50
  depends_on: string[];
37
51
  placeholder: string;
@@ -46,6 +60,100 @@ export declare const InputFieldItemSchema: z.ZodObject<{
46
60
  type: string;
47
61
  } | undefined;
48
62
  }>;
63
+ export declare const InfoFieldItemSchema: z.ZodObject<{
64
+ key: z.ZodString;
65
+ } & {
66
+ type: z.ZodLiteral<"info_field">;
67
+ description: z.ZodString;
68
+ title: z.ZodOptional<z.ZodString>;
69
+ }, "strip", z.ZodTypeAny, {
70
+ type: "info_field";
71
+ key: string;
72
+ description: string;
73
+ title?: string | undefined;
74
+ }, {
75
+ type: "info_field";
76
+ key: string;
77
+ description: string;
78
+ title?: string | undefined;
79
+ }>;
80
+ type FieldsetItemType = z.infer<typeof InputFieldItemSchema> | z.infer<typeof InfoFieldItemSchema> | FieldsetItem;
81
+ export interface FieldsetItem {
82
+ type: "fieldset";
83
+ key: string;
84
+ title: string;
85
+ fields: FieldsetItemType[];
86
+ }
87
+ export declare const FieldsetItemSchema: z.ZodType<FieldsetItem>;
88
+ export declare const RootFieldItemSchema: z.ZodUnion<[z.ZodObject<{
89
+ key: z.ZodString;
90
+ } & {
91
+ type: z.ZodLiteral<"input_field">;
92
+ default_value: z.ZodString;
93
+ depends_on: z.ZodArray<z.ZodString, "many">;
94
+ description: z.ZodString;
95
+ invalidates_input_fields: z.ZodBoolean;
96
+ is_required: z.ZodBoolean;
97
+ placeholder: z.ZodString;
98
+ title: z.ZodString;
99
+ value_type: z.ZodString;
100
+ format: z.ZodOptional<z.ZodString>;
101
+ items: z.ZodOptional<z.ZodObject<{
102
+ type: z.ZodString;
103
+ }, "strip", z.ZodTypeAny, {
104
+ type: string;
105
+ }, {
106
+ type: string;
107
+ }>>;
108
+ }, "strip", z.ZodTypeAny, {
109
+ type: "input_field";
110
+ key: string;
111
+ depends_on: string[];
112
+ placeholder: string;
113
+ description: string;
114
+ title: string;
115
+ default_value: string;
116
+ invalidates_input_fields: boolean;
117
+ is_required: boolean;
118
+ value_type: string;
119
+ format?: string | undefined;
120
+ items?: {
121
+ type: string;
122
+ } | undefined;
123
+ }, {
124
+ type: "input_field";
125
+ key: string;
126
+ depends_on: string[];
127
+ placeholder: string;
128
+ description: string;
129
+ title: string;
130
+ default_value: string;
131
+ invalidates_input_fields: boolean;
132
+ is_required: boolean;
133
+ value_type: string;
134
+ format?: string | undefined;
135
+ items?: {
136
+ type: string;
137
+ } | undefined;
138
+ }>, z.ZodObject<{
139
+ key: z.ZodString;
140
+ } & {
141
+ type: z.ZodLiteral<"info_field">;
142
+ description: z.ZodString;
143
+ title: z.ZodOptional<z.ZodString>;
144
+ }, "strip", z.ZodTypeAny, {
145
+ type: "info_field";
146
+ key: string;
147
+ description: string;
148
+ title?: string | undefined;
149
+ }, {
150
+ type: "info_field";
151
+ key: string;
152
+ description: string;
153
+ title?: string | undefined;
154
+ }>, z.ZodType<FieldsetItem, z.ZodTypeDef, FieldsetItem>]>;
49
155
  export type InputFieldItem = z.infer<typeof InputFieldItemSchema>;
50
- export type FieldItem = InputFieldItem;
156
+ export type InfoFieldItem = z.infer<typeof InfoFieldItemSchema>;
157
+ export type RootFieldItem = z.infer<typeof RootFieldItemSchema>;
158
+ export {};
51
159
  //# sourceMappingURL=Field.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/schemas/Field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkFhC,CAAC;AAMF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAGlE,MAAM,MAAM,SAAS,GAAG,cAAc,CAAC"}
1
+ {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/schemas/Field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,mBAAmB;;;;;;;;;EAG9B,CAAC;AAMH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkFhC,CAAC;AAMF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;EAc/B,CAAC;AAOF,KAAK,gBAAgB,GACjB,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,GACpC,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,GACnC,YAAY,CAAC;AAEjB,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,UAAU,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAED,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAanD,CAAC;AAML,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yDAI9B,CAAC;AAMH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
@@ -1,10 +1,17 @@
1
1
  import { z } from "zod";
2
2
  import { withFormatter } from "../utils/schema-utils";
3
3
  // ============================================================================
4
- // Input Field Item Schema (extends API Need schema with computed fields and formatting)
4
+ // Base Field Schema
5
5
  // ============================================================================
6
- export const InputFieldItemSchema = withFormatter(z.object({
6
+ export const BaseFieldItemSchema = z.object({
7
+ type: z.string(), // "input_field", "info_field", or "fieldset"
7
8
  key: z.string(), // From need.key
9
+ });
10
+ // ============================================================================
11
+ // Input Field Item Schema (extends API Need schema with computed fields and formatting)
12
+ // ============================================================================
13
+ export const InputFieldItemSchema = withFormatter(BaseFieldItemSchema.extend({
14
+ type: z.literal("input_field"),
8
15
  default_value: z.string(), // Mapped from 'default' with fallback to ""
9
16
  depends_on: z.array(z.string()), // Mapped from 'depends_on' with fallback to []
10
17
  description: z.string(), // Mapped from 'help_text' with fallback to ""
@@ -75,3 +82,35 @@ export const InputFieldItemSchema = withFormatter(z.object({
75
82
  };
76
83
  },
77
84
  });
85
+ // ============================================================================
86
+ // Info Field Item Schema (for help text and copy fields)
87
+ // ============================================================================
88
+ export const InfoFieldItemSchema = withFormatter(BaseFieldItemSchema.extend({
89
+ type: z.literal("info_field"),
90
+ description: z.string(), // From need.help_text
91
+ title: z.string().optional(), // Optional title
92
+ }), {
93
+ format: (item) => ({
94
+ title: item.title || "Info",
95
+ key: item.key,
96
+ description: item.description,
97
+ details: [{ text: item.description, style: "normal" }],
98
+ }),
99
+ });
100
+ export const FieldsetItemSchema = BaseFieldItemSchema.extend({
101
+ type: z.literal("fieldset"),
102
+ title: z.string(),
103
+ fields: z.lazy(() => z.array(z.union([
104
+ InputFieldItemSchema,
105
+ InfoFieldItemSchema,
106
+ FieldsetItemSchema,
107
+ ]))),
108
+ });
109
+ // ============================================================================
110
+ // Root Field Item Schema (union of all possible field types)
111
+ // ============================================================================
112
+ export const RootFieldItemSchema = z.union([
113
+ InputFieldItemSchema,
114
+ InfoFieldItemSchema,
115
+ FieldsetItemSchema,
116
+ ]);
@@ -6,8 +6,9 @@ import type { z } from "zod";
6
6
  import type { AppItemSchema } from "../schemas/App";
7
7
  import type { AuthenticationItemSchema } from "../schemas/Auth";
8
8
  import type { ActionItemSchema } from "../schemas/Action";
9
- import type { InputFieldItemSchema } from "../schemas/Field";
9
+ import type { InputFieldItemSchema, InfoFieldItemSchema, RootFieldItemSchema } from "../schemas/Field";
10
10
  import type { UserProfileItemSchema } from "../schemas/UserProfile";
11
+ import type { FieldsetItem } from "../schemas/Field";
11
12
  /**
12
13
  * Represents an app item returned by getApp and listApps functions
13
14
  * Inferred from AppItemSchema which extends the base App API schema
@@ -28,6 +29,21 @@ export type ActionItem = z.infer<typeof ActionItemSchema>;
28
29
  * Inferred from InputFieldItemSchema which extends the base Need API schema
29
30
  */
30
31
  export type InputFieldItem = z.infer<typeof InputFieldItemSchema>;
32
+ /**
33
+ * Represents an info field item (help text/copy) returned by listInputFields functions
34
+ * Inferred from InfoFieldItemSchema
35
+ */
36
+ export type InfoFieldItem = z.infer<typeof InfoFieldItemSchema>;
37
+ /**
38
+ * Represents a fieldset (group of fields) returned by listInputFields functions
39
+ * This is defined as an interface rather than inferred due to recursive nature
40
+ */
41
+ export type { FieldsetItem };
42
+ /**
43
+ * Represents a root field item (any field/fieldset type) returned by listInputFields
44
+ * Inferred from RootFieldItemSchema - use as RootFieldItem[]
45
+ */
46
+ export type RootFieldItem = z.infer<typeof RootFieldItemSchema>;
31
47
  /**
32
48
  * Represents a user profile item returned by getProfile function
33
49
  * Inferred from UserProfileItemSchema which extends the base UserProfile API schema
@@ -1 +1 @@
1
- {"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../src/types/domain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
1
+ {"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../src/types/domain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE;;;GAGG;AACH,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * String utility functions for the Zapier SDK
3
+ */
4
+ /**
5
+ * Converts a string to title case, handling various input formats:
6
+ * - camelCase: "firstName" → "First Name"
7
+ * - snake_case: "first_name" → "First Name"
8
+ * - kebab-case: "first-name" → "First Name"
9
+ * - mixed formats: "first_name-value" → "First Name Value"
10
+ */
11
+ export declare function toTitleCase(input: string): string;
12
+ //# sourceMappingURL=string-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-utils.d.ts","sourceRoot":"","sources":["../../src/utils/string-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAcjD"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * String utility functions for the Zapier SDK
3
+ */
4
+ /**
5
+ * Converts a string to title case, handling various input formats:
6
+ * - camelCase: "firstName" → "First Name"
7
+ * - snake_case: "first_name" → "First Name"
8
+ * - kebab-case: "first-name" → "First Name"
9
+ * - mixed formats: "first_name-value" → "First Name Value"
10
+ */
11
+ export function toTitleCase(input) {
12
+ return (input
13
+ // insert a space before capital letters (handles camelCase)
14
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
15
+ // replace delimiters (underscore, dash, multiple spaces) with single space
16
+ .replace(/[_\-]+/g, " ")
17
+ .replace(/\s+/g, " ")
18
+ .trim()
19
+ // split and capitalize each word
20
+ .split(" ")
21
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
22
+ .join(" "));
23
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=string-utils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-utils.test.d.ts","sourceRoot":"","sources":["../../src/utils/string-utils.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { toTitleCase } from "./string-utils";
3
+ describe("toTitleCase", () => {
4
+ it("converts snake_case to title case", () => {
5
+ expect(toTitleCase("first_name")).toBe("First Name");
6
+ expect(toTitleCase("sender_settings")).toBe("Sender Settings");
7
+ expect(toTitleCase("api_key_config")).toBe("Api Key Config");
8
+ });
9
+ it("converts camelCase to title case", () => {
10
+ expect(toTitleCase("firstName")).toBe("First Name");
11
+ expect(toTitleCase("senderSettings")).toBe("Sender Settings");
12
+ expect(toTitleCase("apiKeyConfig")).toBe("Api Key Config");
13
+ });
14
+ it("converts kebab-case to title case", () => {
15
+ expect(toTitleCase("first-name")).toBe("First Name");
16
+ expect(toTitleCase("sender-settings")).toBe("Sender Settings");
17
+ expect(toTitleCase("api-key-config")).toBe("Api Key Config");
18
+ });
19
+ it("handles mixed formats", () => {
20
+ expect(toTitleCase("first_name-value")).toBe("First Name Value");
21
+ expect(toTitleCase("sender_settings-config")).toBe("Sender Settings Config");
22
+ });
23
+ it("handles single words", () => {
24
+ expect(toTitleCase("name")).toBe("Name");
25
+ expect(toTitleCase("settings")).toBe("Settings");
26
+ });
27
+ it("handles multiple spaces and trims", () => {
28
+ expect(toTitleCase(" first name ")).toBe("First Name");
29
+ expect(toTitleCase("sender__settings")).toBe("Sender Settings");
30
+ });
31
+ it("handles empty and edge cases", () => {
32
+ expect(toTitleCase("")).toBe("");
33
+ expect(toTitleCase("a")).toBe("A");
34
+ expect(toTitleCase("_")).toBe("");
35
+ });
36
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "Complete Zapier SDK - combines all Zapier SDK packages",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",