samva 0.50.0 → 0.52.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/AGENTS.md +49 -5
- package/README.md +137 -7
- package/dist/client/sdk.gen.d.ts +78 -38
- package/dist/client/sdk.gen.js +1554 -967
- package/dist/client/types.gen.d.ts +541 -291
- package/dist/effect/agents.d.ts +4 -4
- package/dist/effect/api-keys.d.ts +4 -6
- package/dist/effect/campaigns.d.ts +222 -230
- package/dist/effect/categories.d.ts +2 -2
- package/dist/effect/categories.js +6 -4
- package/dist/effect/contact-groups.d.ts +4 -4
- package/dist/effect/contacts.d.ts +8 -8
- package/dist/effect/conversations.d.ts +4 -4
- package/dist/effect/descriptors/integrations-catalog.d.ts +1 -1
- package/dist/effect/descriptors/integrations-catalog.js +1 -1
- package/dist/effect/descriptors/integrations.d.ts +1 -1
- package/dist/effect/descriptors/integrations.js +1 -1
- package/dist/effect/descriptors/logs.d.ts +21 -0
- package/dist/effect/descriptors/logs.js +23 -0
- package/dist/effect/descriptors/whats-app.d.ts +1 -1
- package/dist/effect/descriptors/whats-app.js +1 -1
- package/dist/effect/email.d.ts +17 -16
- package/dist/effect/errors.d.ts +1 -0
- package/dist/effect/errors.js +2 -1
- package/dist/effect/generated/agents.js +4 -4
- package/dist/effect/generated/api-keys.d.ts +0 -15
- package/dist/effect/generated/api-keys.js +1 -2
- package/dist/effect/generated/campaigns.d.ts +18 -68
- package/dist/effect/generated/campaigns.js +5 -15
- package/dist/effect/generated/email.d.ts +10 -3
- package/dist/effect/generated/email.js +6 -5
- package/dist/effect/generated/index.d.ts +3 -1
- package/dist/effect/generated/integrations-catalog.d.ts +93 -49
- package/dist/effect/generated/integrations-catalog.js +17 -28
- package/dist/effect/generated/integrations.d.ts +20 -40
- package/dist/effect/generated/integrations.js +9 -13
- package/dist/effect/generated/journeys.d.ts +61 -13
- package/dist/effect/generated/journeys.js +5 -5
- package/dist/effect/generated/logs.d.ts +2311 -0
- package/dist/effect/generated/logs.js +312 -0
- package/dist/effect/generated/mailboxes.d.ts +30 -24
- package/dist/effect/generated/mailboxes.js +25 -25
- package/dist/effect/generated/messages.d.ts +1 -882
- package/dist/effect/generated/messages.js +4 -243
- package/dist/effect/generated/namespaces.js +1 -1
- package/dist/effect/generated/newsletter-domains.d.ts +61 -13
- package/dist/effect/generated/newsletter-domains.js +5 -5
- package/dist/effect/generated/newsletter-issues.d.ts +166 -34
- package/dist/effect/generated/newsletter-issues.js +12 -12
- package/dist/effect/generated/newsletters.d.ts +76 -16
- package/dist/effect/generated/newsletters.js +6 -6
- package/dist/effect/generated/organizations.js +1 -1
- package/dist/effect/generated/policies.js +2 -2
- package/dist/effect/generated/scheduled-messages.d.ts +0 -26
- package/dist/effect/generated/scheduled-messages.js +2 -4
- package/dist/effect/generated/shared.d.ts +1139 -257
- package/dist/effect/generated/shared.js +323 -83
- package/dist/effect/generated/subscriptions.d.ts +4 -4
- package/dist/effect/generated/subscriptions.js +2 -6
- package/dist/effect/generated/template-registrations.d.ts +46 -10
- package/dist/effect/generated/template-registrations.js +4 -4
- package/dist/effect/generated/templates.js +2 -2
- package/dist/effect/generated/whats-app-flows.d.ts +151 -31
- package/dist/effect/generated/whats-app-flows.js +11 -11
- package/dist/effect/generated/whats-app-setup-links.d.ts +61 -13
- package/dist/effect/generated/whats-app-setup-links.js +5 -5
- package/dist/effect/generated/whats-app.d.ts +187 -65
- package/dist/effect/generated/whats-app.js +18 -24
- package/dist/effect/generated-metadata.d.ts +15 -3
- package/dist/effect/generated-metadata.js +375 -349
- package/dist/effect/index.d.ts +1 -0
- package/dist/effect/index.js +3 -1
- package/dist/effect/integrations-catalog.d.ts +92 -4
- package/dist/effect/integrations.d.ts +42 -10
- package/dist/effect/internal/client.d.ts +19 -2
- package/dist/effect/internal/client.js +35 -5
- package/dist/effect/internal/email-sender.d.ts +4 -4
- package/dist/effect/internal/email-sender.js +5 -3
- package/dist/effect/internal/log-events.d.ts +19 -0
- package/dist/effect/internal/log-events.js +53 -0
- package/dist/effect/internal/mailbox-events.d.ts +6 -2
- package/dist/effect/internal/mailbox-events.js +4 -3
- package/dist/effect/internal/operation.d.ts +11 -0
- package/dist/effect/internal/operation.js +10 -6
- package/dist/effect/internal/send.d.ts +4 -0
- package/dist/effect/internal/send.js +11 -8
- package/dist/effect/internal/timeout.d.ts +16 -0
- package/dist/effect/internal/timeout.js +20 -0
- package/dist/effect/journeys.d.ts +4 -4
- package/dist/effect/logs.d.ts +149 -0
- package/dist/effect/logs.js +18 -0
- package/dist/effect/mailboxes.d.ts +184 -178
- package/dist/effect/mailboxes.js +1 -1
- package/dist/effect/messages.d.ts +5 -5
- package/dist/effect/namespaces.d.ts +4 -4
- package/dist/effect/newsletter-domains.d.ts +2 -2
- package/dist/effect/operations.d.ts +2 -2
- package/dist/effect/scheduled-messages.d.ts +2 -6
- package/dist/effect/templates.d.ts +6 -6
- package/dist/effect/topics.d.ts +4 -4
- package/dist/effect/webhooks.d.ts +4 -4
- package/dist/effect/whatsapp-setup-links.d.ts +2 -2
- package/dist/effect/whatsapp.d.ts +73 -3
- package/dist/index.js +2 -2
- package/dist/mailbox-events.d.ts +50 -3
- package/dist/mailbox-events.js +38 -19
- package/dist/package.js +1 -1
- package/dist/promises/client.d.ts +8 -1
- package/dist/promises/client.js +15 -9
- package/dist/promises/errors.gen.d.ts +14 -1
- package/dist/promises/errors.gen.js +158 -36
- package/dist/promises/index.js +2 -2
- package/dist/promises/request.d.ts +31 -2
- package/dist/promises/request.js +42 -7
- package/dist/promises/types.gen.d.ts +1 -1
- package/dist/request-id.d.ts +3 -0
- package/dist/request-id.js +7 -0
- package/dist/request-policy.d.ts +9 -0
- package/dist/request-policy.js +16 -1
- package/dist/service-map.d.ts +14 -3
- package/package.json +6 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { samvaRequestId, withRequestIdMessage } from "../request-id.js";
|
|
1
2
|
// src/promises/errors.gen.ts
|
|
2
3
|
const redactRequest = (request) => request === void 0 ? void 0 : new Request(request.url, { method: request.method });
|
|
3
4
|
/** Base class for failures declared by the public Samva OpenAPI contract. */
|
|
@@ -5,12 +6,15 @@ var SamvaApiError = class extends Error {
|
|
|
5
6
|
request;
|
|
6
7
|
response;
|
|
7
8
|
status;
|
|
9
|
+
requestId;
|
|
8
10
|
constructor(message, context = {}) {
|
|
9
|
-
|
|
11
|
+
const requestId = samvaRequestId(context.response?.headers.get("x-samva-request-id"));
|
|
12
|
+
super(withRequestIdMessage(message, requestId));
|
|
10
13
|
this.name = new.target.name;
|
|
11
14
|
this.request = redactRequest(context.request);
|
|
12
15
|
this.response = context.response;
|
|
13
16
|
this.status = context.response?.status;
|
|
17
|
+
this.requestId = requestId;
|
|
14
18
|
}
|
|
15
19
|
};
|
|
16
20
|
/** A transport or malformed-response failure that is not part of the API error contract. */
|
|
@@ -19,14 +23,31 @@ var SamvaTransportError = class extends Error {
|
|
|
19
23
|
request;
|
|
20
24
|
response;
|
|
21
25
|
status;
|
|
26
|
+
requestId;
|
|
22
27
|
cause;
|
|
23
28
|
constructor(cause, context = {}) {
|
|
24
|
-
|
|
29
|
+
const requestId = samvaRequestId(context.response?.headers.get("x-samva-request-id"));
|
|
30
|
+
super(withRequestIdMessage(cause instanceof Error ? cause.message : "Samva request failed", requestId), { cause });
|
|
25
31
|
this.name = "SamvaTransportError";
|
|
26
32
|
this.cause = cause;
|
|
27
33
|
this.request = redactRequest(context.request);
|
|
28
34
|
this.response = context.response;
|
|
29
35
|
this.status = context.response?.status;
|
|
36
|
+
this.requestId = requestId;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* A request attempt that did not finish within its `timeoutMs`. The request may still have
|
|
41
|
+
* reached the API, so a keyed write retries with the same idempotency key.
|
|
42
|
+
*/
|
|
43
|
+
var SamvaTimeoutError = class extends SamvaTransportError {
|
|
44
|
+
_tag = "SamvaTimeoutError";
|
|
45
|
+
timeoutMs;
|
|
46
|
+
constructor(timeoutMs) {
|
|
47
|
+
super(void 0);
|
|
48
|
+
this.name = "SamvaTimeoutError";
|
|
49
|
+
this.message = "Samva request did not finish within " + timeoutMs + " ms";
|
|
50
|
+
this.timeoutMs = timeoutMs;
|
|
30
51
|
}
|
|
31
52
|
};
|
|
32
53
|
const messageOf = (tag, payload) => {
|
|
@@ -37,224 +58,320 @@ var AnalyticsQueryError = class extends SamvaApiError {
|
|
|
37
58
|
_tag = "AnalyticsQueryError";
|
|
38
59
|
constructor(payload, context = {}) {
|
|
39
60
|
super(messageOf("AnalyticsQueryError", payload), context);
|
|
40
|
-
Object.assign(this, payload
|
|
61
|
+
Object.assign(this, payload, {
|
|
62
|
+
message: this.message,
|
|
63
|
+
requestId: this.requestId
|
|
64
|
+
});
|
|
41
65
|
}
|
|
42
66
|
};
|
|
43
67
|
var BillingProviderError = class extends SamvaApiError {
|
|
44
68
|
_tag = "BillingProviderError";
|
|
45
69
|
constructor(payload, context = {}) {
|
|
46
70
|
super(messageOf("BillingProviderError", payload), context);
|
|
47
|
-
Object.assign(this, payload
|
|
71
|
+
Object.assign(this, payload, {
|
|
72
|
+
message: this.message,
|
|
73
|
+
requestId: this.requestId
|
|
74
|
+
});
|
|
48
75
|
}
|
|
49
76
|
};
|
|
50
77
|
var BrandAddressRequiredError = class extends SamvaApiError {
|
|
51
78
|
_tag = "BrandAddressRequiredError";
|
|
52
79
|
constructor(payload, context = {}) {
|
|
53
80
|
super(messageOf("BrandAddressRequiredError", payload), context);
|
|
54
|
-
Object.assign(this, payload
|
|
81
|
+
Object.assign(this, payload, {
|
|
82
|
+
message: this.message,
|
|
83
|
+
requestId: this.requestId
|
|
84
|
+
});
|
|
55
85
|
}
|
|
56
86
|
};
|
|
57
87
|
var CampaignFooterRequiredError = class extends SamvaApiError {
|
|
58
88
|
_tag = "CampaignFooterRequiredError";
|
|
59
89
|
constructor(payload, context = {}) {
|
|
60
90
|
super(messageOf("CampaignFooterRequiredError", payload), context);
|
|
61
|
-
Object.assign(this, payload
|
|
91
|
+
Object.assign(this, payload, {
|
|
92
|
+
message: this.message,
|
|
93
|
+
requestId: this.requestId
|
|
94
|
+
});
|
|
62
95
|
}
|
|
63
96
|
};
|
|
64
97
|
var ConflictError = class extends SamvaApiError {
|
|
65
98
|
_tag = "ConflictError";
|
|
66
99
|
constructor(payload, context = {}) {
|
|
67
100
|
super(messageOf("ConflictError", payload), context);
|
|
68
|
-
Object.assign(this, payload
|
|
101
|
+
Object.assign(this, payload, {
|
|
102
|
+
message: this.message,
|
|
103
|
+
requestId: this.requestId
|
|
104
|
+
});
|
|
69
105
|
}
|
|
70
106
|
};
|
|
71
107
|
var CredentialsError = class extends SamvaApiError {
|
|
72
108
|
_tag = "CredentialsError";
|
|
73
109
|
constructor(payload, context = {}) {
|
|
74
110
|
super(messageOf("CredentialsError", payload), context);
|
|
75
|
-
Object.assign(this, payload
|
|
111
|
+
Object.assign(this, payload, {
|
|
112
|
+
message: this.message,
|
|
113
|
+
requestId: this.requestId
|
|
114
|
+
});
|
|
76
115
|
}
|
|
77
116
|
};
|
|
78
117
|
var DeliveryUnavailableError = class extends SamvaApiError {
|
|
79
118
|
_tag = "DeliveryUnavailableError";
|
|
80
119
|
constructor(payload, context = {}) {
|
|
81
120
|
super(messageOf("DeliveryUnavailableError", payload), context);
|
|
82
|
-
Object.assign(this, payload
|
|
121
|
+
Object.assign(this, payload, {
|
|
122
|
+
message: this.message,
|
|
123
|
+
requestId: this.requestId
|
|
124
|
+
});
|
|
83
125
|
}
|
|
84
126
|
};
|
|
85
127
|
var EmailChannelError = class extends SamvaApiError {
|
|
86
128
|
_tag = "EmailChannelError";
|
|
87
129
|
constructor(payload, context = {}) {
|
|
88
130
|
super(messageOf("EmailChannelError", payload), context);
|
|
89
|
-
Object.assign(this, payload
|
|
131
|
+
Object.assign(this, payload, {
|
|
132
|
+
message: this.message,
|
|
133
|
+
requestId: this.requestId
|
|
134
|
+
});
|
|
90
135
|
}
|
|
91
136
|
};
|
|
92
137
|
var ExternalServiceError = class extends SamvaApiError {
|
|
93
138
|
_tag = "ExternalServiceError";
|
|
94
139
|
constructor(payload, context = {}) {
|
|
95
140
|
super(messageOf("ExternalServiceError", payload), context);
|
|
96
|
-
Object.assign(this, payload
|
|
141
|
+
Object.assign(this, payload, {
|
|
142
|
+
message: this.message,
|
|
143
|
+
requestId: this.requestId
|
|
144
|
+
});
|
|
97
145
|
}
|
|
98
146
|
};
|
|
99
147
|
var FlagDisabledError = class extends SamvaApiError {
|
|
100
148
|
_tag = "FlagDisabledError";
|
|
101
149
|
constructor(payload, context = {}) {
|
|
102
150
|
super(messageOf("FlagDisabledError", payload), context);
|
|
103
|
-
Object.assign(this, payload
|
|
151
|
+
Object.assign(this, payload, {
|
|
152
|
+
message: this.message,
|
|
153
|
+
requestId: this.requestId
|
|
154
|
+
});
|
|
104
155
|
}
|
|
105
156
|
};
|
|
106
157
|
var ForbiddenError = class extends SamvaApiError {
|
|
107
158
|
_tag = "ForbiddenError";
|
|
108
159
|
constructor(payload, context = {}) {
|
|
109
160
|
super(messageOf("ForbiddenError", payload), context);
|
|
110
|
-
Object.assign(this, payload
|
|
161
|
+
Object.assign(this, payload, {
|
|
162
|
+
message: this.message,
|
|
163
|
+
requestId: this.requestId
|
|
164
|
+
});
|
|
111
165
|
}
|
|
112
166
|
};
|
|
113
167
|
var FromAddressRequiredError = class extends SamvaApiError {
|
|
114
168
|
_tag = "FromAddressRequiredError";
|
|
115
169
|
constructor(payload, context = {}) {
|
|
116
170
|
super(messageOf("FromAddressRequiredError", payload), context);
|
|
117
|
-
Object.assign(this, payload
|
|
171
|
+
Object.assign(this, payload, {
|
|
172
|
+
message: this.message,
|
|
173
|
+
requestId: this.requestId
|
|
174
|
+
});
|
|
118
175
|
}
|
|
119
176
|
};
|
|
120
177
|
var GatewayTimeoutError = class extends SamvaApiError {
|
|
121
178
|
_tag = "GatewayTimeoutError";
|
|
122
179
|
constructor(payload, context = {}) {
|
|
123
180
|
super(messageOf("GatewayTimeoutError", payload), context);
|
|
124
|
-
Object.assign(this, payload
|
|
181
|
+
Object.assign(this, payload, {
|
|
182
|
+
message: this.message,
|
|
183
|
+
requestId: this.requestId
|
|
184
|
+
});
|
|
125
185
|
}
|
|
126
186
|
};
|
|
127
187
|
var InternalError = class extends SamvaApiError {
|
|
128
188
|
_tag = "InternalError";
|
|
129
189
|
constructor(payload, context = {}) {
|
|
130
190
|
super(messageOf("InternalError", payload), context);
|
|
131
|
-
Object.assign(this, payload
|
|
191
|
+
Object.assign(this, payload, {
|
|
192
|
+
message: this.message,
|
|
193
|
+
requestId: this.requestId
|
|
194
|
+
});
|
|
132
195
|
}
|
|
133
196
|
};
|
|
134
197
|
var MailboxSendConflictError = class extends SamvaApiError {
|
|
135
198
|
_tag = "MailboxSendConflictError";
|
|
136
199
|
constructor(payload, context = {}) {
|
|
137
200
|
super(messageOf("MailboxSendConflictError", payload), context);
|
|
138
|
-
Object.assign(this, payload
|
|
201
|
+
Object.assign(this, payload, {
|
|
202
|
+
message: this.message,
|
|
203
|
+
requestId: this.requestId
|
|
204
|
+
});
|
|
139
205
|
}
|
|
140
206
|
};
|
|
141
207
|
var MailboxSendRefusedError = class extends SamvaApiError {
|
|
142
208
|
_tag = "MailboxSendRefusedError";
|
|
143
209
|
constructor(payload, context = {}) {
|
|
144
210
|
super(messageOf("MailboxSendRefusedError", payload), context);
|
|
145
|
-
Object.assign(this, payload
|
|
211
|
+
Object.assign(this, payload, {
|
|
212
|
+
message: this.message,
|
|
213
|
+
requestId: this.requestId
|
|
214
|
+
});
|
|
146
215
|
}
|
|
147
216
|
};
|
|
148
217
|
var MalformedRequestError = class extends SamvaApiError {
|
|
149
218
|
_tag = "MalformedRequestError";
|
|
150
219
|
constructor(payload, context = {}) {
|
|
151
220
|
super(messageOf("MalformedRequestError", payload), context);
|
|
152
|
-
Object.assign(this, payload
|
|
221
|
+
Object.assign(this, payload, {
|
|
222
|
+
message: this.message,
|
|
223
|
+
requestId: this.requestId
|
|
224
|
+
});
|
|
153
225
|
}
|
|
154
226
|
};
|
|
155
227
|
var OnboardingReviewRequiredError = class extends SamvaApiError {
|
|
156
228
|
_tag = "OnboardingReviewRequiredError";
|
|
157
229
|
constructor(payload, context = {}) {
|
|
158
230
|
super(messageOf("OnboardingReviewRequiredError", payload), context);
|
|
159
|
-
Object.assign(this, payload
|
|
231
|
+
Object.assign(this, payload, {
|
|
232
|
+
message: this.message,
|
|
233
|
+
requestId: this.requestId
|
|
234
|
+
});
|
|
160
235
|
}
|
|
161
236
|
};
|
|
162
237
|
var PaymentRequiredError = class extends SamvaApiError {
|
|
163
238
|
_tag = "PaymentRequiredError";
|
|
164
239
|
constructor(payload, context = {}) {
|
|
165
240
|
super(messageOf("PaymentRequiredError", payload), context);
|
|
166
|
-
Object.assign(this, payload
|
|
241
|
+
Object.assign(this, payload, {
|
|
242
|
+
message: this.message,
|
|
243
|
+
requestId: this.requestId
|
|
244
|
+
});
|
|
167
245
|
}
|
|
168
246
|
};
|
|
169
247
|
var RateLimitedError = class extends SamvaApiError {
|
|
170
248
|
_tag = "RateLimitedError";
|
|
171
249
|
constructor(payload, context = {}) {
|
|
172
250
|
super(messageOf("RateLimitedError", payload), context);
|
|
173
|
-
Object.assign(this, payload
|
|
251
|
+
Object.assign(this, payload, {
|
|
252
|
+
message: this.message,
|
|
253
|
+
requestId: this.requestId
|
|
254
|
+
});
|
|
174
255
|
}
|
|
175
256
|
};
|
|
176
257
|
var ResourceNotFoundError = class extends SamvaApiError {
|
|
177
258
|
_tag = "ResourceNotFoundError";
|
|
178
259
|
constructor(payload, context = {}) {
|
|
179
260
|
super(messageOf("ResourceNotFoundError", payload), context);
|
|
180
|
-
Object.assign(this, payload
|
|
261
|
+
Object.assign(this, payload, {
|
|
262
|
+
message: this.message,
|
|
263
|
+
requestId: this.requestId
|
|
264
|
+
});
|
|
181
265
|
}
|
|
182
266
|
};
|
|
183
267
|
var SenderNotReadyError = class extends SamvaApiError {
|
|
184
268
|
_tag = "SenderNotReadyError";
|
|
185
269
|
constructor(payload, context = {}) {
|
|
186
270
|
super(messageOf("SenderNotReadyError", payload), context);
|
|
187
|
-
Object.assign(this, payload
|
|
271
|
+
Object.assign(this, payload, {
|
|
272
|
+
message: this.message,
|
|
273
|
+
requestId: this.requestId
|
|
274
|
+
});
|
|
188
275
|
}
|
|
189
276
|
};
|
|
190
277
|
var ServiceUnavailableError = class extends SamvaApiError {
|
|
191
278
|
_tag = "ServiceUnavailableError";
|
|
192
279
|
constructor(payload, context = {}) {
|
|
193
280
|
super(messageOf("ServiceUnavailableError", payload), context);
|
|
194
|
-
Object.assign(this, payload
|
|
281
|
+
Object.assign(this, payload, {
|
|
282
|
+
message: this.message,
|
|
283
|
+
requestId: this.requestId
|
|
284
|
+
});
|
|
195
285
|
}
|
|
196
286
|
};
|
|
197
287
|
var ShareLinkUnavailable = class extends SamvaApiError {
|
|
198
288
|
_tag = "ShareLinkUnavailable";
|
|
199
289
|
constructor(payload, context = {}) {
|
|
200
290
|
super(messageOf("ShareLinkUnavailable", payload), context);
|
|
201
|
-
Object.assign(this, payload
|
|
291
|
+
Object.assign(this, payload, {
|
|
292
|
+
message: this.message,
|
|
293
|
+
requestId: this.requestId
|
|
294
|
+
});
|
|
202
295
|
}
|
|
203
296
|
};
|
|
204
297
|
var SlugTaken = class extends SamvaApiError {
|
|
205
298
|
_tag = "SlugTaken";
|
|
206
299
|
constructor(payload, context = {}) {
|
|
207
300
|
super(messageOf("SlugTaken", payload), context);
|
|
208
|
-
Object.assign(this, payload
|
|
301
|
+
Object.assign(this, payload, {
|
|
302
|
+
message: this.message,
|
|
303
|
+
requestId: this.requestId
|
|
304
|
+
});
|
|
209
305
|
}
|
|
210
306
|
};
|
|
211
307
|
var TemplateInUseError = class extends SamvaApiError {
|
|
212
308
|
_tag = "TemplateInUseError";
|
|
213
309
|
constructor(payload, context = {}) {
|
|
214
310
|
super(messageOf("TemplateInUseError", payload), context);
|
|
215
|
-
Object.assign(this, payload
|
|
311
|
+
Object.assign(this, payload, {
|
|
312
|
+
message: this.message,
|
|
313
|
+
requestId: this.requestId
|
|
314
|
+
});
|
|
216
315
|
}
|
|
217
316
|
};
|
|
218
317
|
var TemplateSourceError = class extends SamvaApiError {
|
|
219
318
|
_tag = "TemplateSourceError";
|
|
220
319
|
constructor(payload, context = {}) {
|
|
221
320
|
super(messageOf("TemplateSourceError", payload), context);
|
|
222
|
-
Object.assign(this, payload
|
|
321
|
+
Object.assign(this, payload, {
|
|
322
|
+
message: this.message,
|
|
323
|
+
requestId: this.requestId
|
|
324
|
+
});
|
|
223
325
|
}
|
|
224
326
|
};
|
|
225
327
|
var UnauthorizedError = class extends SamvaApiError {
|
|
226
328
|
_tag = "UnauthorizedError";
|
|
227
329
|
constructor(payload, context = {}) {
|
|
228
330
|
super(messageOf("UnauthorizedError", payload), context);
|
|
229
|
-
Object.assign(this, payload
|
|
331
|
+
Object.assign(this, payload, {
|
|
332
|
+
message: this.message,
|
|
333
|
+
requestId: this.requestId
|
|
334
|
+
});
|
|
230
335
|
}
|
|
231
336
|
};
|
|
232
337
|
var ValidationError = class extends SamvaApiError {
|
|
233
338
|
_tag = "ValidationError";
|
|
234
339
|
constructor(payload, context = {}) {
|
|
235
340
|
super(messageOf("ValidationError", payload), context);
|
|
236
|
-
Object.assign(this, payload
|
|
341
|
+
Object.assign(this, payload, {
|
|
342
|
+
message: this.message,
|
|
343
|
+
requestId: this.requestId
|
|
344
|
+
});
|
|
237
345
|
}
|
|
238
346
|
};
|
|
239
347
|
var WhatsAppChannelError = class extends SamvaApiError {
|
|
240
348
|
_tag = "WhatsAppChannelError";
|
|
241
349
|
constructor(payload, context = {}) {
|
|
242
350
|
super(messageOf("WhatsAppChannelError", payload), context);
|
|
243
|
-
Object.assign(this, payload
|
|
351
|
+
Object.assign(this, payload, {
|
|
352
|
+
message: this.message,
|
|
353
|
+
requestId: this.requestId
|
|
354
|
+
});
|
|
244
355
|
}
|
|
245
356
|
};
|
|
246
357
|
var WhatsAppServiceWindowClosedError = class extends SamvaApiError {
|
|
247
358
|
_tag = "WhatsAppServiceWindowClosedError";
|
|
248
359
|
constructor(payload, context = {}) {
|
|
249
360
|
super(messageOf("WhatsAppServiceWindowClosedError", payload), context);
|
|
250
|
-
Object.assign(this, payload
|
|
361
|
+
Object.assign(this, payload, {
|
|
362
|
+
message: this.message,
|
|
363
|
+
requestId: this.requestId
|
|
364
|
+
});
|
|
251
365
|
}
|
|
252
366
|
};
|
|
253
367
|
var WhatsAppSetupLinkUnavailableError = class extends SamvaApiError {
|
|
254
368
|
_tag = "WhatsAppSetupLinkUnavailableError";
|
|
255
369
|
constructor(payload, context = {}) {
|
|
256
370
|
super(messageOf("WhatsAppSetupLinkUnavailableError", payload), context);
|
|
257
|
-
Object.assign(this, payload
|
|
371
|
+
Object.assign(this, payload, {
|
|
372
|
+
message: this.message,
|
|
373
|
+
requestId: this.requestId
|
|
374
|
+
});
|
|
258
375
|
}
|
|
259
376
|
};
|
|
260
377
|
const constructors = {
|
|
@@ -522,12 +639,17 @@ const payloadSchemas = {
|
|
|
522
639
|
verifiedDomains: {
|
|
523
640
|
type: "array",
|
|
524
641
|
items: { type: "string" }
|
|
642
|
+
},
|
|
643
|
+
addresses: {
|
|
644
|
+
type: "array",
|
|
645
|
+
items: { type: "string" }
|
|
525
646
|
}
|
|
526
647
|
},
|
|
527
648
|
required: [
|
|
528
649
|
"_tag",
|
|
529
650
|
"message",
|
|
530
|
-
"verifiedDomains"
|
|
651
|
+
"verifiedDomains",
|
|
652
|
+
"addresses"
|
|
531
653
|
],
|
|
532
654
|
additionalProperties: false,
|
|
533
655
|
"x-category": ["validation"],
|
|
@@ -2072,6 +2194,6 @@ function fromApiError(error, context = {}) {
|
|
|
2072
2194
|
}
|
|
2073
2195
|
return new SamvaTransportError(error, context);
|
|
2074
2196
|
}
|
|
2075
|
-
export { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, CredentialsError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, MalformedRequestError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTransportError, SenderNotReadyError, ServiceUnavailableError, ShareLinkUnavailable, SlugTaken, TemplateInUseError, TemplateSourceError, UnauthorizedError, ValidationError, WhatsAppChannelError, WhatsAppServiceWindowClosedError, WhatsAppSetupLinkUnavailableError, fromApiError };
|
|
2197
|
+
export { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, CredentialsError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, MalformedRequestError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTimeoutError, SamvaTransportError, SenderNotReadyError, ServiceUnavailableError, ShareLinkUnavailable, SlugTaken, TemplateInUseError, TemplateSourceError, UnauthorizedError, ValidationError, WhatsAppChannelError, WhatsAppServiceWindowClosedError, WhatsAppSetupLinkUnavailableError, fromApiError };
|
|
2076
2198
|
|
|
2077
2199
|
//# sourceMappingURL=errors.gen.js.map
|
package/dist/promises/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, CredentialsError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, MalformedRequestError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTransportError, SenderNotReadyError, ServiceUnavailableError, ShareLinkUnavailable, SlugTaken, TemplateInUseError, TemplateSourceError, UnauthorizedError, ValidationError, WhatsAppChannelError, WhatsAppServiceWindowClosedError, WhatsAppSetupLinkUnavailableError, fromApiError } from "./errors.gen.js";
|
|
1
|
+
import { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, CredentialsError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, MalformedRequestError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTimeoutError, SamvaTransportError, SenderNotReadyError, ServiceUnavailableError, ShareLinkUnavailable, SlugTaken, TemplateInUseError, TemplateSourceError, UnauthorizedError, ValidationError, WhatsAppChannelError, WhatsAppServiceWindowClosedError, WhatsAppSetupLinkUnavailableError, fromApiError } from "./errors.gen.js";
|
|
2
2
|
import { MediaUploadError } from "../inline-attachments.js";
|
|
3
3
|
import { MailboxEventStream, MailboxEventStreamError } from "../mailbox-events.js";
|
|
4
4
|
import { createClient } from "./client.js";
|
|
5
|
-
export { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, CredentialsError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxEventStream, MailboxEventStreamError, MailboxSendConflictError, MailboxSendRefusedError, MalformedRequestError, MediaUploadError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTransportError, SenderNotReadyError, ServiceUnavailableError, ShareLinkUnavailable, SlugTaken, TemplateInUseError, TemplateSourceError, UnauthorizedError, ValidationError, WhatsAppChannelError, WhatsAppServiceWindowClosedError, WhatsAppSetupLinkUnavailableError, createClient, fromApiError };
|
|
5
|
+
export { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, CredentialsError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxEventStream, MailboxEventStreamError, MailboxSendConflictError, MailboxSendRefusedError, MalformedRequestError, MediaUploadError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTimeoutError, SamvaTransportError, SenderNotReadyError, ServiceUnavailableError, ShareLinkUnavailable, SlugTaken, TemplateInUseError, TemplateSourceError, UnauthorizedError, ValidationError, WhatsAppChannelError, WhatsAppServiceWindowClosedError, WhatsAppSetupLinkUnavailableError, createClient, fromApiError };
|
|
@@ -1,15 +1,44 @@
|
|
|
1
1
|
import { type Client, mergeHeaders } from "../client/client/index.js";
|
|
2
2
|
import { SamvaOperations } from "../effect/generated-metadata.js";
|
|
3
|
+
import { type TimeoutSetting } from "../request-policy.js";
|
|
4
|
+
import { SamvaTimeoutError } from "./errors.gen.js";
|
|
3
5
|
export interface RequestPolicy {
|
|
4
6
|
readonly maxRetries?: number | undefined;
|
|
5
7
|
readonly idempotency?: ((operation: string) => string) | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Milliseconds each request attempt may take before it fails with `SamvaTimeoutError`
|
|
10
|
+
* (default 30 000). `null` disables the bound.
|
|
11
|
+
*/
|
|
12
|
+
readonly timeoutMs?: number | null | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Milliseconds each put of attachment bytes to storage may take (default 300 000). `null`
|
|
15
|
+
* disables the bound.
|
|
16
|
+
*/
|
|
17
|
+
readonly uploadTimeoutMs?: number | null | undefined;
|
|
6
18
|
}
|
|
7
19
|
export interface CallOptions {
|
|
8
20
|
readonly idempotencyKey?: string | undefined;
|
|
9
21
|
readonly maxRetries?: number | undefined;
|
|
22
|
+
/** Overrides the client's `timeoutMs` for this call; `undefined` inherits it. */
|
|
23
|
+
readonly timeoutMs?: number | null | undefined;
|
|
10
24
|
readonly headers?: Parameters<typeof mergeHeaders>[0];
|
|
11
25
|
readonly signal?: AbortSignal | null | undefined;
|
|
12
26
|
}
|
|
13
27
|
export declare const configureRequests: (client: Client, policy: RequestPolicy) => void;
|
|
14
|
-
/** The
|
|
15
|
-
export declare
|
|
28
|
+
/** The bound on one storage put: the call's `uploadTimeoutMs`, else the client's, else the default. */
|
|
29
|
+
export declare const uploadTimeout: (client: Client, call: TimeoutSetting) => number | null;
|
|
30
|
+
export interface Attempt {
|
|
31
|
+
/** The caller's signal joined with this attempt's own timer. */
|
|
32
|
+
readonly signal: AbortSignal | undefined;
|
|
33
|
+
/** The timeout, when the attempt's timer (not the caller) ended it. */
|
|
34
|
+
readonly timedOut: () => SamvaTimeoutError | undefined;
|
|
35
|
+
readonly end: () => void;
|
|
36
|
+
}
|
|
37
|
+
/** Each attempt gets a fresh timer, so a retry has the whole bound again. */
|
|
38
|
+
export declare const startAttempt: (signal: AbortSignal | null | undefined, timeoutMs: number | null) => Attempt;
|
|
39
|
+
/**
|
|
40
|
+
* The key belongs to a logical call, so all attempts share it and each invocation gets a fresh one.
|
|
41
|
+
* Each attempt runs under its own `timeoutMs` timer joined with the caller's signal; a timed-out
|
|
42
|
+
* attempt fails with `SamvaTimeoutError` and retries only where a transport failure would.
|
|
43
|
+
*/
|
|
44
|
+
export declare function requestWithPolicy<Result>(client: Client, operation: keyof typeof SamvaOperations, options: CallOptions | undefined, send: (headers: Record<string, string | null | undefined>, signal: AbortSignal | undefined) => Promise<Result>, input?: unknown): Promise<Result>;
|
package/dist/promises/request.js
CHANGED
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
import { mergeHeaders } from "../client/client/utils.gen.js";
|
|
2
2
|
import { SamvaErrorMetadata, SamvaOperations } from "../effect/generated-metadata.js";
|
|
3
|
-
import { isRetrySafe } from "../request-policy.js";
|
|
4
|
-
import { SamvaTransportError, fromApiError } from "./errors.gen.js";
|
|
3
|
+
import { DEFAULT_TIMEOUT_MS, DEFAULT_UPLOAD_TIMEOUT_MS, isRetrySafe, resolveTimeout, validateTimeout } from "../request-policy.js";
|
|
4
|
+
import { SamvaTimeoutError, SamvaTransportError, fromApiError } from "./errors.gen.js";
|
|
5
5
|
// src/promises/request.ts
|
|
6
6
|
const policies = /* @__PURE__ */ new WeakMap();
|
|
7
7
|
const configureRequests = (client, policy) => {
|
|
8
8
|
if (policy.maxRetries !== void 0) validateRetries(policy.maxRetries);
|
|
9
|
+
validateTimeout("timeoutMs", policy.timeoutMs);
|
|
10
|
+
validateTimeout("uploadTimeoutMs", policy.uploadTimeoutMs);
|
|
9
11
|
policies.set(client, policy);
|
|
10
12
|
};
|
|
13
|
+
/** The bound on one storage put: the call's `uploadTimeoutMs`, else the client's, else the default. */
|
|
14
|
+
const uploadTimeout = (client, call) => resolveTimeout("uploadTimeoutMs", call, policies.get(client)?.uploadTimeoutMs, DEFAULT_UPLOAD_TIMEOUT_MS);
|
|
15
|
+
/** Each attempt gets a fresh timer, so a retry has the whole bound again. */
|
|
16
|
+
const startAttempt = (signal, timeoutMs) => {
|
|
17
|
+
if (timeoutMs === null) return {
|
|
18
|
+
signal: signal ?? void 0,
|
|
19
|
+
timedOut: () => void 0,
|
|
20
|
+
end: () => {}
|
|
21
|
+
};
|
|
22
|
+
const timer = new AbortController();
|
|
23
|
+
const handle = setTimeout(() => timer.abort(new SamvaTimeoutError(timeoutMs)), timeoutMs);
|
|
24
|
+
const joined = signal ? AbortSignal.any([signal, timer.signal]) : timer.signal;
|
|
25
|
+
return {
|
|
26
|
+
signal: joined,
|
|
27
|
+
timedOut: () => joined.reason instanceof SamvaTimeoutError ? joined.reason : void 0,
|
|
28
|
+
end: () => clearTimeout(handle)
|
|
29
|
+
};
|
|
30
|
+
};
|
|
11
31
|
const validateRetries = (value) => {
|
|
12
32
|
if (!Number.isInteger(value) || value < 0) throw new RangeError("maxRetries must be a nonnegative integer");
|
|
13
33
|
return value;
|
|
14
34
|
};
|
|
15
35
|
const object = (value) => typeof value === "object" && value !== null;
|
|
16
36
|
const retryable = (error) => {
|
|
37
|
+
if (error instanceof SamvaTimeoutError) return true;
|
|
17
38
|
if (error instanceof SamvaTransportError) return error.response === void 0 && error.cause instanceof TypeError;
|
|
18
39
|
if (!object(error) || typeof error._tag !== "string") return false;
|
|
19
40
|
if (error._tag === "EmailChannelError") return error.reason === "transport" || error.reason === "rate_limited";
|
|
@@ -35,7 +56,11 @@ const pause = (milliseconds, signal) => new Promise((resolve, reject) => {
|
|
|
35
56
|
}, milliseconds);
|
|
36
57
|
signal?.addEventListener("abort", abort, { once: true });
|
|
37
58
|
});
|
|
38
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* The key belongs to a logical call, so all attempts share it and each invocation gets a fresh one.
|
|
61
|
+
* Each attempt runs under its own `timeoutMs` timer joined with the caller's signal; a timed-out
|
|
62
|
+
* attempt fails with `SamvaTimeoutError` and retries only where a transport failure would.
|
|
63
|
+
*/
|
|
39
64
|
async function requestWithPolicy(client, operation, options, send, input) {
|
|
40
65
|
const metadata = SamvaOperations[operation];
|
|
41
66
|
const policy = policies.get(client);
|
|
@@ -49,27 +74,37 @@ async function requestWithPolicy(client, operation, options, send, input) {
|
|
|
49
74
|
headers["idempotency-key"] = options?.idempotencyKey ?? policy?.idempotency?.(operation) ?? crypto.randomUUID();
|
|
50
75
|
}
|
|
51
76
|
const maxRetries = validateRetries(options?.maxRetries ?? policy?.maxRetries ?? 3);
|
|
77
|
+
const timeoutMs = resolveTimeout("timeoutMs", options?.timeoutMs, policy?.timeoutMs, DEFAULT_TIMEOUT_MS);
|
|
52
78
|
const safe = isRetrySafe(metadata, input);
|
|
53
79
|
for (let retry = 0;; retry++) {
|
|
54
80
|
let failure;
|
|
55
81
|
let result;
|
|
82
|
+
const attempt = startAttempt(signal, timeoutMs);
|
|
56
83
|
try {
|
|
57
|
-
result = await send(headers);
|
|
84
|
+
result = await send(headers, attempt.signal);
|
|
58
85
|
if (!object(result) || result.error === void 0) return result;
|
|
59
|
-
|
|
86
|
+
const timeout = attempt.timedOut();
|
|
87
|
+
failure = fromApiError(timeout ?? result.error, {
|
|
60
88
|
request: result.request instanceof Request ? result.request : void 0,
|
|
61
89
|
response: result.response instanceof Response ? result.response : void 0
|
|
62
90
|
});
|
|
63
|
-
|
|
91
|
+
if (timeout !== void 0) result = {
|
|
92
|
+
...result,
|
|
93
|
+
error: timeout
|
|
94
|
+
};
|
|
95
|
+
} catch (thrown) {
|
|
96
|
+
const error = attempt.timedOut() ?? thrown;
|
|
64
97
|
failure = fromApiError(error);
|
|
65
98
|
if (!safe || retry >= maxRetries || !retryable(failure) || signal?.aborted) throw error;
|
|
66
99
|
await pause(delay(failure, retry), signal);
|
|
67
100
|
continue;
|
|
101
|
+
} finally {
|
|
102
|
+
attempt.end();
|
|
68
103
|
}
|
|
69
104
|
if (!safe || retry >= maxRetries || !retryable(failure) || signal?.aborted) return result;
|
|
70
105
|
await pause(delay(failure, retry), signal);
|
|
71
106
|
}
|
|
72
107
|
}
|
|
73
|
-
export { configureRequests, requestWithPolicy };
|
|
108
|
+
export { configureRequests, requestWithPolicy, startAttempt, uploadTimeout };
|
|
74
109
|
|
|
75
110
|
//# sourceMappingURL=request.js.map
|