silon-sdk 0.2.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/LICENSE +21 -0
- package/README.md +560 -0
- package/dist/client.d.ts +141 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +249 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +117 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +199 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/utils.d.ts +24 -0
- package/dist/internal/utils.d.ts.map +1 -0
- package/dist/internal/utils.js +58 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/pagination.d.ts +52 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +80 -0
- package/dist/pagination.js.map +1 -0
- package/dist/resources/auth.d.ts +20 -0
- package/dist/resources/auth.d.ts.map +1 -0
- package/dist/resources/auth.js +41 -0
- package/dist/resources/auth.js.map +1 -0
- package/dist/resources/broadcasts.d.ts +63 -0
- package/dist/resources/broadcasts.d.ts.map +1 -0
- package/dist/resources/broadcasts.js +103 -0
- package/dist/resources/broadcasts.js.map +1 -0
- package/dist/resources/bulk.d.ts +60 -0
- package/dist/resources/bulk.d.ts.map +1 -0
- package/dist/resources/bulk.js +137 -0
- package/dist/resources/bulk.js.map +1 -0
- package/dist/resources/client-groups.d.ts +50 -0
- package/dist/resources/client-groups.d.ts.map +1 -0
- package/dist/resources/client-groups.js +97 -0
- package/dist/resources/client-groups.js.map +1 -0
- package/dist/resources/clients.d.ts +51 -0
- package/dist/resources/clients.d.ts.map +1 -0
- package/dist/resources/clients.js +99 -0
- package/dist/resources/clients.js.map +1 -0
- package/dist/resources/events.d.ts +22 -0
- package/dist/resources/events.d.ts.map +1 -0
- package/dist/resources/events.js +38 -0
- package/dist/resources/events.js.map +1 -0
- package/dist/resources/messages.d.ts +99 -0
- package/dist/resources/messages.d.ts.map +1 -0
- package/dist/resources/messages.js +167 -0
- package/dist/resources/messages.js.map +1 -0
- package/dist/resources/otp.d.ts +26 -0
- package/dist/resources/otp.d.ts.map +1 -0
- package/dist/resources/otp.js +40 -0
- package/dist/resources/otp.js.map +1 -0
- package/dist/resources/profile.d.ts +18 -0
- package/dist/resources/profile.d.ts.map +1 -0
- package/dist/resources/profile.js +40 -0
- package/dist/resources/profile.js.map +1 -0
- package/dist/resources/push.d.ts +45 -0
- package/dist/resources/push.d.ts.map +1 -0
- package/dist/resources/push.js +103 -0
- package/dist/resources/push.js.map +1 -0
- package/dist/resources/reports.d.ts +44 -0
- package/dist/resources/reports.d.ts.map +1 -0
- package/dist/resources/reports.js +127 -0
- package/dist/resources/reports.js.map +1 -0
- package/dist/resources/suppressions.d.ts +54 -0
- package/dist/resources/suppressions.d.ts.map +1 -0
- package/dist/resources/suppressions.js +79 -0
- package/dist/resources/suppressions.js.map +1 -0
- package/dist/resources/templates.d.ts +58 -0
- package/dist/resources/templates.d.ts.map +1 -0
- package/dist/resources/templates.js +96 -0
- package/dist/resources/templates.js.map +1 -0
- package/dist/resources/webhook-endpoints.d.ts +54 -0
- package/dist/resources/webhook-endpoints.d.ts.map +1 -0
- package/dist/resources/webhook-endpoints.js +96 -0
- package/dist/resources/webhook-endpoints.js.map +1 -0
- package/dist/resources/whatsapp-templates.d.ts +20 -0
- package/dist/resources/whatsapp-templates.d.ts.map +1 -0
- package/dist/resources/whatsapp-templates.js +33 -0
- package/dist/resources/whatsapp-templates.js.map +1 -0
- package/dist/types/auth.d.ts +34 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +8 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/broadcasts.d.ts +174 -0
- package/dist/types/broadcasts.d.ts.map +1 -0
- package/dist/types/broadcasts.js +8 -0
- package/dist/types/broadcasts.js.map +1 -0
- package/dist/types/bulk.d.ts +161 -0
- package/dist/types/bulk.d.ts.map +1 -0
- package/dist/types/bulk.js +8 -0
- package/dist/types/bulk.js.map +1 -0
- package/dist/types/client-groups.d.ts +52 -0
- package/dist/types/client-groups.d.ts.map +1 -0
- package/dist/types/client-groups.js +8 -0
- package/dist/types/client-groups.js.map +1 -0
- package/dist/types/clients.d.ts +64 -0
- package/dist/types/clients.d.ts.map +1 -0
- package/dist/types/clients.js +8 -0
- package/dist/types/clients.js.map +1 -0
- package/dist/types/events.d.ts +64 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +9 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/messages.d.ts +334 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/messages.js +8 -0
- package/dist/types/messages.js.map +1 -0
- package/dist/types/otp.d.ts +61 -0
- package/dist/types/otp.d.ts.map +1 -0
- package/dist/types/otp.js +8 -0
- package/dist/types/otp.js.map +1 -0
- package/dist/types/profile.d.ts +37 -0
- package/dist/types/profile.d.ts.map +1 -0
- package/dist/types/profile.js +8 -0
- package/dist/types/profile.js.map +1 -0
- package/dist/types/push.d.ts +90 -0
- package/dist/types/push.d.ts.map +1 -0
- package/dist/types/push.js +8 -0
- package/dist/types/push.js.map +1 -0
- package/dist/types/reports.d.ts +109 -0
- package/dist/types/reports.d.ts.map +1 -0
- package/dist/types/reports.js +8 -0
- package/dist/types/reports.js.map +1 -0
- package/dist/types/suppressions.d.ts +72 -0
- package/dist/types/suppressions.d.ts.map +1 -0
- package/dist/types/suppressions.js +8 -0
- package/dist/types/suppressions.js.map +1 -0
- package/dist/types/templates.d.ts +96 -0
- package/dist/types/templates.d.ts.map +1 -0
- package/dist/types/templates.js +9 -0
- package/dist/types/templates.js.map +1 -0
- package/dist/types/webhook-endpoints.d.ts +123 -0
- package/dist/types/webhook-endpoints.d.ts.map +1 -0
- package/dist/types/webhook-endpoints.js +8 -0
- package/dist/types/webhook-endpoints.js.map +1 -0
- package/dist/types/whatsapp-templates.d.ts +59 -0
- package/dist/types/whatsapp-templates.d.ts.map +1 -0
- package/dist/types/whatsapp-templates.js +8 -0
- package/dist/types/whatsapp-templates.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/webhooks.d.ts +48 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +97 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +60 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception hierarchy for the Silon SDK.
|
|
3
|
+
*
|
|
4
|
+
* Every non-2xx API response rejects with a subclass of {@link APIStatusError}
|
|
5
|
+
* selected by HTTP status code. The Silon API returns two error body shapes,
|
|
6
|
+
* both normalized onto the error object:
|
|
7
|
+
*
|
|
8
|
+
* - **Standard errors** (`application/json`) — DRF-standardized:
|
|
9
|
+
* `{"type": "validation_error", "errors": [{"code", "detail", "attr"}]}`
|
|
10
|
+
* - **Inline problems** (`application/problem+json`) — RFC 9457-style:
|
|
11
|
+
* `{"type": "<url>", "title", "status", "detail", "field"}`
|
|
12
|
+
*
|
|
13
|
+
* `.errors` always holds a list of {@link ErrorDetail}, `.errorType` the
|
|
14
|
+
* `type` discriminator, and `.body` the parsed JSON body (useful for shapes
|
|
15
|
+
* like the OTP-verify failure, which carries `remaining_attempts`).
|
|
16
|
+
*/
|
|
17
|
+
import { parseRetryAfter } from "./internal/utils.js";
|
|
18
|
+
/** Base class for every error thrown by this SDK. */
|
|
19
|
+
export class SilonError extends Error {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = new.target.name;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** The request never produced an HTTP response (DNS, TLS, socket...). */
|
|
26
|
+
export class APIConnectionError extends SilonError {
|
|
27
|
+
constructor(message = "Connection error.") {
|
|
28
|
+
super(message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The per-attempt timeout (`timeoutMs`) elapsed before a response arrived. */
|
|
32
|
+
export class APITimeoutError extends APIConnectionError {
|
|
33
|
+
constructor() {
|
|
34
|
+
super("Request timed out.");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** A webhook payload failed `Silon-Signature` verification. */
|
|
38
|
+
export class WebhookSignatureVerificationError extends SilonError {
|
|
39
|
+
}
|
|
40
|
+
/** An API response with a 4xx/5xx status code. */
|
|
41
|
+
export class APIStatusError extends SilonError {
|
|
42
|
+
/** HTTP status code of the response. */
|
|
43
|
+
statusCode;
|
|
44
|
+
/** Value of the `X-Request-Id` response header — quote it in support requests. */
|
|
45
|
+
requestId;
|
|
46
|
+
/** The `type` discriminator from the error body, when present. */
|
|
47
|
+
errorType;
|
|
48
|
+
/** Normalized error entries (both API error shapes map onto this). */
|
|
49
|
+
errors;
|
|
50
|
+
/** The parsed JSON error body, or `null` when the body was not JSON. */
|
|
51
|
+
body;
|
|
52
|
+
/**
|
|
53
|
+
* The error body's `retryable` bool: `true` iff retrying the SAME request
|
|
54
|
+
* could ever succeed (429, 5xx, an in-flight idempotency twin), `false` for
|
|
55
|
+
* every other 4xx. Read verbatim from the v1 error body — NOT recomputed
|
|
56
|
+
* from the status code — and `null` when a legacy/non-v1 body omits it.
|
|
57
|
+
*/
|
|
58
|
+
retryable;
|
|
59
|
+
constructor(message, options) {
|
|
60
|
+
super(message);
|
|
61
|
+
this.statusCode = options.statusCode;
|
|
62
|
+
this.requestId = options.requestId ?? null;
|
|
63
|
+
this.errorType = options.errorType ?? null;
|
|
64
|
+
this.errors = options.errors ?? [];
|
|
65
|
+
this.body = options.body ?? null;
|
|
66
|
+
this.retryable = options.retryable ?? null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** 400 Bad Request. */
|
|
70
|
+
export class BadRequestError extends APIStatusError {
|
|
71
|
+
}
|
|
72
|
+
/** 401 Unauthorized — check the API key. */
|
|
73
|
+
export class AuthenticationError extends APIStatusError {
|
|
74
|
+
}
|
|
75
|
+
/** 403 Forbidden — the key lacks the required scope or tenant access. */
|
|
76
|
+
export class PermissionDeniedError extends APIStatusError {
|
|
77
|
+
}
|
|
78
|
+
/** 404 Not Found. */
|
|
79
|
+
export class NotFoundError extends APIStatusError {
|
|
80
|
+
}
|
|
81
|
+
/** 409 Conflict — e.g. an Idempotency-Key replay with a different body. */
|
|
82
|
+
export class ConflictError extends APIStatusError {
|
|
83
|
+
}
|
|
84
|
+
/** 410 Gone — e.g. an expired OTP. */
|
|
85
|
+
export class GoneError extends APIStatusError {
|
|
86
|
+
}
|
|
87
|
+
/** 422 Unprocessable Entity — semantically invalid request. */
|
|
88
|
+
export class UnprocessableEntityError extends APIStatusError {
|
|
89
|
+
}
|
|
90
|
+
/** 5xx server-side failure. */
|
|
91
|
+
export class InternalServerError extends APIStatusError {
|
|
92
|
+
}
|
|
93
|
+
/** 429 Too Many Requests — back off until {@link retryAfter} seconds pass. */
|
|
94
|
+
export class RateLimitError extends APIStatusError {
|
|
95
|
+
/**
|
|
96
|
+
* Seconds to wait before retrying, parsed from the `Retry-After`
|
|
97
|
+
* (delta-seconds or HTTP-date) or `RateLimit-Reset` (Unix epoch) response
|
|
98
|
+
* headers. `undefined` when the server did not advertise a delay.
|
|
99
|
+
*/
|
|
100
|
+
retryAfter;
|
|
101
|
+
constructor(message, options) {
|
|
102
|
+
super(message, options);
|
|
103
|
+
if (options.retryAfter !== undefined)
|
|
104
|
+
this.retryAfter = options.retryAfter;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const STATUS_MAP = {
|
|
108
|
+
400: BadRequestError,
|
|
109
|
+
401: AuthenticationError,
|
|
110
|
+
403: PermissionDeniedError,
|
|
111
|
+
404: NotFoundError,
|
|
112
|
+
409: ConflictError,
|
|
113
|
+
410: GoneError,
|
|
114
|
+
422: UnprocessableEntityError,
|
|
115
|
+
429: RateLimitError,
|
|
116
|
+
};
|
|
117
|
+
/** `https://silon.tech/docs/errors/not-found` -> `not-found`. */
|
|
118
|
+
function slugFromType(errorType) {
|
|
119
|
+
if (errorType && errorType.includes("/")) {
|
|
120
|
+
const trimmed = errorType.replace(/\/+$/, "");
|
|
121
|
+
return trimmed.slice(trimmed.lastIndexOf("/") + 1);
|
|
122
|
+
}
|
|
123
|
+
return errorType ?? "";
|
|
124
|
+
}
|
|
125
|
+
function asNullableString(value) {
|
|
126
|
+
if (value === null || value === undefined)
|
|
127
|
+
return null;
|
|
128
|
+
return String(value);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Build the right {@link APIStatusError} subclass for a non-2xx response.
|
|
132
|
+
*
|
|
133
|
+
* @internal — exposed for the transport layer; not part of the public API.
|
|
134
|
+
*/
|
|
135
|
+
export function makeStatusError(status, statusText, headers, rawBody) {
|
|
136
|
+
let body = null;
|
|
137
|
+
if (rawBody) {
|
|
138
|
+
try {
|
|
139
|
+
body = JSON.parse(rawBody);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
body = null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
let errorType = null;
|
|
146
|
+
const errors = [];
|
|
147
|
+
let message = "";
|
|
148
|
+
// Read `retryable` verbatim from the body; null when a legacy body omits it
|
|
149
|
+
// (never recomputed from the status code — SPEC 2).
|
|
150
|
+
let retryable = null;
|
|
151
|
+
if (body !== null && typeof body === "object" && !Array.isArray(body)) {
|
|
152
|
+
const record = body;
|
|
153
|
+
errorType = asNullableString(record["type"]);
|
|
154
|
+
if (typeof record["retryable"] === "boolean")
|
|
155
|
+
retryable = record["retryable"];
|
|
156
|
+
const rawErrors = record["errors"];
|
|
157
|
+
if (Array.isArray(rawErrors)) {
|
|
158
|
+
// Standard DRF shape: {"type": ..., "errors": [{code, detail, attr}]}
|
|
159
|
+
for (const entry of rawErrors) {
|
|
160
|
+
if (entry !== null && typeof entry === "object" && !Array.isArray(entry)) {
|
|
161
|
+
const e = entry;
|
|
162
|
+
errors.push({
|
|
163
|
+
code: String(e["code"] ?? ""),
|
|
164
|
+
detail: String(e["detail"] ?? ""),
|
|
165
|
+
attr: asNullableString(e["attr"]),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const first = errors[0];
|
|
170
|
+
if (first) {
|
|
171
|
+
message = first.attr ? `${first.attr}: ${first.detail}` : first.detail;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else if ("detail" in record) {
|
|
175
|
+
// Inline problem shape: {"type": url, "title", "status", "detail", "field"}
|
|
176
|
+
const detail = String(record["detail"] ?? "");
|
|
177
|
+
errors.push({
|
|
178
|
+
code: slugFromType(errorType) || String(record["title"] ?? ""),
|
|
179
|
+
detail,
|
|
180
|
+
attr: asNullableString(record["field"]),
|
|
181
|
+
});
|
|
182
|
+
message = detail;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (!message) {
|
|
186
|
+
message = `HTTP ${status}: ${statusText || rawBody.slice(0, 200)}`;
|
|
187
|
+
}
|
|
188
|
+
const ErrorClass = STATUS_MAP[status] ?? (status >= 500 ? InternalServerError : APIStatusError);
|
|
189
|
+
return new ErrorClass(message, {
|
|
190
|
+
statusCode: status,
|
|
191
|
+
requestId: headers.get("X-Request-Id"),
|
|
192
|
+
body,
|
|
193
|
+
errorType,
|
|
194
|
+
errors,
|
|
195
|
+
retryable,
|
|
196
|
+
retryAfter: parseRetryAfter(headers) ?? undefined,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,qDAAqD;AACrD,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,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AAE,CAAC;IACrE,CAAC;IAED,MAAM,UAAU,GACd,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;IAC/E,OAAO,IAAI,UAAU,CAAC,OAAO,EAAE;QAC7B,UAAU,EAAE,MAAM;QAClB,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;QACtC,IAAI;QACJ,SAAS;QACT,MAAM;QACN,SAAS;QACT,UAAU,EAAE,eAAe,CAAC,OAAO,CAAC,IAAI,SAAS;KAClD,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official Silon SDK for Node.js.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import Silon from "silon-sdk";
|
|
6
|
+
*
|
|
7
|
+
* const client = new Silon({ apiKey: "sk_live_...", workspace: "acme" });
|
|
8
|
+
* const sent = await client.messages.send({
|
|
9
|
+
* channel: "sms",
|
|
10
|
+
* to: { phone_number: "+96512345678" },
|
|
11
|
+
* content: { body: "Your code is 424242" },
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export { Silon, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, type Fetch, type HttpMethod, type QueryParams, type RequestOptions, type SilonOptions, } from "./client.js";
|
|
16
|
+
export { Silon as default } from "./client.js";
|
|
17
|
+
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, ConflictError, GoneError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, SilonError, UnprocessableEntityError, WebhookSignatureVerificationError, type APIStatusErrorOptions, type ErrorDetail, } from "./errors.js";
|
|
18
|
+
export { Page, type CursorPageData } from "./pagination.js";
|
|
19
|
+
export * as webhooks from "./webhooks.js";
|
|
20
|
+
export { Messages } from "./resources/messages.js";
|
|
21
|
+
export { Broadcasts } from "./resources/broadcasts.js";
|
|
22
|
+
export { Otp } from "./resources/otp.js";
|
|
23
|
+
export { Clients } from "./resources/clients.js";
|
|
24
|
+
export { ClientGroups } from "./resources/client-groups.js";
|
|
25
|
+
export { Bulk, BulkFiles, BulkRecipients } from "./resources/bulk.js";
|
|
26
|
+
export { Events } from "./resources/events.js";
|
|
27
|
+
export { WebhookEndpoints } from "./resources/webhook-endpoints.js";
|
|
28
|
+
export { Suppressions } from "./resources/suppressions.js";
|
|
29
|
+
export { Templates } from "./resources/templates.js";
|
|
30
|
+
export { Reports } from "./resources/reports.js";
|
|
31
|
+
export { WhatsAppTemplates } from "./resources/whatsapp-templates.js";
|
|
32
|
+
export { Push } from "./resources/push.js";
|
|
33
|
+
export { Profile } from "./resources/profile.js";
|
|
34
|
+
export { Auth } from "./resources/auth.js";
|
|
35
|
+
export type { BatchAccepted, BatchMessage, MessageAccepted, MessageBatchParams, MessageSendParams, MessageStatus, MessageStatusItem, MessageTimelineEntry, } from "./types/messages.js";
|
|
36
|
+
export type { Event, EventData, EventListParams } from "./types/events.js";
|
|
37
|
+
export type { Broadcast, BroadcastAccepted, BroadcastCreateParams, BroadcastDeliveriesParams, BroadcastDelivery, SkippedBreakdown, } from "./types/broadcasts.js";
|
|
38
|
+
export type { Suppression, SuppressionCreateParams, SuppressionListParams, } from "./types/suppressions.js";
|
|
39
|
+
export type { OtpSendParams, OtpSendResult, OtpVerifyParams, OtpVerifyResult, } from "./types/otp.js";
|
|
40
|
+
export type { WebhookAttempt, WebhookEndpoint, WebhookEndpointAttemptsParams, WebhookEndpointCreateParams, WebhookEndpointListParams, WebhookEndpointTestResult, WebhookEndpointUpdateParams, WebhookEndpointWithSecret, } from "./types/webhook-endpoints.js";
|
|
41
|
+
export type { TemplateCreateParams, TemplateDetail, TemplateListParams, TemplateRow, TemplateUpdateParams, } from "./types/templates.js";
|
|
42
|
+
export type { ClientCreateParams, ClientListParams, ClientProfile, ClientUpdateParams, } from "./types/clients.js";
|
|
43
|
+
export type { ClientGroup, ClientGroupCreateParams, ClientGroupListParams, ClientGroupReplaceParams, ClientGroupUpdateParams, } from "./types/client-groups.js";
|
|
44
|
+
export type { BulkBatch, BulkBatchDetail, BulkFile, BulkFileContent, BulkFileInput, BulkFileList, BulkFileUpload, BulkFileUploadOptions, BulkRecipient, BulkRecipientDetail, BulkSendParams, BulkSendResult, } from "./types/bulk.js";
|
|
45
|
+
export type { ProviderBalance, Report, ReportAwsUsageParams, ReportChannelsParams, ReportClientsParams, ReportDateRangeParams, ReportMessagesParams, ReportSpecificBulksParams, ReportSubscriptionsParams, } from "./types/reports.js";
|
|
46
|
+
export type { Waba, WhatsAppTemplate, WhatsAppTemplateList, WhatsAppTemplateListParams, WhatsAppTemplateVariable, } from "./types/whatsapp-templates.js";
|
|
47
|
+
export type { MarkReadResult, PushClientDevices, PushListNotificationsOptions, PushMarkReadParams, PushNotification, PushPlatform, PushSubscribeAndroidParams, PushSubscribeIosParams, PushSubscribeWebParams, PushUpsertDevicesParams, SubscribeResult, WebPushSubscription, } from "./types/push.js";
|
|
48
|
+
export type { ProfileReplaceParams, ProfileUpdateParams, UserProfile, } from "./types/profile.js";
|
|
49
|
+
export type { LoginParams, LoginResult, SignupParams, SignupResult, } from "./types/auth.js";
|
|
50
|
+
export { VERSION } from "./version.js";
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,KAAK,EACL,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AAE/C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ACJ,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,4BAA4B,EAC5B,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,0BAA0B,EAC1B,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,EACf,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,GACb,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Official Silon SDK for Node.js.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import Silon from "silon-sdk";
|
|
6
|
+
*
|
|
7
|
+
* const client = new Silon({ apiKey: "sk_live_...", workspace: "acme" });
|
|
8
|
+
* const sent = await client.messages.send({
|
|
9
|
+
* channel: "sms",
|
|
10
|
+
* to: { phone_number: "+96512345678" },
|
|
11
|
+
* content: { body: "Your code is 424242" },
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export { Silon, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, } from "./client.js";
|
|
16
|
+
export { Silon as default } from "./client.js";
|
|
17
|
+
export { APIConnectionError, APIStatusError, APITimeoutError, AuthenticationError, BadRequestError, ConflictError, GoneError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, SilonError, UnprocessableEntityError, WebhookSignatureVerificationError, } from "./errors.js";
|
|
18
|
+
export { Page } from "./pagination.js";
|
|
19
|
+
export * as webhooks from "./webhooks.js";
|
|
20
|
+
export { Messages } from "./resources/messages.js";
|
|
21
|
+
export { Broadcasts } from "./resources/broadcasts.js";
|
|
22
|
+
export { Otp } from "./resources/otp.js";
|
|
23
|
+
export { Clients } from "./resources/clients.js";
|
|
24
|
+
export { ClientGroups } from "./resources/client-groups.js";
|
|
25
|
+
export { Bulk, BulkFiles, BulkRecipients } from "./resources/bulk.js";
|
|
26
|
+
export { Events } from "./resources/events.js";
|
|
27
|
+
export { WebhookEndpoints } from "./resources/webhook-endpoints.js";
|
|
28
|
+
export { Suppressions } from "./resources/suppressions.js";
|
|
29
|
+
export { Templates } from "./resources/templates.js";
|
|
30
|
+
export { Reports } from "./resources/reports.js";
|
|
31
|
+
export { WhatsAppTemplates } from "./resources/whatsapp-templates.js";
|
|
32
|
+
export { Push } from "./resources/push.js";
|
|
33
|
+
export { Profile } from "./resources/profile.js";
|
|
34
|
+
export { Auth } from "./resources/auth.js";
|
|
35
|
+
export { VERSION } from "./version.js";
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,KAAK,EACL,mBAAmB,EACnB,kBAAkB,GAMnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,UAAU,EACV,wBAAwB,EACxB,iCAAiC,GAGlC,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,IAAI,EAAuB,MAAM,iBAAiB,CAAC;AAE5D,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAwH3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Internal helpers shared across the SDK. Not part of the public API. */
|
|
2
|
+
/**
|
|
3
|
+
* Return a shallow copy of `obj` with every `null`/`undefined` value removed.
|
|
4
|
+
* Request bodies must omit absent fields entirely (SPEC 7).
|
|
5
|
+
*/
|
|
6
|
+
export declare function dropNull(obj: Record<string, unknown>): Record<string, unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* Emit a `DeprecationWarning` through `process.emitWarning`, at most once per
|
|
9
|
+
* process for each `code`. Deprecated operations call this on invocation (in
|
|
10
|
+
* addition to carrying an `@deprecated` JSDoc tag).
|
|
11
|
+
*/
|
|
12
|
+
export declare function emitDeprecationWarning(code: string, message: string): void;
|
|
13
|
+
/** Test seam — forget which deprecation warnings were already emitted. */
|
|
14
|
+
export declare function resetDeprecationWarnings(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Seconds the server asked us to wait before retrying, if advertised.
|
|
17
|
+
*
|
|
18
|
+
* Reads the standard `Retry-After` header (delta-seconds or HTTP-date) and
|
|
19
|
+
* falls back to the IETF draft `RateLimit-Reset` header, which Silon sends
|
|
20
|
+
* as a Unix epoch on throttled endpoints. Returns `null` when neither header
|
|
21
|
+
* is present or parseable.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseRetryAfter(headers: Headers): number | null;
|
|
24
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/internal/utils.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAE1E;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM9E;AAID;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAI1E;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAgB/D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Internal helpers shared across the SDK. Not part of the public API. */
|
|
2
|
+
/**
|
|
3
|
+
* Return a shallow copy of `obj` with every `null`/`undefined` value removed.
|
|
4
|
+
* Request bodies must omit absent fields entirely (SPEC 7).
|
|
5
|
+
*/
|
|
6
|
+
export function dropNull(obj) {
|
|
7
|
+
const out = {};
|
|
8
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
9
|
+
if (value !== null && value !== undefined)
|
|
10
|
+
out[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
const emittedDeprecations = new Set();
|
|
15
|
+
/**
|
|
16
|
+
* Emit a `DeprecationWarning` through `process.emitWarning`, at most once per
|
|
17
|
+
* process for each `code`. Deprecated operations call this on invocation (in
|
|
18
|
+
* addition to carrying an `@deprecated` JSDoc tag).
|
|
19
|
+
*/
|
|
20
|
+
export function emitDeprecationWarning(code, message) {
|
|
21
|
+
if (emittedDeprecations.has(code))
|
|
22
|
+
return;
|
|
23
|
+
emittedDeprecations.add(code);
|
|
24
|
+
process.emitWarning(message, { type: "DeprecationWarning", code });
|
|
25
|
+
}
|
|
26
|
+
/** Test seam — forget which deprecation warnings were already emitted. */
|
|
27
|
+
export function resetDeprecationWarnings() {
|
|
28
|
+
emittedDeprecations.clear();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Seconds the server asked us to wait before retrying, if advertised.
|
|
32
|
+
*
|
|
33
|
+
* Reads the standard `Retry-After` header (delta-seconds or HTTP-date) and
|
|
34
|
+
* falls back to the IETF draft `RateLimit-Reset` header, which Silon sends
|
|
35
|
+
* as a Unix epoch on throttled endpoints. Returns `null` when neither header
|
|
36
|
+
* is present or parseable.
|
|
37
|
+
*/
|
|
38
|
+
export function parseRetryAfter(headers) {
|
|
39
|
+
const retryAfter = headers.get("Retry-After");
|
|
40
|
+
if (retryAfter) {
|
|
41
|
+
const seconds = Number(retryAfter);
|
|
42
|
+
if (!Number.isNaN(seconds))
|
|
43
|
+
return Math.max(0, seconds);
|
|
44
|
+
const when = Date.parse(retryAfter);
|
|
45
|
+
if (Number.isNaN(when))
|
|
46
|
+
return null;
|
|
47
|
+
return Math.max(0, (when - Date.now()) / 1000);
|
|
48
|
+
}
|
|
49
|
+
const reset = headers.get("RateLimit-Reset");
|
|
50
|
+
if (reset) {
|
|
51
|
+
const epoch = Number(reset);
|
|
52
|
+
if (Number.isNaN(epoch))
|
|
53
|
+
return null;
|
|
54
|
+
return Math.max(0, epoch - Date.now() / 1000);
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/internal/utils.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAE1E;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,GAA4B;IACnD,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC9D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAU,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY,EAAE,OAAe;IAClE,IAAI,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO;IAC1C,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC,CAAC;AACrE,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,wBAAwB;IACtC,mBAAmB,CAAC,KAAK,EAAE,CAAC;AAC9B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC9C,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACxD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACpC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACpC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC7C,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACrC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor pagination for list endpoints that return
|
|
3
|
+
* `{results: [...], next: url|null, previous: url|null}`.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const page = await client.events.list({ limit: 50 });
|
|
7
|
+
* for (const event of page.results) { ... } // this page only
|
|
8
|
+
* for await (const event of page.autoPaging()) { ... } // every page, lazily
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
import type { QueryParams, Silon } from "./client.js";
|
|
12
|
+
/** Raw wire shape of one cursor-paginated response. */
|
|
13
|
+
export interface CursorPageData<T> {
|
|
14
|
+
results?: T[] | null;
|
|
15
|
+
next?: string | null;
|
|
16
|
+
previous?: string | null;
|
|
17
|
+
}
|
|
18
|
+
/** One page of a cursor-paginated list. */
|
|
19
|
+
export declare class Page<T> {
|
|
20
|
+
#private;
|
|
21
|
+
/** The items on this page. */
|
|
22
|
+
readonly results: T[];
|
|
23
|
+
/** Opaque URL of the next page, or `null` on the last page. */
|
|
24
|
+
readonly next: string | null;
|
|
25
|
+
/** Opaque URL of the previous page, or `null` on the first page. */
|
|
26
|
+
readonly previous: string | null;
|
|
27
|
+
constructor(client: Silon, path: string, params: QueryParams | undefined, data: CursorPageData<T>);
|
|
28
|
+
/** Whether another page follows this one. */
|
|
29
|
+
get hasNextPage(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Fetch the next page.
|
|
32
|
+
*
|
|
33
|
+
* The opaque `next` URL is never followed directly: only its query params
|
|
34
|
+
* are extracted and merged over the original params, and the original path
|
|
35
|
+
* is re-requested against the configured base URL — so a proxy-rewritten
|
|
36
|
+
* hostname can never hijack pagination.
|
|
37
|
+
*
|
|
38
|
+
* @throws {SilonError} when called on the last page — check
|
|
39
|
+
* {@link hasNextPage} first.
|
|
40
|
+
*/
|
|
41
|
+
nextPage(): Promise<Page<T>>;
|
|
42
|
+
/**
|
|
43
|
+
* Async generator that lazily walks every item across all pages, fetching
|
|
44
|
+
* each following page only when the current one is exhausted.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* for await (const item of page.autoPaging()) { ... }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
autoPaging(): AsyncGenerator<T, void, void>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGtD,uDAAuD;AACvD,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,2CAA2C;AAC3C,qBAAa,IAAI,CAAC,CAAC;;IACjB,8BAA8B;IAC9B,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;gBAMrB,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC;IASjG,6CAA6C;IAC7C,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED;;;;;;;;;;OAUG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAelC;;;;;;;OAOG;IACI,UAAU,IAAI,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC;CAUnD"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor pagination for list endpoints that return
|
|
3
|
+
* `{results: [...], next: url|null, previous: url|null}`.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const page = await client.events.list({ limit: 50 });
|
|
7
|
+
* for (const event of page.results) { ... } // this page only
|
|
8
|
+
* for await (const event of page.autoPaging()) { ... } // every page, lazily
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
import { SilonError } from "./errors.js";
|
|
12
|
+
/** One page of a cursor-paginated list. */
|
|
13
|
+
export class Page {
|
|
14
|
+
/** The items on this page. */
|
|
15
|
+
results;
|
|
16
|
+
/** Opaque URL of the next page, or `null` on the last page. */
|
|
17
|
+
next;
|
|
18
|
+
/** Opaque URL of the previous page, or `null` on the first page. */
|
|
19
|
+
previous;
|
|
20
|
+
#client;
|
|
21
|
+
#path;
|
|
22
|
+
#params;
|
|
23
|
+
constructor(client, path, params, data) {
|
|
24
|
+
this.#client = client;
|
|
25
|
+
this.#path = path;
|
|
26
|
+
this.#params = { ...(params ?? {}) };
|
|
27
|
+
this.results = [...(data.results ?? [])];
|
|
28
|
+
this.next = data.next ?? null;
|
|
29
|
+
this.previous = data.previous ?? null;
|
|
30
|
+
}
|
|
31
|
+
/** Whether another page follows this one. */
|
|
32
|
+
get hasNextPage() {
|
|
33
|
+
return Boolean(this.next);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fetch the next page.
|
|
37
|
+
*
|
|
38
|
+
* The opaque `next` URL is never followed directly: only its query params
|
|
39
|
+
* are extracted and merged over the original params, and the original path
|
|
40
|
+
* is re-requested against the configured base URL — so a proxy-rewritten
|
|
41
|
+
* hostname can never hijack pagination.
|
|
42
|
+
*
|
|
43
|
+
* @throws {SilonError} when called on the last page — check
|
|
44
|
+
* {@link hasNextPage} first.
|
|
45
|
+
*/
|
|
46
|
+
async nextPage() {
|
|
47
|
+
if (!this.next) {
|
|
48
|
+
throw new SilonError("This page has no next page; check `.hasNextPage` first.");
|
|
49
|
+
}
|
|
50
|
+
const merged = { ...this.#params };
|
|
51
|
+
const nextUrl = new URL(this.next, `${this.#client.baseUrl}/`);
|
|
52
|
+
for (const [key, value] of nextUrl.searchParams) {
|
|
53
|
+
merged[key] = value;
|
|
54
|
+
}
|
|
55
|
+
const data = (await this.#client.request("GET", this.#path, {
|
|
56
|
+
query: merged,
|
|
57
|
+
}));
|
|
58
|
+
return new Page(this.#client, this.#path, merged, data);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Async generator that lazily walks every item across all pages, fetching
|
|
62
|
+
* each following page only when the current one is exhausted.
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* for await (const item of page.autoPaging()) { ... }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
async *autoPaging() {
|
|
69
|
+
let page = this;
|
|
70
|
+
for (;;) {
|
|
71
|
+
for (const item of page.results) {
|
|
72
|
+
yield item;
|
|
73
|
+
}
|
|
74
|
+
if (!page.hasNextPage)
|
|
75
|
+
return;
|
|
76
|
+
page = await page.nextPage();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AASzC,2CAA2C;AAC3C,MAAM,OAAO,IAAI;IACf,8BAA8B;IACrB,OAAO,CAAM;IACtB,+DAA+D;IACtD,IAAI,CAAgB;IAC7B,oEAAoE;IAC3D,QAAQ,CAAgB;IAExB,OAAO,CAAQ;IACf,KAAK,CAAS;IACd,OAAO,CAAc;IAE9B,YAAY,MAAa,EAAE,IAAY,EAAE,MAA+B,EAAE,IAAuB;QAC/F,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC;IACxC,CAAC;IAED,6CAA6C;IAC7C,IAAI,WAAW;QACb,OAAO,OAAO,CAAC,IA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|
|
3
|
+
import type { LoginParams, LoginResult, SignupParams, SignupResult } from "../types/auth.js";
|
|
4
|
+
/** `client.auth` — account signup and the legacy token login. */
|
|
5
|
+
export declare class Auth {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(client: Silon);
|
|
8
|
+
/** Sign up a new user (`POST /api/v1/signup/`; throttled server-side). */
|
|
9
|
+
signup(params: SignupParams): Promise<SignupResult>;
|
|
10
|
+
/**
|
|
11
|
+
* Exchange username + password for a Bearer token
|
|
12
|
+
* (`POST /api/v1/login/`).
|
|
13
|
+
*
|
|
14
|
+
* @deprecated Prefer a scoped `sk_live_` API key created under
|
|
15
|
+
* Settings > API keys. Calling this emits a one-time
|
|
16
|
+
* `DeprecationWarning`.
|
|
17
|
+
*/
|
|
18
|
+
login(params: LoginParams): Promise<LoginResult>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/resources/auth.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAErE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE7F,iEAAiE;AACjE,qBAAa,IAAI;;gBAGH,MAAM,EAAE,KAAK;IAIzB,0EAA0E;IACpE,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAezD;;;;;;;OAOG;IACG,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;CAWvD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** The Auth resource — account signup and the legacy token login. */
|
|
2
|
+
import { dropNull, emitDeprecationWarning } from "../internal/utils.js";
|
|
3
|
+
/** `client.auth` — account signup and the legacy token login. */
|
|
4
|
+
export class Auth {
|
|
5
|
+
#client;
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.#client = client;
|
|
8
|
+
}
|
|
9
|
+
/** Sign up a new user (`POST /api/v1/signup/`; throttled server-side). */
|
|
10
|
+
async signup(params) {
|
|
11
|
+
const body = dropNull({
|
|
12
|
+
email: params.email,
|
|
13
|
+
first_name: params.first_name,
|
|
14
|
+
last_name: params.last_name,
|
|
15
|
+
phone_number: params.phone_number,
|
|
16
|
+
password: params.password,
|
|
17
|
+
civil_id: params.civil_id,
|
|
18
|
+
default_language: params.default_language,
|
|
19
|
+
client_id: params.client_id,
|
|
20
|
+
});
|
|
21
|
+
const data = await this.#client.request("POST", "/api/v1/signup/", { body });
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Exchange username + password for a Bearer token
|
|
26
|
+
* (`POST /api/v1/login/`).
|
|
27
|
+
*
|
|
28
|
+
* @deprecated Prefer a scoped `sk_live_` API key created under
|
|
29
|
+
* Settings > API keys. Calling this emits a one-time
|
|
30
|
+
* `DeprecationWarning`.
|
|
31
|
+
*/
|
|
32
|
+
async login(params) {
|
|
33
|
+
emitDeprecationWarning("SILON_AUTH_LOGIN", "silon: auth.login() (POST /api/v1/login/) is deprecated - prefer a scoped " +
|
|
34
|
+
"sk_live_ API key created under Settings > API keys.");
|
|
35
|
+
const data = await this.#client.request("POST", "/api/v1/login/", {
|
|
36
|
+
body: { username: params.username, password: params.password },
|
|
37
|
+
});
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/resources/auth.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAGrE,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAGxE,iEAAiE;AACjE,MAAM,OAAO,IAAI;IACN,OAAO,CAAQ;I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