@osva-ai/adapter-artifact-azure 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +90 -3
- package/dist/azure-artifact-blob-store.d.ts +41 -0
- package/dist/azure-artifact-blob-store.d.ts.map +1 -0
- package/dist/azure-artifact-blob-store.js +165 -0
- package/dist/azure-artifact-blob-store.js.map +1 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +72 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/sanitize.d.ts +2 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +19 -0
- package/dist/sanitize.js.map +1 -0
- package/dist/stream-digest.d.ts +12 -0
- package/dist/stream-digest.d.ts.map +1 -0
- package/dist/stream-digest.js +51 -0
- package/dist/stream-digest.js.map +1 -0
- package/package.json +43 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works, within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works, or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been informed of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Osva AI
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @osva-ai/adapter-artifact-azure
|
|
2
|
+
|
|
3
|
+
**A1.2** implementation of `ArtifactBlobStore` backed by [Azure Blob Storage](https://learn.microsoft.com/en-us/azure/storage/blobs/).
|
|
4
|
+
|
|
5
|
+
> **Deployment integration required.** This package is verified with unit mocks, Azurite, and an external pack consumer. End-to-end production readiness depends on OSVA core registering the adapter in your deployment image and passing M12.4.x acceptance in your environment.
|
|
6
|
+
|
|
7
|
+
## Registration
|
|
8
|
+
|
|
9
|
+
Install into the OSVA deployment image alongside **`@osva-ai/contracts@1.1.0-rc.3`** (npm `rc` dist-tag), then use the `registered` artifact storage driver:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
export OSVA_ARTIFACT_STORAGE_DRIVER=registered
|
|
13
|
+
export OSVA_ARTIFACT_BLOB_STORE_REGISTER_MODULE="@osva-ai/adapter-artifact-azure"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The default export satisfies `RegisteredArtifactBlobStoreModule` (`createArtifactBlobStore`).
|
|
17
|
+
|
|
18
|
+
## Operator configuration
|
|
19
|
+
|
|
20
|
+
Credentials and container settings are read from the **environment at factory time**. There are no embedded production credentials and no runtime discovery of adapter packages.
|
|
21
|
+
|
|
22
|
+
| Variable | Required | Description |
|
|
23
|
+
| ----------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `OSVA_ARTIFACT_AZURE_CONTAINER` | Yes | Existing blob container name (lowercase, 3–63 characters). |
|
|
25
|
+
| `OSVA_ARTIFACT_AZURE_CONNECTION_STRING` | One of | Azure Storage connection string. |
|
|
26
|
+
| `OSVA_ARTIFACT_AZURE_ACCOUNT_NAME` | One of | Storage account name (with account key below). |
|
|
27
|
+
| `OSVA_ARTIFACT_AZURE_ACCOUNT_KEY` | One of | Storage account key. |
|
|
28
|
+
| `OSVA_ARTIFACT_AZURE_BLOB_ENDPOINT` | No | Custom blob endpoint (Azurite, private link, sovereign cloud). Used with account name + key. |
|
|
29
|
+
| Set **either** `OSVA_ARTIFACT_AZURE_CONNECTION_STRING` **or** `OSVA_ARTIFACT_AZURE_ACCOUNT_NAME` + `OSVA_ARTIFACT_AZURE_ACCOUNT_KEY`, not both. |
|
|
30
|
+
|
|
31
|
+
Per-request size limits come from OSVA via `ArtifactBlobWriteInput.maxBytes` (aligned with `ArtifactStorageConfigRegistered.maxBytes`).
|
|
32
|
+
|
|
33
|
+
## Deployment example (Kubernetes)
|
|
34
|
+
|
|
35
|
+
```yaml
|
|
36
|
+
env:
|
|
37
|
+
- name: OSVA_ARTIFACT_STORAGE_DRIVER
|
|
38
|
+
value: registered
|
|
39
|
+
- name: OSVA_ARTIFACT_BLOB_STORE_REGISTER_MODULE
|
|
40
|
+
value: "@osva-ai/adapter-artifact-azure"
|
|
41
|
+
- name: OSVA_ARTIFACT_AZURE_CONTAINER
|
|
42
|
+
value: osva-artifacts
|
|
43
|
+
- name: OSVA_ARTIFACT_AZURE_CONNECTION_STRING
|
|
44
|
+
valueFrom:
|
|
45
|
+
secretKeyRef:
|
|
46
|
+
name: osva-azure-storage
|
|
47
|
+
key: connection-string
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Provision the container and IAM outside OSVA (Terraform, Bicep, Azure Portal). OSVA core retains metadata, authorization, and workspace isolation in PostgreSQL.
|
|
51
|
+
|
|
52
|
+
## Semantics
|
|
53
|
+
|
|
54
|
+
Aligned with [artifact adapter architecture](../../docs/architecture/ARTIFACT_ADAPTERS.md) and A1.1 reference behavior:
|
|
55
|
+
|
|
56
|
+
- **Writes** stage to a pending blob, verify SHA-256 (and optional `expectedDigest`), then copy into the final key so failed uploads are not visible via `open`.
|
|
57
|
+
- **Overwrite:** last successful `write` replaces prior bytes.
|
|
58
|
+
- **Missing `open`:** `ARTIFACT_UNAVAILABLE`.
|
|
59
|
+
- **`delete`:** idempotent (`deleteIfExists`).
|
|
60
|
+
- **Streaming:** bounded upload buffer (4 MiB); digest computed while streaming.
|
|
61
|
+
- **Errors:** Azure messages are sanitized before surfacing (no account keys or signatures in logs/errors).
|
|
62
|
+
|
|
63
|
+
## Known limitations (Azure / Azurite)
|
|
64
|
+
|
|
65
|
+
- **Staging + copy:** writes land in a pending blob (`.__osva_pending.<uuid>`) and copy to the final key; copy must report success before `write` returns.
|
|
66
|
+
- **Cleanup:** pending blob deletion is best-effort in `finally` (failures are not propagated after a successful copy).
|
|
67
|
+
- **Concurrency:** concurrent writes to the same key are not serialized; last successful copy wins (Azure last-writer-wins).
|
|
68
|
+
- **Azurite vs production:** local Azurite and A1.4 Docker acceptance prove registered-driver wiring and cross-process behavior against an emulator — not Azure SLA, IAM edge cases, or private-link-only endpoints.
|
|
69
|
+
|
|
70
|
+
## Local development (Azurite)
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
docker compose -f packages/artifact-azure/docker-compose.azurite.yml up -d
|
|
74
|
+
export OSVA_ARTIFACT_AZURE_INTEGRATION=1
|
|
75
|
+
export OSVA_ARTIFACT_AZURE_CONTAINER=osva-artifacts-dev
|
|
76
|
+
export OSVA_ARTIFACT_AZURE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;"
|
|
77
|
+
pnpm --filter @osva-ai/adapter-artifact-azure test:integration
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Install (npm)
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm install @osva-ai/adapter-artifact-azure @osva-ai/contracts@1.1.0-rc.3
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Requires Node.js `>=24`. See [COMPATIBILITY.md](../../COMPATIBILITY.md) and [MAINTAINER_RELEASE.md](../../docs/release/MAINTAINER_RELEASE.md) for release pinning.
|
|
87
|
+
|
|
88
|
+
## Errors
|
|
89
|
+
|
|
90
|
+
Throws `ArtifactBlobStoreError` with `code` from `ARTIFACT_ERROR_CODES` in `@osva-ai/contracts`.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BlobServiceClient } from "@azure/storage-blob";
|
|
2
|
+
import { type ArtifactBlobReadHandle, type ArtifactBlobStore, type ArtifactBlobWriteInput, type ArtifactBlobWriteResult, type ArtifactStorageConfigRegistered, type RegisteredArtifactBlobStoreModule } from "@osva-ai/contracts";
|
|
3
|
+
import { type ResolvedAzureArtifactConfig } from "./config.js";
|
|
4
|
+
export interface AzureCopyPollResult {
|
|
5
|
+
readonly copyStatus?: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface AzureBlockBlobLike {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
uploadStream(stream: NodeJS.ReadableStream, bufferSize: number, maxConcurrency: number, options?: unknown): Promise<unknown>;
|
|
10
|
+
beginCopyFromURL(sourceUrl: string): Promise<{
|
|
11
|
+
pollUntilDone(): Promise<AzureCopyPollResult>;
|
|
12
|
+
}>;
|
|
13
|
+
deleteIfExists(): Promise<unknown>;
|
|
14
|
+
getProperties(): Promise<{
|
|
15
|
+
contentLength?: number | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
download(offset: number): Promise<{
|
|
18
|
+
readableStreamBody?: NodeJS.ReadableStream | undefined;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export interface AzureBlobContainerLike {
|
|
22
|
+
getBlockBlobClient(blobName: string): AzureBlockBlobLike;
|
|
23
|
+
}
|
|
24
|
+
export interface AzureArtifactBlobStoreOptions {
|
|
25
|
+
readonly containerClient: AzureBlobContainerLike;
|
|
26
|
+
readonly registeredMaxBytes?: number | undefined;
|
|
27
|
+
}
|
|
28
|
+
export declare class AzureArtifactBlobStore implements ArtifactBlobStore {
|
|
29
|
+
private readonly containerClient;
|
|
30
|
+
private readonly registeredMaxBytes;
|
|
31
|
+
constructor(options: AzureArtifactBlobStoreOptions);
|
|
32
|
+
write(input: ArtifactBlobWriteInput): Promise<ArtifactBlobWriteResult>;
|
|
33
|
+
open(key: string): Promise<ArtifactBlobReadHandle>;
|
|
34
|
+
delete(key: string): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export declare function createAzureArtifactBlobStoreFromConfig(config: ResolvedAzureArtifactConfig, registeredMaxBytes?: number): AzureArtifactBlobStore;
|
|
37
|
+
export declare function createAzureArtifactBlobStoreFromClient(blobServiceClient: BlobServiceClient, containerName: string, registeredMaxBytes?: number): AzureArtifactBlobStore;
|
|
38
|
+
export declare function createArtifactBlobStore(config: ArtifactStorageConfigRegistered): AzureArtifactBlobStore;
|
|
39
|
+
declare const moduleShape: RegisteredArtifactBlobStoreModule;
|
|
40
|
+
export default moduleShape;
|
|
41
|
+
//# sourceMappingURL=azure-artifact-blob-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure-artifact-blob-store.d.ts","sourceRoot":"","sources":["../src/azure-artifact-blob-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAa,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,+BAA+B,EACpC,KAAK,iCAAiC,EACvC,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,KAAK,2BAA2B,EAEjC,MAAM,aAAa,CAAC;AAgBrB,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,YAAY,CACV,MAAM,EAAE,MAAM,CAAC,cAAc,EAC7B,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,gBAAgB,CACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC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EAAE,+BAA+B,GACtC,sBAAsB,CAQxB;AAED,QAAA,MAAM,WAAW,EAAE,iCAElB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
import { BlobServiceClient, RestError } from "@azure/storage-blob";
|
|
4
|
+
import { SHA256_INTEGRITY_PREFIX, isSha256IntegrityDigest, } from "@osva-ai/contracts";
|
|
5
|
+
import { resolveAzureArtifactConfigFromEnv, } from "./config.js";
|
|
6
|
+
import { ArtifactBlobStoreError, blobUnavailable, digestMismatch, invalidRequest, } from "./errors.js";
|
|
7
|
+
import { sanitizeExternalMessage } from "./sanitize.js";
|
|
8
|
+
import { createDigestingReadable, uploadBufferSizeBytes, } from "./stream-digest.js";
|
|
9
|
+
const SAFE_BLOB_KEY_PATTERN = /^[a-zA-Z0-9._/-]+$/;
|
|
10
|
+
const STAGING_SUFFIX = ".__osva_pending.";
|
|
11
|
+
export class AzureArtifactBlobStore {
|
|
12
|
+
containerClient;
|
|
13
|
+
registeredMaxBytes;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.containerClient = options.containerClient;
|
|
16
|
+
this.registeredMaxBytes = options.registeredMaxBytes;
|
|
17
|
+
}
|
|
18
|
+
async write(input) {
|
|
19
|
+
assertSafeBlobKey(input.key);
|
|
20
|
+
const effectiveMaxBytes = resolveEffectiveMaxBytes(input.maxBytes, this.registeredMaxBytes);
|
|
21
|
+
assertWriteLimits(input, effectiveMaxBytes);
|
|
22
|
+
const stagingKey = `${input.key}${STAGING_SUFFIX}${randomUUID()}`;
|
|
23
|
+
const stagingClient = this.containerClient.getBlockBlobClient(stagingKey);
|
|
24
|
+
const { stream, digestPromise } = createDigestingReadable(input.content, effectiveMaxBytes);
|
|
25
|
+
try {
|
|
26
|
+
const { sizeBytes, digest } = await Promise.all([
|
|
27
|
+
digestPromise,
|
|
28
|
+
stagingClient.uploadStream(stream, uploadBufferSizeBytes(), 5, {
|
|
29
|
+
blobHTTPHeaders: { blobContentType: "application/octet-stream" },
|
|
30
|
+
}),
|
|
31
|
+
]).then(([digestResult]) => digestResult);
|
|
32
|
+
if (input.expectedDigest !== undefined &&
|
|
33
|
+
input.expectedDigest !== digest) {
|
|
34
|
+
throw digestMismatch();
|
|
35
|
+
}
|
|
36
|
+
const destination = this.containerClient.getBlockBlobClient(input.key);
|
|
37
|
+
await copyBlobReplace(destination, stagingClient);
|
|
38
|
+
return { sizeBytes, digest };
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error instanceof ArtifactBlobStoreError) {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
throw mapAzureError(error, input.key);
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
await stagingClient.deleteIfExists();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Best-effort staging cleanup; do not mask the write error.
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async open(key) {
|
|
56
|
+
assertSafeBlobKey(key);
|
|
57
|
+
const blobClient = this.containerClient.getBlockBlobClient(key);
|
|
58
|
+
try {
|
|
59
|
+
const properties = await blobClient.getProperties();
|
|
60
|
+
const sizeBytes = properties.contentLength ?? 0;
|
|
61
|
+
const download = await blobClient.download(0);
|
|
62
|
+
const body = download.readableStreamBody;
|
|
63
|
+
if (body === undefined) {
|
|
64
|
+
throw blobUnavailable(key);
|
|
65
|
+
}
|
|
66
|
+
const nodeStream = Readable.from(body);
|
|
67
|
+
return {
|
|
68
|
+
sizeBytes,
|
|
69
|
+
stream: nodeStream,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error instanceof ArtifactBlobStoreError) {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
throw mapAzureOpenError(error, key);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async delete(key) {
|
|
80
|
+
assertSafeBlobKey(key);
|
|
81
|
+
const blobClient = this.containerClient.getBlockBlobClient(key);
|
|
82
|
+
try {
|
|
83
|
+
await blobClient.deleteIfExists();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (error instanceof ArtifactBlobStoreError) {
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
throw mapAzureError(error, key);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function createAzureArtifactBlobStoreFromConfig(config, registeredMaxBytes) {
|
|
94
|
+
const containerClient = config.blobServiceClient.getContainerClient(config.containerName);
|
|
95
|
+
return new AzureArtifactBlobStore({ containerClient, registeredMaxBytes });
|
|
96
|
+
}
|
|
97
|
+
export function createAzureArtifactBlobStoreFromClient(blobServiceClient, containerName, registeredMaxBytes) {
|
|
98
|
+
const containerClient = blobServiceClient.getContainerClient(containerName);
|
|
99
|
+
return new AzureArtifactBlobStore({ containerClient, registeredMaxBytes });
|
|
100
|
+
}
|
|
101
|
+
export function createArtifactBlobStore(config) {
|
|
102
|
+
const azureConfig = resolveAzureArtifactConfigFromEnv();
|
|
103
|
+
return new AzureArtifactBlobStore({
|
|
104
|
+
containerClient: azureConfig.blobServiceClient.getContainerClient(azureConfig.containerName),
|
|
105
|
+
registeredMaxBytes: config.maxBytes,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const moduleShape = {
|
|
109
|
+
createArtifactBlobStore,
|
|
110
|
+
};
|
|
111
|
+
export default moduleShape;
|
|
112
|
+
async function copyBlobReplace(destination, source) {
|
|
113
|
+
const copyPoller = await destination.beginCopyFromURL(source.url);
|
|
114
|
+
const copyResult = await copyPoller.pollUntilDone();
|
|
115
|
+
if (copyResult.copyStatus !== undefined &&
|
|
116
|
+
copyResult.copyStatus !== "success") {
|
|
117
|
+
throw invalidRequest("Azure Blob Storage copy to destination failed.");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function resolveEffectiveMaxBytes(requestMaxBytes, registeredMaxBytes) {
|
|
121
|
+
if (registeredMaxBytes === undefined) {
|
|
122
|
+
return requestMaxBytes;
|
|
123
|
+
}
|
|
124
|
+
return Math.min(requestMaxBytes, registeredMaxBytes);
|
|
125
|
+
}
|
|
126
|
+
function assertWriteLimits(input, effectiveMaxBytes) {
|
|
127
|
+
if (!Number.isFinite(effectiveMaxBytes) || effectiveMaxBytes < 0) {
|
|
128
|
+
throw invalidRequest("maxBytes must be a non-negative finite number.");
|
|
129
|
+
}
|
|
130
|
+
if (input.expectedDigest !== undefined &&
|
|
131
|
+
!isSha256IntegrityDigest(input.expectedDigest)) {
|
|
132
|
+
throw invalidRequest(`expectedDigest must use the ${SHA256_INTEGRITY_PREFIX} prefix with 64 hex digits.`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function assertSafeBlobKey(key) {
|
|
136
|
+
if (typeof key !== "string" || key.length === 0) {
|
|
137
|
+
throw invalidRequest("Blob key is required.");
|
|
138
|
+
}
|
|
139
|
+
if (!SAFE_BLOB_KEY_PATTERN.test(key) ||
|
|
140
|
+
key.includes("..") ||
|
|
141
|
+
key.includes(STAGING_SUFFIX)) {
|
|
142
|
+
throw invalidRequest("Blob key contains unsupported characters.");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function mapAzureOpenError(error, key) {
|
|
146
|
+
if (error instanceof RestError && error.statusCode === 404) {
|
|
147
|
+
return blobUnavailable(key);
|
|
148
|
+
}
|
|
149
|
+
return mapAzureError(error, key);
|
|
150
|
+
}
|
|
151
|
+
function mapAzureError(error, key) {
|
|
152
|
+
if (error instanceof RestError) {
|
|
153
|
+
if (error.statusCode === 404) {
|
|
154
|
+
return blobUnavailable(key);
|
|
155
|
+
}
|
|
156
|
+
return invalidRequest(sanitizeExternalMessage(error.message.length > 0
|
|
157
|
+
? error.message
|
|
158
|
+
: "Azure Blob Storage request failed."));
|
|
159
|
+
}
|
|
160
|
+
if (error instanceof Error) {
|
|
161
|
+
return invalidRequest(sanitizeExternalMessage(error.message));
|
|
162
|
+
}
|
|
163
|
+
return invalidRequest("Azure Blob Storage request failed.");
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=azure-artifact-blob-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure-artifact-blob-store.js","sourceRoot":"","sources":["../src/azure-artifact-blob-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EACL,uBAAuB,EACvB,uBAAuB,GAOxB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEL,iCAAiC,GAClC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,cAAc,EACd,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EACL,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,qBAAqB,GAAG,oBAAoB,CAAC;AACnD,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAiC1C,MAAM,OAAO,sBAAsB;IAChB,eAAe,CAAyB;IACxC,kBAAkB,CAAqB;IAExD,YAAY,OAAsC;QAChD,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;QAC/C,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,KAA6B;QACvC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,iBAAiB,GAAG,wBAAwB,CAChD,KAAK,CAAC,QAAQ,EACd,IAA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C3D,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,aAAa,CAAC,KAAc,EAAE,GAAW;IAChD,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;QAC/B,IAAI,KAAK,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;YAC7B,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,cAAc,CACnB,uBAAuB,CACrB,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;YACtB,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,oCAAoC,CACzC,CACF,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,cAAc,CAAC,uBAAuB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,cAAc,CAAC,oCAAoC,CAAC,CAAC;AAC9D,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BlobServiceClient } from "@azure/storage-blob";
|
|
2
|
+
/** Environment variables read at factory time (operator-controlled). */
|
|
3
|
+
export declare const AZURE_ARTIFACT_ENV: {
|
|
4
|
+
readonly CONTAINER: "OSVA_ARTIFACT_AZURE_CONTAINER";
|
|
5
|
+
readonly CONNECTION_STRING: "OSVA_ARTIFACT_AZURE_CONNECTION_STRING";
|
|
6
|
+
readonly ACCOUNT_NAME: "OSVA_ARTIFACT_AZURE_ACCOUNT_NAME";
|
|
7
|
+
readonly ACCOUNT_KEY: "OSVA_ARTIFACT_AZURE_ACCOUNT_KEY";
|
|
8
|
+
readonly BLOB_ENDPOINT: "OSVA_ARTIFACT_AZURE_BLOB_ENDPOINT";
|
|
9
|
+
};
|
|
10
|
+
export interface ResolvedAzureArtifactConfig {
|
|
11
|
+
readonly containerName: string;
|
|
12
|
+
readonly blobServiceClient: BlobServiceClient;
|
|
13
|
+
}
|
|
14
|
+
export declare function resolveAzureArtifactConfigFromEnv(): ResolvedAzureArtifactConfig;
|
|
15
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAElB,MAAM,qBAAqB,CAAC;AAK7B,wEAAwE;AACxE,eAAO,MAAM,kBAAkB;;;;;;CAMrB,CAAC;AAEX,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;CAC/C;AAmDD,wBAAgB,iCAAiC,IAAI,2BAA2B,CA0C/E"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { BlobServiceClient, StorageSharedKeyCredential, } from "@azure/storage-blob";
|
|
2
|
+
import { configurationError } from "./errors.js";
|
|
3
|
+
import { sanitizeExternalMessage } from "./sanitize.js";
|
|
4
|
+
/** Environment variables read at factory time (operator-controlled). */
|
|
5
|
+
export const AZURE_ARTIFACT_ENV = {
|
|
6
|
+
CONTAINER: "OSVA_ARTIFACT_AZURE_CONTAINER",
|
|
7
|
+
CONNECTION_STRING: "OSVA_ARTIFACT_AZURE_CONNECTION_STRING",
|
|
8
|
+
ACCOUNT_NAME: "OSVA_ARTIFACT_AZURE_ACCOUNT_NAME",
|
|
9
|
+
ACCOUNT_KEY: "OSVA_ARTIFACT_AZURE_ACCOUNT_KEY",
|
|
10
|
+
BLOB_ENDPOINT: "OSVA_ARTIFACT_AZURE_BLOB_ENDPOINT",
|
|
11
|
+
};
|
|
12
|
+
function readNonEmptyEnv(name) {
|
|
13
|
+
const value = process.env[name]?.trim();
|
|
14
|
+
return value === undefined || value.length === 0 ? undefined : value;
|
|
15
|
+
}
|
|
16
|
+
function assertSafeContainerName(containerName) {
|
|
17
|
+
if (!/^[a-z0-9](?:[a-z0-9-]{1,61}[a-z0-9])?$/.test(containerName)) {
|
|
18
|
+
throw configurationError("OSVA_ARTIFACT_AZURE_CONTAINER must be a valid Azure container name (3–63 lowercase alphanumeric characters and hyphens).");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function createClientFromConnectionString(connectionString) {
|
|
22
|
+
try {
|
|
23
|
+
return BlobServiceClient.fromConnectionString(connectionString);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
const detail = error instanceof Error
|
|
27
|
+
? sanitizeExternalMessage(error.message)
|
|
28
|
+
: "Invalid connection string.";
|
|
29
|
+
throw configurationError(`Failed to parse ${AZURE_ARTIFACT_ENV.CONNECTION_STRING}: ${detail}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function createClientFromSharedKey(accountName, accountKey, blobEndpoint) {
|
|
33
|
+
const credential = new StorageSharedKeyCredential(accountName, accountKey);
|
|
34
|
+
const url = blobEndpoint ?? `https://${accountName}.blob.core.windows.net`;
|
|
35
|
+
try {
|
|
36
|
+
return new BlobServiceClient(url, credential);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const detail = error instanceof Error
|
|
40
|
+
? sanitizeExternalMessage(error.message)
|
|
41
|
+
: "Invalid blob endpoint.";
|
|
42
|
+
throw configurationError(`Failed to create Azure Blob service client: ${detail}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function resolveAzureArtifactConfigFromEnv() {
|
|
46
|
+
const containerName = readNonEmptyEnv(AZURE_ARTIFACT_ENV.CONTAINER);
|
|
47
|
+
if (containerName === undefined) {
|
|
48
|
+
throw configurationError(`${AZURE_ARTIFACT_ENV.CONTAINER} is required for @osva-ai/adapter-artifact-azure.`);
|
|
49
|
+
}
|
|
50
|
+
assertSafeContainerName(containerName);
|
|
51
|
+
const connectionString = readNonEmptyEnv(AZURE_ARTIFACT_ENV.CONNECTION_STRING);
|
|
52
|
+
const accountName = readNonEmptyEnv(AZURE_ARTIFACT_ENV.ACCOUNT_NAME);
|
|
53
|
+
const accountKey = readNonEmptyEnv(AZURE_ARTIFACT_ENV.ACCOUNT_KEY);
|
|
54
|
+
const blobEndpoint = readNonEmptyEnv(AZURE_ARTIFACT_ENV.BLOB_ENDPOINT);
|
|
55
|
+
if (connectionString !== undefined) {
|
|
56
|
+
if (accountName !== undefined || accountKey !== undefined) {
|
|
57
|
+
throw configurationError(`Set either ${AZURE_ARTIFACT_ENV.CONNECTION_STRING} or ${AZURE_ARTIFACT_ENV.ACCOUNT_NAME} + ${AZURE_ARTIFACT_ENV.ACCOUNT_KEY}, not both.`);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
containerName,
|
|
61
|
+
blobServiceClient: createClientFromConnectionString(connectionString),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (accountName === undefined || accountKey === undefined) {
|
|
65
|
+
throw configurationError(`Azure credentials are required: set ${AZURE_ARTIFACT_ENV.CONNECTION_STRING} or both ${AZURE_ARTIFACT_ENV.ACCOUNT_NAME} and ${AZURE_ARTIFACT_ENV.ACCOUNT_KEY}.`);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
containerName,
|
|
69
|
+
blobServiceClient: createClientFromSharedKey(accountName, accountKey, blobEndpoint),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAExD,wEAAwE;AACxE,MAAM,CAAC,M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C;QAC1D,MAAM,kBAAkB,CACtB,uCAAuC,kBAAkB,CAAC,iBAAiB,YAAY,kBAAkB,CAAC,YAAY,QAAQ,kBAAkB,CAAC,WAAW,GAAG,CAChK,CAAC;IACJ,CAAC;IAED,OAAO;QACL,aAAa;QACb,iBAAiB,EAAE,yBAAyB,CAC1C,WAAW,EACX,UAAU,EACV,YAAY,CACb;KACF,CAAC;AACJ,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ArtifactErrorCode } from "@osva-ai/contracts";
|
|
2
|
+
export declare class ArtifactBlobStoreError extends Error {
|
|
3
|
+
readonly code: ArtifactErrorCode;
|
|
4
|
+
constructor(code: ArtifactErrorCode, message: string);
|
|
5
|
+
}
|
|
6
|
+
export declare function payloadTooLarge(maxBytes: number): ArtifactBlobStoreError;
|
|
7
|
+
export declare function digestMismatch(): ArtifactBlobStoreError;
|
|
8
|
+
export declare function blobUnavailable(key: string): ArtifactBlobStoreError;
|
|
9
|
+
export declare function invalidRequest(message: string): ArtifactBlobStoreError;
|
|
10
|
+
export declare function configurationError(message: string): ArtifactBlobStoreError;
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;gBAErB,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM;CAKrD;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,sBAAsB,CAKxE;AAED,wBAAgB,cAAc,IAAI,sBAAsB,CAKvD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB,CAKnE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,sBAAsB,CAKtE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,sBAAsB,CAK1E"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ARTIFACT_ERROR_CODES, } from "@osva-ai/contracts";
|
|
2
|
+
export class ArtifactBlobStoreError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "ArtifactBlobStoreError";
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function payloadTooLarge(maxBytes) {
|
|
11
|
+
return new ArtifactBlobStoreError(ARTIFACT_ERROR_CODES.ARTIFACT_PAYLOAD_TOO_LARGE, `Artifact payload exceeds maxBytes (${String(maxBytes)}).`);
|
|
12
|
+
}
|
|
13
|
+
export function digestMismatch() {
|
|
14
|
+
return new ArtifactBlobStoreError(ARTIFACT_ERROR_CODES.ARTIFACT_DIGEST_MISMATCH, "Artifact digest does not match expectedDigest.");
|
|
15
|
+
}
|
|
16
|
+
export function blobUnavailable(key) {
|
|
17
|
+
return new ArtifactBlobStoreError(ARTIFACT_ERROR_CODES.ARTIFACT_UNAVAILABLE, `Artifact blob is unavailable for key '${key}'.`);
|
|
18
|
+
}
|
|
19
|
+
export function invalidRequest(message) {
|
|
20
|
+
return new ArtifactBlobStoreError(ARTIFACT_ERROR_CODES.ARTIFACT_INVALID_REQUEST, message);
|
|
21
|
+
}
|
|
22
|
+
export function configurationError(message) {
|
|
23
|
+
return new ArtifactBlobStoreError(ARTIFACT_ERROR_CODES.ARTIFACT_INVALID_REQUEST, message);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,GAErB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACtC,IAAI,CAAoB;IAEjC,YAAY,IAAuB,EAAE,OAAe;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,IAAI,sBAAsB,CAC/B,oBAAoB,CAAC,0BAA0B,EAC/C,sCAAsC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAC3D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,sBAAsB,CAC/B,oBAAoB,CAAC,wBAAwB,EAC7C,gDAAgD,CACjD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,OAAO,IAAI,sBAAsB,CAC/B,oBAAoB,CAAC,oBAAoB,EACzC,yCAAyC,GAAG,IAAI,CACjD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,OAAO,IAAI,sBAAsB,CAC/B,oBAAoB,CAAC,wBAAwB,EAC7C,OAAO,CACR,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,OAAO,IAAI,sBAAsB,CAC/B,oBAAoB,CAAC,wBAAwB,EAC7C,OAAO,CACR,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createArtifactBlobStore } from "./azure-artifact-blob-store.js";
|
|
2
|
+
export { default as registeredArtifactBlobStoreModule } from "./azure-artifact-blob-store.js";
|
|
3
|
+
export { ArtifactBlobStoreError, blobUnavailable, digestMismatch, invalidRequest, payloadTooLarge, } from "./errors.js";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,iCAAiC,EAAE,MAAM,gCAAgC,CAAC;AAC9F,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,GAChB,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createArtifactBlobStore } from "./azure-artifact-blob-store.js";
|
|
2
|
+
export { default as registeredArtifactBlobStoreModule } from "./azure-artifact-blob-store.js";
|
|
3
|
+
export { ArtifactBlobStoreError, blobUnavailable, digestMismatch, invalidRequest, payloadTooLarge, } from "./errors.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,iCAAiC,EAAE,MAAM,gCAAgC,CAAC;AAC9F,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,GAChB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":"AAYA,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAM/D"}
|
package/dist/sanitize.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const SECRET_PATTERNS = [
|
|
2
|
+
/AccountKey=[^;\s]+/gi,
|
|
3
|
+
/SharedAccessSignature=[^;\s]+/gi,
|
|
4
|
+
/DefaultEndpointsProtocol=[^;\s]+;AccountName=[^;\s]+;AccountKey=[^;\s]+/gi,
|
|
5
|
+
/sig=[^&\s]+/gi,
|
|
6
|
+
/se=[^&\s]+/gi,
|
|
7
|
+
/sp=[^&\s]+/gi,
|
|
8
|
+
/sv=[^&\s]+/gi,
|
|
9
|
+
/sr=[^&\s]+/gi,
|
|
10
|
+
/Bearer\s+[A-Za-z0-9\-._~+/]+=*/gi,
|
|
11
|
+
];
|
|
12
|
+
export function sanitizeExternalMessage(message) {
|
|
13
|
+
let sanitized = message;
|
|
14
|
+
for (const pattern of SECRET_PATTERNS) {
|
|
15
|
+
sanitized = sanitized.replace(pattern, "[redacted]");
|
|
16
|
+
}
|
|
17
|
+
return sanitized;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=sanitize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAsB;IACzC,sBAAsB;IACtB,iCAAiC;IACjC,2EAA2E;IAC3E,eAAe;IACf,cAAc;IACd,cAAc;IACd,cAAc;IACd,cAAc;IACd,kCAAkC;CACnC,CAAC;AAEF,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,IAAI,SAAS,GAAG,OAAO,CAAC;IACxB,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;QACtC,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PassThrough } from "node:stream";
|
|
2
|
+
import { type ArtifactBlobContentStream } from "@osva-ai/contracts";
|
|
3
|
+
export interface DigestingStreamResult {
|
|
4
|
+
readonly stream: PassThrough;
|
|
5
|
+
readonly digestPromise: Promise<{
|
|
6
|
+
sizeBytes: number;
|
|
7
|
+
digest: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export declare function uploadBufferSizeBytes(): number;
|
|
11
|
+
export declare function createDigestingReadable(content: ArtifactBlobContentStream, maxBytes: number): DigestingStreamResult;
|
|
12
|
+
//# sourceMappingURL=stream-digest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-digest.d.ts","sourceRoot":"","sources":["../src/stream-digest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,oBAAoB,CAAC;AAQ5B,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACxE;AAID,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,yBAAyB,EAClC,QAAQ,EAAE,MAAM,GACf,qBAAqB,CAoDvB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { PassThrough } from "node:stream";
|
|
3
|
+
import { SHA256_INTEGRITY_PREFIX, } from "@osva-ai/contracts";
|
|
4
|
+
import { ArtifactBlobStoreError, invalidRequest, payloadTooLarge, } from "./errors.js";
|
|
5
|
+
const UPLOAD_BUFFER_SIZE = 4 * 1024 * 1024;
|
|
6
|
+
export function uploadBufferSizeBytes() {
|
|
7
|
+
return UPLOAD_BUFFER_SIZE;
|
|
8
|
+
}
|
|
9
|
+
export function createDigestingReadable(content, maxBytes) {
|
|
10
|
+
if (!Number.isFinite(maxBytes) || maxBytes < 0) {
|
|
11
|
+
throw invalidRequest("maxBytes must be a non-negative finite number.");
|
|
12
|
+
}
|
|
13
|
+
const pass = new PassThrough({ highWaterMark: UPLOAD_BUFFER_SIZE });
|
|
14
|
+
const hash = createHash("sha256");
|
|
15
|
+
let sizeBytes = 0;
|
|
16
|
+
const digestPromise = (async () => {
|
|
17
|
+
try {
|
|
18
|
+
for await (const chunk of content) {
|
|
19
|
+
if (chunk === undefined || chunk === null) {
|
|
20
|
+
throw invalidRequest("Artifact content stream yielded an empty chunk.");
|
|
21
|
+
}
|
|
22
|
+
const buffer = Buffer.from(chunk);
|
|
23
|
+
sizeBytes += buffer.length;
|
|
24
|
+
if (sizeBytes > maxBytes) {
|
|
25
|
+
throw payloadTooLarge(maxBytes);
|
|
26
|
+
}
|
|
27
|
+
hash.update(buffer);
|
|
28
|
+
const canContinue = pass.write(buffer);
|
|
29
|
+
if (!canContinue) {
|
|
30
|
+
await new Promise((resolve) => pass.once("drain", resolve));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
pass.end();
|
|
34
|
+
return {
|
|
35
|
+
sizeBytes,
|
|
36
|
+
digest: `${SHA256_INTEGRITY_PREFIX}${hash.digest("hex")}`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
pass.destroy(error instanceof Error ? error : new Error("Stream pipeline failed."));
|
|
41
|
+
if (error instanceof ArtifactBlobStoreError) {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
throw invalidRequest(error instanceof Error
|
|
45
|
+
? error.message
|
|
46
|
+
: "Artifact content stream failed.");
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
49
|
+
return { stream: pass, digestPromise };
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=stream-digest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-digest.js","sourceRoot":"","sources":["../src/stream-digest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EACL,uBA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AC;oBACjB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;gBACpE,CAAC;YACH,CAAC;YACD,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,OAAO;gBACL,SAAS;gBACT,MAAM,EAAE,GAAG,uBAAuB,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;aAC1D,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,OAAO,CACV,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,yBAAyB,CAAC,CACtE,CAAC;YACF,IAAI,KAAK,YAAY,sBAAsB,EAAE,CAAC;gBAC5C,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,cAAc,CAClB,KAAK,YAAY,KAAK;gBACpB,CAAC,CAAC,KAAK,CAAC,OAAO;gBACf,CAAC,CAAC,iCAAiC,CACtC,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;AACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osva-ai/adapter-artifact-azure",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Azure Blob Storage ArtifactBlobStore adapter for OSVA (operator-configured credentials)",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Osva-AI/osva-adapters.git",
|
|
9
|
+
"directory": "packages/artifact-azure"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/Osva-AI/osva-adapters/tree/main/packages/artifact-azure",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=24"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@azure/storage-blob": "12.28.0",
|
|
31
|
+
"@osva-ai/contracts": "1.1.0-rc.3"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "24.13.4",
|
|
35
|
+
"eslint": "10.10.0",
|
|
36
|
+
"typescript": "6.0.3",
|
|
37
|
+
"vitest": "5.0.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"lint": "eslint .",
|
|
42
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
43
|
+
"test": "vitest run --config vitest.config.ts",
|
|
44
|
+
"test:integration": "vitest run --config vitest.config.ts --testNamePattern Azurite"
|
|
45
|
+
}
|
|
6
46
|
}
|