Skip to content

Commit fdf4ce8

Browse files
committed
Use params schemas for all methods
1 parent dd2ae2b commit fdf4ce8

File tree

17 files changed

+129
-82
lines changed

17 files changed

+129
-82
lines changed

src/client/catalogs.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import {
44
CatalogFieldMappingsResponseSchema,
55
CatalogItemWithProperties,
66
CatalogItemWithPropertiesSchema,
7+
CreateCatalogParams,
8+
DeleteCatalogItemParams,
9+
DeleteCatalogParams,
710
GetCatalogFieldMappingsParams,
11+
GetCatalogItemParams,
812
GetCatalogItemsParams,
913
GetCatalogItemsResponse,
1014
GetCatalogItemsResponseSchema,
@@ -28,9 +32,11 @@ import type { BaseIterableClient } from "./base.js";
2832
*/
2933
export function Catalogs<T extends Constructor<BaseIterableClient>>(Base: T) {
3034
return class extends Base {
31-
async createCatalog(catalogName: string): Promise<IterableSuccessResponse> {
35+
async createCatalog(
36+
params: CreateCatalogParams
37+
): Promise<IterableSuccessResponse> {
3238
const response = await this.client.post(
33-
`/api/catalogs/${encodeURIComponent(catalogName)}`
39+
`/api/catalogs/${encodeURIComponent(params.catalogName)}`
3440
);
3541
return this.validateResponse(response, IterableSuccessResponseSchema);
3642
}
@@ -63,21 +69,19 @@ export function Catalogs<T extends Constructor<BaseIterableClient>>(Base: T) {
6369
}
6470

6571
async getCatalogItem(
66-
catalogName: string,
67-
itemId: string
72+
params: GetCatalogItemParams
6873
): Promise<CatalogItemWithProperties> {
6974
const response = await this.client.get(
70-
`/api/catalogs/${encodeURIComponent(catalogName)}/items/${encodeURIComponent(itemId)}`
75+
`/api/catalogs/${encodeURIComponent(params.catalogName)}/items/${encodeURIComponent(params.itemId)}`
7176
);
7277
return this.validateResponse(response, CatalogItemWithPropertiesSchema);
7378
}
7479

7580
async deleteCatalogItem(
76-
catalogName: string,
77-
itemId: string
81+
params: DeleteCatalogItemParams
7882
): Promise<IterableSuccessResponse> {
7983
const response = await this.client.delete(
80-
`/api/catalogs/${encodeURIComponent(catalogName)}/items/${encodeURIComponent(itemId)}`
84+
`/api/catalogs/${encodeURIComponent(params.catalogName)}/items/${encodeURIComponent(params.itemId)}`
8185
);
8286
return this.validateResponse(response, IterableSuccessResponseSchema);
8387
}
@@ -168,9 +172,11 @@ export function Catalogs<T extends Constructor<BaseIterableClient>>(Base: T) {
168172
/**
169173
* Delete a catalog
170174
*/
171-
async deleteCatalog(catalogName: string): Promise<IterableSuccessResponse> {
175+
async deleteCatalog(
176+
params: DeleteCatalogParams
177+
): Promise<IterableSuccessResponse> {
172178
const response = await this.client.delete(
173-
`/api/catalogs/${encodeURIComponent(catalogName)}`
179+
`/api/catalogs/${encodeURIComponent(params.catalogName)}`
174180
);
175181
return this.validateResponse(response, IterableSuccessResponseSchema);
176182
}

src/client/lists.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
CreateListParams,
77
CreateListResponse,
88
CreateListResponseSchema,
9+
DeleteListParams,
910
GetListPreviewUsersParams,
1011
GetListPreviewUsersResponse,
1112
GetListPreviewUsersResponseSchema,
@@ -91,8 +92,8 @@ export function Lists<T extends Constructor<BaseIterableClient>>(Base: T) {
9192
return this.validateResponse(response, CreateListResponseSchema);
9293
}
9394

94-
async deleteList(listId: number): Promise<IterableSuccessResponse> {
95-
const response = await this.client.delete(`/api/lists/${listId}`);
95+
async deleteList(params: DeleteListParams): Promise<IterableSuccessResponse> {
96+
const response = await this.client.delete(`/api/lists/${params.listId}`);
9697
return this.validateResponse(response, IterableSuccessResponseSchema);
9798
}
9899

src/client/templates.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
BulkDeleteTemplatesResponseSchema,
1212
EmailTemplate,
1313
EmailTemplateSchema,
14+
GetTemplateByClientIdParams,
1415
GetTemplateByClientIdResponse,
1516
GetTemplateByClientIdResponseSchema,
1617
GetTemplateParams,
@@ -145,12 +146,12 @@ export function Templates<T extends Constructor<BaseIterableClient>>(Base: T) {
145146
}
146147

147148
async getTemplateByClientId(
148-
clientTemplateId: string
149+
params: GetTemplateByClientIdParams
149150
): Promise<GetTemplateByClientIdResponse> {
150151
const response = await this.client.get(
151152
"/api/templates/getByClientTemplateId",
152153
{
153-
params: { clientTemplateId },
154+
params: { clientTemplateId: params.clientTemplateId },
154155
}
155156
);
156157
return this.validateResponse(
@@ -174,9 +175,9 @@ export function Templates<T extends Constructor<BaseIterableClient>>(Base: T) {
174175
* @deprecated Use {@link bulkDeleteTemplates} instead
175176
*/
176177
async deleteTemplates(
177-
templateIds: number[]
178+
params: BulkDeleteTemplatesParams
178179
): Promise<BulkDeleteTemplatesResponse> {
179-
return this.bulkDeleteTemplates({ ids: templateIds });
180+
return this.bulkDeleteTemplates(params);
180181
}
181182

182183
// Email Template Management

src/client/users.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import {
88
} from "../types/lists.js";
99
import {
1010
BulkUpdateUsersParams,
11+
DeleteUserByEmailParams,
12+
DeleteUserByUserIdParams,
1113
GetSentMessagesParams,
1214
GetSentMessagesResponse,
1315
GetSentMessagesResponseSchema,
16+
GetUserByEmailParams,
17+
GetUserByIdParams,
1418
GetUserFieldsResponse,
1519
GetUserFieldsResponseSchema,
1620
UpdateEmailParams,
@@ -30,12 +34,10 @@ export function Users<T extends Constructor<BaseIterableClient>>(Base: T) {
3034
* Get a user by email address
3135
*/
3236
async getUserByEmail(
33-
email: string,
34-
opts?: { signal?: AbortSignal }
37+
params: GetUserByEmailParams
3538
): Promise<UserResponse> {
3639
const response = await this.client.get(
37-
`/api/users/${encodeURIComponent(email)}`,
38-
opts?.signal ? { signal: opts.signal } : {}
40+
`/api/users/${encodeURIComponent(params.email)}`
3941
);
4042
return this.validateResponse(response, UserResponseSchema);
4143
}
@@ -44,12 +46,10 @@ export function Users<T extends Constructor<BaseIterableClient>>(Base: T) {
4446
* Get a user by userId
4547
*/
4648
async getUserByUserId(
47-
userId: string,
48-
opts?: { signal?: AbortSignal }
49+
params: GetUserByIdParams
4950
): Promise<UserResponse> {
5051
const response = await this.client.get(
51-
`/api/users/byUserId/${encodeURIComponent(userId)}`,
52-
opts?.signal ? { signal: opts.signal } : {}
52+
`/api/users/byUserId/${encodeURIComponent(params.userId)}`
5353
);
5454
return this.validateResponse(response, UserResponseSchema);
5555
}
@@ -69,9 +69,11 @@ export function Users<T extends Constructor<BaseIterableClient>>(Base: T) {
6969
* Delete a user by email address
7070
* Asynchronous operation - does not prevent future data collection
7171
*/
72-
async deleteUserByEmail(email: string): Promise<IterableSuccessResponse> {
72+
async deleteUserByEmail(
73+
params: DeleteUserByEmailParams
74+
): Promise<IterableSuccessResponse> {
7375
const response = await this.client.delete(
74-
`/api/users/${encodeURIComponent(email)}`
76+
`/api/users/${encodeURIComponent(params.email)}`
7577
);
7678
return this.validateResponse(response, IterableSuccessResponseSchema);
7779
}
@@ -81,9 +83,11 @@ export function Users<T extends Constructor<BaseIterableClient>>(Base: T) {
8183
* Asynchronous operation - does not prevent future data collection
8284
* If multiple users share the same userId, they'll all be deleted
8385
*/
84-
async deleteUserByUserId(userId: string): Promise<IterableSuccessResponse> {
86+
async deleteUserByUserId(
87+
params: DeleteUserByUserIdParams
88+
): Promise<IterableSuccessResponse> {
8589
const response = await this.client.delete(
86-
`/api/users/byUserId/${encodeURIComponent(userId)}`
90+
`/api/users/byUserId/${encodeURIComponent(params.userId)}`
8791
);
8892
return this.validateResponse(response, IterableSuccessResponseSchema);
8993
}

src/types/catalogs.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ export type GetCatalogFieldMappingsParams = z.infer<
109109
>;
110110
export type CreateCatalogParams = z.infer<typeof CreateCatalogParamsSchema>;
111111

112+
export const DeleteCatalogParamsSchema = z.object({
113+
catalogName: z
114+
.string()
115+
.max(255)
116+
.regex(/^[a-zA-Z0-9-]+$/)
117+
.describe("Name of the catalog to delete"),
118+
});
119+
120+
export type DeleteCatalogParams = z.infer<typeof DeleteCatalogParamsSchema>;
121+
112122
// Catalog items schemas
113123
export const CatalogItemWithPropertiesSchema = z.object({
114124
catalogName: z.string(),

src/types/users.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const GetUserByEmailParamsSchema = z.object({
3535
email: z.email().describe("Email address of the user to retrieve"),
3636
});
3737

38+
export type GetUserByEmailParams = z.infer<typeof GetUserByEmailParamsSchema>;
39+
3840
export const UpdateUserParamsSchema = z
3941
.object({
4042
email: z.email().optional().describe("User email address"),
@@ -69,6 +71,8 @@ export const GetUserByIdParamsSchema = z.object({
6971
userId: z.string().describe("User ID to retrieve"),
7072
});
7173

74+
export type GetUserByIdParams = z.infer<typeof GetUserByIdParamsSchema>;
75+
7276
export const BulkUpdateUsersParamsSchema = z.object({
7377
users: z
7478
.array(
@@ -95,10 +99,18 @@ export const DeleteUserByEmailParamsSchema = z.object({
9599
email: z.email().describe("Email address of the user to delete"),
96100
});
97101

102+
export type DeleteUserByEmailParams = z.infer<
103+
typeof DeleteUserByEmailParamsSchema
104+
>;
105+
98106
export const DeleteUserByUserIdParamsSchema = z.object({
99107
userId: z.string().describe("User ID of the user to delete"),
100108
});
101109

110+
export type DeleteUserByUserIdParams = z.infer<
111+
typeof DeleteUserByUserIdParamsSchema
112+
>;
113+
102114
export const UserEventsResponseSchema = z.object({
103115
events: z.array(z.record(z.string(), z.any())),
104116
});

tests/integration/campaigns.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ describe("Campaign Management Integration Tests", () => {
161161

162162
if (createdTestList) {
163163
try {
164-
await withTimeout(client.deleteList(testListId));
164+
await withTimeout(client.deleteList({ listId: testListId }));
165165
} catch (error) {
166166
console.warn(`Failed to delete test list ${testListId}:`, error);
167167
}
168168
}
169169

170170
if (createdTestTemplate) {
171171
try {
172-
await withTimeout(client.deleteTemplates([testTemplateId]));
172+
await withTimeout(client.deleteTemplates({ ids: [testTemplateId] }));
173173
} catch (error) {
174174
console.warn(`Failed to delete test template ${testTemplateId}:`, error);
175175
}

tests/integration/catalogs.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe("Catalog Management Integration Tests", () => {
2525

2626
it("get nonexistent catalog item should 404", async () => {
2727
await expect(
28-
client.getCatalogItem("nonexistent-catalog", "nonexistent-item")
28+
client.getCatalogItem({ catalogName: "nonexistent-catalog", itemId: "nonexistent-item" })
2929
).rejects.toMatchObject({
3030
statusCode: 404,
3131
});
@@ -42,7 +42,7 @@ describe("Catalog Management Integration Tests", () => {
4242
it("should get catalog field mappings with correct structure", async () => {
4343
// Create a test catalog
4444
const catalogName = uniqueId("test-catalog-mappings");
45-
await withTimeout(client.createCatalog(catalogName));
45+
await withTimeout(client.createCatalog({ catalogName }));
4646

4747
// Add some items to the catalog with various field types
4848
await withTimeout(
@@ -77,7 +77,7 @@ describe("Catalog Management Integration Tests", () => {
7777
it("should get catalog items", async () => {
7878
// Always create a fresh test catalog to ensure clean test state
7979
const catalogName = uniqueId("test-catalog-items");
80-
await withTimeout(client.createCatalog(catalogName));
80+
await withTimeout(client.createCatalog({ catalogName }));
8181

8282
const itemId1 = uniqueId("catalog-items-test-1");
8383
const itemId2 = uniqueId("catalog-items-test-2");
@@ -128,7 +128,7 @@ describe("Catalog Management Integration Tests", () => {
128128
it("should handle pagination parameters for catalog items", async () => {
129129
// Always create a fresh test catalog for pagination testing
130130
const catalogName = uniqueId("test-catalog-pagination");
131-
await withTimeout(client.createCatalog(catalogName));
131+
await withTimeout(client.createCatalog({ catalogName }));
132132

133133
const itemId1 = uniqueId("pagination-test-1");
134134
const itemId2 = uniqueId("pagination-test-2");
@@ -196,10 +196,10 @@ describe("Catalog Management Integration Tests", () => {
196196
it("should delete a catalog", async () => {
197197
// Create a test catalog to delete
198198
const catalogName = uniqueId("test-catalog-delete");
199-
await withTimeout(client.createCatalog(catalogName));
199+
await withTimeout(client.createCatalog({ catalogName }));
200200

201201
// Delete the catalog
202-
const result = await withTimeout(client.deleteCatalog(catalogName));
202+
const result = await withTimeout(client.deleteCatalog({ catalogName }));
203203

204204
expect(result).toBeDefined();
205205
expect(result).toHaveProperty("msg");
@@ -212,7 +212,7 @@ describe("Catalog Management Integration Tests", () => {
212212
it("should update catalog field mappings", async () => {
213213
// Create a test catalog
214214
const catalogName = uniqueId("test-catalog-field-mappings");
215-
await withTimeout(client.createCatalog(catalogName));
215+
await withTimeout(client.createCatalog({ catalogName }));
216216

217217
// Add items with some fields first
218218
await withTimeout(
@@ -258,7 +258,7 @@ describe("Catalog Management Integration Tests", () => {
258258
it("should bulk delete catalog items", async () => {
259259
// Create a test catalog
260260
const catalogName = uniqueId("test-catalog-bulk-delete");
261-
await withTimeout(client.createCatalog(catalogName));
261+
await withTimeout(client.createCatalog({ catalogName }));
262262

263263
const itemId1 = uniqueId("bulk-delete-1");
264264
const itemId2 = uniqueId("bulk-delete-2");
@@ -296,7 +296,7 @@ describe("Catalog Management Integration Tests", () => {
296296
it("should partial update a catalog item", async () => {
297297
// Create a test catalog
298298
const catalogName = uniqueId("test-catalog-patch");
299-
await withTimeout(client.createCatalog(catalogName));
299+
await withTimeout(client.createCatalog({ catalogName }));
300300

301301
const itemId = uniqueId("patch-item");
302302

@@ -345,7 +345,7 @@ describe("Catalog Management Integration Tests", () => {
345345
it("should replace a catalog item", async () => {
346346
// Create a test catalog
347347
const catalogName = uniqueId("test-catalog-replace");
348-
await withTimeout(client.createCatalog(catalogName));
348+
await withTimeout(client.createCatalog({ catalogName }));
349349

350350
const itemId = uniqueId("replace-item");
351351

tests/integration/general.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("General Integration Tests", () => {
5353

5454
// For non-existent users, Iterable API returns an empty object
5555
const userResponse = await withTimeout(
56-
client.getUserByEmail(nonExistentEmail)
56+
client.getUserByEmail({ email: nonExistentEmail })
5757
);
5858

5959
expect(userResponse).toEqual({});

tests/integration/lists.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe("List Management Integration Tests", () => {
9494
await waitForListMembership(client, listId, testUserEmail, false);
9595
} finally {
9696
// Cleanup - delete the list (success indicated by no exception)
97-
await withTimeout(client.deleteList(listId));
97+
await withTimeout(client.deleteList({ listId }));
9898
}
9999
}, 120000);
100100

@@ -145,7 +145,7 @@ describe("List Management Integration Tests", () => {
145145
} finally {
146146
// Clean up test list
147147
if (testListId!) {
148-
await withTimeout(client.deleteList(testListId));
148+
await withTimeout(client.deleteList({ listId: testListId }));
149149
}
150150
}
151151
}, 120000);
@@ -199,7 +199,7 @@ describe("List Management Integration Tests", () => {
199199
} finally {
200200
// Clean up test list
201201
if (testListId!) {
202-
await withTimeout(client.deleteList(testListId));
202+
await withTimeout(client.deleteList({ listId: testListId }));
203203
}
204204
}
205205
}, 120000);

0 commit comments

Comments
 (0)