@healthzkit/s3 0.0.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/README.md +136 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +1 -0
- package/dist/shared-B-1hAtzF.mjs +1 -0
- package/dist/shared-B3WTV2_N.d.mts +13 -0
- package/dist/v2.d.mts +17 -0
- package/dist/v2.mjs +1 -0
- package/dist/v3.d.mts +16 -0
- package/dist/v3.mjs +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# @healthzkit/s3
|
|
2
|
+
|
|
3
|
+
Amazon S3 **healthzkit** `HealthAdapter` helpers for AWS SDK v2 **[`aws-sdk`](https://github.com/aws/aws-sdk-js)** and v3 **[`@aws-sdk/client-s3`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/)**. Successful checks call `ListBuckets` and return `ok` with `metadata.latencyMs`, `metadata.bucketCount`, plus any fields from an optional `metadata` hook; failures return `fail` with the caught error.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @healthzkit/s3 healthzkit
|
|
9
|
+
# plus one of:
|
|
10
|
+
npm install aws-sdk
|
|
11
|
+
npm install @aws-sdk/client-s3
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Both SDKs are optional peers—install only the one you use.
|
|
15
|
+
|
|
16
|
+
## Package entrypoints
|
|
17
|
+
|
|
18
|
+
| Import | Exports |
|
|
19
|
+
| ------------------- | ---------------------------------------------- |
|
|
20
|
+
| `@healthzkit/s3` | `s3V2Adapter`, `s3V3Adapter`, and option types |
|
|
21
|
+
| `@healthzkit/s3/v2` | `s3V2Adapter` only |
|
|
22
|
+
| `@healthzkit/s3/v3` | `s3V3Adapter` only |
|
|
23
|
+
|
|
24
|
+
Use subpath imports when you want to avoid pulling the unused SDK into your bundle analysis path.
|
|
25
|
+
|
|
26
|
+
## Shared options
|
|
27
|
+
|
|
28
|
+
Both factories accept `BaseS3Options`:
|
|
29
|
+
|
|
30
|
+
| Option | Description |
|
|
31
|
+
| ---------- | ----------------------------------------------------------------------------------------------------- |
|
|
32
|
+
| `metadata` | Optional `(client) => Record<string, unknown>` (sync or async) merged into metadata with `latencyMs`. |
|
|
33
|
+
|
|
34
|
+
Pass either `config` or an existing `client` (not both). The shape depends on the adapter (see below).
|
|
35
|
+
|
|
36
|
+
## `s3V2Adapter` (`aws-sdk`)
|
|
37
|
+
|
|
38
|
+
**Peer:** `aws-sdk` ≥ 2.
|
|
39
|
+
|
|
40
|
+
Uses the v2 `S3` client and `listBuckets()`. Suitable for legacy services still on AWS SDK for JavaScript v2.
|
|
41
|
+
|
|
42
|
+
### Config
|
|
43
|
+
|
|
44
|
+
The adapter lazily imports `aws-sdk`, constructs `new AWS.S3(config)` once, and reuses it across checks.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { createHealthKit } from "healthzkit";
|
|
48
|
+
import { s3V2Adapter } from "@healthzkit/s3";
|
|
49
|
+
|
|
50
|
+
const kit = createHealthKit({
|
|
51
|
+
checks: [
|
|
52
|
+
{
|
|
53
|
+
name: "s3",
|
|
54
|
+
type: ["readiness"],
|
|
55
|
+
adapter: s3V2Adapter({
|
|
56
|
+
config: { region: process.env.AWS_REGION ?? "us-east-1" },
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Existing client
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import AWS from "aws-sdk";
|
|
67
|
+
import { s3V2Adapter } from "@healthzkit/s3/v2";
|
|
68
|
+
|
|
69
|
+
const client = new AWS.S3({ region: "us-east-1" });
|
|
70
|
+
|
|
71
|
+
const adapter = s3V2Adapter({
|
|
72
|
+
client,
|
|
73
|
+
metadata: () => ({ sdk: "v2" }),
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## `s3V3Adapter` (`@aws-sdk/client-s3`)
|
|
78
|
+
|
|
79
|
+
**Peer:** `@aws-sdk/client-s3` ≥ 3.
|
|
80
|
+
|
|
81
|
+
Uses `S3Client` and `ListBucketsCommand`. Prefer this for new code on AWS SDK for JavaScript v3.
|
|
82
|
+
|
|
83
|
+
### Config
|
|
84
|
+
|
|
85
|
+
The adapter lazily imports `@aws-sdk/client-s3`, constructs `new S3Client(config)` once, and reuses it across checks.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { s3V3Adapter } from "@healthzkit/s3/v3";
|
|
89
|
+
|
|
90
|
+
const adapter = s3V3Adapter({
|
|
91
|
+
config: { region: process.env.AWS_REGION ?? "us-east-1" },
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Existing client
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { S3Client } from "@aws-sdk/client-s3";
|
|
99
|
+
import { s3V3Adapter } from "@healthzkit/s3";
|
|
100
|
+
|
|
101
|
+
const client = new S3Client({ region: "us-east-1" });
|
|
102
|
+
|
|
103
|
+
const adapter = s3V3Adapter({
|
|
104
|
+
client,
|
|
105
|
+
metadata: async () => ({ sdk: "v3" }),
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Check result
|
|
110
|
+
|
|
111
|
+
On success:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"status": "ok",
|
|
116
|
+
"metadata": { "latencyMs": 42, "bucketCount": 3 }
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
On failure, `status` is `"fail"` and `error` is set (see [healthzkit](https://github.com/alasti-company/healthzkit) for how that rolls up into probe responses).
|
|
121
|
+
|
|
122
|
+
## Scheduling
|
|
123
|
+
|
|
124
|
+
For S3 buckets that should not be queried on every probe, pair these adapters with a **`schedule`** on the check so readiness reads cached results. See the **Scheduling** section in the `healthzkit` README.
|
|
125
|
+
|
|
126
|
+
## Development
|
|
127
|
+
|
|
128
|
+
From the monorepo root:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
vp install
|
|
132
|
+
vp test --filter @healthzkit/s3
|
|
133
|
+
vp pack --filter @healthzkit/s3
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
See the repo root `AGENTS.md` for Vite+ / `vp` conventions.
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{s3V3Adapter as e}from"./v3.mjs";import{s3V2Adapter as t}from"./v2.mjs";export{t as s3V2Adapter,e as s3V3Adapter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){return{status:`ok`,metadata:{...t,latencyMs:e}}}function t(e){return{status:`fail`,error:e instanceof Error?e:Error(String(e))}}export{e as n,t};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HealthAdapter } from "healthzkit";
|
|
2
|
+
|
|
3
|
+
//#region src/shared.d.ts
|
|
4
|
+
type MetadataFn<TClient> = (client: TClient) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
5
|
+
interface BaseS3Options<TClient> {
|
|
6
|
+
/**
|
|
7
|
+
* Optional function to populate metadata in the check result.
|
|
8
|
+
* Receives the resolved client so you can run additional operations.
|
|
9
|
+
*/
|
|
10
|
+
metadata?: MetadataFn<TClient>;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { HealthAdapter as n, BaseS3Options as t };
|
package/dist/v2.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { n as HealthAdapter, t as BaseS3Options } from "./shared-B3WTV2_N.mjs";
|
|
2
|
+
import AWS from "aws-sdk";
|
|
3
|
+
|
|
4
|
+
//#region src/v2.d.ts
|
|
5
|
+
type S3V2 = AWS.S3;
|
|
6
|
+
interface S3V2AdapterOptionsWithClient extends BaseS3Options<S3V2> {
|
|
7
|
+
client: S3V2;
|
|
8
|
+
config?: never;
|
|
9
|
+
}
|
|
10
|
+
interface S3V2AdapterOptionsWithConfig extends BaseS3Options<S3V2> {
|
|
11
|
+
config?: AWS.S3.ClientConfiguration;
|
|
12
|
+
client?: never;
|
|
13
|
+
}
|
|
14
|
+
type S3V2AdapterOptions = S3V2AdapterOptionsWithClient | S3V2AdapterOptionsWithConfig;
|
|
15
|
+
declare function s3V2Adapter(options: S3V2AdapterOptions): HealthAdapter;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { S3V2AdapterOptions, S3V2AdapterOptionsWithClient, S3V2AdapterOptionsWithConfig, s3V2Adapter };
|
package/dist/v2.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./shared-B-1hAtzF.mjs";function n(n){let r=null;async function i(){if(`client`in n&&n.client)return n.client;if(!r){let{default:e}=await import(`aws-sdk`);r=new e.S3(n.config??{})}return r}return{async check(){try{let t=await i(),r=Date.now(),a=await new Promise((e,n)=>{t.listBuckets((t,r)=>{t?n(t):e(r)})}),o=Date.now()-r,s=n.metadata?n.metadata(t):void 0,c=s instanceof Promise?await s:s,l=a.Buckets?.length??0;return e(o,{...c,bucketCount:l})}catch(e){return t(e)}}}}export{n as s3V2Adapter};
|
package/dist/v3.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { n as HealthAdapter, t as BaseS3Options } from "./shared-B3WTV2_N.mjs";
|
|
2
|
+
import { S3Client, S3ClientConfig } from "@aws-sdk/client-s3";
|
|
3
|
+
|
|
4
|
+
//#region src/v3.d.ts
|
|
5
|
+
interface S3V3AdapterOptionsWithClient extends BaseS3Options<S3Client> {
|
|
6
|
+
client: S3Client;
|
|
7
|
+
config?: never;
|
|
8
|
+
}
|
|
9
|
+
interface S3V3AdapterOptionsWithConfig extends BaseS3Options<S3Client> {
|
|
10
|
+
config?: S3ClientConfig;
|
|
11
|
+
client?: never;
|
|
12
|
+
}
|
|
13
|
+
type S3V3AdapterOptions = S3V3AdapterOptionsWithClient | S3V3AdapterOptionsWithConfig;
|
|
14
|
+
declare function s3V3Adapter(options: S3V3AdapterOptions): HealthAdapter;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { S3V3AdapterOptions, S3V3AdapterOptionsWithClient, S3V3AdapterOptionsWithConfig, s3V3Adapter };
|
package/dist/v3.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./shared-B-1hAtzF.mjs";function n(n){let r=null;async function i(){if(`client`in n&&n.client)return n.client;if(!r){let{S3Client:e}=await import(`@aws-sdk/client-s3`);r=new e(n.config??{})}return r}return{async check(){try{let t=await i(),r=Date.now(),{ListBucketsCommand:a}=await import(`@aws-sdk/client-s3`),o=await t.send(new a({})),s=Date.now()-r,c=n.metadata?n.metadata(t):void 0,l=c instanceof Promise?await c:c,u=o.Buckets?.length??0;return e(s,{...l,bucketCount:u})}catch(e){return t(e)}}}}export{n as s3V3Adapter};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@healthzkit/s3",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "AGPL-3.0-only",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/alasti-company/healthzkit.dev",
|
|
8
|
+
"directory": "packages/s3"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./dist/index.mjs",
|
|
16
|
+
"./v2": "./dist/v2.mjs",
|
|
17
|
+
"./v3": "./dist/v3.mjs",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vp pack",
|
|
25
|
+
"dev": "vp pack --watch",
|
|
26
|
+
"test": "vp test",
|
|
27
|
+
"check": "vp check",
|
|
28
|
+
"prepublishOnly": "vp run build"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@aws-sdk/client-s3": "^3.1053.0",
|
|
32
|
+
"@types/node": "^25.6.2",
|
|
33
|
+
"@typescript/native-preview": "7.0.0-dev.20260509.2",
|
|
34
|
+
"aws-sdk": "2.1693.0",
|
|
35
|
+
"bumpp": "^11.1.0",
|
|
36
|
+
"healthzkit": "workspace:*",
|
|
37
|
+
"typescript": "^6.0.3",
|
|
38
|
+
"vite-plus": "^0.1.20"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@aws-sdk/client-s3": ">=3.0.0",
|
|
42
|
+
"aws-sdk": ">=2.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@aws-sdk/client-s3": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"aws-sdk": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|