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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** The Clients resource — CRM contact profiles. */
|
|
2
|
+
import { dropNull, emitDeprecationWarning } from "../internal/utils.js";
|
|
3
|
+
import { Page } from "../pagination.js";
|
|
4
|
+
// Canonical plural route (C2): cursor-paginated LIST + all single-object CRUD.
|
|
5
|
+
const CLIENTS_PATH = "/api/v1/crm/clients/";
|
|
6
|
+
// Deprecated singular route, frozen: its LIST returns a bare JSON array.
|
|
7
|
+
const CLIENTS_LEGACY_PATH = "/api/v1/crm/client/";
|
|
8
|
+
/** Build a client-profile body, omitting absent fields (SPEC 7). */
|
|
9
|
+
function clientBody(params) {
|
|
10
|
+
return dropNull({
|
|
11
|
+
client_id: params.client_id,
|
|
12
|
+
first_name: params.first_name,
|
|
13
|
+
last_name: params.last_name,
|
|
14
|
+
email: params.email,
|
|
15
|
+
phone_number: params.phone_number,
|
|
16
|
+
civil_id: params.civil_id,
|
|
17
|
+
notes: params.notes,
|
|
18
|
+
default_language: params.default_language,
|
|
19
|
+
default_channel: params.default_channel,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** `client.clients` — manage CRM contact profiles. */
|
|
23
|
+
export class Clients {
|
|
24
|
+
#client;
|
|
25
|
+
constructor(client) {
|
|
26
|
+
this.#client = client;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* List every contact as a bare array (`GET /api/v1/crm/client/`).
|
|
30
|
+
*
|
|
31
|
+
* This eagerly returns ALL contacts as a plain `ClientProfile[]` from the
|
|
32
|
+
* deprecated singular route (frozen: never cursor-paginated). Its call
|
|
33
|
+
* signature and return type are preserved for back-compat.
|
|
34
|
+
*
|
|
35
|
+
* @deprecated Prefer {@link Clients.listPaginated}, which pages the canonical
|
|
36
|
+
* `GET /api/v1/crm/clients/` route lazily and scales past the singular
|
|
37
|
+
* route's unbounded response. Calling this emits a one-time
|
|
38
|
+
* `DeprecationWarning`.
|
|
39
|
+
*/
|
|
40
|
+
async list() {
|
|
41
|
+
emitDeprecationWarning("SILON_CRM_CLIENTS_LIST", "silon: clients.list() (GET /api/v1/crm/client/) returns a bare, " +
|
|
42
|
+
"unpaginated array from the deprecated singular route - prefer " +
|
|
43
|
+
"clients.listPaginated() (GET /api/v1/crm/clients/), which is cursor-paginated.");
|
|
44
|
+
const data = await this.#client.request("GET", CLIENTS_LEGACY_PATH);
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* List contacts, cursor-paginated, newest first
|
|
49
|
+
* (`GET /api/v1/crm/clients/` — the canonical C2 route). Returns a
|
|
50
|
+
* {@link Page} you can walk manually or drain with `autoPaging()`.
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* const page = await client.clients.listPaginated({ limit: 100 });
|
|
54
|
+
* for (const contact of page.results) { ... } // this page only
|
|
55
|
+
* for await (const contact of page.autoPaging()) { ... } // every page, lazily
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
async listPaginated(params = {}) {
|
|
59
|
+
const query = dropNull({
|
|
60
|
+
cursor: params.cursor,
|
|
61
|
+
limit: params.limit,
|
|
62
|
+
});
|
|
63
|
+
const data = (await this.#client.request("GET", CLIENTS_PATH, {
|
|
64
|
+
query,
|
|
65
|
+
}));
|
|
66
|
+
return new Page(this.#client, CLIENTS_PATH, query, data);
|
|
67
|
+
}
|
|
68
|
+
/** Create a contact (`POST /api/v1/crm/clients/`). */
|
|
69
|
+
async create(params) {
|
|
70
|
+
const data = await this.#client.request("POST", CLIENTS_PATH, { body: clientBody(params) });
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
/** Fetch one contact (`GET /api/v1/crm/clients/{client_id}/`). */
|
|
74
|
+
async retrieve(clientId) {
|
|
75
|
+
const data = await this.#client.request("GET", `${CLIENTS_PATH}${encodeURIComponent(clientId)}/`);
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Partial update (`PATCH /api/v1/crm/clients/{client_id}/`) — only the
|
|
80
|
+
* given fields change.
|
|
81
|
+
*/
|
|
82
|
+
async update(clientId, params = {}) {
|
|
83
|
+
const data = await this.#client.request("PATCH", `${CLIENTS_PATH}${encodeURIComponent(clientId)}/`, { body: clientBody(params) });
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Full replace (`PUT /api/v1/crm/clients/{client_id}/`). `client_id` itself
|
|
88
|
+
* is immutable.
|
|
89
|
+
*/
|
|
90
|
+
async replace(clientId, params = {}) {
|
|
91
|
+
const data = await this.#client.request("PUT", `${CLIENTS_PATH}${encodeURIComponent(clientId)}/`, { body: clientBody(params) });
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
/** Delete a contact (`DELETE /api/v1/crm/clients/{client_id}/`, 204). */
|
|
95
|
+
async delete(clientId) {
|
|
96
|
+
await this.#client.request("DELETE", `${CLIENTS_PATH}${encodeURIComponent(clientId)}/`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=clients.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../src/resources/clients.ts"],"names":[],"mappings":"AAAA,mDAAmD;AAGnD,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,IAAI,EAAuB,MAAM,kBAAkB,CAAC;AAQ7D,+EAA+E;AAC/E,MAAM,YAAY,GAAG,sBAAsB,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AM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,YAAY,GAAG,kBAAkB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC1F,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The Events resource — the stream your webhooks are fed from. */
|
|
2
|
+
import type { Silon } from "../client.js";
|
|
3
|
+
import { Page } from "../pagination.js";
|
|
4
|
+
import type { Event, EventListParams } from "../types/events.js";
|
|
5
|
+
/** `client.events` — read the event stream (newest first). */
|
|
6
|
+
export declare class Events {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(client: Silon);
|
|
9
|
+
/**
|
|
10
|
+
* List events, cursor-paginated (`GET /api/v1/events`). Filter with
|
|
11
|
+
* `type`, e.g. `{type: "message.failed"}`.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const page = await client.events.list({ type: "message.failed" });
|
|
15
|
+
* for await (const event of page.autoPaging()) { ... }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
list(params?: EventListParams): Promise<Page<Event>>;
|
|
19
|
+
/** Fetch a single event envelope by id (`GET /api/v1/events/{id}`). */
|
|
20
|
+
retrieve(eventId: string): Promise<Event>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/resources/events.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAEnE,OAAO,KAAK,EAAe,KAAK,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,IAAI,EAAuB,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAKjE,8DAA8D;AAC9D,qBAAa,MAAM;;gBAGL,MAAM,EAAE,KAAK;IAIzB;;;;;;;;OAQG;IACG,IAAI,CAAC,MAAM,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAY9D,uEAAuE;IACjE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;CAOhD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** The Events resource — the stream your webhooks are fed from. */
|
|
2
|
+
import { dropNull } from "../internal/utils.js";
|
|
3
|
+
import { Page } from "../pagination.js";
|
|
4
|
+
// NOTE: no trailing slashes on this resource (SPEC 7).
|
|
5
|
+
const EVENTS_PATH = "/api/v1/events";
|
|
6
|
+
/** `client.events` — read the event stream (newest first). */
|
|
7
|
+
export class Events {
|
|
8
|
+
#client;
|
|
9
|
+
constructor(client) {
|
|
10
|
+
this.#client = client;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* List events, cursor-paginated (`GET /api/v1/events`). Filter with
|
|
14
|
+
* `type`, e.g. `{type: "message.failed"}`.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const page = await client.events.list({ type: "message.failed" });
|
|
18
|
+
* for await (const event of page.autoPaging()) { ... }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
async list(params = {}) {
|
|
22
|
+
const query = dropNull({
|
|
23
|
+
type: params.type,
|
|
24
|
+
cursor: params.cursor,
|
|
25
|
+
limit: params.limit,
|
|
26
|
+
});
|
|
27
|
+
const data = (await this.#client.request("GET", EVENTS_PATH, {
|
|
28
|
+
query,
|
|
29
|
+
}));
|
|
30
|
+
return new Page(this.#client, EVENTS_PATH, query, data);
|
|
31
|
+
}
|
|
32
|
+
/** Fetch a single event envelope by id (`GET /api/v1/events/{id}`). */
|
|
33
|
+
async retrieve(eventId) {
|
|
34
|
+
const data = await this.#client.request("GET", `${EVENTS_PATH}/${encodeURIComponent(eventId)}`);
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/resources/events.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAGnE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAuB,MAAM,kBAAkB,CAAC;AAG7D,uDAAuD;AACvD,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAErC,8DAA8D;AAC9D,MAAM,OAAO,MAAM;IACR,OAAO,CAAQ;IAExB,YAAY,MAAa;QACvB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,CAAC,SAA0B,EAAE;QACrC,MAAM,KAAK,GAAG,QAAQ,CAAC;YACrB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAgB,CAAC;QAClB,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE;YAC3D,KAAK;SACN,CAAC,CAA0B,CAAC;QAC7B,OAAO,IAAI,IAAI,CAAQ,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACjE,CAAC;IAED,uEAAuE;IACvE,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CACrC,KAAK,EACL,GAAG,WAAW,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAChD,CAAC;QACF,OAAO,IAAa,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** The Messages resource — unified send across every channel. */
|
|
2
|
+
import type { Silon } from "../client.js";
|
|
3
|
+
import type { BatchAccepted, MessageAccepted, MessageBatchParams, MessageSendParams, MessageStatus } from "../types/messages.js";
|
|
4
|
+
/** `client.messages` — send messages and look up their delivery status. */
|
|
5
|
+
export declare class Messages {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(client: Silon);
|
|
8
|
+
/**
|
|
9
|
+
* Send a message on any channel (`POST /api/v1/messages/`).
|
|
10
|
+
*
|
|
11
|
+
* Exactly one of `to` (single recipient, e.g. `{client_id}`,
|
|
12
|
+
* `{phone_number}`, `{email}`, `{device_token}`) or `audience` (broadcast
|
|
13
|
+
* selector, e.g. `{type: "client_group", slug}` /
|
|
14
|
+
* `{type: "client_ids", client_ids: [...]}`) is required — enforced
|
|
15
|
+
* client-side.
|
|
16
|
+
*
|
|
17
|
+
* Pass `send_at` (an ISO-8601 date-time string with a UTC offset, strictly
|
|
18
|
+
* in the future, at most 90 days ahead — else `422 send-at-invalid`) to
|
|
19
|
+
* schedule the send: the envelope answers `status: "scheduled"` and the
|
|
20
|
+
* same `id` tracks it through dispatch; cancel while still scheduled via
|
|
21
|
+
* {@link cancel}.
|
|
22
|
+
*
|
|
23
|
+
* Sending to an address on the suppression list (`client.suppressions`)
|
|
24
|
+
* rejects `422 recipient-suppressed`. Transactional/legal sends may pass
|
|
25
|
+
* `override_suppression: true` to bypass it — single-recipient sends only,
|
|
26
|
+
* and the key must carry the `suppressions:override` scope (else
|
|
27
|
+
* `403 missing-scope`); the delivery row is then flagged
|
|
28
|
+
* `suppression_overridden: true`.
|
|
29
|
+
*
|
|
30
|
+
* An `Idempotency-Key` header is always sent (auto-generated UUIDv4 when
|
|
31
|
+
* `idempotency_key` is not given), which makes automatic retries safe.
|
|
32
|
+
* Channel-specific fields not covered by the typed params can be passed
|
|
33
|
+
* through `extra_body`, which is merged into the JSON body last.
|
|
34
|
+
*
|
|
35
|
+
* @throws {SilonError} when neither or both of `to` / `audience` are given.
|
|
36
|
+
*/
|
|
37
|
+
send(params: MessageSendParams): Promise<MessageAccepted>;
|
|
38
|
+
/**
|
|
39
|
+
* Send a batch of independent, personalised messages in one call
|
|
40
|
+
* (`POST /api/v1/messages/batch/`).
|
|
41
|
+
*
|
|
42
|
+
* Exactly one of `messages` (inline rows) or `file` (the saved name of a
|
|
43
|
+
* CSV uploaded via `client.bulk.files.upload`) is required — enforced
|
|
44
|
+
* client-side. Request-level fields (`channel`, `content`, `template`,
|
|
45
|
+
* `provider`, `sender`, `application`, `widget_key`, `priority`, `ttl`,
|
|
46
|
+
* `whatsapp`, `whatsapp_template`) act as row defaults on both forms; a
|
|
47
|
+
* row's own field (or CSV column) always wins.
|
|
48
|
+
*
|
|
49
|
+
* INLINE form: up to 500 rows, each a free-form map with the same shape as
|
|
50
|
+
* a {@link send} body minus `audience` (rows are single-recipient by
|
|
51
|
+
* definition): `to` is required. Validation is all-or-nothing: any invalid
|
|
52
|
+
* row fails the whole batch with a `422` whose `attr` carries a per-index
|
|
53
|
+
* path (`messages[3].to.phone_number`) and nothing is queued. The 202
|
|
54
|
+
* response carries per-row envelopes in request order; each `id` is
|
|
55
|
+
* individually pollable via {@link retrieve}. Inline batches have no GET
|
|
56
|
+
* endpoint — for one content fanned out to an audience, use
|
|
57
|
+
* `client.broadcasts.create` instead.
|
|
58
|
+
*
|
|
59
|
+
* FILE form: rows expand asynchronously through the bulk pipeline. The 202
|
|
60
|
+
* response is the aggregate batch object (`status: "queued"`, `row_count`
|
|
61
|
+
* when cheaply known) WITHOUT per-row `messages`; the returned `id` is the
|
|
62
|
+
* bulk batch id — per-row status via `client.bulk.retrieve(id)` and the
|
|
63
|
+
* bulk reports. An unknown `file` name is a 404 (`file-not-found`). The
|
|
64
|
+
* file form also accepts `send_at` (ISO-8601 with a UTC offset, future,
|
|
65
|
+
* at most 90 days ahead) to schedule the batch — the envelope answers
|
|
66
|
+
* `status: "scheduled"` and rows expand + send at dispatch time; `send_at`
|
|
67
|
+
* with inline `messages` is rejected `422 batch-invalid` (schedule those
|
|
68
|
+
* individually via {@link send}, which supports per-message cancel).
|
|
69
|
+
*
|
|
70
|
+
* An `Idempotency-Key` header is always sent (auto-generated UUIDv4 when
|
|
71
|
+
* `idempotency_key` is not given), which makes automatic retries safe.
|
|
72
|
+
* Extra top-level fields can be passed through `extra_body`, which is
|
|
73
|
+
* merged into the JSON body last.
|
|
74
|
+
*
|
|
75
|
+
* @throws {SilonError} when neither or both of `messages` / `file` are given.
|
|
76
|
+
*/
|
|
77
|
+
sendBatch(params: MessageBatchParams): Promise<BatchAccepted>;
|
|
78
|
+
/**
|
|
79
|
+
* Look up a queued/sent message batch by its tracking id
|
|
80
|
+
* (`GET /api/v1/messages/{event_id}/`). A send created with `send_at`
|
|
81
|
+
* answers `status: "scheduled"` (with empty `messages`) until dispatch,
|
|
82
|
+
* then the normal lifecycle — the id is stable across it.
|
|
83
|
+
*/
|
|
84
|
+
retrieve(eventId: string): Promise<MessageStatus>;
|
|
85
|
+
/**
|
|
86
|
+
* Cancel a scheduled message
|
|
87
|
+
* (`POST /api/v1/messages/{event_id}/cancel/`).
|
|
88
|
+
*
|
|
89
|
+
* Allowed only while the send is still `"scheduled"`: resolves with the
|
|
90
|
+
* envelope showing `status: "canceled"`; a canceled send never dispatches
|
|
91
|
+
* and emits a `message.canceled` event. Canceling an already-canceled send
|
|
92
|
+
* is safe and resolves with the same envelope again (cancel is idempotent
|
|
93
|
+
* by nature — no `Idempotency-Key` is sent). Once dispatched (or for an
|
|
94
|
+
* immediate send's id) the server rejects with `409 not-cancellable`; an
|
|
95
|
+
* unknown id rejects with `404`.
|
|
96
|
+
*/
|
|
97
|
+
cancel(eventId: string): Promise<MessageAccepted>;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/resources/messages.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAIjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACd,MAAM,sBAAsB,CAAC;AAK9B,2EAA2E;AAC3E,qBAAa,QAAQ;;gBAGP,MAAM,EAAE,KAAK;IAIzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,IAAI,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC;IAgC/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACG,SAAS,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC;IA+BnE;;;;;OAKG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAQvD;;;;;;;;;;;OAWG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;CAOxD"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/** The Messages resource — unified send across every channel. */
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { SilonError } from "../errors.js";
|
|
4
|
+
import { dropNull } from "../internal/utils.js";
|
|
5
|
+
const MESSAGES_PATH = "/api/v1/messages/";
|
|
6
|
+
const MESSAGES_BATCH_PATH = "/api/v1/messages/batch/";
|
|
7
|
+
/** `client.messages` — send messages and look up their delivery status. */
|
|
8
|
+
export class Messages {
|
|
9
|
+
#client;
|
|
10
|
+
constructor(client) {
|
|
11
|
+
this.#client = client;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Send a message on any channel (`POST /api/v1/messages/`).
|
|
15
|
+
*
|
|
16
|
+
* Exactly one of `to` (single recipient, e.g. `{client_id}`,
|
|
17
|
+
* `{phone_number}`, `{email}`, `{device_token}`) or `audience` (broadcast
|
|
18
|
+
* selector, e.g. `{type: "client_group", slug}` /
|
|
19
|
+
* `{type: "client_ids", client_ids: [...]}`) is required — enforced
|
|
20
|
+
* client-side.
|
|
21
|
+
*
|
|
22
|
+
* Pass `send_at` (an ISO-8601 date-time string with a UTC offset, strictly
|
|
23
|
+
* in the future, at most 90 days ahead — else `422 send-at-invalid`) to
|
|
24
|
+
* schedule the send: the envelope answers `status: "scheduled"` and the
|
|
25
|
+
* same `id` tracks it through dispatch; cancel while still scheduled via
|
|
26
|
+
* {@link cancel}.
|
|
27
|
+
*
|
|
28
|
+
* Sending to an address on the suppression list (`client.suppressions`)
|
|
29
|
+
* rejects `422 recipient-suppressed`. Transactional/legal sends may pass
|
|
30
|
+
* `override_suppression: true` to bypass it — single-recipient sends only,
|
|
31
|
+
* and the key must carry the `suppressions:override` scope (else
|
|
32
|
+
* `403 missing-scope`); the delivery row is then flagged
|
|
33
|
+
* `suppression_overridden: true`.
|
|
34
|
+
*
|
|
35
|
+
* An `Idempotency-Key` header is always sent (auto-generated UUIDv4 when
|
|
36
|
+
* `idempotency_key` is not given), which makes automatic retries safe.
|
|
37
|
+
* Channel-specific fields not covered by the typed params can be passed
|
|
38
|
+
* through `extra_body`, which is merged into the JSON body last.
|
|
39
|
+
*
|
|
40
|
+
* @throws {SilonError} when neither or both of `to` / `audience` are given.
|
|
41
|
+
*/
|
|
42
|
+
async send(params) {
|
|
43
|
+
const { idempotency_key, extra_body, ...fields } = params;
|
|
44
|
+
if ((fields.to == null) === (fields.audience == null)) {
|
|
45
|
+
throw new SilonError("Provide exactly one of 'to' (single recipient) or 'audience' (broadcast).");
|
|
46
|
+
}
|
|
47
|
+
const body = dropNull({
|
|
48
|
+
channel: fields.channel,
|
|
49
|
+
to: fields.to,
|
|
50
|
+
audience: fields.audience,
|
|
51
|
+
content: fields.content,
|
|
52
|
+
template: fields.template,
|
|
53
|
+
provider: fields.provider,
|
|
54
|
+
sender: fields.sender,
|
|
55
|
+
application: fields.application,
|
|
56
|
+
widget_key: fields.widget_key,
|
|
57
|
+
priority: fields.priority,
|
|
58
|
+
ttl: fields.ttl,
|
|
59
|
+
whatsapp: fields.whatsapp,
|
|
60
|
+
whatsapp_template: fields.whatsapp_template,
|
|
61
|
+
send_at: fields.send_at,
|
|
62
|
+
override_suppression: fields.override_suppression,
|
|
63
|
+
});
|
|
64
|
+
if (extra_body)
|
|
65
|
+
Object.assign(body, extra_body);
|
|
66
|
+
const data = await this.#client.request("POST", MESSAGES_PATH, {
|
|
67
|
+
body,
|
|
68
|
+
headers: { "Idempotency-Key": idempotency_key ?? randomUUID() },
|
|
69
|
+
});
|
|
70
|
+
return data;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Send a batch of independent, personalised messages in one call
|
|
74
|
+
* (`POST /api/v1/messages/batch/`).
|
|
75
|
+
*
|
|
76
|
+
* Exactly one of `messages` (inline rows) or `file` (the saved name of a
|
|
77
|
+
* CSV uploaded via `client.bulk.files.upload`) is required — enforced
|
|
78
|
+
* client-side. Request-level fields (`channel`, `content`, `template`,
|
|
79
|
+
* `provider`, `sender`, `application`, `widget_key`, `priority`, `ttl`,
|
|
80
|
+
* `whatsapp`, `whatsapp_template`) act as row defaults on both forms; a
|
|
81
|
+
* row's own field (or CSV column) always wins.
|
|
82
|
+
*
|
|
83
|
+
* INLINE form: up to 500 rows, each a free-form map with the same shape as
|
|
84
|
+
* a {@link send} body minus `audience` (rows are single-recipient by
|
|
85
|
+
* definition): `to` is required. Validation is all-or-nothing: any invalid
|
|
86
|
+
* row fails the whole batch with a `422` whose `attr` carries a per-index
|
|
87
|
+
* path (`messages[3].to.phone_number`) and nothing is queued. The 202
|
|
88
|
+
* response carries per-row envelopes in request order; each `id` is
|
|
89
|
+
* individually pollable via {@link retrieve}. Inline batches have no GET
|
|
90
|
+
* endpoint — for one content fanned out to an audience, use
|
|
91
|
+
* `client.broadcasts.create` instead.
|
|
92
|
+
*
|
|
93
|
+
* FILE form: rows expand asynchronously through the bulk pipeline. The 202
|
|
94
|
+
* response is the aggregate batch object (`status: "queued"`, `row_count`
|
|
95
|
+
* when cheaply known) WITHOUT per-row `messages`; the returned `id` is the
|
|
96
|
+
* bulk batch id — per-row status via `client.bulk.retrieve(id)` and the
|
|
97
|
+
* bulk reports. An unknown `file` name is a 404 (`file-not-found`). The
|
|
98
|
+
* file form also accepts `send_at` (ISO-8601 with a UTC offset, future,
|
|
99
|
+
* at most 90 days ahead) to schedule the batch — the envelope answers
|
|
100
|
+
* `status: "scheduled"` and rows expand + send at dispatch time; `send_at`
|
|
101
|
+
* with inline `messages` is rejected `422 batch-invalid` (schedule those
|
|
102
|
+
* individually via {@link send}, which supports per-message cancel).
|
|
103
|
+
*
|
|
104
|
+
* An `Idempotency-Key` header is always sent (auto-generated UUIDv4 when
|
|
105
|
+
* `idempotency_key` is not given), which makes automatic retries safe.
|
|
106
|
+
* Extra top-level fields can be passed through `extra_body`, which is
|
|
107
|
+
* merged into the JSON body last.
|
|
108
|
+
*
|
|
109
|
+
* @throws {SilonError} when neither or both of `messages` / `file` are given.
|
|
110
|
+
*/
|
|
111
|
+
async sendBatch(params) {
|
|
112
|
+
const { idempotency_key, extra_body, ...fields } = params;
|
|
113
|
+
if ((fields.messages == null) === (fields.file == null)) {
|
|
114
|
+
throw new SilonError("Provide exactly one of 'messages' (inline rows) or 'file' (a saved CSV name).");
|
|
115
|
+
}
|
|
116
|
+
const body = dropNull({
|
|
117
|
+
channel: fields.channel,
|
|
118
|
+
messages: fields.messages,
|
|
119
|
+
file: fields.file,
|
|
120
|
+
content: fields.content,
|
|
121
|
+
template: fields.template,
|
|
122
|
+
provider: fields.provider,
|
|
123
|
+
sender: fields.sender,
|
|
124
|
+
application: fields.application,
|
|
125
|
+
widget_key: fields.widget_key,
|
|
126
|
+
priority: fields.priority,
|
|
127
|
+
ttl: fields.ttl,
|
|
128
|
+
whatsapp: fields.whatsapp,
|
|
129
|
+
whatsapp_template: fields.whatsapp_template,
|
|
130
|
+
send_at: fields.send_at,
|
|
131
|
+
});
|
|
132
|
+
if (extra_body)
|
|
133
|
+
Object.assign(body, extra_body);
|
|
134
|
+
const data = await this.#client.request("POST", MESSAGES_BATCH_PATH, {
|
|
135
|
+
body,
|
|
136
|
+
headers: { "Idempotency-Key": idempotency_key ?? randomUUID() },
|
|
137
|
+
});
|
|
138
|
+
return data;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Look up a queued/sent message batch by its tracking id
|
|
142
|
+
* (`GET /api/v1/messages/{event_id}/`). A send created with `send_at`
|
|
143
|
+
* answers `status: "scheduled"` (with empty `messages`) until dispatch,
|
|
144
|
+
* then the normal lifecycle — the id is stable across it.
|
|
145
|
+
*/
|
|
146
|
+
async retrieve(eventId) {
|
|
147
|
+
const data = await this.#client.request("GET", `${MESSAGES_PATH}${encodeURIComponent(eventId)}/`);
|
|
148
|
+
return data;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Cancel a scheduled message
|
|
152
|
+
* (`POST /api/v1/messages/{event_id}/cancel/`).
|
|
153
|
+
*
|
|
154
|
+
* Allowed only while the send is still `"scheduled"`: resolves with the
|
|
155
|
+
* envelope showing `status: "canceled"`; a canceled send never dispatches
|
|
156
|
+
* and emits a `message.canceled` event. Canceling an already-canceled send
|
|
157
|
+
* is safe and resolves with the same envelope again (cancel is idempotent
|
|
158
|
+
* by nature — no `Idempotency-Key` is sent). Once dispatched (or for an
|
|
159
|
+
* immediate send's id) the server rejects with `409 not-cancellable`; an
|
|
160
|
+
* unknown id rejects with `404`.
|
|
161
|
+
*/
|
|
162
|
+
async cancel(eventId) {
|
|
163
|
+
const data = await this.#client.request("POST", `${MESSAGES_PATH}${encodeURIComponent(eventId)}/cancel/`);
|
|
164
|
+
return data;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/resources/messages.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,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H,IAAI,UAAU;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAChD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,mBAAmB,EAAE;YACnE,IAAI;YACJ,OAAO,EAAE,EAAE,iBAAiB,EAAE,eAAe,IAAI,UAAU,EAAE,EAAE;SAChE,CAAC,CAAC;QACH,OAAO,IAAqB,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CACrC,KAAK,EACL,GAAG,aAAa,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAClD,CAAC;QACF,OAAO,IAAqB,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,MAAM,CAAC,OAAe;QAC1B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CACrC,MAAM,EACN,GAAG,aAAa,GAAG,kBAAkB,CAAC,OAAO,CAAC,UAAU,CACzD,CAAC;QACF,OAAO,IAAuB,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The OTP resource — send and verify one-time passwords. */
|
|
2
|
+
import type { Silon } from "../client.js";
|
|
3
|
+
import type { OtpSendParams, OtpSendResult, OtpVerifyParams, OtpVerifyResult } from "../types/otp.js";
|
|
4
|
+
/** `client.otp` — one-time-password dispatch and verification. */
|
|
5
|
+
export declare class Otp {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(client: Silon);
|
|
8
|
+
/**
|
|
9
|
+
* Dispatch a one-time password (`POST /api/v1/otp/send/`, 202).
|
|
10
|
+
*
|
|
11
|
+
* `to` must contain exactly one of `client_id` / `phone_number` / `email`;
|
|
12
|
+
* the delivery channel is decided by the configured `purpose`. An
|
|
13
|
+
* `Idempotency-Key` header is always sent (auto-generated UUIDv4 when
|
|
14
|
+
* `idempotency_key` is not given), which makes automatic retries safe.
|
|
15
|
+
*/
|
|
16
|
+
send(params: OtpSendParams): Promise<OtpSendResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Verify a code (`POST /api/v1/otp/verify/`).
|
|
19
|
+
*
|
|
20
|
+
* A wrong code rejects with {@link BadRequestError} whose `.body` carries
|
|
21
|
+
* `{verified: false, remaining_attempts: N}`; an expired one rejects with
|
|
22
|
+
* {@link GoneError} (410).
|
|
23
|
+
*/
|
|
24
|
+
verify(params: OtpVerifyParams): Promise<OtpVerifyResult>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=otp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp.d.ts","sourceRoot":"","sources":["../../src/resources/otp.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAI7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAKtG,kEAAkE;AAClE,qBAAa,GAAG;;gBAGF,MAAM,EAAE,KAAK;IAIzB;;;;;;;OAOG;IACG,IAAI,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAQzD;;;;;;OAMG;IACG,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;CAMhE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** The OTP resource — send and verify one-time passwords. */
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
const SEND_PATH = "/api/v1/otp/send/";
|
|
4
|
+
const VERIFY_PATH = "/api/v1/otp/verify/";
|
|
5
|
+
/** `client.otp` — one-time-password dispatch and verification. */
|
|
6
|
+
export class Otp {
|
|
7
|
+
#client;
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.#client = client;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Dispatch a one-time password (`POST /api/v1/otp/send/`, 202).
|
|
13
|
+
*
|
|
14
|
+
* `to` must contain exactly one of `client_id` / `phone_number` / `email`;
|
|
15
|
+
* the delivery channel is decided by the configured `purpose`. An
|
|
16
|
+
* `Idempotency-Key` header is always sent (auto-generated UUIDv4 when
|
|
17
|
+
* `idempotency_key` is not given), which makes automatic retries safe.
|
|
18
|
+
*/
|
|
19
|
+
async send(params) {
|
|
20
|
+
const data = await this.#client.request("POST", SEND_PATH, {
|
|
21
|
+
body: { purpose: params.purpose, to: params.to },
|
|
22
|
+
headers: { "Idempotency-Key": params.idempotency_key ?? randomUUID() },
|
|
23
|
+
});
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Verify a code (`POST /api/v1/otp/verify/`).
|
|
28
|
+
*
|
|
29
|
+
* A wrong code rejects with {@link BadRequestError} whose `.body` carries
|
|
30
|
+
* `{verified: false, remaining_attempts: N}`; an expired one rejects with
|
|
31
|
+
* {@link GoneError} (410).
|
|
32
|
+
*/
|
|
33
|
+
async verify(params) {
|
|
34
|
+
const data = await this.#client.request("POST", VERIFY_PATH, {
|
|
35
|
+
body: { otp_id: params.otp_id, code: params.code },
|
|
36
|
+
});
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=otp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otp.js","sourceRoot":"","sources":["../../src/resources/otp.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,MAAM,SAAS,GAAG,mBAAmB,CAAC;AACtC,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAE1C,kEAAkE;AAClE,MAAM,OAAO,GAAG;IACL,OAAO,CAAQ;IAExB,YAAY,MAAa;QACvB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI,CAAC,MAAqB;QAC9B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE;YACzD,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;YAChD,OAAO,EAAE,EAAE,iBAAiB,EAAE,MAAM,CAAC,eAAe,IAAI,UAAU,EAAE,EAAE;SACvE,CAAC,CAAC;QACH,OAAO,IAAqB,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CAAC,MAAuB;QAClC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE;YAC3D,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE;SACnD,CAAC,CAAC;QACH,OAAO,IAAuB,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The Profile resource — the authenticated user's own profile. */
|
|
2
|
+
import type { Silon } from "../client.js";
|
|
3
|
+
import type { ProfileReplaceParams, ProfileUpdateParams, UserProfile } from "../types/profile.js";
|
|
4
|
+
/** `client.profile` — the authenticated user's own profile. */
|
|
5
|
+
export declare class Profile {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(client: Silon);
|
|
8
|
+
/** Fetch the profile (`GET /api/v1/profile/`). */
|
|
9
|
+
retrieve(): Promise<UserProfile>;
|
|
10
|
+
/**
|
|
11
|
+
* Partial update (`PATCH /api/v1/profile/`) — only the given fields
|
|
12
|
+
* change.
|
|
13
|
+
*/
|
|
14
|
+
update(params?: ProfileUpdateParams): Promise<UserProfile>;
|
|
15
|
+
/** Full replace (`PUT /api/v1/profile/`). */
|
|
16
|
+
replace(params: ProfileReplaceParams): Promise<UserProfile>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/resources/profile.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAEnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAgB7B,+DAA+D;AAC/D,qBAAa,OAAO;;gBAGN,MAAM,EAAE,KAAK;IAIzB,kDAAkD;IAC5C,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC;IAKtC;;;OAGG;IACG,MAAM,CAAC,MAAM,GAAE,mBAAwB,GAAG,OAAO,CAAC,WAAW,CAAC;IAKpE,6CAA6C;IACvC,OAAO,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;CAIlE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** The Profile resource — the authenticated user's own profile. */
|
|
2
|
+
import { dropNull } from "../internal/utils.js";
|
|
3
|
+
const PROFILE_PATH = "/api/v1/profile/";
|
|
4
|
+
/** Build a profile body, omitting absent fields (SPEC 7). */
|
|
5
|
+
function profileBody(params) {
|
|
6
|
+
return dropNull({
|
|
7
|
+
email: params.email,
|
|
8
|
+
first_name: params.first_name,
|
|
9
|
+
last_name: params.last_name,
|
|
10
|
+
phone_number: params.phone_number,
|
|
11
|
+
civil_id: params.civil_id,
|
|
12
|
+
default_language: params.default_language,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/** `client.profile` — the authenticated user's own profile. */
|
|
16
|
+
export class Profile {
|
|
17
|
+
#client;
|
|
18
|
+
constructor(client) {
|
|
19
|
+
this.#client = client;
|
|
20
|
+
}
|
|
21
|
+
/** Fetch the profile (`GET /api/v1/profile/`). */
|
|
22
|
+
async retrieve() {
|
|
23
|
+
const data = await this.#client.request("GET", PROFILE_PATH);
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Partial update (`PATCH /api/v1/profile/`) — only the given fields
|
|
28
|
+
* change.
|
|
29
|
+
*/
|
|
30
|
+
async update(params = {}) {
|
|
31
|
+
const data = await this.#client.request("PATCH", PROFILE_PATH, { body: profileBody(params) });
|
|
32
|
+
return data;
|
|
33
|
+
}
|
|
34
|
+
/** Full replace (`PUT /api/v1/profile/`). */
|
|
35
|
+
async replace(params) {
|
|
36
|
+
const data = await this.#client.request("PUT", PROFILE_PATH, { body: profileBody(params) });
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/resources/profile.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAGnE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAOhD,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC,6DAA6D;AAC7D,SAAS,WAAW,CAAC,MAA2B;IAC9C,OAAO,QAAQ,CAAC;QACd,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;KAC1C,CAAC,CAAC;AACL,CAAC;AAED,+DAA+D;AAC/D,MAAM,OAAO,OAAO;IACT,OAAO,CAAQ;IAExB,YAAY,MAAa;QACvB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,kDAAkD;IAClD,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAC7D,OAAO,IAAmB,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,SAA8B,EAAE;QAC3C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC9F,OAAO,IAAmB,CAAC;IAC7B,CAAC;IAED,6CAA6C;IAC7C,KAAK,CAAC,OAAO,CAAC,MAA4B;QACxC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC5F,OAAO,IAAmB,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** The Push resource — device registration and native notification feeds. */
|
|
2
|
+
import type { Silon } from "../client.js";
|
|
3
|
+
import type { MarkReadResult, PushClientDevices, PushListNotificationsOptions, PushMarkReadParams, PushNotification, PushSubscribeAndroidParams, PushSubscribeIosParams, PushSubscribeWebParams, PushUpsertDevicesParams, SubscribeResult, WebPushSubscription } from "../types/push.js";
|
|
4
|
+
/** `client.push` — mobile / web push registration and notification feeds. */
|
|
5
|
+
export declare class Push {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(client: Silon);
|
|
8
|
+
/**
|
|
9
|
+
* Register an Android device token for the app `slug`
|
|
10
|
+
* (`POST /api/v1/subscribe/android/`).
|
|
11
|
+
*/
|
|
12
|
+
subscribeAndroid(params: PushSubscribeAndroidParams): Promise<SubscribeResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Register an iOS device token (`POST /api/v1/subscribe/ios/`).
|
|
15
|
+
* `environment`: `"dev"` or `"prod"`.
|
|
16
|
+
*/
|
|
17
|
+
subscribeIos(params: PushSubscribeIosParams): Promise<SubscribeResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Register (or prune, with `keep_devices: false`) a client's devices
|
|
20
|
+
* (`POST /api/v1/push/client/`).
|
|
21
|
+
*/
|
|
22
|
+
upsertDevices(params: PushUpsertDevicesParams): Promise<PushClientDevices>;
|
|
23
|
+
/** Mark a native push notification as read (`POST /api/v1/push/read/`). */
|
|
24
|
+
markRead(params: PushMarkReadParams): Promise<MarkReadResult>;
|
|
25
|
+
/**
|
|
26
|
+
* List native push notifications (`GET /api/v1/push/android/{slug}/`,
|
|
27
|
+
* `/api/v1/push/ios/{slug}/`, or the combined `/api/v1/push/list/{slug}/`
|
|
28
|
+
* when `platform` is omitted) — a bare JSON array.
|
|
29
|
+
*
|
|
30
|
+
* @deprecated The native push notification list endpoints are legacy;
|
|
31
|
+
* calling this emits a one-time `DeprecationWarning`.
|
|
32
|
+
* @throws {SilonError} when `platform` is anything other than
|
|
33
|
+
* `"android"`, `"ios"` or omitted.
|
|
34
|
+
*/
|
|
35
|
+
listNotifications(slug: string, options?: PushListNotificationsOptions): Promise<PushNotification[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Register a browser subscription for a client
|
|
38
|
+
* (`POST /api/v1/webpush/client/`).
|
|
39
|
+
*
|
|
40
|
+
* @deprecated Legacy endpoint — register web push subscriptions through
|
|
41
|
+
* the widget instead. Calling this emits a one-time `DeprecationWarning`.
|
|
42
|
+
*/
|
|
43
|
+
subscribeWeb(params: PushSubscribeWebParams): Promise<WebPushSubscription>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=push.d.ts.map
|