@isnap/sdk 0.1.0 → 1.1.0-next.38

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 (104) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +173 -167
  3. package/dist/client.d.ts +48 -50
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +258 -89
  6. package/dist/client.js.map +1 -1
  7. package/dist/config.d.ts +43 -0
  8. package/dist/config.d.ts.map +1 -0
  9. package/dist/config.js +55 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/errors.d.ts +53 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +100 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/generated/openapi.d.ts +10924 -0
  16. package/dist/idempotency.d.ts +2 -0
  17. package/dist/idempotency.d.ts.map +1 -0
  18. package/dist/idempotency.js +4 -0
  19. package/dist/idempotency.js.map +1 -0
  20. package/dist/index.d.ts +26 -8
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +12 -6
  23. package/dist/index.js.map +1 -1
  24. package/dist/internal/sleep.d.ts +10 -0
  25. package/dist/internal/sleep.d.ts.map +1 -0
  26. package/dist/internal/sleep.js +37 -0
  27. package/dist/internal/sleep.js.map +1 -0
  28. package/dist/pagination.d.ts +10 -0
  29. package/dist/pagination.d.ts.map +1 -0
  30. package/dist/pagination.js +16 -0
  31. package/dist/pagination.js.map +1 -0
  32. package/dist/resources/attachments.d.ts +45 -0
  33. package/dist/resources/attachments.d.ts.map +1 -0
  34. package/dist/resources/attachments.js +120 -0
  35. package/dist/resources/attachments.js.map +1 -0
  36. package/dist/resources/base.d.ts +6 -0
  37. package/dist/resources/base.d.ts.map +1 -0
  38. package/dist/resources/base.js +7 -0
  39. package/dist/resources/base.js.map +1 -0
  40. package/dist/resources/byod.d.ts +15 -0
  41. package/dist/resources/byod.d.ts.map +1 -0
  42. package/dist/resources/byod.js +13 -0
  43. package/dist/resources/byod.js.map +1 -0
  44. package/dist/resources/chats.d.ts +29 -0
  45. package/dist/resources/chats.d.ts.map +1 -0
  46. package/dist/resources/chats.js +28 -0
  47. package/dist/resources/chats.js.map +1 -0
  48. package/dist/resources/lines.d.ts +64 -27
  49. package/dist/resources/lines.d.ts.map +1 -1
  50. package/dist/resources/lines.js +77 -37
  51. package/dist/resources/lines.js.map +1 -1
  52. package/dist/resources/lookup.d.ts +15 -0
  53. package/dist/resources/lookup.d.ts.map +1 -0
  54. package/dist/resources/lookup.js +13 -0
  55. package/dist/resources/lookup.js.map +1 -0
  56. package/dist/resources/messages.d.ts +36 -67
  57. package/dist/resources/messages.d.ts.map +1 -1
  58. package/dist/resources/messages.js +37 -94
  59. package/dist/resources/messages.js.map +1 -1
  60. package/dist/resources/trial.d.ts +28 -0
  61. package/dist/resources/trial.d.ts.map +1 -0
  62. package/dist/resources/trial.js +31 -0
  63. package/dist/resources/trial.js.map +1 -0
  64. package/dist/resources/webhooks.d.ts +49 -39
  65. package/dist/resources/webhooks.d.ts.map +1 -1
  66. package/dist/resources/webhooks.js +52 -39
  67. package/dist/resources/webhooks.js.map +1 -1
  68. package/dist/retry.d.ts +14 -0
  69. package/dist/retry.d.ts.map +1 -0
  70. package/dist/retry.js +47 -0
  71. package/dist/retry.js.map +1 -0
  72. package/dist/types.d.ts +30 -196
  73. package/dist/types.d.ts.map +1 -1
  74. package/dist/types.js +1 -28
  75. package/dist/types.js.map +1 -1
  76. package/dist/version.d.ts +3 -0
  77. package/dist/version.d.ts.map +1 -0
  78. package/dist/version.js +20 -0
  79. package/dist/version.js.map +1 -0
  80. package/dist/webhooks/parse.d.ts +15 -0
  81. package/dist/webhooks/parse.d.ts.map +1 -0
  82. package/dist/webhooks/parse.js +47 -0
  83. package/dist/webhooks/parse.js.map +1 -0
  84. package/dist/webhooks/types.d.ts +93 -0
  85. package/dist/webhooks/types.d.ts.map +1 -0
  86. package/dist/webhooks/types.js +20 -0
  87. package/dist/webhooks/types.js.map +1 -0
  88. package/dist/webhooks/verify.d.ts +41 -0
  89. package/dist/webhooks/verify.d.ts.map +1 -0
  90. package/dist/webhooks/verify.js +110 -0
  91. package/dist/webhooks/verify.js.map +1 -0
  92. package/package.json +45 -30
  93. package/dist/paginate.d.ts +0 -33
  94. package/dist/paginate.d.ts.map +0 -1
  95. package/dist/paginate.js +0 -40
  96. package/dist/paginate.js.map +0 -1
  97. package/dist/webhook-events.d.ts +0 -61
  98. package/dist/webhook-events.d.ts.map +0 -1
  99. package/dist/webhook-events.js +0 -44
  100. package/dist/webhook-events.js.map +0 -1
  101. package/dist/webhook-verify.d.ts +0 -27
  102. package/dist/webhook-verify.d.ts.map +0 -1
  103. package/dist/webhook-verify.js +0 -42
  104. package/dist/webhook-verify.js.map +0 -1
@@ -0,0 +1,2 @@
1
+ export declare function generateIdempotencyKey(): string;
2
+ //# sourceMappingURL=idempotency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idempotency.d.ts","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"AAAA,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C"}
@@ -0,0 +1,4 @@
1
+ export function generateIdempotencyKey() {
2
+ return crypto.randomUUID();
3
+ }
4
+ //# sourceMappingURL=idempotency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idempotency.js","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,sBAAsB;IACpC,OAAO,MAAM,CAAC,UAAU,EAAE,CAAA;AAC5B,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,11 +1,29 @@
1
- export { iSnapClient, init } from './client.js';
2
- export { MessagesResource } from './resources/messages.js';
1
+ export { ISnapClient } from './client.js';
2
+ export type { ClientConfig } from './config.js';
3
+ export { SDK_VERSION, MIN_API_VERSION } from './version.js';
4
+ export { APIConnectionError, APIError, AuthenticationError, BadRequestError, ConflictError, GoneError, InternalServerError, NotFoundError, PaymentRequiredError, PermissionDeniedError, QuotaExceededError, RateLimitError, ServiceUnavailableError, UnprocessableEntityError, WebhookSignatureError } from './errors.js';
5
+ export type { APIErrorMeta } from './errors.js';
6
+ export type { ErrorEnvelope, ErrorIssue, HttpMethod, RequestOptions } from './types.js';
7
+ export type { RetryInfo } from './retry.js';
8
+ export { AttachmentsResource } from './resources/attachments.js';
9
+ export { ByodResource } from './resources/byod.js';
10
+ export { ChatsResource } from './resources/chats.js';
3
11
  export { LinesResource } from './resources/lines.js';
12
+ export { LookupResource } from './resources/lookup.js';
13
+ export { MessagesResource } from './resources/messages.js';
14
+ export { TrialResource } from './resources/trial.js';
4
15
  export { WebhooksResource } from './resources/webhooks.js';
5
- export type { iSnapConfig, Message, SendMessageParams, ListMessagesParams, ListMessagesResponse, Line, ListLinesParams, ListLinesResponse, Webhook, CreateWebhookParams, Conversation, ListConversationsParams, ListConversationsResponse, ConversationThreadParams, ConversationThreadResponse, WebhookEventType, WebhookEvent, MessageSentEvent, MessageDeliveredEvent, MessageReadEvent, MessageFailedEvent, MessageReceivedEvent, } from './types.js';
6
- export { iSnapError, RateLimitError } from './types.js';
7
- export { verifyWebhookSignature } from './webhook-verify.js';
8
- export { parseWebhook } from './webhook-events.js';
9
- export type { ParseWebhookOptions, ParseWebhookResult } from './webhook-events.js';
10
- export { paginate } from './paginate.js';
16
+ export type { ChatMarkRead, ChatTypingStart, ChatTypingStop, MarkReadBody, ShareContactCardBody, ShareContactCardResult, TypingStartBody } from './resources/chats.js';
17
+ export type { AssignLineBody, Line, LineConfigPatch, LineConfigResponseData, LineHealth, LineList, ListLinesQuery, ListQueueQuery, MyLines, PatchLineBody, QueueResponseData, QuotaSnapshot, TransferOwnershipBody } from './resources/lines.js';
18
+ export type { LookupRequest, LookupResult } from './resources/lookup.js';
19
+ export type { ListMessagesQuery, Message, Reaction, ReactionRemoval, SendMessageBody, SendReactionBody } from './resources/messages.js';
20
+ export type { Attachment, CreateAttachmentBody, CreateAttachmentResponse, UploadInput, UploadMetadata, UploadOptions } from './resources/attachments.js';
21
+ export type { ByodPairBody, ByodPairResponse } from './resources/byod.js';
22
+ export type { TrialActivityData, TrialInitBody, TrialInitData, TrialStatusData } from './resources/trial.js';
23
+ export type { CreateWebhookBody, ListDeliveriesQuery, ListEventsQuery, UpdateWebhookBody, Webhook, WebhookDelivery, WebhookDeliveryReplay, WebhookEventItem, WebhookList, WebhookRotateSecret } from './resources/webhooks.js';
24
+ export { parseWebhookEvent } from './webhooks/parse.js';
25
+ export { verifyWebhook } from './webhooks/verify.js';
26
+ export type { VerifyWebhookOptions } from './webhooks/verify.js';
27
+ export { isLineEvent, isMessageEvent, isPreOrderEvent, isReactionEvent, isTrialEvent, isTypingIndicatorEvent } from './webhooks/types.js';
28
+ export type { LineEvent, LineEventType, MessageEvent, MessageEventType, PreOrderEvent, PreOrderEventType, ReactionEvent, ReactionEventType, TrialEvent, TrialEventType, TypingIndicatorEvent, TypingIndicatorEventType, WebhookEvent, WebhookEventBase } from './webhooks/types.js';
11
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EACV,WAAW,EACX,OAAO,EACP,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,OAAO,EACP,mBAAmB,EACnB,YAAY,EACZ,uBAAuB,EACvB,yBAAyB,EACzB,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,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EACL,WAAW,EACX,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EACV,SAAS,EACT,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,YAAY,EACZ,gBAAgB,EACjB,MAAM,qBAAqB,CAAA"}
package/dist/index.js CHANGED
@@ -1,9 +1,15 @@
1
- export { iSnapClient, init } from './client.js';
2
- export { MessagesResource } from './resources/messages.js';
1
+ export { ISnapClient } from './client.js';
2
+ export { SDK_VERSION, MIN_API_VERSION } from './version.js';
3
+ export { APIConnectionError, APIError, AuthenticationError, BadRequestError, ConflictError, GoneError, InternalServerError, NotFoundError, PaymentRequiredError, PermissionDeniedError, QuotaExceededError, RateLimitError, ServiceUnavailableError, UnprocessableEntityError, WebhookSignatureError } from './errors.js';
4
+ export { AttachmentsResource } from './resources/attachments.js';
5
+ export { ByodResource } from './resources/byod.js';
6
+ export { ChatsResource } from './resources/chats.js';
3
7
  export { LinesResource } from './resources/lines.js';
8
+ export { LookupResource } from './resources/lookup.js';
9
+ export { MessagesResource } from './resources/messages.js';
10
+ export { TrialResource } from './resources/trial.js';
4
11
  export { WebhooksResource } from './resources/webhooks.js';
5
- export { iSnapError, RateLimitError } from './types.js';
6
- export { verifyWebhookSignature } from './webhook-verify.js';
7
- export { parseWebhook } from './webhook-events.js';
8
- export { paginate } from './paginate.js';
12
+ export { parseWebhookEvent } from './webhooks/parse.js';
13
+ export { verifyWebhook } from './webhooks/verify.js';
14
+ export { isLineEvent, isMessageEvent, isPreOrderEvent, isReactionEvent, isTrialEvent, isTypingIndicatorEvent } from './webhooks/types.js';
9
15
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.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EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAgE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEpD,OAAO,EACL,WAAW,EACX,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Promise-based `setTimeout` that races a timer against an optional
3
+ * AbortSignal. If the signal aborts first, the promise rejects with
4
+ * `APIConnectionError` carrying the signal's `.reason` as the cause.
5
+ *
6
+ * Used by the retry loop's exponential-backoff sleep AND the attachments
7
+ * resource's polling loop — same semantics in both places.
8
+ */
9
+ export declare function sleep(ms: number, signal?: AbortSignal, abortMessage?: string): Promise<void>;
10
+ //# sourceMappingURL=sleep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../src/internal/sleep.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,KAAK,CACnB,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,WAAW,EACpB,YAAY,SAAyB,GACpC,OAAO,CAAC,IAAI,CAAC,CAyBf"}
@@ -0,0 +1,37 @@
1
+ import { APIConnectionError } from '../errors.js';
2
+ /**
3
+ * Promise-based `setTimeout` that races a timer against an optional
4
+ * AbortSignal. If the signal aborts first, the promise rejects with
5
+ * `APIConnectionError` carrying the signal's `.reason` as the cause.
6
+ *
7
+ * Used by the retry loop's exponential-backoff sleep AND the attachments
8
+ * resource's polling loop — same semantics in both places.
9
+ */
10
+ export function sleep(ms, signal, abortMessage = 'Aborted during sleep') {
11
+ return new Promise((resolve, reject) => {
12
+ if (signal?.aborted) {
13
+ reject(new APIConnectionError(abortMessage, { cause: signal.reason }));
14
+ return;
15
+ }
16
+ // Track the abort listener so the timer's resolve path can detach it.
17
+ // Without detachment, sleeps that complete normally still hold a
18
+ // closure on the caller's signal — accumulating one leak per call
19
+ // across the lifetime of a long-lived signal (e.g. a process-wide
20
+ // shutdown signal). Both resolve and reject paths detach.
21
+ let abortListener;
22
+ const timer = setTimeout(() => {
23
+ if (abortListener)
24
+ signal?.removeEventListener('abort', abortListener);
25
+ resolve();
26
+ }, ms);
27
+ if (signal) {
28
+ abortListener = () => {
29
+ clearTimeout(timer);
30
+ signal.removeEventListener('abort', abortListener);
31
+ reject(new APIConnectionError(abortMessage, { cause: signal.reason }));
32
+ };
33
+ signal.addEventListener('abort', abortListener, { once: true });
34
+ }
35
+ });
36
+ }
37
+ //# sourceMappingURL=sleep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sleep.js","sourceRoot":"","sources":["../../src/internal/sleep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEjD;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CACnB,EAAU,EACV,MAAoB,EACpB,YAAY,GAAG,sBAAsB;IAErC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,kBAAkB,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;YACtE,OAAM;QACR,CAAC;QACD,sEAAsE;QACtE,iEAAiE;QACjE,kEAAkE;QAClE,kEAAkE;QAClE,0DAA0D;QAC1D,IAAI,aAAuC,CAAA;QAC3C,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,IAAI,aAAa;gBAAE,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;YACtE,OAAO,EAAE,CAAA;QACX,CAAC,EAAE,EAAE,CAAC,CAAA;QACN,IAAI,MAAM,EAAE,CAAC;YACX,aAAa,GAAG,GAAG,EAAE;gBACnB,YAAY,CAAC,KAAK,CAAC,CAAA;gBACnB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,aAA2B,CAAC,CAAA;gBAChE,MAAM,CAAC,IAAI,kBAAkB,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;YACxE,CAAC,CAAA;YACD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;QACjE,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ export interface CursorPage<T> {
2
+ items: T[];
3
+ has_more: boolean;
4
+ next_cursor: string | null;
5
+ }
6
+ export interface PaginateOptions {
7
+ signal?: AbortSignal;
8
+ }
9
+ export declare function paginate<T>(fetchPage: (cursor: string | undefined) => Promise<CursorPage<T>>, options?: PaginateOptions): AsyncIterable<T>;
10
+ //# sourceMappingURL=pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,QAAQ,EAAE,OAAO,CAAA;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,wBAAuB,QAAQ,CAAC,CAAC,EAC/B,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACjE,OAAO,GAAE,eAAoB,GAC5B,aAAa,CAAC,CAAC,CAAC,CAWlB"}
@@ -0,0 +1,16 @@
1
+ import { APIConnectionError } from './errors.js';
2
+ export async function* paginate(fetchPage, options = {}) {
3
+ let cursor;
4
+ while (true) {
5
+ if (options.signal?.aborted) {
6
+ throw new APIConnectionError('Pagination aborted', { cause: options.signal.reason });
7
+ }
8
+ const page = await fetchPage(cursor);
9
+ for (const item of page.items)
10
+ yield item;
11
+ if (!page.has_more || !page.next_cursor)
12
+ return;
13
+ cursor = page.next_cursor;
14
+ }
15
+ }
16
+ //# sourceMappingURL=pagination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.js","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAYhD,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,QAAQ,CAC7B,SAAiE,EACjE,UAA2B,EAAE;IAE7B,IAAI,MAA0B,CAAA;IAC9B,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YAC5B,MAAM,IAAI,kBAAkB,CAAC,oBAAoB,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;QACtF,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,CAAA;QACpC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,CAAA;QACzC,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,OAAM;QAC/C,MAAM,GAAG,IAAI,CAAC,WAAW,CAAA;IAC3B,CAAC;AACH,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { components } from '../generated/openapi.js';
2
+ import type { RequestOptions } from '../types.js';
3
+ import { BaseResource } from './base.js';
4
+ export type Attachment = components['schemas']['Attachment'];
5
+ export type CreateAttachmentBody = components['schemas']['CreateAttachment'];
6
+ export type CreateAttachmentResponse = components['schemas']['CreateAttachmentResponse'];
7
+ export type UploadInput = Blob | ArrayBuffer | Uint8Array;
8
+ export interface UploadMetadata {
9
+ filename: string;
10
+ contentType: string;
11
+ }
12
+ export interface UploadOptions extends RequestOptions {
13
+ /** Override the polling interval in ms while waiting for `status: ready`. Default 500. */
14
+ pollIntervalMs?: number;
15
+ /** Override the maximum number of polls before giving up. Default 60 (≈30s at 500ms). */
16
+ maxPolls?: number;
17
+ }
18
+ export declare class AttachmentsResource extends BaseResource {
19
+ /**
20
+ * `POST /v1/attachments` — register an attachment and receive a
21
+ * presigned R2 upload URL. Step 1 of the 3-step upload flow; prefer the
22
+ * high-level `upload()` unless you need control over each step.
23
+ *
24
+ * Note: the contract has no DELETE /v1/attachments/{id} endpoint — rows
25
+ * auto-expire after 72h via the retention worker. Don't add a delete
26
+ * method here unless the backend ships one.
27
+ */
28
+ create(body: CreateAttachmentBody, opts?: RequestOptions): Promise<CreateAttachmentResponse>;
29
+ /** `GET /v1/attachments/{id}` — fetch an attachment's status and download URL. */
30
+ get(id: string, opts?: RequestOptions): Promise<Attachment>;
31
+ /**
32
+ * Transparent 3-step attachment upload:
33
+ * 1. `POST /v1/attachments` to register the file and get a presigned R2 URL
34
+ * 2. `PUT` the body directly to R2 with the required headers
35
+ * 3. Poll `GET /v1/attachments/{id}` every `pollIntervalMs` until `status === 'ready'`
36
+ *
37
+ * Throws:
38
+ * - `BadRequestError` if `size_bytes` exceeds the 5 GB cap
39
+ * - `APIError` (`upload_failed`) if the R2 PUT returns non-2xx
40
+ * - `APIError` (`upload_failed`) if the server transitions to `status: failed`
41
+ * - `APIError` (`upload_timeout`) if `status` is still `uploading` after `maxPolls × pollIntervalMs`
42
+ */
43
+ upload(file: UploadInput, metadata: UploadMetadata, opts?: UploadOptions): Promise<Attachment>;
44
+ }
45
+ //# sourceMappingURL=attachments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachments.d.ts","sourceRoot":"","sources":["../../src/resources/attachments.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,CAAA;AAC5D,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAA;AAC5E,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,0BAA0B,CAAC,CAAA;AAExF,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,WAAW,GAAG,UAAU,CAAA;AAEzD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,aAAc,SAAQ,cAAc;IACnD,0FAA0F;IAC1F,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,yFAAyF;IACzF,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAeD,qBAAa,mBAAoB,SAAQ,YAAY;IACnD;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAI,EAAE,oBAAoB,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAI5F,kFAAkF;IAClF,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAS3D;;;;;;;;;;;OAWG;IACG,MAAM,CACV,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,cAAc,EACxB,IAAI,GAAE,aAAkB,GACvB,OAAO,CAAC,UAAU,CAAC;CAgFvB"}
@@ -0,0 +1,120 @@
1
+ import { APIError, APIConnectionError } from '../errors.js';
2
+ import { sleep } from '../internal/sleep.js';
3
+ import { BaseResource } from './base.js';
4
+ const FIVE_GB = 5 * 1024 * 1024 * 1024;
5
+ const DEFAULT_POLL_INTERVAL_MS = 500;
6
+ const DEFAULT_MAX_POLLS = 60;
7
+ function computeSize(file) {
8
+ if (file instanceof Uint8Array)
9
+ return file.byteLength;
10
+ if (file instanceof ArrayBuffer)
11
+ return file.byteLength;
12
+ // Blob check last so a Buffer (which extends Uint8Array under Node) is
13
+ // caught by the Uint8Array branch above.
14
+ if (typeof Blob !== 'undefined' && file instanceof Blob)
15
+ return file.size;
16
+ throw new TypeError('attachments.upload: file must be Blob, ArrayBuffer, or Uint8Array');
17
+ }
18
+ export class AttachmentsResource extends BaseResource {
19
+ /**
20
+ * `POST /v1/attachments` — register an attachment and receive a
21
+ * presigned R2 upload URL. Step 1 of the 3-step upload flow; prefer the
22
+ * high-level `upload()` unless you need control over each step.
23
+ *
24
+ * Note: the contract has no DELETE /v1/attachments/{id} endpoint — rows
25
+ * auto-expire after 72h via the retention worker. Don't add a delete
26
+ * method here unless the backend ships one.
27
+ */
28
+ create(body, opts) {
29
+ return this.client.request('POST', '/v1/attachments', body, opts);
30
+ }
31
+ /** `GET /v1/attachments/{id}` — fetch an attachment's status and download URL. */
32
+ get(id, opts) {
33
+ return this.client.request('GET', `/v1/attachments/${encodeURIComponent(id)}`, undefined, opts);
34
+ }
35
+ /**
36
+ * Transparent 3-step attachment upload:
37
+ * 1. `POST /v1/attachments` to register the file and get a presigned R2 URL
38
+ * 2. `PUT` the body directly to R2 with the required headers
39
+ * 3. Poll `GET /v1/attachments/{id}` every `pollIntervalMs` until `status === 'ready'`
40
+ *
41
+ * Throws:
42
+ * - `BadRequestError` if `size_bytes` exceeds the 5 GB cap
43
+ * - `APIError` (`upload_failed`) if the R2 PUT returns non-2xx
44
+ * - `APIError` (`upload_failed`) if the server transitions to `status: failed`
45
+ * - `APIError` (`upload_timeout`) if `status` is still `uploading` after `maxPolls × pollIntervalMs`
46
+ */
47
+ async upload(file, metadata, opts = {}) {
48
+ const size = computeSize(file);
49
+ if (size > FIVE_GB) {
50
+ throw new APIError({
51
+ status: 413,
52
+ code: 'attachment_exceeds_storage_limit',
53
+ message: `Attachment is ${size} bytes; the server-enforced cap is ${FIVE_GB}`,
54
+ traceId: '',
55
+ requestId: ''
56
+ });
57
+ }
58
+ const created = await this.create({
59
+ filename: metadata.filename,
60
+ content_type: metadata.contentType,
61
+ size_bytes: size
62
+ }, opts);
63
+ // Build PUT headers via the Headers constructor so case-insensitive
64
+ // dedup happens for us — the server may return `required_headers` with
65
+ // any casing of `content-type` / `content-length`, and a plain
66
+ // `Record<string, string>` spread would emit duplicate-cased keys that
67
+ // some R2 deploys reject as `SignatureDoesNotMatch`. We trust the
68
+ // server's `required_headers` because R2 ignores non-AWS keys, so a
69
+ // compromised value cannot be used to inject auth into the upload.
70
+ const putHeaders = new Headers(created.required_headers);
71
+ putHeaders.set('Content-Type', metadata.contentType);
72
+ putHeaders.set('Content-Length', String(size));
73
+ let putResponse;
74
+ try {
75
+ putResponse = await this.client._externalFetch(created.upload_url, {
76
+ method: 'PUT',
77
+ headers: putHeaders,
78
+ body: file,
79
+ signal: opts.signal
80
+ });
81
+ }
82
+ catch (err) {
83
+ throw new APIConnectionError(err instanceof Error ? `R2 upload failed: ${err.message}` : 'R2 upload failed', { cause: err });
84
+ }
85
+ if (!putResponse.ok) {
86
+ throw new APIError({
87
+ status: putResponse.status,
88
+ code: 'upload_failed',
89
+ message: `R2 PUT failed with HTTP ${putResponse.status}`,
90
+ traceId: '',
91
+ requestId: ''
92
+ });
93
+ }
94
+ const pollIntervalMs = opts.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
95
+ const maxPolls = opts.maxPolls ?? DEFAULT_MAX_POLLS;
96
+ for (let i = 0; i < maxPolls; i++) {
97
+ await sleep(pollIntervalMs, opts.signal, 'Upload aborted');
98
+ const att = await this.get(created.id, opts);
99
+ if (att.status === 'ready')
100
+ return att;
101
+ if (att.status === 'failed') {
102
+ throw new APIError({
103
+ status: 422,
104
+ code: 'upload_failed',
105
+ message: `Attachment ${created.id} transitioned to status: failed`,
106
+ traceId: '',
107
+ requestId: ''
108
+ });
109
+ }
110
+ }
111
+ throw new APIError({
112
+ status: 504,
113
+ code: 'upload_timeout',
114
+ message: `Attachment ${created.id} did not become ready within ${maxPolls * pollIntervalMs}ms`,
115
+ traceId: '',
116
+ requestId: ''
117
+ });
118
+ }
119
+ }
120
+ //# sourceMappingURL=attachments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachments.js","sourceRoot":"","sources":["../../src/resources/attachments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAE3D,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAoBxC,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AACtC,MAAM,wBAAwB,GAAG,GAAG,CAAA;AACpC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAE5B,SAAS,WAAW,CAAC,IAAiB;IACpC,IAAI,IAAI,YAAY,UAAU;QAAE,OAAO,IAAI,CAAC,UAAU,CAAA;IACtD,IAAI,IAAI,YAAY,WAAW;QAAE,OAAO,IAAI,CAAC,UAAU,CAAA;IACvD,uEAAuE;IACvE,yCAAyC;IACzC,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,YAAY,IAAI;QAAE,OAAO,IAAI,CAAC,IAAI,CAAA;IACzE,MAAM,IAAI,SAAS,CAAC,mEAAmE,CAAC,CAAA;AAC1F,CAAC;AAED,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IACnD;;;;;;;;OAQG;IACH,MAAM,CAAC,IAA0B,EAAE,IAAqB;QACtD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAA2B,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IAC7F,CAAC;IAED,kFAAkF;IAClF,GAAG,CAAC,EAAU,EAAE,IAAqB;QACnC,O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AiC;oBAClE,OAAO,EAAE,EAAE;oBACX,SAAS,EAAE,EAAE;iBACd,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QACD,MAAM,IAAI,QAAQ,CAAC;YACjB,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,cAAc,OAAO,CAAC,EAAE,gCAAgC,QAAQ,GAAG,cAAc,IAAI;YAC9F,OAAO,EAAE,EAAE;YACX,SAAS,EAAE,EAAE;SACd,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import type { ISnapClient } from '../client.js';
2
+ export declare abstract class BaseResource {
3
+ protected readonly client: ISnapClient;
4
+ constructor(client: ISnapClient);
5
+ }
6
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/resources/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,8BAAsB,YAAY;IACpB,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW;gBAAnB,MAAM,EAAE,WAAW;CACnD"}
@@ -0,0 +1,7 @@
1
+ export class BaseResource {
2
+ client;
3
+ constructor(client) {
4
+ this.client = client;
5
+ }
6
+ }
7
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/resources/base.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,YAAY;IACD;IAA/B,YAA+B,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;IAAG,CAAC;CACvD"}
@@ -0,0 +1,15 @@
1
+ import type { components } from '../generated/openapi.js';
2
+ import type { RequestOptions } from '../types.js';
3
+ import { BaseResource } from './base.js';
4
+ export type ByodPairBody = components['schemas']['ByodPairBody'];
5
+ export type ByodPairResponse = components['schemas']['ByodPairResponse'];
6
+ export declare class ByodResource extends BaseResource {
7
+ /**
8
+ * `POST /v1/byod/pair` — mint a 5-minute activation code and presigned
9
+ * bridge installer URL for a customer-owned device. Returns 402 if the
10
+ * caller has no available BYOD slot. After the customer runs the bridge
11
+ * and pairs, `device.activate` mints the BYOD line server-side.
12
+ */
13
+ pair(body: ByodPairBody, opts?: RequestOptions): Promise<ByodPairResponse>;
14
+ }
15
+ //# sourceMappingURL=byod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"byod.d.ts","sourceRoot":"","sources":["../../src/resources/byod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,CAAA;AAChE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAA;AAExE,qBAAa,YAAa,SAAQ,YAAY;IAC5C;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAG3E"}
@@ -0,0 +1,13 @@
1
+ import { BaseResource } from './base.js';
2
+ export class ByodResource extends BaseResource {
3
+ /**
4
+ * `POST /v1/byod/pair` — mint a 5-minute activation code and presigned
5
+ * bridge installer URL for a customer-owned device. Returns 402 if the
6
+ * caller has no available BYOD slot. After the customer runs the bridge
7
+ * and pairs, `device.activate` mints the BYOD line server-side.
8
+ */
9
+ pair(body, opts) {
10
+ return this.client.request('POST', '/v1/byod/pair', body, opts);
11
+ }
12
+ }
13
+ //# sourceMappingURL=byod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"byod.js","sourceRoot":"","sources":["../../src/resources/byod.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAKxC,MAAM,OAAO,YAAa,SAAQ,YAAY;IAC5C;;;;;OAKG;IACH,IAAI,CAAC,IAAkB,EAAE,IAAqB;QAC5C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAmB,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACnF,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ import type { components, paths } from '../generated/openapi.js';
2
+ import type { RequestOptions } from '../types.js';
3
+ import { BaseResource } from './base.js';
4
+ export type ChatTypingStart = components['schemas']['ChatTypingStart'];
5
+ export type ChatTypingStop = components['schemas']['ChatTypingStop'];
6
+ export type ChatMarkRead = components['schemas']['ChatMarkRead'];
7
+ export type ShareContactCardResult = components['schemas']['ShareContactCardResult'];
8
+ export type TypingStartBody = NonNullable<paths['/v1/chats/{chat_id}/typing']['post']['requestBody']>['content']['application/json'];
9
+ export type MarkReadBody = NonNullable<paths['/v1/chats/{chat_id}/read']['post']['requestBody']>['content']['application/json'];
10
+ export type ShareContactCardBody = NonNullable<paths['/v1/chats/{chat_id}/share-contact-card']['post']['requestBody']>['content']['application/json'];
11
+ export declare class ChatsResource extends BaseResource {
12
+ /**
13
+ * `POST /v1/chats/{chat_id}/typing` — start an explicit typing indicator
14
+ * on a chat. The dots stay visible until `typingStop` is called or a
15
+ * message is sent (see contract §2.3 — explicit overrides
16
+ * `use_typing_indicator`).
17
+ */
18
+ typingStart(chatId: string, body: TypingStartBody, opts?: RequestOptions): Promise<ChatTypingStart>;
19
+ /** `DELETE /v1/chats/{chat_id}/typing` — stop the explicit typing indicator. */
20
+ typingStop(chatId: string, opts?: RequestOptions): Promise<ChatTypingStop>;
21
+ /** `POST /v1/chats/{chat_id}/read` — mark messages up to a given message as read. */
22
+ markRead(chatId: string, body: MarkReadBody, opts?: RequestOptions): Promise<ChatMarkRead>;
23
+ /**
24
+ * `POST /v1/chats/{chat_id}/share-contact-card` — share an Apple
25
+ * contact-card vCard attachment with the recipient.
26
+ */
27
+ shareContactCard(chatId: string, body: ShareContactCardBody, opts?: RequestOptions): Promise<ShareContactCardResult>;
28
+ }
29
+ //# sourceMappingURL=chats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chats.d.ts","sourceRoot":"","sources":["../../src/resources/chats.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,CAAA;AACtE,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAA;AACpE,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,CAAA;AAChE,MAAM,MAAM,sBAAsB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,wBAAwB,CAAC,CAAA;AAEpF,MAAM,MAAM,eAAe,GAAG,WAAW,CACvC,KAAK,CAAC,4BAA4B,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAC3D,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAA;AAChC,MAAM,MAAM,YAAY,GAAG,WAAW,CACpC,KAAK,CAAC,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CACzD,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAA;AAChC,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAC5C,KAAK,CAAC,wCAAwC,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CACvE,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAA;AAEhC,qBAAa,aAAc,SAAQ,YAAY;IAC7C;;;;;OAKG;IACH,WAAW,CACT,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,eAAe,EACrB,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAAC,eAAe,CAAC;IAS3B,gFAAgF;IAChF,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAS1E,qFAAqF;IACrF,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAS1F;;;OAGG;IACH,gBAAgB,CACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,oBAAoB,EAC1B,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAAC,sBAAsB,CAAC;CAQnC"}
@@ -0,0 +1,28 @@
1
+ import { BaseResource } from './base.js';
2
+ export class ChatsResource extends BaseResource {
3
+ /**
4
+ * `POST /v1/chats/{chat_id}/typing` — start an explicit typing indicator
5
+ * on a chat. The dots stay visible until `typingStop` is called or a
6
+ * message is sent (see contract §2.3 — explicit overrides
7
+ * `use_typing_indicator`).
8
+ */
9
+ typingStart(chatId, body, opts) {
10
+ return this.client.request('POST', `/v1/chats/${encodeURIComponent(chatId)}/typing`, body, opts);
11
+ }
12
+ /** `DELETE /v1/chats/{chat_id}/typing` — stop the explicit typing indicator. */
13
+ typingStop(chatId, opts) {
14
+ return this.client.request('DELETE', `/v1/chats/${encodeURIComponent(chatId)}/typing`, undefined, opts);
15
+ }
16
+ /** `POST /v1/chats/{chat_id}/read` — mark messages up to a given message as read. */
17
+ markRead(chatId, body, opts) {
18
+ return this.client.request('POST', `/v1/chats/${encodeURIComponent(chatId)}/read`, body, opts);
19
+ }
20
+ /**
21
+ * `POST /v1/chats/{chat_id}/share-contact-card` — share an Apple
22
+ * contact-card vCard attachment with the recipient.
23
+ */
24
+ shareContactCard(chatId, body, opts) {
25
+ return this.client.request('POST', `/v1/chats/${encodeURIComponent(chatId)}/share-contact-card`, body, opts);
26
+ }
27
+ }
28
+ //# sourceMappingURL=chats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chats.js","sourceRoot":"","sources":["../../src/resources/chats.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAiBxC,MAAM,OAAO,aAAc,SAAQ,YAAY;IAC7C;;;;;OAKG;IACH,WAAW,CACT,MAAc,EACd,IAAqB,EACrB,IAAqB;QAErB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,MAAM,EACN,aAAa,kBAAkB,CAAC,MAAM,CAAC,SAAS,EAChD,IAAI,EACJ,IAAI,CACL,CAAA;IACH,CAAC;IAED,gFAAgF;IAChF,UAAU,CAAC,MAAc,EAAE,IAAqB;QAC9C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,QAAQ,EACR,aAAa,kBAAkB,CAAC,MAAM,CAAC,SAAS,EAChD,SAAS,EACT,IAAI,CACL,CAAA;IACH,CAAC;IAED,qFAAqF;IACrF,QAAQ,CAAC,MAAc,EAAE,IAAkB,EAAE,IAAqB;QAChE,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,MAAM,EACN,aAAa,kBAAkB,CAAC,MAAM,CAAC,OAAO,EAC9C,IAAI,EACJ,IAAI,CACL,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,gBAAgB,CACd,MAAc,EACd,IAA0B,EAC1B,IAAqB;QAErB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,MAAM,EACN,aAAa,kBAAkB,CAAC,MAAM,CAAC,qBAAqB,EAC5D,IAAI,EACJ,IAAI,CACL,CAAA;IACH,CAAC;CACF"}
@@ -1,33 +1,70 @@
1
- import type { iSnapClient } from '../client.js';
2
- import type { Line, ListLinesParams, ListLinesResponse } from '../types.js';
3
- export declare class LinesResource {
4
- private client;
5
- constructor(client: iSnapClient);
1
+ import type { components, paths } from '../generated/openapi.js';
2
+ import type { RequestOptions } from '../types.js';
3
+ import { BaseResource } from './base.js';
4
+ export type Line = components['schemas']['Line'];
5
+ export type LineList = components['schemas']['LineList'];
6
+ export type MyLines = components['schemas']['MyLines'];
7
+ export type AssignLineBody = components['schemas']['AssignLine'];
8
+ export type TransferOwnershipBody = components['schemas']['TransferOwnership'];
9
+ export type PatchLineBody = components['schemas']['PatchLine'];
10
+ export type LineConfigPatch = components['schemas']['LineConfigPatch'];
11
+ export type LineConfigResponseData = components['schemas']['LineConfigResponseData'];
12
+ export type LineHealth = components['schemas']['LineHealth'];
13
+ export type QuotaSnapshot = components['schemas']['QuotaSnapshot'];
14
+ export type QueueResponseData = components['schemas']['QueueResponseData'];
15
+ export type ListLinesQuery = NonNullable<paths['/v1/lines']['get']['parameters']['query']>;
16
+ export type ListQueueQuery = NonNullable<paths['/v1/lines/{id}/queue']['get']['parameters']['query']>;
17
+ export declare class LinesResource extends BaseResource {
6
18
  /**
7
- * List phone lines with optional filters and pagination.
8
- *
9
- * @param params - Optional filters (type, area_code) and pagination
10
- * @returns Paginated list of lines
11
- *
12
- * @example
13
- * ```ts
14
- * const { lines } = await client.lines.list({ type: 'iphone', limit: 10 });
15
- * ```
19
+ * `GET /v1/lines` page/limit-paginated list of lines visible to the
20
+ * caller. Returns the wire-format envelope contents (`{lines, total,
21
+ * page, limit}`); not cursor-paginated like messages because the
22
+ * marketplace UI shows real "page X of Y" pagination.
16
23
  */
17
- list(params?: ListLinesParams): Promise<ListLinesResponse>;
24
+ list(query?: ListLinesQuery, opts?: RequestOptions): Promise<LineList>;
25
+ /** `GET /v1/lines/my` — list of lines owned by the calling account. */
26
+ listMine(opts?: RequestOptions): Promise<MyLines>;
27
+ /** `GET /v1/lines/{id}` — fetch a single line by ID or `line_<base62>` public ID. */
28
+ get(id: string, opts?: RequestOptions): Promise<Line>;
18
29
  /**
19
- * Retrieve a single line by ID.
20
- *
21
- * @param lineId - The line ID
22
- * @returns The line
23
- * @throws {iSnapError} If the line is not found
24
- *
25
- * @example
26
- * ```ts
27
- * const line = await client.lines.get('ln-abc123');
28
- * console.log(line.phone_number);
29
- * ```
30
+ * `POST /v1/lines/assign` atomically find an available line matching
31
+ * the requested billing tier (and optional area code), reserve it, and
32
+ * activate it on the calling account in a single round-trip.
30
33
  */
31
- get(lineId: string): Promise<Line>;
34
+ assign(body: AssignLineBody, opts?: RequestOptions): Promise<Line>;
35
+ /** `POST /v1/lines/{id}/reserve` — soft-hold a marketplace line for 15 minutes. */
36
+ reserve(id: string, opts?: RequestOptions): Promise<Line>;
37
+ /** `POST /v1/lines/{id}/activate` — flip a reserved line to `active`. */
38
+ activate(id: string, opts?: RequestOptions): Promise<Line>;
39
+ /** `POST /v1/lines/{id}/release` — release an active or reserved line back to the pool. */
40
+ release(id: string, opts?: RequestOptions): Promise<Line>;
41
+ /**
42
+ * `POST /v1/lines/{id}/transfer-ownership` — reassign a line to a
43
+ * different end-user account without re-pairing the underlying device.
44
+ */
45
+ transferOwnership(id: string, body: TransferOwnershipBody, opts?: RequestOptions): Promise<Line>;
46
+ /**
47
+ * `PATCH /v1/lines/{id}` — merge-patch the line's free-form metadata
48
+ * object. Null-valued keys delete those keys from the stored object.
49
+ */
50
+ patch(id: string, body: PatchLineBody, opts?: RequestOptions): Promise<Line>;
51
+ /** `GET /v1/lines/{id}/quota` — the line's current 5-bucket quota snapshot. */
52
+ quota(id: string, opts?: RequestOptions): Promise<QuotaSnapshot>;
53
+ /** `GET /v1/lines/{id}/queue` — pending scheduled / queued messages for the line. */
54
+ queue(id: string, query?: ListQueueQuery, opts?: RequestOptions): Promise<QueueResponseData>;
55
+ /**
56
+ * `GET /v1/lines/{id}/health` — BYOD-only line health snapshot. Throws
57
+ * `PermissionDeniedError` (`rental_health_not_exposed`) for rental
58
+ * tiers per contract §2.13.
59
+ */
60
+ health(id: string, opts?: RequestOptions): Promise<LineHealth>;
61
+ /** `GET /v1/lines/{id}/config` — effective per-line config (system defaults + overrides). */
62
+ getConfig(id: string, opts?: RequestOptions): Promise<LineConfigResponseData>;
63
+ /**
64
+ * `PATCH /v1/lines/{id}/config` — partial override of the line's
65
+ * config. BYOD callers can only lower limits / raise delays per
66
+ * contract §2.13.
67
+ */
68
+ updateConfig(id: string, body: LineConfigPatch, opts?: RequestOptions): Promise<LineConfigResponseData>;
32
69
  }
33
70
  //# sourceMappingURL=lines.d.ts.map