zapier-platform-core 18.2.3 → 18.4.0
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 +3 -2
- package/types/inputs.d.ts +29 -2
- package/types/inputs.plainfields.test-d.ts +137 -1
- package/types/inputs.test-d.ts +32 -0
- package/types/schemas.generated.d.ts +52 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zapier-platform-core",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.4.0",
|
|
4
4
|
"description": "The core SDK for CLI apps in the Zapier Developer Platform.",
|
|
5
5
|
"repository": "zapier/zapier-platform",
|
|
6
6
|
"homepage": "https://platform.zapier.com/",
|
|
@@ -35,13 +35,14 @@
|
|
|
35
35
|
"dotenv": "17.2.1",
|
|
36
36
|
"fernet": "^0.3.3",
|
|
37
37
|
"form-data": "4.0.5",
|
|
38
|
+
"json-schema-to-ts": "3.1.1",
|
|
38
39
|
"lodash": "4.17.23",
|
|
39
40
|
"mime-types": "3.0.1",
|
|
40
41
|
"node-abort-controller": "3.1.1",
|
|
41
42
|
"node-fetch": "2.7.0",
|
|
42
43
|
"oauth-sign": "0.9.0",
|
|
43
44
|
"semver": "7.7.2",
|
|
44
|
-
"zapier-platform-schema": "18.
|
|
45
|
+
"zapier-platform-schema": "18.4.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@types/node-fetch": "^2.6.11",
|
package/types/inputs.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
PlainInputField,
|
|
4
4
|
} from './schemas.generated';
|
|
5
5
|
import type { ZObject, Bundle } from './custom';
|
|
6
|
+
import type { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
6
7
|
|
|
7
8
|
// #region UTILITIES
|
|
8
9
|
|
|
@@ -103,6 +104,26 @@ type Merge<T extends object[]> = T extends [infer F, ...infer R]
|
|
|
103
104
|
// MAIN BITS
|
|
104
105
|
// =========
|
|
105
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Any value that is valid in JSON, including primitives. Used for
|
|
109
|
+
* nested values inside a json field's object or array.
|
|
110
|
+
*/
|
|
111
|
+
export type JsonValue =
|
|
112
|
+
| string
|
|
113
|
+
| number
|
|
114
|
+
| boolean
|
|
115
|
+
| null
|
|
116
|
+
| JsonValue[]
|
|
117
|
+
| { [key: string]: JsonValue };
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The root-level type of a `json` input field. Per the platform's
|
|
121
|
+
* functional constraint, a json field's root schema.type must be
|
|
122
|
+
* "object" or "array" — bare primitives are not allowed at the top
|
|
123
|
+
* level. Nested values inside can be any JsonValue.
|
|
124
|
+
*/
|
|
125
|
+
export type JsonFieldValue = JsonValue[] | { [key: string]: JsonValue };
|
|
126
|
+
|
|
106
127
|
type InputDataConstraint = Record<string, unknown>;
|
|
107
128
|
type InputDataDefault = Record<string, undefined>;
|
|
108
129
|
|
|
@@ -130,7 +151,9 @@ type FieldResultTypes = {
|
|
|
130
151
|
? number
|
|
131
152
|
: $FieldType extends 'boolean'
|
|
132
153
|
? boolean
|
|
133
|
-
:
|
|
154
|
+
: $FieldType extends 'json'
|
|
155
|
+
? JsonFieldValue
|
|
156
|
+
: never; // Ignore `copy` and any other non-value types
|
|
134
157
|
};
|
|
135
158
|
|
|
136
159
|
/**
|
|
@@ -156,7 +179,11 @@ type PrimitiveFieldResultType<$Field extends PlainInputField> = $Field extends {
|
|
|
156
179
|
type: infer $T extends PlainInputField['type'];
|
|
157
180
|
}
|
|
158
181
|
? $T extends string
|
|
159
|
-
?
|
|
182
|
+
? $T extends 'json'
|
|
183
|
+
? $Field extends { schema: infer $S extends JSONSchema }
|
|
184
|
+
? FromSchema<$S>
|
|
185
|
+
: JsonFieldValue
|
|
186
|
+
: FieldResultTypes[$T]
|
|
160
187
|
: string
|
|
161
188
|
: string;
|
|
162
189
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expectAssignable, expectType } from 'tsd';
|
|
2
2
|
|
|
3
|
-
import type { PlainFieldContribution } from './inputs';
|
|
3
|
+
import type { PlainFieldContribution, JsonFieldValue } from './inputs';
|
|
4
4
|
|
|
5
5
|
//
|
|
6
6
|
// Parent fields (where `children` is set)
|
|
@@ -636,3 +636,139 @@ expectAssignable<optionalStringArrayChoicesAutoCompleteUnions>({
|
|
|
636
636
|
optional_string_array_choices_auto_complete_unions: 'alpha',
|
|
637
637
|
});
|
|
638
638
|
expectAssignable<optionalStringArrayChoicesAutoCompleteUnions>({});
|
|
639
|
+
|
|
640
|
+
//
|
|
641
|
+
// JSON fields (where `type: 'json'` is set)
|
|
642
|
+
//
|
|
643
|
+
|
|
644
|
+
// Required json primitive field.
|
|
645
|
+
type primitiveRequiredJsonResult = PlainFieldContribution<{
|
|
646
|
+
key: 'primitive_required_json';
|
|
647
|
+
type: 'json';
|
|
648
|
+
required: true;
|
|
649
|
+
}>;
|
|
650
|
+
expectType<primitiveRequiredJsonResult>(
|
|
651
|
+
{} as { primitive_required_json: JsonFieldValue },
|
|
652
|
+
);
|
|
653
|
+
expectAssignable<primitiveRequiredJsonResult>({
|
|
654
|
+
primitive_required_json: { name: 'test' },
|
|
655
|
+
});
|
|
656
|
+
expectAssignable<primitiveRequiredJsonResult>({
|
|
657
|
+
primitive_required_json: ['a', 'b'],
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
// Optional json primitive field.
|
|
661
|
+
type primitiveOptionalJsonResult = PlainFieldContribution<{
|
|
662
|
+
key: 'primitive_optional_json';
|
|
663
|
+
type: 'json';
|
|
664
|
+
}>;
|
|
665
|
+
expectAssignable<primitiveOptionalJsonResult>({
|
|
666
|
+
primitive_optional_json: { nested: { deep: true } },
|
|
667
|
+
});
|
|
668
|
+
expectAssignable<primitiveOptionalJsonResult>({
|
|
669
|
+
primitive_optional_json: [1, 2, 3],
|
|
670
|
+
});
|
|
671
|
+
expectAssignable<primitiveOptionalJsonResult>({
|
|
672
|
+
primitive_optional_json: undefined,
|
|
673
|
+
});
|
|
674
|
+
expectAssignable<primitiveOptionalJsonResult>({});
|
|
675
|
+
|
|
676
|
+
// Required json list field.
|
|
677
|
+
type jsonListRequiredResult = PlainFieldContribution<{
|
|
678
|
+
key: 'list_required_json';
|
|
679
|
+
type: 'json';
|
|
680
|
+
required: true;
|
|
681
|
+
list: true;
|
|
682
|
+
}>;
|
|
683
|
+
expectType<jsonListRequiredResult>(
|
|
684
|
+
{} as { list_required_json: JsonFieldValue[] },
|
|
685
|
+
);
|
|
686
|
+
expectAssignable<jsonListRequiredResult>({
|
|
687
|
+
list_required_json: [{ a: 1 }, { b: 2 }],
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
// Json field with schema — infers specific type from schema.
|
|
691
|
+
type jsonWithSchemaResult = PlainFieldContribution<{
|
|
692
|
+
key: 'payload';
|
|
693
|
+
type: 'json';
|
|
694
|
+
required: true;
|
|
695
|
+
schema: {
|
|
696
|
+
type: 'object';
|
|
697
|
+
properties: {
|
|
698
|
+
name: { type: 'string' };
|
|
699
|
+
age: { type: 'number' };
|
|
700
|
+
};
|
|
701
|
+
required: ['name'];
|
|
702
|
+
additionalProperties: false;
|
|
703
|
+
};
|
|
704
|
+
}>;
|
|
705
|
+
expectType<jsonWithSchemaResult>(
|
|
706
|
+
{} as { payload: { name: string; age?: number } },
|
|
707
|
+
);
|
|
708
|
+
|
|
709
|
+
// Json field with schema, optional.
|
|
710
|
+
type jsonWithSchemaOptionalResult = PlainFieldContribution<{
|
|
711
|
+
key: 'data';
|
|
712
|
+
type: 'json';
|
|
713
|
+
schema: {
|
|
714
|
+
type: 'object';
|
|
715
|
+
properties: {
|
|
716
|
+
items: { type: 'array'; items: { type: 'string' } };
|
|
717
|
+
};
|
|
718
|
+
};
|
|
719
|
+
}>;
|
|
720
|
+
expectAssignable<jsonWithSchemaOptionalResult>({
|
|
721
|
+
data: { items: ['a', 'b'] },
|
|
722
|
+
});
|
|
723
|
+
expectAssignable<jsonWithSchemaOptionalResult>({});
|
|
724
|
+
|
|
725
|
+
// Json field with schema + list.
|
|
726
|
+
type jsonWithSchemaListResult = PlainFieldContribution<{
|
|
727
|
+
key: 'payloads';
|
|
728
|
+
type: 'json';
|
|
729
|
+
required: true;
|
|
730
|
+
list: true;
|
|
731
|
+
schema: {
|
|
732
|
+
type: 'object';
|
|
733
|
+
properties: {
|
|
734
|
+
id: { type: 'number' };
|
|
735
|
+
};
|
|
736
|
+
additionalProperties: false;
|
|
737
|
+
};
|
|
738
|
+
}>;
|
|
739
|
+
expectType<jsonWithSchemaListResult>(
|
|
740
|
+
{} as { payloads: { id?: number }[] },
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
// Json field WITHOUT schema still falls back to JsonFieldValue.
|
|
744
|
+
type jsonNoSchemaResult = PlainFieldContribution<{
|
|
745
|
+
key: 'raw';
|
|
746
|
+
type: 'json';
|
|
747
|
+
required: true;
|
|
748
|
+
}>;
|
|
749
|
+
expectType<jsonNoSchemaResult>(
|
|
750
|
+
{} as { raw: JsonFieldValue },
|
|
751
|
+
);
|
|
752
|
+
|
|
753
|
+
// Json field as a child of a parent field.
|
|
754
|
+
type jsonChildResult = PlainFieldContribution<{
|
|
755
|
+
key: 'parent_with_json';
|
|
756
|
+
children: [
|
|
757
|
+
{ key: 'json_child'; type: 'json'; required: true },
|
|
758
|
+
{ key: 'string_child'; type: 'string'; required: true },
|
|
759
|
+
];
|
|
760
|
+
}>;
|
|
761
|
+
expectAssignable<jsonChildResult>({
|
|
762
|
+
json_child: { key: 'value' },
|
|
763
|
+
string_child: 'hello',
|
|
764
|
+
});
|
|
765
|
+
expectType<jsonChildResult>(
|
|
766
|
+
{} as {
|
|
767
|
+
json_child: JsonFieldValue;
|
|
768
|
+
string_child: string;
|
|
769
|
+
parent_with_json?: {
|
|
770
|
+
json_child: JsonFieldValue;
|
|
771
|
+
string_child: string;
|
|
772
|
+
}[];
|
|
773
|
+
},
|
|
774
|
+
);
|
package/types/inputs.test-d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type {
|
|
10
10
|
InferInputData,
|
|
11
11
|
InputFieldFunctionWithInputs,
|
|
12
|
+
JsonFieldValue,
|
|
12
13
|
StringHints,
|
|
13
14
|
} from './inputs';
|
|
14
15
|
import { defineInputFields } from '.';
|
|
@@ -58,6 +59,7 @@ const typeComboInputs = defineInputFields([
|
|
|
58
59
|
{ key: 'boolean_type', type: 'boolean', required: true },
|
|
59
60
|
{ key: 'datetime_type', type: 'datetime', required: true },
|
|
60
61
|
{ key: 'file_type', type: 'file', required: true },
|
|
62
|
+
{ key: 'json_type', type: 'json', required: true },
|
|
61
63
|
]);
|
|
62
64
|
const typeComboResult: InferInputData<typeof typeComboInputs> = {
|
|
63
65
|
string_type: 'a',
|
|
@@ -69,6 +71,7 @@ const typeComboResult: InferInputData<typeof typeComboInputs> = {
|
|
|
69
71
|
boolean_type: true,
|
|
70
72
|
datetime_type: 'datetime',
|
|
71
73
|
file_type: 'file',
|
|
74
|
+
json_type: { key: 'value' },
|
|
72
75
|
};
|
|
73
76
|
expectType<{
|
|
74
77
|
string_type: string;
|
|
@@ -80,8 +83,37 @@ expectType<{
|
|
|
80
83
|
boolean_type: boolean;
|
|
81
84
|
datetime_type: string;
|
|
82
85
|
file_type: string;
|
|
86
|
+
json_type: JsonFieldValue;
|
|
83
87
|
}>(typeComboResult);
|
|
84
88
|
|
|
89
|
+
//
|
|
90
|
+
// Test json field with schema infers specific type via InferInputData.
|
|
91
|
+
const jsonSchemaInputs = defineInputFields([
|
|
92
|
+
{
|
|
93
|
+
key: 'typed_json',
|
|
94
|
+
type: 'json',
|
|
95
|
+
required: true,
|
|
96
|
+
schema: {
|
|
97
|
+
type: 'object',
|
|
98
|
+
properties: {
|
|
99
|
+
name: { type: 'string' },
|
|
100
|
+
count: { type: 'number' },
|
|
101
|
+
},
|
|
102
|
+
required: ['name'],
|
|
103
|
+
additionalProperties: false,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{ key: 'plain_json', type: 'json', required: true },
|
|
107
|
+
]);
|
|
108
|
+
const jsonSchemaResult: InferInputData<typeof jsonSchemaInputs> = {
|
|
109
|
+
typed_json: { name: 'hello' },
|
|
110
|
+
plain_json: { key: 'value' },
|
|
111
|
+
};
|
|
112
|
+
expectType<{
|
|
113
|
+
typed_json: { name: string; count?: number };
|
|
114
|
+
plain_json: JsonFieldValue;
|
|
115
|
+
}>(jsonSchemaResult);
|
|
116
|
+
|
|
85
117
|
//
|
|
86
118
|
// Test that copy fields are never appear in the bundle.
|
|
87
119
|
const copyComboInputs = defineInputFields([
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* files, and/or the schema-to-ts tool and run its CLI to regenerate
|
|
5
5
|
* these typings.
|
|
6
6
|
*
|
|
7
|
-
* zapier-platform-schema version: 18.
|
|
7
|
+
* zapier-platform-schema version: 18.4.0
|
|
8
8
|
* schema-to-ts compiler version: 0.1.0
|
|
9
9
|
*/
|
|
10
10
|
import type {
|
|
@@ -289,7 +289,11 @@ export interface AppFlags {
|
|
|
289
289
|
* via middleware), [Shorthand
|
|
290
290
|
* requests](https://github.com/zapier/zapier-platform/blob/main/packages/cli/README.md#shorthand-http-requests)
|
|
291
291
|
* _always_ call `throwForStatus()`. `z.request()` calls can also
|
|
292
|
-
* ignore this flag if they set `skipThrowForStatus` directly
|
|
292
|
+
* ignore this flag if they set `skipThrowForStatus` directly. It is
|
|
293
|
+
* important to note that for oauth2 or session auths with
|
|
294
|
+
* `authRefresh:true`, `401` status codes will throw a
|
|
295
|
+
* `RefreshAuthError` regardless of `skipThrowForStatus`, and will
|
|
296
|
+
* need to be handled manually if intervention is required.
|
|
293
297
|
*/
|
|
294
298
|
skipThrowForStatus?: boolean;
|
|
295
299
|
|
|
@@ -1703,7 +1707,8 @@ export interface PlainInputField {
|
|
|
1703
1707
|
| 'file'
|
|
1704
1708
|
| 'password'
|
|
1705
1709
|
| 'copy'
|
|
1706
|
-
| 'code'
|
|
1710
|
+
| 'code'
|
|
1711
|
+
| 'json';
|
|
1707
1712
|
|
|
1708
1713
|
/** If this value is required or not. */
|
|
1709
1714
|
required?: boolean;
|
|
@@ -1744,10 +1749,25 @@ export interface PlainInputField {
|
|
|
1744
1749
|
dynamic?: RefResource;
|
|
1745
1750
|
|
|
1746
1751
|
/**
|
|
1747
|
-
*
|
|
1748
|
-
*
|
|
1752
|
+
* Specifies which other input fields this field depends on. These
|
|
1753
|
+
* must be filled before this one becomes enabled, and when their
|
|
1754
|
+
* values change, this field's value should be cleared.
|
|
1749
1755
|
*/
|
|
1750
|
-
|
|
1756
|
+
dependsOn?: string[];
|
|
1757
|
+
|
|
1758
|
+
/**
|
|
1759
|
+
* Explicitly links this input field to a resource. Use the resource
|
|
1760
|
+
* key (e.g., "spreadsheet") or dot notation for resource fields
|
|
1761
|
+
* (e.g., "spreadsheet.url"). If not set for dynamic dropdowns, the
|
|
1762
|
+
* resource is derived implicitly from the `dynamic` property.
|
|
1763
|
+
*/
|
|
1764
|
+
resource?: string;
|
|
1765
|
+
|
|
1766
|
+
/**
|
|
1767
|
+
* Describes how to populate this dropdown. Can be a static list or
|
|
1768
|
+
* a dynamic object with pagination and search support.
|
|
1769
|
+
*/
|
|
1770
|
+
choices?: FieldChoices | FieldDynamicChoices;
|
|
1751
1771
|
|
|
1752
1772
|
/** An example value that is not saved. */
|
|
1753
1773
|
placeholder?: string;
|
|
@@ -1783,6 +1803,12 @@ export interface PlainInputField {
|
|
|
1783
1803
|
* organize this field with others.
|
|
1784
1804
|
*/
|
|
1785
1805
|
group?: Key;
|
|
1806
|
+
|
|
1807
|
+
/**
|
|
1808
|
+
* A JSON Schema object that describes the expected structure of the
|
|
1809
|
+
* JSON value. Only valid when `type` is `json`.
|
|
1810
|
+
*/
|
|
1811
|
+
schema?: JsonSchema;
|
|
1786
1812
|
}
|
|
1787
1813
|
|
|
1788
1814
|
/** Object for visual grouping of input fields. */
|
|
@@ -1803,5 +1829,25 @@ export interface InputFieldGroup {
|
|
|
1803
1829
|
*/
|
|
1804
1830
|
export type RefResource = string;
|
|
1805
1831
|
|
|
1832
|
+
/**
|
|
1833
|
+
* Describes dynamic dropdowns powered by a perform function or
|
|
1834
|
+
* request.
|
|
1835
|
+
*/
|
|
1836
|
+
export interface FieldDynamicChoices {
|
|
1837
|
+
/**
|
|
1838
|
+
* A function or request that returns choices for this dynamic
|
|
1839
|
+
* dropdown.
|
|
1840
|
+
*/
|
|
1841
|
+
perform: Function | Request;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1806
1844
|
/** Allows for additional metadata to be stored on the field. */
|
|
1807
1845
|
export type FieldMeta = Record<string, string | number | boolean>;
|
|
1846
|
+
|
|
1847
|
+
/**
|
|
1848
|
+
* A JSON Schema object that describes the expected structure of a
|
|
1849
|
+
* JSON value. Validated against JSON Schema Draft 4, 6, or 7
|
|
1850
|
+
* meta-schema (based on the `$schema` field, defaulting to Draft 7)
|
|
1851
|
+
* via the validateJsonFieldSchema functional constraint.
|
|
1852
|
+
*/
|
|
1853
|
+
export type JsonSchema = Record<string, unknown>;
|