@opendatalabs/personal-server-ts-core 0.0.1-canary.def4ff7 → 0.0.1-canary.df07ce2
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/dist/api/index.d.ts +55 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +246 -16
- package/dist/api/index.js.map +1 -1
- package/dist/contracts/data.d.ts +37 -5
- package/dist/contracts/data.d.ts.map +1 -1
- package/dist/contracts/data.js +105 -26
- package/dist/contracts/data.js.map +1 -1
- package/dist/contracts/index.d.ts +1 -1
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/errors/pdpp-catalog.d.ts +1 -1
- package/dist/errors/pdpp-catalog.d.ts.map +1 -1
- package/dist/errors/pdpp-catalog.js +4 -0
- package/dist/errors/pdpp-catalog.js.map +1 -1
- package/dist/grants/index.d.ts +2 -2
- package/dist/grants/index.d.ts.map +1 -1
- package/dist/grants/index.js +2 -2
- package/dist/grants/index.js.map +1 -1
- package/dist/grants/pdpp-binding-store.d.ts +33 -2
- package/dist/grants/pdpp-binding-store.d.ts.map +1 -1
- package/dist/grants/pdpp-binding-store.js +45 -30
- package/dist/grants/pdpp-binding-store.js.map +1 -1
- package/dist/grants/pdpp-binding.d.ts +55 -65
- package/dist/grants/pdpp-binding.d.ts.map +1 -1
- package/dist/grants/pdpp-binding.js +94 -72
- package/dist/grants/pdpp-binding.js.map +1 -1
- package/dist/pdpp/approval.d.ts +92 -3
- package/dist/pdpp/approval.d.ts.map +1 -1
- package/dist/pdpp/approval.js +145 -15
- package/dist/pdpp/approval.js.map +1 -1
- package/dist/pdpp/client-identity.d.ts.map +1 -1
- package/dist/pdpp/client-identity.js +15 -2
- package/dist/pdpp/client-identity.js.map +1 -1
- package/dist/pdpp/commitments.d.ts +75 -0
- package/dist/pdpp/commitments.d.ts.map +1 -0
- package/dist/pdpp/commitments.js +113 -0
- package/dist/pdpp/commitments.js.map +1 -0
- package/dist/pdpp/declaration.d.ts +1 -1
- package/dist/pdpp/declaration.d.ts.map +1 -1
- package/dist/pdpp/declaration.js +287 -0
- package/dist/pdpp/declaration.js.map +1 -1
- package/dist/pdpp/index.d.ts +7 -5
- package/dist/pdpp/index.d.ts.map +1 -1
- package/dist/pdpp/index.js +3 -2
- package/dist/pdpp/index.js.map +1 -1
- package/dist/pdpp/issuance.d.ts +38 -3
- package/dist/pdpp/issuance.d.ts.map +1 -1
- package/dist/pdpp/issuance.js +72 -16
- package/dist/pdpp/issuance.js.map +1 -1
- package/dist/pdpp/resolve.d.ts +59 -3
- package/dist/pdpp/resolve.d.ts.map +1 -1
- package/dist/pdpp/resolve.js +202 -27
- package/dist/pdpp/resolve.js.map +1 -1
- package/dist/pdpp/review.d.ts +126 -1
- package/dist/pdpp/review.d.ts.map +1 -1
- package/dist/pdpp/review.js +83 -20
- package/dist/pdpp/review.js.map +1 -1
- package/dist/pdpp/selection.d.ts +8 -1
- package/dist/pdpp/selection.d.ts.map +1 -1
- package/dist/pdpp/selection.js +258 -27
- package/dist/pdpp/selection.js.map +1 -1
- package/dist/pdpp/store.d.ts +24 -0
- package/dist/pdpp/store.d.ts.map +1 -1
- package/dist/pdpp/store.js +45 -4
- package/dist/pdpp/store.js.map +1 -1
- package/dist/pdpp/tokens.d.ts +33 -1
- package/dist/pdpp/tokens.d.ts.map +1 -1
- package/dist/pdpp/tokens.js +34 -2
- package/dist/pdpp/tokens.js.map +1 -1
- package/dist/pdpp/types.d.ts +187 -4
- package/dist/pdpp/types.d.ts.map +1 -1
- package/dist/pdpp/types.js +22 -1
- package/dist/pdpp/types.js.map +1 -1
- package/dist/ports/index.d.ts +16 -0
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/pdpp-auth.d.ts +26 -0
- package/dist/ports/pdpp-auth.d.ts.map +1 -1
- package/dist/ports/pdpp-auth.js +23 -0
- package/dist/ports/pdpp-auth.js.map +1 -1
- package/dist/schemas/server-config.d.ts +20 -2
- package/dist/schemas/server-config.d.ts.map +1 -1
- package/dist/schemas/server-config.js +43 -1
- package/dist/schemas/server-config.js.map +1 -1
- package/dist/storage/index/manager.d.ts +29 -2
- package/dist/storage/index/manager.d.ts.map +1 -1
- package/dist/storage/index/schema.d.ts +1 -1
- package/dist/storage/index/schema.js +1 -1
- package/dist/storage/index/types.d.ts +7 -1
- package/dist/storage/index/types.d.ts.map +1 -1
- package/dist/storage/pdpp-records/cursor.d.ts +14 -0
- package/dist/storage/pdpp-records/cursor.d.ts.map +1 -1
- package/dist/storage/pdpp-records/cursor.js.map +1 -1
- package/dist/storage/pdpp-records/enforcement.d.ts +15 -0
- package/dist/storage/pdpp-records/enforcement.d.ts.map +1 -1
- package/dist/storage/pdpp-records/enforcement.js +40 -3
- package/dist/storage/pdpp-records/enforcement.js.map +1 -1
- package/dist/storage/pdpp-records/index.d.ts +1 -0
- package/dist/storage/pdpp-records/index.d.ts.map +1 -1
- package/dist/storage/pdpp-records/index.js +1 -0
- package/dist/storage/pdpp-records/index.js.map +1 -1
- package/dist/storage/pdpp-records/ingest-plan.d.ts +39 -0
- package/dist/storage/pdpp-records/ingest-plan.d.ts.map +1 -0
- package/dist/storage/pdpp-records/ingest-plan.js +103 -0
- package/dist/storage/pdpp-records/ingest-plan.js.map +1 -0
- package/dist/storage/pdpp-records/interface.d.ts +72 -17
- package/dist/storage/pdpp-records/interface.d.ts.map +1 -1
- package/dist/storage/pdpp-records/memory-store.d.ts.map +1 -1
- package/dist/storage/pdpp-records/memory-store.js +0 -0
- package/dist/storage/pdpp-records/memory-store.js.map +1 -1
- package/dist/storage/pdpp-records/stream-declaration.d.ts +46 -1
- package/dist/storage/pdpp-records/stream-declaration.d.ts.map +1 -1
- package/dist/storage/pdpp-records/stream-declaration.js +40 -0
- package/dist/storage/pdpp-records/stream-declaration.js.map +1 -1
- package/dist/storage/pdpp-records/types.d.ts +46 -1
- package/dist/storage/pdpp-records/types.d.ts.map +1 -1
- package/dist/storage/pdpp-records/types.js +21 -0
- package/dist/storage/pdpp-records/types.js.map +1 -1
- package/dist/sync/pdpp-import.d.ts +1 -1
- package/dist/sync/pdpp-import.d.ts.map +1 -1
- package/dist/sync/pdpp-import.js +20 -1
- package/dist/sync/pdpp-import.js.map +1 -1
- package/dist/sync/workers/download.d.ts.map +1 -1
- package/dist/sync/workers/download.js +9 -1
- package/dist/sync/workers/download.js.map +1 -1
- package/dist/test-utils/memory-storage.d.ts +1 -1
- package/dist/test-utils/memory-storage.d.ts.map +1 -1
- package/dist/test-utils/memory-storage.js +11 -5
- package/dist/test-utils/memory-storage.js.map +1 -1
- package/package.json +1 -1
package/dist/api/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { DataReadPolicyPorts } from "../policy/index.js";
|
|
|
5
5
|
import type { SyncManager } from "../sync/index.js";
|
|
6
6
|
import { type ScopeDeletionTracker } from "../sync/scope-deletions.js";
|
|
7
7
|
import type { IndexEntry } from "../storage/index/types.js";
|
|
8
|
+
import { type PdppImporter } from "../sync/pdpp-import.js";
|
|
8
9
|
import { type DeleteScopeResult } from "../sync/workers/delete.js";
|
|
9
10
|
import { type OAuthDeviceSessionLookup, type OAuthTokenStorePort } from "../contracts/index.js";
|
|
10
11
|
import type { DataFileEnvelope, DataPortabilityGatewayConfig, GatewayClient } from "@opendatalabs/vana-sdk/browser";
|
|
@@ -34,6 +35,11 @@ export interface PersonalServerWriteAuthInput {
|
|
|
34
35
|
* same precedence as the owner write path). */
|
|
35
36
|
scope: string;
|
|
36
37
|
}
|
|
38
|
+
export interface PersonalServerScopeAuthInput {
|
|
39
|
+
request: Request;
|
|
40
|
+
/** Raw scope path param; auth ports that need scope binding validate it. */
|
|
41
|
+
scope: string;
|
|
42
|
+
}
|
|
37
43
|
/**
|
|
38
44
|
* Result of authorizing a DELEGATED (write-session) write. A void return
|
|
39
45
|
* means the request was authorized as the owner instead — the ingest then
|
|
@@ -112,6 +118,11 @@ export interface PersonalServerReadFulfillmentReporter {
|
|
|
112
118
|
export interface PersonalServerApiAuthPort {
|
|
113
119
|
authorizeOwner(request: Request): Promise<void>;
|
|
114
120
|
authorizeBuilderList(request: Request): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Authorize listing versions for one legacy scope. Optional so auth ports
|
|
123
|
+
* without scoped owner-token support keep the existing builder-list gate.
|
|
124
|
+
*/
|
|
125
|
+
authorizeScopeVersions?(input: PersonalServerScopeAuthInput): Promise<void>;
|
|
115
126
|
authorizeBuilderRead(input: PersonalServerReadAuthInput): Promise<PersonalServerReadAuthResult | void>;
|
|
116
127
|
/**
|
|
117
128
|
* Authorize a data ingest (POST /v1/data/:scope). Optional — auth ports
|
|
@@ -247,6 +258,25 @@ export interface PersonalServerDataApiDeps {
|
|
|
247
258
|
/** The stamped `$lineage.sources` of the written record, if any. */
|
|
248
259
|
lineageSources?: string[];
|
|
249
260
|
}) => void;
|
|
261
|
+
/**
|
|
262
|
+
* Import a locally-ingested envelope into the PDPP record store, when the
|
|
263
|
+
* deployment mounted one.
|
|
264
|
+
*
|
|
265
|
+
* The same importer, the same envelope shape and the same best-effort
|
|
266
|
+
* contract as the download worker's (`sync/workers/download.ts`). It is
|
|
267
|
+
* here because a `$pdpp`-annotated envelope can reach this server two ways
|
|
268
|
+
* — pulled from the gateway by sync, or POSTed to `/v1/data/:scope` by a
|
|
269
|
+
* local owner-authenticated producer — and only the first offered it to the
|
|
270
|
+
* importer. A record that arrived by the second route was stored and
|
|
271
|
+
* indexed but never became readable over the PDPP resource surface, which
|
|
272
|
+
* made a local producer's write silently half-land.
|
|
273
|
+
*
|
|
274
|
+
* Runs AFTER the legacy write and index, never in place of them, and a
|
|
275
|
+
* failure is logged and swallowed: the record is already durable by the
|
|
276
|
+
* time this runs, so throwing would turn a committed write into a 500 and
|
|
277
|
+
* invite a duplicate on retry.
|
|
278
|
+
*/
|
|
279
|
+
pdppImporter?: PdppImporter;
|
|
250
280
|
/**
|
|
251
281
|
* Called on GET /v1/data/:scope once the read is authorized (a live grant
|
|
252
282
|
* covering the scope, or the owner) and the scope is not tombstoned, and
|
|
@@ -294,6 +324,31 @@ export interface PersonalServerOauthTokenApiDeps {
|
|
|
294
324
|
export interface PersonalServerApiDispatchOptions {
|
|
295
325
|
basePath?: string;
|
|
296
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* What a 500 out of this layer must leave behind.
|
|
329
|
+
*
|
|
330
|
+
* These handlers run INSIDE the Hono app, so an error they catch never
|
|
331
|
+
* reaches the framework's `onError` — which is the one place that used to
|
|
332
|
+
* log. The result was that any unexpected fault on `/v1/data` answered a
|
|
333
|
+
* bare `INTERNAL_ERROR` and left nothing in stdout, nothing in the access
|
|
334
|
+
* log, and nothing for an operator to work from. Diagnosing one meant
|
|
335
|
+
* patching the server.
|
|
336
|
+
*
|
|
337
|
+
* Deliberately no request body, no headers, no query string and no
|
|
338
|
+
* authorization material: the route and method are the diagnostic value, and
|
|
339
|
+
* a grant id or signed header in a log file is a credential at rest. The
|
|
340
|
+
* request id is minted here when the caller did not supply one so the log
|
|
341
|
+
* line and the response can always be correlated.
|
|
342
|
+
*/
|
|
343
|
+
export interface ApiErrorLogContext {
|
|
344
|
+
logger?: PersonalServerApiLogger;
|
|
345
|
+
/** Stable route label, e.g. `GET /v1/data/:scope`. Never the raw path. */
|
|
346
|
+
route: string;
|
|
347
|
+
/** Correlates the log line with the response. Minted if absent. */
|
|
348
|
+
requestId?: string;
|
|
349
|
+
/** Non-secret route parameters worth having in the line (e.g. scope). */
|
|
350
|
+
detail?: Record<string, string | undefined>;
|
|
351
|
+
}
|
|
297
352
|
/**
|
|
298
353
|
* The grant the caller nominates for a read: `?grantId=` or the
|
|
299
354
|
* `x-ps-grant-id` header, the SDK's shape on every read route. Exported so
|
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0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BAA6B,GACnC,IAAI,CAIN;AAmED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,4BAA4B,GAAG,IAAI,GAC9C,OAAO,CAMT;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,gBAAgB,GACzB,gBAAgB,CAqClB;AAED,OAAO,EAAE,iCAAiC,EAAE,MAAM,mBAAmB,CAAC;AAEtE,wBAAsB,+BAA+B,CACnD,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,yBAAyB,EAC/B,OAAO,GAAE,gCAAqC,GAC7C,OAAO,CAAC,QAAQ,CAAC,CA6sBnB;AAED,wBAAsB,qCAAqC,CACzD,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,+BAA+B,EACrC,OAAO,GAAE,gCAAqC,GAC7C,OAAO,CAAC,QAAQ,CAAC,CAenB;AAED,wBAAsB,+BAA+B,CACnD,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,yBAAyB,EAC/B,OAAO,GAAE,gCAAqC,GAC7C,OAAO,CAAC,QAAQ,CAAC,CAyCnB;AAED,wBAAsB,iCAAiC,CACrD,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,2BAA2B,EACjC,OAAO,GAAE,gCAAqC,GAC7C,OAAO,CAAC,QAAQ,CAAC,CAyEnB;AAED,wBAAsB,iCAAiC,CACrD,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC,QAAQ,CAAC,CA8BnB;AAED,wBAAsB,qCAAqC,CACzD,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,+BAA+B,GACpC,OAAO,CAAC,QAAQ,CAAC,CA6BnB;AAED,YAAY,EAAE,mBAAmB,EAAE,CAAC"}
|
package/dist/api/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DataDeletedError, DeleteTombstoneFailedError, GrantRequiredError, InvalidCascadeError, LineageCascadeUnavailableError, LineageGatewayError, LineageUnavailableError, ProtocolError, ServerNotConfiguredError, } from "../errors/catalog.js";
|
|
2
2
|
import { computeDataPointId } from "../sync/data-point-id.js";
|
|
3
3
|
import { isEntryCoveredByTombstone, } from "../sync/scope-deletions.js";
|
|
4
|
+
import { isPermanentRejection, } from "../sync/pdpp-import.js";
|
|
4
5
|
import { deleteScope as deleteScopeLocally, } from "../sync/workers/delete.js";
|
|
5
|
-
import { ingestDataContract, ingestBinaryDataContract, listAccessLogsContract, listDataScopesContract, listDataVersionsContract, parseDataScopeContract, parseJsonObjectBody, readDataContract, syncFileContract, triggerSyncContract, getSyncStatusContract, configReadErrorContract, configWriteErrorContract, createGrantContract, listGrantsContract, oauthTokenContract, revokeGrantContract, validateServerConfigContract, verifyGrantContract, decodeBinaryEnvelope, isBinaryEnvelope, parseMetadataHeader, stringifyMetadataHeader, IngestPersistedError, } from "../contracts/index.js";
|
|
6
|
+
import { ingestDataContract, ingestBinaryDataContract, listAccessLogsContract, listDataScopesContract, listDataVersionsContract, parseDataScopeContract, parseJsonObjectBody, readDataContract, syncFileContract, triggerSyncContract, getSyncStatusContract, configReadErrorContract, configWriteErrorContract, createGrantContract, listGrantsContract, oauthTokenContract, revokeGrantContract, validateServerConfigContract, verifyGrantContract, decodeBinaryEnvelope, isBinaryEnvelope, parseMetadataHeader, stringifyMetadataHeader, IngestPersistedError, sha256Hex, } from "../contracts/index.js";
|
|
7
|
+
import { canonicalJsonBytes } from "../derivatives/e2ee/jcs.js";
|
|
6
8
|
import { WRITER_ATTRIBUTION_KEY, } from "../write/attribution.js";
|
|
7
9
|
import { extractLineageField, LINEAGE_KEY, prepareLineage, } from "../lineage/lineage.js";
|
|
8
10
|
import { binaryFilename, binaryMimeType, isJsonContentType, } from "../contracts/binary.js";
|
|
@@ -58,17 +60,80 @@ function methodNotAllowed() {
|
|
|
58
60
|
function notFound() {
|
|
59
61
|
return errorResponse(404, "NOT_FOUND", "Not found");
|
|
60
62
|
}
|
|
61
|
-
async function withApiErrors(handler) {
|
|
63
|
+
async function withApiErrors(handler, context) {
|
|
62
64
|
try {
|
|
63
|
-
|
|
65
|
+
const response = await handler();
|
|
66
|
+
// A handled 4xx that means "the index and the disk disagree" is an
|
|
67
|
+
// operator-facing fault even though it is not a 500 — log it once, here,
|
|
68
|
+
// rather than at the contract that cannot see the route.
|
|
69
|
+
if (response.status === 404 && context) {
|
|
70
|
+
await logMissingDataFile(response, context);
|
|
71
|
+
}
|
|
72
|
+
return response;
|
|
64
73
|
}
|
|
65
74
|
catch (err) {
|
|
66
75
|
if (err instanceof ProtocolError) {
|
|
67
76
|
return protocolErrorResponse(err);
|
|
68
77
|
}
|
|
78
|
+
if (context) {
|
|
79
|
+
context.logger?.error?.({
|
|
80
|
+
route: context.route,
|
|
81
|
+
requestId: context.requestId ?? crypto.randomUUID(),
|
|
82
|
+
errorCode: "INTERNAL_ERROR",
|
|
83
|
+
...stripUndefined(context.detail),
|
|
84
|
+
err: describeError(err),
|
|
85
|
+
}, "Unhandled error in personal server API");
|
|
86
|
+
}
|
|
69
87
|
return errorResponse(500, "INTERNAL_ERROR", "Internal server error");
|
|
70
88
|
}
|
|
71
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* The `DATA_FILE_MISSING` 404 the read contract produces, logged at the one
|
|
92
|
+
* layer that knows which route served it. Peeks at a clone so the response
|
|
93
|
+
* body stays readable by the caller.
|
|
94
|
+
*/
|
|
95
|
+
async function logMissingDataFile(response, context) {
|
|
96
|
+
if (!context.logger?.error)
|
|
97
|
+
return;
|
|
98
|
+
try {
|
|
99
|
+
const body = await response.clone().json();
|
|
100
|
+
if (typeof body !== "object" ||
|
|
101
|
+
body === null ||
|
|
102
|
+
body.error !== "DATA_FILE_MISSING") {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
context.logger.error({
|
|
106
|
+
route: context.route,
|
|
107
|
+
requestId: context.requestId ?? crypto.randomUUID(),
|
|
108
|
+
errorCode: "DATA_FILE_MISSING",
|
|
109
|
+
...stripUndefined(context.detail),
|
|
110
|
+
}, "Indexed data file is missing on disk");
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// A diagnostic log must not change the response sent to the caller.
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* An error rendered for a log line — name, message and stack only. Never the
|
|
118
|
+
* whole object: a thrown error can carry a request, a config or a token on an
|
|
119
|
+
* arbitrary property, and a structured logger would serialize all of it.
|
|
120
|
+
*/
|
|
121
|
+
function describeError(err) {
|
|
122
|
+
if (err instanceof Error) {
|
|
123
|
+
return {
|
|
124
|
+
name: err.name,
|
|
125
|
+
message: err.message,
|
|
126
|
+
...("code" in err && { code: err.code }),
|
|
127
|
+
stack: err.stack,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return { message: String(err) };
|
|
131
|
+
}
|
|
132
|
+
function stripUndefined(detail) {
|
|
133
|
+
if (!detail)
|
|
134
|
+
return {};
|
|
135
|
+
return Object.fromEntries(Object.entries(detail).filter((pair) => pair[1] !== undefined));
|
|
136
|
+
}
|
|
72
137
|
function normalizeLimit(value, fallback) {
|
|
73
138
|
if (value === null)
|
|
74
139
|
return fallback;
|
|
@@ -262,10 +327,83 @@ export async function handleX402Cycle(input) {
|
|
|
262
327
|
}
|
|
263
328
|
return { kind: "gateway-error", status: gatewayRes.status, body: errorBody };
|
|
264
329
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
330
|
+
const lastCollectedAtByStorage = new WeakMap();
|
|
331
|
+
function collectedAt(now, storage, scope) {
|
|
332
|
+
// Further writes in the same second need distinct paths so no version is
|
|
333
|
+
// overwritten. Use one timestamp format so lexical ordering remains valid.
|
|
334
|
+
const second = Math.floor(now().getTime() / 1000) * 1000;
|
|
335
|
+
// The process-local clock resets on restart. Consult the durable head so a
|
|
336
|
+
// same-second restart cannot reuse a committed envelope path.
|
|
337
|
+
const latest = Date.parse(storage.findEntry({ scope })?.collectedAt ?? "");
|
|
338
|
+
const current = Math.max(second, (lastCollectedAtByStorage.get(storage) ?? 0) + 1, Number.isFinite(latest) ? latest + 1 : 0);
|
|
339
|
+
lastCollectedAtByStorage.set(storage, current);
|
|
340
|
+
return new Date(current).toISOString();
|
|
341
|
+
}
|
|
342
|
+
function parseLegacyPrecondition(request) {
|
|
343
|
+
const none = request.headers.get("if-none-match");
|
|
344
|
+
const match = request.headers.get("if-match");
|
|
345
|
+
if (none !== null && match !== null) {
|
|
346
|
+
return errorResponse(400, "INVALID_PRECONDITION", "Supply only one precondition");
|
|
347
|
+
}
|
|
348
|
+
if (none !== null) {
|
|
349
|
+
return none === "*"
|
|
350
|
+
? { kind: "none" }
|
|
351
|
+
: errorResponse(400, "INVALID_PRECONDITION", "If-None-Match must be *");
|
|
352
|
+
}
|
|
353
|
+
if (match !== null) {
|
|
354
|
+
const parsed = /^"([1-9]\d*)"$/.exec(match);
|
|
355
|
+
const version = parsed ? Number(parsed[1]) : NaN;
|
|
356
|
+
return Number.isSafeInteger(version)
|
|
357
|
+
? { kind: "match", version }
|
|
358
|
+
: errorResponse(400, "INVALID_PRECONDITION", "If-Match must be a quoted positive version");
|
|
359
|
+
}
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
function parseProducerHeader(request) {
|
|
363
|
+
const producer = request.headers.get("vana-producer");
|
|
364
|
+
const encodedProvenance = request.headers.get("vana-producer-provenance") ?? undefined;
|
|
365
|
+
if (producer === null && !encodedProvenance)
|
|
366
|
+
return {};
|
|
367
|
+
if (producer !== "pdpp-projector" && producer !== "pdpp-import-projection") {
|
|
368
|
+
return errorResponse(400, "INVALID_PRODUCER", "Vana-Producer is unrecognized or missing");
|
|
369
|
+
}
|
|
370
|
+
if (encodedProvenance &&
|
|
371
|
+
(encodedProvenance.length > 8192 ||
|
|
372
|
+
!/^[A-Za-z0-9_-]+$/.test(encodedProvenance))) {
|
|
373
|
+
return errorResponse(400, "INVALID_PROVENANCE", "Vana-Producer-Provenance is malformed");
|
|
374
|
+
}
|
|
375
|
+
return { producer, encodedProvenance };
|
|
376
|
+
}
|
|
377
|
+
async function parseProducerProvenance(encoded, body) {
|
|
378
|
+
if (!encoded)
|
|
379
|
+
return undefined;
|
|
380
|
+
try {
|
|
381
|
+
const value = JSON.parse(new TextDecoder().decode(Uint8Array.from(atob(encoded.replace(/-/g, "+").replace(/_/g, "/")), (char) => char.charCodeAt(0))));
|
|
382
|
+
if (!value ||
|
|
383
|
+
typeof value !== "object" ||
|
|
384
|
+
typeof value.projector_version !== "string" ||
|
|
385
|
+
!value.projector_version ||
|
|
386
|
+
typeof value.declaration_digest !== "string" ||
|
|
387
|
+
!value.declaration_digest ||
|
|
388
|
+
!Array.isArray(value.inputs) ||
|
|
389
|
+
!value.inputs.every((input) => input &&
|
|
390
|
+
typeof input.stream === "string" &&
|
|
391
|
+
input.stream &&
|
|
392
|
+
typeof input.changes_since_token === "string" &&
|
|
393
|
+
input.changes_since_token) ||
|
|
394
|
+
typeof value.payload_sha256 !== "string" ||
|
|
395
|
+
!/^(?:0x)?[0-9a-fA-F]{64}$/.test(value.payload_sha256)) {
|
|
396
|
+
return errorResponse(400, "INVALID_PROVENANCE", "Producer provenance has invalid fields");
|
|
397
|
+
}
|
|
398
|
+
const actual = (await sha256Hex(canonicalJsonBytes(body))).slice(2);
|
|
399
|
+
if (actual !== value.payload_sha256.replace(/^0x/, "").toLowerCase()) {
|
|
400
|
+
return errorResponse(400, "PAYLOAD_HASH_MISMATCH", "Provenance payload_sha256 does not match the JSON body");
|
|
401
|
+
}
|
|
402
|
+
return value;
|
|
403
|
+
}
|
|
404
|
+
catch {
|
|
405
|
+
return errorResponse(400, "INVALID_PROVENANCE", "Vana-Producer-Provenance is not base64url JSON");
|
|
406
|
+
}
|
|
269
407
|
}
|
|
270
408
|
/**
|
|
271
409
|
* The deletion that applies to a read of `scope`, or null when the read may
|
|
@@ -339,12 +477,11 @@ async function ingestTombstoneMarker(deps, scope) {
|
|
|
339
477
|
}
|
|
340
478
|
// The delete worker wants a full Logger; the API logger is all-optional.
|
|
341
479
|
function apiLoggerAsLogger(logger) {
|
|
342
|
-
const noop = () => undefined;
|
|
343
480
|
return {
|
|
344
|
-
debug: (payload, message) =>
|
|
345
|
-
info: (payload, message) =>
|
|
346
|
-
warn: (payload, message) =>
|
|
347
|
-
error: (payload, message) =>
|
|
481
|
+
debug: (payload, message) => logger?.debug?.(payload, message ?? ""),
|
|
482
|
+
info: (payload, message) => logger?.info?.(payload, message ?? ""),
|
|
483
|
+
warn: (payload, message) => logger?.warn?.(payload, message ?? ""),
|
|
484
|
+
error: (payload, message) => logger?.error?.(payload, message ?? ""),
|
|
348
485
|
};
|
|
349
486
|
}
|
|
350
487
|
function notifyDataWritten(deps, event) {
|
|
@@ -360,6 +497,50 @@ function notifyDataWritten(deps, event) {
|
|
|
360
497
|
}, "onDataWritten hook failed; record already stored");
|
|
361
498
|
}
|
|
362
499
|
}
|
|
500
|
+
/**
|
|
501
|
+
* Offer a just-ingested envelope to the PDPP importer.
|
|
502
|
+
*
|
|
503
|
+
* The local-ingest twin of the download worker's `importIntoPdpp`, and
|
|
504
|
+
* deliberately the same shape: same `ImportableEnvelope`, same total handling
|
|
505
|
+
* of every outcome, same permanent-vs-transient logging split. Keeping the
|
|
506
|
+
* two symmetric is the point — a `$pdpp` envelope must mean the same thing
|
|
507
|
+
* and reach the same store whether the gateway handed it over or a local
|
|
508
|
+
* producer POSTed it, otherwise "imported" would depend on which door the
|
|
509
|
+
* bytes came through.
|
|
510
|
+
*
|
|
511
|
+
* `skipped` is the ordinary legacy case (no `$pdpp` block) and stays silent.
|
|
512
|
+
* A rejection is a WARNING, not an error: it means the producer sent
|
|
513
|
+
* something this deployment could not verify — actionable, but not a failure
|
|
514
|
+
* of the write, which has already committed.
|
|
515
|
+
*/
|
|
516
|
+
function importIngestedIntoPdpp(deps, envelope) {
|
|
517
|
+
if (!deps.pdppImporter)
|
|
518
|
+
return;
|
|
519
|
+
try {
|
|
520
|
+
const outcome = deps.pdppImporter.importEnvelope(envelope);
|
|
521
|
+
if (outcome.status === "rejected") {
|
|
522
|
+
const permanent = isPermanentRejection(outcome.rejection);
|
|
523
|
+
deps.logger?.warn?.({
|
|
524
|
+
scope: envelope.scope,
|
|
525
|
+
collectedAt: envelope.collectedAt,
|
|
526
|
+
code: outcome.rejection.code,
|
|
527
|
+
message: outcome.rejection.message,
|
|
528
|
+
permanent,
|
|
529
|
+
}, permanent
|
|
530
|
+
? "Ingested data point was refused by the PDPP importer and will not be retried"
|
|
531
|
+
: "PDPP import unavailable for this ingested data point");
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
catch (err) {
|
|
535
|
+
// A throwing importer is infrastructure failing, not the envelope being
|
|
536
|
+
// wrong. The record is stored and indexed already, so this must never
|
|
537
|
+
// turn a committed write into a 500.
|
|
538
|
+
deps.logger?.warn?.({
|
|
539
|
+
scope: envelope.scope,
|
|
540
|
+
error: err instanceof Error ? err.message : String(err),
|
|
541
|
+
}, "PDPP import threw on ingest; record already stored and indexed");
|
|
542
|
+
}
|
|
543
|
+
}
|
|
363
544
|
function notifyDataRead(deps, event) {
|
|
364
545
|
if (!deps.onDataRead)
|
|
365
546
|
return;
|
|
@@ -517,6 +698,15 @@ export function redactEnvelopeForGrantee(envelope) {
|
|
|
517
698
|
}
|
|
518
699
|
export { redactJsonEnvelopeBytesForGrantee } from "./raw-envelope.js";
|
|
519
700
|
export async function handlePersonalServerDataRequest(request, deps, options = {}) {
|
|
701
|
+
// Filled in as the dispatch narrows, so a 500 thrown deep in a read is
|
|
702
|
+
// logged against the route that served it rather than a generic label. It
|
|
703
|
+
// is mutable for exactly that reason: the route is not known until the path
|
|
704
|
+
// has been parsed, and by then we are already inside the try.
|
|
705
|
+
const logContext = {
|
|
706
|
+
logger: deps.logger,
|
|
707
|
+
route: `${request.method} ${options.basePath ?? "/v1/data"}`,
|
|
708
|
+
requestId: crypto.randomUUID(),
|
|
709
|
+
};
|
|
520
710
|
return withApiErrors(async () => {
|
|
521
711
|
const url = new URL(request.url);
|
|
522
712
|
const pathname = stripBasePath(url.pathname, options.basePath);
|
|
@@ -537,7 +727,15 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
537
727
|
if (parts.length === 2 && parts[1] === "versions") {
|
|
538
728
|
if (request.method !== "GET")
|
|
539
729
|
return methodNotAllowed();
|
|
540
|
-
|
|
730
|
+
if (deps.auth.authorizeScopeVersions) {
|
|
731
|
+
await deps.auth.authorizeScopeVersions({
|
|
732
|
+
request,
|
|
733
|
+
scope: decodePathPart(parts[0]),
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
else {
|
|
737
|
+
await deps.auth.authorizeBuilderList(request);
|
|
738
|
+
}
|
|
541
739
|
const result = await listDataVersionsContract({
|
|
542
740
|
storage: deps.storage,
|
|
543
741
|
scopeParam: decodePathPart(parts[0]),
|
|
@@ -642,10 +840,12 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
642
840
|
if (parts.length !== 1)
|
|
643
841
|
return notFound();
|
|
644
842
|
const scopeParam = decodePathPart(parts[0]);
|
|
843
|
+
logContext.route = `${request.method} ${options.basePath ?? "/v1/data"}/:scope`;
|
|
645
844
|
if (request.method === "GET") {
|
|
646
845
|
const scopeResult = parseDataScopeContract(scopeParam);
|
|
647
846
|
if (!scopeResult.ok)
|
|
648
847
|
return contractErrorResponse(scopeResult);
|
|
848
|
+
logContext.detail = { scope: scopeResult.scope };
|
|
649
849
|
const selectedEntry = deps.storage.findEntry({
|
|
650
850
|
scope: scopeResult.scope,
|
|
651
851
|
fileId: url.searchParams.get("fileId") ?? undefined,
|
|
@@ -879,7 +1079,16 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
879
1079
|
const scopeResult = parseDataScopeContract(scopeParam);
|
|
880
1080
|
if (!scopeResult.ok)
|
|
881
1081
|
return failWrite(contractErrorResponse(scopeResult));
|
|
882
|
-
const
|
|
1082
|
+
const parsedPrecondition = parseLegacyPrecondition(request);
|
|
1083
|
+
if (parsedPrecondition instanceof Response)
|
|
1084
|
+
return failWrite(parsedPrecondition);
|
|
1085
|
+
const producerHeader = parseProducerHeader(request);
|
|
1086
|
+
if (producerHeader instanceof Response)
|
|
1087
|
+
return failWrite(producerHeader);
|
|
1088
|
+
if (writeAuth && producerHeader.producer) {
|
|
1089
|
+
return failWrite(errorResponse(403, "NOT_OWNER", "Only the owner may assert a producer"));
|
|
1090
|
+
}
|
|
1091
|
+
const collectedAtValue = collectedAt(deps.now ?? (() => new Date()), deps.storage, scopeResult.scope);
|
|
883
1092
|
const status = deps.syncManager ? "syncing" : "stored";
|
|
884
1093
|
const afterTombstoneVersion = await ingestTombstoneMarker(deps, scopeResult.scope);
|
|
885
1094
|
// Builder writes land in the same access log as builder reads, so the
|
|
@@ -919,6 +1128,9 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
919
1128
|
// data needs no schema at all — we ingest it schemaless. (Structured JSON
|
|
920
1129
|
// below still resolves a schema for validation/metadata.)
|
|
921
1130
|
if (!isJsonContentType(request)) {
|
|
1131
|
+
if (producerHeader.producer) {
|
|
1132
|
+
return failWrite(errorResponse(400, "INVALID_PRODUCER", "Producer attribution requires a JSON body"));
|
|
1133
|
+
}
|
|
922
1134
|
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
923
1135
|
const metadata = parseMetadataHeader(request.headers.get("x-vana-metadata"));
|
|
924
1136
|
// A binary derivative names its sources inside the metadata
|
|
@@ -936,6 +1148,7 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
936
1148
|
attribution: writeAuth?.attribution,
|
|
937
1149
|
lineage,
|
|
938
1150
|
afterTombstoneVersion,
|
|
1151
|
+
precondition: parsedPrecondition,
|
|
939
1152
|
});
|
|
940
1153
|
if (!result.ok)
|
|
941
1154
|
return failWrite(contractErrorResponse(result));
|
|
@@ -960,6 +1173,9 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
960
1173
|
const parsed = await parseJsonObjectBody(request, "Request body must be valid JSON");
|
|
961
1174
|
if (!parsed.ok)
|
|
962
1175
|
return failWrite(contractResponse(parsed.result));
|
|
1176
|
+
const provenance = await parseProducerProvenance(producerHeader.encodedProvenance, parsed.body);
|
|
1177
|
+
if (provenance instanceof Response)
|
|
1178
|
+
return failWrite(provenance);
|
|
963
1179
|
// Derivative writes: validate the caller's `lineage` before anything
|
|
964
1180
|
// is stored (a failure here throws, releasing the builder's proof).
|
|
965
1181
|
const lineage = await prepareWriteLineage(deps, scopeResult.scope, extractLineageField(parsed.body));
|
|
@@ -974,6 +1190,9 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
974
1190
|
attribution: writeAuth?.attribution,
|
|
975
1191
|
lineage,
|
|
976
1192
|
afterTombstoneVersion,
|
|
1193
|
+
precondition: parsedPrecondition,
|
|
1194
|
+
producer: producerHeader.producer,
|
|
1195
|
+
producerProvenance: provenance,
|
|
977
1196
|
});
|
|
978
1197
|
if (!result.ok)
|
|
979
1198
|
return failWrite(contractErrorResponse(result));
|
|
@@ -986,6 +1205,14 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
986
1205
|
}, "Data file ingested");
|
|
987
1206
|
await logBuilderWrite();
|
|
988
1207
|
notifyNewData(deps.syncManager);
|
|
1208
|
+
// The parsed body is the envelope's `data`, which is where a producer
|
|
1209
|
+
// stamps `$pdpp`. Offered here rather than inside the ingest contract
|
|
1210
|
+
// so the import stays strictly after the record is durable.
|
|
1211
|
+
importIngestedIntoPdpp(deps, {
|
|
1212
|
+
scope: scopeResult.scope,
|
|
1213
|
+
collectedAt: collectedAtValue,
|
|
1214
|
+
data: parsed.body,
|
|
1215
|
+
});
|
|
989
1216
|
notifyDataWritten(deps, {
|
|
990
1217
|
scope: scopeResult.scope,
|
|
991
1218
|
collectedAt: collectedAtValue,
|
|
@@ -1004,7 +1231,7 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1004
1231
|
error: err.cause instanceof Error
|
|
1005
1232
|
? err.cause.message
|
|
1006
1233
|
: String(err.cause),
|
|
1007
|
-
}, "Envelope
|
|
1234
|
+
}, "Envelope write incomplete after durable commit; boot recovery may finish it");
|
|
1008
1235
|
}
|
|
1009
1236
|
else if (!committed) {
|
|
1010
1237
|
await writeAuth?.releaseProof?.();
|
|
@@ -1087,7 +1314,7 @@ export async function handlePersonalServerDataRequest(request, deps, options = {
|
|
|
1087
1314
|
return jsonResponse(result, { status: 200 });
|
|
1088
1315
|
}
|
|
1089
1316
|
return methodNotAllowed();
|
|
1090
|
-
});
|
|
1317
|
+
}, logContext);
|
|
1091
1318
|
}
|
|
1092
1319
|
export async function handlePersonalServerAccessLogsRequest(request, deps, options = {}) {
|
|
1093
1320
|
return withApiErrors(async () => {
|
|
@@ -1133,6 +1360,9 @@ export async function handlePersonalServerSyncRequest(request, deps, options = {
|
|
|
1133
1360
|
}));
|
|
1134
1361
|
}
|
|
1135
1362
|
return notFound();
|
|
1363
|
+
}, {
|
|
1364
|
+
logger: deps.logger,
|
|
1365
|
+
route: `${request.method} ${options.basePath ?? "/v1/sync"}`,
|
|
1136
1366
|
});
|
|
1137
1367
|
}
|
|
1138
1368
|
export async function handlePersonalServerGrantsRequest(request, deps, options = {}) {
|