jmap-kit 0.0.0 → 1.0.2

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 (198) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +138 -3
  3. package/dist/src/capabilities/blob/blob.d.ts +83 -0
  4. package/dist/src/capabilities/blob/blob.js +98 -0
  5. package/dist/src/capabilities/blob/blob.js.map +1 -0
  6. package/dist/src/capabilities/blob/types.d.ts +212 -0
  7. package/dist/src/capabilities/blob/types.js +16 -0
  8. package/dist/src/capabilities/blob/types.js.map +1 -0
  9. package/dist/src/capabilities/blob-capability.d.ts +195 -0
  10. package/dist/src/capabilities/blob-capability.js +277 -0
  11. package/dist/src/capabilities/blob-capability.js.map +1 -0
  12. package/dist/src/capabilities/core/core.d.ts +47 -0
  13. package/dist/src/capabilities/core/core.js +59 -0
  14. package/dist/src/capabilities/core/core.js.map +1 -0
  15. package/dist/src/capabilities/core/types.d.ts +13 -0
  16. package/dist/src/capabilities/core/types.js +2 -0
  17. package/dist/src/capabilities/core/types.js.map +1 -0
  18. package/dist/src/capabilities/core-capability.d.ts +307 -0
  19. package/dist/src/capabilities/core-capability.js +344 -0
  20. package/dist/src/capabilities/core-capability.js.map +1 -0
  21. package/dist/src/capabilities/email/email.d.ts +124 -0
  22. package/dist/src/capabilities/email/email.js +136 -0
  23. package/dist/src/capabilities/email/email.js.map +1 -0
  24. package/dist/src/capabilities/email/types.d.ts +776 -0
  25. package/dist/src/capabilities/email/types.js +2 -0
  26. package/dist/src/capabilities/email/types.js.map +1 -0
  27. package/dist/src/capabilities/email-capability.d.ts +266 -0
  28. package/dist/src/capabilities/email-capability.js +241 -0
  29. package/dist/src/capabilities/email-capability.js.map +1 -0
  30. package/dist/src/capabilities/emailsubmission/emailsubmission.d.ts +95 -0
  31. package/dist/src/capabilities/emailsubmission/emailsubmission.js +107 -0
  32. package/dist/src/capabilities/emailsubmission/emailsubmission.js.map +1 -0
  33. package/dist/src/capabilities/emailsubmission/types.d.ts +256 -0
  34. package/dist/src/capabilities/emailsubmission/types.js +2 -0
  35. package/dist/src/capabilities/emailsubmission/types.js.map +1 -0
  36. package/dist/src/capabilities/example/example.d.ts +80 -0
  37. package/dist/src/capabilities/example/example.js +91 -0
  38. package/dist/src/capabilities/example/example.js.map +1 -0
  39. package/dist/src/capabilities/example/types.d.ts +33 -0
  40. package/dist/src/capabilities/example/types.js +2 -0
  41. package/dist/src/capabilities/example/types.js.map +1 -0
  42. package/dist/src/capabilities/identity/identity.d.ts +71 -0
  43. package/dist/src/capabilities/identity/identity.js +83 -0
  44. package/dist/src/capabilities/identity/identity.js.map +1 -0
  45. package/dist/src/capabilities/identity/types.d.ts +110 -0
  46. package/dist/src/capabilities/identity/types.js +2 -0
  47. package/dist/src/capabilities/identity/types.js.map +1 -0
  48. package/dist/src/capabilities/mailbox/mailbox.d.ts +91 -0
  49. package/dist/src/capabilities/mailbox/mailbox.js +103 -0
  50. package/dist/src/capabilities/mailbox/mailbox.js.map +1 -0
  51. package/dist/src/capabilities/mailbox/types.d.ts +248 -0
  52. package/dist/src/capabilities/mailbox/types.js +2 -0
  53. package/dist/src/capabilities/mailbox/types.js.map +1 -0
  54. package/dist/src/capabilities/maskedemail/maskedemail.d.ts +60 -0
  55. package/dist/src/capabilities/maskedemail/maskedemail.js +72 -0
  56. package/dist/src/capabilities/maskedemail/maskedemail.js.map +1 -0
  57. package/dist/src/capabilities/maskedemail/types.d.ts +67 -0
  58. package/dist/src/capabilities/maskedemail/types.js +4 -0
  59. package/dist/src/capabilities/maskedemail/types.js.map +1 -0
  60. package/dist/src/capabilities/maskedemail-capability.d.ts +112 -0
  61. package/dist/src/capabilities/maskedemail-capability.js +166 -0
  62. package/dist/src/capabilities/maskedemail-capability.js.map +1 -0
  63. package/dist/src/capabilities/searchsnippet/searchsnippet.d.ts +51 -0
  64. package/dist/src/capabilities/searchsnippet/searchsnippet.js +63 -0
  65. package/dist/src/capabilities/searchsnippet/searchsnippet.js.map +1 -0
  66. package/dist/src/capabilities/searchsnippet/types.d.ts +88 -0
  67. package/dist/src/capabilities/searchsnippet/types.js +2 -0
  68. package/dist/src/capabilities/searchsnippet/types.js.map +1 -0
  69. package/dist/src/capabilities/submission-capability.d.ts +89 -0
  70. package/dist/src/capabilities/submission-capability.js +75 -0
  71. package/dist/src/capabilities/submission-capability.js.map +1 -0
  72. package/dist/src/capabilities/thread/thread.d.ts +58 -0
  73. package/dist/src/capabilities/thread/thread.js +70 -0
  74. package/dist/src/capabilities/thread/thread.js.map +1 -0
  75. package/dist/src/capabilities/thread/types.d.ts +43 -0
  76. package/dist/src/capabilities/thread/types.js +2 -0
  77. package/dist/src/capabilities/thread/types.js.map +1 -0
  78. package/dist/src/capabilities/utils/assert-invocation-datatype.d.ts +7 -0
  79. package/dist/src/capabilities/utils/assert-invocation-datatype.js +13 -0
  80. package/dist/src/capabilities/utils/assert-invocation-datatype.js.map +1 -0
  81. package/dist/src/capabilities/utils/assert-invocation-method.d.ts +7 -0
  82. package/dist/src/capabilities/utils/assert-invocation-method.js +13 -0
  83. package/dist/src/capabilities/utils/assert-invocation-method.js.map +1 -0
  84. package/dist/src/capabilities/utils/assert-invocation.d.ts +7 -0
  85. package/dist/src/capabilities/utils/assert-invocation.js +22 -0
  86. package/dist/src/capabilities/utils/assert-invocation.js.map +1 -0
  87. package/dist/src/capabilities/utils/assert-non-nullish.d.ts +1 -0
  88. package/dist/src/capabilities/utils/assert-non-nullish.js +6 -0
  89. package/dist/src/capabilities/utils/assert-non-nullish.js.map +1 -0
  90. package/dist/src/capabilities/utils/create-readonly-account-validator.d.ts +49 -0
  91. package/dist/src/capabilities/utils/create-readonly-account-validator.js +80 -0
  92. package/dist/src/capabilities/utils/create-readonly-account-validator.js.map +1 -0
  93. package/dist/src/capabilities/vacationresponse/types.d.ts +100 -0
  94. package/dist/src/capabilities/vacationresponse/types.js +2 -0
  95. package/dist/src/capabilities/vacationresponse/types.js.map +1 -0
  96. package/dist/src/capabilities/vacationresponse/vacationresponse.d.ts +61 -0
  97. package/dist/src/capabilities/vacationresponse/vacationresponse.js +73 -0
  98. package/dist/src/capabilities/vacationresponse/vacationresponse.js.map +1 -0
  99. package/dist/src/capabilities/vacationresponse-capability.d.ts +65 -0
  100. package/dist/src/capabilities/vacationresponse-capability.js +68 -0
  101. package/dist/src/capabilities/vacationresponse-capability.js.map +1 -0
  102. package/dist/src/capability-registry/capability-registry.d.ts +148 -0
  103. package/dist/src/capability-registry/capability-registry.js +360 -0
  104. package/dist/src/capability-registry/capability-registry.js.map +1 -0
  105. package/dist/src/capability-registry/types.d.ts +385 -0
  106. package/dist/src/capability-registry/types.js +2 -0
  107. package/dist/src/capability-registry/types.js.map +1 -0
  108. package/dist/src/capability-registry/utils.d.ts +71 -0
  109. package/dist/src/capability-registry/utils.js +163 -0
  110. package/dist/src/capability-registry/utils.js.map +1 -0
  111. package/dist/src/common/registry.d.ts +366 -0
  112. package/dist/src/common/registry.js +321 -0
  113. package/dist/src/common/registry.js.map +1 -0
  114. package/dist/src/common/types.d.ts +338 -0
  115. package/dist/src/common/types.js +21 -0
  116. package/dist/src/common/types.js.map +1 -0
  117. package/dist/src/common/utils.d.ts +20 -0
  118. package/dist/src/common/utils.js +26 -0
  119. package/dist/src/common/utils.js.map +1 -0
  120. package/dist/src/index.d.ts +40 -0
  121. package/dist/src/index.js +33 -0
  122. package/dist/src/index.js.map +1 -0
  123. package/dist/src/invocation/arguments-proxy.d.ts +14 -0
  124. package/dist/src/invocation/arguments-proxy.js +37 -0
  125. package/dist/src/invocation/arguments-proxy.js.map +1 -0
  126. package/dist/src/invocation/error-invocation.d.ts +27 -0
  127. package/dist/src/invocation/error-invocation.js +39 -0
  128. package/dist/src/invocation/error-invocation.js.map +1 -0
  129. package/dist/src/invocation/invocation.d.ts +111 -0
  130. package/dist/src/invocation/invocation.js +158 -0
  131. package/dist/src/invocation/invocation.js.map +1 -0
  132. package/dist/src/invocation/result-reference.d.ts +86 -0
  133. package/dist/src/invocation/result-reference.js +118 -0
  134. package/dist/src/invocation/result-reference.js.map +1 -0
  135. package/dist/src/invocation/types.d.ts +637 -0
  136. package/dist/src/invocation/types.js +2 -0
  137. package/dist/src/invocation/types.js.map +1 -0
  138. package/dist/src/invocation/utils.d.ts +21 -0
  139. package/dist/src/invocation/utils.js +30 -0
  140. package/dist/src/invocation/utils.js.map +1 -0
  141. package/dist/src/invocation-factory/invocation-factory-manager.d.ts +20 -0
  142. package/dist/src/invocation-factory/invocation-factory-manager.js +50 -0
  143. package/dist/src/invocation-factory/invocation-factory-manager.js.map +1 -0
  144. package/dist/src/invocation-factory/invocation-list.d.ts +32 -0
  145. package/dist/src/invocation-factory/invocation-list.js +77 -0
  146. package/dist/src/invocation-factory/invocation-list.js.map +1 -0
  147. package/dist/src/invocation-factory/types.d.ts +11 -0
  148. package/dist/src/invocation-factory/types.js +2 -0
  149. package/dist/src/invocation-factory/types.js.map +1 -0
  150. package/dist/src/jmap-client/jmap-client.d.ts +252 -0
  151. package/dist/src/jmap-client/jmap-client.js +777 -0
  152. package/dist/src/jmap-client/jmap-client.js.map +1 -0
  153. package/dist/src/jmap-client/types.d.ts +427 -0
  154. package/dist/src/jmap-client/types.js +21 -0
  155. package/dist/src/jmap-client/types.js.map +1 -0
  156. package/dist/src/jmap-client/utils/abort-controller.d.ts +8 -0
  157. package/dist/src/jmap-client/utils/abort-controller.js +24 -0
  158. package/dist/src/jmap-client/utils/abort-controller.js.map +1 -0
  159. package/dist/src/jmap-client/utils/assert-connected.d.ts +7 -0
  160. package/dist/src/jmap-client/utils/assert-connected.js +11 -0
  161. package/dist/src/jmap-client/utils/assert-connected.js.map +1 -0
  162. package/dist/src/jmap-client/utils/deep-freeze.d.ts +7 -0
  163. package/dist/src/jmap-client/utils/deep-freeze.js +17 -0
  164. package/dist/src/jmap-client/utils/deep-freeze.js.map +1 -0
  165. package/dist/src/jmap-client/utils/emitter.d.ts +9 -0
  166. package/dist/src/jmap-client/utils/emitter.js +18 -0
  167. package/dist/src/jmap-client/utils/emitter.js.map +1 -0
  168. package/dist/src/jmap-client/utils/filter-session-capabilities.d.ts +22 -0
  169. package/dist/src/jmap-client/utils/filter-session-capabilities.js +40 -0
  170. package/dist/src/jmap-client/utils/filter-session-capabilities.js.map +1 -0
  171. package/dist/src/jmap-client/utils/jmap-request-error.d.ts +28 -0
  172. package/dist/src/jmap-client/utils/jmap-request-error.js +48 -0
  173. package/dist/src/jmap-client/utils/jmap-request-error.js.map +1 -0
  174. package/dist/src/jmap-client/utils/logger.d.ts +6 -0
  175. package/dist/src/jmap-client/utils/logger.js +22 -0
  176. package/dist/src/jmap-client/utils/logger.js.map +1 -0
  177. package/dist/src/jmap-client/utils/merge-headers.d.ts +11 -0
  178. package/dist/src/jmap-client/utils/merge-headers.js +40 -0
  179. package/dist/src/jmap-client/utils/merge-headers.js.map +1 -0
  180. package/dist/src/jmap-client/utils/template-utils.d.ts +27 -0
  181. package/dist/src/jmap-client/utils/template-utils.js +61 -0
  182. package/dist/src/jmap-client/utils/template-utils.js.map +1 -0
  183. package/dist/src/jmap-client/utils/track-utils.d.ts +19 -0
  184. package/dist/src/jmap-client/utils/track-utils.js +35 -0
  185. package/dist/src/jmap-client/utils/track-utils.js.map +1 -0
  186. package/dist/src/jmap-client/utils/transport.d.ts +12 -0
  187. package/dist/src/jmap-client/utils/transport.js +38 -0
  188. package/dist/src/jmap-client/utils/transport.js.map +1 -0
  189. package/dist/src/jmap-client/utils/validate-session.d.ts +19 -0
  190. package/dist/src/jmap-client/utils/validate-session.js +29 -0
  191. package/dist/src/jmap-client/utils/validate-session.js.map +1 -0
  192. package/dist/src/request-builder/request-builder.d.ts +95 -0
  193. package/dist/src/request-builder/request-builder.js +343 -0
  194. package/dist/src/request-builder/request-builder.js.map +1 -0
  195. package/dist/src/request-builder/types.d.ts +32 -0
  196. package/dist/src/request-builder/types.js +2 -0
  197. package/dist/src/request-builder/types.js.map +1 -0
  198. package/package.json +69 -3
@@ -0,0 +1,40 @@
1
+ import { deepFreeze } from "./deep-freeze.js";
2
+ /**
3
+ * Construct a new session object with invalid capabilities filtered out, then deep-freeze it.
4
+ *
5
+ * - Server-level failures cause the capability to be removed from `capabilities`,
6
+ * all `account.accountCapabilities`, and `primaryAccounts`.
7
+ * - Account-level failures cause the capability to be removed from that specific
8
+ * account's `accountCapabilities` and, if the account was the primary for that
9
+ * capability, from `primaryAccounts`.
10
+ *
11
+ * @param session The parsed (mutable) session from structural validation
12
+ * @param serverFailures Server capabilities that failed schema validation
13
+ * @param accountFailures Account capabilities that failed schema validation
14
+ * @returns A deeply frozen JMAPSession with invalid capabilities removed
15
+ */
16
+ export function filterSessionCapabilities(session, serverFailures, accountFailures) {
17
+ const invalidServerUris = new Set(serverFailures.map((f) => f.uri));
18
+ // Build lookup: accountId → Set<uri> for account-level failures
19
+ const accountFailuresByAccount = Map.groupBy(accountFailures, (f) => f.accountId);
20
+ const isInvalidAccountUri = (accountId, uri) => accountFailuresByAccount.get(accountId)?.some((f) => f.uri === uri) ?? false;
21
+ // Filter server capabilities
22
+ const capabilities = Object.fromEntries(Object.entries(session.capabilities).filter(([uri]) => !invalidServerUris.has(uri)));
23
+ // Filter account capabilities
24
+ const accounts = Object.fromEntries(Object.entries(session.accounts).map(([accountId, account]) => [
25
+ accountId,
26
+ {
27
+ ...account,
28
+ accountCapabilities: Object.fromEntries(Object.entries(account.accountCapabilities).filter(([uri]) => !invalidServerUris.has(uri) && !isInvalidAccountUri(accountId, uri))),
29
+ },
30
+ ]));
31
+ // Filter primaryAccounts
32
+ const primaryAccounts = Object.fromEntries(Object.entries(session.primaryAccounts).filter(([uri, accountId]) => !invalidServerUris.has(uri) && !isInvalidAccountUri(accountId, uri)));
33
+ return deepFreeze({
34
+ ...session,
35
+ capabilities,
36
+ accounts,
37
+ primaryAccounts,
38
+ });
39
+ }
40
+ //# sourceMappingURL=filter-session-capabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter-session-capabilities.js","sourceRoot":"","sources":["../../../../src/jmap-client/utils/filter-session-capabilities.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,yBAAyB,CACrC,OAA8B,EAC9B,cAAyC,EACzC,eAA6D;IAE7D,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAEpE,gEAAgE;IAChE,MAAM,wBAAwB,GAAG,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAClF,MAAM,mBAAmB,GAAG,CAAC,SAAiB,EAAE,GAAW,EAAW,EAAE,CACpE,wBAAwB,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC;IAEjF,6BAA6B;IAC7B,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CACnC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CACtF,CAAC;IAEF,8BAA8B;IAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAC/B,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;QAC3D,SAAS;QACT;YACI,GAAG,OAAO;YACV,mBAAmB,EAAE,MAAM,CAAC,WAAW,CACnC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,MAAM,CAC9C,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,GAAG,CAAC,CACjF,CACJ;SACJ;KACJ,CAAC,CACL,CAAC;IAEF,yBAAyB;IACzB,MAAM,eAAe,GAAG,MAAM,CAAC,WAAW,CACtC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,MAAM,CAC1C,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,GAAG,CAAC,CAC5F,CACJ,CAAC;IAEF,OAAO,UAAU,CAAC;QACd,GAAG,OAAO;QACV,YAAY;QACZ,QAAQ;QACR,eAAe;KAClB,CAAgB,CAAC;AACtB,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { JMAPRequestErrorTypes, ProblemDetails } from "../../common/types.js";
2
+ /**
3
+ * Represents a JMAP request-level error.
4
+ *
5
+ * JMAP request-level errors are returned as top-level error objects in the HTTP response,
6
+ * not as part of the methodResponses array. They typically indicate issues with the entire
7
+ * request, such as authentication failures, quota limits, invalid JSON, etc.
8
+ */
9
+ export declare class JMAPRequestError extends Error {
10
+ /**
11
+ * The type URI of the error.
12
+ */
13
+ readonly type: string;
14
+ /**
15
+ * The HTTP status code, if available.
16
+ */
17
+ readonly status?: number;
18
+ /**
19
+ * The raw error response object.
20
+ */
21
+ readonly problemDetails: ProblemDetails<JMAPRequestErrorTypes>;
22
+ /**
23
+ * Creates a new JMAP request error.
24
+ *
25
+ * @param error The error response from the JMAP server.
26
+ */
27
+ constructor(error: ProblemDetails<JMAPRequestErrorTypes>);
28
+ }
@@ -0,0 +1,48 @@
1
+ import { LIMIT, NOT_JSON, NOT_REQUEST, UNKNOWN_CAPABILITY } from "../../common/registry.js";
2
+ /**
3
+ * Default error messages for common JMAP request-level error types.
4
+ * These are used as fallbacks when no detail or title is provided.
5
+ */
6
+ const DEFAULT_ERROR_MESSAGES = {
7
+ [UNKNOWN_CAPABILITY]: "The request included a capability that the server does not support",
8
+ [NOT_JSON]: "The request was not valid JSON or had an incorrect Content-Type",
9
+ [NOT_REQUEST]: "The request did not match the required JMAP request format",
10
+ [LIMIT]: "The request exceeded a server-defined limit",
11
+ };
12
+ /**
13
+ * Represents a JMAP request-level error.
14
+ *
15
+ * JMAP request-level errors are returned as top-level error objects in the HTTP response,
16
+ * not as part of the methodResponses array. They typically indicate issues with the entire
17
+ * request, such as authentication failures, quota limits, invalid JSON, etc.
18
+ */
19
+ export class JMAPRequestError extends Error {
20
+ /**
21
+ * The type URI of the error.
22
+ */
23
+ type;
24
+ /**
25
+ * The HTTP status code, if available.
26
+ */
27
+ status;
28
+ /**
29
+ * The raw error response object.
30
+ */
31
+ problemDetails;
32
+ /**
33
+ * Creates a new JMAP request error.
34
+ *
35
+ * @param error The error response from the JMAP server.
36
+ */
37
+ constructor(error) {
38
+ // Use detail, title, default message for the error type, or finally the type URI itself
39
+ // in order of preference
40
+ const message = error.detail ?? error.title ?? DEFAULT_ERROR_MESSAGES[error.type] ?? error.type;
41
+ super(message);
42
+ this.type = error.type;
43
+ this.status = error.status;
44
+ this.problemDetails = error;
45
+ this.name = "JMAPRequestError";
46
+ }
47
+ }
48
+ //# sourceMappingURL=jmap-request-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jmap-request-error.js","sourceRoot":"","sources":["../../../../src/jmap-client/utils/jmap-request-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG5F;;;GAGG;AACH,MAAM,sBAAsB,GAAwD;IAChF,CAAC,kBAAkB,CAAC,EAAE,oEAAoE;IAC1F,CAAC,QAAQ,CAAC,EAAE,iEAAiE;IAC7E,CAAC,WAAW,CAAC,EAAE,4DAA4D;IAC3E,CAAC,KAAK,CAAC,EAAE,6CAA6C;CACzD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACvC;;OAEG;IACM,IAAI,CAAS;IAEtB;;OAEG;IACM,MAAM,CAAU;IAEzB;;OAEG;IACM,cAAc,CAAwC;IAE/D;;;;OAIG;IACH,YAAY,KAA4C;QACpD,wFAAwF;QACxF,yBAAyB;QACzB,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,KAAK,IAAI,sBAAsB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC;QAEhG,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACnC,CAAC;CACJ"}
@@ -0,0 +1,6 @@
1
+ import type { Logger } from "../types.js";
2
+ /**
3
+ * Create a safe logger that wraps an external logger implementation.
4
+ * All logger methods are wrapped in try/catch to prevent errors in the logger from affecting the application.
5
+ */
6
+ export declare function createLogger(getCurrentLogger: () => Logger | undefined): Logger;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Create a safe logger that wraps an external logger implementation.
3
+ * All logger methods are wrapped in try/catch to prevent errors in the logger from affecting the application.
4
+ */
5
+ export function createLogger(getCurrentLogger) {
6
+ const log = (method) => (message, ...optionalParameters) => {
7
+ try {
8
+ getCurrentLogger()?.[method](message, ...optionalParameters);
9
+ }
10
+ catch {
11
+ // Ignore any errors from the external logger
12
+ }
13
+ };
14
+ return {
15
+ log: log("log"),
16
+ info: log("info"),
17
+ warn: log("warn"),
18
+ error: log("error"),
19
+ debug: log("debug"),
20
+ };
21
+ }
22
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../src/jmap-client/utils/logger.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,gBAA0C;IACnE,MAAM,GAAG,GACL,CAAC,MAAoB,EAAgB,EAAE,CACvC,CAAC,OAAO,EAAE,GAAG,kBAAkB,EAAE,EAAE;QAC/B,IAAI,CAAC;YACD,gBAAgB,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,GAAI,kBAAgC,CAAC,CAAC;QAChF,CAAC;QAAC,MAAM,CAAC;YACL,6CAA6C;QACjD,CAAC;IACL,CAAC,CAAC;IACN,OAAO;QACH,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC;QACf,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC;QACjB,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC;QACjB,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC;QACnB,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC;KACtB,CAAC;AACN,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { HeadersInit } from "../types.js";
2
+ /**
3
+ * Merges two Headers objects, respecting known single-value and multi-value headers.
4
+ * If a single-value header appears in both, the value from the second Headers object will override the first.
5
+ * Multi-value headers will combine values from both Headers objects, ensuring no duplicates.
6
+ *
7
+ * @param h1 The first set of headers.
8
+ * @param h2 The second set of headers.
9
+ * @returns A new Headers object containing the merged headers.
10
+ */
11
+ export declare function mergeHeaders(h1: HeadersInit, h2: HeadersInit): Headers;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Merges two Headers objects, respecting known single-value and multi-value headers.
3
+ * If a single-value header appears in both, the value from the second Headers object will override the first.
4
+ * Multi-value headers will combine values from both Headers objects, ensuring no duplicates.
5
+ *
6
+ * @param h1 The first set of headers.
7
+ * @param h2 The second set of headers.
8
+ * @returns A new Headers object containing the merged headers.
9
+ */
10
+ export function mergeHeaders(h1, h2) {
11
+ const result = new Headers(h1);
12
+ const newHeaders = new Headers(h2);
13
+ // Known single-value headers (case-insensitive)
14
+ const singleValueRequestHeaders = new Set([
15
+ "authorization",
16
+ "content-disposition",
17
+ "content-encoding",
18
+ "content-language",
19
+ "content-location",
20
+ "content-type",
21
+ "if-match",
22
+ "if-modified-since",
23
+ "if-none-match",
24
+ "if-unmodified-since",
25
+ ]);
26
+ for (const [key, value] of newHeaders) {
27
+ const lowerKey = key.toLowerCase();
28
+ if (singleValueRequestHeaders.has(lowerKey)) {
29
+ result.set(key, value); // override
30
+ }
31
+ else {
32
+ const existing = new Set(result.get(key)?.split(/\s*,\s*/) ?? []);
33
+ const values = new Set(value.split(/\s*,\s*/));
34
+ const combined = existing.union(values);
35
+ result.set(key, Array.from(combined).join(", "));
36
+ }
37
+ }
38
+ return result;
39
+ }
40
+ //# sourceMappingURL=merge-headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-headers.js","sourceRoot":"","sources":["../../../../src/jmap-client/utils/merge-headers.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,EAAe,EAAE,EAAe;IACzD,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC;IAEnC,gDAAgD;IAChD,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC;QACtC,eAAe;QACf,qBAAqB;QACrB,kBAAkB;QAClB,kBAAkB;QAClB,kBAAkB;QAClB,cAAc;QACd,UAAU;QACV,mBAAmB;QACnB,eAAe;QACf,qBAAqB;KACxB,CAAC,CAAC;IAEH,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QAEnC,IAAI,yBAAyB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1C,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,WAAW;QACvC,CAAC;aAAM,CAAC;YACJ,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;YAClE,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;YAC/C,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACxC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { PrimitiveValue } from "url-template";
2
+ /**
3
+ * Extracts variable names from a URI template string.
4
+ *
5
+ * This extraction function is limited in its ability to handle malformed template strings,
6
+ * and it differs from how `url-template` handles such cases. However, JMAP defines that all
7
+ * URI Templates MUST be level 1 compliant, so this function should work correctly in all
8
+ * anticipated cases. It will, however, extract parameters from any valid template string
9
+ * from levels 1 to 4.
10
+ *
11
+ * @param template The URI template string from which to extract variables
12
+ * @returns A Set of variable names extracted from the template
13
+ */
14
+ export declare function extractTemplateVariables(template: string): Set<string>;
15
+ /**
16
+ * Expands a URI template with parameters, and ensures that any parameters not used in the template
17
+ * are appended as query parameters to the resulting URL.
18
+ *
19
+ * This behaviour is not technically part of the JMAP specification, but it has been observed that
20
+ * some JMAP servers (such as Fastmail) provide non-compliant templates that do not use all parameters,
21
+ * and are assumed to be expected as query string parameters.
22
+ *
23
+ * @param templateString The URI template string
24
+ * @param params An object containing parameter values to expand in the template
25
+ * @returns A URL object with the expanded template and any unused parameters as query params
26
+ */
27
+ export declare function expandUrlWithParams(templateString: string, params: Record<string, PrimitiveValue>): URL;
@@ -0,0 +1,61 @@
1
+ import { parseTemplate } from "url-template";
2
+ /**
3
+ * Extracts variable names from a URI template string.
4
+ *
5
+ * This extraction function is limited in its ability to handle malformed template strings,
6
+ * and it differs from how `url-template` handles such cases. However, JMAP defines that all
7
+ * URI Templates MUST be level 1 compliant, so this function should work correctly in all
8
+ * anticipated cases. It will, however, extract parameters from any valid template string
9
+ * from levels 1 to 4.
10
+ *
11
+ * @param template The URI template string from which to extract variables
12
+ * @returns A Set of variable names extracted from the template
13
+ */
14
+ export function extractTemplateVariables(template) {
15
+ const regex = /\{([^}]+)\}/g;
16
+ const operatorChars = new Set(["+", "#", ".", "/", ";", "?", "&", "=", ",", "!", "@", "|"]);
17
+ const variables = new Set();
18
+ let match;
19
+ while ((match = regex.exec(template)) !== null) {
20
+ const expression = match[1];
21
+ /* v8 ignore else -- @preserve */
22
+ if (expression && expression.length > 0) {
23
+ /* istanbul ignore next */
24
+ const [opChar = ""] = expression;
25
+ const varList = operatorChars.has(opChar) ? expression.slice(1) : expression;
26
+ varList.split(",").forEach((v) => {
27
+ // Remove explode modifier (*) and prefix modifier (:number)
28
+ const name = v.replace(/\*$|:\d+$/, "");
29
+ variables.add(name);
30
+ });
31
+ }
32
+ }
33
+ return variables;
34
+ }
35
+ /**
36
+ * Expands a URI template with parameters, and ensures that any parameters not used in the template
37
+ * are appended as query parameters to the resulting URL.
38
+ *
39
+ * This behaviour is not technically part of the JMAP specification, but it has been observed that
40
+ * some JMAP servers (such as Fastmail) provide non-compliant templates that do not use all parameters,
41
+ * and are assumed to be expected as query string parameters.
42
+ *
43
+ * @param templateString The URI template string
44
+ * @param params An object containing parameter values to expand in the template
45
+ * @returns A URL object with the expanded template and any unused parameters as query params
46
+ */
47
+ export function expandUrlWithParams(templateString, params) {
48
+ const template = parseTemplate(templateString);
49
+ const expandedUrl = template.expand(params);
50
+ const url = new URL(expandedUrl);
51
+ // Get the set of parameters that are in the template
52
+ const templateVars = extractTemplateVariables(templateString);
53
+ // For each parameter that's not in the template, add it as a query parameter
54
+ for (const [key, value] of Object.entries(params)) {
55
+ if (value !== null && !templateVars.has(key)) {
56
+ url.searchParams.set(key, `${value}`);
57
+ }
58
+ }
59
+ return url;
60
+ }
61
+ //# sourceMappingURL=template-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-utils.js","sourceRoot":"","sources":["../../../../src/jmap-client/utils/template-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAgB;IACrD,MAAM,KAAK,GAAG,cAAc,CAAC;IAC7B,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC5F,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IACpC,IAAI,KAA6B,CAAC;IAElC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC7C,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5B,iCAAiC;QACjC,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtC,0BAA0B;YAC1B,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,UAAU,CAAC;YACjC,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;YAE7E,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC7B,4DAA4D;gBAC5D,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;gBACxC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CAAC,cAAsB,EAAE,MAAsC;IAC9F,MAAM,QAAQ,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IAEjC,qDAAqD;IACrD,MAAM,YAAY,GAAG,wBAAwB,CAAC,cAAc,CAAC,CAAC;IAE9D,6EAA6E;IAC7E,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAChD,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3C,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QAC1C,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Adds a promise to the given Set while it is pending, and automatically removes it once the promise settles (resolves or rejects).
3
+ * Returns a promise that resolves or rejects with the same value as the input promise.
4
+ *
5
+ * @template T The resolved value type of the promise.
6
+ * @param set Set to track the pending promise.
7
+ * @param promise The promise to track.
8
+ * @returns A promise that resolves or rejects with the same value as the input promise.
9
+ */
10
+ export declare function trackPromise<T>(set: Set<Promise<unknown>>, promise: Promise<T>): Promise<T>;
11
+ /**
12
+ * Adds an AbortController to the given Set and automatically removes it when it is aborted.
13
+ * Returns the same AbortController instance for chaining or further use.
14
+ *
15
+ * @param set Set to track the AbortController.
16
+ * @param controller The AbortController to track.
17
+ * @returns The same AbortController instance.
18
+ */
19
+ export declare function trackAbortController(set: Set<AbortController>, controller: AbortController): AbortController;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Adds a promise to the given Set while it is pending, and automatically removes it once the promise settles (resolves or rejects).
3
+ * Returns a promise that resolves or rejects with the same value as the input promise.
4
+ *
5
+ * @template T The resolved value type of the promise.
6
+ * @param set Set to track the pending promise.
7
+ * @param promise The promise to track.
8
+ * @returns A promise that resolves or rejects with the same value as the input promise.
9
+ */
10
+ export async function trackPromise(set, promise) {
11
+ set.add(promise);
12
+ try {
13
+ return await promise;
14
+ }
15
+ finally {
16
+ set.delete(promise);
17
+ }
18
+ }
19
+ /**
20
+ * Adds an AbortController to the given Set and automatically removes it when it is aborted.
21
+ * Returns the same AbortController instance for chaining or further use.
22
+ *
23
+ * @param set Set to track the AbortController.
24
+ * @param controller The AbortController to track.
25
+ * @returns The same AbortController instance.
26
+ */
27
+ export function trackAbortController(set, controller) {
28
+ set.add(controller);
29
+ const cleanup = () => {
30
+ set.delete(controller);
31
+ };
32
+ controller.signal.addEventListener("abort", cleanup, { once: true });
33
+ return controller;
34
+ }
35
+ //# sourceMappingURL=track-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"track-utils.js","sourceRoot":"","sources":["../../../../src/jmap-client/utils/track-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAI,GAA0B,EAAE,OAAmB;IACjF,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACjB,IAAI,CAAC;QACD,OAAO,MAAM,OAAO,CAAC;IACzB,CAAC;YAAS,CAAC;QACP,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAyB,EAAE,UAA2B;IACvF,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACpB,MAAM,OAAO,GAAG,GAAG,EAAE;QACjB,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC3B,CAAC,CAAC;IACF,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACrE,OAAO,UAAU,CAAC;AACtB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Transport } from "../types.js";
2
+ /**
3
+ * Wrap a Transport implementation so that all requests and abort controllers are tracked in the provided Sets.
4
+ * Each request promise is added to the set and removed when settled.
5
+ * Each AbortController is tracked and removed when aborted.
6
+ *
7
+ * @param transport The original Transport implementation.
8
+ * @param activeRequests The Set to track all active (not yet settled) request promises.
9
+ * @param activeAbortControllers The Set to track all active (not yet aborted) AbortControllers.
10
+ * @returns A new Transport that tracks all requests and abort controllers.
11
+ */
12
+ export declare function createTransport(transport: Transport, activeRequests: Set<Promise<unknown>>, activeAbortControllers: Set<AbortController>): Transport;
@@ -0,0 +1,38 @@
1
+ import { createAbortController } from "./abort-controller.js";
2
+ import { trackAbortController, trackPromise } from "./track-utils.js";
3
+ /**
4
+ * Wrap a Transport implementation so that all requests and abort controllers are tracked in the provided Sets.
5
+ * Each request promise is added to the set and removed when settled.
6
+ * Each AbortController is tracked and removed when aborted.
7
+ *
8
+ * @param transport The original Transport implementation.
9
+ * @param activeRequests The Set to track all active (not yet settled) request promises.
10
+ * @param activeAbortControllers The Set to track all active (not yet aborted) AbortControllers.
11
+ * @returns A new Transport that tracks all requests and abort controllers.
12
+ */
13
+ export function createTransport(transport, activeRequests, activeAbortControllers) {
14
+ function createChainedAbortController(externalSignal) {
15
+ const controller = createAbortController(externalSignal);
16
+ return trackAbortController(activeAbortControllers, controller);
17
+ }
18
+ function wrapMethod(method) {
19
+ return (url, options = {}) => {
20
+ const controller = createChainedAbortController(options.signal);
21
+ const promise = (async () => {
22
+ try {
23
+ return await transport[method](url, { ...options, signal: controller.signal });
24
+ }
25
+ finally {
26
+ activeAbortControllers.delete(controller);
27
+ }
28
+ })();
29
+ return trackPromise(activeRequests, promise);
30
+ };
31
+ }
32
+ const wrapped = {
33
+ get: wrapMethod("get"),
34
+ post: wrapMethod("post"),
35
+ };
36
+ return wrapped;
37
+ }
38
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../../src/jmap-client/utils/transport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEtE;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAC3B,SAAoB,EACpB,cAAqC,EACrC,sBAA4C;IAE5C,SAAS,4BAA4B,CAAC,cAA4B;QAC9D,MAAM,UAAU,GAAG,qBAAqB,CAAC,cAAc,CAAC,CAAC;QACzD,OAAO,oBAAoB,CAAC,sBAAsB,EAAE,UAAU,CAAC,CAAC;IACpE,CAAC;IAOD,SAAS,UAAU,CAAI,MAAsB;QACzC,OAAO,CACH,GAAiB,EACjB,UAA2E,EAAE,EACnE,EAAE;YACZ,MAAM,UAAU,GAAG,4BAA4B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAChE,MAAM,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE;gBACxB,IAAI,CAAC;oBACD,OAAO,MAAM,SAAS,CAAC,MAAM,CAAC,CAAI,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;gBACtF,CAAC;wBAAS,CAAC;oBACP,sBAAsB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAC9C,CAAC;YACL,CAAC,CAAC,EAAE,CAAC;YACL,OAAO,YAAY,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC,CAAC;IACN,CAAC;IAED,MAAM,OAAO,GAAc;QACvB,GAAG,EAAE,UAAU,CAAC,KAAK,CAAC;QACtB,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC;KAC3B,CAAC;IAEF,OAAO,OAAO,CAAC;AACnB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { JMAPSessionFromSchema, Logger } from "../types.js";
2
+ /**
3
+ * Parse and validate a JMAP session response using the JMAPSessionSchema.
4
+ *
5
+ * Performs structural validation only (required top-level fields, account shape,
6
+ * presence of the Core server capability key). Capability-specific content
7
+ * validation is performed separately via the capability registry's
8
+ * `validateServerCapabilities()` and `validateAccountCapabilities()` methods.
9
+ *
10
+ * The returned session object is **not** frozen — callers should apply
11
+ * `deepFreeze()` after capability validation has had a chance to strip
12
+ * invalid capabilities from the session.
13
+ *
14
+ * @param jsonResponse The raw JSON response from the server to be validated.
15
+ * @param logger Logger instance used to log validation errors.
16
+ * @returns The parsed and structurally validated session object (mutable).
17
+ * @throws Error if the response does not conform to the JMAPSessionSchema.
18
+ */
19
+ export declare function parseAndValidateJMAPSession(jsonResponse: unknown, logger: Logger): JMAPSessionFromSchema;
@@ -0,0 +1,29 @@
1
+ import { JMAPSessionSchema } from "../types.js";
2
+ /**
3
+ * Parse and validate a JMAP session response using the JMAPSessionSchema.
4
+ *
5
+ * Performs structural validation only (required top-level fields, account shape,
6
+ * presence of the Core server capability key). Capability-specific content
7
+ * validation is performed separately via the capability registry's
8
+ * `validateServerCapabilities()` and `validateAccountCapabilities()` methods.
9
+ *
10
+ * The returned session object is **not** frozen — callers should apply
11
+ * `deepFreeze()` after capability validation has had a chance to strip
12
+ * invalid capabilities from the session.
13
+ *
14
+ * @param jsonResponse The raw JSON response from the server to be validated.
15
+ * @param logger Logger instance used to log validation errors.
16
+ * @returns The parsed and structurally validated session object (mutable).
17
+ * @throws Error if the response does not conform to the JMAPSessionSchema.
18
+ */
19
+ export function parseAndValidateJMAPSession(jsonResponse, logger) {
20
+ const parseResult = JMAPSessionSchema.safeParse(jsonResponse);
21
+ if (!parseResult.success) {
22
+ logger.error("Invalid JMAP session response", { error: parseResult.error });
23
+ throw new Error("Invalid JMAP session response", {
24
+ cause: parseResult.error,
25
+ });
26
+ }
27
+ return parseResult.data;
28
+ }
29
+ //# sourceMappingURL=validate-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-session.js","sourceRoot":"","sources":["../../../../src/jmap-client/utils/validate-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,2BAA2B,CAAC,YAAqB,EAAE,MAAc;IAC7E,MAAM,WAAW,GAAG,iBAAiB,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAC9D,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,+BAA+B,EAAE;YAC7C,KAAK,EAAE,WAAW,CAAC,KAAK;SAC3B,CAAC,CAAC;IACP,CAAC;IACD,OAAO,WAAW,CAAC,IAAI,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,95 @@
1
+ import type { Id, IdMap, JMAPCapability, JMAPRequest } from "../common/types.js";
2
+ import type { Invocation } from "../invocation/invocation.js";
3
+ import type { BaseInvocationArgs } from "../invocation/types.js";
4
+ import type { ClientContext, JMAPClientInterface } from "../jmap-client/types.js";
5
+ export declare class RequestBuilder {
6
+ #private;
7
+ constructor(client: JMAPClientInterface<RequestBuilder>, { logger }: ClientContext);
8
+ /** Get the set of unique URIs that will be included in the `using` parameter of the JMAP request */
9
+ get using(): Set<JMAPCapability>;
10
+ /** Get the collection of method calls that are included in this request */
11
+ get methodCalls(): readonly Invocation<BaseInvocationArgs>[];
12
+ /** Get the map of created IDs that are included in this request */
13
+ get createdIds(): Readonly<Record<string, string>> | null;
14
+ /** Get the map of client-specified creation IDs to server-assigned IDs */
15
+ get idMap(): Map<symbol, Id>;
16
+ /** Get the reverse map of server-assigned IDs to client-specified creation IDs */
17
+ get reverseIdMap(): Map<Id, symbol>;
18
+ /**
19
+ * Add a method call to the request. All methods must be unique. If the method
20
+ * already exists in the request, it will not be added again.
21
+ *
22
+ * @param method The method call to add to the request
23
+ * @returns The invocation builder instance to allow for method chaining
24
+ * @throws Error if the method's capability is not registered with the client
25
+ * @throws Error if adding this method would exceed the server's maxCallsInRequest limit
26
+ * @throws AggregateError if the invocation validation fails
27
+ */
28
+ add(method: Invocation<BaseInvocationArgs>): this;
29
+ /**
30
+ * Remove a method call from the request. If the method does not exist in the
31
+ * request, this method will do nothing.
32
+ *
33
+ * @param method The method call to remove from the request
34
+ * @returns The invocation builder instance to allow for method chaining
35
+ */
36
+ remove(method: Invocation<BaseInvocationArgs>): this;
37
+ /**
38
+ * Add the map of client specified creation IDs to server assigned IDs, to be included in the request.
39
+ *
40
+ * This may be invoked with an empty object to initialise the createdIds for the first request,
41
+ * or with a map of client-specified creation IDs to the server-assigned IDs that were obtained from a
42
+ * previous response.
43
+ *
44
+ * @param createdIds The map of client-specified creation IDs to the server assigned IDs
45
+ * @returns The invocation builder instance to allow for method chaining
46
+ */
47
+ addCreatedIds(createdIds: IdMap): this;
48
+ /**
49
+ * Reset the map of creation ids to remove any that had been previously added.
50
+ * After invoking this, the createdIds property will will be omitted from the request.
51
+ */
52
+ clearCreatedIds(): this;
53
+ /**
54
+ * Build the JMAP request object from the current state of the builder.
55
+ *
56
+ * This will generate unique IDs for each method call, and resolve any
57
+ * client-specified creation IDs to server-assigned IDs if they were provided.
58
+ *
59
+ * @param idPrefix The prefix to use for generated IDs (default is "id_")
60
+ * @returns The constructed JMAP request object
61
+ * @throws AggregateError if the pre-build validation fails
62
+ */
63
+ build(idPrefix?: string): JMAPRequest;
64
+ /**
65
+ * Serialise the request for sending as a request body.
66
+ * By default, returns a JSON string, but can be extended to support other formats.
67
+ *
68
+ * @returns The serialised request (string, Blob, ArrayBuffer, etc.)
69
+ * @throws AggregateError if the pre-serialization validation fails
70
+ * @throws AggregateError if the post-serialization validation fails
71
+ */
72
+ serialize(): Promise<{
73
+ body: string | Blob | ArrayBuffer | File;
74
+ headers: Headers;
75
+ }>;
76
+ /**
77
+ * Send this request to the JMAP server using the associated client.
78
+ *
79
+ * @param signal Optional AbortSignal to cancel the request.
80
+ * @returns The parsed response from the server.
81
+ */
82
+ send(signal?: AbortSignal): Promise<{
83
+ methodResponses: import("../invocation-factory/invocation-list.js").InvocationList<BaseInvocationArgs>;
84
+ sessionState: string;
85
+ createdIds: IdMap;
86
+ }>;
87
+ toJSON(): JMAPRequest;
88
+ /**
89
+ * Validate all invocations currently in the request.
90
+ *
91
+ * @returns A Promise resolving to the invocation builder instance
92
+ * @throws AggregateError if any invocation validation fails
93
+ */
94
+ validateInvocations(): Promise<this>;
95
+ }