@superbee/core 0.2.0-pre.15 → 0.2.0-pre.16
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/README.md +213 -0
- package/dist/backend.d.ts +3 -0
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +7 -0
- package/dist/backend.js.map +1 -1
- package/dist/blob-contract.d.ts +80 -0
- package/dist/blob-contract.d.ts.map +1 -0
- package/dist/blob-contract.js +131 -0
- package/dist/blob-contract.js.map +1 -0
- package/dist/blob-journal.d.ts +117 -0
- package/dist/blob-journal.d.ts.map +1 -0
- package/dist/blob-journal.js +168 -0
- package/dist/blob-journal.js.map +1 -0
- package/dist/engine.d.ts +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js.map +1 -1
- package/dist/file-journaled-backend-internal.d.ts +2 -0
- package/dist/file-journaled-backend-internal.d.ts.map +1 -1
- package/dist/file-journaled-backend-internal.js +2 -0
- package/dist/file-journaled-backend-internal.js.map +1 -1
- package/dist/file-journaled-backend.d.ts +14 -2
- package/dist/file-journaled-backend.d.ts.map +1 -1
- package/dist/file-journaled-backend.js +245 -37
- package/dist/file-journaled-backend.js.map +1 -1
- package/dist/hosted-client/binding.d.ts +7 -0
- package/dist/hosted-client/binding.d.ts.map +1 -0
- package/dist/hosted-client/binding.js +10 -0
- package/dist/hosted-client/binding.js.map +1 -0
- package/dist/hosted-client/blob-delivery.d.ts +61 -0
- package/dist/hosted-client/blob-delivery.d.ts.map +1 -0
- package/dist/hosted-client/blob-delivery.js +147 -0
- package/dist/hosted-client/blob-delivery.js.map +1 -0
- package/dist/hosted-client/bundle-listing.d.ts +46 -0
- package/dist/hosted-client/bundle-listing.d.ts.map +1 -0
- package/dist/hosted-client/bundle-listing.js +36 -0
- package/dist/hosted-client/bundle-listing.js.map +1 -0
- package/dist/hosted-client/client.d.ts +155 -0
- package/dist/hosted-client/client.d.ts.map +1 -0
- package/dist/hosted-client/client.js +278 -0
- package/dist/hosted-client/client.js.map +1 -0
- package/dist/hosted-client/errors.d.ts +16 -0
- package/dist/hosted-client/errors.d.ts.map +1 -0
- package/dist/hosted-client/errors.js +22 -0
- package/dist/hosted-client/errors.js.map +1 -0
- package/dist/hosted-client/index.d.ts +23 -0
- package/dist/hosted-client/index.d.ts.map +1 -0
- package/dist/hosted-client/index.js +25 -0
- package/dist/hosted-client/index.js.map +1 -0
- package/dist/hosted-client/node.d.ts +70 -0
- package/dist/hosted-client/node.d.ts.map +1 -0
- package/dist/hosted-client/node.js +214 -0
- package/dist/hosted-client/node.js.map +1 -0
- package/dist/hosted-client/reference.d.ts +12 -0
- package/dist/hosted-client/reference.d.ts.map +1 -0
- package/dist/hosted-client/reference.js +29 -0
- package/dist/hosted-client/reference.js.map +1 -0
- package/dist/hosted-client/write.d.ts +191 -0
- package/dist/hosted-client/write.d.ts.map +1 -0
- package/dist/hosted-client/write.js +396 -0
- package/dist/hosted-client/write.js.map +1 -0
- package/dist/hosted-transport/answer-rows.d.ts +26 -0
- package/dist/hosted-transport/answer-rows.d.ts.map +1 -1
- package/dist/hosted-transport/answer-rows.js +59 -1
- package/dist/hosted-transport/answer-rows.js.map +1 -1
- package/dist/hosted-transport/blob-reads.d.ts +35 -0
- package/dist/hosted-transport/blob-reads.d.ts.map +1 -0
- package/dist/hosted-transport/blob-reads.js +179 -0
- package/dist/hosted-transport/blob-reads.js.map +1 -0
- package/dist/hosted-transport/blob-write.d.ts +34 -0
- package/dist/hosted-transport/blob-write.d.ts.map +1 -0
- package/dist/hosted-transport/blob-write.js +115 -0
- package/dist/hosted-transport/blob-write.js.map +1 -0
- package/dist/hosted-transport/carrier.d.ts +8 -9
- package/dist/hosted-transport/carrier.d.ts.map +1 -1
- package/dist/hosted-transport/carrier.js +40 -41
- package/dist/hosted-transport/carrier.js.map +1 -1
- package/dist/hosted-transport/index.d.ts +4 -4
- package/dist/hosted-transport/index.d.ts.map +1 -1
- package/dist/hosted-transport/index.js +4 -4
- package/dist/hosted-transport/index.js.map +1 -1
- package/dist/hosted-transport/read-adapter.d.ts +6 -0
- package/dist/hosted-transport/read-adapter.d.ts.map +1 -1
- package/dist/hosted-transport/read-adapter.js +11 -0
- package/dist/hosted-transport/read-adapter.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/journaled-backend.d.ts +10 -2
- package/dist/journaled-backend.d.ts.map +1 -1
- package/dist/journaled-backend.js +3 -3
- package/dist/journaled-backend.js.map +1 -1
- package/dist/link-types.d.ts +26 -0
- package/dist/link-types.d.ts.map +1 -0
- package/dist/link-types.js +57 -0
- package/dist/link-types.js.map +1 -0
- package/dist/platform.d.ts +4 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +16 -0
- package/dist/platform.js.map +1 -1
- package/dist/recipe-lifecycle/errors.d.ts +77 -0
- package/dist/recipe-lifecycle/errors.d.ts.map +1 -0
- package/dist/recipe-lifecycle/errors.js +96 -0
- package/dist/recipe-lifecycle/errors.js.map +1 -0
- package/dist/recipe-lifecycle/evolution.d.ts +71 -0
- package/dist/recipe-lifecycle/evolution.d.ts.map +1 -0
- package/dist/recipe-lifecycle/evolution.js +659 -0
- package/dist/recipe-lifecycle/evolution.js.map +1 -0
- package/dist/recipe-lifecycle/index.d.ts +23 -0
- package/dist/recipe-lifecycle/index.d.ts.map +1 -0
- package/dist/recipe-lifecycle/index.js +19 -0
- package/dist/recipe-lifecycle/index.js.map +1 -0
- package/dist/recipe-lifecycle/install.d.ts +111 -0
- package/dist/recipe-lifecycle/install.d.ts.map +1 -0
- package/dist/recipe-lifecycle/install.js +412 -0
- package/dist/recipe-lifecycle/install.js.map +1 -0
- package/dist/recipe-lifecycle/legacy-aliases.d.ts +16 -0
- package/dist/recipe-lifecycle/legacy-aliases.d.ts.map +1 -0
- package/dist/recipe-lifecycle/legacy-aliases.js +51 -0
- package/dist/recipe-lifecycle/legacy-aliases.js.map +1 -0
- package/dist/recipe-lifecycle/stamp.d.ts +98 -0
- package/dist/recipe-lifecycle/stamp.d.ts.map +1 -0
- package/dist/recipe-lifecycle/stamp.js +260 -0
- package/dist/recipe-lifecycle/stamp.js.map +1 -0
- package/dist/recipes.d.ts +5 -0
- package/dist/recipes.d.ts.map +1 -1
- package/dist/recipes.js +5 -0
- package/dist/recipes.js.map +1 -1
- package/dist/storage.d.ts +3 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +3 -0
- package/dist/storage.js.map +1 -1
- package/dist/uncertain-write.d.ts +70 -2
- package/dist/uncertain-write.d.ts.map +1 -1
- package/dist/uncertain-write.js +45 -32
- package/dist/uncertain-write.js.map +1 -1
- package/dist/write-identity.d.ts +5 -0
- package/dist/write-identity.d.ts.map +1 -0
- package/dist/write-identity.js +9 -0
- package/dist/write-identity.js.map +1 -0
- package/package.json +13 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle-listing.js","sourceRoot":"","sources":["../../src/hosted-client/bundle-listing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAA8B,MAAM,gBAAgB,CAAC;AAUnH,sGAAsG;AACtG,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AAgCnC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAgC;IAChE,MAAM,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;IACtD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAuB,CAAC;IACjD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACvC,MAAM,SAAS,GAAG,IAAI,EAAE,SAAS,IAAI,0BAA0B,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9E,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,GAAG,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,UAAU,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;QACzG,IAAI,CAAC,SAAS;YAAE,SAAS;QACzB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5E,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI;YAAE,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrI,CAAC;IACD,OAAO;QACL,OAAO;QACP,QAAQ,EAAE,IAAI,CAAC,MAAM,GAAG,eAAe;QACvC,MAAM,CAAC,SAAS;YACd,OAAO;gBACL,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI;gBACnE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAC7C,UAAU,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;aAClE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { type HostedCarrier, type HostedHistoryAnswer, type HostedHistoryRequest, type HostedOperationListingAnswer, type HostedOperationRun, type HostedReadAdapter, type FetchCarrierOptions, type JsonObject } from "../hosted-transport/index.js";
|
|
2
|
+
import type { HostedBundleRow } from "./bundle-listing.js";
|
|
3
|
+
import { type HostedIntentStore, type HostedWriteInput, type HostedWriteIntent, type HostedWriteLookupResult, type HostedWriteOptions, type HostedWriteResult } from "./write.js";
|
|
4
|
+
/** Where a hosted client sends its requests. */
|
|
5
|
+
export interface HostedClientTarget {
|
|
6
|
+
/** The host's origin, such as `https://mcp.getsuperbee.com`; routes resolve against it. */
|
|
7
|
+
readonly origin: string;
|
|
8
|
+
/**
|
|
9
|
+
* The sync family's path prefix: `/sync/v1` for the Superbee API, or `/agents/<id>/sync/v1` for
|
|
10
|
+
* an agent connection. {@link syncRoutePrefix} derives it from a protected-resource audience.
|
|
11
|
+
*/
|
|
12
|
+
readonly syncPrefix: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The credential headers for one request, such as `{ Authorization: "Bearer …" }` or a browser's
|
|
16
|
+
* cookie-bound CSRF header: the carrier seam's own `credentials` (`FetchCarrierOptions`), passed
|
|
17
|
+
* through unchanged. It is called before every request (never cached by the client), so it may
|
|
18
|
+
* renew a short-lived token. A rejection means no credential: the request is not sent and fails
|
|
19
|
+
* as a `HostedCarrierError` with code `denied`.
|
|
20
|
+
*/
|
|
21
|
+
export type HostedCredentialProvider = FetchCarrierOptions["credentials"];
|
|
22
|
+
/**
|
|
23
|
+
* A {@link HostedCredentialProvider} sending `Authorization: Bearer <token>`, asking `getToken`
|
|
24
|
+
* before every request. A value that is not a string is no credential (`denied`).
|
|
25
|
+
*/
|
|
26
|
+
export declare function bearerCredentials(getToken: (signal: AbortSignal) => Promise<string> | string): HostedCredentialProvider;
|
|
27
|
+
export interface HostedClientOptions {
|
|
28
|
+
readonly target: HostedClientTarget;
|
|
29
|
+
readonly credentials: HostedCredentialProvider;
|
|
30
|
+
readonly fetch?: typeof fetch;
|
|
31
|
+
/** Every request is answered within this many milliseconds. Default 15 s. */
|
|
32
|
+
readonly deadlineMs?: number;
|
|
33
|
+
/** Aborting it stops every request the client (and each `within` client) sends. */
|
|
34
|
+
readonly signal?: AbortSignal;
|
|
35
|
+
/**
|
|
36
|
+
* Where `write` records each write until it settles, for its outcome lookup. Default: an
|
|
37
|
+
* in-memory store ({@link createMemoryIntentStore}) owned by this client.
|
|
38
|
+
*/
|
|
39
|
+
readonly intentStore?: HostedIntentStore;
|
|
40
|
+
/** How a write recovers an unclear answer: the wait between its outcome lookups (default 250 ms). */
|
|
41
|
+
readonly writeRecovery?: {
|
|
42
|
+
readonly lookupDelayMs?: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* How long a bundle's capabilities answer serves this client's writes (and its `within`
|
|
46
|
+
* clients'), in milliseconds after it arrives. Default 60,000; 0 reads them before every write.
|
|
47
|
+
* A write refused `read_only`, `invalid_input`, `validation_failed` or `PERMISSION_DENIED`, or
|
|
48
|
+
* whose outcome is `unknown`, drops the answer so the next write reads it again. `reader()` never
|
|
49
|
+
* shares it.
|
|
50
|
+
*/
|
|
51
|
+
readonly capabilitiesTtlMs?: number;
|
|
52
|
+
/** The clock the capabilities answers age by, in epoch milliseconds. Default `Date.now`. */
|
|
53
|
+
readonly now?: () => number;
|
|
54
|
+
}
|
|
55
|
+
/** One operation run's options. */
|
|
56
|
+
export interface HostedRunOptions {
|
|
57
|
+
/** The largest answer read, in bytes. Default `HOSTED_READ_BOUNDS.runBytes`. */
|
|
58
|
+
readonly maximumBytes?: number;
|
|
59
|
+
}
|
|
60
|
+
export interface HostedIdentity {
|
|
61
|
+
readonly principalId: string;
|
|
62
|
+
readonly tenantIds: readonly string[];
|
|
63
|
+
/**
|
|
64
|
+
* Each workspace with the slug a qualified reference names it by (null for none), in
|
|
65
|
+
* `tenantIds` order. A host from before qualified references reports no slugs: every one is null.
|
|
66
|
+
*/
|
|
67
|
+
readonly workspaces: readonly HostedWorkspace[];
|
|
68
|
+
/**
|
|
69
|
+
* The host's whole-document write bound (`limits.documentInputBytes`), or null when it states
|
|
70
|
+
* none (every host before the bound was stated accepts 65,536).
|
|
71
|
+
*/
|
|
72
|
+
readonly documentInputBytes: number | null;
|
|
73
|
+
/** The person's email, when the host names one (null otherwise). */
|
|
74
|
+
readonly email: string | null;
|
|
75
|
+
}
|
|
76
|
+
export interface HostedWorkspace {
|
|
77
|
+
readonly tenantId: string;
|
|
78
|
+
readonly slug: string | null;
|
|
79
|
+
}
|
|
80
|
+
export interface HostedClient {
|
|
81
|
+
readonly target: HostedClientTarget;
|
|
82
|
+
/** The sync family's prefix, `target.syncPrefix`. */
|
|
83
|
+
readonly prefix: string;
|
|
84
|
+
/** The bearer carrier, for routes this client has no method for; it qualifies as {@link within} does. */
|
|
85
|
+
readonly carrier: HostedCarrier;
|
|
86
|
+
/** The signal every request is sent under. */
|
|
87
|
+
readonly signal: AbortSignal;
|
|
88
|
+
/** Who the bearer is (`<prefix>/whoami`). */
|
|
89
|
+
whoami(): Promise<HostedIdentity>;
|
|
90
|
+
/** The bundles the bearer may sync (`<prefix>/bundles`), at most `BUNDLE_LIST_CAP` rows. */
|
|
91
|
+
bundles(): Promise<HostedBundleRow[]>;
|
|
92
|
+
/** The read adapter (capabilities, heads, snapshot, read) for one bundle. */
|
|
93
|
+
reader(bundleId: string): HostedReadAdapter;
|
|
94
|
+
/** One page of a document's history (`documents.history.v1`), validated against the page asked for. */
|
|
95
|
+
history(bundleId: string, request: HostedHistoryRequest): Promise<HostedHistoryAnswer>;
|
|
96
|
+
/**
|
|
97
|
+
* The same client, naming its bundles in the workspace with this slug: every bundle-scoped
|
|
98
|
+
* request names its bundle as `<slug>/<bundle-id>` ({@link qualifyingCarrier}).
|
|
99
|
+
*/
|
|
100
|
+
within(slug: string): HostedClient;
|
|
101
|
+
/**
|
|
102
|
+
* The reads this host runs by id for one bundle (`<prefix>/operations`). A bundle the host does
|
|
103
|
+
* not serve to this person is the refusal `bundle_not_found`, as a run answers it.
|
|
104
|
+
*/
|
|
105
|
+
listOperations(bundleId: string): Promise<HostedOperationListingAnswer>;
|
|
106
|
+
/**
|
|
107
|
+
* One operation, run by id (`<prefix>/run`) in one request: the operation's data, or its
|
|
108
|
+
* refusal. The route's own `unknown_operation` (the host does not run this id) and
|
|
109
|
+
* `invalid_input` come back as refusals too. `input.bundleId` is set to `bundleId`.
|
|
110
|
+
*/
|
|
111
|
+
runOperation(bundleId: string, operationId: string, input: JsonObject, options?: HostedRunOptions): Promise<HostedOperationRun>;
|
|
112
|
+
/**
|
|
113
|
+
* Write one whole serialized document: a create when `expectAbsent` is true, else a replace at
|
|
114
|
+
* exactly `expectedVersion`. One request identity, minted here unless given, settles it: the
|
|
115
|
+
* answer, or after an unclear one a lookup under the same identity and this client's binding.
|
|
116
|
+
* Returns committed, a conflict (final; never resent), a refusal, or `unknown` with the request
|
|
117
|
+
* identity for {@link lookupWrite}. Nothing is thrown once a request may have left.
|
|
118
|
+
*/
|
|
119
|
+
write(bundleId: string, input: HostedWriteInput, options?: HostedWriteOptions): Promise<HostedWriteResult>;
|
|
120
|
+
/**
|
|
121
|
+
* What the host recorded for a held write: one outcome lookup under its own identity and
|
|
122
|
+
* binding. It never sends the write; a host holding no outcome yet answers `unknown`.
|
|
123
|
+
*/
|
|
124
|
+
lookupWrite(requestId: string, options?: {
|
|
125
|
+
signal?: AbortSignal;
|
|
126
|
+
}): Promise<HostedWriteLookupResult>;
|
|
127
|
+
/**
|
|
128
|
+
* Settle a held write: look it up and, when the host never recorded it within the retention
|
|
129
|
+
* window it serves, send that same identity once more.
|
|
130
|
+
*/
|
|
131
|
+
settleWrite(requestId: string, options?: {
|
|
132
|
+
signal?: AbortSignal;
|
|
133
|
+
}): Promise<HostedWriteLookupResult>;
|
|
134
|
+
/** Every write the intent store holds (unsettled, or never sent); needs a store with `list`. */
|
|
135
|
+
heldWrites(): Promise<HostedWriteIntent[]>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The sync family under a protected resource's audience: `/sync/v1` for the Superbee API
|
|
139
|
+
* (`<origin>/mcp`), `/agents/<uuid>/sync/v1` for an agent connection. Null for any other
|
|
140
|
+
* audience, which has no sync family.
|
|
141
|
+
*/
|
|
142
|
+
export declare function syncRoutePrefix(resource: {
|
|
143
|
+
readonly origin: string;
|
|
144
|
+
readonly audience: string;
|
|
145
|
+
}): string | null;
|
|
146
|
+
/**
|
|
147
|
+
* The carrier with a workspace: every bundle-scoped request names its bundle as
|
|
148
|
+
* `<slug>/<bundle-id>`, so the host selects that workspace's bundle. The host's answers still
|
|
149
|
+
* name the bare id. An id that already names a workspace is a caller's mistake (a `TypeError`),
|
|
150
|
+
* as is a raw body sent to a bundle-scoped route other than an ordinary blob create/replace.
|
|
151
|
+
*/
|
|
152
|
+
export declare function qualifyingCarrier(carrier: HostedCarrier, prefix: string, slug: string): HostedCarrier;
|
|
153
|
+
/** A client of the hosted sync family at `options.target`, authenticated by `options.credentials`. */
|
|
154
|
+
export declare function createHostedClient(options: HostedClientOptions): HostedClient;
|
|
155
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/hosted-client/client.ts"],"names":[],"mappings":"AASA,OAAO,EAaL,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EACjC,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EAExB,KAAK,UAAU,EAChB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAK3D,OAAO,EAQL,KAAK,iBAAiB,EAEtB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACvB,MAAM,YAAY,CAAC;AAMpB,gDAAgD;AAChD,MAAM,WAAW,kBAAkB;IACjC,2FAA2F;IAC3F,QAAQ,CAAC,MAAM,EAAE,MA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M,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC3G;;;OAGG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACrG;;;OAGG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACrG,gGAAgG;IAChG,UAAU,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;CAC5C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,IAAI,CAQ/G;AA4BD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAiCrG;AAED,sGAAsG;AACtG,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAe7E"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// The headless client of the hosted sync route family (`/sync/v1`): a bearer carrier over the
|
|
2
|
+
// shared hosted transport, the identity and bundle-list reads a caller needs before it opens a
|
|
3
|
+
// bundle, document reads and history, and operations run by id.
|
|
4
|
+
//
|
|
5
|
+
// Credentials come from the caller's provider, asked once per request through the carrier seam, so
|
|
6
|
+
// a short-lived token can be renewed between requests. The client never logs them, and its errors
|
|
7
|
+
// carry the route and code, never a credential. Failures are typed and never worded for a particular surface:
|
|
8
|
+
// `HostedCarrierError` (transport), `MalformedAnswer` (an answer the contract does not admit),
|
|
9
|
+
// `RemoteError` (a refusal, with the host's code and status) and `HostedRouteNotServed`.
|
|
10
|
+
import { createFetchCarrier, createHostedReadAdapter, decodeHistoryAnswer, decodeOperationListing, decodeOperationRun, familyRefusal, historyInput, HOSTED_READ_BOUNDS, operationRunBody, readRefusal, statedDocumentInputBytes, } from "../hosted-transport/index.js";
|
|
11
|
+
import { MalformedAnswer, RemoteError } from "../remote-error.js";
|
|
12
|
+
import { HostedRouteNotServed } from "./errors.js";
|
|
13
|
+
import { hostedBundleReferenceText, isWorkspaceSlug, parseHostedBundleReference } from "./reference.js";
|
|
14
|
+
import { checkoutBindingDigest } from "./binding.js";
|
|
15
|
+
import { mintRequestId } from "../uncertain-write.js";
|
|
16
|
+
import { createCapabilitiesCache, createMemoryIntentStore, hostedHeldWrites, hostedLookupWrite, hostedSettleWrite, hostedWrite, } from "./write.js";
|
|
17
|
+
const IDENTITY_BYTES = 64 * 1024;
|
|
18
|
+
const BUNDLES_BYTES = 256 * 1024;
|
|
19
|
+
const AGENT_AUDIENCE_PATH = /^\/agents\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/mcp$/;
|
|
20
|
+
/**
|
|
21
|
+
* A {@link HostedCredentialProvider} sending `Authorization: Bearer <token>`, asking `getToken`
|
|
22
|
+
* before every request. A value that is not a string is no credential (`denied`).
|
|
23
|
+
*/
|
|
24
|
+
export function bearerCredentials(getToken) {
|
|
25
|
+
return async (signal) => {
|
|
26
|
+
const token = await getToken(signal);
|
|
27
|
+
if (typeof token !== "string")
|
|
28
|
+
throw new TypeError("the token provider returned no bearer");
|
|
29
|
+
return { Authorization: `Bearer ${token}` };
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The sync family under a protected resource's audience: `/sync/v1` for the Superbee API
|
|
34
|
+
* (`<origin>/mcp`), `/agents/<uuid>/sync/v1` for an agent connection. Null for any other
|
|
35
|
+
* audience, which has no sync family.
|
|
36
|
+
*/
|
|
37
|
+
export function syncRoutePrefix(resource) {
|
|
38
|
+
const { origin, audience } = resource;
|
|
39
|
+
// The audience must be on the origin itself, not on another host whose name merely starts the same.
|
|
40
|
+
if (!audience.startsWith(origin) || (audience.length > origin.length && audience[origin.length] !== "/"))
|
|
41
|
+
return null;
|
|
42
|
+
const audiencePath = audience.slice(origin.length);
|
|
43
|
+
if (audiencePath === "/mcp")
|
|
44
|
+
return "/sync/v1";
|
|
45
|
+
if (AGENT_AUDIENCE_PATH.test(audiencePath))
|
|
46
|
+
return `${audiencePath.slice(0, -"/mcp".length)}/sync/v1`;
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function syncReadRoutes(prefix) {
|
|
50
|
+
return Object.freeze({
|
|
51
|
+
capabilities: `${prefix}/capabilities`,
|
|
52
|
+
heads: `${prefix}/heads`,
|
|
53
|
+
snapshot: `${prefix}/snapshot`,
|
|
54
|
+
read: `${prefix}/read`,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The sync routes whose body never names one bundle by reference: `whoami` and `bundles` span the
|
|
59
|
+
* person's workspaces, and `bundle-create` and the staged creation's four routes name their
|
|
60
|
+
* workspace in the body (the blob route in its headers) and a bundle that does not exist yet.
|
|
61
|
+
* Every other route under the family's prefix is bundle-scoped, the host's own rule, so a route
|
|
62
|
+
* added later is qualified by default rather than read as an absent bundle once an id collides.
|
|
63
|
+
*/
|
|
64
|
+
const UNSCOPED_ROUTES = Object.freeze([
|
|
65
|
+
"whoami",
|
|
66
|
+
"bundles",
|
|
67
|
+
"bundle-create",
|
|
68
|
+
"bundle-create-begin",
|
|
69
|
+
"bundle-create-stage",
|
|
70
|
+
"bundle-create-blob",
|
|
71
|
+
"bundle-create-commit",
|
|
72
|
+
]);
|
|
73
|
+
/**
|
|
74
|
+
* The carrier with a workspace: every bundle-scoped request names its bundle as
|
|
75
|
+
* `<slug>/<bundle-id>`, so the host selects that workspace's bundle. The host's answers still
|
|
76
|
+
* name the bare id. An id that already names a workspace is a caller's mistake (a `TypeError`),
|
|
77
|
+
* as is a raw body sent to a bundle-scoped route other than an ordinary blob create/replace.
|
|
78
|
+
*/
|
|
79
|
+
export function qualifyingCarrier(carrier, prefix, slug) {
|
|
80
|
+
const unscoped = new Set(UNSCOPED_ROUTES.map((route) => `${prefix}/${route}`));
|
|
81
|
+
const blobUploads = new Set([`${prefix}/blob-create`, `${prefix}/blob-replace`]);
|
|
82
|
+
const scoped = (route) => route.startsWith(`${prefix}/`) && !unscoped.has(route);
|
|
83
|
+
const qualify = (route, input) => {
|
|
84
|
+
if (!scoped(route) || input === null || typeof input !== "object" || Array.isArray(input))
|
|
85
|
+
return input;
|
|
86
|
+
const bundleId = input.bundleId;
|
|
87
|
+
if (typeof bundleId !== "string")
|
|
88
|
+
return input;
|
|
89
|
+
if (bundleId.includes("/"))
|
|
90
|
+
throw new TypeError("a qualified reference sent through a qualifying client");
|
|
91
|
+
return { ...input, bundleId: hostedBundleReferenceText({ slug, bundleId }) };
|
|
92
|
+
};
|
|
93
|
+
const bytes = carrier.bytes?.bind(carrier);
|
|
94
|
+
return {
|
|
95
|
+
json: async (route, input, signal, options) => carrier.json(route, qualify(route, input), signal, options),
|
|
96
|
+
stream: async (route, input, signal) => carrier.stream(route, qualify(route, input), signal),
|
|
97
|
+
// Ordinary blob uploads name their bundle in one route header, not in the binary body.
|
|
98
|
+
...(bytes
|
|
99
|
+
? {
|
|
100
|
+
bytes: async (route, body, signal, options) => {
|
|
101
|
+
if (blobUploads.has(route)) {
|
|
102
|
+
const entries = Object.entries(options.headers ?? {}).filter(([name]) => name.toLowerCase() === "x-superbee-bundle");
|
|
103
|
+
if (entries.length !== 1)
|
|
104
|
+
throw new TypeError("a blob upload must name exactly one bundle header");
|
|
105
|
+
const [name, value] = entries[0];
|
|
106
|
+
const reference = typeof value === "string" ? parseHostedBundleReference(value) : null;
|
|
107
|
+
if (reference === null || reference.slug !== null)
|
|
108
|
+
throw new TypeError("a blob upload through a qualifying client must name a bare hosted bundle id");
|
|
109
|
+
return bytes(route, body, signal, { ...options, headers: { ...options.headers, [name]: hostedBundleReferenceText({ slug, bundleId: reference.bundleId }) } });
|
|
110
|
+
}
|
|
111
|
+
if (scoped(route))
|
|
112
|
+
throw new TypeError(`a raw body sent to the bundle-scoped route ${route} through a qualifying client`);
|
|
113
|
+
return bytes(route, body, signal, options);
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
: {}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** A client of the hosted sync family at `options.target`, authenticated by `options.credentials`. */
|
|
120
|
+
export function createHostedClient(options) {
|
|
121
|
+
const { syncPrefix } = options.target;
|
|
122
|
+
if (typeof syncPrefix !== "string" || !syncPrefix.startsWith("/") || syncPrefix.endsWith("/")) {
|
|
123
|
+
throw new TypeError("a hosted client's sync prefix is an absolute path without a trailing slash");
|
|
124
|
+
}
|
|
125
|
+
if (typeof options.credentials !== "function")
|
|
126
|
+
throw new TypeError("a hosted client needs a credential provider");
|
|
127
|
+
// One binding per client instance, shared by its `within` clients: a digest of a random id, as a
|
|
128
|
+
// checkout's is, so the id itself never leaves.
|
|
129
|
+
const writes = {
|
|
130
|
+
binding: checkoutBindingDigest(mintRequestId()),
|
|
131
|
+
store: options.intentStore ?? createMemoryIntentStore(),
|
|
132
|
+
inFlight: new Map(),
|
|
133
|
+
capabilities: createCapabilitiesCache(options.capabilitiesTtlMs, options.now),
|
|
134
|
+
};
|
|
135
|
+
return clientIn(options, options.signal ?? new AbortController().signal, undefined, writes);
|
|
136
|
+
}
|
|
137
|
+
/** The client, naming its bundles in the workspace with `slug` when there is one. */
|
|
138
|
+
function clientIn(options, signal, slug, writes) {
|
|
139
|
+
const { target } = options;
|
|
140
|
+
const prefix = target.syncPrefix;
|
|
141
|
+
const fetchCarrier = createFetchCarrier({
|
|
142
|
+
baseUrl: target.origin,
|
|
143
|
+
credentials: options.credentials,
|
|
144
|
+
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
145
|
+
...(options.deadlineMs ? { deadlineMs: options.deadlineMs } : {}),
|
|
146
|
+
});
|
|
147
|
+
const carrier = slug === undefined ? fetchCarrier : qualifyingCarrier(fetchCarrier, prefix, slug);
|
|
148
|
+
const writeContext = {
|
|
149
|
+
...writes,
|
|
150
|
+
prefix,
|
|
151
|
+
workspace: slug ?? null,
|
|
152
|
+
signal,
|
|
153
|
+
...(options.writeRecovery?.lookupDelayMs !== undefined ? { lookupDelayMs: options.writeRecovery.lookupDelayMs } : {}),
|
|
154
|
+
readRoutes: syncReadRoutes(prefix),
|
|
155
|
+
// A recorded write is looked up in the workspace it was sent in, whichever client asks.
|
|
156
|
+
carrierFor: (workspace) => (workspace === null ? fetchCarrier : qualifyingCarrier(fetchCarrier, prefix, workspace)),
|
|
157
|
+
};
|
|
158
|
+
/** An unscoped read: the body on a `200`, otherwise the host's refusal as a `RemoteError`. */
|
|
159
|
+
async function json(route, maximum) {
|
|
160
|
+
const answer = await carrier.json(`${prefix}/${route}`, {}, signal, { maximum });
|
|
161
|
+
if (answer.status !== 200) {
|
|
162
|
+
const code = answer.body?.error;
|
|
163
|
+
const named = typeof code === "string" ? code : typeof code?.code === "string" ? code.code : undefined;
|
|
164
|
+
throw new RemoteError(`hosted ${route} answered ${answer.status}`, named ?? "RUNTIME", answer.status);
|
|
165
|
+
}
|
|
166
|
+
return answer.body;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* One request of a route a gateway may not have yet. That gateway answers the family's
|
|
170
|
+
* unknown-route 404, which is {@link HostedRouteNotServed}. An answer larger than `maximum` is
|
|
171
|
+
* the carrier's `unavailable` whose cause is `HostedAnswerTooLarge` (see `isAnswerTooLarge`).
|
|
172
|
+
*/
|
|
173
|
+
async function send(route, input, maximum) {
|
|
174
|
+
const answer = await carrier.json(route, input, signal, { maximum });
|
|
175
|
+
if (answer.status === 404 && isUnknownRoute(answer.body))
|
|
176
|
+
throw new HostedRouteNotServed(route);
|
|
177
|
+
return answer;
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
target,
|
|
181
|
+
prefix,
|
|
182
|
+
carrier,
|
|
183
|
+
signal,
|
|
184
|
+
async whoami() {
|
|
185
|
+
const route = `${prefix}/whoami`;
|
|
186
|
+
const body = (await json("whoami", IDENTITY_BYTES));
|
|
187
|
+
if (typeof body?.principalId !== "string" ||
|
|
188
|
+
body.principalId === "" ||
|
|
189
|
+
!Array.isArray(body.tenantIds) ||
|
|
190
|
+
!body.tenantIds.every((id) => typeof id === "string")) {
|
|
191
|
+
throw new MalformedAnswer("not an identity", route);
|
|
192
|
+
}
|
|
193
|
+
const tenantIds = [...body.tenantIds].sort();
|
|
194
|
+
// A host from before qualified references names no slugs.
|
|
195
|
+
const slugs = new Map();
|
|
196
|
+
if (body.workspaces !== undefined) {
|
|
197
|
+
if (!Array.isArray(body.workspaces) ||
|
|
198
|
+
body.workspaces.length !== tenantIds.length ||
|
|
199
|
+
!body.workspaces.every((w) => typeof w?.tenantId === "string" &&
|
|
200
|
+
tenantIds.includes(w.tenantId) &&
|
|
201
|
+
(w.slug === null || isWorkspaceSlug(w.slug)))) {
|
|
202
|
+
throw new MalformedAnswer("not an identity's workspaces", route);
|
|
203
|
+
}
|
|
204
|
+
for (const w of body.workspaces)
|
|
205
|
+
slugs.set(w.tenantId, w.slug);
|
|
206
|
+
if (slugs.size !== tenantIds.length)
|
|
207
|
+
throw new MalformedAnswer("an identity naming a workspace twice", route);
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
principalId: body.principalId,
|
|
211
|
+
tenantIds,
|
|
212
|
+
workspaces: tenantIds.map((tenantId) => ({ tenantId, slug: slugs.get(tenantId) ?? null })),
|
|
213
|
+
documentInputBytes: statedDocumentInputBytes(body.limits),
|
|
214
|
+
email: typeof body.email === "string" && /^[^\s\p{Cc}\p{Cf}]{3,320}$/u.test(body.email) ? body.email : null,
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
async bundles() {
|
|
218
|
+
const body = (await json("bundles", BUNDLES_BYTES));
|
|
219
|
+
if (body?.ok === false) {
|
|
220
|
+
const code = typeof body.error?.code === "string" ? body.error.code : "RUNTIME";
|
|
221
|
+
throw new RemoteError(`hosted bundles answered ${code}`, code, code === "insufficient_scope" ? 403 : 422);
|
|
222
|
+
}
|
|
223
|
+
const rows = body?.data?.bundles;
|
|
224
|
+
if (body?.ok !== true || !Array.isArray(rows))
|
|
225
|
+
throw new MalformedAnswer("not a bundle list", `${prefix}/bundles`);
|
|
226
|
+
return rows
|
|
227
|
+
.filter((row) => typeof row?.bundleId === "string" && typeof row?.name === "string")
|
|
228
|
+
.map((row) => ({ bundleId: row.bundleId, name: row.name, lifecycle: typeof row.lifecycle === "string" ? row.lifecycle : null }));
|
|
229
|
+
},
|
|
230
|
+
reader(bundleId) {
|
|
231
|
+
return createHostedReadAdapter({ carrier, bundleId, routes: syncReadRoutes(prefix) });
|
|
232
|
+
},
|
|
233
|
+
within(workspace) {
|
|
234
|
+
return clientIn(options, signal, workspace, writes);
|
|
235
|
+
},
|
|
236
|
+
write: (bundleId, input, writeOptions) => hostedWrite(writeContext, bundleId, input, writeOptions),
|
|
237
|
+
lookupWrite: (requestId, lookupOptions) => hostedLookupWrite(writeContext, requestId, lookupOptions),
|
|
238
|
+
settleWrite: (requestId, settleOptions) => hostedSettleWrite(writeContext, requestId, settleOptions),
|
|
239
|
+
heldWrites: () => hostedHeldWrites(writeContext),
|
|
240
|
+
async history(bundleId, request) {
|
|
241
|
+
const route = `${prefix}/history`;
|
|
242
|
+
const answer = await send(route, historyInput(bundleId, request), HOSTED_READ_BOUNDS.historyBytes);
|
|
243
|
+
if (answer.status !== 200)
|
|
244
|
+
throw readRefusal(answer);
|
|
245
|
+
return decodeHistoryAnswer(request, answer.body, route);
|
|
246
|
+
},
|
|
247
|
+
async listOperations(bundleId) {
|
|
248
|
+
const route = `${prefix}/operations`;
|
|
249
|
+
const answer = await send(route, { bundleId }, HOSTED_READ_BOUNDS.operationsBytes);
|
|
250
|
+
if (answer.status !== 200) {
|
|
251
|
+
// The listing refuses a bundle as capabilities does: a 404 naming the code, never a 200.
|
|
252
|
+
const refusal = answer.status === 404 ? familyRefusal(answer) : undefined;
|
|
253
|
+
if (refusal?.code === "bundle_not_found")
|
|
254
|
+
return { ok: false, refusal };
|
|
255
|
+
throw readRefusal(answer);
|
|
256
|
+
}
|
|
257
|
+
return { ok: true, listing: decodeOperationListing(answer.body, route) };
|
|
258
|
+
},
|
|
259
|
+
async runOperation(bundleId, operationId, input, runOptions = {}) {
|
|
260
|
+
const route = `${prefix}/run`;
|
|
261
|
+
const answer = await send(route, operationRunBody(bundleId, operationId, input), runOptions.maximumBytes ?? HOSTED_READ_BOUNDS.runBytes);
|
|
262
|
+
if (answer.status !== 200) {
|
|
263
|
+
// The route's own refusals of the request, before any operation ran: an id the host does
|
|
264
|
+
// not run by id, and an envelope or input it refuses. Both are typed, for the caller to word.
|
|
265
|
+
const refusal = answer.status === 400 ? familyRefusal(answer) : undefined;
|
|
266
|
+
if (refusal?.code === "unknown_operation" || refusal?.code === "invalid_input")
|
|
267
|
+
return { ok: false, refusal };
|
|
268
|
+
throw readRefusal(answer);
|
|
269
|
+
}
|
|
270
|
+
return decodeOperationRun(operationId, answer.body, route);
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/** The sync family's answer to a route it does not have: `404 {"error":"not_found"}`, nothing else. */
|
|
275
|
+
function isUnknownRoute(body) {
|
|
276
|
+
return typeof body === "object" && body !== null && !Array.isArray(body) && Object.keys(body).length === 1 && body.error === "not_found";
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/hosted-client/client.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,+FAA+F;AAC/F,gEAAgE;AA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FAA8F;gBAC9F,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBAC1E,IAAI,OAAO,EAAE,IAAI,KAAK,mBAAmB,IAAI,OAAO,EAAE,IAAI,KAAK,eAAe;oBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;gBAC9G,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;YAC5B,CAAC;YACD,OAAO,kBAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC;AACJ,CAAC;AAED,uGAAuG;AACvG,SAAS,cAAc,CAAC,IAAa;IACnC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAK,IAA4B,CAAC,KAAK,KAAK,WAAW,CAAC;AACpK,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RemoteError } from "../remote-error.js";
|
|
2
|
+
/** The code of {@link HostedRouteNotServed}. */
|
|
3
|
+
export declare const ROUTE_NOT_SERVED = "ROUTE_NOT_SERVED";
|
|
4
|
+
/**
|
|
5
|
+
* The host does not have this route yet: the sync family's own unknown-route answer,
|
|
6
|
+
* `404 {"error":"not_found"}` and nothing else, which a gateway from before the route sends. It
|
|
7
|
+
* is deterministic for that host version, so it is never retried; a later host serves the route.
|
|
8
|
+
* Its status stays `404`, and it names the route asked for.
|
|
9
|
+
*/
|
|
10
|
+
export declare class HostedRouteNotServed extends RemoteError {
|
|
11
|
+
readonly route: string;
|
|
12
|
+
constructor(route: string);
|
|
13
|
+
}
|
|
14
|
+
/** True when `error` is a {@link HostedRouteNotServed}. */
|
|
15
|
+
export declare function isRouteNotServed(error: unknown): error is HostedRouteNotServed;
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/hosted-client/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,gDAAgD;AAChD,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,WAAW;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBACX,KAAK,EAAE,MAAM;CAK1B;AAED,2DAA2D;AAC3D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,oBAAoB,CAE9E"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RemoteError } from "../remote-error.js";
|
|
2
|
+
/** The code of {@link HostedRouteNotServed}. */
|
|
3
|
+
export const ROUTE_NOT_SERVED = "ROUTE_NOT_SERVED";
|
|
4
|
+
/**
|
|
5
|
+
* The host does not have this route yet: the sync family's own unknown-route answer,
|
|
6
|
+
* `404 {"error":"not_found"}` and nothing else, which a gateway from before the route sends. It
|
|
7
|
+
* is deterministic for that host version, so it is never retried; a later host serves the route.
|
|
8
|
+
* Its status stays `404`, and it names the route asked for.
|
|
9
|
+
*/
|
|
10
|
+
export class HostedRouteNotServed extends RemoteError {
|
|
11
|
+
route;
|
|
12
|
+
constructor(route) {
|
|
13
|
+
super(`the host does not serve ${route}`, ROUTE_NOT_SERVED, 404);
|
|
14
|
+
this.name = "HostedRouteNotServed";
|
|
15
|
+
this.route = route;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** True when `error` is a {@link HostedRouteNotServed}. */
|
|
19
|
+
export function isRouteNotServed(error) {
|
|
20
|
+
return error instanceof HostedRouteNotServed;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/hosted-client/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,OAAO,oBAAqB,SAAQ,WAAW;IAC1C,KAAK,CAAS;IACvB,YAAY,KAAa;QACvB,KAAK,CAAC,2BAA2B,KAAK,EAAE,EAAE,gBAAgB,EAAE,GAAG,CAAC,CAAC;QACjE,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED,2DAA2D;AAC3D,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,oBAAoB,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@superbee/core/hosted-client`: the headless client of a hosted Superbee's sync route family
|
|
3
|
+
* (`/sync/v1`), a supported public API under core's normal versioning. It is runtime-neutral
|
|
4
|
+
* (`fetch` and Web streams only), so it runs in Node, a browser or a Worker.
|
|
5
|
+
*
|
|
6
|
+
* The caller supplies the target (origin and sync prefix) and an async credential provider; the
|
|
7
|
+
* client supplies identity, the bundle list, reads, history, workspace qualification, operations
|
|
8
|
+
* by id and the one-call document write over `@superbee/core/hosted-transport`, and throws typed
|
|
9
|
+
* errors only.
|
|
10
|
+
*
|
|
11
|
+
* Export download is Node-only (its verification needs Node), so it is the separate
|
|
12
|
+
* `@superbee/core/hosted-client/node`; nothing here imports it.
|
|
13
|
+
*/
|
|
14
|
+
export { bearerCredentials, createHostedClient, qualifyingCarrier, syncRoutePrefix, type HostedClient, type HostedClientOptions, type HostedClientTarget, type HostedCredentialProvider, type HostedIdentity, type HostedRunOptions, type HostedWorkspace, } from "./client.js";
|
|
15
|
+
export { BUNDLE_LIST_CAP, readBundleListing, type HostedBundleListing, type HostedBundleRow, type HostedListedBundle, } from "./bundle-listing.js";
|
|
16
|
+
export { hostedBundleReferenceText, isWorkspaceSlug, parseHostedBundleReference, type HostedBundleReference, } from "./reference.js";
|
|
17
|
+
export { checkoutBindingDigest } from "./binding.js";
|
|
18
|
+
export { createMemoryIntentStore, HostedIntentsNotListable, INTENTS_NOT_LISTABLE, type HostedIntentStore, type HostedWriteInput, type HostedWriteIntent, type HostedWriteLookupResult, type HostedWriteOptions, type HostedWriteRefusalCode, type HostedWriteResult, } from "./write.js";
|
|
19
|
+
export { HostedRouteNotServed, isRouteNotServed, ROUTE_NOT_SERVED } from "./errors.js";
|
|
20
|
+
export { MALFORMED_ANSWER, MalformedAnswer, RemoteError, isMalformedAnswer } from "../remote-error.js";
|
|
21
|
+
export { HostedAnswerTooLarge, HostedCarrierError, isAnswerTooLarge } from "../hosted-transport/carrier.js";
|
|
22
|
+
export { performHostedBlobDelivery, type HostedBlobDeliveryContext, type HostedBlobDeliveryOptions, type HostedBlobDeliveryOutcome, type HostedBlobDeliveryResult, } from "./blob-delivery.js";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hosted-client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,yBAAyB,EACzB,eAAe,EACf,0BAA0B,EAC1B,KAAK,qBAAqB,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,GACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGvF,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvG,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAC5G,OAAO,EACL,yBAAyB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,GAC9B,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@superbee/core/hosted-client`: the headless client of a hosted Superbee's sync route family
|
|
3
|
+
* (`/sync/v1`), a supported public API under core's normal versioning. It is runtime-neutral
|
|
4
|
+
* (`fetch` and Web streams only), so it runs in Node, a browser or a Worker.
|
|
5
|
+
*
|
|
6
|
+
* The caller supplies the target (origin and sync prefix) and an async credential provider; the
|
|
7
|
+
* client supplies identity, the bundle list, reads, history, workspace qualification, operations
|
|
8
|
+
* by id and the one-call document write over `@superbee/core/hosted-transport`, and throws typed
|
|
9
|
+
* errors only.
|
|
10
|
+
*
|
|
11
|
+
* Export download is Node-only (its verification needs Node), so it is the separate
|
|
12
|
+
* `@superbee/core/hosted-client/node`; nothing here imports it.
|
|
13
|
+
*/
|
|
14
|
+
export { bearerCredentials, createHostedClient, qualifyingCarrier, syncRoutePrefix, } from "./client.js";
|
|
15
|
+
export { BUNDLE_LIST_CAP, readBundleListing, } from "./bundle-listing.js";
|
|
16
|
+
export { hostedBundleReferenceText, isWorkspaceSlug, parseHostedBundleReference, } from "./reference.js";
|
|
17
|
+
export { checkoutBindingDigest } from "./binding.js";
|
|
18
|
+
export { createMemoryIntentStore, HostedIntentsNotListable, INTENTS_NOT_LISTABLE, } from "./write.js";
|
|
19
|
+
export { HostedRouteNotServed, isRouteNotServed, ROUTE_NOT_SERVED } from "./errors.js";
|
|
20
|
+
// The other typed failures, re-exported (same identities) so a caller can tell them apart from
|
|
21
|
+
// this one subpath.
|
|
22
|
+
export { MALFORMED_ANSWER, MalformedAnswer, RemoteError, isMalformedAnswer } from "../remote-error.js";
|
|
23
|
+
export { HostedAnswerTooLarge, HostedCarrierError, isAnswerTooLarge } from "../hosted-transport/carrier.js";
|
|
24
|
+
export { performHostedBlobDelivery, } from "./blob-delivery.js";
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hosted-client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,GAQhB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,iBAAiB,GAIlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,yBAAyB,EACzB,eAAe,EACf,0BAA0B,GAE3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,GAQrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACvF,+FAA+F;AAC/F,oBAAoB;AACpB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvG,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAC5G,OAAO,EACL,yBAAyB,GAK1B,MAAM,oBAAoB,CAAC"}
|