Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/client/catalogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import {
CatalogFieldMappingsResponseSchema,
CatalogItemWithProperties,
CatalogItemWithPropertiesSchema,
CreateCatalogParams,
DeleteCatalogItemParams,
DeleteCatalogParams,
GetCatalogFieldMappingsParams,
GetCatalogItemParams,
GetCatalogItemsParams,
GetCatalogItemsResponse,
GetCatalogItemsResponseSchema,
Expand All @@ -28,9 +32,11 @@ import type { BaseIterableClient } from "./base.js";
*/
export function Catalogs<T extends Constructor<BaseIterableClient>>(Base: T) {
return class extends Base {
async createCatalog(catalogName: string): Promise<IterableSuccessResponse> {
async createCatalog(
params: CreateCatalogParams
): Promise<IterableSuccessResponse> {
const response = await this.client.post(
`/api/catalogs/${encodeURIComponent(catalogName)}`
`/api/catalogs/${encodeURIComponent(params.catalogName)}`
);
return this.validateResponse(response, IterableSuccessResponseSchema);
}
Expand Down Expand Up @@ -63,21 +69,19 @@ export function Catalogs<T extends Constructor<BaseIterableClient>>(Base: T) {
}

async getCatalogItem(
catalogName: string,
itemId: string
params: GetCatalogItemParams
): Promise<CatalogItemWithProperties> {
const response = await this.client.get(
`/api/catalogs/${encodeURIComponent(catalogName)}/items/${encodeURIComponent(itemId)}`
`/api/catalogs/${encodeURIComponent(params.catalogName)}/items/${encodeURIComponent(params.itemId)}`
);
return this.validateResponse(response, CatalogItemWithPropertiesSchema);
}

async deleteCatalogItem(
catalogName: string,
itemId: string
params: DeleteCatalogItemParams
): Promise<IterableSuccessResponse> {
const response = await this.client.delete(
`/api/catalogs/${encodeURIComponent(catalogName)}/items/${encodeURIComponent(itemId)}`
`/api/catalogs/${encodeURIComponent(params.catalogName)}/items/${encodeURIComponent(params.itemId)}`
);
return this.validateResponse(response, IterableSuccessResponseSchema);
}
Expand Down Expand Up @@ -168,9 +172,11 @@ export function Catalogs<T extends Constructor<BaseIterableClient>>(Base: T) {
/**
* Delete a catalog
*/
async deleteCatalog(catalogName: string): Promise<IterableSuccessResponse> {
async deleteCatalog(
params: DeleteCatalogParams
): Promise<IterableSuccessResponse> {
const response = await this.client.delete(
`/api/catalogs/${encodeURIComponent(catalogName)}`
`/api/catalogs/${encodeURIComponent(params.catalogName)}`
);
return this.validateResponse(response, IterableSuccessResponseSchema);
}
Expand Down
5 changes: 3 additions & 2 deletions src/client/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CreateListParams,
CreateListResponse,
CreateListResponseSchema,
DeleteListParams,
GetListPreviewUsersParams,
GetListPreviewUsersResponse,
GetListPreviewUsersResponseSchema,
Expand Down Expand Up @@ -91,8 +92,8 @@ export function Lists<T extends Constructor<BaseIterableClient>>(Base: T) {
return this.validateResponse(response, CreateListResponseSchema);
}

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

Expand Down
9 changes: 5 additions & 4 deletions src/client/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
BulkDeleteTemplatesResponseSchema,
EmailTemplate,
EmailTemplateSchema,
GetTemplateByClientIdParams,
GetTemplateByClientIdResponse,
GetTemplateByClientIdResponseSchema,
GetTemplateParams,
Expand Down Expand Up @@ -145,12 +146,12 @@ export function Templates<T extends Constructor<BaseIterableClient>>(Base: T) {
}

async getTemplateByClientId(
clientTemplateId: string
params: GetTemplateByClientIdParams
): Promise<GetTemplateByClientIdResponse> {
const response = await this.client.get(
"/api/templates/getByClientTemplateId",
{
params: { clientTemplateId },
params: { clientTemplateId: params.clientTemplateId },
}
);
return this.validateResponse(
Expand All @@ -174,9 +175,9 @@ export function Templates<T extends Constructor<BaseIterableClient>>(Base: T) {
* @deprecated Use {@link bulkDeleteTemplates} instead
*/
async deleteTemplates(
templateIds: number[]
params: BulkDeleteTemplatesParams
): Promise<BulkDeleteTemplatesResponse> {
return this.bulkDeleteTemplates({ ids: templateIds });
return this.bulkDeleteTemplates(params);
}

// Email Template Management
Expand Down
28 changes: 16 additions & 12 deletions src/client/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import {
} from "../types/lists.js";
import {
BulkUpdateUsersParams,
DeleteUserByEmailParams,
DeleteUserByUserIdParams,
GetSentMessagesParams,
GetSentMessagesResponse,
GetSentMessagesResponseSchema,
GetUserByEmailParams,
GetUserByIdParams,
GetUserFieldsResponse,
GetUserFieldsResponseSchema,
UpdateEmailParams,
Expand All @@ -30,12 +34,10 @@ export function Users<T extends Constructor<BaseIterableClient>>(Base: T) {
* Get a user by email address
*/
async getUserByEmail(
email: string,
opts?: { signal?: AbortSignal }
params: GetUserByEmailParams
): Promise<UserResponse> {
const response = await this.client.get(
`/api/users/${encodeURIComponent(email)}`,
opts?.signal ? { signal: opts.signal } : {}
`/api/users/${encodeURIComponent(params.email)}`
);
return this.validateResponse(response, UserResponseSchema);
}
Expand All @@ -44,12 +46,10 @@ export function Users<T extends Constructor<BaseIterableClient>>(Base: T) {
* Get a user by userId
*/
async getUserByUserId(
userId: string,
opts?: { signal?: AbortSignal }
params: GetUserByIdParams
): Promise<UserResponse> {
const response = await this.client.get(
`/api/users/byUserId/${encodeURIComponent(userId)}`,
opts?.signal ? { signal: opts.signal } : {}
`/api/users/byUserId/${encodeURIComponent(params.userId)}`
);
return this.validateResponse(response, UserResponseSchema);
}
Expand All @@ -69,9 +69,11 @@ export function Users<T extends Constructor<BaseIterableClient>>(Base: T) {
* Delete a user by email address
* Asynchronous operation - does not prevent future data collection
*/
async deleteUserByEmail(email: string): Promise<IterableSuccessResponse> {
async deleteUserByEmail(
params: DeleteUserByEmailParams
): Promise<IterableSuccessResponse> {
const response = await this.client.delete(
`/api/users/${encodeURIComponent(email)}`
`/api/users/${encodeURIComponent(params.email)}`
);
return this.validateResponse(response, IterableSuccessResponseSchema);
}
Expand All @@ -81,9 +83,11 @@ export function Users<T extends Constructor<BaseIterableClient>>(Base: T) {
* Asynchronous operation - does not prevent future data collection
* If multiple users share the same userId, they'll all be deleted
*/
async deleteUserByUserId(userId: string): Promise<IterableSuccessResponse> {
async deleteUserByUserId(
params: DeleteUserByUserIdParams
): Promise<IterableSuccessResponse> {
const response = await this.client.delete(
`/api/users/byUserId/${encodeURIComponent(userId)}`
`/api/users/byUserId/${encodeURIComponent(params.userId)}`
);
return this.validateResponse(response, IterableSuccessResponseSchema);
}
Expand Down
10 changes: 10 additions & 0 deletions src/types/catalogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ export type GetCatalogFieldMappingsParams = z.infer<
>;
export type CreateCatalogParams = z.infer<typeof CreateCatalogParamsSchema>;

export const DeleteCatalogParamsSchema = z.object({
catalogName: z
.string()
.max(255)
.regex(/^[a-zA-Z0-9-]+$/)
.describe("Name of the catalog to delete"),
});

export type DeleteCatalogParams = z.infer<typeof DeleteCatalogParamsSchema>;

// Catalog items schemas
export const CatalogItemWithPropertiesSchema = z.object({
catalogName: z.string(),
Expand Down
12 changes: 12 additions & 0 deletions src/types/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const GetUserByEmailParamsSchema = z.object({
email: z.email().describe("Email address of the user to retrieve"),
});

export type GetUserByEmailParams = z.infer<typeof GetUserByEmailParamsSchema>;

export const UpdateUserParamsSchema = z
.object({
email: z.email().optional().describe("User email address"),
Expand Down Expand Up @@ -69,6 +71,8 @@ export const GetUserByIdParamsSchema = z.object({
userId: z.string().describe("User ID to retrieve"),
});

export type GetUserByIdParams = z.infer<typeof GetUserByIdParamsSchema>;

export const BulkUpdateUsersParamsSchema = z.object({
users: z
.array(
Expand All @@ -95,10 +99,18 @@ export const DeleteUserByEmailParamsSchema = z.object({
email: z.email().describe("Email address of the user to delete"),
});

export type DeleteUserByEmailParams = z.infer<
typeof DeleteUserByEmailParamsSchema
>;

export const DeleteUserByUserIdParamsSchema = z.object({
userId: z.string().describe("User ID of the user to delete"),
});

export type DeleteUserByUserIdParams = z.infer<
typeof DeleteUserByUserIdParamsSchema
>;

export const UserEventsResponseSchema = z.object({
events: z.array(z.record(z.string(), z.any())),
});
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/campaigns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ describe("Campaign Management Integration Tests", () => {

if (createdTestList) {
try {
await withTimeout(client.deleteList(testListId));
await withTimeout(client.deleteList({ listId: testListId }));
} catch (error) {
console.warn(`Failed to delete test list ${testListId}:`, error);
}
}

if (createdTestTemplate) {
try {
await withTimeout(client.deleteTemplates([testTemplateId]));
await withTimeout(client.deleteTemplates({ ids: [testTemplateId] }));
} catch (error) {
console.warn(`Failed to delete test template ${testTemplateId}:`, error);
}
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/catalogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Catalog Management Integration Tests", () => {

it("get nonexistent catalog item should 404", async () => {
await expect(
client.getCatalogItem("nonexistent-catalog", "nonexistent-item")
client.getCatalogItem({ catalogName: "nonexistent-catalog", itemId: "nonexistent-item" })
).rejects.toMatchObject({
statusCode: 404,
});
Expand All @@ -42,7 +42,7 @@ describe("Catalog Management Integration Tests", () => {
it("should get catalog field mappings with correct structure", async () => {
// Create a test catalog
const catalogName = uniqueId("test-catalog-mappings");
await withTimeout(client.createCatalog(catalogName));
await withTimeout(client.createCatalog({ catalogName }));

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

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

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

// Delete the catalog
const result = await withTimeout(client.deleteCatalog(catalogName));
const result = await withTimeout(client.deleteCatalog({ catalogName }));

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

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

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("General Integration Tests", () => {

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

expect(userResponse).toEqual({});
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/lists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("List Management Integration Tests", () => {
await waitForListMembership(client, listId, testUserEmail, false);
} finally {
// Cleanup - delete the list (success indicated by no exception)
await withTimeout(client.deleteList(listId));
await withTimeout(client.deleteList({ listId }));
}
}, 120000);

Expand Down Expand Up @@ -145,7 +145,7 @@ describe("List Management Integration Tests", () => {
} finally {
// Clean up test list
if (testListId!) {
await withTimeout(client.deleteList(testListId));
await withTimeout(client.deleteList({ listId: testListId }));
}
}
}, 120000);
Expand Down Expand Up @@ -199,7 +199,7 @@ describe("List Management Integration Tests", () => {
} finally {
// Clean up test list
if (testListId!) {
await withTimeout(client.deleteList(testListId));
await withTimeout(client.deleteList({ listId: testListId }));
}
}
}, 120000);
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/subscriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("Subscription Management Integration Tests", () => {
// Clean up test list only if we created it
if (createdTestList) {
try {
await withTimeout(client.deleteList(testListId));
await withTimeout(client.deleteList({ listId: testListId }));
} catch (error) {
console.warn(`Failed to delete test list ${testListId}:`, error);
}
Expand Down
Loading
Loading