@adcp/sdk 16.0.0-beta.3 → 16.0.0-beta.5
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/lib/auth/oauth/diagnose.js +3 -11
- package/dist/lib/auth/oauth/diagnose.mjs +4 -12
- package/dist/lib/auth/oauth/diagnostics.d.mts +2 -1
- package/dist/lib/auth/oauth/diagnostics.d.ts +2 -1
- package/dist/lib/auth/oauth/diagnostics.js +8 -10
- package/dist/lib/auth/oauth/diagnostics.mjs +7 -10
- package/dist/lib/index.d.mts +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +2 -0
- package/dist/lib/index.mjs +7 -1
- package/dist/lib/reporting/consumer-runtime.js +2 -1
- package/dist/lib/reporting/consumer-runtime.mjs +2 -1
- package/dist/lib/reporting/ledger/handler.js +50 -11
- package/dist/lib/reporting/ledger/handler.mjs +50 -12
- package/dist/lib/reporting/ledger/index.d.mts +17 -14
- package/dist/lib/reporting/ledger/index.d.ts +17 -14
- package/dist/lib/reporting/ledger/index.js +32 -20
- package/dist/lib/reporting/ledger/index.mjs +21 -10
- package/dist/lib/reporting/ledger/offering-validation.d.mts +9 -0
- package/dist/lib/reporting/ledger/offering-validation.d.ts +9 -0
- package/dist/lib/reporting/{gcs/bucket-policy.js → ledger/offering-validation.js} +9 -8
- package/dist/lib/reporting/ledger/offering-validation.mjs +8 -0
- package/dist/lib/reporting/ledger/receipts.d.mts +48 -0
- package/dist/lib/reporting/ledger/receipts.d.ts +48 -0
- package/dist/lib/reporting/ledger/receipts.js +186 -0
- package/dist/lib/reporting/ledger/receipts.mjs +161 -0
- package/dist/lib/reporting/ledger/status-ingest.js +3 -3
- package/dist/lib/reporting/ledger/status-ingest.mjs +4 -5
- package/dist/lib/reporting/ledger/types.d.mts +43 -0
- package/dist/lib/reporting/ledger/types.d.ts +43 -0
- package/dist/lib/reporting/ledger/types.js +31 -2
- package/dist/lib/reporting/ledger/types.mjs +26 -1
- package/dist/lib/reporting/pagination.d.mts +6 -0
- package/dist/lib/reporting/pagination.d.ts +6 -0
- package/dist/lib/reporting/{gcs/errors.js → pagination.js} +12 -17
- package/dist/lib/reporting/pagination.mjs +12 -0
- package/dist/lib/reporting/reconciliation.d.mts +1 -0
- package/dist/lib/reporting/reconciliation.d.ts +1 -0
- package/dist/lib/reporting/reconciliation.js +3 -2
- package/dist/lib/reporting/reconciliation.mjs +3 -2
- package/dist/lib/reporting/service/index.d.mts +79 -153
- package/dist/lib/reporting/service/index.d.ts +79 -153
- package/dist/lib/reporting/service/index.js +34 -491
- package/dist/lib/reporting/service/index.mjs +36 -510
- package/dist/lib/reporting/service/scheduler-support.d.mts +43 -0
- package/dist/lib/reporting/service/scheduler-support.d.ts +43 -0
- package/dist/lib/reporting/service/scheduler-support.js +125 -0
- package/dist/lib/reporting/service/scheduler-support.mjs +96 -0
- package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
- package/dist/lib/signing/canonicalize.d.mts +4 -0
- package/dist/lib/signing/canonicalize.d.ts +4 -0
- package/dist/lib/signing/canonicalize.js +14 -8
- package/dist/lib/signing/canonicalize.mjs +14 -8
- package/dist/lib/signing/content-digest.d.mts +8 -0
- package/dist/lib/signing/content-digest.d.ts +8 -0
- package/dist/lib/signing/content-digest.js +11 -5
- package/dist/lib/signing/content-digest.mjs +10 -5
- package/dist/lib/signing/signer.js +9 -6
- package/dist/lib/signing/signer.mjs +10 -7
- package/dist/lib/signing/web-bot-auth.js +103 -37
- package/dist/lib/signing/web-bot-auth.mjs +108 -37
- package/dist/lib/testing/storyboard/junit.js +16 -3
- package/dist/lib/testing/storyboard/junit.mjs +16 -3
- package/dist/lib/testing/storyboard/request-signing/builder.js +10 -9
- package/dist/lib/testing/storyboard/request-signing/builder.mjs +10 -9
- package/dist/lib/testing/storyboard/runner.js +94 -25
- package/dist/lib/testing/storyboard/runner.mjs +94 -25
- package/dist/lib/testing/storyboard/types.d.mts +6 -0
- package/dist/lib/testing/storyboard/types.d.ts +6 -0
- package/dist/lib/testing/storyboard/validations.d.mts +1 -1
- package/dist/lib/testing/storyboard/validations.d.ts +1 -1
- package/dist/lib/types/schemas.generated.d.ts +907 -60
- package/dist/lib/types/schemas.generated.js +7 -7
- package/dist/lib/types/schemas.generated.mjs +7 -7
- package/dist/lib/version.d.mts +3 -3
- package/dist/lib/version.d.ts +3 -3
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.mjs +3 -3
- package/docs/TYPE-SUMMARY.md +23 -5
- package/docs/guides/REPORTING-GCS-FENCE.md +3 -3
- package/docs/guides/REPORTING-GCS-MANAGED.md +4 -4
- package/docs/guides/REPORTING-LEDGER-CUTOVER.md +7 -7
- package/docs/guides/REPORTING-LEDGER.md +107 -51
- package/docs/guides/REPORTING-OPERATIONS.md +66 -5
- package/docs/guides/REPORTING-STABILITY.md +36 -32
- package/docs/llms.txt +4 -3
- package/docs/migration-14.x-rc-worksheet.md +4 -7
- package/docs/migration-reporting-storage-package.md +186 -0
- package/examples/README.md +1 -1
- package/package.json +13 -78
- package/dist/lib/reporting/azure/index.d.mts +0 -31
- package/dist/lib/reporting/azure/index.d.ts +0 -31
- package/dist/lib/reporting/azure/index.js +0 -266
- package/dist/lib/reporting/azure/index.mjs +0 -249
- package/dist/lib/reporting/bigquery/index.d.mts +0 -246
- package/dist/lib/reporting/bigquery/index.d.ts +0 -246
- package/dist/lib/reporting/bigquery/index.js +0 -633
- package/dist/lib/reporting/bigquery/index.mjs +0 -594
- package/dist/lib/reporting/gcs/adapter.d.mts +0 -38
- package/dist/lib/reporting/gcs/adapter.d.ts +0 -38
- package/dist/lib/reporting/gcs/adapter.js +0 -342
- package/dist/lib/reporting/gcs/adapter.mjs +0 -325
- package/dist/lib/reporting/gcs/bucket-policy.d.mts +0 -3
- package/dist/lib/reporting/gcs/bucket-policy.d.ts +0 -3
- package/dist/lib/reporting/gcs/bucket-policy.mjs +0 -7
- package/dist/lib/reporting/gcs/errors.d.mts +0 -11
- package/dist/lib/reporting/gcs/errors.d.ts +0 -11
- package/dist/lib/reporting/gcs/errors.mjs +0 -16
- package/dist/lib/reporting/gcs/fence.d.mts +0 -41
- package/dist/lib/reporting/gcs/fence.d.ts +0 -41
- package/dist/lib/reporting/gcs/fence.js +0 -250
- package/dist/lib/reporting/gcs/fence.mjs +0 -230
- package/dist/lib/reporting/gcs/index.d.mts +0 -18
- package/dist/lib/reporting/gcs/index.d.ts +0 -18
- package/dist/lib/reporting/gcs/index.js +0 -44
- package/dist/lib/reporting/gcs/index.mjs +0 -14
- package/dist/lib/reporting/gcs/io.d.mts +0 -7
- package/dist/lib/reporting/gcs/io.d.ts +0 -7
- package/dist/lib/reporting/gcs/io.js +0 -95
- package/dist/lib/reporting/gcs/io.mjs +0 -69
- package/dist/lib/reporting/gcs/reader.d.mts +0 -67
- package/dist/lib/reporting/gcs/reader.d.ts +0 -67
- package/dist/lib/reporting/gcs/reader.js +0 -193
- package/dist/lib/reporting/gcs/reader.mjs +0 -169
- package/dist/lib/reporting/gcs/row-provider.d.mts +0 -39
- package/dist/lib/reporting/gcs/row-provider.d.ts +0 -39
- package/dist/lib/reporting/gcs/row-provider.js +0 -225
- package/dist/lib/reporting/gcs/row-provider.mjs +0 -208
- package/dist/lib/reporting/gcs/validation.d.mts +0 -5
- package/dist/lib/reporting/gcs/validation.d.ts +0 -5
- package/dist/lib/reporting/gcs/validation.js +0 -49
- package/dist/lib/reporting/gcs/validation.mjs +0 -25
- package/dist/lib/reporting/ledger/change-feed.d.mts +0 -69
- package/dist/lib/reporting/ledger/change-feed.d.ts +0 -69
- package/dist/lib/reporting/ledger/change-feed.js +0 -107
- package/dist/lib/reporting/ledger/change-feed.mjs +0 -80
- package/dist/lib/reporting/ledger/managed-postgres.d.mts +0 -293
- package/dist/lib/reporting/ledger/managed-postgres.d.ts +0 -293
- package/dist/lib/reporting/ledger/managed-postgres.js +0 -2346
- package/dist/lib/reporting/ledger/managed-postgres.mjs +0 -2332
- package/dist/lib/reporting/ledger/managed-router.d.mts +0 -148
- package/dist/lib/reporting/ledger/managed-router.d.ts +0 -148
- package/dist/lib/reporting/ledger/managed-router.js +0 -280
- package/dist/lib/reporting/ledger/managed-router.mjs +0 -258
- package/dist/lib/reporting/ledger/managed.d.mts +0 -535
- package/dist/lib/reporting/ledger/managed.d.ts +0 -535
- package/dist/lib/reporting/ledger/managed.js +0 -761
- package/dist/lib/reporting/ledger/managed.mjs +0 -729
- package/dist/lib/reporting/ledger/notification-activity.d.mts +0 -332
- package/dist/lib/reporting/ledger/notification-activity.d.ts +0 -332
- package/dist/lib/reporting/ledger/notification-activity.js +0 -1366
- package/dist/lib/reporting/ledger/notification-activity.mjs +0 -1337
- package/dist/lib/reporting/ledger/object-writes.d.mts +0 -128
- package/dist/lib/reporting/ledger/object-writes.d.ts +0 -128
- package/dist/lib/reporting/ledger/object-writes.js +0 -147
- package/dist/lib/reporting/ledger/object-writes.mjs +0 -114
- package/dist/lib/reporting/ledger/postgres.d.mts +0 -689
- package/dist/lib/reporting/ledger/postgres.d.ts +0 -689
- package/dist/lib/reporting/ledger/postgres.js +0 -4462
- package/dist/lib/reporting/ledger/postgres.mjs +0 -4462
- package/dist/lib/reporting/ledger/row-storage-migration.d.mts +0 -59
- package/dist/lib/reporting/ledger/row-storage-migration.d.ts +0 -59
- package/dist/lib/reporting/ledger/row-storage-migration.js +0 -365
- package/dist/lib/reporting/ledger/row-storage-migration.mjs +0 -339
- package/dist/lib/reporting/ledger/row-storage-object.d.mts +0 -203
- package/dist/lib/reporting/ledger/row-storage-object.d.ts +0 -203
- package/dist/lib/reporting/ledger/row-storage-object.js +0 -379
- package/dist/lib/reporting/ledger/row-storage-object.mjs +0 -335
- package/dist/lib/reporting/ledger/row-storage-provider-io.d.mts +0 -44
- package/dist/lib/reporting/ledger/row-storage-provider-io.d.ts +0 -44
- package/dist/lib/reporting/ledger/row-storage-provider-io.js +0 -142
- package/dist/lib/reporting/ledger/row-storage-provider-io.mjs +0 -111
- package/dist/lib/reporting/ledger/row-storage.d.mts +0 -316
- package/dist/lib/reporting/ledger/row-storage.d.ts +0 -316
- package/dist/lib/reporting/ledger/row-storage.js +0 -812
- package/dist/lib/reporting/ledger/row-storage.mjs +0 -802
- package/dist/lib/reporting/s3/index.d.mts +0 -34
- package/dist/lib/reporting/s3/index.d.ts +0 -34
- package/dist/lib/reporting/s3/index.js +0 -347
- package/dist/lib/reporting/s3/index.mjs +0 -340
- package/dist/lib/reporting/service/maintenance.d.mts +0 -148
- package/dist/lib/reporting/service/maintenance.d.ts +0 -148
- package/dist/lib/reporting/service/maintenance.js +0 -185
- package/dist/lib/reporting/service/maintenance.mjs +0 -159
- package/examples/reliable-reporting-service/README.md +0 -169
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var azure_exports = {};
|
|
20
|
-
__export(azure_exports, {
|
|
21
|
-
createAzureBlobReportingRowObjectProviderV1: () => createAzureBlobReportingRowObjectProviderV1
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(azure_exports);
|
|
24
|
-
var import_node_crypto = require("node:crypto");
|
|
25
|
-
var import_row_storage_errors = require('../ledger/row-storage-errors.js');
|
|
26
|
-
var import_row_storage_provider_io = require('../ledger/row-storage-provider-io.js');
|
|
27
|
-
const ACCOUNT = /^[a-z0-9]{3,24}$/;
|
|
28
|
-
const CONTAINER = /^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){2,62}$/;
|
|
29
|
-
const VERSION_ID = /^[0-9A-Za-z:.+-]{1,64}$/;
|
|
30
|
-
function statusOf(error) {
|
|
31
|
-
const status = Number(error?.statusCode);
|
|
32
|
-
return Number.isInteger(status) ? status : void 0;
|
|
33
|
-
}
|
|
34
|
-
function codeOf(error) {
|
|
35
|
-
const value = error?.code ?? error?.details?.errorCode;
|
|
36
|
-
return typeof value === "string" ? value : "";
|
|
37
|
-
}
|
|
38
|
-
const isConflict = (error) => statusOf(error) === 409 || statusOf(error) === 412 || codeOf(error) === "BlobAlreadyExists";
|
|
39
|
-
const isMissing = (error) => statusOf(error) === 404 || statusOf(error) === 412;
|
|
40
|
-
const isForbidden = (error) => statusOf(error) === 401 || statusOf(error) === 403;
|
|
41
|
-
function versionOf(response) {
|
|
42
|
-
const id = response.versionId;
|
|
43
|
-
if (typeof id !== "string" || !VERSION_ID.test(id)) {
|
|
44
|
-
throw new import_row_storage_errors.ReportingRowStoreError(
|
|
45
|
-
"UNSAFE_BINDING",
|
|
46
|
-
"store returned no blob versionId; blob versioning must be enabled on the storage account so deletes are fenced to one write"
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return id;
|
|
50
|
-
}
|
|
51
|
-
function servedVersion(response, versionId) {
|
|
52
|
-
return response.versionId === versionId;
|
|
53
|
-
}
|
|
54
|
-
function metadataOf(metadata) {
|
|
55
|
-
const result = {};
|
|
56
|
-
for (const [name, value] of Object.entries(metadata)) {
|
|
57
|
-
const identifier = name.replace(/[^A-Za-z0-9_]/g, "_");
|
|
58
|
-
result[/^[A-Za-z_]/.test(identifier) ? identifier : `_${identifier}`] = value;
|
|
59
|
-
}
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
function createAzureBlobReportingRowObjectProviderV1(options) {
|
|
63
|
-
if (!options || typeof options !== "object") {
|
|
64
|
-
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "Azure Blob row provider options are required");
|
|
65
|
-
}
|
|
66
|
-
const clients = (0, import_row_storage_provider_io.reportingRowClientMap)(options.clients);
|
|
67
|
-
const isClient = (value) => !!value && typeof value === "object" && typeof value.getContainerClient === "function" && typeof value.accountName === "string";
|
|
68
|
-
if (options.client !== void 0 && !isClient(options.client) || [...clients.values()].some((client) => !isClient(client)) || options.client === void 0 && clients.size === 0) {
|
|
69
|
-
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "inject an official BlobServiceClient as client or clients");
|
|
70
|
-
}
|
|
71
|
-
const validateLocation = (location) => {
|
|
72
|
-
(0, import_row_storage_provider_io.assertReportingRowLocationKeys)(location, ["account", "container"]);
|
|
73
|
-
if (!ACCOUNT.test(location.account)) {
|
|
74
|
-
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "Azure storage account name is invalid");
|
|
75
|
-
}
|
|
76
|
-
if (!CONTAINER.test(location.container)) {
|
|
77
|
-
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "Azure container name is invalid");
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const containerFor = (input) => {
|
|
81
|
-
validateLocation(input.location);
|
|
82
|
-
const client = (0, import_row_storage_provider_io.selectReportingRowClient)(options.client, clients, input.credentialRef);
|
|
83
|
-
if (client.accountName !== input.location.account) {
|
|
84
|
-
throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "client does not belong to the binding account");
|
|
85
|
-
}
|
|
86
|
-
return client.getContainerClient(input.location.container);
|
|
87
|
-
};
|
|
88
|
-
const blobFor = (input) => {
|
|
89
|
-
if (typeof input.objectRef !== "string" || input.objectRef.length === 0 || input.objectRef.length > 1024) {
|
|
90
|
-
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "object key is invalid");
|
|
91
|
-
}
|
|
92
|
-
return containerFor(input).getBlockBlobClient(input.objectRef);
|
|
93
|
-
};
|
|
94
|
-
const pinned = (blob, nativeVersionRef) => typeof nativeVersionRef === "string" && VERSION_ID.test(nativeVersionRef) ? { blob: blob.withVersion(nativeVersionRef), versionId: nativeVersionRef } : null;
|
|
95
|
-
async function assertCreateOnlyEnforced(container, prefix, signal) {
|
|
96
|
-
const blob = container.getBlockBlobClient(`${prefix}/.adcp-probe/${(0, import_node_crypto.randomUUID)()}`);
|
|
97
|
-
const versionIds = [];
|
|
98
|
-
let written = false;
|
|
99
|
-
const upload = async (body) => {
|
|
100
|
-
const bytes = Buffer.from(body);
|
|
101
|
-
const response = await blob.upload(bytes, bytes.byteLength, {
|
|
102
|
-
conditions: { ifNoneMatch: "*" },
|
|
103
|
-
blobHTTPHeaders: { blobContentType: "application/x-ndjson", blobCacheControl: "no-store" },
|
|
104
|
-
abortSignal: signal
|
|
105
|
-
});
|
|
106
|
-
written = true;
|
|
107
|
-
if (response.versionId) versionIds.push(response.versionId);
|
|
108
|
-
versionOf(response);
|
|
109
|
-
};
|
|
110
|
-
try {
|
|
111
|
-
await upload('{"probe":1}\n');
|
|
112
|
-
try {
|
|
113
|
-
await upload('{"probe":2}\n');
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (isConflict(error)) return;
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "store ignores If-None-Match and replaces blobs");
|
|
119
|
-
} finally {
|
|
120
|
-
if (written && !signal.aborted) {
|
|
121
|
-
await blob.delete({ abortSignal: signal }).catch(() => void 0);
|
|
122
|
-
for (const versionId of versionIds) {
|
|
123
|
-
if (signal.aborted) break;
|
|
124
|
-
await blob.withVersion(versionId).delete({ abortSignal: signal }).catch(() => void 0);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
name: "azure_blob",
|
|
131
|
-
rangedReads: true,
|
|
132
|
-
validateLocation,
|
|
133
|
-
probe(input, context) {
|
|
134
|
-
return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
|
|
135
|
-
const container = containerFor(input);
|
|
136
|
-
let properties;
|
|
137
|
-
try {
|
|
138
|
-
properties = await container.getProperties({ abortSignal: context.signal });
|
|
139
|
-
} catch (error) {
|
|
140
|
-
if (statusOf(error) === 404) throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "container does not exist");
|
|
141
|
-
if (isForbidden(error)) throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "container is not accessible");
|
|
142
|
-
throw error;
|
|
143
|
-
}
|
|
144
|
-
if (properties.blobPublicAccess) {
|
|
145
|
-
throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "container allows anonymous read access");
|
|
146
|
-
}
|
|
147
|
-
await assertCreateOnlyEnforced(container, input.prefix, context.signal);
|
|
148
|
-
});
|
|
149
|
-
},
|
|
150
|
-
putIfAbsent(input, context) {
|
|
151
|
-
return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
|
|
152
|
-
const blob = blobFor(input);
|
|
153
|
-
const bytes = Buffer.from(input.bytes);
|
|
154
|
-
try {
|
|
155
|
-
const response = await blob.upload(bytes, bytes.byteLength, {
|
|
156
|
-
conditions: { ifNoneMatch: "*" },
|
|
157
|
-
blobHTTPHeaders: { blobContentType: input.contentType, blobCacheControl: "no-store" },
|
|
158
|
-
metadata: metadataOf(input.metadata),
|
|
159
|
-
abortSignal: context.signal
|
|
160
|
-
});
|
|
161
|
-
return { created: true, nativeVersionRef: versionOf(response) };
|
|
162
|
-
} catch (error) {
|
|
163
|
-
if (!isConflict(error)) throw error;
|
|
164
|
-
}
|
|
165
|
-
const existing = await blob.getProperties({ abortSignal: context.signal });
|
|
166
|
-
return { created: false, nativeVersionRef: versionOf(existing) };
|
|
167
|
-
});
|
|
168
|
-
},
|
|
169
|
-
get(input, context) {
|
|
170
|
-
return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
|
|
171
|
-
const blob = blobFor(input);
|
|
172
|
-
(0, import_row_storage_provider_io.assertReportingRowReadBounds)(input);
|
|
173
|
-
const target = pinned(blob, input.nativeVersionRef);
|
|
174
|
-
if (target === null) return null;
|
|
175
|
-
try {
|
|
176
|
-
if (input.range?.length === 0) {
|
|
177
|
-
const properties = await target.blob.getProperties({ abortSignal: context.signal });
|
|
178
|
-
if (!servedVersion(properties, target.versionId)) return null;
|
|
179
|
-
if (input.range.offset > Number(properties.contentLength ?? 0)) {
|
|
180
|
-
throw new import_row_storage_errors.ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
|
|
181
|
-
}
|
|
182
|
-
return Buffer.alloc(0);
|
|
183
|
-
}
|
|
184
|
-
const response = await target.blob.download(input.range?.offset ?? 0, input.range?.length, {
|
|
185
|
-
abortSignal: context.signal
|
|
186
|
-
});
|
|
187
|
-
const body = response.readableStreamBody;
|
|
188
|
-
if (!body || typeof body[Symbol.asyncIterator] !== "function") {
|
|
189
|
-
throw new import_row_storage_errors.ReportingRowStoreError("PROVIDER_UNAVAILABLE", "blob body is not a stream");
|
|
190
|
-
}
|
|
191
|
-
if (!servedVersion(response, target.versionId)) {
|
|
192
|
-
body.destroy?.();
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
if (typeof response.contentLength === "number" && response.contentLength > input.maxBytes) {
|
|
196
|
-
body.destroy?.();
|
|
197
|
-
throw new import_row_storage_errors.ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "stored object exceeds its recorded size");
|
|
198
|
-
}
|
|
199
|
-
return await (0, import_row_storage_provider_io.readReportingRowStream)(body, input.maxBytes, context.signal);
|
|
200
|
-
} catch (error) {
|
|
201
|
-
if (isMissing(error)) return null;
|
|
202
|
-
if (statusOf(error) === 400) return null;
|
|
203
|
-
if (statusOf(error) === 416 || codeOf(error) === "InvalidRange") {
|
|
204
|
-
throw new import_row_storage_errors.ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
|
|
205
|
-
}
|
|
206
|
-
throw error;
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
},
|
|
210
|
-
stat(input, context) {
|
|
211
|
-
return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
|
|
212
|
-
const blob = blobFor(input);
|
|
213
|
-
const target = pinned(blob, input.nativeVersionRef);
|
|
214
|
-
if (target === null) return null;
|
|
215
|
-
try {
|
|
216
|
-
const properties = await target.blob.getProperties({ abortSignal: context.signal });
|
|
217
|
-
if (!servedVersion(properties, target.versionId)) return null;
|
|
218
|
-
const size = properties.contentLength;
|
|
219
|
-
if (typeof size !== "number" || !Number.isSafeInteger(size) || size < 0) {
|
|
220
|
-
throw new import_row_storage_errors.ReportingRowStoreError("PROVIDER_UNAVAILABLE", "blob metadata is malformed");
|
|
221
|
-
}
|
|
222
|
-
return { nativeVersionRef: target.versionId, sizeBytes: size };
|
|
223
|
-
} catch (error) {
|
|
224
|
-
if (isMissing(error) || statusOf(error) === 400) return null;
|
|
225
|
-
throw error;
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
},
|
|
229
|
-
delete(input, context) {
|
|
230
|
-
return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
|
|
231
|
-
const blob = blobFor(input);
|
|
232
|
-
const target = pinned(blob, input.nativeVersionRef);
|
|
233
|
-
if (target === null) return "absent";
|
|
234
|
-
const signal = context.signal;
|
|
235
|
-
try {
|
|
236
|
-
const recorded = await target.blob.getProperties({ abortSignal: signal });
|
|
237
|
-
if (recorded.versionId !== target.versionId) return "absent";
|
|
238
|
-
} catch (error) {
|
|
239
|
-
if (isMissing(error) || statusOf(error) === 400) return "absent";
|
|
240
|
-
throw error;
|
|
241
|
-
}
|
|
242
|
-
let deletedCurrent = false;
|
|
243
|
-
try {
|
|
244
|
-
const current = await blob.getProperties({ abortSignal: signal });
|
|
245
|
-
if (current.versionId === target.versionId && current.etag) {
|
|
246
|
-
await blob.delete({ conditions: { ifMatch: current.etag }, abortSignal: signal });
|
|
247
|
-
deletedCurrent = true;
|
|
248
|
-
}
|
|
249
|
-
} catch (error) {
|
|
250
|
-
if (!isMissing(error)) throw error;
|
|
251
|
-
}
|
|
252
|
-
try {
|
|
253
|
-
await target.blob.delete({ abortSignal: signal });
|
|
254
|
-
return "deleted";
|
|
255
|
-
} catch (error) {
|
|
256
|
-
if (isMissing(error) || statusOf(error) === 400) return deletedCurrent ? "deleted" : "absent";
|
|
257
|
-
throw error;
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
264
|
-
0 && (module.exports = {
|
|
265
|
-
createAzureBlobReportingRowObjectProviderV1
|
|
266
|
-
});
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { ReportingRowStoreError } from "../ledger/row-storage-errors.mjs";
|
|
3
|
-
import {
|
|
4
|
-
assertReportingRowLocationKeys,
|
|
5
|
-
assertReportingRowReadBounds,
|
|
6
|
-
readReportingRowStream,
|
|
7
|
-
reportingRowClientMap,
|
|
8
|
-
runReportingRowProviderOperation,
|
|
9
|
-
selectReportingRowClient
|
|
10
|
-
} from "../ledger/row-storage-provider-io.mjs";
|
|
11
|
-
const ACCOUNT = /^[a-z0-9]{3,24}$/;
|
|
12
|
-
const CONTAINER = /^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){2,62}$/;
|
|
13
|
-
const VERSION_ID = /^[0-9A-Za-z:.+-]{1,64}$/;
|
|
14
|
-
function statusOf(error) {
|
|
15
|
-
const status = Number(error?.statusCode);
|
|
16
|
-
return Number.isInteger(status) ? status : void 0;
|
|
17
|
-
}
|
|
18
|
-
function codeOf(error) {
|
|
19
|
-
const value = error?.code ?? error?.details?.errorCode;
|
|
20
|
-
return typeof value === "string" ? value : "";
|
|
21
|
-
}
|
|
22
|
-
const isConflict = (error) => statusOf(error) === 409 || statusOf(error) === 412 || codeOf(error) === "BlobAlreadyExists";
|
|
23
|
-
const isMissing = (error) => statusOf(error) === 404 || statusOf(error) === 412;
|
|
24
|
-
const isForbidden = (error) => statusOf(error) === 401 || statusOf(error) === 403;
|
|
25
|
-
function versionOf(response) {
|
|
26
|
-
const id = response.versionId;
|
|
27
|
-
if (typeof id !== "string" || !VERSION_ID.test(id)) {
|
|
28
|
-
throw new ReportingRowStoreError(
|
|
29
|
-
"UNSAFE_BINDING",
|
|
30
|
-
"store returned no blob versionId; blob versioning must be enabled on the storage account so deletes are fenced to one write"
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
return id;
|
|
34
|
-
}
|
|
35
|
-
function servedVersion(response, versionId) {
|
|
36
|
-
return response.versionId === versionId;
|
|
37
|
-
}
|
|
38
|
-
function metadataOf(metadata) {
|
|
39
|
-
const result = {};
|
|
40
|
-
for (const [name, value] of Object.entries(metadata)) {
|
|
41
|
-
const identifier = name.replace(/[^A-Za-z0-9_]/g, "_");
|
|
42
|
-
result[/^[A-Za-z_]/.test(identifier) ? identifier : `_${identifier}`] = value;
|
|
43
|
-
}
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
function createAzureBlobReportingRowObjectProviderV1(options) {
|
|
47
|
-
if (!options || typeof options !== "object") {
|
|
48
|
-
throw new ReportingRowStoreError("INVALID_INPUT", "Azure Blob row provider options are required");
|
|
49
|
-
}
|
|
50
|
-
const clients = reportingRowClientMap(options.clients);
|
|
51
|
-
const isClient = (value) => !!value && typeof value === "object" && typeof value.getContainerClient === "function" && typeof value.accountName === "string";
|
|
52
|
-
if (options.client !== void 0 && !isClient(options.client) || [...clients.values()].some((client) => !isClient(client)) || options.client === void 0 && clients.size === 0) {
|
|
53
|
-
throw new ReportingRowStoreError("INVALID_INPUT", "inject an official BlobServiceClient as client or clients");
|
|
54
|
-
}
|
|
55
|
-
const validateLocation = (location) => {
|
|
56
|
-
assertReportingRowLocationKeys(location, ["account", "container"]);
|
|
57
|
-
if (!ACCOUNT.test(location.account)) {
|
|
58
|
-
throw new ReportingRowStoreError("INVALID_INPUT", "Azure storage account name is invalid");
|
|
59
|
-
}
|
|
60
|
-
if (!CONTAINER.test(location.container)) {
|
|
61
|
-
throw new ReportingRowStoreError("INVALID_INPUT", "Azure container name is invalid");
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const containerFor = (input) => {
|
|
65
|
-
validateLocation(input.location);
|
|
66
|
-
const client = selectReportingRowClient(options.client, clients, input.credentialRef);
|
|
67
|
-
if (client.accountName !== input.location.account) {
|
|
68
|
-
throw new ReportingRowStoreError("UNSAFE_BINDING", "client does not belong to the binding account");
|
|
69
|
-
}
|
|
70
|
-
return client.getContainerClient(input.location.container);
|
|
71
|
-
};
|
|
72
|
-
const blobFor = (input) => {
|
|
73
|
-
if (typeof input.objectRef !== "string" || input.objectRef.length === 0 || input.objectRef.length > 1024) {
|
|
74
|
-
throw new ReportingRowStoreError("INVALID_INPUT", "object key is invalid");
|
|
75
|
-
}
|
|
76
|
-
return containerFor(input).getBlockBlobClient(input.objectRef);
|
|
77
|
-
};
|
|
78
|
-
const pinned = (blob, nativeVersionRef) => typeof nativeVersionRef === "string" && VERSION_ID.test(nativeVersionRef) ? { blob: blob.withVersion(nativeVersionRef), versionId: nativeVersionRef } : null;
|
|
79
|
-
async function assertCreateOnlyEnforced(container, prefix, signal) {
|
|
80
|
-
const blob = container.getBlockBlobClient(`${prefix}/.adcp-probe/${randomUUID()}`);
|
|
81
|
-
const versionIds = [];
|
|
82
|
-
let written = false;
|
|
83
|
-
const upload = async (body) => {
|
|
84
|
-
const bytes = Buffer.from(body);
|
|
85
|
-
const response = await blob.upload(bytes, bytes.byteLength, {
|
|
86
|
-
conditions: { ifNoneMatch: "*" },
|
|
87
|
-
blobHTTPHeaders: { blobContentType: "application/x-ndjson", blobCacheControl: "no-store" },
|
|
88
|
-
abortSignal: signal
|
|
89
|
-
});
|
|
90
|
-
written = true;
|
|
91
|
-
if (response.versionId) versionIds.push(response.versionId);
|
|
92
|
-
versionOf(response);
|
|
93
|
-
};
|
|
94
|
-
try {
|
|
95
|
-
await upload('{"probe":1}\n');
|
|
96
|
-
try {
|
|
97
|
-
await upload('{"probe":2}\n');
|
|
98
|
-
} catch (error) {
|
|
99
|
-
if (isConflict(error)) return;
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
throw new ReportingRowStoreError("UNSAFE_BINDING", "store ignores If-None-Match and replaces blobs");
|
|
103
|
-
} finally {
|
|
104
|
-
if (written && !signal.aborted) {
|
|
105
|
-
await blob.delete({ abortSignal: signal }).catch(() => void 0);
|
|
106
|
-
for (const versionId of versionIds) {
|
|
107
|
-
if (signal.aborted) break;
|
|
108
|
-
await blob.withVersion(versionId).delete({ abortSignal: signal }).catch(() => void 0);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return {
|
|
114
|
-
name: "azure_blob",
|
|
115
|
-
rangedReads: true,
|
|
116
|
-
validateLocation,
|
|
117
|
-
probe(input, context) {
|
|
118
|
-
return runReportingRowProviderOperation(context.signal, async () => {
|
|
119
|
-
const container = containerFor(input);
|
|
120
|
-
let properties;
|
|
121
|
-
try {
|
|
122
|
-
properties = await container.getProperties({ abortSignal: context.signal });
|
|
123
|
-
} catch (error) {
|
|
124
|
-
if (statusOf(error) === 404) throw new ReportingRowStoreError("UNSAFE_BINDING", "container does not exist");
|
|
125
|
-
if (isForbidden(error)) throw new ReportingRowStoreError("UNSAFE_BINDING", "container is not accessible");
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
if (properties.blobPublicAccess) {
|
|
129
|
-
throw new ReportingRowStoreError("UNSAFE_BINDING", "container allows anonymous read access");
|
|
130
|
-
}
|
|
131
|
-
await assertCreateOnlyEnforced(container, input.prefix, context.signal);
|
|
132
|
-
});
|
|
133
|
-
},
|
|
134
|
-
putIfAbsent(input, context) {
|
|
135
|
-
return runReportingRowProviderOperation(context.signal, async () => {
|
|
136
|
-
const blob = blobFor(input);
|
|
137
|
-
const bytes = Buffer.from(input.bytes);
|
|
138
|
-
try {
|
|
139
|
-
const response = await blob.upload(bytes, bytes.byteLength, {
|
|
140
|
-
conditions: { ifNoneMatch: "*" },
|
|
141
|
-
blobHTTPHeaders: { blobContentType: input.contentType, blobCacheControl: "no-store" },
|
|
142
|
-
metadata: metadataOf(input.metadata),
|
|
143
|
-
abortSignal: context.signal
|
|
144
|
-
});
|
|
145
|
-
return { created: true, nativeVersionRef: versionOf(response) };
|
|
146
|
-
} catch (error) {
|
|
147
|
-
if (!isConflict(error)) throw error;
|
|
148
|
-
}
|
|
149
|
-
const existing = await blob.getProperties({ abortSignal: context.signal });
|
|
150
|
-
return { created: false, nativeVersionRef: versionOf(existing) };
|
|
151
|
-
});
|
|
152
|
-
},
|
|
153
|
-
get(input, context) {
|
|
154
|
-
return runReportingRowProviderOperation(context.signal, async () => {
|
|
155
|
-
const blob = blobFor(input);
|
|
156
|
-
assertReportingRowReadBounds(input);
|
|
157
|
-
const target = pinned(blob, input.nativeVersionRef);
|
|
158
|
-
if (target === null) return null;
|
|
159
|
-
try {
|
|
160
|
-
if (input.range?.length === 0) {
|
|
161
|
-
const properties = await target.blob.getProperties({ abortSignal: context.signal });
|
|
162
|
-
if (!servedVersion(properties, target.versionId)) return null;
|
|
163
|
-
if (input.range.offset > Number(properties.contentLength ?? 0)) {
|
|
164
|
-
throw new ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
|
|
165
|
-
}
|
|
166
|
-
return Buffer.alloc(0);
|
|
167
|
-
}
|
|
168
|
-
const response = await target.blob.download(input.range?.offset ?? 0, input.range?.length, {
|
|
169
|
-
abortSignal: context.signal
|
|
170
|
-
});
|
|
171
|
-
const body = response.readableStreamBody;
|
|
172
|
-
if (!body || typeof body[Symbol.asyncIterator] !== "function") {
|
|
173
|
-
throw new ReportingRowStoreError("PROVIDER_UNAVAILABLE", "blob body is not a stream");
|
|
174
|
-
}
|
|
175
|
-
if (!servedVersion(response, target.versionId)) {
|
|
176
|
-
body.destroy?.();
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
if (typeof response.contentLength === "number" && response.contentLength > input.maxBytes) {
|
|
180
|
-
body.destroy?.();
|
|
181
|
-
throw new ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "stored object exceeds its recorded size");
|
|
182
|
-
}
|
|
183
|
-
return await readReportingRowStream(body, input.maxBytes, context.signal);
|
|
184
|
-
} catch (error) {
|
|
185
|
-
if (isMissing(error)) return null;
|
|
186
|
-
if (statusOf(error) === 400) return null;
|
|
187
|
-
if (statusOf(error) === 416 || codeOf(error) === "InvalidRange") {
|
|
188
|
-
throw new ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
|
|
189
|
-
}
|
|
190
|
-
throw error;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
},
|
|
194
|
-
stat(input, context) {
|
|
195
|
-
return runReportingRowProviderOperation(context.signal, async () => {
|
|
196
|
-
const blob = blobFor(input);
|
|
197
|
-
const target = pinned(blob, input.nativeVersionRef);
|
|
198
|
-
if (target === null) return null;
|
|
199
|
-
try {
|
|
200
|
-
const properties = await target.blob.getProperties({ abortSignal: context.signal });
|
|
201
|
-
if (!servedVersion(properties, target.versionId)) return null;
|
|
202
|
-
const size = properties.contentLength;
|
|
203
|
-
if (typeof size !== "number" || !Number.isSafeInteger(size) || size < 0) {
|
|
204
|
-
throw new ReportingRowStoreError("PROVIDER_UNAVAILABLE", "blob metadata is malformed");
|
|
205
|
-
}
|
|
206
|
-
return { nativeVersionRef: target.versionId, sizeBytes: size };
|
|
207
|
-
} catch (error) {
|
|
208
|
-
if (isMissing(error) || statusOf(error) === 400) return null;
|
|
209
|
-
throw error;
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
},
|
|
213
|
-
delete(input, context) {
|
|
214
|
-
return runReportingRowProviderOperation(context.signal, async () => {
|
|
215
|
-
const blob = blobFor(input);
|
|
216
|
-
const target = pinned(blob, input.nativeVersionRef);
|
|
217
|
-
if (target === null) return "absent";
|
|
218
|
-
const signal = context.signal;
|
|
219
|
-
try {
|
|
220
|
-
const recorded = await target.blob.getProperties({ abortSignal: signal });
|
|
221
|
-
if (recorded.versionId !== target.versionId) return "absent";
|
|
222
|
-
} catch (error) {
|
|
223
|
-
if (isMissing(error) || statusOf(error) === 400) return "absent";
|
|
224
|
-
throw error;
|
|
225
|
-
}
|
|
226
|
-
let deletedCurrent = false;
|
|
227
|
-
try {
|
|
228
|
-
const current = await blob.getProperties({ abortSignal: signal });
|
|
229
|
-
if (current.versionId === target.versionId && current.etag) {
|
|
230
|
-
await blob.delete({ conditions: { ifMatch: current.etag }, abortSignal: signal });
|
|
231
|
-
deletedCurrent = true;
|
|
232
|
-
}
|
|
233
|
-
} catch (error) {
|
|
234
|
-
if (!isMissing(error)) throw error;
|
|
235
|
-
}
|
|
236
|
-
try {
|
|
237
|
-
await target.blob.delete({ abortSignal: signal });
|
|
238
|
-
return "deleted";
|
|
239
|
-
} catch (error) {
|
|
240
|
-
if (isMissing(error) || statusOf(error) === 400) return deletedCurrent ? "deleted" : "absent";
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
export {
|
|
248
|
-
createAzureBlobReportingRowObjectProviderV1
|
|
249
|
-
};
|