@pithy-sh/storage 0.1.6 → 0.2.1
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/capability.js +2 -2
- package/dist/secret/registry.d.ts +21 -1
- package/dist/secret/registry.d.ts.map +1 -1
- package/dist/secret/registry.js +21 -4
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/package.json +13 -10
- package/src/capability.ts +2 -2
- package/src/secret/registry.ts +28 -3
- package/src/version.generated.ts +1 -1
package/dist/capability.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { StorageConfig } from "./config/config.js";
|
|
4
4
|
import { storageTables } from "./data/tables.js";
|
|
5
|
-
import { storageSecretsRegistry } from "./secret/registry.js";
|
|
5
|
+
import { STORAGE_BUCKET_BINDING, storageSecretsRegistry } from "./secret/registry.js";
|
|
6
6
|
import { registerStorageRoutes } from "./http/routes.js";
|
|
7
7
|
import { storage_0001_objects } from "./migrations/0001_objects.js";
|
|
8
8
|
import { storageExampleSeed } from "./seeds/example.js";
|
|
@@ -42,7 +42,7 @@ function storage(options = {}) {
|
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
type: "r2",
|
|
45
|
-
name:
|
|
45
|
+
name: STORAGE_BUCKET_BINDING
|
|
46
46
|
},
|
|
47
47
|
...workflowBindings(storageWorkflows)
|
|
48
48
|
];
|
|
@@ -59,14 +59,34 @@ export interface R2CredentialsEntry {
|
|
|
59
59
|
origin: SecretOrigin;
|
|
60
60
|
/** How the pair is replaced. `manual`, always — the same page, by the same human. */
|
|
61
61
|
rotation: SecretRotation;
|
|
62
|
+
/**
|
|
63
|
+
* The R2 binding this bundle presigns, when the declaring capability names one — `STORAGE_BUCKET`,
|
|
64
|
+
* `MEDIA_BUCKET`, `SUPPORT_BUCKET`. See {@link SecretRegistryEntryBase.binding}: it is what lets
|
|
65
|
+
* `pithy doctor` and `pithy secrets ls` stop asking for a credential whose bucket the project has
|
|
66
|
+
* declined (#541).
|
|
67
|
+
*/
|
|
68
|
+
binding?: string;
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* A one-entry secret-registry slice declaring `name` as an R2 credential bundle. Hang it on the
|
|
65
72
|
* declaring capability's `secretRegistry`, then pass the same `name` to `objectStore`.
|
|
73
|
+
*
|
|
74
|
+
* **`binding` is the bucket this bundle presigns**, and a capability that declares this slice states it
|
|
75
|
+
* — `STORAGE_BUCKET` here, `MEDIA_BUCKET` in `@pithy-sh/media`, `SUPPORT_BUCKET` in `@pithy-sh/support`.
|
|
76
|
+
* It is what lets the CLI stop asking for a credential whose bucket the project declined (#541), and
|
|
77
|
+
* `secret/registry.test.ts` in each of those packages holds its own call to it.
|
|
78
|
+
*
|
|
79
|
+
* It is **optional rather than required**, and for exactly one caller: `objectStore` builds a one-entry
|
|
80
|
+
* registry per read from the secret *name* it was handed, holding an `R2Bucket` object and no binding
|
|
81
|
+
* name to state. That registry is never composed onto a capability and never reaches a reporting
|
|
82
|
+
* command, so the field would have nothing to say there — and making it required would force that call
|
|
83
|
+
* site to invent one.
|
|
66
84
|
*/
|
|
67
|
-
export declare function r2CredentialsRegistry<const N extends string>(name: N): Record<N, R2CredentialsEntry>;
|
|
85
|
+
export declare function r2CredentialsRegistry<const N extends string>(name: N, binding?: string): Record<N, R2CredentialsEntry>;
|
|
68
86
|
/** The name storage's own bucket credentials are stored and resolved under. */
|
|
69
87
|
export declare const STORAGE_R2_SECRET = "storage-r2-credentials";
|
|
88
|
+
/** The binding storage's own bundle presigns — the one `storage()` declares and `objectStore` writes through. */
|
|
89
|
+
export declare const STORAGE_BUCKET_BINDING = "STORAGE_BUCKET";
|
|
70
90
|
/** The storage capability's secret-registry slice — aggregated into the shared accessor at startup. */
|
|
71
91
|
export declare const storageSecretsRegistry: Record<"storage-r2-credentials", R2CredentialsEntry>;
|
|
72
92
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/secret/registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAE/F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;GAeG;AAEH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;iBAkBmF,CAAC;AACrH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;OAQG;IACH,OAAO,EAAE,IAAI,CAAC;IACd,uEAAuE;IACvE,KAAK,EAAE,aAAa,CAAC;IACrB,uFAAuF;IACvF,SAAS,EAAE,KAAK,CAAC;IACjB,0FAA0F;IAC1F,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,MAAM,EAAE,OAAO,oBAAoB,CAAC;IACpC,uFAAuF;IACvF,MAAM,EAAE,YAAY,CAAC;IACrB,qFAAqF;IACrF,QAAQ,EAAE,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/secret/registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAE/F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;GAeG;AAEH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;iBAkBmF,CAAC;AACrH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;OAQG;IACH,OAAO,EAAE,IAAI,CAAC;IACd,uEAAuE;IACvE,KAAK,EAAE,aAAa,CAAC;IACrB,uFAAuF;IACvF,SAAS,EAAE,KAAK,CAAC;IACjB,0FAA0F;IAC1F,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,MAAM,EAAE,OAAO,oBAAoB,CAAC;IACpC,uFAAuF;IACvF,MAAM,EAAE,YAAY,CAAC;IACrB,qFAAqF;IACrF,QAAQ,EAAE,cAAc,CAAC;IACzB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAmCD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAC1D,IAAI,EAAE,CAAC,EACP,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAG/B;AAED,+EAA+E;AAC/E,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D,iHAAiH;AACjH,eAAO,MAAM,sBAAsB,mBAAmB,CAAC;AAEvD,uGAAuG;AACvG,eAAO,MAAM,sBAAsB,sDAAmE,CAAC"}
|
package/dist/secret/registry.js
CHANGED
|
@@ -72,13 +72,30 @@ const R2_CREDENTIALS_ENTRY = {
|
|
|
72
72
|
/**
|
|
73
73
|
* A one-entry secret-registry slice declaring `name` as an R2 credential bundle. Hang it on the
|
|
74
74
|
* declaring capability's `secretRegistry`, then pass the same `name` to `objectStore`.
|
|
75
|
+
*
|
|
76
|
+
* **`binding` is the bucket this bundle presigns**, and a capability that declares this slice states it
|
|
77
|
+
* — `STORAGE_BUCKET` here, `MEDIA_BUCKET` in `@pithy-sh/media`, `SUPPORT_BUCKET` in `@pithy-sh/support`.
|
|
78
|
+
* It is what lets the CLI stop asking for a credential whose bucket the project declined (#541), and
|
|
79
|
+
* `secret/registry.test.ts` in each of those packages holds its own call to it.
|
|
80
|
+
*
|
|
81
|
+
* It is **optional rather than required**, and for exactly one caller: `objectStore` builds a one-entry
|
|
82
|
+
* registry per read from the secret *name* it was handed, holding an `R2Bucket` object and no binding
|
|
83
|
+
* name to state. That registry is never composed onto a capability and never reaches a reporting
|
|
84
|
+
* command, so the field would have nothing to say there — and making it required would force that call
|
|
85
|
+
* site to invent one.
|
|
75
86
|
*/
|
|
76
|
-
function r2CredentialsRegistry(name) {
|
|
77
|
-
|
|
87
|
+
function r2CredentialsRegistry(name, binding) {
|
|
88
|
+
const entry = binding === void 0 ? R2_CREDENTIALS_ENTRY : {
|
|
89
|
+
...R2_CREDENTIALS_ENTRY,
|
|
90
|
+
binding
|
|
91
|
+
};
|
|
92
|
+
return defineSecretRegistry({ [name]: entry });
|
|
78
93
|
}
|
|
79
94
|
/** The name storage's own bucket credentials are stored and resolved under. */
|
|
80
95
|
const STORAGE_R2_SECRET = "storage-r2-credentials";
|
|
96
|
+
/** The binding storage's own bundle presigns — the one `storage()` declares and `objectStore` writes through. */
|
|
97
|
+
const STORAGE_BUCKET_BINDING = "STORAGE_BUCKET";
|
|
81
98
|
/** The storage capability's secret-registry slice — aggregated into the shared accessor at startup. */
|
|
82
|
-
const storageSecretsRegistry = r2CredentialsRegistry(STORAGE_R2_SECRET);
|
|
99
|
+
const storageSecretsRegistry = r2CredentialsRegistry(STORAGE_R2_SECRET, STORAGE_BUCKET_BINDING);
|
|
83
100
|
//#endregion
|
|
84
|
-
export { R2StorageCredentials, STORAGE_R2_SECRET, r2CredentialsRegistry, storageSecretsRegistry };
|
|
101
|
+
export { R2StorageCredentials, STORAGE_BUCKET_BINDING, STORAGE_R2_SECRET, r2CredentialsRegistry, storageSecretsRegistry };
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
/** This package's npm name — the join key against a release feed. */
|
|
4
4
|
export declare const PACKAGE_NAME = "@pithy-sh/storage";
|
|
5
5
|
/** This package's version, stamped from its own package.json at generation time. */
|
|
6
|
-
export declare const PACKAGE_VERSION = "0.1
|
|
6
|
+
export declare const PACKAGE_VERSION = "0.2.1";
|
|
7
7
|
//# sourceMappingURL=version.generated.d.ts.map
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
/** This package's npm name — the join key against a release feed. */
|
|
5
5
|
const PACKAGE_NAME = "@pithy-sh/storage";
|
|
6
6
|
/** This package's version, stamped from its own package.json at generation time. */
|
|
7
|
-
const PACKAGE_VERSION = "0.1
|
|
7
|
+
const PACKAGE_VERSION = "0.2.1";
|
|
8
8
|
//#endregion
|
|
9
9
|
export { PACKAGE_NAME, PACKAGE_VERSION };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pithy-sh/storage",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,13 +36,21 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@cloudflare/workers-types": "^5.20260729.1",
|
|
39
|
-
"@hono/zod-validator": "^0.9.0"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"@pithy-sh/
|
|
39
|
+
"@hono/zod-validator": "^0.9.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@pithy-sh/cloudflare": "^0.2.1",
|
|
43
|
+
"@pithy-sh/core": "^0.5.0",
|
|
44
|
+
"@pithy-sh/secrets": "^0.2.1",
|
|
45
|
+
"hono": "^4.13.2",
|
|
46
|
+
"kysely": "^0.29.0",
|
|
47
|
+
"zod": "^4.4.0"
|
|
43
48
|
},
|
|
44
49
|
"devDependencies": {
|
|
45
50
|
"@cloudflare/vitest-plugin": "^1.0.0",
|
|
51
|
+
"@pithy-sh/cloudflare": "workspace:*",
|
|
52
|
+
"@pithy-sh/core": "workspace:*",
|
|
53
|
+
"@pithy-sh/secrets": "workspace:*",
|
|
46
54
|
"@pithy-sh/tsconfig": "workspace:*",
|
|
47
55
|
"@types/node": "^22.15.0",
|
|
48
56
|
"@vitest/coverage-v8": "^4.1.0",
|
|
@@ -54,10 +62,5 @@
|
|
|
54
62
|
"vitest": "^4.1.0",
|
|
55
63
|
"wrangler": "^4.115.0",
|
|
56
64
|
"zod": "^4.4.0"
|
|
57
|
-
},
|
|
58
|
-
"peerDependencies": {
|
|
59
|
-
"hono": "^4.13.2",
|
|
60
|
-
"kysely": "^0.29.0",
|
|
61
|
-
"zod": "^4.4.0"
|
|
62
65
|
}
|
|
63
66
|
}
|
package/src/capability.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { StorageConfig, type StorageConfigInput } from "./config/config";
|
|
|
11
11
|
import { storageTables } from "./data/tables";
|
|
12
12
|
import { registerStorageRoutes } from "./http/routes";
|
|
13
13
|
import { storage_0001_objects } from "./migrations/0001_objects";
|
|
14
|
-
import { storageSecretsRegistry } from "./secret/registry";
|
|
14
|
+
import { STORAGE_BUCKET_BINDING, storageSecretsRegistry } from "./secret/registry";
|
|
15
15
|
import { storageExampleSeed } from "./seeds/example";
|
|
16
16
|
import { PACKAGE_VERSION } from "./version.generated";
|
|
17
17
|
import { storageWorkflows } from "./workflows/specs";
|
|
@@ -66,7 +66,7 @@ export function storage(options: StorageOptions = {}): StorageCapability {
|
|
|
66
66
|
// The app database — the objects and shares tables live here.
|
|
67
67
|
{ type: "d1", name: "DB" },
|
|
68
68
|
// The bucket the bytes live in. Deliberately separate from media's `MEDIA_BUCKET`.
|
|
69
|
-
{ type: "r2", name:
|
|
69
|
+
{ type: "r2", name: STORAGE_BUCKET_BINDING },
|
|
70
70
|
// The sweep's Workflow binding, derived from the spec rather than written again — one declaration,
|
|
71
71
|
// so a binding rename cannot leave the two disagreeing. Optional: the binding exists only once
|
|
72
72
|
// `pithy storage provision` has deployed the sweep worker, and an unprovisioned project must still
|
package/src/secret/registry.ts
CHANGED
|
@@ -77,6 +77,13 @@ export interface R2CredentialsEntry {
|
|
|
77
77
|
origin: SecretOrigin;
|
|
78
78
|
/** How the pair is replaced. `manual`, always — the same page, by the same human. */
|
|
79
79
|
rotation: SecretRotation;
|
|
80
|
+
/**
|
|
81
|
+
* The R2 binding this bundle presigns, when the declaring capability names one — `STORAGE_BUCKET`,
|
|
82
|
+
* `MEDIA_BUCKET`, `SUPPORT_BUCKET`. See {@link SecretRegistryEntryBase.binding}: it is what lets
|
|
83
|
+
* `pithy doctor` and `pithy secrets ls` stop asking for a credential whose bucket the project has
|
|
84
|
+
* declined (#541).
|
|
85
|
+
*/
|
|
86
|
+
binding?: string;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
/**
|
|
@@ -115,13 +122,31 @@ const R2_CREDENTIALS_ENTRY: R2CredentialsEntry = {
|
|
|
115
122
|
/**
|
|
116
123
|
* A one-entry secret-registry slice declaring `name` as an R2 credential bundle. Hang it on the
|
|
117
124
|
* declaring capability's `secretRegistry`, then pass the same `name` to `objectStore`.
|
|
125
|
+
*
|
|
126
|
+
* **`binding` is the bucket this bundle presigns**, and a capability that declares this slice states it
|
|
127
|
+
* — `STORAGE_BUCKET` here, `MEDIA_BUCKET` in `@pithy-sh/media`, `SUPPORT_BUCKET` in `@pithy-sh/support`.
|
|
128
|
+
* It is what lets the CLI stop asking for a credential whose bucket the project declined (#541), and
|
|
129
|
+
* `secret/registry.test.ts` in each of those packages holds its own call to it.
|
|
130
|
+
*
|
|
131
|
+
* It is **optional rather than required**, and for exactly one caller: `objectStore` builds a one-entry
|
|
132
|
+
* registry per read from the secret *name* it was handed, holding an `R2Bucket` object and no binding
|
|
133
|
+
* name to state. That registry is never composed onto a capability and never reaches a reporting
|
|
134
|
+
* command, so the field would have nothing to say there — and making it required would force that call
|
|
135
|
+
* site to invent one.
|
|
118
136
|
*/
|
|
119
|
-
export function r2CredentialsRegistry<const N extends string>(
|
|
120
|
-
|
|
137
|
+
export function r2CredentialsRegistry<const N extends string>(
|
|
138
|
+
name: N,
|
|
139
|
+
binding?: string,
|
|
140
|
+
): Record<N, R2CredentialsEntry> {
|
|
141
|
+
const entry: R2CredentialsEntry = binding === undefined ? R2_CREDENTIALS_ENTRY : { ...R2_CREDENTIALS_ENTRY, binding };
|
|
142
|
+
return defineSecretRegistry({ [name]: entry } as Record<N, R2CredentialsEntry> & SecretRegistry);
|
|
121
143
|
}
|
|
122
144
|
|
|
123
145
|
/** The name storage's own bucket credentials are stored and resolved under. */
|
|
124
146
|
export const STORAGE_R2_SECRET = "storage-r2-credentials";
|
|
125
147
|
|
|
148
|
+
/** The binding storage's own bundle presigns — the one `storage()` declares and `objectStore` writes through. */
|
|
149
|
+
export const STORAGE_BUCKET_BINDING = "STORAGE_BUCKET";
|
|
150
|
+
|
|
126
151
|
/** The storage capability's secret-registry slice — aggregated into the shared accessor at startup. */
|
|
127
|
-
export const storageSecretsRegistry = r2CredentialsRegistry(STORAGE_R2_SECRET);
|
|
152
|
+
export const storageSecretsRegistry = r2CredentialsRegistry(STORAGE_R2_SECRET, STORAGE_BUCKET_BINDING);
|
package/src/version.generated.ts
CHANGED