Skip to content

Commit cf3bf08

Browse files
authored
Rename *Request schemas to *Params (#8)
1 parent 2e7e4f2 commit cf3bf08

File tree

7 files changed

+83
-75
lines changed

7 files changed

+83
-75
lines changed

src/client/snippets.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
CreateSnippetRequest,
2+
CreateSnippetParams,
33
CreateSnippetResponse,
44
CreateSnippetResponseSchema,
55
DeleteSnippetParams,
@@ -11,7 +11,6 @@ import {
1111
GetSnippetsResponse,
1212
GetSnippetsResponseSchema,
1313
UpdateSnippetParams,
14-
UpdateSnippetRequest,
1514
UpdateSnippetResponse,
1615
UpdateSnippetResponseSchema,
1716
} from "../types/snippets.js";
@@ -33,7 +32,7 @@ export function Snippets<T extends Constructor<BaseIterableClient>>(Base: T) {
3332
}
3433

3534
async createSnippet(
36-
params: CreateSnippetRequest,
35+
params: CreateSnippetParams,
3736
opts?: { signal?: AbortSignal }
3837
): Promise<CreateSnippetResponse> {
3938
const response = await this.client.post("/api/snippets", params, opts);
@@ -53,11 +52,11 @@ export function Snippets<T extends Constructor<BaseIterableClient>>(Base: T) {
5352

5453
async updateSnippet(
5554
params: UpdateSnippetParams,
56-
body: UpdateSnippetRequest,
5755
opts?: { signal?: AbortSignal }
5856
): Promise<UpdateSnippetResponse> {
57+
const { identifier, ...body } = params;
5958
const response = await this.client.put(
60-
`/api/snippets/${params.identifier}`,
59+
`/api/snippets/${identifier}`,
6160
body,
6261
opts
6362
);

src/client/templates.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import {
1919
PreviewTemplateParams,
2020
PushTemplate,
2121
PushTemplateSchema,
22+
SendTemplateProofParams,
2223
SMSTemplate,
2324
SMSTemplateSchema,
24-
TemplateProofRequest,
2525
UpdateEmailTemplateParams,
2626
UpdateInAppTemplateParams,
2727
UpdatePushTemplateParams,
@@ -91,7 +91,7 @@ export function Templates<T extends Constructor<BaseIterableClient>>(Base: T) {
9191

9292
async #sendTemplateProof(
9393
pathSegment: string,
94-
request: TemplateProofRequest
94+
request: SendTemplateProofParams
9595
): Promise<IterableSuccessResponse> {
9696
const response = await this.client.post(
9797
`/api/templates/${pathSegment}/proof`,
@@ -181,7 +181,7 @@ export function Templates<T extends Constructor<BaseIterableClient>>(Base: T) {
181181
}
182182

183183
async sendEmailTemplateProof(
184-
request: TemplateProofRequest
184+
request: SendTemplateProofParams
185185
): Promise<IterableSuccessResponse> {
186186
return this.#sendTemplateProof("email", request);
187187
}
@@ -208,7 +208,7 @@ export function Templates<T extends Constructor<BaseIterableClient>>(Base: T) {
208208
}
209209

210210
async sendSMSTemplateProof(
211-
request: TemplateProofRequest
211+
request: SendTemplateProofParams
212212
): Promise<IterableSuccessResponse> {
213213
return this.#sendTemplateProof("sms", request);
214214
}
@@ -231,7 +231,7 @@ export function Templates<T extends Constructor<BaseIterableClient>>(Base: T) {
231231
}
232232

233233
async sendPushTemplateProof(
234-
request: TemplateProofRequest
234+
request: SendTemplateProofParams
235235
): Promise<IterableSuccessResponse> {
236236
return this.#sendTemplateProof("push", request);
237237
}
@@ -254,7 +254,7 @@ export function Templates<T extends Constructor<BaseIterableClient>>(Base: T) {
254254
}
255255

256256
async sendInAppTemplateProof(
257-
request: TemplateProofRequest
257+
request: SendTemplateProofParams
258258
): Promise<IterableSuccessResponse> {
259259
return this.#sendTemplateProof("inapp", request);
260260
}

src/types/snippets.ts

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export const SnippetResponseSchema = z.object({
3030

3131
export type SnippetResponse = z.infer<typeof SnippetResponseSchema>;
3232

33-
// Request schemas
34-
export const CreateSnippetRequestSchema = z.object({
33+
// Parameter schemas for creating snippets
34+
export const CreateSnippetParamsSchema = z.object({
3535
content: z
3636
.string()
3737
.describe(
@@ -57,30 +57,7 @@ export const CreateSnippetRequestSchema = z.object({
5757
),
5858
});
5959

60-
export type CreateSnippetRequest = z.infer<typeof CreateSnippetRequestSchema>;
61-
62-
export const UpdateSnippetRequestSchema = z.object({
63-
content: z
64-
.string()
65-
.describe(
66-
'Content of the snippet. Handlebars must be valid. Disallowed content: script tags with JS sources or non-JSON content, inline JS event handlers (e.g., onload="..."), and javascript: in href or src attributes (anchors and iframes).'
67-
),
68-
description: z.string().optional().describe("Description of the snippet"),
69-
createdByUserId: z
70-
.string()
71-
.optional()
72-
.describe(
73-
"User ID (email) of the updater. If not provided, defaults to the project creator."
74-
),
75-
variables: z
76-
.array(z.string())
77-
.optional()
78-
.describe(
79-
"List of variable names used in the content with a Handlebars expression such as {{myField}}. Variable names are case-sensitive and should be simple identifiers (letters, numbers, underscores). To learn more about using Handlebars in Snippets, see Customizing Snippets with Variables."
80-
),
81-
});
82-
83-
export type UpdateSnippetRequest = z.infer<typeof UpdateSnippetRequestSchema>;
60+
export type CreateSnippetParams = z.infer<typeof CreateSnippetParamsSchema>;
8461

8562
// Response schemas
8663
export const GetSnippetsResponseSchema = z.object({
@@ -113,7 +90,7 @@ export const DeleteSnippetResponseSchema = z.object({
11390

11491
export type DeleteSnippetResponse = z.infer<typeof DeleteSnippetResponseSchema>;
11592

116-
// Parameter schemas
93+
// Identifier schema for get/update/delete operations
11794
export const SnippetIdentifierSchema = z
11895
.union([
11996
z.string().describe("Snippet name"),
@@ -133,6 +110,24 @@ export type GetSnippetParams = z.infer<typeof GetSnippetParamsSchema>;
133110

134111
export const UpdateSnippetParamsSchema = z.object({
135112
identifier: SnippetIdentifierSchema,
113+
content: z
114+
.string()
115+
.describe(
116+
'Content of the snippet. Handlebars must be valid. Disallowed content: script tags with JS sources or non-JSON content, inline JS event handlers (e.g., onload="..."), and javascript: in href or src attributes (anchors and iframes).'
117+
),
118+
description: z.string().optional().describe("Description of the snippet"),
119+
createdByUserId: z
120+
.string()
121+
.optional()
122+
.describe(
123+
"User ID (email) of the updater. If not provided, defaults to the project creator."
124+
),
125+
variables: z
126+
.array(z.string())
127+
.optional()
128+
.describe(
129+
"List of variable names used in the content with a Handlebars expression such as {{myField}}. Variable names are case-sensitive and should be simple identifiers (letters, numbers, underscores). To learn more about using Handlebars in Snippets, see Customizing Snippets with Variables."
130+
),
136131
});
137132

138133
export type UpdateSnippetParams = z.infer<typeof UpdateSnippetParamsSchema>;

src/types/templates.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ export type BulkDeleteTemplatesResponse = z.infer<
459459
>;
460460

461461
// Template proof schemas
462-
export const TemplateProofRequestSchema = z
462+
export const SendTemplateProofParamsSchema = z
463463
.object({
464464
templateId: z.number().describe("Template ID to send proof for"),
465465
recipientEmail: z
@@ -490,7 +490,9 @@ export const TemplateProofRequestSchema = z
490490
path: ["recipientEmail", "recipientUserId"],
491491
});
492492

493-
export type TemplateProofRequest = z.infer<typeof TemplateProofRequestSchema>;
493+
export type SendTemplateProofParams = z.infer<
494+
typeof SendTemplateProofParamsSchema
495+
>;
494496

495497
// Template preview schemas
496498
export const TemplatePreviewRequestSchema = z.object({

tests/integration/snippets.test.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,12 @@ describe("Snippets Management Integration Tests", () => {
141141
const updateResponse = await retryRateLimited(
142142
() =>
143143
withTimeout(
144-
client.updateSnippet(
145-
{ identifier: testSnippetName },
146-
{
147-
content: updatedContent,
148-
description: "Updated CRUD test snippet",
149-
variables: ["firstName", "company"],
150-
}
151-
)
144+
client.updateSnippet({
145+
identifier: testSnippetName,
146+
content: updatedContent,
147+
description: "Updated CRUD test snippet",
148+
variables: ["firstName", "company"],
149+
})
152150
),
153151
"Update snippet by name"
154152
);
@@ -160,13 +158,11 @@ describe("Snippets Management Integration Tests", () => {
160158
const updateByIdResponse = await retryRateLimited(
161159
() =>
162160
withTimeout(
163-
client.updateSnippet(
164-
{ identifier: snippetId },
165-
{
166-
content: updateByIdContent,
167-
variables: ["user"],
168-
}
169-
)
161+
client.updateSnippet({
162+
identifier: snippetId,
163+
content: updateByIdContent,
164+
variables: ["user"],
165+
})
170166
),
171167
"Update snippet by ID"
172168
);

tests/unit/snippets.test.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99

1010
import { IterableClient } from "../../src/client";
1111
import {
12-
CreateSnippetRequestSchema,
12+
CreateSnippetParamsSchema,
1313
SnippetResponseSchema,
14-
UpdateSnippetRequestSchema,
14+
UpdateSnippetParamsSchema,
1515
} from "../../src/types/snippets.js";
1616
import { createMockClient, createMockSnippet } from "../utils/test-helpers";
1717

@@ -158,15 +158,19 @@ describe("Snippets Management", () => {
158158
mockAxiosInstance.put.mockResolvedValue(mockResponse);
159159

160160
const params = {
161+
identifier: "test-snippet",
161162
content: "<p>Updated content {{name}}!</p>",
162163
description: "Updated description",
163164
};
164165

165-
await client.updateSnippet({ identifier: "test-snippet" }, params);
166+
await client.updateSnippet(params);
166167

167168
expect(mockAxiosInstance.put).toHaveBeenCalledWith(
168169
"/api/snippets/test-snippet",
169-
params,
170+
{
171+
content: "<p>Updated content {{name}}!</p>",
172+
description: "Updated description",
173+
},
170174
undefined
171175
);
172176
});
@@ -176,10 +180,11 @@ describe("Snippets Management", () => {
176180
mockAxiosInstance.put.mockResolvedValue(mockResponse);
177181

178182
const params = {
183+
identifier: 12345,
179184
content: "<p>Updated content!</p>",
180185
};
181186

182-
const result = await client.updateSnippet({ identifier: 12345 }, params);
187+
const result = await client.updateSnippet(params);
183188

184189
expect(result).toHaveProperty("snippetId", 12345);
185190
});
@@ -241,7 +246,7 @@ describe("Snippets Management", () => {
241246
).toThrow();
242247
});
243248

244-
it("should validate create snippet request schema", () => {
249+
it("should validate create snippet params schema", () => {
245250
const validRequest = {
246251
name: "test-snippet",
247252
content: "<p>Hello {{name}}!</p>",
@@ -251,53 +256,64 @@ describe("Snippets Management", () => {
251256

252257
// Valid request
253258
expect(() =>
254-
CreateSnippetRequestSchema.parse(validRequest)
259+
CreateSnippetParamsSchema.parse(validRequest)
255260
).not.toThrow();
256261

257262
// Missing required fields
258263
expect(() =>
259-
CreateSnippetRequestSchema.parse({ ...validRequest, name: undefined })
264+
CreateSnippetParamsSchema.parse({ ...validRequest, name: undefined })
260265
).toThrow();
261266

262267
expect(() =>
263-
CreateSnippetRequestSchema.parse({
268+
CreateSnippetParamsSchema.parse({
264269
...validRequest,
265270
content: undefined,
266271
})
267272
).toThrow();
268273

269274
// Optional fields should work
270275
expect(() =>
271-
CreateSnippetRequestSchema.parse({
276+
CreateSnippetParamsSchema.parse({
272277
name: "test",
273278
content: "<p>Test</p>",
274279
})
275280
).not.toThrow();
276281
});
277282

278-
it("should validate update snippet request schema", () => {
283+
it("should validate update snippet params schema", () => {
279284
const validRequest = {
285+
identifier: "test-snippet",
280286
content: "<p>Updated content {{name}}!</p>",
281287
description: "Updated description",
282288
variables: ["name"],
283289
};
284290

285291
// Valid request
286292
expect(() =>
287-
UpdateSnippetRequestSchema.parse(validRequest)
293+
UpdateSnippetParamsSchema.parse(validRequest)
288294
).not.toThrow();
289295

290-
// Content is required for updates
296+
// Identifier and content are required for updates
297+
expect(() =>
298+
UpdateSnippetParamsSchema.parse({
299+
...validRequest,
300+
identifier: undefined,
301+
})
302+
).toThrow();
303+
291304
expect(() =>
292-
UpdateSnippetRequestSchema.parse({
305+
UpdateSnippetParamsSchema.parse({
293306
...validRequest,
294307
content: undefined,
295308
})
296309
).toThrow();
297310

298311
// Other fields are optional
299312
expect(() =>
300-
UpdateSnippetRequestSchema.parse({ content: "<p>Test</p>" })
313+
UpdateSnippetParamsSchema.parse({
314+
identifier: 12345,
315+
content: "<p>Test</p>",
316+
})
301317
).not.toThrow();
302318
});
303319
});

0 commit comments

Comments
 (0)