@crevio/sdk 0.4.16 → 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.
Files changed (71) hide show
  1. package/README.md +4 -2
  2. package/dist/commonjs/funcs/formsCreate.d.ts +3 -4
  3. package/dist/commonjs/funcs/formsCreate.d.ts.map +1 -1
  4. package/dist/commonjs/funcs/formsCreate.js +7 -14
  5. package/dist/commonjs/funcs/formsCreate.js.map +1 -1
  6. package/dist/commonjs/funcs/formsSubmit.d.ts +19 -0
  7. package/dist/commonjs/funcs/formsSubmit.d.ts.map +1 -0
  8. package/dist/commonjs/funcs/formsSubmit.js +126 -0
  9. package/dist/commonjs/funcs/formsSubmit.js.map +1 -0
  10. package/dist/commonjs/lib/config.d.ts +2 -2
  11. package/dist/commonjs/lib/config.js +2 -2
  12. package/dist/commonjs/models/form.d.ts +8 -8
  13. package/dist/commonjs/models/form.d.ts.map +1 -1
  14. package/dist/commonjs/models/form.js +10 -10
  15. package/dist/commonjs/models/form.js.map +1 -1
  16. package/dist/commonjs/models/formfield.d.ts +14 -1
  17. package/dist/commonjs/models/formfield.d.ts.map +1 -1
  18. package/dist/commonjs/models/formfield.js +13 -2
  19. package/dist/commonjs/models/formfield.js.map +1 -1
  20. package/dist/commonjs/models/formrequest.d.ts +83 -0
  21. package/dist/commonjs/models/formrequest.d.ts.map +1 -1
  22. package/dist/commonjs/models/formrequest.js +52 -1
  23. package/dist/commonjs/models/formrequest.js.map +1 -1
  24. package/dist/commonjs/models/formsubmissionrequest.d.ts +11 -16
  25. package/dist/commonjs/models/formsubmissionrequest.d.ts.map +1 -1
  26. package/dist/commonjs/models/formsubmissionrequest.js +4 -10
  27. package/dist/commonjs/models/formsubmissionrequest.js.map +1 -1
  28. package/dist/commonjs/sdk/forms.d.ts +8 -1
  29. package/dist/commonjs/sdk/forms.d.ts.map +1 -1
  30. package/dist/commonjs/sdk/forms.js +12 -2
  31. package/dist/commonjs/sdk/forms.js.map +1 -1
  32. package/dist/esm/funcs/formsCreate.d.ts +3 -4
  33. package/dist/esm/funcs/formsCreate.d.ts.map +1 -1
  34. package/dist/esm/funcs/formsCreate.js +8 -15
  35. package/dist/esm/funcs/formsCreate.js.map +1 -1
  36. package/dist/esm/funcs/formsSubmit.d.ts +19 -0
  37. package/dist/esm/funcs/formsSubmit.d.ts.map +1 -0
  38. package/dist/esm/funcs/formsSubmit.js +90 -0
  39. package/dist/esm/funcs/formsSubmit.js.map +1 -0
  40. package/dist/esm/lib/config.d.ts +2 -2
  41. package/dist/esm/lib/config.js +2 -2
  42. package/dist/esm/models/form.d.ts +8 -8
  43. package/dist/esm/models/form.d.ts.map +1 -1
  44. package/dist/esm/models/form.js +8 -8
  45. package/dist/esm/models/form.js.map +1 -1
  46. package/dist/esm/models/formfield.d.ts +14 -1
  47. package/dist/esm/models/formfield.d.ts.map +1 -1
  48. package/dist/esm/models/formfield.js +12 -1
  49. package/dist/esm/models/formfield.js.map +1 -1
  50. package/dist/esm/models/formrequest.d.ts +83 -0
  51. package/dist/esm/models/formrequest.d.ts.map +1 -1
  52. package/dist/esm/models/formrequest.js +49 -0
  53. package/dist/esm/models/formrequest.js.map +1 -1
  54. package/dist/esm/models/formsubmissionrequest.d.ts +11 -16
  55. package/dist/esm/models/formsubmissionrequest.d.ts.map +1 -1
  56. package/dist/esm/models/formsubmissionrequest.js +3 -8
  57. package/dist/esm/models/formsubmissionrequest.js.map +1 -1
  58. package/dist/esm/sdk/forms.d.ts +8 -1
  59. package/dist/esm/sdk/forms.d.ts.map +1 -1
  60. package/dist/esm/sdk/forms.js +12 -2
  61. package/dist/esm/sdk/forms.js.map +1 -1
  62. package/jsr.json +1 -1
  63. package/package.json +1 -1
  64. package/src/funcs/formsCreate.ts +14 -22
  65. package/src/funcs/formsSubmit.ts +180 -0
  66. package/src/lib/config.ts +2 -2
  67. package/src/models/form.ts +15 -15
  68. package/src/models/formfield.ts +19 -2
  69. package/src/models/formrequest.ts +138 -0
  70. package/src/models/formsubmissionrequest.ts +10 -29
  71. package/src/sdk/forms.ts +20 -2
@@ -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.16",
64
+ sdkVersion: "0.4.17",
65
65
  genVersion: "2.882.0",
66
- userAgent: "speakeasy-sdk/typescript 0.4.16 2.882.0 1.0.0 @crevio/sdk",
66
+ userAgent: "speakeasy-sdk/typescript 0.4.17 2.882.0 1.0.0 @crevio/sdk",
67
67
  } as const;
@@ -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 Purpose = {
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 Purpose = ClosedEnum<typeof Purpose>;
19
+ export type FormPurpose = ClosedEnum<typeof FormPurpose>;
20
20
 
21
- export type Settings = {};
21
+ export type FormSettings = {};
22
22
 
23
23
  export type Form = {
24
24
  id: string;
25
25
  object: string;
26
- purpose: Purpose;
26
+ purpose: FormPurpose;
27
27
  name: string;
28
28
  isPrimary: boolean;
29
29
  confirmationRequired: boolean;
30
- settings: 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 Purpose$inboundSchema: z.ZodNativeEnum<typeof Purpose> = z
40
- .nativeEnum(Purpose);
39
+ export const FormPurpose$inboundSchema: z.ZodNativeEnum<typeof FormPurpose> = z
40
+ .nativeEnum(FormPurpose);
41
41
 
42
42
  /** @internal */
43
- export const Settings$inboundSchema: z.ZodType<
44
- Settings,
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 settingsFromJSON(
49
+ export function formSettingsFromJSON(
50
50
  jsonString: string,
51
- ): SafeParseResult<Settings, SDKValidationError> {
51
+ ): SafeParseResult<FormSettings, SDKValidationError> {
52
52
  return safeParse(
53
53
  jsonString,
54
- (x) => Settings$inboundSchema.parse(JSON.parse(x)),
55
- `Failed to parse 'Settings' from JSON`,
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: Purpose$inboundSchema,
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(() => Settings$inboundSchema),
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)),
@@ -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: string;
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: z.string(),
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
- * ID of the lead magnet block being submitted
10
+ * Form prefix_id being submitted
16
11
  */
17
- leadMagnetId: string;
12
+ formId: string;
18
13
  /**
19
14
  * Respondent email address
20
15
  */
21
16
  email: string;
22
17
  /**
23
- * Respondent name (defaults to 'Lead' if omitted)
18
+ * Respondent name (defaults to email local-part if omitted)
24
19
  */
25
20
  name?: string | null | undefined;
26
21
  /**
27
- * Map of form question IDs to answer values
22
+ * Map of form_field id answer value
28
23
  */
29
- answers?: Answers | undefined;
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
- lead_magnet_id: string;
29
+ form_id: string;
49
30
  email: string;
50
31
  name?: string | null | undefined;
51
- answers?: Answers$Outbound | undefined;
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
- leadMagnetId: z.string(),
41
+ formId: z.string(),
61
42
  email: z.string(),
62
43
  name: z.nullable(z.string()).optional(),
63
- answers: z.lazy(() => Answers$outboundSchema).optional(),
44
+ answers: z.record(z.any()),
64
45
  }).transform((v) => {
65
46
  return remap$(v, {
66
- leadMagnetId: "lead_magnet_id",
47
+ formId: "form_id",
67
48
  });
68
49
  });
69
50
 
package/src/sdk/forms.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  import { formsCreate } from "../funcs/formsCreate.js";
6
6
  import { formsGet } from "../funcs/formsGet.js";
7
7
  import { formsList } from "../funcs/formsList.js";
8
+ import { formsSubmit } from "../funcs/formsSubmit.js";
8
9
  import { formsUpdate } from "../funcs/formsUpdate.js";
9
10
  import { ClientSDK, RequestOptions } from "../lib/sdks.js";
10
11
  import * as models from "../models/index.js";
@@ -29,17 +30,34 @@ export class Forms extends ClientSDK {
29
30
  ));
30
31
  }
31
32
 
33
+ /**
34
+ * Create form
35
+ *
36
+ * @remarks
37
+ * 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.
38
+ */
39
+ async create(
40
+ request: models.FormRequest,
41
+ options?: RequestOptions,
42
+ ): Promise<models.Form> {
43
+ return unwrapAsync(formsCreate(
44
+ this,
45
+ request,
46
+ options,
47
+ ));
48
+ }
49
+
32
50
  /**
33
51
  * Create form submission
34
52
  *
35
53
  * @remarks
36
54
  * Submits an answer set to a specific Form. Customer is upserted by email; lead-magnet purpose forms also trigger delivery.
37
55
  */
38
- async create(
56
+ async submit(
39
57
  request: operations.CreateFormSubmissionForFormRequest,
40
58
  options?: RequestOptions,
41
59
  ): Promise<models.FormSubmission> {
42
- return unwrapAsync(formsCreate(
60
+ return unwrapAsync(formsSubmit(
43
61
  this,
44
62
  request,
45
63
  options,