@kirimdev/sdk 1.0.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 (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -0
  3. package/dist/client.d.ts +52 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +75 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/errors.d.ts +70 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/errors.js +167 -0
  10. package/dist/errors.js.map +1 -0
  11. package/dist/http.d.ts +71 -0
  12. package/dist/http.d.ts.map +1 -0
  13. package/dist/http.js +197 -0
  14. package/dist/http.js.map +1 -0
  15. package/dist/index.d.ts +12 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +9 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/pagination.d.ts +36 -0
  20. package/dist/pagination.d.ts.map +1 -0
  21. package/dist/pagination.js +59 -0
  22. package/dist/pagination.js.map +1 -0
  23. package/dist/resources/contacts.d.ts +36 -0
  24. package/dist/resources/contacts.d.ts.map +1 -0
  25. package/dist/resources/contacts.js +68 -0
  26. package/dist/resources/contacts.js.map +1 -0
  27. package/dist/resources/conversations.d.ts +23 -0
  28. package/dist/resources/conversations.d.ts.map +1 -0
  29. package/dist/resources/conversations.js +43 -0
  30. package/dist/resources/conversations.js.map +1 -0
  31. package/dist/resources/labels.d.ts +17 -0
  32. package/dist/resources/labels.d.ts.map +1 -0
  33. package/dist/resources/labels.js +41 -0
  34. package/dist/resources/labels.js.map +1 -0
  35. package/dist/resources/messages.d.ts +19 -0
  36. package/dist/resources/messages.d.ts.map +1 -0
  37. package/dist/resources/messages.js +40 -0
  38. package/dist/resources/messages.js.map +1 -0
  39. package/dist/resources/templates.d.ts +10 -0
  40. package/dist/resources/templates.d.ts.map +1 -0
  41. package/dist/resources/templates.js +19 -0
  42. package/dist/resources/templates.js.map +1 -0
  43. package/dist/resources/webhook-deliveries.d.ts +19 -0
  44. package/dist/resources/webhook-deliveries.d.ts.map +1 -0
  45. package/dist/resources/webhook-deliveries.js +35 -0
  46. package/dist/resources/webhook-deliveries.js.map +1 -0
  47. package/dist/resources/webhook-subscriptions.d.ts +26 -0
  48. package/dist/resources/webhook-subscriptions.d.ts.map +1 -0
  49. package/dist/resources/webhook-subscriptions.js +60 -0
  50. package/dist/resources/webhook-subscriptions.js.map +1 -0
  51. package/dist/types.d.ts +55 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +2 -0
  54. package/dist/types.js.map +1 -0
  55. package/dist/webhooks.d.ts +100 -0
  56. package/dist/webhooks.d.ts.map +1 -0
  57. package/dist/webhooks.js +65 -0
  58. package/dist/webhooks.js.map +1 -0
  59. package/openapi.json +6181 -0
  60. package/package.json +63 -0
@@ -0,0 +1,40 @@
1
+ import { Paginator } from '../pagination.js';
2
+ export class MessagesResource {
3
+ http;
4
+ constructor(http) {
5
+ this.http = http;
6
+ }
7
+ /** POST /messages — send a WhatsApp message (any supported type). */
8
+ send(params, options) {
9
+ return this.http.requestData({
10
+ method: 'POST',
11
+ path: '/messages',
12
+ body: params,
13
+ ...(options ? { options } : {}),
14
+ });
15
+ }
16
+ /** GET /messages — list messages; async-iterable + per-page. */
17
+ list(params, options) {
18
+ return new Paginator(this.http, { path: '/messages', ...(params ? { query: params } : {}) }, options);
19
+ }
20
+ /** GET /messages/{id} */
21
+ retrieve(id, options) {
22
+ return this.http.requestData({
23
+ method: 'GET',
24
+ path: `/messages/${encodeURIComponent(id)}`,
25
+ ...(options ? { options } : {}),
26
+ });
27
+ }
28
+ /**
29
+ * GET /messages/{id}/media — returns the signed URL the API redirects to
30
+ * (the SDK does NOT follow the redirect — you decide whether to stream).
31
+ */
32
+ media(id, options) {
33
+ return this.http.requestData({
34
+ method: 'GET',
35
+ path: `/messages/${encodeURIComponent(id)}/media`,
36
+ ...(options ? { options } : {}),
37
+ });
38
+ }
39
+ }
40
+ //# sourceMappingURL=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;YACb,IAAI,EAAE,aAAa,kBAAkB,CAAC,EAAE,CAAC,QAAQ;YACjD,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import type { HttpClient, RequestOptions } from '../http.js';
2
+ import { Paginator } from '../pagination.js';
3
+ import type { ListTemplatesParams, RetrieveTemplateParams, Template, TemplateListItem } from '../types.js';
4
+ export declare class TemplatesResource {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ list(params?: ListTemplatesParams, options?: RequestOptions): Paginator<TemplateListItem>;
8
+ retrieve(name: string, params?: RetrieveTemplateParams, options?: RequestOptions): Promise<Template>;
9
+ }
10
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/resources/templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,QAAQ,EACR,gBAAgB,EACjB,MAAM,aAAa,CAAA;AAEpB,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C,IAAI,CAAC,MAAM,CAAC,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC,gBAAgB,CAAC;IAQzF,QAAQ,CACN,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,sBAAsB,EAC/B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,QAAQ,CAAC;CAQrB"}
@@ -0,0 +1,19 @@
1
+ import { Paginator } from '../pagination.js';
2
+ export class TemplatesResource {
3
+ http;
4
+ constructor(http) {
5
+ this.http = http;
6
+ }
7
+ list(params, options) {
8
+ return new Paginator(this.http, { path: '/templates', ...(params ? { query: params } : {}) }, options);
9
+ }
10
+ retrieve(name, params, options) {
11
+ return this.http.requestData({
12
+ method: 'GET',
13
+ path: `/templates/${encodeURIComponent(name)}`,
14
+ ...(params ? { query: params } : {}),
15
+ ...(options ? { options } : {}),
16
+ });
17
+ }
18
+ }
19
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/resources/templates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAQ5C,MAAM,OAAO,iBAAiB;IACC;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD,IAAI,CAAC,MAA4B,EAAE,OAAwB;QACzD,OAAO,IAAI,SAAS,CAClB,IAAI,CAAC,IAAI,EACT,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAsE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAC5H,OAAO,CACR,CAAA;IACH,CAAC;IAED,QAAQ,CACN,IAAY,EACZ,MAA+B,EAC/B,OAAwB;QAExB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAW;YACrC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,cAAc,kBAAkB,CAAC,IAAI,CAAC,EAAE;YAC9C,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAsE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ import type { HttpClient, RequestOptions } from '../http.js';
2
+ import { Paginator } from '../pagination.js';
3
+ import type { BulkReplayParams, BulkReplayResult, ListWebhookDeliveriesParams, WebhookDelivery, WebhookDeliveryListItem } from '../types.js';
4
+ export declare class WebhookDeliveriesResource {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ list(params?: ListWebhookDeliveriesParams, options?: RequestOptions): Paginator<WebhookDeliveryListItem>;
8
+ retrieve(id: string, options?: RequestOptions): Promise<WebhookDelivery>;
9
+ /** POST /webhook_deliveries/{id}/replay */
10
+ replay(id: string, options?: RequestOptions): Promise<{
11
+ id: string;
12
+ object: 'webhook_delivery';
13
+ replayed_from: string;
14
+ status: 'pending';
15
+ }>;
16
+ /** POST /webhook_deliveries/bulk_replay */
17
+ bulkReplay(params: BulkReplayParams, options?: RequestOptions): Promise<BulkReplayResult>;
18
+ }
19
+ //# sourceMappingURL=webhook-deliveries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-deliveries.d.ts","sourceRoot":"","sources":["../../src/resources/webhook-deliveries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,2BAA2B,EAC3B,eAAe,EACf,uBAAuB,EACxB,MAAM,aAAa,CAAA;AAEpB,qBAAa,yBAAyB;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C,IAAI,CACF,MAAM,CAAC,EAAE,2BAA2B,EACpC,OAAO,CAAC,EAAE,cAAc,GACvB,SAAS,CAAC,uBAAuB,CAAC;IAQrC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAQxE,2CAA2C;IAC3C,MAAM,CACJ,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC;QACT,EAAE,EAAE,MAAM,CAAA;QACV,MAAM,EAAE,kBAAkB,CAAA;QAC1B,aAAa,EAAE,MAAM,CAAA;QACrB,MAAM,EAAE,SAAS,CAAA;KAClB,CAAC;IAQF,2CAA2C;IAC3C,UAAU,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAQ1F"}
@@ -0,0 +1,35 @@
1
+ import { Paginator } from '../pagination.js';
2
+ export class WebhookDeliveriesResource {
3
+ http;
4
+ constructor(http) {
5
+ this.http = http;
6
+ }
7
+ list(params, options) {
8
+ return new Paginator(this.http, { path: '/webhook_deliveries', ...(params ? { query: params } : {}) }, options);
9
+ }
10
+ retrieve(id, options) {
11
+ return this.http.requestData({
12
+ method: 'GET',
13
+ path: `/webhook_deliveries/${encodeURIComponent(id)}`,
14
+ ...(options ? { options } : {}),
15
+ });
16
+ }
17
+ /** POST /webhook_deliveries/{id}/replay */
18
+ replay(id, options) {
19
+ return this.http.requestData({
20
+ method: 'POST',
21
+ path: `/webhook_deliveries/${encodeURIComponent(id)}/replay`,
22
+ ...(options ? { options } : {}),
23
+ });
24
+ }
25
+ /** POST /webhook_deliveries/bulk_replay */
26
+ bulkReplay(params, options) {
27
+ return this.http.requestData({
28
+ method: 'POST',
29
+ path: '/webhook_deliveries/bulk_replay',
30
+ body: params,
31
+ ...(options ? { options } : {}),
32
+ });
33
+ }
34
+ }
35
+ //# sourceMappingURL=webhook-deliveries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-deliveries.js","sourceRoot":"","sources":["../../src/resources/webhook-deliveries.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAS5C,MAAM,OAAO,yBAAyB;IACP;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IA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Paginator } from '../pagination.js';
3
+ import type { AddWebhookSecret, CreateWebhookSubscriptionParams, UpdateWebhookSubscriptionParams, WebhookSubscription, WebhookSubscriptionListItem } from '../types.js';
4
+ export declare class WebhookSubscriptionsResource {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ create(params: CreateWebhookSubscriptionParams, options?: RequestOptions): Promise<WebhookSubscription>;
8
+ list(options?: RequestOptions): Paginator<WebhookSubscriptionListItem>;
9
+ retrieve(id: string, options?: RequestOptions): Promise<WebhookSubscription>;
10
+ update(id: string, params: UpdateWebhookSubscriptionParams, options?: RequestOptions): Promise<WebhookSubscription>;
11
+ del(id: string, options?: RequestOptions): Promise<{
12
+ id: string;
13
+ deleted: true;
14
+ }>;
15
+ /**
16
+ * POST /webhook_subscriptions/{id}/secrets — mint a new signing secret.
17
+ * The returned `secret` is shown ONCE. Store it.
18
+ */
19
+ addSecret(id: string, options?: RequestOptions): Promise<AddWebhookSecret>;
20
+ /** DELETE /webhook_subscriptions/{id}/secrets/{secret_id} */
21
+ revokeSecret(id: string, secretId: string, options?: RequestOptions): Promise<{
22
+ id: string;
23
+ deleted: true;
24
+ }>;
25
+ }
26
+ //# sourceMappingURL=webhook-subscriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-subscriptions.d.ts","sourceRoot":"","sources":["../../src/resources/webhook-subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EACV,gBAAgB,EAChB,+BAA+B,EAC/B,+BAA+B,EAC/B,mBAAmB,EACnB,2BAA2B,EAC5B,MAAM,aAAa,CAAA;AAEpB,qBAAa,4BAA4B;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C,MAAM,CACJ,MAAM,EAAE,+BAA+B,EACvC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,mBAAmB,CAAC;IAS/B,IAAI,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC,2BAA2B,CAAC;IAQtE,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAQ5E,MAAM,CACJ,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,+BAA+B,EACvC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,mBAAmB,CAAC;IAS/B,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,IAAI,CAAA;KAAE,CAAC;IAQjF;;;OAGG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAQ1E,6DAA6D;IAC7D,YAAY,CACV,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,IAAI,CAAA;KAAE,CAAC;CAO1C"}
@@ -0,0 +1,60 @@
1
+ import { Paginator } from '../pagination.js';
2
+ export class WebhookSubscriptionsResource {
3
+ http;
4
+ constructor(http) {
5
+ this.http = http;
6
+ }
7
+ create(params, options) {
8
+ return this.http.requestData({
9
+ method: 'POST',
10
+ path: '/webhook_subscriptions',
11
+ body: params,
12
+ ...(options ? { options } : {}),
13
+ });
14
+ }
15
+ list(options) {
16
+ return new Paginator(this.http, { path: '/webhook_subscriptions' }, options);
17
+ }
18
+ retrieve(id, options) {
19
+ return this.http.requestData({
20
+ method: 'GET',
21
+ path: `/webhook_subscriptions/${encodeURIComponent(id)}`,
22
+ ...(options ? { options } : {}),
23
+ });
24
+ }
25
+ update(id, params, options) {
26
+ return this.http.requestData({
27
+ method: 'PATCH',
28
+ path: `/webhook_subscriptions/${encodeURIComponent(id)}`,
29
+ body: params,
30
+ ...(options ? { options } : {}),
31
+ });
32
+ }
33
+ del(id, options) {
34
+ return this.http.requestData({
35
+ method: 'DELETE',
36
+ path: `/webhook_subscriptions/${encodeURIComponent(id)}`,
37
+ ...(options ? { options } : {}),
38
+ });
39
+ }
40
+ /**
41
+ * POST /webhook_subscriptions/{id}/secrets — mint a new signing secret.
42
+ * The returned `secret` is shown ONCE. Store it.
43
+ */
44
+ addSecret(id, options) {
45
+ return this.http.requestData({
46
+ method: 'POST',
47
+ path: `/webhook_subscriptions/${encodeURIComponent(id)}/secrets`,
48
+ ...(options ? { options } : {}),
49
+ });
50
+ }
51
+ /** DELETE /webhook_subscriptions/{id}/secrets/{secret_id} */
52
+ revokeSecret(id, secretId, options) {
53
+ return this.http.requestData({
54
+ method: 'DELETE',
55
+ path: `/webhook_subscriptions/${encodeURIComponent(id)}/secrets/${encodeURIComponent(secretId)}`,
56
+ ...(options ? { options } : {}),
57
+ });
58
+ }
59
+ }
60
+ //# sourceMappingURL=webhook-subscriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-subscriptions.js","sourceRoot":"","sources":["../../src/resources/webhook-subscriptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAS5C,MAAM,OAAO,4BAA4B;IACV;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD,MAAM,CACJ,MAAuC,EACvC,OAAwB;QAExB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAsB;YAChD,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,wBAAwB;YAC9B,IAAI,EAAE,MAAM;YACZ,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CA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ACd,IAAI,EAAE,0BAA0B,kBAAkB,CAAC,EAAE,CAAC,UAAU;YAChE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,CAAC,CAAA;IACJ,CAAC;IAED,6DAA6D;IAC7D,YAAY,CACV,EAAU,EACV,QAAgB,EAChB,OAAwB;QAExB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;YAC3B,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,0BAA0B,kBAAkB,CAAC,EAAE,CAAC,YAAY,kBAAkB,CAAC,QAAQ,CAAC,EAAE;YAChG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Re-export and alias types from the generated OpenAPI schema in a stable,
3
+ * user-facing namespace. Resource files import from here so a regeneration
4
+ * never breaks downstream import paths.
5
+ */
6
+ import type { components, paths } from './generated/schema.js';
7
+ export type Schemas = components['schemas'];
8
+ type SingleData<T> = T extends {
9
+ data: infer D;
10
+ } ? D : never;
11
+ type ListData<T> = T extends {
12
+ data: Array<infer D>;
13
+ } ? D : never;
14
+ export type MeContext = SingleData<Schemas['MeResponse']>;
15
+ export type Message = SingleData<Schemas['GetMessageResponse']>;
16
+ export type MessageListItem = ListData<Schemas['ListMessagesResponse']>;
17
+ export type SendMessageParams = NonNullable<paths['/messages']['post']['requestBody']>['content']['application/json'];
18
+ export type ListMessagesParams = NonNullable<paths['/messages']['get']['parameters']['query']>;
19
+ export type MessageMediaRedirect = {
20
+ url: string | null;
21
+ request_id: string | null;
22
+ };
23
+ export type Template = SingleData<Schemas['GetTemplateResponse']>;
24
+ export type TemplateListItem = ListData<Schemas['ListTemplatesResponse']>;
25
+ export type ListTemplatesParams = NonNullable<paths['/templates']['get']['parameters']['query']>;
26
+ export type RetrieveTemplateParams = NonNullable<paths['/templates/{name}']['get']['parameters']['query']>;
27
+ export type Conversation = SingleData<Schemas['GetConversationResponse']>;
28
+ export type ConversationListItem = ListData<Schemas['ListConversationsResponse']>;
29
+ export type ListConversationsParams = NonNullable<paths['/conversations']['get']['parameters']['query']>;
30
+ export type UpdateConversationParams = NonNullable<paths['/conversations/{id}']['patch']['requestBody']>['content']['application/json'];
31
+ export type AttachConversationLabelParams = NonNullable<paths['/conversations/{id}/labels']['post']['requestBody']>['content']['application/json'];
32
+ export type Contact = SingleData<Schemas['GetContactResponse']>;
33
+ export type ContactListItem = ListData<Schemas['ListContactsResponse']>;
34
+ export type ListContactsParams = NonNullable<paths['/contacts']['get']['parameters']['query']>;
35
+ export type CreateContactParams = NonNullable<paths['/contacts']['post']['requestBody']>['content']['application/json'];
36
+ export type UpdateContactParams = NonNullable<paths['/contacts/{id}']['patch']['requestBody']>['content']['application/json'];
37
+ export type AttachContactLabelParams = NonNullable<paths['/contacts/{id}/labels']['post']['requestBody']>['content']['application/json'];
38
+ export type BulkLabelContactsParams = NonNullable<paths['/contacts/bulk_label']['post']['requestBody']>['content']['application/json'];
39
+ export type Label = SingleData<Schemas['GetLabelResponse']>;
40
+ export type LabelListItem = ListData<Schemas['ListLabelsResponse']>;
41
+ export type ListLabelsParams = NonNullable<paths['/labels']['get']['parameters']['query']>;
42
+ export type CreateLabelParams = NonNullable<paths['/labels']['post']['requestBody']>['content']['application/json'];
43
+ export type UpdateLabelParams = NonNullable<paths['/labels/{id}']['patch']['requestBody']>['content']['application/json'];
44
+ export type WebhookSubscription = SingleData<Schemas['GetWebhookSubscriptionResponse']>;
45
+ export type WebhookSubscriptionListItem = ListData<Schemas['ListWebhookSubscriptionsResponse']>;
46
+ export type CreateWebhookSubscriptionParams = NonNullable<paths['/webhook_subscriptions']['post']['requestBody']>['content']['application/json'];
47
+ export type UpdateWebhookSubscriptionParams = NonNullable<paths['/webhook_subscriptions/{id}']['patch']['requestBody']>['content']['application/json'];
48
+ export type AddWebhookSecret = SingleData<Schemas['AddWebhookSecretResponse']>;
49
+ export type WebhookDelivery = SingleData<Schemas['GetWebhookDeliveryResponse']>;
50
+ export type WebhookDeliveryListItem = ListData<Schemas['ListWebhookDeliveriesResponse']>;
51
+ export type ListWebhookDeliveriesParams = NonNullable<paths['/webhook_deliveries']['get']['parameters']['query']>;
52
+ export type BulkReplayParams = NonNullable<paths['/webhook_deliveries/bulk_replay']['post']['requestBody']>['content']['application/json'];
53
+ export type BulkReplayResult = SingleData<Schemas['BulkReplayResponse']>;
54
+ export {};
55
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAE9D,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,CAAA;AAG3C,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAA;AAC5D,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAA;AAGjE,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAA;AAGzD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAA;AAC/D,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAA;AACvE,MAAM,MAAM,iBAAiB,GAAG,WAAW,CACzC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAC1C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KAAK,CAAC,qBAAqB,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAC3D,CAAA;AACD,MAAM,MAAM,gBAAgB,GAAG,WAAW,CACxC,KAAK,CAAC,iCAAiC,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAChE,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAA;AAChC,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Webhook HMAC verification + typed event payloads.
3
+ *
4
+ * The Kirim API signs outbound webhook deliveries with HMAC-SHA256 over the
5
+ * raw request body, encoded as `sha256=<hex>` in the `X-Kirim-Signature`
6
+ * header. This module exposes a constant-time verifier using Web Crypto
7
+ * (`crypto.subtle`) so it runs on Node 18+, Bun, Deno, and edge runtimes.
8
+ *
9
+ * The signing scheme mirrors `apps/api/src/lib/webhook-security.ts`.
10
+ *
11
+ * Usage:
12
+ * import { verifyWebhookSignature } from '@kirimdev/sdk/webhooks'
13
+ *
14
+ * const ok = await verifyWebhookSignature(
15
+ * await req.text(),
16
+ * req.headers.get('x-kirim-signature') ?? '',
17
+ * process.env.KIRIM_WEBHOOK_SECRET!,
18
+ * )
19
+ * if (!ok) return new Response('bad signature', { status: 401 })
20
+ */
21
+ /**
22
+ * Verify a Kirim webhook signature.
23
+ *
24
+ * MUST be called with the raw request body (the same bytes Kirim signed —
25
+ * re-serializing JSON will break the signature). Returns `false` (never
26
+ * throws) when the header is absent / malformed / mismatched. The caller
27
+ * MUST reject the request when this returns `false` (fail-closed).
28
+ */
29
+ export declare function verifyWebhookSignature(body: string, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;
30
+ /**
31
+ * Discriminated union of all event types Kirim can deliver to a webhook
32
+ * subscription. The `type` literal is the discriminator.
33
+ *
34
+ * The list of events here MUST stay in sync with what the API actually
35
+ * emits (see the worker's webhook dispatch + `apps/api` event constants).
36
+ * Treat unknown event types as forward-compatible: callers should keep a
37
+ * `default` branch and ignore unknown payloads rather than throwing.
38
+ */
39
+ export type KirimWebhookEvent = MessageCreatedEvent | MessageStatusUpdatedEvent | ConversationCreatedEvent | ConversationUpdatedEvent | ContactCreatedEvent | ContactUpdatedEvent;
40
+ interface BaseEvent {
41
+ id: string;
42
+ created_at: string;
43
+ /** Subscription id that triggered the delivery. */
44
+ subscription_id: string;
45
+ }
46
+ export interface MessageCreatedEvent extends BaseEvent {
47
+ type: 'message.created';
48
+ data: {
49
+ id: string;
50
+ object: 'message';
51
+ conversation_id?: string;
52
+ to: string;
53
+ type: string;
54
+ status: string;
55
+ created_at: string;
56
+ };
57
+ }
58
+ export interface MessageStatusUpdatedEvent extends BaseEvent {
59
+ type: 'message.status_updated';
60
+ data: {
61
+ id: string;
62
+ object: 'message';
63
+ status: 'sent' | 'delivered' | 'read' | 'failed' | 'queued' | 'pending';
64
+ error?: {
65
+ code: string;
66
+ message: string;
67
+ provider_code: number | null;
68
+ };
69
+ };
70
+ }
71
+ export interface ConversationCreatedEvent extends BaseEvent {
72
+ type: 'conversation.created';
73
+ data: {
74
+ id: string;
75
+ object: 'conversation';
76
+ };
77
+ }
78
+ export interface ConversationUpdatedEvent extends BaseEvent {
79
+ type: 'conversation.updated';
80
+ data: {
81
+ id: string;
82
+ object: 'conversation';
83
+ };
84
+ }
85
+ export interface ContactCreatedEvent extends BaseEvent {
86
+ type: 'contact.created';
87
+ data: {
88
+ id: string;
89
+ object: 'contact';
90
+ };
91
+ }
92
+ export interface ContactUpdatedEvent extends BaseEvent {
93
+ type: 'contact.updated';
94
+ data: {
95
+ id: string;
96
+ object: 'contact';
97
+ };
98
+ }
99
+ export {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AAE,MAAM,CAAC;YAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAA;KACxE,CAAA;CACF;AAED,MAAM,WAAW,wBAAyB,SAAQ,SAAS;IACzD,IAAI,EAAE,sBAAsB,CAAA;IAC5B,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,cAAc,CAAA;KAAE,CAAA;CAC7C;AAED,MAAM,WAAW,wBAAyB,SAAQ,SAAS;IACzD,IAAI,EAAE,sBAAsB,CAAA;IAC5B,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,cAAc,CAAA;KAAE,CAAA;CAC7C;AAED,MAAM,WAAW,mBAAoB,SAAQ,SAAS;IACpD,IAAI,EAAE,iBAAiB,CAAA;IACvB,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,CAAA;KAAE,CAAA;CACxC;AAED,MAAM,WAAW,mBAAoB,SAAQ,SAAS;IACpD,IAAI,EAAE,iBAAiB,CAAA;IACvB,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,CAAA;KAAE,CAAA;CACxC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Webhook HMAC verification + typed event payloads.
3
+ *
4
+ * The Kirim API signs outbound webhook deliveries with HMAC-SHA256 over the
5
+ * raw request body, encoded as `sha256=<hex>` in the `X-Kirim-Signature`
6
+ * header. This module exposes a constant-time verifier using Web Crypto
7
+ * (`crypto.subtle`) so it runs on Node 18+, Bun, Deno, and edge runtimes.
8
+ *
9
+ * The signing scheme mirrors `apps/api/src/lib/webhook-security.ts`.
10
+ *
11
+ * Usage:
12
+ * import { verifyWebhookSignature } from '@kirimdev/sdk/webhooks'
13
+ *
14
+ * const ok = await verifyWebhookSignature(
15
+ * await req.text(),
16
+ * req.headers.get('x-kirim-signature') ?? '',
17
+ * process.env.KIRIM_WEBHOOK_SECRET!,
18
+ * )
19
+ * if (!ok) return new Response('bad signature', { status: 401 })
20
+ */
21
+ /**
22
+ * Verify a Kirim webhook signature.
23
+ *
24
+ * MUST be called with the raw request body (the same bytes Kirim signed —
25
+ * re-serializing JSON will break the signature). Returns `false` (never
26
+ * throws) when the header is absent / malformed / mismatched. The caller
27
+ * MUST reject the request when this returns `false` (fail-closed).
28
+ */
29
+ export async function verifyWebhookSignature(body, signatureHeader, secret) {
30
+ if (!signatureHeader || !secret)
31
+ return false;
32
+ const provided = signatureHeader.startsWith('sha256=')
33
+ ? signatureHeader.slice('sha256='.length)
34
+ : signatureHeader;
35
+ const expected = await hmacSha256Hex(secret, body);
36
+ // Length comparison short-circuits *before* the timing-safe step. That's
37
+ // safe because byte length is not a secret (HMAC-SHA256 hex is always 64
38
+ // chars); leaking it gives the attacker nothing.
39
+ if (expected.length !== provided.length)
40
+ return false;
41
+ return timingSafeEqualHex(expected, provided);
42
+ }
43
+ async function hmacSha256Hex(secret, body) {
44
+ const enc = new TextEncoder();
45
+ const key = await crypto.subtle.importKey('raw', enc.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
46
+ const buf = await crypto.subtle.sign('HMAC', key, enc.encode(body));
47
+ return bufferToHex(new Uint8Array(buf));
48
+ }
49
+ function bufferToHex(buf) {
50
+ let out = '';
51
+ for (let i = 0; i < buf.length; i++) {
52
+ const byte = buf[i] ?? 0;
53
+ out += byte.toString(16).padStart(2, '0');
54
+ }
55
+ return out;
56
+ }
57
+ /** Constant-time string comparison. Inputs MUST be equal length. */
58
+ function timingSafeEqualHex(a, b) {
59
+ let diff = 0;
60
+ for (let i = 0; i < a.length; i++) {
61
+ diff |= (a.charCodeAt(i) ^ b.charCodeAt(i));
62
+ }
63
+ return diff === 0;
64
+ }
65
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAAA;;;;;;;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