@chatwise/node 0.0.0-stage → 0.1.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +202 -0
  3. package/README.md +506 -2
  4. package/dist/cjs/client.d.ts +20 -0
  5. package/dist/cjs/client.js +32 -0
  6. package/dist/cjs/core/errors.d.ts +91 -0
  7. package/dist/cjs/core/errors.js +131 -0
  8. package/dist/cjs/core/http.d.ts +74 -0
  9. package/dist/cjs/core/http.js +336 -0
  10. package/dist/cjs/core/pagination.d.ts +35 -0
  11. package/dist/cjs/core/pagination.js +101 -0
  12. package/dist/cjs/generated/types.d.ts +969 -0
  13. package/dist/cjs/generated/types.js +3 -0
  14. package/dist/cjs/index.d.ts +15 -0
  15. package/dist/cjs/index.js +25 -0
  16. package/dist/cjs/package.json +1 -0
  17. package/dist/cjs/resources/conversations.d.ts +20 -0
  18. package/dist/cjs/resources/conversations.js +32 -0
  19. package/dist/cjs/resources/messages.d.ts +46 -0
  20. package/dist/cjs/resources/messages.js +60 -0
  21. package/dist/cjs/resources/webhook-deliveries.d.ts +27 -0
  22. package/dist/cjs/resources/webhook-deliveries.js +42 -0
  23. package/dist/cjs/resources/webhook-endpoints.d.ts +54 -0
  24. package/dist/cjs/resources/webhook-endpoints.js +82 -0
  25. package/dist/cjs/resources/webhook-event-types.d.ts +13 -0
  26. package/dist/cjs/resources/webhook-event-types.js +22 -0
  27. package/dist/cjs/resources/whatsapp-templates.d.ts +48 -0
  28. package/dist/cjs/resources/whatsapp-templates.js +69 -0
  29. package/dist/cjs/version.d.ts +2 -0
  30. package/dist/cjs/version.js +5 -0
  31. package/dist/cjs/webhooks.d.ts +74 -0
  32. package/dist/cjs/webhooks.js +123 -0
  33. package/dist/esm/client.d.ts +20 -0
  34. package/dist/esm/client.js +28 -0
  35. package/dist/esm/core/errors.d.ts +91 -0
  36. package/dist/esm/core/errors.js +113 -0
  37. package/dist/esm/core/http.d.ts +74 -0
  38. package/dist/esm/core/http.js +332 -0
  39. package/dist/esm/core/pagination.d.ts +35 -0
  40. package/dist/esm/core/pagination.js +95 -0
  41. package/dist/esm/generated/types.d.ts +969 -0
  42. package/dist/esm/generated/types.js +2 -0
  43. package/dist/esm/index.d.ts +15 -0
  44. package/dist/esm/index.js +4 -0
  45. package/dist/esm/package.json +1 -0
  46. package/dist/esm/resources/conversations.d.ts +20 -0
  47. package/dist/esm/resources/conversations.js +28 -0
  48. package/dist/esm/resources/messages.d.ts +46 -0
  49. package/dist/esm/resources/messages.js +56 -0
  50. package/dist/esm/resources/webhook-deliveries.d.ts +27 -0
  51. package/dist/esm/resources/webhook-deliveries.js +38 -0
  52. package/dist/esm/resources/webhook-endpoints.d.ts +54 -0
  53. package/dist/esm/resources/webhook-endpoints.js +78 -0
  54. package/dist/esm/resources/webhook-event-types.d.ts +13 -0
  55. package/dist/esm/resources/webhook-event-types.js +18 -0
  56. package/dist/esm/resources/whatsapp-templates.d.ts +48 -0
  57. package/dist/esm/resources/whatsapp-templates.js +65 -0
  58. package/dist/esm/version.d.ts +2 -0
  59. package/dist/esm/version.js +2 -0
  60. package/dist/esm/webhooks.d.ts +74 -0
  61. package/dist/esm/webhooks.js +118 -0
  62. package/package.json +79 -4
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // Generated by `npm run generate` from spec/openapi.json. Don't edit.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ export { Chatwise } from './client.js';
2
+ export type { AbortSignalLike, ChatwiseOptions, FetchLike, RequestOptions, ResponseLike } from './core/http.js';
3
+ export type { Page, PagePromise } from './core/pagination.js';
4
+ export { APIError, AuthenticationError, BadRequestError, ChatwiseError, ConflictError, ConnectionError, NotFoundError, PayloadTooLargeError, PaymentRequiredError, PermissionDeniedError, RateLimitError, RequestAbortedError, RequestTimeoutError, ServerError, } from './core/errors.js';
5
+ export type { APIErrorDetails, FieldError } from './core/errors.js';
6
+ export { verifyWebhook, WebhookVerificationError } from './webhooks.js';
7
+ export type { UnknownWebhookEvent, UnknownWebhookEventType, VerifyWebhookOptions, WebhookEvent, WebhookHeaders, WebhookVerificationErrorCode } from './webhooks.js';
8
+ export { VERSION } from './version.js';
9
+ export type { Conversations } from './resources/conversations.js';
10
+ export type { Messages, SendMessageParams } from './resources/messages.js';
11
+ export type { WebhookDeliveries } from './resources/webhook-deliveries.js';
12
+ export type { WebhookEndpoints } from './resources/webhook-endpoints.js';
13
+ export type { WebhookEventTypes } from './resources/webhook-event-types.js';
14
+ export type { CreateWhatsappTemplateOptions, WhatsappTemplates } from './resources/whatsapp-templates.js';
15
+ export type { Channel, CommentReceivedEvent, CommentReceivedEventData, Conversation, ConversationStatus, CreateWebhookEndpointParams, CreateWhatsappTemplateParams, DeleteWebhookEndpointResult, KnownWebhookEvent, KnownWebhookEventType, ListConversationMessagesParams, ListConversationsParams, ListMessagesParams, ListWebhookDeliveriesParams, ListWhatsappTemplatesParams, Message, MessageDeliveredEvent, MessageDirection, MessageEventData, MessageFailedEvent, MessageFailedEventData, MessageReadEvent, MessageReceivedEvent, MessageSentEvent, Open, RotateWebhookSecretResult, SendMessageResult, SendWhatsappTemplateParams, SendWhatsappTemplateResult, TestWebhookEndpointResult, UpdateWebhookEndpointParams, WebhookDelivery, WebhookDeliveryDetails, WebhookDeliveryStatus, WebhookEndpoint, WebhookEndpointStatus, WebhookEndpointWithSecret, WebhookEventType, WebhookEventTypeInfo, WebhookTestEvent, WebhookTestEventData, WhatsappTemplate, WhatsappTemplateCategory, WhatsappTemplateComponent, WhatsappTemplateParam, } from './generated/types.js';
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = exports.WebhookVerificationError = exports.verifyWebhook = exports.ServerError = exports.RequestTimeoutError = exports.RequestAbortedError = exports.RateLimitError = exports.PermissionDeniedError = exports.PaymentRequiredError = exports.PayloadTooLargeError = exports.NotFoundError = exports.ConnectionError = exports.ConflictError = exports.ChatwiseError = exports.BadRequestError = exports.AuthenticationError = exports.APIError = exports.Chatwise = void 0;
4
+ var client_js_1 = require("./client.js");
5
+ Object.defineProperty(exports, "Chatwise", { enumerable: true, get: function () { return client_js_1.Chatwise; } });
6
+ var errors_js_1 = require("./core/errors.js");
7
+ Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_js_1.APIError; } });
8
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_js_1.AuthenticationError; } });
9
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return errors_js_1.BadRequestError; } });
10
+ Object.defineProperty(exports, "ChatwiseError", { enumerable: true, get: function () { return errors_js_1.ChatwiseError; } });
11
+ Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return errors_js_1.ConflictError; } });
12
+ Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_js_1.ConnectionError; } });
13
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
14
+ Object.defineProperty(exports, "PayloadTooLargeError", { enumerable: true, get: function () { return errors_js_1.PayloadTooLargeError; } });
15
+ Object.defineProperty(exports, "PaymentRequiredError", { enumerable: true, get: function () { return errors_js_1.PaymentRequiredError; } });
16
+ Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return errors_js_1.PermissionDeniedError; } });
17
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
18
+ Object.defineProperty(exports, "RequestAbortedError", { enumerable: true, get: function () { return errors_js_1.RequestAbortedError; } });
19
+ Object.defineProperty(exports, "RequestTimeoutError", { enumerable: true, get: function () { return errors_js_1.RequestTimeoutError; } });
20
+ Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return errors_js_1.ServerError; } });
21
+ var webhooks_js_1 = require("./webhooks.js");
22
+ Object.defineProperty(exports, "verifyWebhook", { enumerable: true, get: function () { return webhooks_js_1.verifyWebhook; } });
23
+ Object.defineProperty(exports, "WebhookVerificationError", { enumerable: true, get: function () { return webhooks_js_1.WebhookVerificationError; } });
24
+ var version_js_1 = require("./version.js");
25
+ Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_js_1.VERSION; } });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,20 @@
1
+ import { type RequestOptions } from '../core/http.js';
2
+ import { type PagePromise } from '../core/pagination.js';
3
+ import type { Conversation, ListConversationsParams } from '../generated/types.js';
4
+ /** The conversations in the workspace's inbox. */
5
+ export declare class Conversations {
6
+ #private;
7
+ /**
8
+ * Lists conversations, or finds them by customer. The latest activity comes first. One that gets a
9
+ * message while you read the pages moves to the top, so you can miss it.
10
+ *
11
+ * Scope: `conversations:read`.
12
+ */
13
+ list(params?: ListConversationsParams, options?: RequestOptions): PagePromise<Conversation>;
14
+ /**
15
+ * Reads one conversation: its channel, status and customer.
16
+ *
17
+ * Scope: `conversations:read`.
18
+ */
19
+ get(conversationId: string, options?: RequestOptions): Promise<Conversation>;
20
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Conversations = void 0;
4
+ const http_js_1 = require("../core/http.js");
5
+ const pagination_js_1 = require("../core/pagination.js");
6
+ /** The conversations in the workspace's inbox. */
7
+ class Conversations {
8
+ #request;
9
+ /** @internal */
10
+ constructor(request) {
11
+ this.#request = request;
12
+ }
13
+ /**
14
+ * Lists conversations, or finds them by customer. The latest activity comes first. One that gets a
15
+ * message while you read the pages moves to the top, so you can miss it.
16
+ *
17
+ * Scope: `conversations:read`.
18
+ */
19
+ list(params = {}, options) {
20
+ return (0, pagination_js_1.list)(this.#request, () => '/v1/conversations', params, options);
21
+ }
22
+ /**
23
+ * Reads one conversation: its channel, status and customer.
24
+ *
25
+ * Scope: `conversations:read`.
26
+ */
27
+ async get(conversationId, options) {
28
+ const { data } = await this.#request({ method: 'GET', path: (0, http_js_1.path) `/v1/conversations/${conversationId}` }, options);
29
+ return data;
30
+ }
31
+ }
32
+ exports.Conversations = Conversations;
@@ -0,0 +1,46 @@
1
+ import { type RequestOptions } from '../core/http.js';
2
+ import { type PagePromise } from '../core/pagination.js';
3
+ import type { ListConversationMessagesParams, ListMessagesParams, Message, SendMessageParams as SendMessageBody, SendMessageResult } from '../generated/types.js';
4
+ /** A template to send by id, and its values. */
5
+ export type SendMessageParams = Omit<SendMessageBody, 'channel' | 'templateId'> & {
6
+ /** The template's `id`. */
7
+ templateId: string;
8
+ /**
9
+ * The channel to send on. Only WhatsApp templates can be sent.
10
+ * @defaultValue 'WHATSAPP'
11
+ */
12
+ channel?: 'WHATSAPP' | undefined;
13
+ };
14
+ /** Messages on every channel. */
15
+ export declare class Messages {
16
+ #private;
17
+ /**
18
+ * Lists messages across the workspace, or searches their text. Deleted and hidden messages are left out.
19
+ *
20
+ * Scope: `messages:read`.
21
+ */
22
+ list(params?: ListMessagesParams, options?: RequestOptions): PagePromise<Message>;
23
+ /**
24
+ * Lists one conversation's messages. Deleted and hidden messages are left out.
25
+ *
26
+ * Scope: `messages:read`.
27
+ */
28
+ listInConversation(conversationId: string, params?: ListConversationMessagesParams, options?: RequestOptions): PagePromise<Message>;
29
+ /**
30
+ * Reads one message. A deleted or hidden message is not found.
31
+ *
32
+ * Scope: `messages:read`.
33
+ */
34
+ get(conversationId: string, messageId: string, options?: RequestOptions): Promise<Message>;
35
+ /**
36
+ * Sends an approved WhatsApp template by its id. The answer means WhatsApp accepted the message, not
37
+ * that it was delivered. To send one by its name, use `whatsappTemplates.send`.
38
+ *
39
+ * Sending twice sends two messages, so this is retried only after a 429. After anything but a 4xx
40
+ * (a timeout, a connection error, an abort, a 5xx) it may have been sent, even if the conversation
41
+ * doesn't show it, so check before you send again.
42
+ *
43
+ * Scope: `messages:send`.
44
+ */
45
+ send(params: SendMessageParams, options?: RequestOptions): Promise<SendMessageResult>;
46
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Messages = void 0;
4
+ const errors_js_1 = require("../core/errors.js");
5
+ const http_js_1 = require("../core/http.js");
6
+ const pagination_js_1 = require("../core/pagination.js");
7
+ /** Messages on every channel. */
8
+ class Messages {
9
+ #request;
10
+ /** @internal */
11
+ constructor(request) {
12
+ this.#request = request;
13
+ }
14
+ /**
15
+ * Lists messages across the workspace, or searches their text. Deleted and hidden messages are left out.
16
+ *
17
+ * Scope: `messages:read`.
18
+ */
19
+ list(params = {}, options) {
20
+ return (0, pagination_js_1.list)(this.#request, () => '/v1/messages', params, options);
21
+ }
22
+ /**
23
+ * Lists one conversation's messages. Deleted and hidden messages are left out.
24
+ *
25
+ * Scope: `messages:read`.
26
+ */
27
+ listInConversation(conversationId, params = {}, options) {
28
+ return (0, pagination_js_1.list)(this.#request, () => (0, http_js_1.path) `/v1/conversations/${conversationId}/messages`, params, options);
29
+ }
30
+ /**
31
+ * Reads one message. A deleted or hidden message is not found.
32
+ *
33
+ * Scope: `messages:read`.
34
+ */
35
+ async get(conversationId, messageId, options) {
36
+ const { data } = await this.#request({ method: 'GET', path: (0, http_js_1.path) `/v1/conversations/${conversationId}/messages/${messageId}` }, options);
37
+ return data;
38
+ }
39
+ /**
40
+ * Sends an approved WhatsApp template by its id. The answer means WhatsApp accepted the message, not
41
+ * that it was delivered. To send one by its name, use `whatsappTemplates.send`.
42
+ *
43
+ * Sending twice sends two messages, so this is retried only after a 429. After anything but a 4xx
44
+ * (a timeout, a connection error, an abort, a 5xx) it may have been sent, even if the conversation
45
+ * doesn't show it, so check before you send again.
46
+ *
47
+ * Scope: `messages:send`.
48
+ */
49
+ async send(params, options) {
50
+ const channel = params?.channel ?? 'WHATSAPP';
51
+ // The API answers 201 to these too, and sends nothing.
52
+ if (!params?.templateId)
53
+ throw new errors_js_1.ChatwiseError('messages.send needs a templateId: without one nothing would be sent.');
54
+ if (channel !== 'WHATSAPP')
55
+ throw new errors_js_1.ChatwiseError('messages.send can only send on WHATSAPP: on another channel nothing would be sent.');
56
+ const { data } = await this.#request({ method: 'POST', path: '/v1/messages', body: { ...params, channel } }, options);
57
+ return data;
58
+ }
59
+ }
60
+ exports.Messages = Messages;
@@ -0,0 +1,27 @@
1
+ import { type RequestOptions } from '../core/http.js';
2
+ import { type PagePromise } from '../core/pagination.js';
3
+ import type { ListWebhookDeliveriesParams, WebhookDelivery, WebhookDeliveryDetails } from '../generated/types.js';
4
+ /** What was sent to an endpoint. Deliveries are kept for 30 days. */
5
+ export declare class WebhookDeliveries {
6
+ #private;
7
+ /**
8
+ * Lists an endpoint's deliveries, newest first.
9
+ *
10
+ * Scope: `webhooks:read`.
11
+ */
12
+ list(endpointId: string, params?: ListWebhookDeliveriesParams, options?: RequestOptions): PagePromise<WebhookDelivery>;
13
+ /**
14
+ * Reads one delivery, with the payload it sends and its attempts.
15
+ *
16
+ * Scope: `webhooks:read`, and `messages:read` if it is for a `message.*` event.
17
+ */
18
+ get(deliveryId: string, options?: RequestOptions): Promise<WebhookDeliveryDetails>;
19
+ /**
20
+ * Sends a delivery again, with the same event id, starting from its first attempt. If Chatwise was
21
+ * waiting before it tries the endpoint again, the wait ends. A `BadRequestError` says that it can't be
22
+ * sent again: its message was unsent, deleted or hidden, or its comment hidden or no longer stored.
23
+ *
24
+ * Scope: `webhooks:write`, and `messages:read` if it is for a `message.*` event.
25
+ */
26
+ redeliver(deliveryId: string, options?: RequestOptions): Promise<WebhookDeliveryDetails>;
27
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookDeliveries = void 0;
4
+ const http_js_1 = require("../core/http.js");
5
+ const pagination_js_1 = require("../core/pagination.js");
6
+ /** What was sent to an endpoint. Deliveries are kept for 30 days. */
7
+ class WebhookDeliveries {
8
+ #request;
9
+ /** @internal */
10
+ constructor(request) {
11
+ this.#request = request;
12
+ }
13
+ /**
14
+ * Lists an endpoint's deliveries, newest first.
15
+ *
16
+ * Scope: `webhooks:read`.
17
+ */
18
+ list(endpointId, params = {}, options) {
19
+ return (0, pagination_js_1.list)(this.#request, () => (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}/deliveries`, params, options);
20
+ }
21
+ /**
22
+ * Reads one delivery, with the payload it sends and its attempts.
23
+ *
24
+ * Scope: `webhooks:read`, and `messages:read` if it is for a `message.*` event.
25
+ */
26
+ async get(deliveryId, options) {
27
+ const { data } = await this.#request({ method: 'GET', path: (0, http_js_1.path) `/v1/webhook-deliveries/${deliveryId}` }, options);
28
+ return data;
29
+ }
30
+ /**
31
+ * Sends a delivery again, with the same event id, starting from its first attempt. If Chatwise was
32
+ * waiting before it tries the endpoint again, the wait ends. A `BadRequestError` says that it can't be
33
+ * sent again: its message was unsent, deleted or hidden, or its comment hidden or no longer stored.
34
+ *
35
+ * Scope: `webhooks:write`, and `messages:read` if it is for a `message.*` event.
36
+ */
37
+ async redeliver(deliveryId, options) {
38
+ const { data } = await this.#request({ method: 'POST', path: (0, http_js_1.path) `/v1/webhook-deliveries/${deliveryId}/redeliver` }, options);
39
+ return data;
40
+ }
41
+ }
42
+ exports.WebhookDeliveries = WebhookDeliveries;
@@ -0,0 +1,54 @@
1
+ import { type RequestOptions } from '../core/http.js';
2
+ import type { CreateWebhookEndpointParams, DeleteWebhookEndpointResult, RotateWebhookSecretResult, TestWebhookEndpointResult, UpdateWebhookEndpointParams, WebhookEndpoint, WebhookEndpointWithSecret } from '../generated/types.js';
3
+ /** Where Chatwise sends events. */
4
+ export declare class WebhookEndpoints {
5
+ #private;
6
+ /**
7
+ * Lists the workspace's webhook endpoints, oldest first. There are at most 10, so there are no pages.
8
+ *
9
+ * Scope: `webhooks:read`.
10
+ */
11
+ list(options?: RequestOptions): Promise<WebhookEndpoint[]>;
12
+ /**
13
+ * Creates an endpoint. Store `signingSecret` right away: it is returned only here.
14
+ *
15
+ * Scope: `webhooks:write`, and `messages:read` to subscribe to `message.*` events.
16
+ */
17
+ create(params: CreateWebhookEndpointParams, options?: RequestOptions): Promise<WebhookEndpointWithSecret>;
18
+ /**
19
+ * Reads one endpoint and how its deliveries are going.
20
+ *
21
+ * Scope: `webhooks:read`.
22
+ */
23
+ get(endpointId: string, options?: RequestOptions): Promise<WebhookEndpoint>;
24
+ /**
25
+ * Changes an endpoint: only the fields you pass, at least one. `status: 'PAUSED'` stops new
26
+ * deliveries, and `status: 'ACTIVE'` resumes them, also after Chatwise disabled the endpoint. It clears
27
+ * the endpoint's failures and any wait (`health.backoffUntil`), and so does a new `url`, which also
28
+ * receives the deliveries that were already waiting.
29
+ *
30
+ * Scope: `webhooks:write`, and `messages:read` if the endpoint has `message.*` events before or after the change.
31
+ */
32
+ update(endpointId: string, params: UpdateWebhookEndpointParams, options?: RequestOptions): Promise<WebhookEndpoint>;
33
+ /**
34
+ * Deletes an endpoint and cancels its deliveries that weren't sent yet.
35
+ *
36
+ * Scope: `webhooks:write`.
37
+ */
38
+ delete(endpointId: string, options?: RequestOptions): Promise<DeleteWebhookEndpointResult>;
39
+ /**
40
+ * Sends a signed `webhook.test` event now, also to a paused endpoint, and returns what your endpoint
41
+ * answered. Check `delivered`: this doesn't throw when your endpoint failed. If Chatwise is waiting
42
+ * before it tries the endpoint again (`health.backoffUntil`), a test that succeeds ends the wait.
43
+ *
44
+ * Scope: `webhooks:write`.
45
+ */
46
+ test(endpointId: string, options?: RequestOptions): Promise<TestWebhookEndpointResult>;
47
+ /**
48
+ * Replaces the signing secret. Store it right away: it is returned only here. For 24 hours deliveries
49
+ * are signed with the previous secret too.
50
+ *
51
+ * Scope: `webhooks:write`, and `messages:read` if the endpoint has `message.*` events.
52
+ */
53
+ rotateSecret(endpointId: string, options?: RequestOptions): Promise<RotateWebhookSecretResult>;
54
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookEndpoints = void 0;
4
+ const http_js_1 = require("../core/http.js");
5
+ /** Where Chatwise sends events. */
6
+ class WebhookEndpoints {
7
+ #request;
8
+ /** @internal */
9
+ constructor(request) {
10
+ this.#request = request;
11
+ }
12
+ /**
13
+ * Lists the workspace's webhook endpoints, oldest first. There are at most 10, so there are no pages.
14
+ *
15
+ * Scope: `webhooks:read`.
16
+ */
17
+ async list(options) {
18
+ const { data } = await this.#request({ method: 'GET', path: '/v1/webhook-endpoints' }, options);
19
+ return data;
20
+ }
21
+ /**
22
+ * Creates an endpoint. Store `signingSecret` right away: it is returned only here.
23
+ *
24
+ * Scope: `webhooks:write`, and `messages:read` to subscribe to `message.*` events.
25
+ */
26
+ async create(params, options) {
27
+ const { data } = await this.#request({ method: 'POST', path: '/v1/webhook-endpoints', body: params }, options);
28
+ return data;
29
+ }
30
+ /**
31
+ * Reads one endpoint and how its deliveries are going.
32
+ *
33
+ * Scope: `webhooks:read`.
34
+ */
35
+ async get(endpointId, options) {
36
+ const { data } = await this.#request({ method: 'GET', path: (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}` }, options);
37
+ return data;
38
+ }
39
+ /**
40
+ * Changes an endpoint: only the fields you pass, at least one. `status: 'PAUSED'` stops new
41
+ * deliveries, and `status: 'ACTIVE'` resumes them, also after Chatwise disabled the endpoint. It clears
42
+ * the endpoint's failures and any wait (`health.backoffUntil`), and so does a new `url`, which also
43
+ * receives the deliveries that were already waiting.
44
+ *
45
+ * Scope: `webhooks:write`, and `messages:read` if the endpoint has `message.*` events before or after the change.
46
+ */
47
+ async update(endpointId, params, options) {
48
+ const { data } = await this.#request({ method: 'PATCH', path: (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}`, body: params }, options);
49
+ return data;
50
+ }
51
+ /**
52
+ * Deletes an endpoint and cancels its deliveries that weren't sent yet.
53
+ *
54
+ * Scope: `webhooks:write`.
55
+ */
56
+ async delete(endpointId, options) {
57
+ const { data } = await this.#request({ method: 'DELETE', path: (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}` }, options);
58
+ return data;
59
+ }
60
+ /**
61
+ * Sends a signed `webhook.test` event now, also to a paused endpoint, and returns what your endpoint
62
+ * answered. Check `delivered`: this doesn't throw when your endpoint failed. If Chatwise is waiting
63
+ * before it tries the endpoint again (`health.backoffUntil`), a test that succeeds ends the wait.
64
+ *
65
+ * Scope: `webhooks:write`.
66
+ */
67
+ async test(endpointId, options) {
68
+ const { data } = await this.#request({ method: 'POST', path: (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}/test` }, options);
69
+ return data;
70
+ }
71
+ /**
72
+ * Replaces the signing secret. Store it right away: it is returned only here. For 24 hours deliveries
73
+ * are signed with the previous secret too.
74
+ *
75
+ * Scope: `webhooks:write`, and `messages:read` if the endpoint has `message.*` events.
76
+ */
77
+ async rotateSecret(endpointId, options) {
78
+ const { data } = await this.#request({ method: 'POST', path: (0, http_js_1.path) `/v1/webhook-endpoints/${endpointId}/rotate-secret` }, options);
79
+ return data;
80
+ }
81
+ }
82
+ exports.WebhookEndpoints = WebhookEndpoints;
@@ -0,0 +1,13 @@
1
+ import type { RequestOptions } from '../core/http.js';
2
+ import type { WebhookEventTypeInfo } from '../generated/types.js';
3
+ /** The events a webhook endpoint can subscribe to. */
4
+ export declare class WebhookEventTypes {
5
+ #private;
6
+ /**
7
+ * Lists the events an endpoint can subscribe to and the channels each covers. Some are listed before
8
+ * they are sent: today Chatwise sends only `message.received`.
9
+ *
10
+ * Scope: `webhooks:read`.
11
+ */
12
+ list(options?: RequestOptions): Promise<WebhookEventTypeInfo[]>;
13
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookEventTypes = void 0;
4
+ /** The events a webhook endpoint can subscribe to. */
5
+ class WebhookEventTypes {
6
+ #request;
7
+ /** @internal */
8
+ constructor(request) {
9
+ this.#request = request;
10
+ }
11
+ /**
12
+ * Lists the events an endpoint can subscribe to and the channels each covers. Some are listed before
13
+ * they are sent: today Chatwise sends only `message.received`.
14
+ *
15
+ * Scope: `webhooks:read`.
16
+ */
17
+ async list(options) {
18
+ const { data } = await this.#request({ method: 'GET', path: '/v1/webhook-event-types' }, options);
19
+ return data;
20
+ }
21
+ }
22
+ exports.WebhookEventTypes = WebhookEventTypes;
@@ -0,0 +1,48 @@
1
+ import { type RequestOptions } from '../core/http.js';
2
+ import { type PagePromise } from '../core/pagination.js';
3
+ import type { CreateWhatsappTemplateParams, ListWhatsappTemplatesParams, SendWhatsappTemplateParams, SendWhatsappTemplateResult, WhatsappTemplate } from '../generated/types.js';
4
+ export interface CreateWhatsappTemplateOptions extends RequestOptions {
5
+ /**
6
+ * A key you choose for this template, 1 to 128 letters, digits, dots, underscores, hyphens or colons.
7
+ * Use the same one, with the same template, when you repeat the call: you get the same template back.
8
+ * Without it, two identical submissions count as a repeat too.
9
+ */
10
+ idempotencyKey?: string | undefined;
11
+ }
12
+ /** WhatsApp message templates. */
13
+ export declare class WhatsappTemplates {
14
+ #private;
15
+ /**
16
+ * Lists the workspace's WhatsApp templates, newest first, with the variables and buttons each takes.
17
+ *
18
+ * Scope: `templates:read`.
19
+ */
20
+ list(params?: ListWhatsappTemplatesParams, options?: RequestOptions): PagePromise<WhatsappTemplate>;
21
+ /**
22
+ * Reads one WhatsApp template. After creating one, poll it until `status` is no longer `PENDING`.
23
+ * `sendable` then says whether it can be sent.
24
+ *
25
+ * Scope: `templates:read`.
26
+ */
27
+ get(templateId: string, options?: RequestOptions): Promise<WhatsappTemplate>;
28
+ /**
29
+ * Creates a WhatsApp template and submits it to Meta for review. The route recognizes a repeat, by
30
+ * `idempotencyKey` or by the template itself, so this is retried like a read. Only an answer with a
31
+ * `code` isn't. `TEMPLATE_SUBMISSION_IN_PROGRESS`, which a retry can end with, and
32
+ * `TEMPLATE_SUBMISSION_UNCONFIRMED` mean to repeat the call later, with the same key and template.
33
+ *
34
+ * Scope: `templates:write`.
35
+ */
36
+ create(params: CreateWhatsappTemplateParams, options?: CreateWhatsappTemplateOptions): Promise<WhatsappTemplate>;
37
+ /**
38
+ * Sends an approved WhatsApp template by its name. The answer means WhatsApp accepted the message,
39
+ * not that it was delivered. To send one by its id, use `messages.send`.
40
+ *
41
+ * Sending twice sends two messages, so this is retried only after a 429. After anything but a 4xx
42
+ * (a timeout, a connection error, an abort, a 5xx) it may have been sent, even if the conversation
43
+ * doesn't show it, so check before you send again.
44
+ *
45
+ * Scope: `messages:send`.
46
+ */
47
+ send(params: SendWhatsappTemplateParams, options?: RequestOptions): Promise<SendWhatsappTemplateResult>;
48
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WhatsappTemplates = void 0;
4
+ const errors_js_1 = require("../core/errors.js");
5
+ const http_js_1 = require("../core/http.js");
6
+ const pagination_js_1 = require("../core/pagination.js");
7
+ /** WhatsApp message templates. */
8
+ class WhatsappTemplates {
9
+ #request;
10
+ /** @internal */
11
+ constructor(request) {
12
+ this.#request = request;
13
+ }
14
+ /**
15
+ * Lists the workspace's WhatsApp templates, newest first, with the variables and buttons each takes.
16
+ *
17
+ * Scope: `templates:read`.
18
+ */
19
+ list(params = {}, options) {
20
+ return (0, pagination_js_1.list)(this.#request, () => '/v1/whatsapp/templates', params, options);
21
+ }
22
+ /**
23
+ * Reads one WhatsApp template. After creating one, poll it until `status` is no longer `PENDING`.
24
+ * `sendable` then says whether it can be sent.
25
+ *
26
+ * Scope: `templates:read`.
27
+ */
28
+ async get(templateId, options) {
29
+ const { data } = await this.#request({ method: 'GET', path: (0, http_js_1.path) `/v1/whatsapp/templates/${templateId}` }, options);
30
+ return data;
31
+ }
32
+ /**
33
+ * Creates a WhatsApp template and submits it to Meta for review. The route recognizes a repeat, by
34
+ * `idempotencyKey` or by the template itself, so this is retried like a read. Only an answer with a
35
+ * `code` isn't. `TEMPLATE_SUBMISSION_IN_PROGRESS`, which a retry can end with, and
36
+ * `TEMPLATE_SUBMISSION_UNCONFIRMED` mean to repeat the call later, with the same key and template.
37
+ *
38
+ * Scope: `templates:write`.
39
+ */
40
+ async create(params, options) {
41
+ const { idempotencyKey, ...rest } = options ?? {};
42
+ if (idempotencyKey !== undefined && !/^[\x21-\x7e]+$/.test(idempotencyKey)) {
43
+ throw new errors_js_1.ChatwiseError('idempotencyKey must be 1 to 128 letters, digits, dots, underscores, hyphens or colons.');
44
+ }
45
+ const { data } = await this.#request({
46
+ method: 'POST',
47
+ path: '/v1/whatsapp/templates',
48
+ body: params,
49
+ headers: idempotencyKey === undefined ? undefined : { 'Idempotency-Key': idempotencyKey },
50
+ idempotent: true,
51
+ }, rest);
52
+ return data;
53
+ }
54
+ /**
55
+ * Sends an approved WhatsApp template by its name. The answer means WhatsApp accepted the message,
56
+ * not that it was delivered. To send one by its id, use `messages.send`.
57
+ *
58
+ * Sending twice sends two messages, so this is retried only after a 429. After anything but a 4xx
59
+ * (a timeout, a connection error, an abort, a 5xx) it may have been sent, even if the conversation
60
+ * doesn't show it, so check before you send again.
61
+ *
62
+ * Scope: `messages:send`.
63
+ */
64
+ async send(params, options) {
65
+ const { data } = await this.#request({ method: 'POST', path: '/v1/template/whatsapp', body: params }, options);
66
+ return data;
67
+ }
68
+ }
69
+ exports.WhatsappTemplates = WhatsappTemplates;
@@ -0,0 +1,2 @@
1
+ /** The version of this package. A test keeps it equal to package.json's. */
2
+ export declare const VERSION = "0.1.0";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = void 0;
4
+ /** The version of this package. A test keeps it equal to package.json's. */
5
+ exports.VERSION = '0.1.0';