@ewyn/client 0.1.0 → 0.3.0
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/README.md +64 -16
- package/dist/__tests__/cli-fetch-config.test.d.ts +2 -0
- package/dist/__tests__/cli-fetch-config.test.d.ts.map +1 -0
- package/dist/__tests__/cli-fetch-config.test.js +70 -0
- package/dist/__tests__/config-types.test-d.js +7 -7
- package/dist/__tests__/dashboard-config.test.js +7 -12
- package/dist/__tests__/errors.test.js +37 -37
- package/dist/__tests__/ewyn.test.d.ts +2 -0
- package/dist/__tests__/ewyn.test.d.ts.map +1 -0
- package/dist/__tests__/ewyn.test.js +428 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +140 -0
- package/dist/errors.d.ts +2 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +4 -4
- package/dist/index.d.ts +6 -54
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -14
- package/dist/types.d.ts +17 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -2
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACf,MAAM,YAAY,CAAC;AAmDpB,qBAAa,IAAI,CAAC,OAAO,SAAS,cAAc,GAAG,cAAc;IAC/D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE,WAAW,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAQ5D;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,IAAI,CACR,OAAO,EAAE,OAAO,SAAS,cAAc,GACnC,qBAAqB,CAAC,OAAO,CAAC,GAAG,gBAAgB,GACjD,gBAAgB,GACnB,OAAO,CAAC,iBAAiB,CAAC;IA8C7B;;OAEG;YACW,iBAAiB;IAyB/B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA2BzB;;OAEG;YACW,gBAAgB;CAuE/B;AAED,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EACV,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EwynApiError } from './errors.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Ewyn SDK Client
|
|
4
4
|
*
|
|
5
5
|
* @example Basic usage without template config
|
|
6
6
|
* ```ts
|
|
7
|
-
* const client = new
|
|
7
|
+
* const client = new Ewyn({
|
|
8
8
|
* workspaceId: 'your-workspace-id',
|
|
9
9
|
* apiKey: 'your-api-key',
|
|
10
10
|
* });
|
|
@@ -30,7 +30,7 @@ import { MailerApiError } from './errors.js';
|
|
|
30
30
|
* }
|
|
31
31
|
* } as const;
|
|
32
32
|
*
|
|
33
|
-
* const client = new
|
|
33
|
+
* const client = new Ewyn({
|
|
34
34
|
* workspaceId: 'your-workspace-id',
|
|
35
35
|
* apiKey: 'your-api-key',
|
|
36
36
|
* templates: config
|
|
@@ -46,17 +46,16 @@ import { MailerApiError } from './errors.js';
|
|
|
46
46
|
* });
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
const EWYN_API_BASE_URL = 'https://www.ewyn.ai/api/v1';
|
|
50
|
+
export class Ewyn {
|
|
50
51
|
workspaceId;
|
|
51
52
|
apiKey;
|
|
52
|
-
baseUrl;
|
|
53
53
|
templates;
|
|
54
54
|
maxRetries;
|
|
55
55
|
timeout;
|
|
56
56
|
constructor(options) {
|
|
57
57
|
this.workspaceId = options.workspaceId;
|
|
58
58
|
this.apiKey = options.apiKey;
|
|
59
|
-
this.baseUrl = options.baseUrl || 'https://www.ewyn.ai/api/v1';
|
|
60
59
|
this.templates = options.templates;
|
|
61
60
|
this.maxRetries = options.maxRetries ?? 3;
|
|
62
61
|
this.timeout = options.timeout ?? 30000;
|
|
@@ -66,7 +65,7 @@ export class Mailer {
|
|
|
66
65
|
*
|
|
67
66
|
* @param options - Email sending options
|
|
68
67
|
* @returns Promise resolving to the send response
|
|
69
|
-
* @throws {
|
|
68
|
+
* @throws {EwynApiError} If the API request fails
|
|
70
69
|
*
|
|
71
70
|
* @example With template ID
|
|
72
71
|
* ```ts
|
|
@@ -166,7 +165,7 @@ export class Mailer {
|
|
|
166
165
|
* Make HTTP request with retry logic
|
|
167
166
|
*/
|
|
168
167
|
async requestWithRetry(path, init, attempt = 1) {
|
|
169
|
-
const url = `${
|
|
168
|
+
const url = `${EWYN_API_BASE_URL}${path}`;
|
|
170
169
|
const controller = new AbortController();
|
|
171
170
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
172
171
|
try {
|
|
@@ -177,7 +176,7 @@ export class Mailer {
|
|
|
177
176
|
clearTimeout(timeoutId);
|
|
178
177
|
const data = await response.json().catch(() => ({}));
|
|
179
178
|
if (!response.ok) {
|
|
180
|
-
const error = new
|
|
179
|
+
const error = new EwynApiError(response.status, data.code, data.details || data, data.error || data.message);
|
|
181
180
|
// Retry on retryable errors
|
|
182
181
|
if (error.isRetryable() && attempt < this.maxRetries) {
|
|
183
182
|
// Exponential backoff: 1s, 2s, 4s
|
|
@@ -191,12 +190,12 @@ export class Mailer {
|
|
|
191
190
|
}
|
|
192
191
|
catch (error) {
|
|
193
192
|
clearTimeout(timeoutId);
|
|
194
|
-
if (error instanceof
|
|
193
|
+
if (error instanceof EwynApiError) {
|
|
195
194
|
throw error;
|
|
196
195
|
}
|
|
197
196
|
// Handle network errors or timeouts
|
|
198
197
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
199
|
-
throw new
|
|
198
|
+
throw new EwynApiError(408, 'TIMEOUT', undefined, `Request timed out after ${this.timeout}ms`);
|
|
200
199
|
}
|
|
201
200
|
// Retry on network errors if we have attempts left
|
|
202
201
|
if (attempt < this.maxRetries) {
|
|
@@ -204,8 +203,8 @@ export class Mailer {
|
|
|
204
203
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
205
204
|
return this.requestWithRetry(path, init, attempt + 1);
|
|
206
205
|
}
|
|
207
|
-
throw new
|
|
206
|
+
throw new EwynApiError(500, 'NETWORK_ERROR', undefined, error instanceof Error ? error.message : 'Unknown network error');
|
|
208
207
|
}
|
|
209
208
|
}
|
|
210
209
|
}
|
|
211
|
-
export {
|
|
210
|
+
export { EwynApiError } from './errors.js';
|
package/dist/types.d.ts
CHANGED
|
@@ -97,15 +97,13 @@ export interface SendEmailResponse {
|
|
|
97
97
|
queuedAt: string;
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
* Configuration options for the
|
|
100
|
+
* Configuration options for the Ewyn client (base)
|
|
101
101
|
*/
|
|
102
|
-
export interface
|
|
102
|
+
export interface EwynOptionsBase {
|
|
103
103
|
/** Workspace ID (UUID) */
|
|
104
104
|
workspaceId: string;
|
|
105
105
|
/** API key secret */
|
|
106
106
|
apiKey: string;
|
|
107
|
-
/** Base URL for the API (defaults to production) */
|
|
108
|
-
baseUrl?: string;
|
|
109
107
|
/** Maximum number of retries for retryable errors (default: 3) */
|
|
110
108
|
maxRetries?: number;
|
|
111
109
|
/** Request timeout in milliseconds (default: 30000) */
|
|
@@ -114,16 +112,28 @@ export interface MailerOptionsBase {
|
|
|
114
112
|
/**
|
|
115
113
|
* Configuration options with typed template config
|
|
116
114
|
*/
|
|
117
|
-
export type
|
|
115
|
+
export type EwynOptionsTyped<TConfig extends TemplateConfig> = EwynOptionsBase & {
|
|
118
116
|
/** Template configuration for type-safe sending */
|
|
119
117
|
templates: TConfig;
|
|
120
118
|
};
|
|
121
119
|
/**
|
|
122
|
-
* Configuration options for the
|
|
120
|
+
* Configuration options for the Ewyn client (generic version)
|
|
123
121
|
*/
|
|
124
|
-
export type
|
|
122
|
+
export type EwynOptions = EwynOptionsBase & {
|
|
125
123
|
/** Template configuration for name-based sending and validation */
|
|
126
124
|
templates?: TemplateConfig;
|
|
127
125
|
};
|
|
126
|
+
/**
|
|
127
|
+
* Configuration for the fetch-config CLI (ewyn.config.ts).
|
|
128
|
+
* Used only by the CLI to know which workspace/API key to use and where to write the generated file.
|
|
129
|
+
*/
|
|
130
|
+
export interface EwynFetchConfig {
|
|
131
|
+
/** Workspace ID (UUID) */
|
|
132
|
+
workspaceId: string;
|
|
133
|
+
/** API key secret (e.g. process.env.EWYN_API_KEY) */
|
|
134
|
+
apiKey: string;
|
|
135
|
+
/** Output path for the generated ewynTemplates file (e.g. ./src/ewynTemplates.ts). If omitted, defaults to ./ewynTemplates.ts in cwd. */
|
|
136
|
+
configurationPath?: string;
|
|
137
|
+
}
|
|
128
138
|
export {};
|
|
129
139
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,EAAE,EAAE,MAAM,CA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AO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,OAAO,SAAS,cAAc,IAAI,eAAe,GAAG;IAC/E,mDAAmD;IACnD,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG;IAC1C,mEAAmE;IACnE,SAAS,CAAC,EAAE,cAAc,CAAC;CAC5B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,0BAA0B;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,yIAAyI;IACzI,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ewyn/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Official TypeScript SDK for Ewyn email service with full type safety",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"ewyn": "./dist/cli.js"
|
|
16
|
+
},
|
|
14
17
|
"files": [
|
|
15
18
|
"dist"
|
|
16
19
|
],
|
|
@@ -35,7 +38,9 @@
|
|
|
35
38
|
"engines": {
|
|
36
39
|
"node": ">=18.0.0"
|
|
37
40
|
},
|
|
38
|
-
"dependencies": {
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"tsx": "^4.19.0"
|
|
43
|
+
},
|
|
39
44
|
"devDependencies": {
|
|
40
45
|
"@types/node": "^20.11.0",
|
|
41
46
|
"@workspace/eslint-config": "workspace:*",
|