@mountaya/client 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +104 -0
- package/LICENCE.fr.txt +280 -0
- package/LICENSE.txt +262 -0
- package/README.md +1260 -2
- package/dist/admin/index.cjs +3521 -0
- package/dist/admin/index.cjs.map +1 -0
- package/dist/admin/index.d.cts +1070 -0
- package/dist/admin/index.d.ts +1070 -0
- package/dist/admin/index.js +301 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/browser.cjs +8073 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +106 -0
- package/dist/browser.d.ts +106 -0
- package/dist/browser.js +53 -0
- package/dist/browser.js.map +1 -0
- package/dist/chunk-BM526BHG.js +342 -0
- package/dist/chunk-BM526BHG.js.map +1 -0
- package/dist/chunk-D2YEVTG7.js +327 -0
- package/dist/chunk-D2YEVTG7.js.map +1 -0
- package/dist/chunk-OHKVUREN.js +3500 -0
- package/dist/chunk-OHKVUREN.js.map +1 -0
- package/dist/chunk-TDTK2L5H.js +3842 -0
- package/dist/chunk-TDTK2L5H.js.map +1 -0
- package/dist/coreOperations.gen-BMYPoBbz.d.ts +1760 -0
- package/dist/coreOperations.gen-BxX5xRxw.d.cts +1760 -0
- package/dist/errors-B-GqAtQv.d.cts +75960 -0
- package/dist/errors-B-GqAtQv.d.ts +75960 -0
- package/dist/events/index.cjs +1972 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.d.cts +781 -0
- package/dist/events/index.d.ts +781 -0
- package/dist/events/index.js +826 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.cjs +8072 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/operations.gen-CvTyzKNF.d.cts +3993 -0
- package/dist/operations.gen-DUD406TV.d.ts +3993 -0
- package/package.json +127 -4
- package/src/admin/index.ts +47 -0
- package/src/admin/rules/mountayaAdmin.ts +102 -0
- package/src/browser.ts +232 -0
- package/src/core/engines/sessionToken.ts +870 -0
- package/src/core/rules/auth.ts +1017 -0
- package/src/core/rules/clientHeader.ts +28 -0
- package/src/core/rules/dates.ts +200 -0
- package/src/core/rules/decode.ts +154 -0
- package/src/core/rules/envelope.ts +41 -0
- package/src/core/rules/errors.ts +1486 -0
- package/src/core/rules/graphql.ts +576 -0
- package/src/core/rules/headerValue.ts +42 -0
- package/src/core/rules/idempotencyKey.ts +64 -0
- package/src/core/rules/nullMask.ts +127 -0
- package/src/core/rules/nullMasks.gen.ts +416 -0
- package/src/core/rules/paginate.ts +316 -0
- package/src/core/rules/rateLimit.ts +507 -0
- package/src/core/rules/redaction.ts +219 -0
- package/src/core/rules/resourceRef.ts +110 -0
- package/src/core/rules/responseBody.ts +492 -0
- package/src/core/rules/retry.ts +386 -0
- package/src/core/rules/selection.ts +416 -0
- package/src/core/rules/sessionAnswer.ts +90 -0
- package/src/core/rules/sessionSchedule.ts +131 -0
- package/src/core/rules/sessionWait.ts +112 -0
- package/src/core/rules/transport.ts +2386 -0
- package/src/core/rules/version.gen.ts +16 -0
- package/src/core/rules/webAddress.ts +165 -0
- package/src/core/rules/webAddresses.gen.ts +30 -0
- package/src/data/operations.gen.ts +603 -0
- package/src/data/schema.gen.ts +8078 -0
- package/src/data/selection.gen.ts +472 -0
- package/src/events/index.ts +67 -0
- package/src/events/rules/agent.ts +439 -0
- package/src/events/rules/collab.ts +554 -0
- package/src/events/rules/collabNulls.gen.ts +17 -0
- package/src/events/rules/eventStream.ts +94 -0
- package/src/events/rules/openSseStream.ts +594 -0
- package/src/events/rules/sse.ts +349 -0
- package/src/index.ts +231 -0
- package/src/rest/adminOperations.gen.ts +70 -0
- package/src/rest/adminResources.gen.ts +136 -0
- package/src/rest/coreOperations.gen.ts +74 -0
- package/src/rest/coreResources.gen.ts +244 -0
- package/src/rest/dates.gen.ts +217 -0
- package/src/rest/operations.gen.ts +4341 -0
- package/src/rest/resources.gen.ts +369 -0
- package/src/rest/schema.gen.ts +56840 -0
- package/src/tiles/operations.gen.ts +206 -0
- package/src/tiles/schema.gen.ts +8408 -0
- package/src/webhooks/rules/constructWebhookEvent.ts +482 -0
- package/src/webhooks/rules/webhookEvent.ts +38 -0
- package/src/webhooks/rules/webhookEvents.gen.ts +732 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wait for a session token a source is minting.
|
|
3
|
+
*
|
|
4
|
+
* A page opens before its first session token is minted, and every read it starts in that window
|
|
5
|
+
* would go out under the publishable key alone, which the API answers with the anonymous
|
|
6
|
+
* projection. A request made while the credential's {@link SessionTokenSource} holds no token and
|
|
7
|
+
* reports one on its way therefore holds the source for the span of a wait: it subscribes, which
|
|
8
|
+
* starts the mint of an engine nobody holds yet, and it is sent once the source holds a token or
|
|
9
|
+
* reports none on its way.
|
|
10
|
+
*
|
|
11
|
+
* The wait reads the snapshot exactly as `credentialScope` does (a token held, or `isLoading`),
|
|
12
|
+
* so a read keyed under a scope that says no session is sent under the key alone, and one keyed
|
|
13
|
+
* under a scope that says a session waits for it.
|
|
14
|
+
*
|
|
15
|
+
* The rule lives in the transport rather than in a binding, so every caller of the client (a
|
|
16
|
+
* component, a worker, a CLI) and every port of it waits the same way.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { SessionTokenSource } from "./auth.js";
|
|
20
|
+
import { MountayaConnectionError } from "./errors.js";
|
|
21
|
+
import { isAborted } from "./responseBody.js";
|
|
22
|
+
import { abortReasonOf } from "./retry.js";
|
|
23
|
+
|
|
24
|
+
/** What bounds one wait, and the operation its refusal names. */
|
|
25
|
+
interface SessionWaitBounds {
|
|
26
|
+
readonly operationId: string;
|
|
27
|
+
readonly signal?: AbortSignal | undefined;
|
|
28
|
+
readonly timeoutMs: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* waitForSessionToken answers `undefined` where the source holds a token or reports none on its
|
|
33
|
+
* way, so neither case costs a turn of the event loop or a subscription, and otherwise a promise
|
|
34
|
+
* that settles once a request made now has nothing left to wait for: the source holds a token,
|
|
35
|
+
* or reports none on its way.
|
|
36
|
+
*
|
|
37
|
+
* The source is subscribed for the span of the wait and released as it ends, however it ends.
|
|
38
|
+
*
|
|
39
|
+
* @throws (as a rejection) the caller's abort reason once `signal` aborts, and a
|
|
40
|
+
* `MountayaConnectionError` naming the operation once `timeoutMs` passes with a mint still out.
|
|
41
|
+
*/
|
|
42
|
+
export const waitForSessionToken = (
|
|
43
|
+
source: SessionTokenSource,
|
|
44
|
+
bounds: SessionWaitBounds,
|
|
45
|
+
): Promise<void> | undefined => {
|
|
46
|
+
const held = source.getSnapshot();
|
|
47
|
+
if (held.token !== undefined || !held.isLoading) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { operationId, signal, timeoutMs } = bounds;
|
|
52
|
+
if (signal !== undefined && isAborted(signal)) {
|
|
53
|
+
return Promise.reject(abortReasonOf(signal));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return new Promise<void>((resolve, reject) => {
|
|
57
|
+
let ended = false;
|
|
58
|
+
let release: (() => void) | undefined;
|
|
59
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
60
|
+
|
|
61
|
+
const end = (settle: () => void): void => {
|
|
62
|
+
if (ended) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
ended = true;
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
signal?.removeEventListener("abort", onAbort);
|
|
69
|
+
release?.();
|
|
70
|
+
settle();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const onAbort = (): void => {
|
|
74
|
+
end(() => {
|
|
75
|
+
reject(signal === undefined ? undefined : abortReasonOf(signal));
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const check = (): void => {
|
|
80
|
+
const snapshot = source.getSnapshot();
|
|
81
|
+
if (snapshot.token !== undefined || !snapshot.isLoading) {
|
|
82
|
+
end(resolve);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// A source may tell its listener inside `subscribe` (an engine reports the mint it starts),
|
|
87
|
+
// so the wait can end before the release is in hand: it is then released here.
|
|
88
|
+
const unsubscribe = source.subscribe(check);
|
|
89
|
+
if (ended) {
|
|
90
|
+
unsubscribe();
|
|
91
|
+
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
release = unsubscribe;
|
|
96
|
+
check();
|
|
97
|
+
if (ended) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
102
|
+
timer = setTimeout(() => {
|
|
103
|
+
end(() => {
|
|
104
|
+
reject(
|
|
105
|
+
new MountayaConnectionError(
|
|
106
|
+
`${operationId}: no session token within ${timeoutMs} ms: the session token mint has not answered. Raise timeoutMs, or check the endpoint the mint calls.`,
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
}, timeoutMs);
|
|
111
|
+
});
|
|
112
|
+
};
|