@foldrun/core 19.1.0 → 19.3.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/dist/src/data-import.d.ts +156 -0
- package/dist/src/data-import.js +670 -0
- package/dist/src/storage.d.ts +12 -1
- package/dist/src/storage.js +50 -16
- package/package.json +1 -1
- package/src/data-import.ts +764 -0
- package/src/storage.ts +45 -15
package/dist/src/storage.d.ts
CHANGED
|
@@ -155,7 +155,18 @@ export interface S3Config {
|
|
|
155
155
|
/** `https://s3.ap-southeast-2.amazonaws.com` → `ap-southeast-2`. Null for
|
|
156
156
|
* anything else (R2, MinIO), whose region is whatever the env says. */
|
|
157
157
|
export declare function regionOfEndpoint(endpoint: string): string | null;
|
|
158
|
-
export declare function s3Config(): S3Config | null;
|
|
158
|
+
export declare function s3Config(env?: NodeJS.ProcessEnv): S3Config | null;
|
|
159
|
+
/**
|
|
160
|
+
* The origin the browser reaches the object store at — where a presigned PUT
|
|
161
|
+
* (an upload) and a presigned GET (a video, audio or PDF preview) go — so the
|
|
162
|
+
* dashboard's Content-Security-Policy can name it and nothing wider. Null
|
|
163
|
+
* unless S3 is the driver in force (the same test driverFor makes), or when
|
|
164
|
+
* the address is not a plain http(s) host. It is built by the same function
|
|
165
|
+
* as the signed URLs (bucketHost), so the two cannot drift: path-style gives
|
|
166
|
+
* the endpoint's origin, virtual-hosted gives `https://<bucket>.<host>`.
|
|
167
|
+
* Reads only the environment; it fetches no credentials.
|
|
168
|
+
*/
|
|
169
|
+
export declare function storeOrigin(env?: NodeJS.ProcessEnv): string | null;
|
|
159
170
|
/** For tests: forget cached role credentials. */
|
|
160
171
|
export declare function forgetS3Credentials(): void;
|
|
161
172
|
/** A body that is not held in memory: read as it is sent. `length` and
|
package/dist/src/storage.js
CHANGED
|
@@ -434,31 +434,59 @@ export function regionOfEndpoint(endpoint) {
|
|
|
434
434
|
/** True when this process runs under an AWS role handed out through the
|
|
435
435
|
* container credential endpoint — EKS Pod Identity, ECS, or an IRSA-style
|
|
436
436
|
* shim. The endpoint is the pod's, and the token file is mounted beside it. */
|
|
437
|
-
function containerCredentialsAvailable() {
|
|
438
|
-
return Boolean(
|
|
439
|
-
}
|
|
440
|
-
export function s3Config() {
|
|
441
|
-
const endpoint =
|
|
442
|
-
const bucket =
|
|
443
|
-
const accessKeyId =
|
|
444
|
-
const secretAccessKey =
|
|
437
|
+
function containerCredentialsAvailable(env = process.env) {
|
|
438
|
+
return Boolean(env.AWS_CONTAINER_CREDENTIALS_FULL_URI || env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI);
|
|
439
|
+
}
|
|
440
|
+
export function s3Config(env = process.env) {
|
|
441
|
+
const endpoint = env.FOLDRUN_S3_ENDPOINT;
|
|
442
|
+
const bucket = env.FOLDRUN_S3_BUCKET;
|
|
443
|
+
const accessKeyId = env.FOLDRUN_S3_ACCESS_KEY_ID;
|
|
444
|
+
const secretAccessKey = env.FOLDRUN_S3_SECRET_ACCESS_KEY;
|
|
445
445
|
if (!endpoint || !bucket)
|
|
446
446
|
return null;
|
|
447
447
|
const staticKeys = Boolean(accessKeyId && secretAccessKey);
|
|
448
448
|
// No key and no role is a half-set environment: fall back to fs rather
|
|
449
449
|
// than fail at the first upload (driverFor says why).
|
|
450
|
-
if (!staticKeys && !containerCredentialsAvailable())
|
|
450
|
+
if (!staticKeys && !containerCredentialsAvailable(env))
|
|
451
451
|
return null;
|
|
452
452
|
return {
|
|
453
453
|
endpoint: endpoint.replace(/\/+$/, ""),
|
|
454
454
|
bucket,
|
|
455
455
|
// R2 has one region and calls it `auto`. An AWS endpoint names its own;
|
|
456
456
|
// anything else says so in the env.
|
|
457
|
-
region:
|
|
457
|
+
region: env.FOLDRUN_S3_REGION ?? regionOfEndpoint(endpoint) ?? "auto",
|
|
458
458
|
...(staticKeys ? { accessKeyId, secretAccessKey } : {}),
|
|
459
|
-
pathStyle:
|
|
459
|
+
pathStyle: env.FOLDRUN_S3_PATH_STYLE !== "false",
|
|
460
460
|
};
|
|
461
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* The origin the browser reaches the object store at — where a presigned PUT
|
|
464
|
+
* (an upload) and a presigned GET (a video, audio or PDF preview) go — so the
|
|
465
|
+
* dashboard's Content-Security-Policy can name it and nothing wider. Null
|
|
466
|
+
* unless S3 is the driver in force (the same test driverFor makes), or when
|
|
467
|
+
* the address is not a plain http(s) host. It is built by the same function
|
|
468
|
+
* as the signed URLs (bucketHost), so the two cannot drift: path-style gives
|
|
469
|
+
* the endpoint's origin, virtual-hosted gives `https://<bucket>.<host>`.
|
|
470
|
+
* Reads only the environment; it fetches no credentials.
|
|
471
|
+
*/
|
|
472
|
+
export function storeOrigin(env = process.env) {
|
|
473
|
+
if (env.FOLDRUN_STORAGE_DRIVER !== "s3")
|
|
474
|
+
return null;
|
|
475
|
+
try {
|
|
476
|
+
const cfg = s3Config(env);
|
|
477
|
+
if (!cfg)
|
|
478
|
+
return null;
|
|
479
|
+
const u = new URL(bucketHost(cfg).origin);
|
|
480
|
+
if (u.protocol !== "https:" && u.protocol !== "http:")
|
|
481
|
+
return null;
|
|
482
|
+
if (!u.hostname || u.hostname.includes("*") || u.origin === "null")
|
|
483
|
+
return null;
|
|
484
|
+
return u.origin;
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
return null; // an endpoint that is not a URL: no source, never a broken one
|
|
488
|
+
}
|
|
489
|
+
}
|
|
462
490
|
// ---------- credentials ----------
|
|
463
491
|
//
|
|
464
492
|
// Static keys are used as given. Without them, the process is running under
|
|
@@ -523,13 +551,19 @@ function signingKey(cfg, creds, dateStamp) {
|
|
|
523
551
|
}
|
|
524
552
|
/** Where a key lives, split into the host and the canonical path SigV4 signs. */
|
|
525
553
|
function target(cfg, key) {
|
|
526
|
-
const url = new URL(cfg.endpoint);
|
|
527
554
|
const encoded = uriEncode(key, true);
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
555
|
+
const { host, origin } = bucketHost(cfg);
|
|
556
|
+
return { host, origin, canonicalUri: cfg.pathStyle ? `/${cfg.bucket}/${encoded}` : `/${encoded}` };
|
|
557
|
+
}
|
|
558
|
+
/** The host a request for this bucket goes to: the endpoint's own
|
|
559
|
+
* (path-style), or `<bucket>.<endpoint host>` (virtual-hosted). Shared by
|
|
560
|
+
* target() and storeOrigin(). */
|
|
561
|
+
function bucketHost(cfg) {
|
|
562
|
+
const url = new URL(cfg.endpoint);
|
|
563
|
+
if (cfg.pathStyle)
|
|
564
|
+
return { host: url.host, origin: url.origin };
|
|
531
565
|
const host = `${cfg.bucket}.${url.host}`;
|
|
532
|
-
return { host, origin: `${url.protocol}//${host}
|
|
566
|
+
return { host, origin: `${url.protocol}//${host}` };
|
|
533
567
|
}
|
|
534
568
|
/**
|
|
535
569
|
* A presigned URL — SigV4 in the query string, so the browser (or a run pod)
|