@crevio/sdk 0.4.15 → 0.4.17
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/README.md +4 -2
- package/dist/commonjs/funcs/formsCreate.d.ts +3 -4
- package/dist/commonjs/funcs/formsCreate.d.ts.map +1 -1
- package/dist/commonjs/funcs/formsCreate.js +7 -14
- package/dist/commonjs/funcs/formsCreate.js.map +1 -1
- package/dist/commonjs/funcs/formsSubmit.d.ts +19 -0
- package/dist/commonjs/funcs/formsSubmit.d.ts.map +1 -0
- package/dist/commonjs/funcs/formsSubmit.js +126 -0
- package/dist/commonjs/funcs/formsSubmit.js.map +1 -0
- package/dist/commonjs/lib/config.d.ts +2 -2
- package/dist/commonjs/lib/config.js +2 -2
- package/dist/commonjs/models/customer.d.ts +1 -0
- package/dist/commonjs/models/customer.d.ts.map +1 -1
- package/dist/commonjs/models/customer.js +2 -0
- package/dist/commonjs/models/customer.js.map +1 -1
- package/dist/commonjs/models/form.d.ts +8 -8
- package/dist/commonjs/models/form.d.ts.map +1 -1
- package/dist/commonjs/models/form.js +10 -10
- package/dist/commonjs/models/form.js.map +1 -1
- package/dist/commonjs/models/formfield.d.ts +14 -1
- package/dist/commonjs/models/formfield.d.ts.map +1 -1
- package/dist/commonjs/models/formfield.js +13 -2
- package/dist/commonjs/models/formfield.js.map +1 -1
- package/dist/commonjs/models/formrequest.d.ts +83 -0
- package/dist/commonjs/models/formrequest.d.ts.map +1 -1
- package/dist/commonjs/models/formrequest.js +52 -1
- package/dist/commonjs/models/formrequest.js.map +1 -1
- package/dist/commonjs/models/formsubmissionrequest.d.ts +11 -16
- package/dist/commonjs/models/formsubmissionrequest.d.ts.map +1 -1
- package/dist/commonjs/models/formsubmissionrequest.js +4 -10
- package/dist/commonjs/models/formsubmissionrequest.js.map +1 -1
- package/dist/commonjs/sdk/forms.d.ts +8 -1
- package/dist/commonjs/sdk/forms.d.ts.map +1 -1
- package/dist/commonjs/sdk/forms.js +12 -2
- package/dist/commonjs/sdk/forms.js.map +1 -1
- package/dist/esm/funcs/formsCreate.d.ts +3 -4
- package/dist/esm/funcs/formsCreate.d.ts.map +1 -1
- package/dist/esm/funcs/formsCreate.js +8 -15
- package/dist/esm/funcs/formsCreate.js.map +1 -1
- package/dist/esm/funcs/formsSubmit.d.ts +19 -0
- package/dist/esm/funcs/formsSubmit.d.ts.map +1 -0
- package/dist/esm/funcs/formsSubmit.js +90 -0
- package/dist/esm/funcs/formsSubmit.js.map +1 -0
- package/dist/esm/lib/config.d.ts +2 -2
- package/dist/esm/lib/config.js +2 -2
- package/dist/esm/models/customer.d.ts +1 -0
- package/dist/esm/models/customer.d.ts.map +1 -1
- package/dist/esm/models/customer.js +2 -0
- package/dist/esm/models/customer.js.map +1 -1
- package/dist/esm/models/form.d.ts +8 -8
- package/dist/esm/models/form.d.ts.map +1 -1
- package/dist/esm/models/form.js +8 -8
- package/dist/esm/models/form.js.map +1 -1
- package/dist/esm/models/formfield.d.ts +14 -1
- package/dist/esm/models/formfield.d.ts.map +1 -1
- package/dist/esm/models/formfield.js +12 -1
- package/dist/esm/models/formfield.js.map +1 -1
- package/dist/esm/models/formrequest.d.ts +83 -0
- package/dist/esm/models/formrequest.d.ts.map +1 -1
- package/dist/esm/models/formrequest.js +49 -0
- package/dist/esm/models/formrequest.js.map +1 -1
- package/dist/esm/models/formsubmissionrequest.d.ts +11 -16
- package/dist/esm/models/formsubmissionrequest.d.ts.map +1 -1
- package/dist/esm/models/formsubmissionrequest.js +3 -8
- package/dist/esm/models/formsubmissionrequest.js.map +1 -1
- package/dist/esm/sdk/forms.d.ts +8 -1
- package/dist/esm/sdk/forms.d.ts.map +1 -1
- package/dist/esm/sdk/forms.js +12 -2
- package/dist/esm/sdk/forms.js.map +1 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/funcs/formsCreate.ts +14 -22
- package/src/funcs/formsSubmit.ts +180 -0
- package/src/lib/config.ts +2 -2
- package/src/models/customer.ts +5 -0
- package/src/models/form.ts +15 -15
- package/src/models/formfield.ts +19 -2
- package/src/models/formrequest.ts +138 -0
- package/src/models/formsubmissionrequest.ts +10 -29
- package/src/sdk/forms.ts +20 -2
package/src/funcs/formsCreate.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { CrevioCore } from "../core.js";
|
|
6
|
-
import { encodeJSON
|
|
6
|
+
import { encodeJSON } from "../lib/encodings.js";
|
|
7
7
|
import { matchStatusCode } from "../lib/http.js";
|
|
8
8
|
import * as M from "../lib/matchers.js";
|
|
9
9
|
import { compactMap } from "../lib/primitives.js";
|
|
@@ -23,23 +23,22 @@ import * as errors from "../models/errors/index.js";
|
|
|
23
23
|
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
24
24
|
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
25
25
|
import * as models from "../models/index.js";
|
|
26
|
-
import * as operations from "../models/operations/index.js";
|
|
27
26
|
import { APICall, APIPromise } from "../types/async.js";
|
|
28
27
|
import { Result } from "../types/fp.js";
|
|
29
28
|
|
|
30
29
|
/**
|
|
31
|
-
* Create form
|
|
30
|
+
* Create form
|
|
32
31
|
*
|
|
33
32
|
* @remarks
|
|
34
|
-
*
|
|
33
|
+
* Creates a new Form, optionally with fields nested via form_fields_attributes. Use this to provision newsletter, contact, lead-magnet, or custom-purpose forms programmatically.
|
|
35
34
|
*/
|
|
36
35
|
export function formsCreate(
|
|
37
36
|
client: CrevioCore,
|
|
38
|
-
request:
|
|
37
|
+
request: models.FormRequest,
|
|
39
38
|
options?: RequestOptions,
|
|
40
39
|
): APIPromise<
|
|
41
40
|
Result<
|
|
42
|
-
models.
|
|
41
|
+
models.Form,
|
|
43
42
|
| errors.ErrorT
|
|
44
43
|
| CrevioError
|
|
45
44
|
| ResponseValidationError
|
|
@@ -60,12 +59,12 @@ export function formsCreate(
|
|
|
60
59
|
|
|
61
60
|
async function $do(
|
|
62
61
|
client: CrevioCore,
|
|
63
|
-
request:
|
|
62
|
+
request: models.FormRequest,
|
|
64
63
|
options?: RequestOptions,
|
|
65
64
|
): Promise<
|
|
66
65
|
[
|
|
67
66
|
Result<
|
|
68
|
-
models.
|
|
67
|
+
models.Form,
|
|
69
68
|
| errors.ErrorT
|
|
70
69
|
| CrevioError
|
|
71
70
|
| ResponseValidationError
|
|
@@ -81,23 +80,16 @@ async function $do(
|
|
|
81
80
|
> {
|
|
82
81
|
const parsed = safeParse(
|
|
83
82
|
request,
|
|
84
|
-
(value) =>
|
|
85
|
-
operations.CreateFormSubmissionForFormRequest$outboundSchema.parse(value),
|
|
83
|
+
(value) => models.FormRequest$outboundSchema.parse(value),
|
|
86
84
|
"Input validation failed",
|
|
87
85
|
);
|
|
88
86
|
if (!parsed.ok) {
|
|
89
87
|
return [parsed, { status: "invalid" }];
|
|
90
88
|
}
|
|
91
89
|
const payload = parsed.value;
|
|
92
|
-
const body = encodeJSON("body", payload
|
|
90
|
+
const body = encodeJSON("body", payload, { explode: true });
|
|
93
91
|
|
|
94
|
-
const
|
|
95
|
-
form_id: encodeSimple("form_id", payload.form_id, {
|
|
96
|
-
explode: false,
|
|
97
|
-
charEncoding: "percent",
|
|
98
|
-
}),
|
|
99
|
-
};
|
|
100
|
-
const path = pathToFunc("/forms/{form_id}/submissions")(pathParams);
|
|
92
|
+
const path = pathToFunc("/forms")();
|
|
101
93
|
|
|
102
94
|
const headers = new Headers(compactMap({
|
|
103
95
|
"Content-Type": "application/json",
|
|
@@ -111,7 +103,7 @@ async function $do(
|
|
|
111
103
|
const context = {
|
|
112
104
|
options: client._options,
|
|
113
105
|
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
114
|
-
operationID: "
|
|
106
|
+
operationID: "createForm",
|
|
115
107
|
oAuth2Scopes: null,
|
|
116
108
|
|
|
117
109
|
resolvedSecurity: requestSecurity,
|
|
@@ -155,7 +147,7 @@ async function $do(
|
|
|
155
147
|
};
|
|
156
148
|
|
|
157
149
|
const [result] = await M.match<
|
|
158
|
-
models.
|
|
150
|
+
models.Form,
|
|
159
151
|
| errors.ErrorT
|
|
160
152
|
| CrevioError
|
|
161
153
|
| ResponseValidationError
|
|
@@ -166,8 +158,8 @@ async function $do(
|
|
|
166
158
|
| UnexpectedClientError
|
|
167
159
|
| SDKValidationError
|
|
168
160
|
>(
|
|
169
|
-
M.json(201, models.
|
|
170
|
-
M.jsonErr([400, 401, 403,
|
|
161
|
+
M.json(201, models.Form$inboundSchema),
|
|
162
|
+
M.jsonErr([400, 401, 403, 422], errors.ErrorT$inboundSchema),
|
|
171
163
|
M.jsonErr(500, errors.ErrorT$inboundSchema),
|
|
172
164
|
M.fail("4XX"),
|
|
173
165
|
M.fail("5XX"),
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { CrevioCore } from "../core.js";
|
|
6
|
+
import { encodeJSON, encodeSimple } from "../lib/encodings.js";
|
|
7
|
+
import { matchStatusCode } from "../lib/http.js";
|
|
8
|
+
import * as M from "../lib/matchers.js";
|
|
9
|
+
import { compactMap } from "../lib/primitives.js";
|
|
10
|
+
import { safeParse } from "../lib/schemas.js";
|
|
11
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
12
|
+
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
|
|
13
|
+
import { pathToFunc } from "../lib/url.js";
|
|
14
|
+
import { CrevioError } from "../models/errors/crevioerror.js";
|
|
15
|
+
import {
|
|
16
|
+
ConnectionError,
|
|
17
|
+
InvalidRequestError,
|
|
18
|
+
RequestAbortedError,
|
|
19
|
+
RequestTimeoutError,
|
|
20
|
+
UnexpectedClientError,
|
|
21
|
+
} from "../models/errors/httpclienterrors.js";
|
|
22
|
+
import * as errors from "../models/errors/index.js";
|
|
23
|
+
import { ResponseValidationError } from "../models/errors/responsevalidationerror.js";
|
|
24
|
+
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
|
|
25
|
+
import * as models from "../models/index.js";
|
|
26
|
+
import * as operations from "../models/operations/index.js";
|
|
27
|
+
import { APICall, APIPromise } from "../types/async.js";
|
|
28
|
+
import { Result } from "../types/fp.js";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create form submission
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Submits an answer set to a specific Form. Customer is upserted by email; lead-magnet purpose forms also trigger delivery.
|
|
35
|
+
*/
|
|
36
|
+
export function formsSubmit(
|
|
37
|
+
client: CrevioCore,
|
|
38
|
+
request: operations.CreateFormSubmissionForFormRequest,
|
|
39
|
+
options?: RequestOptions,
|
|
40
|
+
): APIPromise<
|
|
41
|
+
Result<
|
|
42
|
+
models.FormSubmission,
|
|
43
|
+
| errors.ErrorT
|
|
44
|
+
| CrevioError
|
|
45
|
+
| ResponseValidationError
|
|
46
|
+
| ConnectionError
|
|
47
|
+
| RequestAbortedError
|
|
48
|
+
| RequestTimeoutError
|
|
49
|
+
| InvalidRequestError
|
|
50
|
+
| UnexpectedClientError
|
|
51
|
+
| SDKValidationError
|
|
52
|
+
>
|
|
53
|
+
> {
|
|
54
|
+
return new APIPromise($do(
|
|
55
|
+
client,
|
|
56
|
+
request,
|
|
57
|
+
options,
|
|
58
|
+
));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function $do(
|
|
62
|
+
client: CrevioCore,
|
|
63
|
+
request: operations.CreateFormSubmissionForFormRequest,
|
|
64
|
+
options?: RequestOptions,
|
|
65
|
+
): Promise<
|
|
66
|
+
[
|
|
67
|
+
Result<
|
|
68
|
+
models.FormSubmission,
|
|
69
|
+
| errors.ErrorT
|
|
70
|
+
| CrevioError
|
|
71
|
+
| ResponseValidationError
|
|
72
|
+
| ConnectionError
|
|
73
|
+
| RequestAbortedError
|
|
74
|
+
| RequestTimeoutError
|
|
75
|
+
| InvalidRequestError
|
|
76
|
+
| UnexpectedClientError
|
|
77
|
+
| SDKValidationError
|
|
78
|
+
>,
|
|
79
|
+
APICall,
|
|
80
|
+
]
|
|
81
|
+
> {
|
|
82
|
+
const parsed = safeParse(
|
|
83
|
+
request,
|
|
84
|
+
(value) =>
|
|
85
|
+
operations.CreateFormSubmissionForFormRequest$outboundSchema.parse(value),
|
|
86
|
+
"Input validation failed",
|
|
87
|
+
);
|
|
88
|
+
if (!parsed.ok) {
|
|
89
|
+
return [parsed, { status: "invalid" }];
|
|
90
|
+
}
|
|
91
|
+
const payload = parsed.value;
|
|
92
|
+
const body = encodeJSON("body", payload.RequestBody, { explode: true });
|
|
93
|
+
|
|
94
|
+
const pathParams = {
|
|
95
|
+
form_id: encodeSimple("form_id", payload.form_id, {
|
|
96
|
+
explode: false,
|
|
97
|
+
charEncoding: "percent",
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
100
|
+
const path = pathToFunc("/forms/{form_id}/submissions")(pathParams);
|
|
101
|
+
|
|
102
|
+
const headers = new Headers(compactMap({
|
|
103
|
+
"Content-Type": "application/json",
|
|
104
|
+
Accept: "application/json",
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
const secConfig = await extractSecurity(client._options.apiKey);
|
|
108
|
+
const securityInput = secConfig == null ? {} : { apiKey: secConfig };
|
|
109
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
110
|
+
|
|
111
|
+
const context = {
|
|
112
|
+
options: client._options,
|
|
113
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
114
|
+
operationID: "createFormSubmissionForForm",
|
|
115
|
+
oAuth2Scopes: null,
|
|
116
|
+
|
|
117
|
+
resolvedSecurity: requestSecurity,
|
|
118
|
+
|
|
119
|
+
securitySource: client._options.apiKey,
|
|
120
|
+
retryConfig: options?.retries
|
|
121
|
+
|| client._options.retryConfig
|
|
122
|
+
|| { strategy: "none" },
|
|
123
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const requestRes = client._createRequest(context, {
|
|
127
|
+
security: requestSecurity,
|
|
128
|
+
method: "POST",
|
|
129
|
+
baseURL: options?.serverURL,
|
|
130
|
+
path: path,
|
|
131
|
+
headers: headers,
|
|
132
|
+
body: body,
|
|
133
|
+
userAgent: client._options.userAgent,
|
|
134
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
135
|
+
}, options);
|
|
136
|
+
if (!requestRes.ok) {
|
|
137
|
+
return [requestRes, { status: "invalid" }];
|
|
138
|
+
}
|
|
139
|
+
const req = requestRes.value;
|
|
140
|
+
|
|
141
|
+
const doResult = await client._do(req, {
|
|
142
|
+
context,
|
|
143
|
+
isErrorStatusCode: (statusCode: number) =>
|
|
144
|
+
matchStatusCode({ status: statusCode } as Response, ["4XX", "5XX"]),
|
|
145
|
+
retryConfig: context.retryConfig,
|
|
146
|
+
retryCodes: context.retryCodes,
|
|
147
|
+
});
|
|
148
|
+
if (!doResult.ok) {
|
|
149
|
+
return [doResult, { status: "request-error", request: req }];
|
|
150
|
+
}
|
|
151
|
+
const response = doResult.value;
|
|
152
|
+
|
|
153
|
+
const responseFields = {
|
|
154
|
+
HttpMeta: { Response: response, Request: req },
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const [result] = await M.match<
|
|
158
|
+
models.FormSubmission,
|
|
159
|
+
| errors.ErrorT
|
|
160
|
+
| CrevioError
|
|
161
|
+
| ResponseValidationError
|
|
162
|
+
| ConnectionError
|
|
163
|
+
| RequestAbortedError
|
|
164
|
+
| RequestTimeoutError
|
|
165
|
+
| InvalidRequestError
|
|
166
|
+
| UnexpectedClientError
|
|
167
|
+
| SDKValidationError
|
|
168
|
+
>(
|
|
169
|
+
M.json(201, models.FormSubmission$inboundSchema),
|
|
170
|
+
M.jsonErr([400, 401, 403, 404, 422], errors.ErrorT$inboundSchema),
|
|
171
|
+
M.jsonErr(500, errors.ErrorT$inboundSchema),
|
|
172
|
+
M.fail("4XX"),
|
|
173
|
+
M.fail("5XX"),
|
|
174
|
+
)(response, req, { extraFields: responseFields });
|
|
175
|
+
if (!result.ok) {
|
|
176
|
+
return [result, { status: "complete", request: req, response }];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return [result, { status: "complete", request: req, response }];
|
|
180
|
+
}
|
package/src/lib/config.ts
CHANGED
|
@@ -61,7 +61,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
61
61
|
export const SDK_METADATA = {
|
|
62
62
|
language: "typescript",
|
|
63
63
|
openapiDocVersion: "1.0.0",
|
|
64
|
-
sdkVersion: "0.4.
|
|
64
|
+
sdkVersion: "0.4.17",
|
|
65
65
|
genVersion: "2.882.0",
|
|
66
|
-
userAgent: "speakeasy-sdk/typescript 0.4.
|
|
66
|
+
userAgent: "speakeasy-sdk/typescript 0.4.17 2.882.0 1.0.0 @crevio/sdk",
|
|
67
67
|
} as const;
|
package/src/models/customer.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type Customer = {
|
|
|
24
24
|
firstName: string | null;
|
|
25
25
|
lastName: string | null;
|
|
26
26
|
customerType: CustomerCustomerType;
|
|
27
|
+
confirmedAt: Date | null;
|
|
27
28
|
createdAt: Date;
|
|
28
29
|
updatedAt: Date;
|
|
29
30
|
ordersCount: number;
|
|
@@ -49,6 +50,9 @@ export const Customer$inboundSchema: z.ZodType<
|
|
|
49
50
|
first_name: z.nullable(z.string()),
|
|
50
51
|
last_name: z.nullable(z.string()),
|
|
51
52
|
customer_type: CustomerCustomerType$inboundSchema,
|
|
53
|
+
confirmed_at: z.nullable(
|
|
54
|
+
z.string().datetime({ offset: true }).transform(v => new Date(v)),
|
|
55
|
+
),
|
|
52
56
|
created_at: z.string().datetime({ offset: true }).transform(v => new Date(v)),
|
|
53
57
|
updated_at: z.string().datetime({ offset: true }).transform(v => new Date(v)),
|
|
54
58
|
orders_count: z.number().int(),
|
|
@@ -59,6 +63,7 @@ export const Customer$inboundSchema: z.ZodType<
|
|
|
59
63
|
"first_name": "firstName",
|
|
60
64
|
"last_name": "lastName",
|
|
61
65
|
"customer_type": "customerType",
|
|
66
|
+
"confirmed_at": "confirmedAt",
|
|
62
67
|
"created_at": "createdAt",
|
|
63
68
|
"updated_at": "updatedAt",
|
|
64
69
|
"orders_count": "ordersCount",
|
package/src/models/form.ts
CHANGED
|
@@ -10,24 +10,24 @@ import { Result as SafeParseResult } from "../types/fp.js";
|
|
|
10
10
|
import { SDKValidationError } from "./errors/sdkvalidationerror.js";
|
|
11
11
|
import { FormField, FormField$inboundSchema } from "./formfield.js";
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const FormPurpose = {
|
|
14
14
|
Newsletter: "newsletter",
|
|
15
15
|
Contact: "contact",
|
|
16
16
|
LeadMagnet: "lead_magnet",
|
|
17
17
|
Custom: "custom",
|
|
18
18
|
} as const;
|
|
19
|
-
export type
|
|
19
|
+
export type FormPurpose = ClosedEnum<typeof FormPurpose>;
|
|
20
20
|
|
|
21
|
-
export type
|
|
21
|
+
export type FormSettings = {};
|
|
22
22
|
|
|
23
23
|
export type Form = {
|
|
24
24
|
id: string;
|
|
25
25
|
object: string;
|
|
26
|
-
purpose:
|
|
26
|
+
purpose: FormPurpose;
|
|
27
27
|
name: string;
|
|
28
28
|
isPrimary: boolean;
|
|
29
29
|
confirmationRequired: boolean;
|
|
30
|
-
settings:
|
|
30
|
+
settings: FormSettings;
|
|
31
31
|
tagIds: Array<number>;
|
|
32
32
|
archivedAt: Date | null;
|
|
33
33
|
createdAt: Date;
|
|
@@ -36,23 +36,23 @@ export type Form = {
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
/** @internal */
|
|
39
|
-
export const
|
|
40
|
-
.nativeEnum(
|
|
39
|
+
export const FormPurpose$inboundSchema: z.ZodNativeEnum<typeof FormPurpose> = z
|
|
40
|
+
.nativeEnum(FormPurpose);
|
|
41
41
|
|
|
42
42
|
/** @internal */
|
|
43
|
-
export const
|
|
44
|
-
|
|
43
|
+
export const FormSettings$inboundSchema: z.ZodType<
|
|
44
|
+
FormSettings,
|
|
45
45
|
z.ZodTypeDef,
|
|
46
46
|
unknown
|
|
47
47
|
> = z.object({});
|
|
48
48
|
|
|
49
|
-
export function
|
|
49
|
+
export function formSettingsFromJSON(
|
|
50
50
|
jsonString: string,
|
|
51
|
-
): SafeParseResult<
|
|
51
|
+
): SafeParseResult<FormSettings, SDKValidationError> {
|
|
52
52
|
return safeParse(
|
|
53
53
|
jsonString,
|
|
54
|
-
(x) =>
|
|
55
|
-
`Failed to parse '
|
|
54
|
+
(x) => FormSettings$inboundSchema.parse(JSON.parse(x)),
|
|
55
|
+
`Failed to parse 'FormSettings' from JSON`,
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -61,11 +61,11 @@ export const Form$inboundSchema: z.ZodType<Form, z.ZodTypeDef, unknown> = z
|
|
|
61
61
|
.object({
|
|
62
62
|
id: z.string(),
|
|
63
63
|
object: z.string(),
|
|
64
|
-
purpose:
|
|
64
|
+
purpose: FormPurpose$inboundSchema,
|
|
65
65
|
name: z.string(),
|
|
66
66
|
is_primary: z.boolean(),
|
|
67
67
|
confirmation_required: z.boolean(),
|
|
68
|
-
settings: z.lazy(() =>
|
|
68
|
+
settings: z.lazy(() => FormSettings$inboundSchema),
|
|
69
69
|
tag_ids: z.array(z.number().int()),
|
|
70
70
|
archived_at: z.nullable(
|
|
71
71
|
z.string().datetime({ offset: true }).transform(v => new Date(v)),
|
package/src/models/formfield.ts
CHANGED
|
@@ -5,19 +5,36 @@
|
|
|
5
5
|
import * as z from "zod/v3";
|
|
6
6
|
import { remap as remap$ } from "../lib/primitives.js";
|
|
7
7
|
import { safeParse } from "../lib/schemas.js";
|
|
8
|
+
import { ClosedEnum } from "../types/enums.js";
|
|
8
9
|
import { Result as SafeParseResult } from "../types/fp.js";
|
|
9
10
|
import { SDKValidationError } from "./errors/sdkvalidationerror.js";
|
|
10
11
|
|
|
12
|
+
export const FormFieldFieldType = {
|
|
13
|
+
Email: "email",
|
|
14
|
+
Text: "text",
|
|
15
|
+
Phone: "phone",
|
|
16
|
+
Textarea: "textarea",
|
|
17
|
+
Radio: "radio",
|
|
18
|
+
Select: "select",
|
|
19
|
+
Checkbox: "checkbox",
|
|
20
|
+
} as const;
|
|
21
|
+
export type FormFieldFieldType = ClosedEnum<typeof FormFieldFieldType>;
|
|
22
|
+
|
|
11
23
|
export type FormField = {
|
|
12
24
|
id: string;
|
|
13
25
|
object: string;
|
|
14
26
|
name: string;
|
|
15
|
-
fieldType:
|
|
27
|
+
fieldType: FormFieldFieldType;
|
|
16
28
|
required: boolean | null;
|
|
17
29
|
position: number | null;
|
|
18
30
|
options: Array<string>;
|
|
19
31
|
};
|
|
20
32
|
|
|
33
|
+
/** @internal */
|
|
34
|
+
export const FormFieldFieldType$inboundSchema: z.ZodNativeEnum<
|
|
35
|
+
typeof FormFieldFieldType
|
|
36
|
+
> = z.nativeEnum(FormFieldFieldType);
|
|
37
|
+
|
|
21
38
|
/** @internal */
|
|
22
39
|
export const FormField$inboundSchema: z.ZodType<
|
|
23
40
|
FormField,
|
|
@@ -27,7 +44,7 @@ export const FormField$inboundSchema: z.ZodType<
|
|
|
27
44
|
id: z.string(),
|
|
28
45
|
object: z.string(),
|
|
29
46
|
name: z.string(),
|
|
30
|
-
field_type:
|
|
47
|
+
field_type: FormFieldFieldType$inboundSchema,
|
|
31
48
|
required: z.nullable(z.boolean()),
|
|
32
49
|
position: z.nullable(z.number().int()),
|
|
33
50
|
options: z.array(z.string()),
|
|
@@ -4,22 +4,154 @@
|
|
|
4
4
|
|
|
5
5
|
import * as z from "zod/v3";
|
|
6
6
|
import { remap as remap$ } from "../lib/primitives.js";
|
|
7
|
+
import { ClosedEnum } from "../types/enums.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* newsletter and contact have account-wide defaults; lead_magnet wraps a Blocks::LeadMagnet; custom is anything else.
|
|
11
|
+
*/
|
|
12
|
+
export const FormRequestPurpose = {
|
|
13
|
+
Newsletter: "newsletter",
|
|
14
|
+
Contact: "contact",
|
|
15
|
+
LeadMagnet: "lead_magnet",
|
|
16
|
+
Custom: "custom",
|
|
17
|
+
} as const;
|
|
18
|
+
/**
|
|
19
|
+
* newsletter and contact have account-wide defaults; lead_magnet wraps a Blocks::LeadMagnet; custom is anything else.
|
|
20
|
+
*/
|
|
21
|
+
export type FormRequestPurpose = ClosedEnum<typeof FormRequestPurpose>;
|
|
22
|
+
|
|
23
|
+
export const FormRequestFieldType = {
|
|
24
|
+
Email: "email",
|
|
25
|
+
Text: "text",
|
|
26
|
+
Phone: "phone",
|
|
27
|
+
Textarea: "textarea",
|
|
28
|
+
Radio: "radio",
|
|
29
|
+
Select: "select",
|
|
30
|
+
Checkbox: "checkbox",
|
|
31
|
+
} as const;
|
|
32
|
+
export type FormRequestFieldType = ClosedEnum<typeof FormRequestFieldType>;
|
|
33
|
+
|
|
34
|
+
export type FormFieldsAttribute = {
|
|
35
|
+
/**
|
|
36
|
+
* FormField id (omit when creating)
|
|
37
|
+
*/
|
|
38
|
+
id?: number | null | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* User-facing label
|
|
41
|
+
*/
|
|
42
|
+
name: string;
|
|
43
|
+
fieldType: FormRequestFieldType;
|
|
44
|
+
required?: boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Zero-based ordinal
|
|
47
|
+
*/
|
|
48
|
+
position?: number | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Required when field_type is radio/select/checkbox
|
|
51
|
+
*/
|
|
52
|
+
options?: Array<string> | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Set true to remove this field
|
|
55
|
+
*/
|
|
56
|
+
destroy?: boolean | undefined;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type FormRequestSettings = {};
|
|
7
60
|
|
|
8
61
|
export type FormRequest = {
|
|
9
62
|
name?: string | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* newsletter and contact have account-wide defaults; lead_magnet wraps a Blocks::LeadMagnet; custom is anything else.
|
|
65
|
+
*/
|
|
66
|
+
purpose?: FormRequestPurpose | undefined;
|
|
10
67
|
isPrimary?: boolean | undefined;
|
|
11
68
|
confirmationRequired?: boolean | undefined;
|
|
12
69
|
archivedAt?: Date | null | undefined;
|
|
13
70
|
tagIds?: Array<string> | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Nested-attributes payload for creating, updating, or destroying fields in one round-trip. Pass `id` to update an existing field; pass `_destroy: true` to remove one.
|
|
73
|
+
*/
|
|
74
|
+
formFieldsAttributes?: Array<FormFieldsAttribute> | undefined;
|
|
75
|
+
settings?: FormRequestSettings | undefined;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** @internal */
|
|
79
|
+
export const FormRequestPurpose$outboundSchema: z.ZodNativeEnum<
|
|
80
|
+
typeof FormRequestPurpose
|
|
81
|
+
> = z.nativeEnum(FormRequestPurpose);
|
|
82
|
+
|
|
83
|
+
/** @internal */
|
|
84
|
+
export const FormRequestFieldType$outboundSchema: z.ZodNativeEnum<
|
|
85
|
+
typeof FormRequestFieldType
|
|
86
|
+
> = z.nativeEnum(FormRequestFieldType);
|
|
87
|
+
|
|
88
|
+
/** @internal */
|
|
89
|
+
export type FormFieldsAttribute$Outbound = {
|
|
90
|
+
id?: number | null | undefined;
|
|
91
|
+
name: string;
|
|
92
|
+
field_type: string;
|
|
93
|
+
required?: boolean | undefined;
|
|
94
|
+
position?: number | undefined;
|
|
95
|
+
options?: Array<string> | undefined;
|
|
96
|
+
_destroy?: boolean | undefined;
|
|
14
97
|
};
|
|
15
98
|
|
|
99
|
+
/** @internal */
|
|
100
|
+
export const FormFieldsAttribute$outboundSchema: z.ZodType<
|
|
101
|
+
FormFieldsAttribute$Outbound,
|
|
102
|
+
z.ZodTypeDef,
|
|
103
|
+
FormFieldsAttribute
|
|
104
|
+
> = z.object({
|
|
105
|
+
id: z.nullable(z.number().int()).optional(),
|
|
106
|
+
name: z.string(),
|
|
107
|
+
fieldType: FormRequestFieldType$outboundSchema,
|
|
108
|
+
required: z.boolean().optional(),
|
|
109
|
+
position: z.number().int().optional(),
|
|
110
|
+
options: z.array(z.string()).optional(),
|
|
111
|
+
destroy: z.boolean().optional(),
|
|
112
|
+
}).transform((v) => {
|
|
113
|
+
return remap$(v, {
|
|
114
|
+
fieldType: "field_type",
|
|
115
|
+
destroy: "_destroy",
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
export function formFieldsAttributeToJSON(
|
|
120
|
+
formFieldsAttribute: FormFieldsAttribute,
|
|
121
|
+
): string {
|
|
122
|
+
return JSON.stringify(
|
|
123
|
+
FormFieldsAttribute$outboundSchema.parse(formFieldsAttribute),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** @internal */
|
|
128
|
+
export type FormRequestSettings$Outbound = {};
|
|
129
|
+
|
|
130
|
+
/** @internal */
|
|
131
|
+
export const FormRequestSettings$outboundSchema: z.ZodType<
|
|
132
|
+
FormRequestSettings$Outbound,
|
|
133
|
+
z.ZodTypeDef,
|
|
134
|
+
FormRequestSettings
|
|
135
|
+
> = z.object({});
|
|
136
|
+
|
|
137
|
+
export function formRequestSettingsToJSON(
|
|
138
|
+
formRequestSettings: FormRequestSettings,
|
|
139
|
+
): string {
|
|
140
|
+
return JSON.stringify(
|
|
141
|
+
FormRequestSettings$outboundSchema.parse(formRequestSettings),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
16
145
|
/** @internal */
|
|
17
146
|
export type FormRequest$Outbound = {
|
|
18
147
|
name?: string | undefined;
|
|
148
|
+
purpose?: string | undefined;
|
|
19
149
|
is_primary?: boolean | undefined;
|
|
20
150
|
confirmation_required?: boolean | undefined;
|
|
21
151
|
archived_at?: string | null | undefined;
|
|
22
152
|
tag_ids?: Array<string> | undefined;
|
|
153
|
+
form_fields_attributes?: Array<FormFieldsAttribute$Outbound> | undefined;
|
|
154
|
+
settings?: FormRequestSettings$Outbound | undefined;
|
|
23
155
|
};
|
|
24
156
|
|
|
25
157
|
/** @internal */
|
|
@@ -29,16 +161,22 @@ export const FormRequest$outboundSchema: z.ZodType<
|
|
|
29
161
|
FormRequest
|
|
30
162
|
> = z.object({
|
|
31
163
|
name: z.string().optional(),
|
|
164
|
+
purpose: FormRequestPurpose$outboundSchema.optional(),
|
|
32
165
|
isPrimary: z.boolean().optional(),
|
|
33
166
|
confirmationRequired: z.boolean().optional(),
|
|
34
167
|
archivedAt: z.nullable(z.date().transform(v => v.toISOString())).optional(),
|
|
35
168
|
tagIds: z.array(z.string()).optional(),
|
|
169
|
+
formFieldsAttributes: z.array(
|
|
170
|
+
z.lazy(() => FormFieldsAttribute$outboundSchema),
|
|
171
|
+
).optional(),
|
|
172
|
+
settings: z.lazy(() => FormRequestSettings$outboundSchema).optional(),
|
|
36
173
|
}).transform((v) => {
|
|
37
174
|
return remap$(v, {
|
|
38
175
|
isPrimary: "is_primary",
|
|
39
176
|
confirmationRequired: "confirmation_required",
|
|
40
177
|
archivedAt: "archived_at",
|
|
41
178
|
tagIds: "tag_ids",
|
|
179
|
+
formFieldsAttributes: "form_fields_attributes",
|
|
42
180
|
});
|
|
43
181
|
});
|
|
44
182
|
|
|
@@ -5,50 +5,31 @@
|
|
|
5
5
|
import * as z from "zod/v3";
|
|
6
6
|
import { remap as remap$ } from "../lib/primitives.js";
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Map of form question IDs to answer values
|
|
10
|
-
*/
|
|
11
|
-
export type Answers = {};
|
|
12
|
-
|
|
13
8
|
export type FormSubmissionRequest = {
|
|
14
9
|
/**
|
|
15
|
-
*
|
|
10
|
+
* Form prefix_id being submitted
|
|
16
11
|
*/
|
|
17
|
-
|
|
12
|
+
formId: string;
|
|
18
13
|
/**
|
|
19
14
|
* Respondent email address
|
|
20
15
|
*/
|
|
21
16
|
email: string;
|
|
22
17
|
/**
|
|
23
|
-
* Respondent name (defaults to
|
|
18
|
+
* Respondent name (defaults to email local-part if omitted)
|
|
24
19
|
*/
|
|
25
20
|
name?: string | null | undefined;
|
|
26
21
|
/**
|
|
27
|
-
* Map of
|
|
22
|
+
* Map of form_field id → answer value
|
|
28
23
|
*/
|
|
29
|
-
answers
|
|
24
|
+
answers: { [k: string]: any };
|
|
30
25
|
};
|
|
31
26
|
|
|
32
|
-
/** @internal */
|
|
33
|
-
export type Answers$Outbound = {};
|
|
34
|
-
|
|
35
|
-
/** @internal */
|
|
36
|
-
export const Answers$outboundSchema: z.ZodType<
|
|
37
|
-
Answers$Outbound,
|
|
38
|
-
z.ZodTypeDef,
|
|
39
|
-
Answers
|
|
40
|
-
> = z.object({});
|
|
41
|
-
|
|
42
|
-
export function answersToJSON(answers: Answers): string {
|
|
43
|
-
return JSON.stringify(Answers$outboundSchema.parse(answers));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
27
|
/** @internal */
|
|
47
28
|
export type FormSubmissionRequest$Outbound = {
|
|
48
|
-
|
|
29
|
+
form_id: string;
|
|
49
30
|
email: string;
|
|
50
31
|
name?: string | null | undefined;
|
|
51
|
-
answers
|
|
32
|
+
answers: { [k: string]: any };
|
|
52
33
|
};
|
|
53
34
|
|
|
54
35
|
/** @internal */
|
|
@@ -57,13 +38,13 @@ export const FormSubmissionRequest$outboundSchema: z.ZodType<
|
|
|
57
38
|
z.ZodTypeDef,
|
|
58
39
|
FormSubmissionRequest
|
|
59
40
|
> = z.object({
|
|
60
|
-
|
|
41
|
+
formId: z.string(),
|
|
61
42
|
email: z.string(),
|
|
62
43
|
name: z.nullable(z.string()).optional(),
|
|
63
|
-
answers: z.
|
|
44
|
+
answers: z.record(z.any()),
|
|
64
45
|
}).transform((v) => {
|
|
65
46
|
return remap$(v, {
|
|
66
|
-
|
|
47
|
+
formId: "form_id",
|
|
67
48
|
});
|
|
68
49
|
});
|
|
69
50
|
|