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.
- package/LICENSE +21 -0
- package/README.md +138 -3
- package/dist/src/capabilities/blob/blob.d.ts +83 -0
- package/dist/src/capabilities/blob/blob.js +98 -0
- package/dist/src/capabilities/blob/blob.js.map +1 -0
- package/dist/src/capabilities/blob/types.d.ts +212 -0
- package/dist/src/capabilities/blob/types.js +16 -0
- package/dist/src/capabilities/blob/types.js.map +1 -0
- package/dist/src/capabilities/blob-capability.d.ts +195 -0
- package/dist/src/capabilities/blob-capability.js +277 -0
- package/dist/src/capabilities/blob-capability.js.map +1 -0
- package/dist/src/capabilities/core/core.d.ts +47 -0
- package/dist/src/capabilities/core/core.js +59 -0
- package/dist/src/capabilities/core/core.js.map +1 -0
- package/dist/src/capabilities/core/types.d.ts +13 -0
- package/dist/src/capabilities/core/types.js +2 -0
- package/dist/src/capabilities/core/types.js.map +1 -0
- package/dist/src/capabilities/core-capability.d.ts +307 -0
- package/dist/src/capabilities/core-capability.js +344 -0
- package/dist/src/capabilities/core-capability.js.map +1 -0
- package/dist/src/capabilities/email/email.d.ts +124 -0
- package/dist/src/capabilities/email/email.js +136 -0
- package/dist/src/capabilities/email/email.js.map +1 -0
- package/dist/src/capabilities/email/types.d.ts +776 -0
- package/dist/src/capabilities/email/types.js +2 -0
- package/dist/src/capabilities/email/types.js.map +1 -0
- package/dist/src/capabilities/email-capability.d.ts +266 -0
- package/dist/src/capabilities/email-capability.js +241 -0
- package/dist/src/capabilities/email-capability.js.map +1 -0
- package/dist/src/capabilities/emailsubmission/emailsubmission.d.ts +95 -0
- package/dist/src/capabilities/emailsubmission/emailsubmission.js +107 -0
- package/dist/src/capabilities/emailsubmission/emailsubmission.js.map +1 -0
- package/dist/src/capabilities/emailsubmission/types.d.ts +256 -0
- package/dist/src/capabilities/emailsubmission/types.js +2 -0
- package/dist/src/capabilities/emailsubmission/types.js.map +1 -0
- package/dist/src/capabilities/example/example.d.ts +80 -0
- package/dist/src/capabilities/example/example.js +91 -0
- package/dist/src/capabilities/example/example.js.map +1 -0
- package/dist/src/capabilities/example/types.d.ts +33 -0
- package/dist/src/capabilities/example/types.js +2 -0
- package/dist/src/capabilities/example/types.js.map +1 -0
- package/dist/src/capabilities/identity/identity.d.ts +71 -0
- package/dist/src/capabilities/identity/identity.js +83 -0
- package/dist/src/capabilities/identity/identity.js.map +1 -0
- package/dist/src/capabilities/identity/types.d.ts +110 -0
- package/dist/src/capabilities/identity/types.js +2 -0
- package/dist/src/capabilities/identity/types.js.map +1 -0
- package/dist/src/capabilities/mailbox/mailbox.d.ts +91 -0
- package/dist/src/capabilities/mailbox/mailbox.js +103 -0
- package/dist/src/capabilities/mailbox/mailbox.js.map +1 -0
- package/dist/src/capabilities/mailbox/types.d.ts +248 -0
- package/dist/src/capabilities/mailbox/types.js +2 -0
- package/dist/src/capabilities/mailbox/types.js.map +1 -0
- package/dist/src/capabilities/maskedemail/maskedemail.d.ts +60 -0
- package/dist/src/capabilities/maskedemail/maskedemail.js +72 -0
- package/dist/src/capabilities/maskedemail/maskedemail.js.map +1 -0
- package/dist/src/capabilities/maskedemail/types.d.ts +67 -0
- package/dist/src/capabilities/maskedemail/types.js +4 -0
- package/dist/src/capabilities/maskedemail/types.js.map +1 -0
- package/dist/src/capabilities/maskedemail-capability.d.ts +112 -0
- package/dist/src/capabilities/maskedemail-capability.js +166 -0
- package/dist/src/capabilities/maskedemail-capability.js.map +1 -0
- package/dist/src/capabilities/searchsnippet/searchsnippet.d.ts +51 -0
- package/dist/src/capabilities/searchsnippet/searchsnippet.js +63 -0
- package/dist/src/capabilities/searchsnippet/searchsnippet.js.map +1 -0
- package/dist/src/capabilities/searchsnippet/types.d.ts +88 -0
- package/dist/src/capabilities/searchsnippet/types.js +2 -0
- package/dist/src/capabilities/searchsnippet/types.js.map +1 -0
- package/dist/src/capabilities/submission-capability.d.ts +89 -0
- package/dist/src/capabilities/submission-capability.js +75 -0
- package/dist/src/capabilities/submission-capability.js.map +1 -0
- package/dist/src/capabilities/thread/thread.d.ts +58 -0
- package/dist/src/capabilities/thread/thread.js +70 -0
- package/dist/src/capabilities/thread/thread.js.map +1 -0
- package/dist/src/capabilities/thread/types.d.ts +43 -0
- package/dist/src/capabilities/thread/types.js +2 -0
- package/dist/src/capabilities/thread/types.js.map +1 -0
- package/dist/src/capabilities/utils/assert-invocation-datatype.d.ts +7 -0
- package/dist/src/capabilities/utils/assert-invocation-datatype.js +13 -0
- package/dist/src/capabilities/utils/assert-invocation-datatype.js.map +1 -0
- package/dist/src/capabilities/utils/assert-invocation-method.d.ts +7 -0
- package/dist/src/capabilities/utils/assert-invocation-method.js +13 -0
- package/dist/src/capabilities/utils/assert-invocation-method.js.map +1 -0
- package/dist/src/capabilities/utils/assert-invocation.d.ts +7 -0
- package/dist/src/capabilities/utils/assert-invocation.js +22 -0
- package/dist/src/capabilities/utils/assert-invocation.js.map +1 -0
- package/dist/src/capabilities/utils/assert-non-nullish.d.ts +1 -0
- package/dist/src/capabilities/utils/assert-non-nullish.js +6 -0
- package/dist/src/capabilities/utils/assert-non-nullish.js.map +1 -0
- package/dist/src/capabilities/utils/create-readonly-account-validator.d.ts +49 -0
- package/dist/src/capabilities/utils/create-readonly-account-validator.js +80 -0
- package/dist/src/capabilities/utils/create-readonly-account-validator.js.map +1 -0
- package/dist/src/capabilities/vacationresponse/types.d.ts +100 -0
- package/dist/src/capabilities/vacationresponse/types.js +2 -0
- package/dist/src/capabilities/vacationresponse/types.js.map +1 -0
- package/dist/src/capabilities/vacationresponse/vacationresponse.d.ts +61 -0
- package/dist/src/capabilities/vacationresponse/vacationresponse.js +73 -0
- package/dist/src/capabilities/vacationresponse/vacationresponse.js.map +1 -0
- package/dist/src/capabilities/vacationresponse-capability.d.ts +65 -0
- package/dist/src/capabilities/vacationresponse-capability.js +68 -0
- package/dist/src/capabilities/vacationresponse-capability.js.map +1 -0
- package/dist/src/capability-registry/capability-registry.d.ts +148 -0
- package/dist/src/capability-registry/capability-registry.js +360 -0
- package/dist/src/capability-registry/capability-registry.js.map +1 -0
- package/dist/src/capability-registry/types.d.ts +385 -0
- package/dist/src/capability-registry/types.js +2 -0
- package/dist/src/capability-registry/types.js.map +1 -0
- package/dist/src/capability-registry/utils.d.ts +71 -0
- package/dist/src/capability-registry/utils.js +163 -0
- package/dist/src/capability-registry/utils.js.map +1 -0
- package/dist/src/common/registry.d.ts +366 -0
- package/dist/src/common/registry.js +321 -0
- package/dist/src/common/registry.js.map +1 -0
- package/dist/src/common/types.d.ts +338 -0
- package/dist/src/common/types.js +21 -0
- package/dist/src/common/types.js.map +1 -0
- package/dist/src/common/utils.d.ts +20 -0
- package/dist/src/common/utils.js +26 -0
- package/dist/src/common/utils.js.map +1 -0
- package/dist/src/index.d.ts +40 -0
- package/dist/src/index.js +33 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/invocation/arguments-proxy.d.ts +14 -0
- package/dist/src/invocation/arguments-proxy.js +37 -0
- package/dist/src/invocation/arguments-proxy.js.map +1 -0
- package/dist/src/invocation/error-invocation.d.ts +27 -0
- package/dist/src/invocation/error-invocation.js +39 -0
- package/dist/src/invocation/error-invocation.js.map +1 -0
- package/dist/src/invocation/invocation.d.ts +111 -0
- package/dist/src/invocation/invocation.js +158 -0
- package/dist/src/invocation/invocation.js.map +1 -0
- package/dist/src/invocation/result-reference.d.ts +86 -0
- package/dist/src/invocation/result-reference.js +118 -0
- package/dist/src/invocation/result-reference.js.map +1 -0
- package/dist/src/invocation/types.d.ts +637 -0
- package/dist/src/invocation/types.js +2 -0
- package/dist/src/invocation/types.js.map +1 -0
- package/dist/src/invocation/utils.d.ts +21 -0
- package/dist/src/invocation/utils.js +30 -0
- package/dist/src/invocation/utils.js.map +1 -0
- package/dist/src/invocation-factory/invocation-factory-manager.d.ts +20 -0
- package/dist/src/invocation-factory/invocation-factory-manager.js +50 -0
- package/dist/src/invocation-factory/invocation-factory-manager.js.map +1 -0
- package/dist/src/invocation-factory/invocation-list.d.ts +32 -0
- package/dist/src/invocation-factory/invocation-list.js +77 -0
- package/dist/src/invocation-factory/invocation-list.js.map +1 -0
- package/dist/src/invocation-factory/types.d.ts +11 -0
- package/dist/src/invocation-factory/types.js +2 -0
- package/dist/src/invocation-factory/types.js.map +1 -0
- package/dist/src/jmap-client/jmap-client.d.ts +252 -0
- package/dist/src/jmap-client/jmap-client.js +777 -0
- package/dist/src/jmap-client/jmap-client.js.map +1 -0
- package/dist/src/jmap-client/types.d.ts +427 -0
- package/dist/src/jmap-client/types.js +21 -0
- package/dist/src/jmap-client/types.js.map +1 -0
- package/dist/src/jmap-client/utils/abort-controller.d.ts +8 -0
- package/dist/src/jmap-client/utils/abort-controller.js +24 -0
- package/dist/src/jmap-client/utils/abort-controller.js.map +1 -0
- package/dist/src/jmap-client/utils/assert-connected.d.ts +7 -0
- package/dist/src/jmap-client/utils/assert-connected.js +11 -0
- package/dist/src/jmap-client/utils/assert-connected.js.map +1 -0
- package/dist/src/jmap-client/utils/deep-freeze.d.ts +7 -0
- package/dist/src/jmap-client/utils/deep-freeze.js +17 -0
- package/dist/src/jmap-client/utils/deep-freeze.js.map +1 -0
- package/dist/src/jmap-client/utils/emitter.d.ts +9 -0
- package/dist/src/jmap-client/utils/emitter.js +18 -0
- package/dist/src/jmap-client/utils/emitter.js.map +1 -0
- package/dist/src/jmap-client/utils/filter-session-capabilities.d.ts +22 -0
- package/dist/src/jmap-client/utils/filter-session-capabilities.js +40 -0
- package/dist/src/jmap-client/utils/filter-session-capabilities.js.map +1 -0
- package/dist/src/jmap-client/utils/jmap-request-error.d.ts +28 -0
- package/dist/src/jmap-client/utils/jmap-request-error.js +48 -0
- package/dist/src/jmap-client/utils/jmap-request-error.js.map +1 -0
- package/dist/src/jmap-client/utils/logger.d.ts +6 -0
- package/dist/src/jmap-client/utils/logger.js +22 -0
- package/dist/src/jmap-client/utils/logger.js.map +1 -0
- package/dist/src/jmap-client/utils/merge-headers.d.ts +11 -0
- package/dist/src/jmap-client/utils/merge-headers.js +40 -0
- package/dist/src/jmap-client/utils/merge-headers.js.map +1 -0
- package/dist/src/jmap-client/utils/template-utils.d.ts +27 -0
- package/dist/src/jmap-client/utils/template-utils.js +61 -0
- package/dist/src/jmap-client/utils/template-utils.js.map +1 -0
- package/dist/src/jmap-client/utils/track-utils.d.ts +19 -0
- package/dist/src/jmap-client/utils/track-utils.js +35 -0
- package/dist/src/jmap-client/utils/track-utils.js.map +1 -0
- package/dist/src/jmap-client/utils/transport.d.ts +12 -0
- package/dist/src/jmap-client/utils/transport.js +38 -0
- package/dist/src/jmap-client/utils/transport.js.map +1 -0
- package/dist/src/jmap-client/utils/validate-session.d.ts +19 -0
- package/dist/src/jmap-client/utils/validate-session.js +29 -0
- package/dist/src/jmap-client/utils/validate-session.js.map +1 -0
- package/dist/src/request-builder/request-builder.d.ts +95 -0
- package/dist/src/request-builder/request-builder.js +343 -0
- package/dist/src/request-builder/request-builder.js.map +1 -0
- package/dist/src/request-builder/types.d.ts +32 -0
- package/dist/src/request-builder/types.js +2 -0
- package/dist/src/request-builder/types.js.map +1 -0
- package/package.json +69 -3
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { CORE_CAPABILITY_URI } from "../common/registry.js";
|
|
2
|
+
import { idGenerator } from "../common/utils.js";
|
|
3
|
+
const ID_PREFIX = "id_";
|
|
4
|
+
export class RequestBuilder {
|
|
5
|
+
#client;
|
|
6
|
+
#logger;
|
|
7
|
+
// readonly #emitter: EventEmitterFn;
|
|
8
|
+
#methods = new Set();
|
|
9
|
+
#createdIds = null;
|
|
10
|
+
#idMap = new Map();
|
|
11
|
+
constructor(client, { logger }) {
|
|
12
|
+
this.#client = client;
|
|
13
|
+
this.#logger = logger;
|
|
14
|
+
}
|
|
15
|
+
/** Get the set of unique URIs that will be included in the `using` parameter of the JMAP request */
|
|
16
|
+
get using() {
|
|
17
|
+
// RFC 8620 errata (EID 6606) clarifies that core MUST be present in `using` for every request.
|
|
18
|
+
return new Set([CORE_CAPABILITY_URI, ...[...this.#methods].map((invocation) => invocation.uri)]);
|
|
19
|
+
}
|
|
20
|
+
/** Get the collection of method calls that are included in this request */
|
|
21
|
+
get methodCalls() {
|
|
22
|
+
return Object.freeze([...this.#methods]);
|
|
23
|
+
}
|
|
24
|
+
/** Get the map of created IDs that are included in this request */
|
|
25
|
+
get createdIds() {
|
|
26
|
+
return this.#createdIds ? Object.freeze(Object.fromEntries(this.#createdIds)) : null;
|
|
27
|
+
}
|
|
28
|
+
/** Get the map of client-specified creation IDs to server-assigned IDs */
|
|
29
|
+
get idMap() {
|
|
30
|
+
const entries = [...this.#idMap];
|
|
31
|
+
return new Map(entries);
|
|
32
|
+
}
|
|
33
|
+
/** Get the reverse map of server-assigned IDs to client-specified creation IDs */
|
|
34
|
+
get reverseIdMap() {
|
|
35
|
+
const entries = [...this.#idMap].map(([symbol, id]) => [id, symbol]);
|
|
36
|
+
return new Map(entries);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Add a method call to the request. All methods must be unique. If the method
|
|
40
|
+
* already exists in the request, it will not be added again.
|
|
41
|
+
*
|
|
42
|
+
* @param method The method call to add to the request
|
|
43
|
+
* @returns The invocation builder instance to allow for method chaining
|
|
44
|
+
* @throws Error if the method's capability is not registered with the client
|
|
45
|
+
* @throws Error if adding this method would exceed the server's maxCallsInRequest limit
|
|
46
|
+
* @throws AggregateError if the invocation validation fails
|
|
47
|
+
*/
|
|
48
|
+
add(method) {
|
|
49
|
+
// Ensure the method's capability is registered with the client
|
|
50
|
+
if (!this.#client.capabilityRegistry.has(method.uri)) {
|
|
51
|
+
this.#logger.error(`Cannot add method: Unknown capability '${method.uri}'`);
|
|
52
|
+
throw new Error(`Unknown capability: ${method.uri}`);
|
|
53
|
+
}
|
|
54
|
+
// Check if the method is already in the set
|
|
55
|
+
if (this.#methods.has(method)) {
|
|
56
|
+
this.#logger.debug(`Method ${method.name} already exists in request, skipping`);
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
// Check if adding this method would exceed the server's maxCallsInRequest limit
|
|
60
|
+
const serverCapabilities = this.#client.serverCapabilities;
|
|
61
|
+
if (serverCapabilities) {
|
|
62
|
+
const { maxCallsInRequest } = serverCapabilities[CORE_CAPABILITY_URI];
|
|
63
|
+
if (this.#methods.size + 1 > maxCallsInRequest) {
|
|
64
|
+
this.#logger.error(`Cannot add method ${method.name}: Would exceed server limit of ${maxCallsInRequest} method calls (current: ${this.#methods.size})`);
|
|
65
|
+
throw new Error(`Cannot add method: Request would exceed the server limit of ${maxCallsInRequest} method calls.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
this.#logger.debug(`Adding method ${method.name} to request (${this.#methods.size + 1} total methods)`);
|
|
69
|
+
this.#methods.add(method);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Remove a method call from the request. If the method does not exist in the
|
|
74
|
+
* request, this method will do nothing.
|
|
75
|
+
*
|
|
76
|
+
* @param method The method call to remove from the request
|
|
77
|
+
* @returns The invocation builder instance to allow for method chaining
|
|
78
|
+
*/
|
|
79
|
+
remove(method) {
|
|
80
|
+
if (this.#methods.has(method)) {
|
|
81
|
+
this.#logger.debug(`Removing method ${method.name} from request`);
|
|
82
|
+
this.#methods.delete(method);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.#logger.debug(`Method ${method.name} not found in request, nothing to remove`);
|
|
86
|
+
}
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Add the map of client specified creation IDs to server assigned IDs, to be included in the request.
|
|
91
|
+
*
|
|
92
|
+
* This may be invoked with an empty object to initialise the createdIds for the first request,
|
|
93
|
+
* or with a map of client-specified creation IDs to the server-assigned IDs that were obtained from a
|
|
94
|
+
* previous response.
|
|
95
|
+
*
|
|
96
|
+
* @param createdIds The map of client-specified creation IDs to the server assigned IDs
|
|
97
|
+
* @returns The invocation builder instance to allow for method chaining
|
|
98
|
+
*/
|
|
99
|
+
addCreatedIds(createdIds) {
|
|
100
|
+
const entries = Object.entries(createdIds);
|
|
101
|
+
this.#logger.debug(`Adding ${entries.length} created IDs to request`);
|
|
102
|
+
this.#createdIds ??= new Map();
|
|
103
|
+
for (const [key, value] of entries) {
|
|
104
|
+
this.#createdIds.set(key, value);
|
|
105
|
+
}
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Reset the map of creation ids to remove any that had been previously added.
|
|
110
|
+
* After invoking this, the createdIds property will will be omitted from the request.
|
|
111
|
+
*/
|
|
112
|
+
clearCreatedIds() {
|
|
113
|
+
const previousCount = this.#createdIds?.size ?? 0;
|
|
114
|
+
if (previousCount > 0) {
|
|
115
|
+
this.#logger.debug(`Clearing ${previousCount} created IDs from request`);
|
|
116
|
+
}
|
|
117
|
+
this.#createdIds = null;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Build the JMAP request object from the current state of the builder.
|
|
122
|
+
*
|
|
123
|
+
* This will generate unique IDs for each method call, and resolve any
|
|
124
|
+
* client-specified creation IDs to server-assigned IDs if they were provided.
|
|
125
|
+
*
|
|
126
|
+
* @param idPrefix The prefix to use for generated IDs (default is "id_")
|
|
127
|
+
* @returns The constructed JMAP request object
|
|
128
|
+
* @throws AggregateError if the pre-build validation fails
|
|
129
|
+
*/
|
|
130
|
+
build(idPrefix = ID_PREFIX) {
|
|
131
|
+
this.#logger.debug(`Building JMAP request with ${this.#methods.size} method calls`);
|
|
132
|
+
const generateId = idGenerator(idPrefix);
|
|
133
|
+
// Map invocations to request format with IDs
|
|
134
|
+
const methodCalls = this.methodCalls.map((invocation) => {
|
|
135
|
+
const newId = generateId.next().value;
|
|
136
|
+
this.#idMap.set(invocation.id, newId);
|
|
137
|
+
return invocation.resolve(newId, (id) => this.#idMap.get(id));
|
|
138
|
+
});
|
|
139
|
+
const createdIds = this.#createdIds ? Object.fromEntries(this.#createdIds) : null;
|
|
140
|
+
// Create initial request object
|
|
141
|
+
const request = {
|
|
142
|
+
using: [...this.using],
|
|
143
|
+
methodCalls,
|
|
144
|
+
...(createdIds && {
|
|
145
|
+
createdIds,
|
|
146
|
+
}),
|
|
147
|
+
};
|
|
148
|
+
this.#logger.debug(`Built JMAP request using capabilities: ${[...this.using].join(", ")}`);
|
|
149
|
+
return request;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Serialise the request for sending as a request body.
|
|
153
|
+
* By default, returns a JSON string, but can be extended to support other formats.
|
|
154
|
+
*
|
|
155
|
+
* @returns The serialised request (string, Blob, ArrayBuffer, etc.)
|
|
156
|
+
* @throws AggregateError if the pre-serialization validation fails
|
|
157
|
+
* @throws AggregateError if the post-serialization validation fails
|
|
158
|
+
*/
|
|
159
|
+
async serialize() {
|
|
160
|
+
this.#logger.info(`Serialising JMAP request with ${this.#methods.size} method calls`);
|
|
161
|
+
// Validate all invocations
|
|
162
|
+
await this.validateInvocations();
|
|
163
|
+
// Build the request first
|
|
164
|
+
const builtRequest = this.build();
|
|
165
|
+
// Run pre-build validators
|
|
166
|
+
let { valid, errors = [] } = await this.#validateLifecycleHook("pre-build", builtRequest);
|
|
167
|
+
if (!valid) {
|
|
168
|
+
this.#logger.error(`Pre-build validation failed with ${errors.length} errors`);
|
|
169
|
+
throw new AggregateError(errors, "Pre-build validation failed");
|
|
170
|
+
}
|
|
171
|
+
// Apply pre-serialization transformers
|
|
172
|
+
const transformedRequest = await this.#transformBuild(builtRequest);
|
|
173
|
+
// Run pre-serialization validators
|
|
174
|
+
({ valid, errors = [] } = await this.#validateLifecycleHook("pre-serialization", transformedRequest));
|
|
175
|
+
if (!valid) {
|
|
176
|
+
this.#logger.error(`Pre-serialization validation failed with ${errors.length} errors`);
|
|
177
|
+
throw new AggregateError(errors, `Pre-serialization validation failed`);
|
|
178
|
+
}
|
|
179
|
+
// Serialise to JSON
|
|
180
|
+
const body = JSON.stringify(transformedRequest);
|
|
181
|
+
const serializedData = {
|
|
182
|
+
body,
|
|
183
|
+
headers: new Headers({
|
|
184
|
+
"Content-Type": "application/json",
|
|
185
|
+
}),
|
|
186
|
+
};
|
|
187
|
+
const transformedSerialization = await this.#transformSerialization(serializedData);
|
|
188
|
+
// Run post-serialization validators on the serialised string
|
|
189
|
+
({ valid, errors = [] } = await this.#validateSerialization(transformedSerialization));
|
|
190
|
+
if (!valid) {
|
|
191
|
+
this.#logger.error(`Post-serialization validation failed with ${errors.length} errors`);
|
|
192
|
+
throw new AggregateError(errors, `Post-serialization validation failed`);
|
|
193
|
+
}
|
|
194
|
+
this.#logger.debug(`Successfully serialised JMAP request (${body.length} characters)`);
|
|
195
|
+
return transformedSerialization;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Send this request to the JMAP server using the associated client.
|
|
199
|
+
*
|
|
200
|
+
* @param signal Optional AbortSignal to cancel the request.
|
|
201
|
+
* @returns The parsed response from the server.
|
|
202
|
+
*/
|
|
203
|
+
async send(signal) {
|
|
204
|
+
this.#logger.info(`Sending JMAP request with ${this.#methods.size} method ${this.#methods.size === 1 ? "call" : "calls"}`);
|
|
205
|
+
return this.#client.sendAPIRequest(this, signal);
|
|
206
|
+
}
|
|
207
|
+
toJSON() {
|
|
208
|
+
return this.build();
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Validate all invocations currently in the request.
|
|
212
|
+
*
|
|
213
|
+
* @returns A Promise resolving to the invocation builder instance
|
|
214
|
+
* @throws AggregateError if any invocation validation fails
|
|
215
|
+
*/
|
|
216
|
+
async validateInvocations() {
|
|
217
|
+
this.#logger.debug(`Validating ${this.methodCalls.length} invocations`);
|
|
218
|
+
// Validate all invocations. Aggregate the errors from all of them before throwing
|
|
219
|
+
const validationErrors = [];
|
|
220
|
+
for (const invocation of this.methodCalls) {
|
|
221
|
+
const { valid, errors = [] } = await this.#validateInvocation(invocation);
|
|
222
|
+
if (!valid) {
|
|
223
|
+
this.#logger.warn(`Validation failed for ${invocation.name}: ${errors.length} errors`);
|
|
224
|
+
validationErrors.push(...errors);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (validationErrors.length > 0) {
|
|
228
|
+
this.#logger.error(`Invocation validation failed with ${validationErrors.length} total errors`);
|
|
229
|
+
throw new AggregateError(validationErrors, `Invocation validation failed`);
|
|
230
|
+
}
|
|
231
|
+
this.#logger.debug(`All invocations validated successfully`);
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Validates an invocation against registered validators
|
|
236
|
+
*
|
|
237
|
+
* @param invocation The invocation to validate
|
|
238
|
+
*/
|
|
239
|
+
async #validateInvocation(invocation) {
|
|
240
|
+
// Only run validation if the client is connected (i.e., has serverCapabilities and accounts)
|
|
241
|
+
const serverCapabilities = this.#client.serverCapabilities;
|
|
242
|
+
const accounts = this.#client.accounts;
|
|
243
|
+
if (!serverCapabilities || !accounts)
|
|
244
|
+
return { valid: true };
|
|
245
|
+
const registry = this.#client.capabilityRegistry;
|
|
246
|
+
// Use the unified executeValidators method with the invocation context
|
|
247
|
+
return registry.executeValidators({
|
|
248
|
+
hook: "invocation",
|
|
249
|
+
context: {
|
|
250
|
+
invocation,
|
|
251
|
+
serverCapabilities,
|
|
252
|
+
accounts,
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Validates a request against registered lifecycle hook validators
|
|
258
|
+
*
|
|
259
|
+
* @param hook The lifecycle hook to validate for
|
|
260
|
+
* @param data The request data to validate
|
|
261
|
+
*/
|
|
262
|
+
async #validateLifecycleHook(hook, data) {
|
|
263
|
+
// Only run validation if the client is connected (i.e., has serverCapabilities and accounts)
|
|
264
|
+
const serverCapabilities = this.#client.serverCapabilities;
|
|
265
|
+
const accounts = this.#client.accounts;
|
|
266
|
+
if (!serverCapabilities || !accounts)
|
|
267
|
+
return { valid: true };
|
|
268
|
+
const registry = this.#client.capabilityRegistry;
|
|
269
|
+
const executionContext = {
|
|
270
|
+
hook,
|
|
271
|
+
context: {
|
|
272
|
+
data,
|
|
273
|
+
serverCapabilities,
|
|
274
|
+
accounts,
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
return registry.executeValidators(executionContext);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Validates serialised request data against registered post-serialization validators
|
|
281
|
+
*
|
|
282
|
+
* @param data The serialised data
|
|
283
|
+
*/
|
|
284
|
+
async #validateSerialization(data) {
|
|
285
|
+
// Only run validation if the client is connected (i.e., has serverCapabilities and accounts)
|
|
286
|
+
const serverCapabilities = this.#client.serverCapabilities;
|
|
287
|
+
const accounts = this.#client.accounts;
|
|
288
|
+
if (!serverCapabilities || !accounts)
|
|
289
|
+
return { valid: true };
|
|
290
|
+
const registry = this.#client.capabilityRegistry;
|
|
291
|
+
// Use the unified executeValidators method with the post-serialization context
|
|
292
|
+
return registry.executeValidators({
|
|
293
|
+
hook: "post-serialization",
|
|
294
|
+
context: {
|
|
295
|
+
data,
|
|
296
|
+
serverCapabilities,
|
|
297
|
+
accounts,
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Applies transformation plugins for the pre-serialization hook
|
|
303
|
+
*
|
|
304
|
+
* @param hook The lifecycle hook to transform for
|
|
305
|
+
* @param data The request data to transform
|
|
306
|
+
*/
|
|
307
|
+
async #transformBuild(data) {
|
|
308
|
+
const serverCapabilities = this.#client.serverCapabilities;
|
|
309
|
+
const accounts = this.#client.accounts;
|
|
310
|
+
if (!serverCapabilities || !accounts)
|
|
311
|
+
return data;
|
|
312
|
+
const registry = this.#client.capabilityRegistry;
|
|
313
|
+
const executionContext = {
|
|
314
|
+
context: {
|
|
315
|
+
data,
|
|
316
|
+
serverCapabilities,
|
|
317
|
+
accounts,
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
return await registry.executeBuildTransformers(executionContext);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Applies transformation plugins for the post-serialization hook
|
|
324
|
+
*
|
|
325
|
+
* @param data The serialised data to transform
|
|
326
|
+
*/
|
|
327
|
+
async #transformSerialization(data) {
|
|
328
|
+
const serverCapabilities = this.#client.serverCapabilities;
|
|
329
|
+
const accounts = this.#client.accounts;
|
|
330
|
+
if (!serverCapabilities || !accounts)
|
|
331
|
+
return data;
|
|
332
|
+
const registry = this.#client.capabilityRegistry;
|
|
333
|
+
const executionContext = {
|
|
334
|
+
context: {
|
|
335
|
+
data,
|
|
336
|
+
serverCapabilities,
|
|
337
|
+
accounts,
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
return await registry.executeSerializationTransformers(executionContext);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
//# sourceMappingURL=request-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-builder.js","sourceRoot":"","sources":["../../../src/request-builder/request-builder.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKjD,MAAM,SAAS,GAAG,KAAK,CAAC;AAExB,MAAM,OAAO,cAAc;IACd,OAAO,CAAsC;IAE7C,OAAO,CAAS;IACzB,qCAAqC;IAE5B,QAAQ,GAAG,IAAI,GAAG,EAAkC,CAAC;IAC9D,WAAW,GAA+B,IAAI,CAAC;IACtC,MAAM,GAAG,IAAI,GAAG,EAAc,CAAC;IAExC,YAAY,MAA2C,EAAE,EAAE,MAAM,EAAiB;QAC9E,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED,oGAAoG;IACpG,IAAI,KAAK;QACL,+FAA+F;QAC/F,OAAO,IAAI,GAAG,CAAC,CAAC,mBAAmB,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC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I,CAAC,kBAAkB,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QAElD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC;QAEjD,MAAM,gBAAgB,GAAsD;YACxE,OAAO,EAAE;gBACL,IAAI;gBACJ,kBAAkB;gBAClB,QAAQ;aACX;SACJ,CAAC;QAEF,OAAO,MAAM,QAAQ,CAAC,gCAAgC,CAAC,gBAAgB,CAAC,CAAC;IAC7E,CAAC;CACJ"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility type that makes all properties of T optional recursively
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type to make partially optional
|
|
5
|
+
* @template Depth - Maximum recursion depth (default: 5)
|
|
6
|
+
* @returns A new type where all properties of T are optional, recursively down to the specified
|
|
7
|
+
* depth for nested objects
|
|
8
|
+
*/
|
|
9
|
+
export type DeepPartial<T, Depth extends number = 5> = [Depth] extends [0] ? T : T extends object ? {
|
|
10
|
+
[P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial<U, Decrement<Depth>>[] : Extract<T[P], object> extends object ? DeepPartial<T[P], Decrement<Depth>> : T[P];
|
|
11
|
+
} : T;
|
|
12
|
+
/**
|
|
13
|
+
* Utility type to build a tuple of length L
|
|
14
|
+
* @template L - The desired length of the tuple. The length must be >= 0.
|
|
15
|
+
* TypeScript limits tuples to a maximum length of 999.
|
|
16
|
+
* @template T - The type of each element in the tuple (default: unknown)
|
|
17
|
+
* @returns A tuple of length L with elements of type T, or never if L is negative.
|
|
18
|
+
*/
|
|
19
|
+
export type BuildTuple<L extends number, T extends unknown[] = []> = T["length"] extends L ? T : IsNegative<L> extends true ? never : BuildTuple<L, [unknown, ...T]>;
|
|
20
|
+
/**
|
|
21
|
+
* Utility type to check if a number is negative
|
|
22
|
+
* @template N - The number to check
|
|
23
|
+
* @returns true if N is negative, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
export type IsNegative<N extends number> = `${N}` extends `-${string}` ? true : false;
|
|
26
|
+
/**
|
|
27
|
+
* Utility type to decrement a number by 1
|
|
28
|
+
* @template N - The positive number to decrement. If N is 0, it returns never.
|
|
29
|
+
* If N is a negative number, it returns never.
|
|
30
|
+
* @returns The decremented number, or never if N is negative or 0.
|
|
31
|
+
*/
|
|
32
|
+
export type Decrement<N extends number> = IsNegative<N> extends true ? never : BuildTuple<N> extends [infer _, ...infer Rest] ? Rest["length"] : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/request-builder/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jmap-kit",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"packageManager": "yarn@4.13.0",
|
|
5
5
|
"author": "Lachlan Hunt <lachlan.hunt@lachy.id.au> (https://lachy.id.au)",
|
|
6
|
+
"description": "A comprehensive, type-safe JMAP SDK for building JMAP-based client applications",
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
@@ -19,5 +20,70 @@
|
|
|
19
20
|
"rfc8621",
|
|
20
21
|
"typescript",
|
|
21
22
|
"client"
|
|
22
|
-
]
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"format:check": "prettier --check .",
|
|
26
|
+
"lint": "eslint .",
|
|
27
|
+
"test": "vitest",
|
|
28
|
+
"test:coverage": "vitest run --coverage",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"build": "tsc --project tsconfig.build.json",
|
|
31
|
+
"bundle": "rollup -c",
|
|
32
|
+
"bundle:standalone": "rollup -c rollup.config.standalone.js",
|
|
33
|
+
"bundle:analyse": "NODE_ENV=production rollup -c",
|
|
34
|
+
"size-check": "yarn bundle && ls -lh dist/jmap-kit.bundle.js",
|
|
35
|
+
"docs": "typedoc"
|
|
36
|
+
},
|
|
37
|
+
"type": "module",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/src/index.d.ts",
|
|
41
|
+
"default": "./dist/src/index.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"main": "./dist/src/index.js",
|
|
46
|
+
"types": "./dist/src/index.d.ts",
|
|
47
|
+
"files": [
|
|
48
|
+
"dist/src/**",
|
|
49
|
+
"!dist/src/**/*.test.*",
|
|
50
|
+
"!dist/src/**/*.typestest.*",
|
|
51
|
+
"!dist/src/**/test-utils.*"
|
|
52
|
+
],
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@standard-schema/spec": "^1.1.0",
|
|
55
|
+
"p-limit": "^7.3.0",
|
|
56
|
+
"url-template": "^3.1.1",
|
|
57
|
+
"zod": "^4.3.6"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@eslint/js": "^9.39.3",
|
|
61
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
62
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
63
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
64
|
+
"@types/node": "^24.10.13",
|
|
65
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
66
|
+
"@vitest/runner": "^4.0.18",
|
|
67
|
+
"@vitest/snapshot": "^4.0.18",
|
|
68
|
+
"dotenv": "^17.3.1",
|
|
69
|
+
"eslint": "^9.39.3",
|
|
70
|
+
"eslint-config-prettier": "^10.1.8",
|
|
71
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
72
|
+
"eslint-plugin-import": "^2.32.0",
|
|
73
|
+
"globals": "^16.5.0",
|
|
74
|
+
"husky": "^9.1.7",
|
|
75
|
+
"lint-staged": "^16.2.7",
|
|
76
|
+
"prettier": "3.8.1",
|
|
77
|
+
"rollup": "^4.59.0",
|
|
78
|
+
"rollup-plugin-visualizer": "^7.0.0",
|
|
79
|
+
"tsx": "^4.21.0",
|
|
80
|
+
"typedoc": "^0.28.15",
|
|
81
|
+
"typescript": "^5.9.3",
|
|
82
|
+
"typescript-eslint": "^8.56.1",
|
|
83
|
+
"vitest": "^4.0.18"
|
|
84
|
+
},
|
|
85
|
+
"lint-staged": {
|
|
86
|
+
"*.{ts,tsx,js,mjs}": "eslint --fix",
|
|
87
|
+
"**/*": "prettier --write --ignore-unknown"
|
|
88
|
+
}
|
|
23
89
|
}
|