@koralabs/kora-labs-common 6.7.3 → 6.7.4

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/aws/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export { decryptKmsCiphertext, hydrateKmsEnvironment, isKmsDisabled, loadAfterHydratingKmsEnvironment } from './kmsEnvironment';
2
2
  export type { KmsClientLike } from './kmsEnvironment';
3
3
  export { signRs256, verifyRs256, isLocalJwtSigner } from './jwtSigner';
4
+ export { isR2ObjectStore, objectStoreConfig } from './objectStore';
5
+ export type { ObjectStoreConfig } from './objectStore';
package/aws/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isLocalJwtSigner = exports.verifyRs256 = exports.signRs256 = exports.loadAfterHydratingKmsEnvironment = exports.isKmsDisabled = exports.hydrateKmsEnvironment = exports.decryptKmsCiphertext = void 0;
3
+ exports.objectStoreConfig = exports.isR2ObjectStore = exports.isLocalJwtSigner = exports.verifyRs256 = exports.signRs256 = exports.loadAfterHydratingKmsEnvironment = exports.isKmsDisabled = exports.hydrateKmsEnvironment = exports.decryptKmsCiphertext = void 0;
4
4
  var kmsEnvironment_1 = require("./kmsEnvironment");
5
5
  Object.defineProperty(exports, "decryptKmsCiphertext", { enumerable: true, get: function () { return kmsEnvironment_1.decryptKmsCiphertext; } });
6
6
  Object.defineProperty(exports, "hydrateKmsEnvironment", { enumerable: true, get: function () { return kmsEnvironment_1.hydrateKmsEnvironment; } });
@@ -10,3 +10,6 @@ var jwtSigner_1 = require("./jwtSigner");
10
10
  Object.defineProperty(exports, "signRs256", { enumerable: true, get: function () { return jwtSigner_1.signRs256; } });
11
11
  Object.defineProperty(exports, "verifyRs256", { enumerable: true, get: function () { return jwtSigner_1.verifyRs256; } });
12
12
  Object.defineProperty(exports, "isLocalJwtSigner", { enumerable: true, get: function () { return jwtSigner_1.isLocalJwtSigner; } });
13
+ var objectStore_1 = require("./objectStore");
14
+ Object.defineProperty(exports, "isR2ObjectStore", { enumerable: true, get: function () { return objectStore_1.isR2ObjectStore; } });
15
+ Object.defineProperty(exports, "objectStoreConfig", { enumerable: true, get: function () { return objectStore_1.objectStoreConfig; } });
@@ -0,0 +1,24 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ /// <reference types="node" />
6
+ /// <reference types="node" />
7
+ /// <reference types="node" />
8
+ /// <reference types="node" />
9
+ export interface ObjectStoreConfig {
10
+ region: string;
11
+ endpoint?: string;
12
+ credentials?: {
13
+ accessKeyId: string;
14
+ secretAccessKey: string;
15
+ };
16
+ }
17
+ /** True when the object store should be Cloudflare R2 rather than AWS S3. */
18
+ export declare const isR2ObjectStore: (env?: NodeJS.ProcessEnv) => boolean;
19
+ /**
20
+ * S3-client config for the active object store; pass straight into `new S3Client(...)`.
21
+ * Returns R2 config when R2 is selected (R2_ENDPOINT or KORA_OBJECT_STORE=r2), otherwise the
22
+ * unchanged AWS S3 config. Throws if R2 is selected without complete R2 credentials.
23
+ */
24
+ export declare const objectStoreConfig: (env?: NodeJS.ProcessEnv) => ObjectStoreConfig;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ // Object-store config shim: swap AWS S3 <-> Cloudflare R2 behind one env-gated factory.
3
+ // Analogous to the KMS<->SOPS swap (kmsEnvironment) and the local-RS256 JWT shim (jwtSigner):
4
+ // a thin, shared, reversible seam so call sites don't bake in a provider.
5
+ //
6
+ // R2 is S3-API-compatible, so this returns an object assignable to @aws-sdk/client-s3's
7
+ // S3ClientConfig (region/endpoint/credentials) -- call sites keep using
8
+ // `new S3Client(objectStoreConfig())` + GetObjectCommand({ Bucket, Key })
9
+ // completely UNCHANGED. The bucket name and keys stay in the command, not here.
10
+ //
11
+ // REVERSIBILITY: with no R2 env set this returns exactly the previous AWS S3 config
12
+ // ({ region: AWS_REGION ?? 'us-east-1' }), so the AWS/Lambda code path is untouched and
13
+ // "go back to S3" is simply "don't set R2_ENDPOINT" -- no code change.
14
+ //
15
+ // Env contract:
16
+ // R2_ENDPOINT https://<account>.r2.cloudflarestorage.com (presence selects R2)
17
+ // R2_ACCESS_KEY_ID R2 S3 access key id
18
+ // R2_SECRET_ACCESS_KEY R2 S3 secret access key
19
+ // KORA_OBJECT_STORE optional explicit override: 's3' | 'r2'
20
+ // AWS_REGION S3 region (default 'us-east-1') in S3 mode
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.objectStoreConfig = exports.isR2ObjectStore = void 0;
23
+ /** True when the object store should be Cloudflare R2 rather than AWS S3. */
24
+ const isR2ObjectStore = (env = process.env) => {
25
+ if (env.KORA_OBJECT_STORE === 'r2')
26
+ return true;
27
+ if (env.KORA_OBJECT_STORE === 's3')
28
+ return false;
29
+ return !!env.R2_ENDPOINT;
30
+ };
31
+ exports.isR2ObjectStore = isR2ObjectStore;
32
+ /**
33
+ * S3-client config for the active object store; pass straight into `new S3Client(...)`.
34
+ * Returns R2 config when R2 is selected (R2_ENDPOINT or KORA_OBJECT_STORE=r2), otherwise the
35
+ * unchanged AWS S3 config. Throws if R2 is selected without complete R2 credentials.
36
+ */
37
+ const objectStoreConfig = (env = process.env) => {
38
+ var _a;
39
+ if ((0, exports.isR2ObjectStore)(env)) {
40
+ const { R2_ENDPOINT, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY } = env;
41
+ if (!R2_ENDPOINT || !R2_ACCESS_KEY_ID || !R2_SECRET_ACCESS_KEY) {
42
+ throw new Error('R2 object store selected but R2_ENDPOINT, R2_ACCESS_KEY_ID and R2_SECRET_ACCESS_KEY must all be set');
43
+ }
44
+ return {
45
+ region: 'auto',
46
+ endpoint: R2_ENDPOINT,
47
+ credentials: { accessKeyId: R2_ACCESS_KEY_ID, secretAccessKey: R2_SECRET_ACCESS_KEY }
48
+ };
49
+ }
50
+ return { region: (_a = env.AWS_REGION) !== null && _a !== void 0 ? _a : 'us-east-1' };
51
+ };
52
+ exports.objectStoreConfig = objectStoreConfig;
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
1
  {
2
- "name": "@koralabs/kora-labs-common",
3
- "version": "6.7.3",
4
- "description": "Kora Labs Common Utilities",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "homepage": "https://github.com/koralabs/kora-labs-common",
8
- "repository": {
9
- "url": "https://github.com/koralabs/kora-labs-common"
2
+ "name": "@koralabs/kora-labs-common",
3
+ "version": "6.7.4",
4
+ "description": "Kora Labs Common Utilities",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "homepage": "https://github.com/koralabs/kora-labs-common",
8
+ "repository": {
9
+ "url": "https://github.com/koralabs/kora-labs-common"
10
+ },
11
+ "contributors": [
12
+ {
13
+ "name": "BigIrishLion"
10
14
  },
11
- "contributors": [
12
- {
13
- "name": "BigIrishLion"
14
- },
15
- {
16
- "name": "papag00se"
17
- }
18
- ],
19
- "scripts": {
20
- "lint": "ESLINT_USE_FLAT_CONFIG=false eslint --ext=.js,.ts --fix --max-warnings=0 .",
21
- "test": "NETWORK=mainnet node --experimental-vm-modules node_modules/.bin/jest",
22
- "build": "tsc",
23
- "build:local": "npm run build && cp package.json ./lib/package.json && cd lib && npm i --production",
24
- "npm:publish": "npm run build && cp package.json ./lib/package.json && (cd ./lib && npm publish)"
25
- },
26
- "author": "",
27
- "license": "ISC",
28
- "devDependencies": {
29
- "@aws-sdk/client-dynamodb": "^3.549.0",
30
- "@aws-sdk/lib-dynamodb": "^3.549.0",
31
- "@types/jest": "^28.1.1",
32
- "@types/node": "^22.15.17",
33
- "@types/pluralize": "^0.0.29",
34
- "@typescript-eslint/eslint-plugin": "^7.6.0",
35
- "@typescript-eslint/parser": "^7.6.0",
36
- "eslint": "^8.57.0",
37
- "jest": "^28.1.1",
38
- "ts-jest": "^28.0.4",
39
- "typescript": "^4.7.3"
40
- },
41
- "dependencies": {
42
- "@aws-sdk/client-kms": "^3.1003.0",
43
- "@emurgo/cardano-message-signing-nodejs": "^1.0.1",
44
- "bech32": "^2.0.0",
45
- "blakejs": "^1.2.1",
46
- "boolean": "^3.2.0",
47
- "bs58": "^6.0.0",
48
- "cbor": "^9.0.2",
49
- "crc": "^4.3.2",
50
- "libsodium-wrappers-sumo": "^0.8.3",
51
- "pluralize-esm": "^9.0.5"
15
+ {
16
+ "name": "papag00se"
52
17
  }
18
+ ],
19
+ "scripts": {
20
+ "lint": "ESLINT_USE_FLAT_CONFIG=false eslint --ext=.js,.ts --fix --max-warnings=0 .",
21
+ "test": "NETWORK=mainnet node --experimental-vm-modules node_modules/.bin/jest",
22
+ "build": "tsc",
23
+ "build:local": "npm run build && cp package.json ./lib/package.json && cd lib && npm i --production",
24
+ "npm:publish": "npm run build && cp package.json ./lib/package.json && (cd ./lib && npm publish)"
25
+ },
26
+ "author": "",
27
+ "license": "ISC",
28
+ "devDependencies": {
29
+ "@aws-sdk/client-dynamodb": "^3.549.0",
30
+ "@aws-sdk/lib-dynamodb": "^3.549.0",
31
+ "@types/jest": "^28.1.1",
32
+ "@types/node": "^22.15.17",
33
+ "@types/pluralize": "^0.0.29",
34
+ "@typescript-eslint/eslint-plugin": "^7.6.0",
35
+ "@typescript-eslint/parser": "^7.6.0",
36
+ "eslint": "^8.57.0",
37
+ "jest": "^28.1.1",
38
+ "ts-jest": "^28.0.4",
39
+ "typescript": "^4.7.3"
40
+ },
41
+ "dependencies": {
42
+ "@aws-sdk/client-kms": "^3.1003.0",
43
+ "@emurgo/cardano-message-signing-nodejs": "^1.0.1",
44
+ "bech32": "^2.0.0",
45
+ "blakejs": "^1.2.1",
46
+ "boolean": "^3.2.0",
47
+ "bs58": "^6.0.0",
48
+ "cbor": "^9.0.2",
49
+ "crc": "^4.3.2",
50
+ "libsodium-wrappers-sumo": "^0.8.3",
51
+ "pluralize-esm": "^9.0.5"
52
+ }
53
53
  }