@iterable/api 0.0.1
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/LICENSE +21 -0
- package/README.md +74 -0
- package/dist/client/base.d.ts +33 -0
- package/dist/client/base.d.ts.map +1 -0
- package/dist/client/base.js +155 -0
- package/dist/client/base.js.map +1 -0
- package/dist/client/campaigns.d.ts +71 -0
- package/dist/client/campaigns.d.ts.map +1 -0
- package/dist/client/campaigns.js +125 -0
- package/dist/client/campaigns.js.map +1 -0
- package/dist/client/catalogs.d.ts +60 -0
- package/dist/client/catalogs.d.ts.map +1 -0
- package/dist/client/catalogs.js +138 -0
- package/dist/client/catalogs.js.map +1 -0
- package/dist/client/events.d.ts +38 -0
- package/dist/client/events.d.ts.map +1 -0
- package/dist/client/events.js +38 -0
- package/dist/client/events.js.map +1 -0
- package/dist/client/experiments.d.ts +24 -0
- package/dist/client/experiments.d.ts.map +1 -0
- package/dist/client/experiments.js +29 -0
- package/dist/client/experiments.js.map +1 -0
- package/dist/client/export.d.ts +27 -0
- package/dist/client/export.d.ts.map +1 -0
- package/dist/client/export.js +31 -0
- package/dist/client/export.js.map +1 -0
- package/dist/client/index.d.ts +315 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +25 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/journeys.d.ts +26 -0
- package/dist/client/journeys.d.ts.map +1 -0
- package/dist/client/journeys.js +32 -0
- package/dist/client/journeys.js.map +1 -0
- package/dist/client/lists.d.ts +39 -0
- package/dist/client/lists.d.ts.map +1 -0
- package/dist/client/lists.js +80 -0
- package/dist/client/lists.js.map +1 -0
- package/dist/client/messaging.d.ts +39 -0
- package/dist/client/messaging.d.ts.map +1 -0
- package/dist/client/messaging.js +110 -0
- package/dist/client/messaging.js.map +1 -0
- package/dist/client/snippets.d.ts +37 -0
- package/dist/client/snippets.d.ts.map +1 -0
- package/dist/client/snippets.js +29 -0
- package/dist/client/snippets.js.map +1 -0
- package/dist/client/subscriptions.d.ts +26 -0
- package/dist/client/subscriptions.d.ts.map +1 -0
- package/dist/client/subscriptions.js +31 -0
- package/dist/client/subscriptions.js.map +1 -0
- package/dist/client/templates.d.ts +52 -0
- package/dist/client/templates.d.ts.map +1 -0
- package/dist/client/templates.js +132 -0
- package/dist/client/templates.js.map +1 -0
- package/dist/client/users.d.ts +76 -0
- package/dist/client/users.d.ts.map +1 -0
- package/dist/client/users.js +115 -0
- package/dist/client/users.js.map +1 -0
- package/dist/client/webhooks.d.ts +25 -0
- package/dist/client/webhooks.d.ts.map +1 -0
- package/dist/client/webhooks.js +17 -0
- package/dist/client/webhooks.js.map +1 -0
- package/dist/config.d.ts +26 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +51 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +45 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +144 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +32 -0
- package/dist/logger.js.map +1 -0
- package/dist/types/campaigns.d.ts +307 -0
- package/dist/types/campaigns.d.ts.map +1 -0
- package/dist/types/campaigns.js +226 -0
- package/dist/types/campaigns.js.map +1 -0
- package/dist/types/catalogs.d.ts +138 -0
- package/dist/types/catalogs.d.ts.map +1 -0
- package/dist/types/catalogs.js +139 -0
- package/dist/types/catalogs.js.map +1 -0
- package/dist/types/common.d.ts +145 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +110 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/events.d.ts +124 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +118 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/experiments.d.ts +14 -0
- package/dist/types/experiments.d.ts.map +1 -0
- package/dist/types/experiments.js +24 -0
- package/dist/types/experiments.js.map +1 -0
- package/dist/types/export.d.ts +121 -0
- package/dist/types/export.d.ts.map +1 -0
- package/dist/types/export.js +105 -0
- package/dist/types/export.js.map +1 -0
- package/dist/types/journeys.d.ts +72 -0
- package/dist/types/journeys.d.ts.map +1 -0
- package/dist/types/journeys.js +65 -0
- package/dist/types/journeys.js.map +1 -0
- package/dist/types/lists.d.ts +149 -0
- package/dist/types/lists.d.ts.map +1 -0
- package/dist/types/lists.js +140 -0
- package/dist/types/lists.js.map +1 -0
- package/dist/types/messaging.d.ts +246 -0
- package/dist/types/messaging.d.ts.map +1 -0
- package/dist/types/messaging.js +323 -0
- package/dist/types/messaging.js.map +1 -0
- package/dist/types/snippets.d.ts +89 -0
- package/dist/types/snippets.d.ts.map +1 -0
- package/dist/types/snippets.js +85 -0
- package/dist/types/snippets.js.map +1 -0
- package/dist/types/subscriptions.d.ts +63 -0
- package/dist/types/subscriptions.d.ts.map +1 -0
- package/dist/types/subscriptions.js +40 -0
- package/dist/types/subscriptions.js.map +1 -0
- package/dist/types/templates.d.ts +315 -0
- package/dist/types/templates.d.ts.map +1 -0
- package/dist/types/templates.js +357 -0
- package/dist/types/templates.js.map +1 -0
- package/dist/types/users.d.ts +144 -0
- package/dist/types/users.d.ts.map +1 -0
- package/dist/types/users.js +189 -0
- package/dist/types/users.js.map +1 -0
- package/dist/types/webhooks.d.ts +52 -0
- package/dist/types/webhooks.d.ts.map +1 -0
- package/dist/types/webhooks.js +32 -0
- package/dist/types/webhooks.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { IterableSuccessResponseSchema } from "../types/common.js";
|
|
2
|
+
import { UserBulkUpdateListResponseSchema } from "../types/lists.js";
|
|
3
|
+
import { GetUserFieldsResponseSchema, } from "../types/users.js";
|
|
4
|
+
/**
|
|
5
|
+
* User management operations mixin
|
|
6
|
+
*/
|
|
7
|
+
export function Users(Base) {
|
|
8
|
+
return class extends Base {
|
|
9
|
+
/**
|
|
10
|
+
* Get a user by email address
|
|
11
|
+
*/
|
|
12
|
+
async getUserByEmail(email, opts) {
|
|
13
|
+
const response = await this.client.get(`/api/users/${encodeURIComponent(email)}`, opts?.signal ? { signal: opts.signal } : {});
|
|
14
|
+
return response.data;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get a user by userId
|
|
18
|
+
*/
|
|
19
|
+
async getUserByUserId(userId, opts) {
|
|
20
|
+
const response = await this.client.get(`/api/users/byUserId/${userId}`, {
|
|
21
|
+
...(opts?.signal ? { signal: opts.signal } : {}),
|
|
22
|
+
});
|
|
23
|
+
return response.data;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Update user data or add a user if none exists
|
|
27
|
+
* Accepts email OR userId in the userProfile parameter
|
|
28
|
+
*/
|
|
29
|
+
async updateUser(userProfile) {
|
|
30
|
+
const response = await this.client.post("/api/users/update", userProfile);
|
|
31
|
+
return this.validateResponse(response, IterableSuccessResponseSchema);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Delete a user by email address
|
|
35
|
+
* Asynchronous operation - does not prevent future data collection
|
|
36
|
+
*/
|
|
37
|
+
async deleteUserByEmail(email) {
|
|
38
|
+
const response = await this.client.delete(`/api/users/${encodeURIComponent(email)}`);
|
|
39
|
+
return response.data;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Delete a user by userId
|
|
43
|
+
* Asynchronous operation - does not prevent future data collection
|
|
44
|
+
* If multiple users share the same userId, they'll all be deleted
|
|
45
|
+
*/
|
|
46
|
+
async deleteUserByUserId(userId) {
|
|
47
|
+
const response = await this.client.delete(`/api/users/byUserId/${encodeURIComponent(userId)}`);
|
|
48
|
+
return response.data;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Update a user's email address
|
|
52
|
+
* Only use with email-based projects. For userId/hybrid projects, use updateUser instead.
|
|
53
|
+
* Returns an error if the new email already exists or has been forgotten via GDPR.
|
|
54
|
+
*/
|
|
55
|
+
async updateEmail(params) {
|
|
56
|
+
const response = await this.client.post("/api/users/updateEmail", params);
|
|
57
|
+
return this.validateResponse(response, IterableSuccessResponseSchema);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Update user subscriptions
|
|
61
|
+
* IMPORTANT: This endpoint overwrites (does not merge) existing data for any non-null fields specified.
|
|
62
|
+
*/
|
|
63
|
+
async updateUserSubscriptions(params) {
|
|
64
|
+
const response = await this.client.post("/api/users/updateSubscriptions", params);
|
|
65
|
+
return this.validateResponse(response, IterableSuccessResponseSchema);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Bulk update user data
|
|
69
|
+
*/
|
|
70
|
+
async bulkUpdateUsers(params) {
|
|
71
|
+
const response = await this.client.post("/api/users/bulkUpdate", params);
|
|
72
|
+
return this.validateResponse(response, UserBulkUpdateListResponseSchema);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get messages sent to a user
|
|
76
|
+
*/
|
|
77
|
+
async getSentMessages(params) {
|
|
78
|
+
const queryParams = new URLSearchParams();
|
|
79
|
+
if (params.email) {
|
|
80
|
+
queryParams.append("email", params.email);
|
|
81
|
+
}
|
|
82
|
+
if (params.userId) {
|
|
83
|
+
queryParams.append("userId", params.userId);
|
|
84
|
+
}
|
|
85
|
+
if (params.limit !== undefined) {
|
|
86
|
+
queryParams.append("limit", params.limit.toString());
|
|
87
|
+
}
|
|
88
|
+
if (params.campaignIds && params.campaignIds.length > 0) {
|
|
89
|
+
params.campaignIds.forEach((id) => queryParams.append("campaignIds", id.toString()));
|
|
90
|
+
}
|
|
91
|
+
if (params.startDateTime) {
|
|
92
|
+
queryParams.append("startDateTime", params.startDateTime);
|
|
93
|
+
}
|
|
94
|
+
if (params.endDateTime) {
|
|
95
|
+
queryParams.append("endDateTime", params.endDateTime);
|
|
96
|
+
}
|
|
97
|
+
if (params.excludeBlastCampaigns !== undefined) {
|
|
98
|
+
queryParams.append("excludeBlastCampaigns", params.excludeBlastCampaigns.toString());
|
|
99
|
+
}
|
|
100
|
+
if (params.messageMedium) {
|
|
101
|
+
queryParams.append("messageMedium", params.messageMedium);
|
|
102
|
+
}
|
|
103
|
+
const response = await this.client.get(`/api/users/getSentMessages?${queryParams.toString()}`);
|
|
104
|
+
return response.data;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get all user profile field definitions
|
|
108
|
+
*/
|
|
109
|
+
async getUserFields() {
|
|
110
|
+
const response = await this.client.get("/api/users/getFields");
|
|
111
|
+
return this.validateResponse(response, GetUserFieldsResponseSchema);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=users.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/client/users.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAEnE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAKL,2BAA2B,GAK5B,MAAM,mBAAmB,CAAC;AAI3B;;GAEG;AACH,MAAM,UAAU,KAAK,CAA4C,IAAO;IACtE,OAAO,KAAM,SAAQ,IAAI;QACvB;;WAEG;QACH,KAAK,CAAC,cAAc,CAClB,KAAa,EACb,IAA+B;YAE/B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CACpC,cAAc,kBAAkB,CAAC,KAAK,CAAC,EAAE,EACzC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAC5C,CAAC;YACF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,eAAe,CACnB,MAAc,EACd,IAA+B;YAE/B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC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eAAe,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;gBACvB,WAAW,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;YACxD,CAAC;YACD,IAAI,MAAM,CAAC,qBAAqB,KAAK,SAAS,EAAE,CAAC;gBAC/C,WAAW,CAAC,MAAM,CAChB,uBAAuB,EACvB,MAAM,CAAC,qBAAqB,CAAC,QAAQ,EAAE,CACxC,CAAC;YACJ,CAAC;YACD,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACzB,WAAW,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;YAC5D,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CACpC,8BAA8B,WAAW,CAAC,QAAQ,EAAE,EAAE,CACvD,CAAC;YACF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,aAAa;YACjB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,2BAA2B,CAAC,CAAC;QACtE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GetWebhooksResponse, UpdateWebhookParams, Webhook } from "../types/webhooks.js";
|
|
2
|
+
import type { Constructor } from "./base.js";
|
|
3
|
+
import type { BaseIterableClient } from "./base.js";
|
|
4
|
+
/**
|
|
5
|
+
* Webhooks operations mixin
|
|
6
|
+
*/
|
|
7
|
+
export declare function Webhooks<T extends Constructor<BaseIterableClient>>(Base: T): {
|
|
8
|
+
new (...args: any[]): {
|
|
9
|
+
getWebhooks(): Promise<GetWebhooksResponse>;
|
|
10
|
+
updateWebhook(options: UpdateWebhookParams): Promise<Webhook>;
|
|
11
|
+
client: import("axios").AxiosInstance;
|
|
12
|
+
"__#private@#httpAgent"?: import("http").Agent;
|
|
13
|
+
"__#private@#httpsAgent"?: import("https").Agent;
|
|
14
|
+
parseNdjson(data: string): any[];
|
|
15
|
+
parseCsv(data: string): any[];
|
|
16
|
+
validateResponse<T_1>(response: {
|
|
17
|
+
data: unknown;
|
|
18
|
+
config?: {
|
|
19
|
+
url?: string;
|
|
20
|
+
};
|
|
21
|
+
}, schema: import("zod").ZodType<T_1>): T_1;
|
|
22
|
+
destroy(): void;
|
|
23
|
+
};
|
|
24
|
+
} & T;
|
|
25
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/client/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAEnB,mBAAmB,EACnB,OAAO,EAER,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEpD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,WAAW,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC;;uBAElD,OAAO,CAAC,mBAAmB,CAAC;+BAKpB,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;;;;;;;;kBAUw7H,CAAC;mBAAO,CAAC;;;;;MADvgI"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GetWebhooksResponseSchema, WebhookSchema, } from "../types/webhooks.js";
|
|
2
|
+
/**
|
|
3
|
+
* Webhooks operations mixin
|
|
4
|
+
*/
|
|
5
|
+
export function Webhooks(Base) {
|
|
6
|
+
return class extends Base {
|
|
7
|
+
async getWebhooks() {
|
|
8
|
+
const response = await this.client.get("/api/webhooks");
|
|
9
|
+
return this.validateResponse(response, GetWebhooksResponseSchema);
|
|
10
|
+
}
|
|
11
|
+
async updateWebhook(options) {
|
|
12
|
+
const response = await this.client.post("/api/webhooks", options);
|
|
13
|
+
return this.validateResponse(response, WebhookSchema);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=webhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/client/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,yBAAyB,EAGzB,aAAa,GACd,MAAM,sBAAsB,CAAC;AAI9B;;GAEG;AACH,MAAM,UAAU,QAAQ,CAA4C,IAAO;IACzE,OAAO,KAAM,SAAQ,IAAI;QACvB,KAAK,CAAC,WAAW;YACf,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,yBAAyB,CAAC,CAAC;QACpE,CAAC;QAED,KAAK,CAAC,aAAa,CAAC,OAA4B;YAC9C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YAClE,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;QACxD,CAAC;KAKF,CAAC;AACJ,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IterableConfig } from "./types/common.js";
|
|
2
|
+
/**
|
|
3
|
+
* Environment configuration with validation using t3-env
|
|
4
|
+
* Single source of truth for all environment variables
|
|
5
|
+
*/
|
|
6
|
+
export declare const config: Readonly<{
|
|
7
|
+
ITERABLE_API_KEY?: string | undefined;
|
|
8
|
+
LOG_FILE?: string | undefined;
|
|
9
|
+
ITERABLE_BASE_URL: string;
|
|
10
|
+
API_TIMEOUT: number;
|
|
11
|
+
ITERABLE_DEBUG: boolean;
|
|
12
|
+
ITERABLE_DEBUG_VERBOSE: boolean;
|
|
13
|
+
NODE_ENV: "production" | "development" | "test";
|
|
14
|
+
LOG_LEVEL: "error" | "debug" | "warn" | "info" | "http" | "verbose" | "silly";
|
|
15
|
+
LOG_JSON: boolean;
|
|
16
|
+
LOG_STDERR: boolean;
|
|
17
|
+
SHUTDOWN_TIMEOUT: number;
|
|
18
|
+
CLEANUP_TEST_DATA: boolean;
|
|
19
|
+
TEST_TIMEOUT: number;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Create IterableClient config from environment variables
|
|
23
|
+
* Used internally by IterableClient constructor
|
|
24
|
+
*/
|
|
25
|
+
export declare function createIterableConfig(): IterableConfig;
|
|
26
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;EA+BjB,CAAC;AAEH;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CAYrD"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createEnv } from "@t3-oss/env-core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* Environment configuration with validation using t3-env
|
|
5
|
+
* Single source of truth for all environment variables
|
|
6
|
+
*/
|
|
7
|
+
export const config = createEnv({
|
|
8
|
+
server: {
|
|
9
|
+
// API Configuration
|
|
10
|
+
ITERABLE_API_KEY: z.string().optional(),
|
|
11
|
+
ITERABLE_BASE_URL: z.url().default("https://api.iterable.com"),
|
|
12
|
+
API_TIMEOUT: z.coerce.number().positive().default(30000),
|
|
13
|
+
ITERABLE_DEBUG: z.coerce.boolean().default(false),
|
|
14
|
+
ITERABLE_DEBUG_VERBOSE: z.coerce.boolean().default(false),
|
|
15
|
+
// Logging Configuration
|
|
16
|
+
LOG_LEVEL: z
|
|
17
|
+
.enum(["error", "warn", "info", "http", "verbose", "debug", "silly"])
|
|
18
|
+
.default(process.env.NODE_ENV === "production" ? "info" : "debug"),
|
|
19
|
+
LOG_JSON: z.coerce.boolean().default(process.env.NODE_ENV === "production"),
|
|
20
|
+
LOG_FILE: z.string().optional(),
|
|
21
|
+
LOG_STDERR: z.coerce.boolean().default(true),
|
|
22
|
+
// Server Configuration
|
|
23
|
+
SHUTDOWN_TIMEOUT: z.coerce.number().positive().default(30000),
|
|
24
|
+
// Test Configuration
|
|
25
|
+
CLEANUP_TEST_DATA: z.coerce.boolean().default(true),
|
|
26
|
+
TEST_TIMEOUT: z.coerce.number().positive().default(15000),
|
|
27
|
+
// Node Environment
|
|
28
|
+
NODE_ENV: z
|
|
29
|
+
.enum(["development", "test", "production"])
|
|
30
|
+
.default("development"),
|
|
31
|
+
},
|
|
32
|
+
runtimeEnv: process.env,
|
|
33
|
+
emptyStringAsUndefined: true,
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Create IterableClient config from environment variables
|
|
37
|
+
* Used internally by IterableClient constructor
|
|
38
|
+
*/
|
|
39
|
+
export function createIterableConfig() {
|
|
40
|
+
if (!config.ITERABLE_API_KEY) {
|
|
41
|
+
throw new Error("ITERABLE_API_KEY environment variable is required");
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
apiKey: config.ITERABLE_API_KEY,
|
|
45
|
+
baseUrl: config.ITERABLE_BASE_URL,
|
|
46
|
+
timeout: config.API_TIMEOUT,
|
|
47
|
+
debug: config.ITERABLE_DEBUG || config.ITERABLE_DEBUG_VERBOSE,
|
|
48
|
+
debugVerbose: config.ITERABLE_DEBUG_VERBOSE,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=config.js.map
|
|
@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CAAC;QAE5C,uBAAuB;QACvB,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QAE7D,qBAAqB;QACrB,iBAAiB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;QACnD,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QAEzD,mBAAmB;QACnB,QAAQ,EAAE,CAAC;aACR,IAAI,CAAC,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;aAC3C,OAAO,CAAC,aAAa,CAAC;KAC1B;IACD,UAAU,EAAE,OAAO,CAAC,GAAG;IACvB,sBAAsB,EAAE,IAAI;CAC7B,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAClC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,gBAAgB;QAC/B,OAAO,EAAE,MAAM,CAAC,iBAAiB;QACjC,OAAO,EAAE,MAAM,CAAC,WAAW;QAC3B,KAAK,EAAE,MAAM,CAAC,cAAc,IAAI,MAAM,CAAC,sBAAsB;QAC7D,YAAY,EAAE,MAAM,CAAC,sBAAsB;KAC5C,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IterableErrorResponse, IterableErrorResponseCode } from "./types/common.js";
|
|
2
|
+
export declare abstract class IterableError extends Error {
|
|
3
|
+
readonly statusCode: number;
|
|
4
|
+
readonly endpoint?: string | undefined;
|
|
5
|
+
constructor(message: string, statusCode: number, endpoint?: string | undefined, options?: ErrorOptions);
|
|
6
|
+
isAuthError: () => boolean;
|
|
7
|
+
isValidationError: () => boolean;
|
|
8
|
+
isNotFoundError: () => boolean;
|
|
9
|
+
isRateLimitError: () => boolean;
|
|
10
|
+
isForbiddenError: () => boolean;
|
|
11
|
+
isServerError: () => boolean;
|
|
12
|
+
isClientError: () => boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class IterableApiError extends IterableError {
|
|
15
|
+
readonly statusCode: number;
|
|
16
|
+
readonly apiResponse: IterableErrorResponse;
|
|
17
|
+
readonly endpoint?: string | undefined;
|
|
18
|
+
readonly code: IterableErrorResponseCode | "Success";
|
|
19
|
+
readonly params: Record<string, unknown> | null | undefined;
|
|
20
|
+
constructor(statusCode: number, apiResponse: IterableErrorResponse, endpoint?: string | undefined, options?: ErrorOptions);
|
|
21
|
+
}
|
|
22
|
+
export declare class IterableRawError extends IterableError {
|
|
23
|
+
readonly statusCode: number;
|
|
24
|
+
readonly rawResponse: unknown;
|
|
25
|
+
readonly endpoint?: string | undefined;
|
|
26
|
+
constructor(statusCode: number, rawResponse: unknown, endpoint?: string | undefined, options?: ErrorOptions);
|
|
27
|
+
get truncatedResponse(): string;
|
|
28
|
+
}
|
|
29
|
+
export declare class IterableResponseValidationError extends IterableError {
|
|
30
|
+
readonly statusCode: number;
|
|
31
|
+
readonly rawResponse: unknown;
|
|
32
|
+
readonly validationError: string;
|
|
33
|
+
readonly endpoint?: string | undefined;
|
|
34
|
+
constructor(statusCode: number, rawResponse: unknown, validationError: string, endpoint?: string | undefined, options?: ErrorOptions);
|
|
35
|
+
}
|
|
36
|
+
export declare class IterableNetworkError extends Error {
|
|
37
|
+
readonly originalError?: Error | undefined;
|
|
38
|
+
constructor(message: string, originalError?: Error | undefined, options?: ErrorOptions);
|
|
39
|
+
}
|
|
40
|
+
export declare function isIterableError(error: unknown): error is IterableError;
|
|
41
|
+
export declare function isIterableApiError(error: unknown): error is IterableApiError;
|
|
42
|
+
export declare function isIterableRawError(error: unknown): error is IterableRawError;
|
|
43
|
+
export declare function isIterableResponseValidationError(error: unknown): error is IterableResponseValidationError;
|
|
44
|
+
export declare function createIterableError(error: any): Error;
|
|
45
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EAE1B,MAAM,mBAAmB,CAAC;AAG3B,8BAAsB,aAAc,SAAQ,KAAK;aAG7B,UAAU,EAAE,MAAM;aAClB,QAAQ,CAAC,EAAE,MAAM;gBAFjC,OAAO,EAAE,MAAM,EACC,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,YAAA,EACjC,OAAO,CAAC,EAAE,YAAY;IAMxB,WAAW,gBAAiC;IAC5C,iBAAiB,gBAAiC;IAClD,eAAe,gBAAiC;IAChD,gBAAgB,gBAAiC;IACjD,gBAAgB,gBAAiC;IACjD,aAAa,gBAAgC;IAC7C,aAAa,gBAAyD;CACvE;AAED,qBAAa,gBAAiB,SAAQ,aAAa;aAKtB,UAAU,EAAE,MAAM;aAC3B,WAAW,EAAE,qBAAqB;aACzB,QAAQ,CAAC,EAAE,MAAM;IAN5C,SAAgB,IAAI,EAAE,yBAAyB,GAAG,SAAS,CAAC;IAC5D,SAAgB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;gBAGxC,UAAU,EAAE,MAAM,EAC3B,WAAW,EAAE,qBAAqB,EACzB,QAAQ,CAAC,EAAE,MAAM,YAAA,EAC1C,OAAO,CAAC,EAAE,YAAY;CAMzB;AAED,qBAAa,gBAAiB,SAAQ,aAAa;aAEtB,UAAU,EAAE,MAAM;aAC3B,WAAW,EAAE,OAAO;aACX,QAAQ,CAAC,EAAE,MAAM;gBAFjB,UAAU,EAAE,MAAM,EAC3B,WAAW,EAAE,OAAO,EACX,QAAQ,CAAC,EAAE,MAAM,YAAA,EAC1C,OAAO,CAAC,EAAE,YAAY;IAUxB,IAAI,iBAAiB,IAAI,MAAM,CAO9B;CACF;AAGD,qBAAa,+BAAgC,SAAQ,aAAa;aAErC,UAAU,EAAE,MAAM;aAC3B,WAAW,EAAE,OAAO;aACpB,eAAe,EAAE,MAAM;aACd,QAAQ,CAAC,EAAE,MAAM;gBAHjB,UAAU,EAAE,MAAM,EAC3B,WAAW,EAAE,OAAO,EACpB,eAAe,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,YAAA,EAC1C,OAAO,CAAC,EAAE,YAAY;CASzB;AAGD,qBAAa,oBAAqB,SAAQ,KAAK;aAG3B,aAAa,CAAC,EAAE,KAAK;gBADrC,OAAO,EAAE,MAAM,EACC,aAAa,CAAC,EAAE,KAAK,YAAA,EACrC,OAAO,CAAC,EAAE,YAAY;CAKzB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAE5E;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAE5E;AAED,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,+BAA+B,CAE1C;AAoCD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,CAmCrD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { IterableErrorResponseSchema, } from "./types/common.js";
|
|
2
|
+
// Base class for all Iterable-related errors
|
|
3
|
+
export class IterableError extends Error {
|
|
4
|
+
statusCode;
|
|
5
|
+
endpoint;
|
|
6
|
+
constructor(message, statusCode, endpoint, options) {
|
|
7
|
+
super(message, options);
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.endpoint = endpoint;
|
|
10
|
+
this.name = this.constructor.name;
|
|
11
|
+
}
|
|
12
|
+
isAuthError = () => this.statusCode === 401;
|
|
13
|
+
isValidationError = () => this.statusCode === 400;
|
|
14
|
+
isNotFoundError = () => this.statusCode === 404;
|
|
15
|
+
isRateLimitError = () => this.statusCode === 429;
|
|
16
|
+
isForbiddenError = () => this.statusCode === 403;
|
|
17
|
+
isServerError = () => this.statusCode >= 500;
|
|
18
|
+
isClientError = () => this.statusCode >= 400 && this.statusCode < 500;
|
|
19
|
+
}
|
|
20
|
+
export class IterableApiError extends IterableError {
|
|
21
|
+
statusCode;
|
|
22
|
+
apiResponse;
|
|
23
|
+
endpoint;
|
|
24
|
+
code;
|
|
25
|
+
params;
|
|
26
|
+
constructor(statusCode, apiResponse, endpoint, options) {
|
|
27
|
+
super(apiResponse.msg, statusCode, endpoint, options);
|
|
28
|
+
this.statusCode = statusCode;
|
|
29
|
+
this.apiResponse = apiResponse;
|
|
30
|
+
this.endpoint = endpoint;
|
|
31
|
+
this.code = apiResponse.code;
|
|
32
|
+
this.params = apiResponse.params;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class IterableRawError extends IterableError {
|
|
36
|
+
statusCode;
|
|
37
|
+
rawResponse;
|
|
38
|
+
endpoint;
|
|
39
|
+
constructor(statusCode, rawResponse, endpoint, options) {
|
|
40
|
+
super(extractErrorMessage(rawResponse, statusCode), statusCode, endpoint, options);
|
|
41
|
+
this.statusCode = statusCode;
|
|
42
|
+
this.rawResponse = rawResponse;
|
|
43
|
+
this.endpoint = endpoint;
|
|
44
|
+
}
|
|
45
|
+
get truncatedResponse() {
|
|
46
|
+
if (typeof this.rawResponse === "string") {
|
|
47
|
+
return this.rawResponse.length > 500
|
|
48
|
+
? this.rawResponse.substring(0, 500) + "...[truncated]"
|
|
49
|
+
: this.rawResponse;
|
|
50
|
+
}
|
|
51
|
+
return JSON.stringify(this.rawResponse);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// For response validation errors (success response with wrong structure)
|
|
55
|
+
export class IterableResponseValidationError extends IterableError {
|
|
56
|
+
statusCode;
|
|
57
|
+
rawResponse;
|
|
58
|
+
validationError;
|
|
59
|
+
endpoint;
|
|
60
|
+
constructor(statusCode, rawResponse, validationError, endpoint, options) {
|
|
61
|
+
super(`Response validation failed: ${validationError}`, statusCode, endpoint, options);
|
|
62
|
+
this.statusCode = statusCode;
|
|
63
|
+
this.rawResponse = rawResponse;
|
|
64
|
+
this.validationError = validationError;
|
|
65
|
+
this.endpoint = endpoint;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// For network-level errors (no response received)
|
|
69
|
+
export class IterableNetworkError extends Error {
|
|
70
|
+
originalError;
|
|
71
|
+
constructor(message, originalError, options) {
|
|
72
|
+
super(message, options);
|
|
73
|
+
this.originalError = originalError;
|
|
74
|
+
this.name = "IterableNetworkError";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export function isIterableError(error) {
|
|
78
|
+
return error instanceof IterableError;
|
|
79
|
+
}
|
|
80
|
+
export function isIterableApiError(error) {
|
|
81
|
+
return error instanceof IterableApiError;
|
|
82
|
+
}
|
|
83
|
+
export function isIterableRawError(error) {
|
|
84
|
+
return error instanceof IterableRawError;
|
|
85
|
+
}
|
|
86
|
+
export function isIterableResponseValidationError(error) {
|
|
87
|
+
return error instanceof IterableResponseValidationError;
|
|
88
|
+
}
|
|
89
|
+
function extractErrorMessage(data, status) {
|
|
90
|
+
// Handle JSON objects that look like error responses
|
|
91
|
+
const msg = data?.msg;
|
|
92
|
+
if (typeof msg === "string") {
|
|
93
|
+
return msg;
|
|
94
|
+
}
|
|
95
|
+
if (typeof data === "string") {
|
|
96
|
+
// Try to extract meaningful info from HTML
|
|
97
|
+
const titleMatch = data.match(/<title[^>]*>([^<]+)<\/title>/i)?.[1];
|
|
98
|
+
if (titleMatch) {
|
|
99
|
+
return titleMatch.replace(/\s+/g, " ").trim();
|
|
100
|
+
}
|
|
101
|
+
// Look for error content in common HTML patterns
|
|
102
|
+
const errorMatch = data.match(/<h[1-6][^>]*>([^<]*(?:error|not found|failed)[^<]*)<\/h[1-6]>/i)?.[1];
|
|
103
|
+
if (errorMatch) {
|
|
104
|
+
return errorMatch
|
|
105
|
+
.replace(/<[^>]*>/g, "")
|
|
106
|
+
.replace(/\s+/g, " ")
|
|
107
|
+
.trim();
|
|
108
|
+
}
|
|
109
|
+
// If it's a short string, use it directly
|
|
110
|
+
if (data.length < 200 && !data.includes("<")) {
|
|
111
|
+
return data.trim();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return `HTTP ${status} error`;
|
|
115
|
+
}
|
|
116
|
+
export function createIterableError(error) {
|
|
117
|
+
if (error.response) {
|
|
118
|
+
const { status, data } = error.response;
|
|
119
|
+
const url = error.config?.url;
|
|
120
|
+
let parsedData = data;
|
|
121
|
+
if (typeof data === "string") {
|
|
122
|
+
try {
|
|
123
|
+
parsedData = JSON.parse(data);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Invalid JSON, keep as string
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (parsedData && typeof parsedData === "object") {
|
|
130
|
+
const validation = IterableErrorResponseSchema.safeParse(parsedData);
|
|
131
|
+
if (validation.success) {
|
|
132
|
+
return new IterableApiError(status, validation.data, url, {
|
|
133
|
+
cause: error,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return new IterableRawError(status, data, url, { cause: error });
|
|
138
|
+
}
|
|
139
|
+
if (error.request) {
|
|
140
|
+
return new IterableNetworkError("Network error: No response received from Iterable API", error, { cause: error });
|
|
141
|
+
}
|
|
142
|
+
return new Error(`Request setup error: ${error.message}`, { cause: error });
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,2BAA2B,GAC5B,MA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AK,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,IAAI,oBAAoB,CAC7B,uDAAuD,EACvD,KAAK,EACL,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,KAAK,CAAC,wBAAwB,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAC9E,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { BaseIterableClient, DEFAULT_USER_AGENT } from "./client/base.js";
|
|
2
|
+
export { IterableClient } from "./client/index.js";
|
|
3
|
+
export * from "./types/campaigns.js";
|
|
4
|
+
export * from "./types/catalogs.js";
|
|
5
|
+
export * from "./types/common.js";
|
|
6
|
+
export * from "./types/events.js";
|
|
7
|
+
export * from "./types/experiments.js";
|
|
8
|
+
export * from "./types/export.js";
|
|
9
|
+
export * from "./types/journeys.js";
|
|
10
|
+
export * from "./types/lists.js";
|
|
11
|
+
export * from "./types/messaging.js";
|
|
12
|
+
export * from "./types/snippets.js";
|
|
13
|
+
export * from "./types/subscriptions.js";
|
|
14
|
+
export * from "./types/templates.js";
|
|
15
|
+
export * from "./types/users.js";
|
|
16
|
+
export * from "./types/webhooks.js";
|
|
17
|
+
export * from "./errors.js";
|
|
18
|
+
export { createIterableConfig } from "./config.js";
|
|
19
|
+
export type { IterableConfig } from "./types/common.js";
|
|
20
|
+
export { logger } from "./logger.js";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,aAAa,CAAC;AAG5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Main exports for the Iterable API Client
|
|
2
|
+
export { BaseIterableClient, DEFAULT_USER_AGENT } from "./client/base.js";
|
|
3
|
+
export { IterableClient } from "./client/index.js";
|
|
4
|
+
// Export all types
|
|
5
|
+
export * from "./types/campaigns.js";
|
|
6
|
+
export * from "./types/catalogs.js";
|
|
7
|
+
export * from "./types/common.js";
|
|
8
|
+
export * from "./types/events.js";
|
|
9
|
+
export * from "./types/experiments.js";
|
|
10
|
+
export * from "./types/export.js";
|
|
11
|
+
export * from "./types/journeys.js";
|
|
12
|
+
export * from "./types/lists.js";
|
|
13
|
+
export * from "./types/messaging.js";
|
|
14
|
+
export * from "./types/snippets.js";
|
|
15
|
+
export * from "./types/subscriptions.js";
|
|
16
|
+
export * from "./types/templates.js";
|
|
17
|
+
export * from "./types/users.js";
|
|
18
|
+
export * from "./types/webhooks.js";
|
|
19
|
+
// Export error classes and utilities
|
|
20
|
+
export * from "./errors.js";
|
|
21
|
+
// Export configuration utilities
|
|
22
|
+
export { createIterableConfig } from "./config.js";
|
|
23
|
+
// Export logger
|
|
24
|
+
export { logger } from "./logger.js";
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,mBAAmB;AACnB,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AAEpC,qCAAqC;AACrC,cAAc,aAAa,CAAC;AAE5B,iCAAiC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGnD,gBAAgB;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAsC9B,eAAO,MAAM,MAAM,gBASjB,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import winston from "winston";
|
|
2
|
+
import { config } from "./config.js";
|
|
3
|
+
const structuredFormat = winston.format.printf(({ level, message, timestamp, ...metadata }) => {
|
|
4
|
+
const logObject = {
|
|
5
|
+
timestamp,
|
|
6
|
+
level,
|
|
7
|
+
message,
|
|
8
|
+
...metadata,
|
|
9
|
+
};
|
|
10
|
+
return JSON.stringify(logObject);
|
|
11
|
+
});
|
|
12
|
+
const transports = [];
|
|
13
|
+
if (config.LOG_FILE) {
|
|
14
|
+
transports.push(new winston.transports.File({
|
|
15
|
+
filename: config.LOG_FILE,
|
|
16
|
+
format: config.LOG_JSON ? structuredFormat : winston.format.simple(),
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
if (config.LOG_STDERR) {
|
|
20
|
+
// Log to stderr (never stdout to avoid breaking MCP protocol)
|
|
21
|
+
// MCP servers communicate over stdin/stdout, so logs to stdout interfere with JSON-RPC messages
|
|
22
|
+
transports.push(new winston.transports.Console({
|
|
23
|
+
stderrLevels: Object.keys(winston.config.npm.levels),
|
|
24
|
+
format: config.LOG_JSON ? structuredFormat : winston.format.simple(),
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
export const logger = winston.createLogger({
|
|
28
|
+
level: config.LOG_LEVEL,
|
|
29
|
+
format: winston.format.combine(winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSS" }), winston.format.errors({ stack: true }), winston.format.splat(), structuredFormat),
|
|
30
|
+
transports,
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAC5C,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,QAAQ,EAAE,EAAE,EAAE;IAC7C,MAAM,SAAS,GAAG;QAChB,SAAS;QACT,KAAK;QACL,OAAO;QACP,GAAG,QAAQ;KACZ,CAAC;IACF,OAAO,IAAI,CAAC,SAAS,CAAC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