@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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -5
- package/dist/index.cjs +130 -15
- package/dist/index.d.mts +121 -15
- package/dist/index.mjs +130 -15
- package/dist/plugins/listInputFields/index.d.ts +4 -4
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +61 -7
- package/dist/plugins/listInputFields/schemas.d.ts +3 -3
- package/dist/plugins/listInputFields/schemas.d.ts.map +1 -1
- package/dist/resolvers/inputFieldKey.d.ts.map +1 -1
- package/dist/resolvers/inputFieldKey.js +25 -1
- package/dist/resolvers/inputs.d.ts +12 -8
- package/dist/resolvers/inputs.d.ts.map +1 -1
- package/dist/resolvers/inputs.js +23 -4
- package/dist/schemas/Field.d.ts +109 -1
- package/dist/schemas/Field.d.ts.map +1 -1
- package/dist/schemas/Field.js +41 -2
- package/dist/types/domain.d.ts +17 -1
- package/dist/types/domain.d.ts.map +1 -1
- package/dist/utils/string-utils.d.ts +12 -0
- package/dist/utils/string-utils.d.ts.map +1 -0
- package/dist/utils/string-utils.js +23 -0
- package/dist/utils/string-utils.test.d.ts +2 -0
- package/dist/utils/string-utils.test.d.ts.map +1 -0
- package/dist/utils/string-utils.test.js +36 -0
- package/package.json +1 -1
- package/src/plugins/listInputFields/index.ts +73 -13
- package/src/plugins/listInputFields/schemas.ts +6 -3
- package/src/resolvers/inputFieldKey.ts +33 -1
- package/src/resolvers/inputs.ts +38 -12
- package/src/schemas/Field.ts +75 -5
- package/src/types/domain.ts +24 -1
- package/src/utils/string-utils.test.ts +45 -0
- package/src/utils/string-utils.ts +26 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @zapier/zapier-sdk
|
|
2
2
|
|
|
3
|
+
## 0.11.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0002fe9: Updated doc generation
|
|
8
|
+
|
|
9
|
+
## 0.11.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 12c6d3d: Return nested fields with fieldsets instead of flat fields. Also have CLI properly create line items from fieldsets for run-action.
|
|
14
|
+
|
|
3
15
|
## 0.10.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# @zapier/zapier-sdk
|
|
2
2
|
|
|
3
|
-
<!-- Generated API Reference -->
|
|
4
|
-
|
|
5
3
|
## Table of Contents
|
|
6
4
|
|
|
7
5
|
- [Installation](#installation)
|
|
@@ -170,7 +168,7 @@ Get the input fields required for a specific action
|
|
|
170
168
|
| `pageSize` | `number` | ❌ | — | — | Number of input fields per page |
|
|
171
169
|
| `maxItems` | `number` | ❌ | — | — | Maximum total items to return across all pages |
|
|
172
170
|
|
|
173
|
-
**Returns:** `Promise<PaginatedResult<
|
|
171
|
+
**Returns:** `Promise<PaginatedResult<RootFieldItemItem>>`
|
|
174
172
|
|
|
175
173
|
**Example:**
|
|
176
174
|
|
|
@@ -372,5 +370,3 @@ const result = await sdk.request({
|
|
|
372
370
|
url: "https://example.com",
|
|
373
371
|
});
|
|
374
372
|
```
|
|
375
|
-
|
|
376
|
-
<!-- End Generated API Reference -->
|
package/dist/index.cjs
CHANGED
|
@@ -1381,6 +1381,23 @@ var authenticationIdGenericResolver = {
|
|
|
1381
1381
|
};
|
|
1382
1382
|
|
|
1383
1383
|
// src/resolvers/inputs.ts
|
|
1384
|
+
function makeFieldsOptional(fields) {
|
|
1385
|
+
return fields.map((field) => {
|
|
1386
|
+
if (field.type === "input_field") {
|
|
1387
|
+
return {
|
|
1388
|
+
...field,
|
|
1389
|
+
is_required: false
|
|
1390
|
+
};
|
|
1391
|
+
} else if (field.type === "fieldset") {
|
|
1392
|
+
return {
|
|
1393
|
+
...field,
|
|
1394
|
+
fields: makeFieldsOptional(field.fields)
|
|
1395
|
+
};
|
|
1396
|
+
} else {
|
|
1397
|
+
return field;
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1384
1401
|
var inputsResolver = {
|
|
1385
1402
|
type: "fields",
|
|
1386
1403
|
depends: ["appKey", "actionKey", "actionType", "authenticationId"],
|
|
@@ -1408,14 +1425,27 @@ var inputsAllOptionalResolver = {
|
|
|
1408
1425
|
inputs: resolvedParams.inputs
|
|
1409
1426
|
// Pass along currently resolved inputs
|
|
1410
1427
|
});
|
|
1411
|
-
return fieldsResponse.data
|
|
1412
|
-
...field,
|
|
1413
|
-
is_required: false
|
|
1414
|
-
}));
|
|
1428
|
+
return makeFieldsOptional(fieldsResponse.data);
|
|
1415
1429
|
}
|
|
1416
1430
|
};
|
|
1417
1431
|
|
|
1418
1432
|
// src/resolvers/inputFieldKey.ts
|
|
1433
|
+
function flattenRootFieldset(rootFieldset) {
|
|
1434
|
+
const result = [];
|
|
1435
|
+
function processItem(item) {
|
|
1436
|
+
if (item.type === "input_field") {
|
|
1437
|
+
result.push(item);
|
|
1438
|
+
} else if (item.type === "fieldset") {
|
|
1439
|
+
for (const field of item.fields) {
|
|
1440
|
+
processItem(field);
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
for (const item of rootFieldset) {
|
|
1445
|
+
processItem(item);
|
|
1446
|
+
}
|
|
1447
|
+
return result;
|
|
1448
|
+
}
|
|
1419
1449
|
var inputFieldKeyResolver = {
|
|
1420
1450
|
type: "dynamic",
|
|
1421
1451
|
depends: ["appKey", "actionKey", "actionType", "authenticationId"],
|
|
@@ -1428,7 +1458,7 @@ var inputFieldKeyResolver = {
|
|
|
1428
1458
|
inputs: resolvedParams.inputs
|
|
1429
1459
|
// Pass along currently resolved inputs
|
|
1430
1460
|
});
|
|
1431
|
-
return fieldsResponse.data;
|
|
1461
|
+
return flattenRootFieldset(fieldsResponse.data);
|
|
1432
1462
|
},
|
|
1433
1463
|
prompt: (fields) => ({
|
|
1434
1464
|
type: "list",
|
|
@@ -1530,10 +1560,15 @@ var ListInputFieldsSchema = zod.z.object({
|
|
|
1530
1560
|
pageSize: zod.z.number().min(1).optional().describe("Number of input fields per page"),
|
|
1531
1561
|
maxItems: zod.z.number().min(1).optional().describe("Maximum total items to return across all pages")
|
|
1532
1562
|
}).describe("Get the input fields required for a specific action");
|
|
1563
|
+
var BaseFieldItemSchema = zod.z.object({
|
|
1564
|
+
type: zod.z.string(),
|
|
1565
|
+
// "input_field", "info_field", or "fieldset"
|
|
1566
|
+
key: zod.z.string()
|
|
1567
|
+
// From need.key
|
|
1568
|
+
});
|
|
1533
1569
|
var InputFieldItemSchema = withFormatter(
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
// From need.key
|
|
1570
|
+
BaseFieldItemSchema.extend({
|
|
1571
|
+
type: zod.z.literal("input_field"),
|
|
1537
1572
|
default_value: zod.z.string(),
|
|
1538
1573
|
// Mapped from 'default' with fallback to ""
|
|
1539
1574
|
depends_on: zod.z.array(zod.z.string()),
|
|
@@ -1607,6 +1642,46 @@ var InputFieldItemSchema = withFormatter(
|
|
|
1607
1642
|
}
|
|
1608
1643
|
}
|
|
1609
1644
|
);
|
|
1645
|
+
var InfoFieldItemSchema = withFormatter(
|
|
1646
|
+
BaseFieldItemSchema.extend({
|
|
1647
|
+
type: zod.z.literal("info_field"),
|
|
1648
|
+
description: zod.z.string(),
|
|
1649
|
+
// From need.help_text
|
|
1650
|
+
title: zod.z.string().optional()
|
|
1651
|
+
// Optional title
|
|
1652
|
+
}),
|
|
1653
|
+
{
|
|
1654
|
+
format: (item) => ({
|
|
1655
|
+
title: item.title || "Info",
|
|
1656
|
+
key: item.key,
|
|
1657
|
+
description: item.description,
|
|
1658
|
+
details: [{ text: item.description, style: "normal" }]
|
|
1659
|
+
})
|
|
1660
|
+
}
|
|
1661
|
+
);
|
|
1662
|
+
var FieldsetItemSchema = BaseFieldItemSchema.extend({
|
|
1663
|
+
type: zod.z.literal("fieldset"),
|
|
1664
|
+
title: zod.z.string(),
|
|
1665
|
+
fields: zod.z.lazy(
|
|
1666
|
+
() => zod.z.array(
|
|
1667
|
+
zod.z.union([
|
|
1668
|
+
InputFieldItemSchema,
|
|
1669
|
+
InfoFieldItemSchema,
|
|
1670
|
+
FieldsetItemSchema
|
|
1671
|
+
])
|
|
1672
|
+
)
|
|
1673
|
+
)
|
|
1674
|
+
});
|
|
1675
|
+
var RootFieldItemSchema = zod.z.union([
|
|
1676
|
+
InputFieldItemSchema,
|
|
1677
|
+
InfoFieldItemSchema,
|
|
1678
|
+
FieldsetItemSchema
|
|
1679
|
+
]);
|
|
1680
|
+
|
|
1681
|
+
// src/utils/string-utils.ts
|
|
1682
|
+
function toTitleCase(input) {
|
|
1683
|
+
return input.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_\-]+/g, " ").replace(/\s+/g, " ").trim().split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
1684
|
+
}
|
|
1610
1685
|
|
|
1611
1686
|
// src/plugins/listInputFields/index.ts
|
|
1612
1687
|
function getInputFieldTypeFromNeed(need) {
|
|
@@ -1651,7 +1726,7 @@ function getItemsTypeFromNeed(need) {
|
|
|
1651
1726
|
function transformNeedToInputFieldItem(need) {
|
|
1652
1727
|
const itemsType = getItemsTypeFromNeed(need);
|
|
1653
1728
|
return {
|
|
1654
|
-
|
|
1729
|
+
type: "input_field",
|
|
1655
1730
|
key: need.key,
|
|
1656
1731
|
default_value: need.default || "",
|
|
1657
1732
|
depends_on: need.depends_on || [],
|
|
@@ -1665,6 +1740,48 @@ function transformNeedToInputFieldItem(need) {
|
|
|
1665
1740
|
items: itemsType ? { type: itemsType } : void 0
|
|
1666
1741
|
};
|
|
1667
1742
|
}
|
|
1743
|
+
function transformNeedToInfoFieldItem(need) {
|
|
1744
|
+
return {
|
|
1745
|
+
type: "info_field",
|
|
1746
|
+
key: need.key,
|
|
1747
|
+
description: need.help_text || "",
|
|
1748
|
+
title: need.label
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
function transformNeedsToFields(needs) {
|
|
1752
|
+
const rootFields = [];
|
|
1753
|
+
const fieldsetMap = /* @__PURE__ */ new Map();
|
|
1754
|
+
for (const need of needs) {
|
|
1755
|
+
if (need.computed) {
|
|
1756
|
+
continue;
|
|
1757
|
+
}
|
|
1758
|
+
if (need.parent_key) {
|
|
1759
|
+
let fieldset = fieldsetMap.get(need.parent_key);
|
|
1760
|
+
if (!fieldset) {
|
|
1761
|
+
fieldset = {
|
|
1762
|
+
type: "fieldset",
|
|
1763
|
+
key: need.parent_key,
|
|
1764
|
+
title: toTitleCase(need.parent_key),
|
|
1765
|
+
fields: []
|
|
1766
|
+
};
|
|
1767
|
+
fieldsetMap.set(need.parent_key, fieldset);
|
|
1768
|
+
rootFields.push(fieldset);
|
|
1769
|
+
}
|
|
1770
|
+
if (need.type === "copy" && need.help_text) {
|
|
1771
|
+
fieldset.fields.push(transformNeedToInfoFieldItem(need));
|
|
1772
|
+
} else {
|
|
1773
|
+
fieldset.fields.push(transformNeedToInputFieldItem(need));
|
|
1774
|
+
}
|
|
1775
|
+
} else {
|
|
1776
|
+
if (need.type === "copy" && need.help_text) {
|
|
1777
|
+
rootFields.push(transformNeedToInfoFieldItem(need));
|
|
1778
|
+
} else {
|
|
1779
|
+
rootFields.push(transformNeedToInputFieldItem(need));
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
return rootFields;
|
|
1784
|
+
}
|
|
1668
1785
|
var listInputFieldsPlugin = ({ context }) => {
|
|
1669
1786
|
const listInputFields = createPaginatedFunction(
|
|
1670
1787
|
async function listInputFieldsPage(options) {
|
|
@@ -1695,11 +1812,9 @@ var listInputFieldsPlugin = ({ context }) => {
|
|
|
1695
1812
|
`Failed to get action fields: ${needsData.errors?.join(", ") || "Unknown error"}`
|
|
1696
1813
|
);
|
|
1697
1814
|
}
|
|
1698
|
-
const
|
|
1699
|
-
transformNeedToInputFieldItem
|
|
1700
|
-
);
|
|
1815
|
+
const rootFieldset = transformNeedsToFields(needsData.needs || []);
|
|
1701
1816
|
return {
|
|
1702
|
-
data:
|
|
1817
|
+
data: rootFieldset,
|
|
1703
1818
|
nextCursor: void 0
|
|
1704
1819
|
// No pagination needed since we return all input fields
|
|
1705
1820
|
};
|
|
@@ -1713,9 +1828,9 @@ var listInputFieldsPlugin = ({ context }) => {
|
|
|
1713
1828
|
listInputFields: {
|
|
1714
1829
|
categories: ["action"],
|
|
1715
1830
|
type: "list",
|
|
1716
|
-
itemType: "
|
|
1831
|
+
itemType: "RootFieldItem",
|
|
1717
1832
|
inputSchema: ListInputFieldsSchema,
|
|
1718
|
-
outputSchema:
|
|
1833
|
+
outputSchema: RootFieldItemSchema,
|
|
1719
1834
|
resolvers: {
|
|
1720
1835
|
appKey: appKeyResolver,
|
|
1721
1836
|
actionType: actionTypeResolver,
|
package/dist/index.d.mts
CHANGED
|
@@ -2079,12 +2079,12 @@ FindUniqueAuthenticationPluginProvides>;
|
|
|
2079
2079
|
|
|
2080
2080
|
interface ListInputFieldsPluginProvides {
|
|
2081
2081
|
listInputFields: (options?: ListInputFieldsOptions) => Promise<{
|
|
2082
|
-
data:
|
|
2082
|
+
data: RootFieldItem[];
|
|
2083
2083
|
}> & AsyncIterable<{
|
|
2084
|
-
data:
|
|
2084
|
+
data: RootFieldItem[];
|
|
2085
2085
|
nextCursor?: string;
|
|
2086
2086
|
}> & {
|
|
2087
|
-
items(): AsyncIterable<InputFieldItem>;
|
|
2087
|
+
items(): AsyncIterable<InputFieldItem | InfoFieldItem | FieldsetItem>;
|
|
2088
2088
|
};
|
|
2089
2089
|
context: {
|
|
2090
2090
|
meta: {
|
|
@@ -2209,6 +2209,8 @@ interface ZapierSdk extends GetSdkType<RegistryPluginProvides & FetchPluginProvi
|
|
|
2209
2209
|
|
|
2210
2210
|
declare const InputFieldItemSchema: z.ZodObject<{
|
|
2211
2211
|
key: z.ZodString;
|
|
2212
|
+
} & {
|
|
2213
|
+
type: z.ZodLiteral<"input_field">;
|
|
2212
2214
|
default_value: z.ZodString;
|
|
2213
2215
|
depends_on: z.ZodArray<z.ZodString, "many">;
|
|
2214
2216
|
description: z.ZodString;
|
|
@@ -2226,6 +2228,7 @@ declare const InputFieldItemSchema: z.ZodObject<{
|
|
|
2226
2228
|
type: string;
|
|
2227
2229
|
}>>;
|
|
2228
2230
|
}, "strip", z.ZodTypeAny, {
|
|
2231
|
+
type: "input_field";
|
|
2229
2232
|
key: string;
|
|
2230
2233
|
depends_on: string[];
|
|
2231
2234
|
placeholder: string;
|
|
@@ -2240,6 +2243,7 @@ declare const InputFieldItemSchema: z.ZodObject<{
|
|
|
2240
2243
|
type: string;
|
|
2241
2244
|
} | undefined;
|
|
2242
2245
|
}, {
|
|
2246
|
+
type: "input_field";
|
|
2243
2247
|
key: string;
|
|
2244
2248
|
depends_on: string[];
|
|
2245
2249
|
placeholder: string;
|
|
@@ -2254,6 +2258,97 @@ declare const InputFieldItemSchema: z.ZodObject<{
|
|
|
2254
2258
|
type: string;
|
|
2255
2259
|
} | undefined;
|
|
2256
2260
|
}>;
|
|
2261
|
+
declare const InfoFieldItemSchema: z.ZodObject<{
|
|
2262
|
+
key: z.ZodString;
|
|
2263
|
+
} & {
|
|
2264
|
+
type: z.ZodLiteral<"info_field">;
|
|
2265
|
+
description: z.ZodString;
|
|
2266
|
+
title: z.ZodOptional<z.ZodString>;
|
|
2267
|
+
}, "strip", z.ZodTypeAny, {
|
|
2268
|
+
type: "info_field";
|
|
2269
|
+
key: string;
|
|
2270
|
+
description: string;
|
|
2271
|
+
title?: string | undefined;
|
|
2272
|
+
}, {
|
|
2273
|
+
type: "info_field";
|
|
2274
|
+
key: string;
|
|
2275
|
+
description: string;
|
|
2276
|
+
title?: string | undefined;
|
|
2277
|
+
}>;
|
|
2278
|
+
type FieldsetItemType = z.infer<typeof InputFieldItemSchema> | z.infer<typeof InfoFieldItemSchema> | FieldsetItem;
|
|
2279
|
+
interface FieldsetItem {
|
|
2280
|
+
type: "fieldset";
|
|
2281
|
+
key: string;
|
|
2282
|
+
title: string;
|
|
2283
|
+
fields: FieldsetItemType[];
|
|
2284
|
+
}
|
|
2285
|
+
declare const RootFieldItemSchema: z.ZodUnion<[z.ZodObject<{
|
|
2286
|
+
key: z.ZodString;
|
|
2287
|
+
} & {
|
|
2288
|
+
type: z.ZodLiteral<"input_field">;
|
|
2289
|
+
default_value: z.ZodString;
|
|
2290
|
+
depends_on: z.ZodArray<z.ZodString, "many">;
|
|
2291
|
+
description: z.ZodString;
|
|
2292
|
+
invalidates_input_fields: z.ZodBoolean;
|
|
2293
|
+
is_required: z.ZodBoolean;
|
|
2294
|
+
placeholder: z.ZodString;
|
|
2295
|
+
title: z.ZodString;
|
|
2296
|
+
value_type: z.ZodString;
|
|
2297
|
+
format: z.ZodOptional<z.ZodString>;
|
|
2298
|
+
items: z.ZodOptional<z.ZodObject<{
|
|
2299
|
+
type: z.ZodString;
|
|
2300
|
+
}, "strip", z.ZodTypeAny, {
|
|
2301
|
+
type: string;
|
|
2302
|
+
}, {
|
|
2303
|
+
type: string;
|
|
2304
|
+
}>>;
|
|
2305
|
+
}, "strip", z.ZodTypeAny, {
|
|
2306
|
+
type: "input_field";
|
|
2307
|
+
key: string;
|
|
2308
|
+
depends_on: string[];
|
|
2309
|
+
placeholder: string;
|
|
2310
|
+
description: string;
|
|
2311
|
+
title: string;
|
|
2312
|
+
default_value: string;
|
|
2313
|
+
invalidates_input_fields: boolean;
|
|
2314
|
+
is_required: boolean;
|
|
2315
|
+
value_type: string;
|
|
2316
|
+
format?: string | undefined;
|
|
2317
|
+
items?: {
|
|
2318
|
+
type: string;
|
|
2319
|
+
} | undefined;
|
|
2320
|
+
}, {
|
|
2321
|
+
type: "input_field";
|
|
2322
|
+
key: string;
|
|
2323
|
+
depends_on: string[];
|
|
2324
|
+
placeholder: string;
|
|
2325
|
+
description: string;
|
|
2326
|
+
title: string;
|
|
2327
|
+
default_value: string;
|
|
2328
|
+
invalidates_input_fields: boolean;
|
|
2329
|
+
is_required: boolean;
|
|
2330
|
+
value_type: string;
|
|
2331
|
+
format?: string | undefined;
|
|
2332
|
+
items?: {
|
|
2333
|
+
type: string;
|
|
2334
|
+
} | undefined;
|
|
2335
|
+
}>, z.ZodObject<{
|
|
2336
|
+
key: z.ZodString;
|
|
2337
|
+
} & {
|
|
2338
|
+
type: z.ZodLiteral<"info_field">;
|
|
2339
|
+
description: z.ZodString;
|
|
2340
|
+
title: z.ZodOptional<z.ZodString>;
|
|
2341
|
+
}, "strip", z.ZodTypeAny, {
|
|
2342
|
+
type: "info_field";
|
|
2343
|
+
key: string;
|
|
2344
|
+
description: string;
|
|
2345
|
+
title?: string | undefined;
|
|
2346
|
+
}, {
|
|
2347
|
+
type: "info_field";
|
|
2348
|
+
key: string;
|
|
2349
|
+
description: string;
|
|
2350
|
+
title?: string | undefined;
|
|
2351
|
+
}>, z.ZodType<FieldsetItem, z.ZodTypeDef, FieldsetItem>]>;
|
|
2257
2352
|
type InputFieldItem$1 = z.infer<typeof InputFieldItemSchema>;
|
|
2258
2353
|
|
|
2259
2354
|
interface PromptConfig {
|
|
@@ -2279,10 +2374,6 @@ interface DynamicResolver<TItem = unknown, TParams = Record<string, unknown>> ex
|
|
|
2279
2374
|
fetch: (sdk: ZapierSdk, resolvedParams: TParams) => Promise<TItem[]>;
|
|
2280
2375
|
prompt: (items: TItem[], params: TParams) => PromptConfig;
|
|
2281
2376
|
}
|
|
2282
|
-
interface FieldsResolver<TParams = Record<string, unknown>> extends Resolver {
|
|
2283
|
-
type: "fields";
|
|
2284
|
-
fetch: (sdk: ZapierSdk, resolvedParams: TParams) => Promise<InputFieldItem$1[]>;
|
|
2285
|
-
}
|
|
2286
2377
|
interface PositionalMetadata {
|
|
2287
2378
|
positionalMeta: {
|
|
2288
2379
|
positional: true;
|
|
@@ -3066,6 +3157,17 @@ type ActionItem$1 = z.infer<typeof ActionItemSchema>;
|
|
|
3066
3157
|
* Inferred from InputFieldItemSchema which extends the base Need API schema
|
|
3067
3158
|
*/
|
|
3068
3159
|
type InputFieldItem = z.infer<typeof InputFieldItemSchema>;
|
|
3160
|
+
/**
|
|
3161
|
+
* Represents an info field item (help text/copy) returned by listInputFields functions
|
|
3162
|
+
* Inferred from InfoFieldItemSchema
|
|
3163
|
+
*/
|
|
3164
|
+
type InfoFieldItem = z.infer<typeof InfoFieldItemSchema>;
|
|
3165
|
+
|
|
3166
|
+
/**
|
|
3167
|
+
* Represents a root field item (any field/fieldset type) returned by listInputFields
|
|
3168
|
+
* Inferred from RootFieldItemSchema - use as RootFieldItem[]
|
|
3169
|
+
*/
|
|
3170
|
+
type RootFieldItem = z.infer<typeof RootFieldItemSchema>;
|
|
3069
3171
|
/**
|
|
3070
3172
|
* Represents a user profile item returned by getProfile function
|
|
3071
3173
|
* Inferred from UserProfileItemSchema which extends the base UserProfile API schema
|
|
@@ -3136,13 +3238,17 @@ type AuthenticationIdResolver = DynamicResolver<AuthItem, {
|
|
|
3136
3238
|
declare const authenticationIdResolver: AuthenticationIdResolver;
|
|
3137
3239
|
declare const authenticationIdGenericResolver: AuthenticationIdResolver;
|
|
3138
3240
|
|
|
3139
|
-
type InputsResolver =
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3241
|
+
type InputsResolver = {
|
|
3242
|
+
type: "fields";
|
|
3243
|
+
depends: readonly string[];
|
|
3244
|
+
fetch: (sdk: any, resolvedParams: {
|
|
3245
|
+
appKey: string;
|
|
3246
|
+
actionKey: string;
|
|
3247
|
+
actionType: ActionTypeProperty;
|
|
3248
|
+
authenticationId: number;
|
|
3249
|
+
inputs?: Record<string, unknown>;
|
|
3250
|
+
}) => Promise<RootFieldItem[]>;
|
|
3251
|
+
};
|
|
3146
3252
|
declare const inputsResolver: InputsResolver;
|
|
3147
3253
|
declare const inputsAllOptionalResolver: InputsResolver;
|
|
3148
3254
|
|
|
@@ -3288,4 +3394,4 @@ declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOptions): Sdk
|
|
|
3288
3394
|
}>;
|
|
3289
3395
|
declare function createZapierSdk(options?: ZapierSdkOptions): ZapierSdk;
|
|
3290
3396
|
|
|
3291
|
-
export { type Action, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type AppsPluginProvides, type AuthEvent, type AuthOptions, type Authentication, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type AuthenticationItem, type AuthenticationsResponse, type Choice, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, type ErrorOptions, type EventCallback, type FetchPluginProvides, type Field, type FindFirstAuthenticationPluginProvides, type FindUniqueAuthenticationPluginProvides, type FunctionOptions, type FunctionRegistryEntry, type GetActionPluginProvides, type GetAppPluginProvides, type GetAuthenticationPluginProvides, type GetContextType, type GetProfilePluginProvides, type GetSdkType, type InputFieldItem, type InputsProperty, InputsPropertySchema, type LimitProperty, LimitPropertySchema, type ListActionsPluginProvides, type ListAppsPluginProvides, type ListAuthenticationsPluginProvides, type ListInputFieldsPluginProvides, type LoadingEvent, type ManifestPluginOptions, type ManifestPluginProvides, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type RunActionPluginProvides, type Sdk, type SdkEvent, type UserProfile, type UserProfileItem, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, type ZapierFetchInitOptions, ZapierNotFoundError, ZapierResourceNotFoundError, type ZapierSdk, type ZapierSdkApps, type ZapierSdkOptions, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdGenericResolver, authenticationIdResolver, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getPreferredManifestEntryKey, getProfilePlugin, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listInputFieldsPlugin, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, runActionPlugin };
|
|
3397
|
+
export { type Action, type ActionExecutionOptions, type ActionExecutionResult, type ActionField, type ActionFieldChoice, type ActionItem$1 as ActionItem, type ActionKeyProperty, ActionKeyPropertySchema, type ActionTypeProperty, ActionTypePropertySchema, type ApiError, type ApiEvent, type ApiPluginOptions, type ApiPluginProvides, type App, type AppItem, type AppKeyProperty, AppKeyPropertySchema, type AppsPluginProvides, type AuthEvent, type AuthOptions, type Authentication, type AuthenticationIdProperty, AuthenticationIdPropertySchema, type AuthenticationItem, type AuthenticationsResponse, type Choice, DEFAULT_CONFIG_PATH, type DebugProperty, DebugPropertySchema, type ErrorOptions, type EventCallback, type FetchPluginProvides, type Field, type FieldsetItem, type FindFirstAuthenticationPluginProvides, type FindUniqueAuthenticationPluginProvides, type FunctionOptions, type FunctionRegistryEntry, type GetActionPluginProvides, type GetAppPluginProvides, type GetAuthenticationPluginProvides, type GetContextType, type GetProfilePluginProvides, type GetSdkType, type InfoFieldItem, type InputFieldItem, type InputsProperty, InputsPropertySchema, type LimitProperty, LimitPropertySchema, type ListActionsPluginProvides, type ListAppsPluginProvides, type ListAuthenticationsPluginProvides, type ListInputFieldsPluginProvides, type LoadingEvent, type ManifestPluginOptions, type ManifestPluginProvides, type Need, type NeedsRequest, type NeedsResponse, type OffsetProperty, OffsetPropertySchema, type OutputProperty, OutputPropertySchema, type PaginatedSdkFunction, type ParamsProperty, ParamsPropertySchema, type Plugin, type PluginDependencies, type PluginOptions, type PluginProvides, type PositionalMetadata, RelayFetchSchema, RelayRequestSchema, type RequestPluginProvides, type RootFieldItem, type RunActionPluginProvides, type Sdk, type SdkEvent, type UserProfile, type UserProfileItem, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, type ZapierFetchInitOptions, ZapierNotFoundError, ZapierResourceNotFoundError, type ZapierSdk, type ZapierSdkApps, type ZapierSdkOptions, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdGenericResolver, authenticationIdResolver, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getPreferredManifestEntryKey, getProfilePlugin, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listInputFieldsPlugin, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, runActionPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -1379,6 +1379,23 @@ var authenticationIdGenericResolver = {
|
|
|
1379
1379
|
};
|
|
1380
1380
|
|
|
1381
1381
|
// src/resolvers/inputs.ts
|
|
1382
|
+
function makeFieldsOptional(fields) {
|
|
1383
|
+
return fields.map((field) => {
|
|
1384
|
+
if (field.type === "input_field") {
|
|
1385
|
+
return {
|
|
1386
|
+
...field,
|
|
1387
|
+
is_required: false
|
|
1388
|
+
};
|
|
1389
|
+
} else if (field.type === "fieldset") {
|
|
1390
|
+
return {
|
|
1391
|
+
...field,
|
|
1392
|
+
fields: makeFieldsOptional(field.fields)
|
|
1393
|
+
};
|
|
1394
|
+
} else {
|
|
1395
|
+
return field;
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1382
1399
|
var inputsResolver = {
|
|
1383
1400
|
type: "fields",
|
|
1384
1401
|
depends: ["appKey", "actionKey", "actionType", "authenticationId"],
|
|
@@ -1406,14 +1423,27 @@ var inputsAllOptionalResolver = {
|
|
|
1406
1423
|
inputs: resolvedParams.inputs
|
|
1407
1424
|
// Pass along currently resolved inputs
|
|
1408
1425
|
});
|
|
1409
|
-
return fieldsResponse.data
|
|
1410
|
-
...field,
|
|
1411
|
-
is_required: false
|
|
1412
|
-
}));
|
|
1426
|
+
return makeFieldsOptional(fieldsResponse.data);
|
|
1413
1427
|
}
|
|
1414
1428
|
};
|
|
1415
1429
|
|
|
1416
1430
|
// src/resolvers/inputFieldKey.ts
|
|
1431
|
+
function flattenRootFieldset(rootFieldset) {
|
|
1432
|
+
const result = [];
|
|
1433
|
+
function processItem(item) {
|
|
1434
|
+
if (item.type === "input_field") {
|
|
1435
|
+
result.push(item);
|
|
1436
|
+
} else if (item.type === "fieldset") {
|
|
1437
|
+
for (const field of item.fields) {
|
|
1438
|
+
processItem(field);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
for (const item of rootFieldset) {
|
|
1443
|
+
processItem(item);
|
|
1444
|
+
}
|
|
1445
|
+
return result;
|
|
1446
|
+
}
|
|
1417
1447
|
var inputFieldKeyResolver = {
|
|
1418
1448
|
type: "dynamic",
|
|
1419
1449
|
depends: ["appKey", "actionKey", "actionType", "authenticationId"],
|
|
@@ -1426,7 +1456,7 @@ var inputFieldKeyResolver = {
|
|
|
1426
1456
|
inputs: resolvedParams.inputs
|
|
1427
1457
|
// Pass along currently resolved inputs
|
|
1428
1458
|
});
|
|
1429
|
-
return fieldsResponse.data;
|
|
1459
|
+
return flattenRootFieldset(fieldsResponse.data);
|
|
1430
1460
|
},
|
|
1431
1461
|
prompt: (fields) => ({
|
|
1432
1462
|
type: "list",
|
|
@@ -1528,10 +1558,15 @@ var ListInputFieldsSchema = z.object({
|
|
|
1528
1558
|
pageSize: z.number().min(1).optional().describe("Number of input fields per page"),
|
|
1529
1559
|
maxItems: z.number().min(1).optional().describe("Maximum total items to return across all pages")
|
|
1530
1560
|
}).describe("Get the input fields required for a specific action");
|
|
1561
|
+
var BaseFieldItemSchema = z.object({
|
|
1562
|
+
type: z.string(),
|
|
1563
|
+
// "input_field", "info_field", or "fieldset"
|
|
1564
|
+
key: z.string()
|
|
1565
|
+
// From need.key
|
|
1566
|
+
});
|
|
1531
1567
|
var InputFieldItemSchema = withFormatter(
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
// From need.key
|
|
1568
|
+
BaseFieldItemSchema.extend({
|
|
1569
|
+
type: z.literal("input_field"),
|
|
1535
1570
|
default_value: z.string(),
|
|
1536
1571
|
// Mapped from 'default' with fallback to ""
|
|
1537
1572
|
depends_on: z.array(z.string()),
|
|
@@ -1605,6 +1640,46 @@ var InputFieldItemSchema = withFormatter(
|
|
|
1605
1640
|
}
|
|
1606
1641
|
}
|
|
1607
1642
|
);
|
|
1643
|
+
var InfoFieldItemSchema = withFormatter(
|
|
1644
|
+
BaseFieldItemSchema.extend({
|
|
1645
|
+
type: z.literal("info_field"),
|
|
1646
|
+
description: z.string(),
|
|
1647
|
+
// From need.help_text
|
|
1648
|
+
title: z.string().optional()
|
|
1649
|
+
// Optional title
|
|
1650
|
+
}),
|
|
1651
|
+
{
|
|
1652
|
+
format: (item) => ({
|
|
1653
|
+
title: item.title || "Info",
|
|
1654
|
+
key: item.key,
|
|
1655
|
+
description: item.description,
|
|
1656
|
+
details: [{ text: item.description, style: "normal" }]
|
|
1657
|
+
})
|
|
1658
|
+
}
|
|
1659
|
+
);
|
|
1660
|
+
var FieldsetItemSchema = BaseFieldItemSchema.extend({
|
|
1661
|
+
type: z.literal("fieldset"),
|
|
1662
|
+
title: z.string(),
|
|
1663
|
+
fields: z.lazy(
|
|
1664
|
+
() => z.array(
|
|
1665
|
+
z.union([
|
|
1666
|
+
InputFieldItemSchema,
|
|
1667
|
+
InfoFieldItemSchema,
|
|
1668
|
+
FieldsetItemSchema
|
|
1669
|
+
])
|
|
1670
|
+
)
|
|
1671
|
+
)
|
|
1672
|
+
});
|
|
1673
|
+
var RootFieldItemSchema = z.union([
|
|
1674
|
+
InputFieldItemSchema,
|
|
1675
|
+
InfoFieldItemSchema,
|
|
1676
|
+
FieldsetItemSchema
|
|
1677
|
+
]);
|
|
1678
|
+
|
|
1679
|
+
// src/utils/string-utils.ts
|
|
1680
|
+
function toTitleCase(input) {
|
|
1681
|
+
return input.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_\-]+/g, " ").replace(/\s+/g, " ").trim().split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
1682
|
+
}
|
|
1608
1683
|
|
|
1609
1684
|
// src/plugins/listInputFields/index.ts
|
|
1610
1685
|
function getInputFieldTypeFromNeed(need) {
|
|
@@ -1649,7 +1724,7 @@ function getItemsTypeFromNeed(need) {
|
|
|
1649
1724
|
function transformNeedToInputFieldItem(need) {
|
|
1650
1725
|
const itemsType = getItemsTypeFromNeed(need);
|
|
1651
1726
|
return {
|
|
1652
|
-
|
|
1727
|
+
type: "input_field",
|
|
1653
1728
|
key: need.key,
|
|
1654
1729
|
default_value: need.default || "",
|
|
1655
1730
|
depends_on: need.depends_on || [],
|
|
@@ -1663,6 +1738,48 @@ function transformNeedToInputFieldItem(need) {
|
|
|
1663
1738
|
items: itemsType ? { type: itemsType } : void 0
|
|
1664
1739
|
};
|
|
1665
1740
|
}
|
|
1741
|
+
function transformNeedToInfoFieldItem(need) {
|
|
1742
|
+
return {
|
|
1743
|
+
type: "info_field",
|
|
1744
|
+
key: need.key,
|
|
1745
|
+
description: need.help_text || "",
|
|
1746
|
+
title: need.label
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
function transformNeedsToFields(needs) {
|
|
1750
|
+
const rootFields = [];
|
|
1751
|
+
const fieldsetMap = /* @__PURE__ */ new Map();
|
|
1752
|
+
for (const need of needs) {
|
|
1753
|
+
if (need.computed) {
|
|
1754
|
+
continue;
|
|
1755
|
+
}
|
|
1756
|
+
if (need.parent_key) {
|
|
1757
|
+
let fieldset = fieldsetMap.get(need.parent_key);
|
|
1758
|
+
if (!fieldset) {
|
|
1759
|
+
fieldset = {
|
|
1760
|
+
type: "fieldset",
|
|
1761
|
+
key: need.parent_key,
|
|
1762
|
+
title: toTitleCase(need.parent_key),
|
|
1763
|
+
fields: []
|
|
1764
|
+
};
|
|
1765
|
+
fieldsetMap.set(need.parent_key, fieldset);
|
|
1766
|
+
rootFields.push(fieldset);
|
|
1767
|
+
}
|
|
1768
|
+
if (need.type === "copy" && need.help_text) {
|
|
1769
|
+
fieldset.fields.push(transformNeedToInfoFieldItem(need));
|
|
1770
|
+
} else {
|
|
1771
|
+
fieldset.fields.push(transformNeedToInputFieldItem(need));
|
|
1772
|
+
}
|
|
1773
|
+
} else {
|
|
1774
|
+
if (need.type === "copy" && need.help_text) {
|
|
1775
|
+
rootFields.push(transformNeedToInfoFieldItem(need));
|
|
1776
|
+
} else {
|
|
1777
|
+
rootFields.push(transformNeedToInputFieldItem(need));
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
return rootFields;
|
|
1782
|
+
}
|
|
1666
1783
|
var listInputFieldsPlugin = ({ context }) => {
|
|
1667
1784
|
const listInputFields = createPaginatedFunction(
|
|
1668
1785
|
async function listInputFieldsPage(options) {
|
|
@@ -1693,11 +1810,9 @@ var listInputFieldsPlugin = ({ context }) => {
|
|
|
1693
1810
|
`Failed to get action fields: ${needsData.errors?.join(", ") || "Unknown error"}`
|
|
1694
1811
|
);
|
|
1695
1812
|
}
|
|
1696
|
-
const
|
|
1697
|
-
transformNeedToInputFieldItem
|
|
1698
|
-
);
|
|
1813
|
+
const rootFieldset = transformNeedsToFields(needsData.needs || []);
|
|
1699
1814
|
return {
|
|
1700
|
-
data:
|
|
1815
|
+
data: rootFieldset,
|
|
1701
1816
|
nextCursor: void 0
|
|
1702
1817
|
// No pagination needed since we return all input fields
|
|
1703
1818
|
};
|
|
@@ -1711,9 +1826,9 @@ var listInputFieldsPlugin = ({ context }) => {
|
|
|
1711
1826
|
listInputFields: {
|
|
1712
1827
|
categories: ["action"],
|
|
1713
1828
|
type: "list",
|
|
1714
|
-
itemType: "
|
|
1829
|
+
itemType: "RootFieldItem",
|
|
1715
1830
|
inputSchema: ListInputFieldsSchema,
|
|
1716
|
-
outputSchema:
|
|
1831
|
+
outputSchema: RootFieldItemSchema,
|
|
1717
1832
|
resolvers: {
|
|
1718
1833
|
appKey: appKeyResolver,
|
|
1719
1834
|
actionType: actionTypeResolver,
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Plugin, GetSdkType } from "../../types/plugin";
|
|
2
2
|
import type { ApiClient } from "../../api";
|
|
3
|
-
import type { InputFieldItem } from "../../types/domain";
|
|
3
|
+
import type { InputFieldItem, InfoFieldItem, FieldsetItem, RootFieldItem } from "../../types/domain";
|
|
4
4
|
import { ListInputFieldsSchema, type ListInputFieldsOptions } from "./schemas";
|
|
5
5
|
import type { GetAppPluginProvides } from "../getApp";
|
|
6
6
|
import type { GetVersionedImplementationId } from "../manifest/schemas";
|
|
7
7
|
export interface ListInputFieldsPluginProvides {
|
|
8
8
|
listInputFields: (options?: ListInputFieldsOptions) => Promise<{
|
|
9
|
-
data:
|
|
9
|
+
data: RootFieldItem[];
|
|
10
10
|
}> & AsyncIterable<{
|
|
11
|
-
data:
|
|
11
|
+
data: RootFieldItem[];
|
|
12
12
|
nextCursor?: string;
|
|
13
13
|
}> & {
|
|
14
|
-
items(): AsyncIterable<InputFieldItem>;
|
|
14
|
+
items(): AsyncIterable<InputFieldItem | InfoFieldItem | FieldsetItem>;
|
|
15
15
|
};
|
|
16
16
|
context: {
|
|
17
17
|
meta: {
|