@technomoron/mail-magic-client 1.0.34 → 1.0.35
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/CHANGES +5 -0
- package/dist/cjs/mail-magic-client.d.ts +1 -0
- package/dist/cjs/mail-magic-client.js +17 -23
- package/dist/esm/mail-magic-client.js +17 -23
- package/package.json +1 -1
package/CHANGES
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
CHANGES
|
|
2
2
|
=======
|
|
3
3
|
|
|
4
|
+
Version 1.0.35 (2026-03-05)
|
|
5
|
+
|
|
6
|
+
- fix(client): check response `content-type` header in `postFormData` before calling `response.json()`; extract shared `parseJsonResponse` helper used by both `request()` and `postFormData()`.
|
|
7
|
+
- (Changes generated/assisted by Claude Code (profile: anthropic-claude-opus-4-6/high).)
|
|
8
|
+
|
|
4
9
|
Version 1.0.34 (2026-03-04)
|
|
5
10
|
|
|
6
11
|
- chore(dist): remove generated `dist/mail-magic-client.js` artifact from package tree.
|
|
@@ -77,6 +77,7 @@ declare class TemplateClient {
|
|
|
77
77
|
private baseURL;
|
|
78
78
|
private apiKey;
|
|
79
79
|
constructor(baseURL: string, apiKey: string);
|
|
80
|
+
private parseJsonResponse;
|
|
80
81
|
request<T>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', command: string, body?: RequestBody): Promise<T>;
|
|
81
82
|
get<T>(command: string): Promise<T>;
|
|
82
83
|
post<T>(command: string, body: RequestBody): Promise<T>;
|
|
@@ -15,6 +15,21 @@ class TemplateClient {
|
|
|
15
15
|
throw new Error('Apikey/api-url required');
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
async parseJsonResponse(response) {
|
|
19
|
+
const contentType = response.headers.get('content-type') || '';
|
|
20
|
+
if (!contentType.includes('application/json')) {
|
|
21
|
+
const text = await response.text();
|
|
22
|
+
throw new Error(`FETCH FAILED: ${response.status} unexpected content-type "${contentType}" - ${text.slice(0, 200)}`);
|
|
23
|
+
}
|
|
24
|
+
const j = await response.json();
|
|
25
|
+
if (response.ok) {
|
|
26
|
+
return j;
|
|
27
|
+
}
|
|
28
|
+
if (j && j.message) {
|
|
29
|
+
throw new Error(`FETCH FAILED: ${response.status} ${j.message}`);
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`FETCH FAILED: ${response.status} ${response.statusText}`);
|
|
32
|
+
}
|
|
18
33
|
async request(method, command, body) {
|
|
19
34
|
const url = `${this.baseURL}${command}`;
|
|
20
35
|
const headers = {
|
|
@@ -31,21 +46,7 @@ class TemplateClient {
|
|
|
31
46
|
options.body = JSON.stringify(body);
|
|
32
47
|
}
|
|
33
48
|
const response = await fetch(url, options);
|
|
34
|
-
|
|
35
|
-
if (!contentType.includes('application/json')) {
|
|
36
|
-
const text = await response.text();
|
|
37
|
-
throw new Error(`FETCH FAILED: ${response.status} unexpected content-type "${contentType}" - ${text.slice(0, 200)}`);
|
|
38
|
-
}
|
|
39
|
-
const j = await response.json();
|
|
40
|
-
if (response.ok) {
|
|
41
|
-
return j;
|
|
42
|
-
}
|
|
43
|
-
if (j && j.message) {
|
|
44
|
-
throw new Error(`FETCH FAILED: ${response.status} ${j.message}`);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
throw new Error(`FETCH FAILED: ${response.status} ${response.statusText}`);
|
|
48
|
-
}
|
|
49
|
+
return this.parseJsonResponse(response);
|
|
49
50
|
}
|
|
50
51
|
async get(command) {
|
|
51
52
|
return this.request('GET', command);
|
|
@@ -144,14 +145,7 @@ class TemplateClient {
|
|
|
144
145
|
},
|
|
145
146
|
body: formData
|
|
146
147
|
});
|
|
147
|
-
|
|
148
|
-
if (response.ok) {
|
|
149
|
-
return j;
|
|
150
|
-
}
|
|
151
|
-
if (j && j.message) {
|
|
152
|
-
throw new Error(`FETCH FAILED: ${response.status} ${j.message}`);
|
|
153
|
-
}
|
|
154
|
-
throw new Error(`FETCH FAILED: ${response.status} ${response.statusText}`);
|
|
148
|
+
return this.parseJsonResponse(response);
|
|
155
149
|
}
|
|
156
150
|
async storeTemplate(td) {
|
|
157
151
|
// Backward-compatible alias for transactional template storage.
|
|
@@ -10,6 +10,21 @@ class TemplateClient {
|
|
|
10
10
|
throw new Error('Apikey/api-url required');
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
async parseJsonResponse(response) {
|
|
14
|
+
const contentType = response.headers.get('content-type') || '';
|
|
15
|
+
if (!contentType.includes('application/json')) {
|
|
16
|
+
const text = await response.text();
|
|
17
|
+
throw new Error(`FETCH FAILED: ${response.status} unexpected content-type "${contentType}" - ${text.slice(0, 200)}`);
|
|
18
|
+
}
|
|
19
|
+
const j = await response.json();
|
|
20
|
+
if (response.ok) {
|
|
21
|
+
return j;
|
|
22
|
+
}
|
|
23
|
+
if (j && j.message) {
|
|
24
|
+
throw new Error(`FETCH FAILED: ${response.status} ${j.message}`);
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`FETCH FAILED: ${response.status} ${response.statusText}`);
|
|
27
|
+
}
|
|
13
28
|
async request(method, command, body) {
|
|
14
29
|
const url = `${this.baseURL}${command}`;
|
|
15
30
|
const headers = {
|
|
@@ -26,21 +41,7 @@ class TemplateClient {
|
|
|
26
41
|
options.body = JSON.stringify(body);
|
|
27
42
|
}
|
|
28
43
|
const response = await fetch(url, options);
|
|
29
|
-
|
|
30
|
-
if (!contentType.includes('application/json')) {
|
|
31
|
-
const text = await response.text();
|
|
32
|
-
throw new Error(`FETCH FAILED: ${response.status} unexpected content-type "${contentType}" - ${text.slice(0, 200)}`);
|
|
33
|
-
}
|
|
34
|
-
const j = await response.json();
|
|
35
|
-
if (response.ok) {
|
|
36
|
-
return j;
|
|
37
|
-
}
|
|
38
|
-
if (j && j.message) {
|
|
39
|
-
throw new Error(`FETCH FAILED: ${response.status} ${j.message}`);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
throw new Error(`FETCH FAILED: ${response.status} ${response.statusText}`);
|
|
43
|
-
}
|
|
44
|
+
return this.parseJsonResponse(response);
|
|
44
45
|
}
|
|
45
46
|
async get(command) {
|
|
46
47
|
return this.request('GET', command);
|
|
@@ -139,14 +140,7 @@ class TemplateClient {
|
|
|
139
140
|
},
|
|
140
141
|
body: formData
|
|
141
142
|
});
|
|
142
|
-
|
|
143
|
-
if (response.ok) {
|
|
144
|
-
return j;
|
|
145
|
-
}
|
|
146
|
-
if (j && j.message) {
|
|
147
|
-
throw new Error(`FETCH FAILED: ${response.status} ${j.message}`);
|
|
148
|
-
}
|
|
149
|
-
throw new Error(`FETCH FAILED: ${response.status} ${response.statusText}`);
|
|
143
|
+
return this.parseJsonResponse(response);
|
|
150
144
|
}
|
|
151
145
|
async storeTemplate(td) {
|
|
152
146
|
// Backward-compatible alias for transactional template storage.
|