@hot-updater/aws 1.2.0-rc.3 → 1.2.0-rc.31
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/index.cjs +144 -188
- package/dist/index.d.cts +30 -12
- package/dist/index.d.mts +30 -12
- package/dist/index.mjs +145 -189
- package/dist/init/index.cjs +66 -22
- package/dist/init/index.d.cts +3 -2
- package/dist/init/index.d.mts +3 -2
- package/dist/init/index.mjs +67 -23
- package/dist/lambda/index.cjs +938 -225
- package/package.json +8 -7
package/dist/lambda/index.cjs
CHANGED
|
@@ -30,6 +30,7 @@ let _aws_sdk_client_cloudfront = require("@aws-sdk/client-cloudfront");
|
|
|
30
30
|
let _aws_sdk_lib_dynamodb = require("@aws-sdk/lib-dynamodb");
|
|
31
31
|
let _aws_sdk_client_s3 = require("@aws-sdk/client-s3");
|
|
32
32
|
let _aws_sdk_lib_storage = require("@aws-sdk/lib-storage");
|
|
33
|
+
let _aws_sdk_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
|
|
33
34
|
const SHA256_FILE_HASH_RE = /^[0-9a-f]{64}$/;
|
|
34
35
|
const isContentAddressedAssetFileHash = (value) => {
|
|
35
36
|
return typeof value === "string" && SHA256_FILE_HASH_RE.test(value);
|
|
@@ -1437,6 +1438,10 @@ const semverSatisfies = (targetAppVersion, currentVersion) => {
|
|
|
1437
1438
|
return satisfies(currentCoerce, targetAppVersion);
|
|
1438
1439
|
};
|
|
1439
1440
|
//#endregion
|
|
1441
|
+
//#region ../plugin-core/dist/types/index.mjs
|
|
1442
|
+
/** The value of a `Lazy`, calling its function. */
|
|
1443
|
+
const resolveLazy = async (value) => typeof value === "function" ? await value() : value;
|
|
1444
|
+
//#endregion
|
|
1440
1445
|
//#region ../plugin-core/dist/serverPlugin/definePlugin.mjs
|
|
1441
1446
|
/** Declares a plugin; Hot Updater's own plugins and third-party ones use the same contract. */
|
|
1442
1447
|
const definePlugin = (plugin) => plugin;
|
|
@@ -2126,7 +2131,10 @@ const CHANNEL_ID = {
|
|
|
2126
2131
|
* every database's migrator creates missing tables and then records the
|
|
2127
2132
|
* version, and none of them changes an existing table, so changing one
|
|
2128
2133
|
* needs a migration step of its own first. The schema fence answers 503 on
|
|
2129
|
-
* a database whose row differs, until it runs.
|
|
2134
|
+
* a database whose row differs, until it runs. Before a version is released,
|
|
2135
|
+
* its tables change in place in its own migration, and a database one of its
|
|
2136
|
+
* prereleases migrated takes the same change by hand: the fence compares this
|
|
2137
|
+
* row, not columns, so nothing reports it.
|
|
2130
2138
|
*/
|
|
2131
2139
|
const HOT_UPDATER_SCHEMA_VERSION = "1.2.0";
|
|
2132
2140
|
const bundles = defineTable({
|
|
@@ -2390,6 +2398,27 @@ const channels = defineTable({
|
|
|
2390
2398
|
* or `versionCode`. `submitted_to`, `submitted_at_ms` and
|
|
2391
2399
|
* `submitted_version` record the store track a build went to, when, and
|
|
2392
2400
|
* the store's label of the build; they stay null for a build no store took.
|
|
2401
|
+
* `is_store_build` is true on the build a person or a job says the store
|
|
2402
|
+
* sells, and false on every other: deploys patch from it over the scope's
|
|
2403
|
+
* newest build. The engine copies the scope key into `store_build_scope_key`
|
|
2404
|
+
* for that build alone, so `byStoreBuild` holds one entry per scope at most,
|
|
2405
|
+
* on every store, while any number of a scope's builds hold none.
|
|
2406
|
+
* `is_sandbox` is true on a sandbox build, set when it registers and never
|
|
2407
|
+
* changed, and `sandbox_url_scheme` is the URL scheme its artifact registers,
|
|
2408
|
+
* which its preview links open; null on any other build, and on a sandbox
|
|
2409
|
+
* build registered before the column, which registered the derived one.
|
|
2410
|
+
* `export_method` is how an `.ipa` was exported, read from its profile when
|
|
2411
|
+
* it registers and never changed; null on any other artifact, on an `.ipa`
|
|
2412
|
+
* whose profile couldn't be read, and on one registered before the column.
|
|
2413
|
+
* `native_app_version` is the app version the artifact itself reports, its
|
|
2414
|
+
* `CFBundleShortVersionString` or `versionName`, read from the artifact when
|
|
2415
|
+
* it registers and never changed, whatever the update strategy; `app_version`
|
|
2416
|
+
* stays the version OTAs target, null on a fingerprint build. It is null
|
|
2417
|
+
* when the artifact's can't be read, and on a build registered before the
|
|
2418
|
+
* column.
|
|
2419
|
+
* Boolean columns follow one rule: `is_*` for a fact about the row or
|
|
2420
|
+
* `should_*` for an instruction to the client, never null; a unique index over
|
|
2421
|
+
* the rows where one is true keys a derived slot, not the boolean.
|
|
2393
2422
|
*/
|
|
2394
2423
|
const nativeBuilds = defineTable({
|
|
2395
2424
|
id: {
|
|
@@ -2466,9 +2495,34 @@ const nativeBuilds = defineTable({
|
|
|
2466
2495
|
type: "string",
|
|
2467
2496
|
maxLength: 255,
|
|
2468
2497
|
required: false
|
|
2498
|
+
},
|
|
2499
|
+
is_store_build: { type: "boolean" },
|
|
2500
|
+
is_sandbox: { type: "boolean" },
|
|
2501
|
+
sandbox_url_scheme: {
|
|
2502
|
+
type: "string",
|
|
2503
|
+
maxLength: 255,
|
|
2504
|
+
ascii: true,
|
|
2505
|
+
required: false
|
|
2506
|
+
},
|
|
2507
|
+
export_method: {
|
|
2508
|
+
type: "string",
|
|
2509
|
+
maxLength: 16,
|
|
2510
|
+
required: false
|
|
2511
|
+
},
|
|
2512
|
+
native_app_version: {
|
|
2513
|
+
type: "string",
|
|
2514
|
+
required: false
|
|
2469
2515
|
}
|
|
2470
2516
|
}, {
|
|
2471
2517
|
key: ["id"],
|
|
2518
|
+
derived: {
|
|
2519
|
+
/** The scope this build is the store build of; null on every other. */
|
|
2520
|
+
store_build_scope_key: {
|
|
2521
|
+
type: "string",
|
|
2522
|
+
maxLength: 2048,
|
|
2523
|
+
ascii: true,
|
|
2524
|
+
compute: (row) => row.is_store_build ? row.scope_key : null
|
|
2525
|
+
} },
|
|
2472
2526
|
indexes: {
|
|
2473
2527
|
byScope: {
|
|
2474
2528
|
eq: ["scope_key"],
|
|
@@ -2478,6 +2532,11 @@ const nativeBuilds = defineTable({
|
|
|
2478
2532
|
eq: ["scope_key", "build_key"],
|
|
2479
2533
|
sort: ["id"]
|
|
2480
2534
|
},
|
|
2535
|
+
byStoreBuild: {
|
|
2536
|
+
eq: ["store_build_scope_key"],
|
|
2537
|
+
sort: [],
|
|
2538
|
+
unique: true
|
|
2539
|
+
},
|
|
2481
2540
|
byChannel: {
|
|
2482
2541
|
eq: ["channel_id"],
|
|
2483
2542
|
sort: ["id"],
|
|
@@ -2489,6 +2548,115 @@ const nativeBuilds = defineTable({
|
|
|
2489
2548
|
}
|
|
2490
2549
|
}
|
|
2491
2550
|
});
|
|
2551
|
+
/**
|
|
2552
|
+
* The iPhones a team asks to install ad hoc builds on. A row decides what the
|
|
2553
|
+
* CLI registers with Apple, not what an export includes: Xcode's automatic ad
|
|
2554
|
+
* hoc profile lists every device the Apple account has enabled. `status` is
|
|
2555
|
+
* `pending` until someone approves it, `approved` until a build or
|
|
2556
|
+
* `native-build devices add` registers it with Apple, then `registered`;
|
|
2557
|
+
* declining or removing one deletes its row. `udid` is the UDID in lower case.
|
|
2558
|
+
* `apple_issuer_id` is the App Store Connect issuer whose key registered it,
|
|
2559
|
+
* set once: a build signed by another account never registers these rows.
|
|
2560
|
+
* `apple_error` is Apple's refusal of the device, or why it stopped counting
|
|
2561
|
+
* it, cleared by the next success. `build_id` is the newest native build whose
|
|
2562
|
+
* .ipa the CLI checked lists it; deleting that build never touches the row.
|
|
2563
|
+
* It holds personal data: a UDID, a name, and the emails of who asked and who
|
|
2564
|
+
* approved, null for the CLI.
|
|
2565
|
+
*/
|
|
2566
|
+
const iosDevices = defineTable({
|
|
2567
|
+
id: {
|
|
2568
|
+
type: "string",
|
|
2569
|
+
maxLength: 36
|
|
2570
|
+
},
|
|
2571
|
+
udid: {
|
|
2572
|
+
type: "string",
|
|
2573
|
+
maxLength: 40,
|
|
2574
|
+
ascii: true,
|
|
2575
|
+
unique: true
|
|
2576
|
+
},
|
|
2577
|
+
name: {
|
|
2578
|
+
type: "string",
|
|
2579
|
+
maxLength: 100
|
|
2580
|
+
},
|
|
2581
|
+
status: {
|
|
2582
|
+
type: "string",
|
|
2583
|
+
maxLength: 16
|
|
2584
|
+
},
|
|
2585
|
+
requested_by: {
|
|
2586
|
+
type: "string",
|
|
2587
|
+
maxLength: 320,
|
|
2588
|
+
required: false
|
|
2589
|
+
},
|
|
2590
|
+
created_at_ms: { type: "integer" },
|
|
2591
|
+
approved_by: {
|
|
2592
|
+
type: "string",
|
|
2593
|
+
maxLength: 320,
|
|
2594
|
+
required: false
|
|
2595
|
+
},
|
|
2596
|
+
approved_at_ms: {
|
|
2597
|
+
type: "integer",
|
|
2598
|
+
required: false
|
|
2599
|
+
},
|
|
2600
|
+
registered_at_ms: {
|
|
2601
|
+
type: "integer",
|
|
2602
|
+
required: false
|
|
2603
|
+
},
|
|
2604
|
+
apple_issuer_id: {
|
|
2605
|
+
type: "string",
|
|
2606
|
+
maxLength: 64,
|
|
2607
|
+
ascii: true,
|
|
2608
|
+
required: false
|
|
2609
|
+
},
|
|
2610
|
+
apple_error: {
|
|
2611
|
+
type: "string",
|
|
2612
|
+
maxLength: 512,
|
|
2613
|
+
required: false
|
|
2614
|
+
},
|
|
2615
|
+
build_id: {
|
|
2616
|
+
type: "string",
|
|
2617
|
+
maxLength: 36,
|
|
2618
|
+
required: false
|
|
2619
|
+
}
|
|
2620
|
+
}, {
|
|
2621
|
+
key: ["id"],
|
|
2622
|
+
indexes: {
|
|
2623
|
+
byStatus: {
|
|
2624
|
+
eq: ["status"],
|
|
2625
|
+
sort: ["id"]
|
|
2626
|
+
},
|
|
2627
|
+
all: {
|
|
2628
|
+
eq: [],
|
|
2629
|
+
sort: ["id"]
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
});
|
|
2633
|
+
/**
|
|
2634
|
+
* The Apple account the iOS device registry belongs to: one row, keyed
|
|
2635
|
+
* `registry`, holding the App Store Connect issuer that first registered a
|
|
2636
|
+
* device. A build claims it before it sends Apple anything, and its key makes
|
|
2637
|
+
* the claim atomic on every store, so two builds of two accounts can't both
|
|
2638
|
+
* spend a slot; another account's build then registers nothing. Removing
|
|
2639
|
+
* devices never releases it.
|
|
2640
|
+
*/
|
|
2641
|
+
const iosDeviceAccount = defineTable({
|
|
2642
|
+
id: {
|
|
2643
|
+
type: "string",
|
|
2644
|
+
maxLength: 16,
|
|
2645
|
+
ascii: true
|
|
2646
|
+
},
|
|
2647
|
+
apple_issuer_id: {
|
|
2648
|
+
type: "string",
|
|
2649
|
+
maxLength: 64,
|
|
2650
|
+
ascii: true
|
|
2651
|
+
},
|
|
2652
|
+
claimed_at_ms: { type: "integer" }
|
|
2653
|
+
}, {
|
|
2654
|
+
key: ["id"],
|
|
2655
|
+
indexes: { all: {
|
|
2656
|
+
eq: [],
|
|
2657
|
+
sort: ["id"]
|
|
2658
|
+
} }
|
|
2659
|
+
});
|
|
2492
2660
|
/** Core's module: always installed, never a plugin. */
|
|
2493
2661
|
const coreModule = {
|
|
2494
2662
|
id: "core",
|
|
@@ -2509,7 +2677,9 @@ const coreModule = {
|
|
|
2509
2677
|
sort: []
|
|
2510
2678
|
} }
|
|
2511
2679
|
}),
|
|
2512
|
-
native_builds: nativeBuilds
|
|
2680
|
+
native_builds: nativeBuilds,
|
|
2681
|
+
ios_devices: iosDevices,
|
|
2682
|
+
ios_device_account: iosDeviceAccount
|
|
2513
2683
|
}
|
|
2514
2684
|
};
|
|
2515
2685
|
//#endregion
|
|
@@ -2698,15 +2868,8 @@ const LEASE_TABLE = "aggregate_lease";
|
|
|
2698
2868
|
const LEASE = { id: "compaction" };
|
|
2699
2869
|
/** How long a compaction holds the lease before another process may take it. */
|
|
2700
2870
|
const LEASE_MS = 3e4;
|
|
2701
|
-
/**
|
|
2702
|
-
|
|
2703
|
-
* first; memory mode flushes every 15, since its window is what a crash
|
|
2704
|
-
* loses.
|
|
2705
|
-
*/
|
|
2706
|
-
const WINDOW_MS$1 = {
|
|
2707
|
-
log: 6e4,
|
|
2708
|
-
memory: 15e3
|
|
2709
|
-
};
|
|
2871
|
+
/** A commit compacts once this has passed since the last compaction. */
|
|
2872
|
+
const WINDOW_MS$1 = 6e4;
|
|
2710
2873
|
/** Log rows a compaction reads from each log table for one group. */
|
|
2711
2874
|
const LOG_PAGE = 200;
|
|
2712
2875
|
/**
|
|
@@ -2720,8 +2883,6 @@ const GROUPS = {
|
|
|
2720
2883
|
};
|
|
2721
2884
|
/** Tries per write after a conflict or a transient error. */
|
|
2722
2885
|
const ATTEMPTS = 5;
|
|
2723
|
-
/** Aggregate rows a memory buffer holds before a commit waits for a flush. */
|
|
2724
|
-
const MAX_BUFFERED = 1e4;
|
|
2725
2886
|
const log = defineTable({
|
|
2726
2887
|
id: {
|
|
2727
2888
|
type: "string",
|
|
@@ -2771,7 +2932,7 @@ const valuesOf = ({ deltas, sketches }) => ({
|
|
|
2771
2932
|
/**
|
|
2772
2933
|
* Merges `values` into the change for `key`'s identity as `tx.aggregate`
|
|
2773
2934
|
* does: deltas add up and sketches merge. One constant `shardBy` keys each
|
|
2774
|
-
* identity to one entry;
|
|
2935
|
+
* identity to one entry; `compile` writes it to shard 0.
|
|
2775
2936
|
*/
|
|
2776
2937
|
const merge = (into, model, key, values) => recordAggregate(into, model, Object.fromEntries(shapeOf(model).key.map((field, at) => [field, key[at]])), values, "");
|
|
2777
2938
|
const mergeAll = (into, changes) => {
|
|
@@ -2805,7 +2966,7 @@ const increment = ({ model, deltas }, key) => Object.values(deltas).some((delta)
|
|
|
2805
2966
|
/**
|
|
2806
2967
|
* The guarded write that merges `change` into `current`: insert, patch, or
|
|
2807
2968
|
* delete at zero. Unlike a transaction's, a gauge may go below zero here: a
|
|
2808
|
-
*
|
|
2969
|
+
* group can hold a loss without the gain before it, and reads sum every shard.
|
|
2809
2970
|
*/
|
|
2810
2971
|
const rewrite = (change, key, current) => {
|
|
2811
2972
|
const { model } = change;
|
|
@@ -2843,12 +3004,12 @@ const rewrite = (change, key, current) => {
|
|
|
2843
3004
|
};
|
|
2844
3005
|
};
|
|
2845
3006
|
/**
|
|
2846
|
-
* The write for each change on
|
|
2847
|
-
* the row for counters, and a guarded rewrite
|
|
2848
|
-
* rows are read in one batch per table.
|
|
3007
|
+
* The write for each change on shard 0, since one compaction runs at a time:
|
|
3008
|
+
* a blind increment that creates the row for counters, and a guarded rewrite
|
|
3009
|
+
* for gauges and sketches, whose rows are read in one batch per table.
|
|
2849
3010
|
*/
|
|
2850
|
-
const compile = async (adapter, changes
|
|
2851
|
-
const keys = changes.map(({
|
|
3011
|
+
const compile = async (adapter, changes) => {
|
|
3012
|
+
const keys = changes.map(({ key }) => [...key.slice(0, -1), 0]);
|
|
2852
3013
|
const reads = /* @__PURE__ */ new Map();
|
|
2853
3014
|
changes.forEach((change, at) => {
|
|
2854
3015
|
if (rewrites(change)) reads.set(change.model, [...reads.get(change.model) ?? [], at]);
|
|
@@ -2902,14 +3063,13 @@ const encode = async (changes) => {
|
|
|
2902
3063
|
return zipped !== void 0 && zipped.length < json.length ? `z${zipped}` : json;
|
|
2903
3064
|
};
|
|
2904
3065
|
/**
|
|
2905
|
-
* Batches changes to aggregates declared `batched`. A transaction
|
|
2906
|
-
* them
|
|
2907
|
-
*
|
|
2908
|
-
*
|
|
2909
|
-
*
|
|
2910
|
-
* applies exactly once. One lease row keeps compactions one at a time.
|
|
3066
|
+
* Batches changes to aggregates declared `batched`. A transaction writes
|
|
3067
|
+
* them as one log row in its own atomic write, in place of their rows; a
|
|
3068
|
+
* compaction later merges log rows into the aggregates and deletes them,
|
|
3069
|
+
* atomically again, so each applies exactly once. One lease row keeps
|
|
3070
|
+
* compactions one at a time.
|
|
2911
3071
|
*/
|
|
2912
|
-
const createAggregateBatches = ({ engine, adapter, schema, batching: {
|
|
3072
|
+
const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs = WINDOW_MS$1 }, now }) => {
|
|
2913
3073
|
if (!schema.models.has(LEASE_TABLE)) throw new DatabaseTransactionError("An engine that batches aggregates needs aggregateBatchingModule in its schema.");
|
|
2914
3074
|
const holder = crypto.randomUUID().replaceAll("-", "");
|
|
2915
3075
|
const table = (name) => schema.models.get(name).table;
|
|
@@ -2937,68 +3097,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2937
3097
|
}
|
|
2938
3098
|
return changes;
|
|
2939
3099
|
};
|
|
2940
|
-
/**
|
|
2941
|
-
* Writes changes in atomic chunks within `fits`, and returns the ones it
|
|
2942
|
-
* could not apply. A write whose outcome is unknown is dropped, never
|
|
2943
|
-
* resent, so no change applies twice.
|
|
2944
|
-
*/
|
|
2945
|
-
const apply = async (changes, shard) => {
|
|
2946
|
-
let rest = changes;
|
|
2947
|
-
let ops = [];
|
|
2948
|
-
let read = true;
|
|
2949
|
-
for (let failures = 0; rest.length > 0 && failures < ATTEMPTS;) try {
|
|
2950
|
-
if (read) ops = await compile(adapter, rest, shard);
|
|
2951
|
-
let size = rest.length;
|
|
2952
|
-
const chunk = () => ops.slice(0, size).filter(isOp);
|
|
2953
|
-
while (size > 1 && !adapter.fits(chunk())) size = Math.ceil(size / 2);
|
|
2954
|
-
let result = { ok: true };
|
|
2955
|
-
if (chunk().length > 0) result = await adapter.write(chunk()).catch((error) => {
|
|
2956
|
-
warn("flush")(error);
|
|
2957
|
-
return { ok: true };
|
|
2958
|
-
});
|
|
2959
|
-
read = !result.ok && !("retry" in result);
|
|
2960
|
-
if (result.ok) {
|
|
2961
|
-
rest = rest.slice(size);
|
|
2962
|
-
ops = ops.slice(size);
|
|
2963
|
-
failures = 0;
|
|
2964
|
-
} else {
|
|
2965
|
-
failures += 1;
|
|
2966
|
-
if (!read) await sleep$2(failures);
|
|
2967
|
-
}
|
|
2968
|
-
} catch (error) {
|
|
2969
|
-
warn("flush")(error);
|
|
2970
|
-
return rest;
|
|
2971
|
-
}
|
|
2972
|
-
return rest;
|
|
2973
|
-
};
|
|
2974
|
-
let buffer = /* @__PURE__ */ new Map();
|
|
2975
|
-
let timer;
|
|
2976
|
-
let flushing;
|
|
2977
|
-
const shards = /* @__PURE__ */ new Map();
|
|
2978
|
-
/** Each process writes its own shard, so flushes of two processes rarely meet. */
|
|
2979
|
-
const processShard = (model) => {
|
|
2980
|
-
if (!shards.has(model)) shards.set(model, Math.floor(Math.random() * shapeOf(model).shards));
|
|
2981
|
-
return shards.get(model);
|
|
2982
|
-
};
|
|
2983
|
-
const schedule = () => {
|
|
2984
|
-
if (timer !== void 0 || buffer.size === 0) return;
|
|
2985
|
-
timer = setTimeout(() => {
|
|
2986
|
-
timer = void 0;
|
|
2987
|
-
flushBuffer();
|
|
2988
|
-
}, windowMs);
|
|
2989
|
-
timer.unref?.();
|
|
2990
|
-
};
|
|
2991
|
-
/** Never rejects: what it cannot apply goes back into the buffer. */
|
|
2992
|
-
const flushBuffer = () => flushing ??= (async () => {
|
|
2993
|
-
clearTimeout(timer);
|
|
2994
|
-
timer = void 0;
|
|
2995
|
-
const pending = [...buffer.values()];
|
|
2996
|
-
buffer = /* @__PURE__ */ new Map();
|
|
2997
|
-
mergeAll(buffer, await apply(pending, processShard));
|
|
2998
|
-
})().catch(warn("flush")).finally(() => {
|
|
2999
|
-
flushing = void 0;
|
|
3000
|
-
schedule();
|
|
3001
|
-
});
|
|
3002
3100
|
let nextDue = 0;
|
|
3003
3101
|
let compacting;
|
|
3004
3102
|
/** Log rows this process read, by `[log table's index, id]`, for the deletes after a group. */
|
|
@@ -3133,7 +3231,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3133
3231
|
more
|
|
3134
3232
|
};
|
|
3135
3233
|
};
|
|
3136
|
-
const rowsFor = async (changes) => (await compile(adapter, changes
|
|
3234
|
+
const rowsFor = async (changes) => (await compile(adapter, changes)).filter(isOp);
|
|
3137
3235
|
/**
|
|
3138
3236
|
* Applies the oldest pending log rows whose merged changes fit in one
|
|
3139
3237
|
* atomic write with the lease, which lists them as applied; the rows are
|
|
@@ -3227,20 +3325,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3227
3325
|
}))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
|
|
3228
3326
|
checking = void 0;
|
|
3229
3327
|
});
|
|
3230
|
-
/** Takes a committed transaction's changes; never rejects, since the transaction already committed. */
|
|
3231
|
-
const committed = async (changes) => {
|
|
3232
|
-
if (mode === "log") {
|
|
3233
|
-
if (now() >= nextDue) await compact(false, GROUPS.commit);
|
|
3234
|
-
return;
|
|
3235
|
-
}
|
|
3236
|
-
mergeAll(buffer, changes.values());
|
|
3237
|
-
schedule();
|
|
3238
|
-
if (buffer.size >= MAX_BUFFERED) await flushBuffer();
|
|
3239
|
-
};
|
|
3240
|
-
const flush = async () => {
|
|
3241
|
-
await flushBuffer();
|
|
3242
|
-
if (mode === "log" && await hasPending()) await compact(true, GROUPS.flush);
|
|
3243
|
-
};
|
|
3244
3328
|
return {
|
|
3245
3329
|
async transaction(fn) {
|
|
3246
3330
|
let changes = /* @__PURE__ */ new Map();
|
|
@@ -3266,7 +3350,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3266
3350
|
aggregate
|
|
3267
3351
|
});
|
|
3268
3352
|
if (failure) throw failure.error;
|
|
3269
|
-
if (
|
|
3353
|
+
if (attempt.size > 0) {
|
|
3270
3354
|
const id = `${now().toString(36).padStart(9, "0")}${holder.slice(0, 8)}${crypto.randomUUID().slice(0, 8)}`;
|
|
3271
3355
|
const shard = Math.floor(Math.random() * LOG_TABLES.length);
|
|
3272
3356
|
const merged = mergeAll(/* @__PURE__ */ new Map(), attempt.values());
|
|
@@ -3280,24 +3364,18 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3280
3364
|
open = false;
|
|
3281
3365
|
}
|
|
3282
3366
|
});
|
|
3283
|
-
if (changes.size > 0) await
|
|
3367
|
+
if (changes.size > 0 && now() >= nextDue) await compact(false, GROUPS.commit);
|
|
3284
3368
|
return result;
|
|
3285
3369
|
},
|
|
3286
3370
|
async beforeRead(name) {
|
|
3287
3371
|
if (!isBatched(schema.models.get(name))) return;
|
|
3288
|
-
if (
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
return false;
|
|
3293
|
-
})) await compact(true, GROUPS.read);
|
|
3294
|
-
}
|
|
3372
|
+
if (await hasPending().catch((error) => {
|
|
3373
|
+
warn("read")(error);
|
|
3374
|
+
return false;
|
|
3375
|
+
})) await compact(true, GROUPS.read);
|
|
3295
3376
|
},
|
|
3296
|
-
flush
|
|
3297
|
-
|
|
3298
|
-
clearTimeout(timer);
|
|
3299
|
-
timer = void 0;
|
|
3300
|
-
await flush();
|
|
3377
|
+
async flush() {
|
|
3378
|
+
if (await hasPending()) await compact(true, GROUPS.flush);
|
|
3301
3379
|
}
|
|
3302
3380
|
};
|
|
3303
3381
|
};
|
|
@@ -3439,7 +3517,8 @@ const fieldProblems = (definition, add) => {
|
|
|
3439
3517
|
else if (field.required === false) add(`key field "${name}" is nullable`);
|
|
3440
3518
|
else if (field.type === "json") add(`key field "${name}" is json`);
|
|
3441
3519
|
}
|
|
3442
|
-
|
|
3520
|
+
const bounded = [...Object.entries(definition.fields), ...definition.kind === "table" ? Object.entries(definition.derived) : []];
|
|
3521
|
+
for (const [name, { type, maxLength, ascii }] of bounded) {
|
|
3443
3522
|
if (maxLength !== void 0 && (type !== "string" || !Number.isSafeInteger(maxLength) || maxLength < 1)) add(`field "${name}" has an invalid maxLength`);
|
|
3444
3523
|
if (ascii && type !== "string") add(`field "${name}" is ascii but not a string`);
|
|
3445
3524
|
}
|
|
@@ -3556,11 +3635,13 @@ const resolveSchema = (modules) => {
|
|
|
3556
3635
|
...maxLength === void 0 ? {} : { maxLength },
|
|
3557
3636
|
...ascii ? { ascii } : {}
|
|
3558
3637
|
}));
|
|
3559
|
-
if (definition.kind === "table") for (const [field, { type, multi }] of Object.entries(definition.derived)) columns.push({
|
|
3638
|
+
if (definition.kind === "table") for (const [field, { type, multi, maxLength, ascii }] of Object.entries(definition.derived)) columns.push({
|
|
3560
3639
|
name: field,
|
|
3561
3640
|
type,
|
|
3562
3641
|
nullable: true,
|
|
3563
|
-
...multi ? { multi } : {}
|
|
3642
|
+
...multi ? { multi } : {},
|
|
3643
|
+
...maxLength === void 0 ? {} : { maxLength },
|
|
3644
|
+
...ascii ? { ascii } : {}
|
|
3564
3645
|
});
|
|
3565
3646
|
else columns.push(integer(SHARD_COLUMN), ...[...definition.counters, ...definition.gauges].map((metric) => integer(metric)), ...definition.distinct.map((metric) => ({
|
|
3566
3647
|
name: metric,
|
|
@@ -4326,13 +4407,10 @@ const createDatabaseEngine = ({ batching, now = Date.now, meter, ...options }) =
|
|
|
4326
4407
|
};
|
|
4327
4408
|
return {
|
|
4328
4409
|
...engine,
|
|
4329
|
-
/** Applies batched aggregate changes still
|
|
4410
|
+
/** Applies the batched aggregate changes still in the log. */
|
|
4330
4411
|
flush: async () => {
|
|
4331
4412
|
await batches?.flush();
|
|
4332
4413
|
},
|
|
4333
|
-
dispose: async () => {
|
|
4334
|
-
await batches?.dispose();
|
|
4335
|
-
},
|
|
4336
4414
|
database(module) {
|
|
4337
4415
|
const name = (model) => module.namespace ? `${module.namespace}_${model}` : model;
|
|
4338
4416
|
return {
|
|
@@ -4413,8 +4491,7 @@ const createEngine = (database, { plugins = [], now = Date.now } = {}) => {
|
|
|
4413
4491
|
if (module === void 0) throw new HotUpdaterConfigError(`Plugin "${plugin.id}" is not one of this engine's plugins.`);
|
|
4414
4492
|
return engine.database(module);
|
|
4415
4493
|
},
|
|
4416
|
-
flush: () => engine.flush()
|
|
4417
|
-
dispose: () => engine.dispose()
|
|
4494
|
+
flush: () => engine.flush()
|
|
4418
4495
|
};
|
|
4419
4496
|
};
|
|
4420
4497
|
//#endregion
|
|
@@ -4707,7 +4784,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
4707
4784
|
};
|
|
4708
4785
|
//#endregion
|
|
4709
4786
|
//#region ../../packages/server/dist/version.mjs
|
|
4710
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
4787
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.31";
|
|
4711
4788
|
//#endregion
|
|
4712
4789
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
4713
4790
|
/**
|
|
@@ -5500,8 +5577,8 @@ const baseBundleIdsOf = (row, range, bundleId, limit) => {
|
|
|
5500
5577
|
//#endregion
|
|
5501
5578
|
//#region ../../packages/server/dist/core/reads.mjs
|
|
5502
5579
|
const PAGE$3 = 500;
|
|
5503
|
-
const pick$
|
|
5504
|
-
const toBundleRow = pick$
|
|
5580
|
+
const pick$2 = (fields) => (row) => Object.fromEntries(fields.map((field) => [field, row[field]]));
|
|
5581
|
+
const toBundleRow = pick$2([
|
|
5505
5582
|
"id",
|
|
5506
5583
|
"platform",
|
|
5507
5584
|
"git_commit_hash",
|
|
@@ -5510,7 +5587,7 @@ const toBundleRow = pick$1([
|
|
|
5510
5587
|
"manifest_file_hash",
|
|
5511
5588
|
"asset_base_storage_uri"
|
|
5512
5589
|
]);
|
|
5513
|
-
const toPatchRow = pick$
|
|
5590
|
+
const toPatchRow = pick$2([
|
|
5514
5591
|
"id",
|
|
5515
5592
|
"bundle_id",
|
|
5516
5593
|
"base_bundle_id",
|
|
@@ -5520,7 +5597,7 @@ const toPatchRow = pick$1([
|
|
|
5520
5597
|
"byte_size",
|
|
5521
5598
|
"order_index"
|
|
5522
5599
|
]);
|
|
5523
|
-
const toReleaseRow = pick$
|
|
5600
|
+
const toReleaseRow = pick$2([
|
|
5524
5601
|
"id",
|
|
5525
5602
|
"revision",
|
|
5526
5603
|
"scope_key",
|
|
@@ -5541,7 +5618,7 @@ const toReleaseRow = pick$1([
|
|
|
5541
5618
|
"created_at_ms",
|
|
5542
5619
|
"updated_at_ms"
|
|
5543
5620
|
]);
|
|
5544
|
-
const toCatalogRow = pick$
|
|
5621
|
+
const toCatalogRow = pick$2([
|
|
5545
5622
|
"scope_key",
|
|
5546
5623
|
"catalog_id",
|
|
5547
5624
|
"strategy",
|
|
@@ -5556,7 +5633,7 @@ const toCatalogRow = pick$1([
|
|
|
5556
5633
|
"is_tombstone",
|
|
5557
5634
|
"updated_at_ms"
|
|
5558
5635
|
]);
|
|
5559
|
-
const toChannelRow = pick$
|
|
5636
|
+
const toChannelRow = pick$2(["id", "name"]);
|
|
5560
5637
|
/** Every page of one read, in order. */
|
|
5561
5638
|
const drain$1 = async (read) => {
|
|
5562
5639
|
const rows = [];
|
|
@@ -5569,7 +5646,15 @@ const drain$1 = async (read) => {
|
|
|
5569
5646
|
return rows;
|
|
5570
5647
|
};
|
|
5571
5648
|
/** A keyset page's range: the keys strictly after `after`, in `order`. */
|
|
5572
|
-
|
|
5649
|
+
/** A keyset read's range on its index's order: past `after`, up to `through`. */
|
|
5650
|
+
const after = (input) => {
|
|
5651
|
+
const asc = (input.order ?? "asc") === "asc";
|
|
5652
|
+
const range = {
|
|
5653
|
+
...input.after === void 0 ? {} : asc ? { gt: input.after } : { lt: input.after },
|
|
5654
|
+
...input.through === void 0 ? {} : asc ? { lte: input.through } : { gte: input.through }
|
|
5655
|
+
};
|
|
5656
|
+
return Object.keys(range).length === 0 ? {} : { range };
|
|
5657
|
+
};
|
|
5573
5658
|
/** Core's reads, each through one declared index or key. */
|
|
5574
5659
|
const createCoreReads = (db, storage) => {
|
|
5575
5660
|
/** A bundle row's patches, exactly as many as its reference counter holds. */
|
|
@@ -5774,6 +5859,321 @@ const createCoreReads = (db, storage) => {
|
|
|
5774
5859
|
};
|
|
5775
5860
|
};
|
|
5776
5861
|
//#endregion
|
|
5862
|
+
//#region ../../packages/server/dist/core/iosDevices.mjs
|
|
5863
|
+
/**
|
|
5864
|
+
* A device's UDID: 40 hex digits, or 8 and 16 joined by a hyphen. The same
|
|
5865
|
+
* rule as `normalizeIosUdid` of `@hot-updater/protocol/native-artifact`,
|
|
5866
|
+
* implemented here so the server's runtime never loads the artifact readers.
|
|
5867
|
+
*/
|
|
5868
|
+
const UDID = /^(?:[0-9a-f]{40}|[0-9a-f]{8}-[0-9a-f]{16})$/iu;
|
|
5869
|
+
/** The form the registry stores and compares a UDID in, or null for text that isn't one. */
|
|
5870
|
+
const normalizeIosUdid = (value) => {
|
|
5871
|
+
const trimmed = value.trim();
|
|
5872
|
+
return UDID.test(trimmed) ? trimmed.toLowerCase() : null;
|
|
5873
|
+
};
|
|
5874
|
+
/** `ios_devices.name`'s bound in core's schema. */
|
|
5875
|
+
const NAME_MAX_LENGTH = 100;
|
|
5876
|
+
/** `ios_devices.requested_by` and `approved_by`'s bound: an email address. */
|
|
5877
|
+
const EMAIL_MAX_LENGTH = 320;
|
|
5878
|
+
/** `ios_devices.apple_issuer_id`'s bound. */
|
|
5879
|
+
const ISSUER_MAX_LENGTH = 64;
|
|
5880
|
+
/** How many registry rows one read takes while finding its account. */
|
|
5881
|
+
const ACCOUNT_SCAN_PAGE = 200;
|
|
5882
|
+
/** The one row of `ios_device_account`. */
|
|
5883
|
+
const ACCOUNT_ROW = "registry";
|
|
5884
|
+
/** `ios_devices.apple_error`'s bound. */
|
|
5885
|
+
const ERROR_MAX_LENGTH = 512;
|
|
5886
|
+
const STATUSES = [
|
|
5887
|
+
"pending",
|
|
5888
|
+
"approved",
|
|
5889
|
+
"registered"
|
|
5890
|
+
];
|
|
5891
|
+
const OUTCOMES = [
|
|
5892
|
+
"registered",
|
|
5893
|
+
"refused",
|
|
5894
|
+
"disabled",
|
|
5895
|
+
"missing"
|
|
5896
|
+
];
|
|
5897
|
+
/** The `apple_error` of a device Apple has disabled. */
|
|
5898
|
+
const IOS_DEVICE_DISABLED_ERROR = "Disabled in the Apple account.";
|
|
5899
|
+
/** The `apple_error` of a registered device Apple no longer lists. */
|
|
5900
|
+
const IOS_DEVICE_MISSING_ERROR = "Gone from the Apple account. Approve it again to register it.";
|
|
5901
|
+
/** A device or registry request core cannot store: the caller's input. */
|
|
5902
|
+
var IosDeviceInputError = class extends TypeError {
|
|
5903
|
+
name = "IosDeviceInputError";
|
|
5904
|
+
};
|
|
5905
|
+
const pick$1 = (row) => ({
|
|
5906
|
+
id: row.id,
|
|
5907
|
+
udid: row.udid,
|
|
5908
|
+
name: row.name,
|
|
5909
|
+
status: row.status,
|
|
5910
|
+
requested_by: row.requested_by ?? null,
|
|
5911
|
+
created_at_ms: row.created_at_ms,
|
|
5912
|
+
approved_by: row.approved_by ?? null,
|
|
5913
|
+
approved_at_ms: row.approved_at_ms ?? null,
|
|
5914
|
+
registered_at_ms: row.registered_at_ms ?? null,
|
|
5915
|
+
apple_issuer_id: row.apple_issuer_id ?? null,
|
|
5916
|
+
apple_error: row.apple_error ?? null,
|
|
5917
|
+
build_id: row.build_id ?? null
|
|
5918
|
+
});
|
|
5919
|
+
const udidOf = (udid) => {
|
|
5920
|
+
const key = typeof udid === "string" ? normalizeIosUdid(udid) : null;
|
|
5921
|
+
if (key === null) throw new IosDeviceInputError("Invalid iOS device: udid must be 40 hex digits, or 8 and 16 joined by a hyphen.");
|
|
5922
|
+
return key;
|
|
5923
|
+
};
|
|
5924
|
+
const nameOf$1 = (name) => {
|
|
5925
|
+
const trimmed = typeof name === "string" ? name.trim() : "";
|
|
5926
|
+
if (trimmed.length === 0 || trimmed.length > NAME_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device: name must be 1 to ${NAME_MAX_LENGTH} characters.`);
|
|
5927
|
+
return trimmed;
|
|
5928
|
+
};
|
|
5929
|
+
/** An email, lower-cased, or null for the CLI. */
|
|
5930
|
+
const personOf = (value, field) => {
|
|
5931
|
+
if (value === null) return null;
|
|
5932
|
+
const email = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
5933
|
+
if (email.length === 0 || email.length > EMAIL_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device: ${field} must be an email of at most ${EMAIL_MAX_LENGTH} characters, or null.`);
|
|
5934
|
+
return email;
|
|
5935
|
+
};
|
|
5936
|
+
/** Apple's words, on one line and within the column's bound. */
|
|
5937
|
+
const errorText = (text) => {
|
|
5938
|
+
const line = text.replace(/\s+/gu, " ").trim();
|
|
5939
|
+
return line.length > ERROR_MAX_LENGTH ? `${line.slice(0, 511)}…` : line;
|
|
5940
|
+
};
|
|
5941
|
+
/**
|
|
5942
|
+
* The iOS device registry: the iPhones and iPads a team asked to install ad hoc
|
|
5943
|
+
* builds on. The Console writes requests and approvals, and the CLI what Apple
|
|
5944
|
+
* said, each over the row it read.
|
|
5945
|
+
*/
|
|
5946
|
+
const createIosDeviceApi = (db, { now = Date.now } = {}) => {
|
|
5947
|
+
const findIosDevice = async (udid) => {
|
|
5948
|
+
const key = normalizeIosUdid(udid);
|
|
5949
|
+
if (key === null) return null;
|
|
5950
|
+
const row = await db.findOne("ios_devices", { udid: key });
|
|
5951
|
+
return row === null ? null : pick$1(row);
|
|
5952
|
+
};
|
|
5953
|
+
/**
|
|
5954
|
+
* The issuer of the registry's earliest registration among its rows, by
|
|
5955
|
+
* when and then by ID, or null when no row names one: read only while the
|
|
5956
|
+
* registry has no account yet, a page at a time.
|
|
5957
|
+
*/
|
|
5958
|
+
const accountOfRows = async () => {
|
|
5959
|
+
let earliest = null;
|
|
5960
|
+
for (let after;;) {
|
|
5961
|
+
const { rows } = await db.findMany("ios_devices", {
|
|
5962
|
+
index: "all",
|
|
5963
|
+
where: {},
|
|
5964
|
+
order: "asc",
|
|
5965
|
+
limit: ACCOUNT_SCAN_PAGE,
|
|
5966
|
+
...after === void 0 ? {} : { range: { gt: after } }
|
|
5967
|
+
});
|
|
5968
|
+
for (const row of rows.map(pick$1)) {
|
|
5969
|
+
if (row.apple_issuer_id === null) continue;
|
|
5970
|
+
if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
|
|
5971
|
+
}
|
|
5972
|
+
if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
|
|
5973
|
+
after = rows.at(-1).id;
|
|
5974
|
+
}
|
|
5975
|
+
};
|
|
5976
|
+
return {
|
|
5977
|
+
async listIosDevices(input) {
|
|
5978
|
+
if (input.status !== void 0 && !STATUSES.includes(input.status)) throw new IosDeviceInputError(`Invalid iOS device status: ${String(input.status)}. Expected ${STATUSES.join(", ")}.`);
|
|
5979
|
+
const page = {
|
|
5980
|
+
order: input.order ?? "asc",
|
|
5981
|
+
limit: input.limit,
|
|
5982
|
+
...after(input)
|
|
5983
|
+
};
|
|
5984
|
+
const { rows } = input.status === void 0 ? await db.findMany("ios_devices", {
|
|
5985
|
+
index: "all",
|
|
5986
|
+
where: {},
|
|
5987
|
+
...page
|
|
5988
|
+
}) : await db.findMany("ios_devices", {
|
|
5989
|
+
index: "byStatus",
|
|
5990
|
+
where: { status: input.status },
|
|
5991
|
+
...page
|
|
5992
|
+
});
|
|
5993
|
+
return rows.map(pick$1);
|
|
5994
|
+
},
|
|
5995
|
+
findIosDevice,
|
|
5996
|
+
async requestIosDevice(input) {
|
|
5997
|
+
const udid = udidOf(input.udid);
|
|
5998
|
+
const name = nameOf$1(input.name);
|
|
5999
|
+
const requestedBy = personOf(input.requestedBy, "requestedBy");
|
|
6000
|
+
const existing = await db.findOne("ios_devices", { udid });
|
|
6001
|
+
if (existing !== null) return {
|
|
6002
|
+
device: pick$1(existing),
|
|
6003
|
+
created: false
|
|
6004
|
+
};
|
|
6005
|
+
const device = {
|
|
6006
|
+
id: createUUIDv7(),
|
|
6007
|
+
udid,
|
|
6008
|
+
name,
|
|
6009
|
+
status: "pending",
|
|
6010
|
+
requested_by: requestedBy,
|
|
6011
|
+
created_at_ms: now(),
|
|
6012
|
+
approved_by: null,
|
|
6013
|
+
approved_at_ms: null,
|
|
6014
|
+
registered_at_ms: null,
|
|
6015
|
+
apple_issuer_id: null,
|
|
6016
|
+
apple_error: null,
|
|
6017
|
+
build_id: null
|
|
6018
|
+
};
|
|
6019
|
+
try {
|
|
6020
|
+
await db.transaction(async (tx) => {
|
|
6021
|
+
tx.create("ios_devices", device);
|
|
6022
|
+
});
|
|
6023
|
+
} catch (error) {
|
|
6024
|
+
if (error instanceof DatabaseConstraintError && error.reason === "unique") {
|
|
6025
|
+
const winner = await db.findOne("ios_devices", { udid });
|
|
6026
|
+
if (winner !== null) return {
|
|
6027
|
+
device: pick$1(winner),
|
|
6028
|
+
created: false
|
|
6029
|
+
};
|
|
6030
|
+
}
|
|
6031
|
+
throw error;
|
|
6032
|
+
}
|
|
6033
|
+
return {
|
|
6034
|
+
device,
|
|
6035
|
+
created: true
|
|
6036
|
+
};
|
|
6037
|
+
},
|
|
6038
|
+
async approveIosDevice(id, input) {
|
|
6039
|
+
const name = input.name === void 0 ? void 0 : nameOf$1(input.name);
|
|
6040
|
+
const approvedBy = personOf(input.approvedBy, "approvedBy");
|
|
6041
|
+
return db.transaction(async (tx) => {
|
|
6042
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
6043
|
+
if (row === null) return null;
|
|
6044
|
+
const device = pick$1(row);
|
|
6045
|
+
const set = {
|
|
6046
|
+
...name === void 0 || name === device.name ? {} : { name },
|
|
6047
|
+
...device.status === "pending" ? {
|
|
6048
|
+
status: "approved",
|
|
6049
|
+
approved_by: approvedBy,
|
|
6050
|
+
approved_at_ms: now()
|
|
6051
|
+
} : {}
|
|
6052
|
+
};
|
|
6053
|
+
if (Object.keys(set).length === 0) return device;
|
|
6054
|
+
tx.update("ios_devices", row, set);
|
|
6055
|
+
return {
|
|
6056
|
+
...device,
|
|
6057
|
+
...set
|
|
6058
|
+
};
|
|
6059
|
+
});
|
|
6060
|
+
},
|
|
6061
|
+
async renameIosDevice(id, input) {
|
|
6062
|
+
const name = nameOf$1(input);
|
|
6063
|
+
return db.transaction(async (tx) => {
|
|
6064
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
6065
|
+
if (row === null) return null;
|
|
6066
|
+
const device = pick$1(row);
|
|
6067
|
+
if (device.name === name) return device;
|
|
6068
|
+
tx.update("ios_devices", row, { name });
|
|
6069
|
+
return {
|
|
6070
|
+
...device,
|
|
6071
|
+
name
|
|
6072
|
+
};
|
|
6073
|
+
});
|
|
6074
|
+
},
|
|
6075
|
+
async recordIosDeviceOutcome({ id, seen, issuerId, outcome, reason }) {
|
|
6076
|
+
if (!OUTCOMES.includes(outcome)) throw new IosDeviceInputError(`Invalid iOS device outcome: ${String(outcome)}. Expected ${OUTCOMES.join(", ")}.`);
|
|
6077
|
+
if (typeof issuerId !== "string" || issuerId.trim().length === 0 || issuerId.length > ISSUER_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device outcome: issuerId must be an App Store Connect issuer of at most ${ISSUER_MAX_LENGTH} characters.`);
|
|
6078
|
+
return db.transaction(async (tx) => {
|
|
6079
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
6080
|
+
if (row === null) return null;
|
|
6081
|
+
const device = pick$1(row);
|
|
6082
|
+
if (device.status !== seen.status || device.approved_at_ms !== seen.approvedAtMs || device.apple_issuer_id !== null && device.apple_issuer_id !== issuerId) return null;
|
|
6083
|
+
let set;
|
|
6084
|
+
switch (outcome) {
|
|
6085
|
+
case "registered":
|
|
6086
|
+
if (device.status === "pending") return null;
|
|
6087
|
+
set = {
|
|
6088
|
+
status: "registered",
|
|
6089
|
+
registered_at_ms: device.registered_at_ms ?? now(),
|
|
6090
|
+
apple_issuer_id: issuerId,
|
|
6091
|
+
apple_error: null
|
|
6092
|
+
};
|
|
6093
|
+
break;
|
|
6094
|
+
case "refused":
|
|
6095
|
+
if (device.status !== "approved") return null;
|
|
6096
|
+
set = { apple_error: errorText(reason === void 0 || reason.trim() === "" ? "Apple refused it." : reason) };
|
|
6097
|
+
break;
|
|
6098
|
+
case "disabled":
|
|
6099
|
+
if (device.status === "pending") return null;
|
|
6100
|
+
set = { apple_error: IOS_DEVICE_DISABLED_ERROR };
|
|
6101
|
+
break;
|
|
6102
|
+
case "missing":
|
|
6103
|
+
if (device.status !== "registered") return null;
|
|
6104
|
+
set = {
|
|
6105
|
+
status: "pending",
|
|
6106
|
+
approved_by: null,
|
|
6107
|
+
approved_at_ms: null,
|
|
6108
|
+
apple_error: IOS_DEVICE_MISSING_ERROR
|
|
6109
|
+
};
|
|
6110
|
+
}
|
|
6111
|
+
if (Object.entries(set).some(([column, value]) => device[column] !== (value ?? null))) tx.update("ios_devices", row, set);
|
|
6112
|
+
return {
|
|
6113
|
+
...device,
|
|
6114
|
+
...set
|
|
6115
|
+
};
|
|
6116
|
+
});
|
|
6117
|
+
},
|
|
6118
|
+
async markIosDevicesInBuild({ buildId, ids }) {
|
|
6119
|
+
for (const id of new Set(ids)) await db.transaction(async (tx) => {
|
|
6120
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
6121
|
+
if (row === null || typeof row.build_id === "string" && row.build_id >= buildId) return;
|
|
6122
|
+
tx.update("ios_devices", row, { build_id: buildId });
|
|
6123
|
+
});
|
|
6124
|
+
},
|
|
6125
|
+
async claimIosDeviceAccount(issuerId) {
|
|
6126
|
+
if (typeof issuerId !== "string" || issuerId.trim().length === 0 || issuerId.length > ISSUER_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device account: issuerId must be an App Store Connect issuer of at most ${ISSUER_MAX_LENGTH} characters.`);
|
|
6127
|
+
const answer = (held) => ({
|
|
6128
|
+
issuerId: held,
|
|
6129
|
+
claimed: held === issuerId
|
|
6130
|
+
});
|
|
6131
|
+
const existing = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
|
|
6132
|
+
if (existing !== null) return answer(existing.apple_issuer_id);
|
|
6133
|
+
const holder = await accountOfRows() ?? issuerId;
|
|
6134
|
+
try {
|
|
6135
|
+
await db.transaction(async (tx) => {
|
|
6136
|
+
tx.create("ios_device_account", {
|
|
6137
|
+
id: ACCOUNT_ROW,
|
|
6138
|
+
apple_issuer_id: holder,
|
|
6139
|
+
claimed_at_ms: now()
|
|
6140
|
+
});
|
|
6141
|
+
});
|
|
6142
|
+
return answer(holder);
|
|
6143
|
+
} catch (error) {
|
|
6144
|
+
if (error instanceof DatabaseConstraintError && (error.reason === "exists" || error.reason === "unique")) {
|
|
6145
|
+
const winner = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
|
|
6146
|
+
if (winner !== null) return answer(winner.apple_issuer_id);
|
|
6147
|
+
}
|
|
6148
|
+
throw error;
|
|
6149
|
+
}
|
|
6150
|
+
},
|
|
6151
|
+
async deleteIosDevice(id, only) {
|
|
6152
|
+
const requestedBy = only?.requestedBy === void 0 ? void 0 : personOf(only.requestedBy, "requestedBy");
|
|
6153
|
+
return db.transaction(async (tx) => {
|
|
6154
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
6155
|
+
if (row === null) return null;
|
|
6156
|
+
const device = pick$1(row);
|
|
6157
|
+
if (only?.status !== void 0 && device.status !== only.status || requestedBy !== void 0 && device.requested_by !== requestedBy) return null;
|
|
6158
|
+
await tx.delete("ios_devices", row);
|
|
6159
|
+
return device;
|
|
6160
|
+
});
|
|
6161
|
+
}
|
|
6162
|
+
};
|
|
6163
|
+
};
|
|
6164
|
+
//#endregion
|
|
6165
|
+
//#region ../../packages/server/dist/core/nativeBuildDestinations.mjs
|
|
6166
|
+
/** Store destinations accepted for each native platform. */
|
|
6167
|
+
const NATIVE_BUILD_SUBMISSION_DESTINATIONS = {
|
|
6168
|
+
android: [
|
|
6169
|
+
"play-internal",
|
|
6170
|
+
"play-closed",
|
|
6171
|
+
"play-open",
|
|
6172
|
+
"play-production"
|
|
6173
|
+
],
|
|
6174
|
+
ios: ["testflight"]
|
|
6175
|
+
};
|
|
6176
|
+
//#endregion
|
|
5777
6177
|
//#region ../../packages/server/dist/core/writes.mjs
|
|
5778
6178
|
const PAGE$2 = 500;
|
|
5779
6179
|
/** Moves one bundle into or out of its platform's total and the overall total. */
|
|
@@ -5891,6 +6291,13 @@ const GIT_COMMIT_HASH_MAX_LENGTH = 255;
|
|
|
5891
6291
|
* and looks up nothing else.
|
|
5892
6292
|
*/
|
|
5893
6293
|
const BUILD_KEY = /^nbk1:[0-9a-f]{64}$/;
|
|
6294
|
+
/** `native_builds.sandbox_url_scheme`'s bound in core's schema. */
|
|
6295
|
+
const SANDBOX_URL_SCHEME_MAX_LENGTH = 255;
|
|
6296
|
+
/**
|
|
6297
|
+
* A URL scheme as RFC 3986 spells it, in lower case: what a sandbox build's
|
|
6298
|
+
* artifact registers, as `@hot-updater/protocol/native-artifact` reads it.
|
|
6299
|
+
*/
|
|
6300
|
+
const URL_SCHEME = new RegExp(`^[a-z][a-z0-9+.-]{0,254}$`);
|
|
5894
6301
|
/** A native build or scope core cannot store or look up: the caller's input. */
|
|
5895
6302
|
var NativeBuildInputError = class extends TypeError {
|
|
5896
6303
|
name = "NativeBuildInputError";
|
|
@@ -5912,13 +6319,33 @@ const pick = (row) => ({
|
|
|
5912
6319
|
build_number: row.build_number ?? null,
|
|
5913
6320
|
submitted_to: row.submitted_to ?? null,
|
|
5914
6321
|
submitted_at_ms: row.submitted_at_ms ?? null,
|
|
5915
|
-
submitted_version: row.submitted_version ?? null
|
|
6322
|
+
submitted_version: row.submitted_version ?? null,
|
|
6323
|
+
is_store_build: row.is_store_build === true,
|
|
6324
|
+
is_sandbox: row.is_sandbox === true,
|
|
6325
|
+
sandbox_url_scheme: row.sandbox_url_scheme ?? null,
|
|
6326
|
+
export_method: row.export_method ?? null,
|
|
6327
|
+
native_app_version: row.native_app_version ?? null
|
|
5916
6328
|
});
|
|
5917
|
-
/** The
|
|
5918
|
-
const
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
6329
|
+
/** The export methods an `.ipa` registers with. */
|
|
6330
|
+
const EXPORT_METHODS = /* @__PURE__ */ new Set([
|
|
6331
|
+
"app-store",
|
|
6332
|
+
"ad-hoc",
|
|
6333
|
+
"development",
|
|
6334
|
+
"enterprise"
|
|
6335
|
+
]);
|
|
6336
|
+
/**
|
|
6337
|
+
* The channels only sandbox builds register on: a registration's `sandbox`
|
|
6338
|
+
* must agree with it. The registry's convention, as
|
|
6339
|
+
* `@hot-updater/protocol/native-artifact` checks it for a build's artifact.
|
|
6340
|
+
*/
|
|
6341
|
+
const SANDBOX_CHANNEL_PREFIX = "sandbox-";
|
|
6342
|
+
/**
|
|
6343
|
+
* How many older builds of a scope one read takes, looking for one older than
|
|
6344
|
+
* a bundle when a build made after the bundle is the newest.
|
|
6345
|
+
*/
|
|
6346
|
+
const OLDER_BUILDS_PAGE = 20;
|
|
6347
|
+
/** How many times a mark runs again after losing its scope's mark to another. */
|
|
6348
|
+
const MARK_ATTEMPTS = 8;
|
|
5922
6349
|
/** `native_builds.build_number`'s bound in core's schema. */
|
|
5923
6350
|
const BUILD_NUMBER_MAX_LENGTH = 64;
|
|
5924
6351
|
/** `native_builds.submitted_version`'s bound in core's schema. */
|
|
@@ -5951,17 +6378,30 @@ const nativeBuildScopeKey = (scope) => {
|
|
|
5951
6378
|
};
|
|
5952
6379
|
/** Whether `bundleId` is a native build's built-in bundle: one unique read. */
|
|
5953
6380
|
const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
|
|
5954
|
-
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, artifact }) => {
|
|
6381
|
+
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, nativeAppVersion, artifact }) => {
|
|
5955
6382
|
if (!isUUIDv7(id)) return "id must be a UUIDv7";
|
|
5956
6383
|
if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
|
|
5957
6384
|
if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
|
|
5958
6385
|
if (channel.trim().length === 0) return "channel is required";
|
|
6386
|
+
if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
|
|
6387
|
+
const reserved = channel.startsWith(SANDBOX_CHANNEL_PREFIX);
|
|
6388
|
+
if (isSandbox === true && !reserved) return `a sandbox build registers on a ${SANDBOX_CHANNEL_PREFIX}* channel, not ${channel}`;
|
|
6389
|
+
if (isSandbox !== true && reserved) return `channel ${channel} is reserved for sandbox builds`;
|
|
6390
|
+
if (sandboxUrlScheme !== void 0 && sandboxUrlScheme !== null) {
|
|
6391
|
+
if (isSandbox !== true) return "sandboxUrlScheme is a sandbox build's, and this isn't one";
|
|
6392
|
+
if (typeof sandboxUrlScheme !== "string" || !URL_SCHEME.test(sandboxUrlScheme)) return `sandboxUrlScheme must be a URL scheme in lower case, up to ${SANDBOX_URL_SCHEME_MAX_LENGTH} characters, or null`;
|
|
6393
|
+
}
|
|
5959
6394
|
if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
|
|
5960
6395
|
if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
|
|
5961
6396
|
if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
|
|
5962
6397
|
if (buildNumber !== void 0 && buildNumber !== null && (buildNumber.trim().length === 0 || buildNumber.length > BUILD_NUMBER_MAX_LENGTH)) return `buildNumber must be the artifact's build number, up to ${BUILD_NUMBER_MAX_LENGTH} characters, or null`;
|
|
6398
|
+
if (nativeAppVersion !== void 0 && nativeAppVersion !== null && (typeof nativeAppVersion !== "string" || nativeAppVersion.trim().length === 0)) return "nativeAppVersion must be the artifact's app version, or null";
|
|
5963
6399
|
const kinds = ARTIFACT_KINDS[platform];
|
|
5964
6400
|
if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
|
|
6401
|
+
if (exportMethod !== void 0 && exportMethod !== null) {
|
|
6402
|
+
if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
|
|
6403
|
+
if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
|
|
6404
|
+
}
|
|
5965
6405
|
if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
|
|
5966
6406
|
return null;
|
|
5967
6407
|
};
|
|
@@ -5990,7 +6430,12 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
5990
6430
|
build_number: registration.buildNumber ?? null,
|
|
5991
6431
|
submitted_to: null,
|
|
5992
6432
|
submitted_at_ms: null,
|
|
5993
|
-
submitted_version: null
|
|
6433
|
+
submitted_version: null,
|
|
6434
|
+
is_store_build: false,
|
|
6435
|
+
is_sandbox: registration.isSandbox === true,
|
|
6436
|
+
sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
|
|
6437
|
+
export_method: registration.exportMethod ?? null,
|
|
6438
|
+
native_app_version: registration.nativeAppVersion ?? null
|
|
5994
6439
|
};
|
|
5995
6440
|
for (let attempt = 1;; attempt += 1) {
|
|
5996
6441
|
await insertChannel(db, {
|
|
@@ -6028,21 +6473,42 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
6028
6473
|
const scopeKey = nativeBuildScopeKey(scope);
|
|
6029
6474
|
const buildKey = options?.buildKey;
|
|
6030
6475
|
if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6476
|
+
if (options?.storeBuild) {
|
|
6477
|
+
const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
|
|
6478
|
+
return marked === null ? null : pick(marked);
|
|
6479
|
+
}
|
|
6480
|
+
const read = (limit, before) => {
|
|
6481
|
+
const page = {
|
|
6482
|
+
order: "desc",
|
|
6483
|
+
limit,
|
|
6484
|
+
...before === void 0 ? {} : { range: { lt: before } }
|
|
6485
|
+
};
|
|
6486
|
+
return buildKey === void 0 ? db.findMany("native_builds", {
|
|
6487
|
+
index: "byScope",
|
|
6488
|
+
where: { scope_key: scopeKey },
|
|
6489
|
+
...page
|
|
6490
|
+
}) : db.findMany("native_builds", {
|
|
6491
|
+
index: "byBuildKey",
|
|
6492
|
+
where: {
|
|
6493
|
+
scope_key: scopeKey,
|
|
6494
|
+
build_key: buildKey
|
|
6495
|
+
},
|
|
6496
|
+
...page
|
|
6497
|
+
});
|
|
6498
|
+
};
|
|
6499
|
+
const { rows } = await read(1);
|
|
6500
|
+
const newest = rows[0];
|
|
6501
|
+
if (newest === void 0) return null;
|
|
6502
|
+
const bundleId = options?.builtInOlderThan;
|
|
6503
|
+
if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
|
|
6504
|
+
for (let before = newest.id;;) {
|
|
6505
|
+
const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
|
|
6506
|
+
const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
|
|
6507
|
+
if (usable !== void 0) return pick(usable);
|
|
6508
|
+
const last = older.at(-1);
|
|
6509
|
+
if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
|
|
6510
|
+
before = last.id;
|
|
6511
|
+
}
|
|
6046
6512
|
},
|
|
6047
6513
|
async recordNativeBuildSubmission(id, { destination, version }) {
|
|
6048
6514
|
if (version.trim().length === 0 || version.length > SUBMITTED_VERSION_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build submission: version must be the store's label of the build, up to ${SUBMITTED_VERSION_MAX_LENGTH} characters.`);
|
|
@@ -6050,7 +6516,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
6050
6516
|
const row = await tx.findOne("native_builds", { id });
|
|
6051
6517
|
if (row === null) return null;
|
|
6052
6518
|
const build = pick(row);
|
|
6053
|
-
if (
|
|
6519
|
+
if (!NATIVE_BUILD_SUBMISSION_DESTINATIONS[build.platform].includes(destination)) throw new NativeBuildInputError(`Invalid native build submission: an ${build.platform} build is submitted to ${NATIVE_BUILD_SUBMISSION_DESTINATIONS[build.platform].join(" or ")}, not ${destination}.`);
|
|
6520
|
+
if (build.is_sandbox && destination !== "testflight" && destination !== "play-internal") throw new NativeBuildInputError("A sandbox build can submit only to TestFlight or Play internal testing.");
|
|
6054
6521
|
const set = {
|
|
6055
6522
|
submitted_to: destination,
|
|
6056
6523
|
submitted_at_ms: now(),
|
|
@@ -6063,6 +6530,46 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
6063
6530
|
};
|
|
6064
6531
|
});
|
|
6065
6532
|
},
|
|
6533
|
+
async markNativeBuild(id, { storeBuild }) {
|
|
6534
|
+
for (let attempt = 1;; attempt += 1) try {
|
|
6535
|
+
return await db.transaction(async (tx) => {
|
|
6536
|
+
const row = await tx.findOne("native_builds", { id });
|
|
6537
|
+
if (row === null) return null;
|
|
6538
|
+
const build = pick(row);
|
|
6539
|
+
if (!storeBuild) {
|
|
6540
|
+
if (build.is_store_build) tx.update("native_builds", row, { is_store_build: false });
|
|
6541
|
+
return {
|
|
6542
|
+
nativeBuild: {
|
|
6543
|
+
...build,
|
|
6544
|
+
is_store_build: false
|
|
6545
|
+
},
|
|
6546
|
+
previous: null
|
|
6547
|
+
};
|
|
6548
|
+
}
|
|
6549
|
+
if (build.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
|
|
6550
|
+
if (build.is_store_build) return {
|
|
6551
|
+
nativeBuild: build,
|
|
6552
|
+
previous: null
|
|
6553
|
+
};
|
|
6554
|
+
const holder = await tx.findOne("native_builds", { store_build_scope_key: build.scope_key });
|
|
6555
|
+
if (holder !== null) tx.update("native_builds", holder, { is_store_build: false });
|
|
6556
|
+
tx.update("native_builds", row, { is_store_build: true });
|
|
6557
|
+
return {
|
|
6558
|
+
nativeBuild: {
|
|
6559
|
+
...build,
|
|
6560
|
+
is_store_build: true
|
|
6561
|
+
},
|
|
6562
|
+
previous: holder === null ? null : {
|
|
6563
|
+
...pick(holder),
|
|
6564
|
+
is_store_build: false
|
|
6565
|
+
}
|
|
6566
|
+
};
|
|
6567
|
+
});
|
|
6568
|
+
} catch (error) {
|
|
6569
|
+
if (attempt < MARK_ATTEMPTS && error instanceof DatabaseConstraintError && error.reason === "unique") continue;
|
|
6570
|
+
throw error;
|
|
6571
|
+
}
|
|
6572
|
+
},
|
|
6066
6573
|
async deleteNativeBuild(id) {
|
|
6067
6574
|
return db.transaction(async (tx) => {
|
|
6068
6575
|
const row = await tx.findOne("native_builds", { id });
|
|
@@ -6675,6 +7182,7 @@ const createCoreApi = (db, storage, options = {}) => {
|
|
|
6675
7182
|
...reads,
|
|
6676
7183
|
...createCoreOperations(purgingCachedRoutes(db, options.onCachedRoutesChange), options),
|
|
6677
7184
|
...createNativeBuildApi(db, options),
|
|
7185
|
+
...createIosDeviceApi(db, options),
|
|
6678
7186
|
/** One read, which checks the schema settings first. */
|
|
6679
7187
|
ready: async () => {
|
|
6680
7188
|
await reads.listReleaseCatalogs({ limit: 1 });
|
|
@@ -6894,10 +7402,12 @@ const keyset = (url, maxValue = LIMITS.maxValue) => {
|
|
|
6894
7402
|
const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
|
|
6895
7403
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
|
|
6896
7404
|
const cursor = url.searchParams.get("cursor");
|
|
7405
|
+
const through = url.searchParams.get("through");
|
|
6897
7406
|
return {
|
|
6898
7407
|
order,
|
|
6899
7408
|
limit,
|
|
6900
|
-
...cursor === null ? {} : { after: cursor }
|
|
7409
|
+
...cursor === null ? {} : { after: cursor },
|
|
7410
|
+
...through === null ? {} : { through }
|
|
6901
7411
|
};
|
|
6902
7412
|
};
|
|
6903
7413
|
/** A page and the cursor of the next one, when the page is full. */
|
|
@@ -7012,11 +7522,11 @@ const refusingInvalid = async (operation) => {
|
|
|
7012
7522
|
try {
|
|
7013
7523
|
return await operation();
|
|
7014
7524
|
} catch (error) {
|
|
7015
|
-
if (error instanceof NativeBuildInputError) throw new HandlerBadRequestError(error.message);
|
|
7525
|
+
if (error instanceof NativeBuildInputError || error instanceof IosDeviceInputError) throw new HandlerBadRequestError(error.message);
|
|
7016
7526
|
throw error;
|
|
7017
7527
|
}
|
|
7018
7528
|
};
|
|
7019
|
-
const isNativeBuildRegistration = (value) => isRecord$5(value) && isText$2(value.id) && isText$2(value.minBundleId) && typeof value.platform === "string" && isPlatform(value.platform) && isText$2(value.channel) && isTextOrNull$1(value.fingerprintHash) && isTextOrNull$1(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull$1(value.gitCommitHash) && isTextOrNull$1(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull$1(value.buildNumber)) && isRecord$5(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText$2(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord$5(value.embeddedBundle) && isText$2(value.embeddedBundle.manifestStorageUri) && isText$2(value.embeddedBundle.manifestFileHash) && isText$2(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord$5(value.embeddedBundle.metadata));
|
|
7529
|
+
const isNativeBuildRegistration = (value) => isRecord$5(value) && isText$2(value.id) && isText$2(value.minBundleId) && typeof value.platform === "string" && isPlatform(value.platform) && isText$2(value.channel) && isTextOrNull$1(value.fingerprintHash) && isTextOrNull$1(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull$1(value.gitCommitHash) && isTextOrNull$1(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull$1(value.buildNumber)) && (value.isSandbox === void 0 || typeof value.isSandbox === "boolean") && (value.sandboxUrlScheme === void 0 || isTextOrNull$1(value.sandboxUrlScheme)) && (value.exportMethod === void 0 || isTextOrNull$1(value.exportMethod)) && (value.nativeAppVersion === void 0 || isTextOrNull$1(value.nativeAppVersion)) && isRecord$5(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText$2(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord$5(value.embeddedBundle) && isText$2(value.embeddedBundle.manifestStorageUri) && isText$2(value.embeddedBundle.manifestFileHash) && isText$2(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord$5(value.embeddedBundle.metadata));
|
|
7020
7530
|
const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
|
|
7021
7531
|
/** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
|
|
7022
7532
|
const createAdminRouteHandlers = () => ({
|
|
@@ -7145,7 +7655,13 @@ const createAdminRouteHandlers = () => ({
|
|
|
7145
7655
|
const url = new URL(request.url);
|
|
7146
7656
|
const scope = nativeBuildScopeOf(url);
|
|
7147
7657
|
const buildKey = url.searchParams.get("buildKey");
|
|
7148
|
-
|
|
7658
|
+
const builtInOlderThan = url.searchParams.get("builtInOlderThan");
|
|
7659
|
+
const options = {
|
|
7660
|
+
...buildKey === null ? {} : { buildKey },
|
|
7661
|
+
...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
|
|
7662
|
+
...builtInOlderThan === null ? {} : { builtInOlderThan }
|
|
7663
|
+
};
|
|
7664
|
+
return json$2({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
|
|
7149
7665
|
}),
|
|
7150
7666
|
getNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
|
|
7151
7667
|
listNativeBuilds: onCore(async (core, request) => {
|
|
@@ -7159,14 +7675,95 @@ const createAdminRouteHandlers = () => ({
|
|
|
7159
7675
|
}),
|
|
7160
7676
|
recordNativeBuildSubmission: onCore(async (core, request, params) => {
|
|
7161
7677
|
const input = await body(request);
|
|
7162
|
-
if (!isRecord$5(input) ||
|
|
7678
|
+
if (!isRecord$5(input) || !Object.values(NATIVE_BUILD_SUBMISSION_DESTINATIONS).flat().includes(input.destination) || !isText$2(input.version)) throw new HandlerBadRequestError("A native build submission needs a valid store destination and version.");
|
|
7163
7679
|
const submission = {
|
|
7164
7680
|
destination: input.destination,
|
|
7165
7681
|
version: input.version
|
|
7166
7682
|
};
|
|
7167
7683
|
return json$2({ data: await refusingInvalid(() => core.recordNativeBuildSubmission(requireRouteParam(params, "id"), submission)) });
|
|
7168
7684
|
}),
|
|
7685
|
+
markNativeBuild: onCore(async (core, request, params) => {
|
|
7686
|
+
const input = await body(request);
|
|
7687
|
+
if (!isRecord$5(input) || typeof input.storeBuild !== "boolean") throw new HandlerBadRequestError("A native build's store build mark needs storeBuild, true or false.");
|
|
7688
|
+
const mark = { storeBuild: input.storeBuild };
|
|
7689
|
+
return json$2({ data: await refusingInvalid(() => core.markNativeBuild(requireRouteParam(params, "id"), mark)) });
|
|
7690
|
+
}),
|
|
7169
7691
|
deleteNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.deleteNativeBuild(requireRouteParam(params, "id")) })),
|
|
7692
|
+
listIosDevices: onCore(async (core, request) => {
|
|
7693
|
+
const url = new URL(request.url);
|
|
7694
|
+
const input = keyset(url);
|
|
7695
|
+
const status = url.searchParams.get("status");
|
|
7696
|
+
return page(await refusingInvalid(() => core.listIosDevices({
|
|
7697
|
+
...input,
|
|
7698
|
+
...status === null ? {} : { status }
|
|
7699
|
+
})), input, ({ id }) => id);
|
|
7700
|
+
}),
|
|
7701
|
+
findIosDevice: onCore(async (core, _request, params) => json$2({ data: await core.findIosDevice(requireRouteParam(params, "udid")) })),
|
|
7702
|
+
requestIosDevice: onCore(async (core, request) => {
|
|
7703
|
+
const input = await body(request);
|
|
7704
|
+
if (!isText$2(input.udid) || !isText$2(input.name) || !isTextOrNull$1(input.requestedBy)) throw new HandlerBadRequestError("An iOS device request needs udid, name, and requestedBy, an email or null.");
|
|
7705
|
+
const device = {
|
|
7706
|
+
udid: input.udid,
|
|
7707
|
+
name: input.name,
|
|
7708
|
+
requestedBy: input.requestedBy
|
|
7709
|
+
};
|
|
7710
|
+
return json$2({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
|
|
7711
|
+
}),
|
|
7712
|
+
approveIosDevice: onCore(async (core, request, params) => {
|
|
7713
|
+
const input = await body(request);
|
|
7714
|
+
if (!isTextOrNull$1(input.approvedBy) || input.name !== void 0 && !isText$2(input.name)) throw new HandlerBadRequestError("An iOS device approval needs approvedBy, an email or null, and an optional name.");
|
|
7715
|
+
const approval = {
|
|
7716
|
+
approvedBy: input.approvedBy,
|
|
7717
|
+
...input.name === void 0 ? {} : { name: input.name }
|
|
7718
|
+
};
|
|
7719
|
+
return json$2({ data: await refusingInvalid(() => core.approveIosDevice(requireRouteParam(params, "id"), approval)) });
|
|
7720
|
+
}),
|
|
7721
|
+
renameIosDevice: onCore(async (core, request, params) => {
|
|
7722
|
+
const input = await body(request);
|
|
7723
|
+
if (!isText$2(input.name)) throw new HandlerBadRequestError("An iOS device's new name is required.");
|
|
7724
|
+
const name = input.name;
|
|
7725
|
+
return json$2({ data: await refusingInvalid(() => core.renameIosDevice(requireRouteParam(params, "id"), name)) });
|
|
7726
|
+
}),
|
|
7727
|
+
recordIosDeviceOutcome: onCore(async (core, request, params) => {
|
|
7728
|
+
const input = await body(request);
|
|
7729
|
+
const seen = input.seen;
|
|
7730
|
+
if (!isRecord$5(seen) || typeof seen.status !== "string" || !(seen.approvedAtMs === null || Number.isSafeInteger(seen.approvedAtMs)) || !isText$2(input.issuerId) || typeof input.outcome !== "string" || input.reason !== void 0 && typeof input.reason !== "string") throw new HandlerBadRequestError("An iOS device outcome needs seen { status, approvedAtMs }, issuerId, outcome, and an optional reason.");
|
|
7731
|
+
const outcome = {
|
|
7732
|
+
id: requireRouteParam(params, "id"),
|
|
7733
|
+
seen: {
|
|
7734
|
+
status: seen.status,
|
|
7735
|
+
approvedAtMs: seen.approvedAtMs
|
|
7736
|
+
},
|
|
7737
|
+
issuerId: input.issuerId,
|
|
7738
|
+
outcome: input.outcome,
|
|
7739
|
+
...input.reason === void 0 ? {} : { reason: input.reason }
|
|
7740
|
+
};
|
|
7741
|
+
return json$2({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
|
|
7742
|
+
}),
|
|
7743
|
+
claimIosDeviceAccount: onCore(async (core, request) => {
|
|
7744
|
+
const { issuerId } = await body(request);
|
|
7745
|
+
if (!isText$2(issuerId)) throw new HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
|
|
7746
|
+
return json$2({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
|
|
7747
|
+
}),
|
|
7748
|
+
markIosDevicesInBuild: onCore(async (core, request) => {
|
|
7749
|
+
const { buildId, ids } = await body(request);
|
|
7750
|
+
if (!isText$2(buildId) || !Array.isArray(ids) || !ids.every((id) => isText$2(id))) throw new HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
|
|
7751
|
+
await core.markIosDevicesInBuild({
|
|
7752
|
+
buildId,
|
|
7753
|
+
ids
|
|
7754
|
+
});
|
|
7755
|
+
return noContent();
|
|
7756
|
+
}),
|
|
7757
|
+
deleteIosDevice: onCore(async (core, request, params) => {
|
|
7758
|
+
const url = new URL(request.url);
|
|
7759
|
+
const status = url.searchParams.get("status");
|
|
7760
|
+
const requestedBy = url.searchParams.get("requestedBy");
|
|
7761
|
+
const only = {
|
|
7762
|
+
...status === null ? {} : { status },
|
|
7763
|
+
...requestedBy === null ? {} : { requestedBy }
|
|
7764
|
+
};
|
|
7765
|
+
return json$2({ data: await refusingInvalid(() => Object.keys(only).length === 0 ? core.deleteIosDevice(requireRouteParam(params, "id")) : core.deleteIosDevice(requireRouteParam(params, "id"), only)) });
|
|
7766
|
+
}),
|
|
7170
7767
|
deleteBundles: onCore(async (core, request) => {
|
|
7171
7768
|
const { ids } = await body(request);
|
|
7172
7769
|
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new HandlerBadRequestError("Bundle deletion needs ids");
|
|
@@ -7311,10 +7908,60 @@ const ADMIN_ROUTES = [
|
|
|
7311
7908
|
path: "/native-builds/:id/submission",
|
|
7312
7909
|
handler: "recordNativeBuildSubmission"
|
|
7313
7910
|
},
|
|
7911
|
+
{
|
|
7912
|
+
method: "POST",
|
|
7913
|
+
path: "/native-builds/:id/store-build",
|
|
7914
|
+
handler: "markNativeBuild"
|
|
7915
|
+
},
|
|
7314
7916
|
{
|
|
7315
7917
|
method: "DELETE",
|
|
7316
7918
|
path: "/native-builds/:id",
|
|
7317
7919
|
handler: "deleteNativeBuild"
|
|
7920
|
+
},
|
|
7921
|
+
{
|
|
7922
|
+
method: "GET",
|
|
7923
|
+
path: "/ios-devices",
|
|
7924
|
+
handler: "listIosDevices"
|
|
7925
|
+
},
|
|
7926
|
+
{
|
|
7927
|
+
method: "POST",
|
|
7928
|
+
path: "/ios-devices",
|
|
7929
|
+
handler: "requestIosDevice"
|
|
7930
|
+
},
|
|
7931
|
+
{
|
|
7932
|
+
method: "GET",
|
|
7933
|
+
path: "/ios-devices/udid/:udid",
|
|
7934
|
+
handler: "findIosDevice"
|
|
7935
|
+
},
|
|
7936
|
+
{
|
|
7937
|
+
method: "POST",
|
|
7938
|
+
path: "/ios-devices/in-build",
|
|
7939
|
+
handler: "markIosDevicesInBuild"
|
|
7940
|
+
},
|
|
7941
|
+
{
|
|
7942
|
+
method: "POST",
|
|
7943
|
+
path: "/ios-devices/account",
|
|
7944
|
+
handler: "claimIosDeviceAccount"
|
|
7945
|
+
},
|
|
7946
|
+
{
|
|
7947
|
+
method: "POST",
|
|
7948
|
+
path: "/ios-devices/:id/approval",
|
|
7949
|
+
handler: "approveIosDevice"
|
|
7950
|
+
},
|
|
7951
|
+
{
|
|
7952
|
+
method: "POST",
|
|
7953
|
+
path: "/ios-devices/:id/outcome",
|
|
7954
|
+
handler: "recordIosDeviceOutcome"
|
|
7955
|
+
},
|
|
7956
|
+
{
|
|
7957
|
+
method: "PATCH",
|
|
7958
|
+
path: "/ios-devices/:id",
|
|
7959
|
+
handler: "renameIosDevice"
|
|
7960
|
+
},
|
|
7961
|
+
{
|
|
7962
|
+
method: "DELETE",
|
|
7963
|
+
path: "/ios-devices/:id",
|
|
7964
|
+
handler: "deleteIosDevice"
|
|
7318
7965
|
}
|
|
7319
7966
|
];
|
|
7320
7967
|
//#endregion
|
|
@@ -14295,10 +14942,30 @@ async apply() {
|
|
|
14295
14942
|
};
|
|
14296
14943
|
};
|
|
14297
14944
|
//#endregion
|
|
14945
|
+
//#region src/lazyCredentials.ts
|
|
14946
|
+
/**
|
|
14947
|
+
* `credentials` as the AWS SDK takes them: access keys with a lazy field
|
|
14948
|
+
* become a provider, which the SDK calls once, on its first request.
|
|
14949
|
+
*/
|
|
14950
|
+
const toSdkCredentials$1 = (credentials) => {
|
|
14951
|
+
if (credentials === void 0 || typeof credentials === "function") return credentials;
|
|
14952
|
+
const { accessKeyId, secretAccessKey, sessionToken, ...rest } = credentials;
|
|
14953
|
+
if (typeof accessKeyId !== "function" && typeof secretAccessKey !== "function" && typeof sessionToken !== "function") return credentials;
|
|
14954
|
+
return async () => ({
|
|
14955
|
+
...rest,
|
|
14956
|
+
accessKeyId: await resolveLazy(accessKeyId),
|
|
14957
|
+
secretAccessKey: await resolveLazy(secretAccessKey),
|
|
14958
|
+
...sessionToken === void 0 ? {} : { sessionToken: await resolveLazy(sessionToken) }
|
|
14959
|
+
});
|
|
14960
|
+
};
|
|
14961
|
+
//#endregion
|
|
14298
14962
|
//#region src/dynamoDB.ts
|
|
14299
14963
|
/** The DynamoDB client ignores the CloudFront and batching settings. */
|
|
14300
|
-
const adapterOf = ({ tableName, ...clientConfig }) => {
|
|
14301
|
-
const client = new _aws_sdk_client_dynamodb.DynamoDBClient(
|
|
14964
|
+
const adapterOf = ({ tableName, credentials, ...clientConfig }) => {
|
|
14965
|
+
const client = new _aws_sdk_client_dynamodb.DynamoDBClient({
|
|
14966
|
+
...clientConfig,
|
|
14967
|
+
credentials: toSdkCredentials$1(credentials)
|
|
14968
|
+
});
|
|
14302
14969
|
const store = createDynamoDBStore({
|
|
14303
14970
|
client,
|
|
14304
14971
|
tableName
|
|
@@ -14323,7 +14990,10 @@ const marked = (target) => ({ [DATABASE_TARGET]: target });
|
|
|
14323
14990
|
*/
|
|
14324
14991
|
const dynamoDB = (config) => {
|
|
14325
14992
|
const { client, adapter } = adapterOf(config);
|
|
14326
|
-
const cloudFront = createUpdateRouteInvalidation(
|
|
14993
|
+
const cloudFront = createUpdateRouteInvalidation({
|
|
14994
|
+
...config,
|
|
14995
|
+
credentials: toSdkCredentials$1(config.credentials)
|
|
14996
|
+
});
|
|
14327
14997
|
return {
|
|
14328
14998
|
...createEngineDatabase({
|
|
14329
14999
|
name: "dynamoDB",
|
|
@@ -14340,18 +15010,49 @@ const dynamoDB = (config) => {
|
|
|
14340
15010
|
};
|
|
14341
15011
|
};
|
|
14342
15012
|
//#endregion
|
|
14343
|
-
//#region
|
|
15013
|
+
//#region ../storage-s3/dist/index.mjs
|
|
15014
|
+
/**
|
|
15015
|
+
* `credentials` as the AWS SDK takes them: access keys with a lazy field
|
|
15016
|
+
* become a provider, which the SDK calls once, on its first request.
|
|
15017
|
+
*/
|
|
15018
|
+
const toSdkCredentials = (credentials) => {
|
|
15019
|
+
if (credentials === void 0 || typeof credentials === "function") return credentials;
|
|
15020
|
+
const { accessKeyId, secretAccessKey, sessionToken, ...rest } = credentials;
|
|
15021
|
+
if (typeof accessKeyId !== "function" && typeof secretAccessKey !== "function" && typeof sessionToken !== "function") return credentials;
|
|
15022
|
+
return async () => ({
|
|
15023
|
+
...rest,
|
|
15024
|
+
accessKeyId: await resolveLazy(accessKeyId),
|
|
15025
|
+
secretAccessKey: await resolveLazy(secretAccessKey),
|
|
15026
|
+
...sessionToken === void 0 ? {} : { sessionToken: await resolveLazy(sessionToken) }
|
|
15027
|
+
});
|
|
15028
|
+
};
|
|
14344
15029
|
/** Devices download right after the update check that returns the URL. */
|
|
14345
|
-
const
|
|
14346
|
-
|
|
14347
|
-
|
|
14348
|
-
|
|
14349
|
-
|
|
14350
|
-
|
|
15030
|
+
const DEFAULT_SIGNED_LIFETIME_SECONDS = 3600;
|
|
15031
|
+
/** SigV4's limit on a presigned URL. */
|
|
15032
|
+
const MAX_SIGNED_LIFETIME_SECONDS = 604800;
|
|
15033
|
+
/** DeleteObjects takes at most 1000 keys a request. */
|
|
15034
|
+
const DELETE_BATCH_SIZE = 1e3;
|
|
15035
|
+
const isObjectNotFoundError = (error) => {
|
|
15036
|
+
if (error instanceof Error && (error.name === "NotFound" || error.name === "NoSuchKey")) return true;
|
|
15037
|
+
return typeof error === "object" && error !== null && "$metadata" in error && error.$metadata?.httpStatusCode === 404;
|
|
15038
|
+
};
|
|
15039
|
+
const trimSlashes = (value) => value.replace(/^\/+|\/+$/g, "");
|
|
15040
|
+
/**
|
|
15041
|
+
* A storage adapter over a bucket's S3 API, which AWS S3, Cloudflare R2, and
|
|
15042
|
+
* Neon Object Storage all serve. Each provider package passes its own name,
|
|
15043
|
+
* URI protocol, and client defaults.
|
|
15044
|
+
*/
|
|
15045
|
+
const createS3Storage = ({ name, protocol }, config) => {
|
|
15046
|
+
const { bucketName, basePath, getDownloadUrl, signedUrlExpiresIn = DEFAULT_SIGNED_LIFETIME_SECONDS, credentials, ...clientConfig } = config;
|
|
15047
|
+
if (!Number.isFinite(signedUrlExpiresIn) || signedUrlExpiresIn <= 0 || signedUrlExpiresIn > MAX_SIGNED_LIFETIME_SECONDS) throw new Error(`${name} signedUrlExpiresIn must be between 1 and ${MAX_SIGNED_LIFETIME_SECONDS} seconds (seven days).`);
|
|
15048
|
+
const client = new _aws_sdk_client_s3.S3Client({
|
|
15049
|
+
...clientConfig,
|
|
15050
|
+
credentials: toSdkCredentials(credentials)
|
|
15051
|
+
});
|
|
15052
|
+
const normalizedBasePath = trimSlashes(basePath ?? "");
|
|
14351
15053
|
const getStorageKey = createStorageKeyBuilder(normalizedBasePath);
|
|
14352
15054
|
const getListPrefix = (prefix = "") => {
|
|
14353
|
-
const
|
|
14354
|
-
const value = [normalizedBasePath, normalizedPrefix].filter(Boolean).join("/");
|
|
15055
|
+
const value = [normalizedBasePath, trimSlashes(prefix)].filter(Boolean).join("/");
|
|
14355
15056
|
return value ? `${value}/` : "";
|
|
14356
15057
|
};
|
|
14357
15058
|
/**
|
|
@@ -14363,7 +15064,7 @@ function s3Storage(config) {
|
|
|
14363
15064
|
return createStorageUri({
|
|
14364
15065
|
bucket: bucketName,
|
|
14365
15066
|
key,
|
|
14366
|
-
protocol
|
|
15067
|
+
protocol
|
|
14367
15068
|
});
|
|
14368
15069
|
} catch {
|
|
14369
15070
|
return null;
|
|
@@ -14375,55 +15076,16 @@ function s3Storage(config) {
|
|
|
14375
15076
|
return key.startsWith(basePrefix) ? key.slice(basePrefix.length) : key;
|
|
14376
15077
|
};
|
|
14377
15078
|
const parseAndValidate = (storageUri) => {
|
|
14378
|
-
const parsed = parseStorageUri(storageUri,
|
|
15079
|
+
const parsed = parseStorageUri(storageUri, protocol);
|
|
14379
15080
|
if (parsed.bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${parsed.bucket}".`);
|
|
14380
15081
|
return parsed;
|
|
14381
15082
|
};
|
|
14382
15083
|
return createStorageAdapter({
|
|
14383
|
-
name
|
|
14384
|
-
protocol
|
|
14385
|
-
async listObjects(prefix) {
|
|
14386
|
-
const objects = [];
|
|
14387
|
-
let continuationToken;
|
|
14388
|
-
do {
|
|
14389
|
-
const response = await client.send(new _aws_sdk_client_s3.ListObjectsV2Command({
|
|
14390
|
-
Bucket: bucketName,
|
|
14391
|
-
ContinuationToken: continuationToken,
|
|
14392
|
-
Prefix: getListPrefix(prefix)
|
|
14393
|
-
}));
|
|
14394
|
-
for (const object of response.Contents ?? []) {
|
|
14395
|
-
if (!object.Key) continue;
|
|
14396
|
-
const storageUri = getListedStorageUri(object.Key);
|
|
14397
|
-
if (storageUri === null) continue;
|
|
14398
|
-
objects.push({
|
|
14399
|
-
key: getRelativeKey(object.Key),
|
|
14400
|
-
lastModifiedAt: object.LastModified,
|
|
14401
|
-
size: object.Size ?? 0,
|
|
14402
|
-
storageUri
|
|
14403
|
-
});
|
|
14404
|
-
}
|
|
14405
|
-
continuationToken = response.NextContinuationToken;
|
|
14406
|
-
} while (continuationToken);
|
|
14407
|
-
return objects;
|
|
14408
|
-
},
|
|
14409
|
-
async deleteObjects(relativeKeys) {
|
|
14410
|
-
const keys = relativeKeys.map((key) => getStorageKey(key));
|
|
14411
|
-
for (let offset = 0; offset < keys.length; offset += 1e3) {
|
|
14412
|
-
const batch = keys.slice(offset, offset + 1e3);
|
|
14413
|
-
if (batch.length === 0) continue;
|
|
14414
|
-
const response = await client.send(new _aws_sdk_client_s3.DeleteObjectsCommand({
|
|
14415
|
-
Bucket: bucketName,
|
|
14416
|
-
Delete: {
|
|
14417
|
-
Objects: batch.map((Key) => ({ Key })),
|
|
14418
|
-
Quiet: true
|
|
14419
|
-
}
|
|
14420
|
-
}));
|
|
14421
|
-
if (response.Errors && response.Errors.length > 0) throw new Error(`Failed to delete ${response.Errors.length} S3 object(s).`);
|
|
14422
|
-
}
|
|
14423
|
-
},
|
|
15084
|
+
name,
|
|
15085
|
+
protocol,
|
|
14424
15086
|
async put({ key, body, contentLength, contentType }) {
|
|
14425
15087
|
const storageKey = getStorageKey(key);
|
|
14426
|
-
|
|
15088
|
+
await new _aws_sdk_lib_storage.Upload({
|
|
14427
15089
|
client,
|
|
14428
15090
|
params: {
|
|
14429
15091
|
Body: body,
|
|
@@ -14434,11 +15096,10 @@ function s3Storage(config) {
|
|
|
14434
15096
|
Key: storageKey
|
|
14435
15097
|
}
|
|
14436
15098
|
}).done();
|
|
14437
|
-
if (!response.Bucket || !response.Key) throw new Error("Upload failed");
|
|
14438
15099
|
return { storageUri: createStorageUri({
|
|
14439
15100
|
bucket: bucketName,
|
|
14440
15101
|
key: storageKey,
|
|
14441
|
-
protocol
|
|
15102
|
+
protocol
|
|
14442
15103
|
}) };
|
|
14443
15104
|
},
|
|
14444
15105
|
async get({ storageUri }) {
|
|
@@ -14461,11 +15122,10 @@ function s3Storage(config) {
|
|
|
14461
15122
|
async getDownloadUrl({ storageUri }) {
|
|
14462
15123
|
const { key } = parseAndValidate(storageUri);
|
|
14463
15124
|
if (getDownloadUrl) return getDownloadUrl({ storageUri });
|
|
14464
|
-
|
|
14465
|
-
return { url: await getSignedUrl(client, new _aws_sdk_client_s3.GetObjectCommand({
|
|
15125
|
+
return { url: await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(client, new _aws_sdk_client_s3.GetObjectCommand({
|
|
14466
15126
|
Bucket: bucketName,
|
|
14467
15127
|
Key: key
|
|
14468
|
-
}), { expiresIn:
|
|
15128
|
+
}), { expiresIn: signedUrlExpiresIn }) };
|
|
14469
15129
|
},
|
|
14470
15130
|
async exists({ storageUri }) {
|
|
14471
15131
|
const { key } = parseAndValidate(storageUri);
|
|
@@ -14487,8 +15147,61 @@ function s3Storage(config) {
|
|
|
14487
15147
|
Key: key
|
|
14488
15148
|
}));
|
|
14489
15149
|
return { deleted: true };
|
|
15150
|
+
},
|
|
15151
|
+
async listObjects(prefix) {
|
|
15152
|
+
const objects = [];
|
|
15153
|
+
let continuationToken;
|
|
15154
|
+
do {
|
|
15155
|
+
const response = await client.send(new _aws_sdk_client_s3.ListObjectsV2Command({
|
|
15156
|
+
Bucket: bucketName,
|
|
15157
|
+
ContinuationToken: continuationToken,
|
|
15158
|
+
Prefix: getListPrefix(prefix)
|
|
15159
|
+
}));
|
|
15160
|
+
for (const object of response.Contents ?? []) {
|
|
15161
|
+
if (!object.Key) continue;
|
|
15162
|
+
const storageUri = getListedStorageUri(object.Key);
|
|
15163
|
+
if (storageUri === null) continue;
|
|
15164
|
+
objects.push({
|
|
15165
|
+
key: getRelativeKey(object.Key),
|
|
15166
|
+
lastModifiedAt: object.LastModified,
|
|
15167
|
+
size: object.Size ?? 0,
|
|
15168
|
+
storageUri
|
|
15169
|
+
});
|
|
15170
|
+
}
|
|
15171
|
+
continuationToken = response.NextContinuationToken;
|
|
15172
|
+
} while (continuationToken);
|
|
15173
|
+
return objects;
|
|
15174
|
+
},
|
|
15175
|
+
async deleteObjects(relativeKeys) {
|
|
15176
|
+
const keys = relativeKeys.map((key) => getStorageKey(key));
|
|
15177
|
+
for (let offset = 0; offset < keys.length; offset += DELETE_BATCH_SIZE) {
|
|
15178
|
+
const batch = keys.slice(offset, offset + DELETE_BATCH_SIZE);
|
|
15179
|
+
const response = await client.send(new _aws_sdk_client_s3.DeleteObjectsCommand({
|
|
15180
|
+
Bucket: bucketName,
|
|
15181
|
+
Delete: {
|
|
15182
|
+
Objects: batch.map((Key) => ({ Key })),
|
|
15183
|
+
Quiet: true
|
|
15184
|
+
}
|
|
15185
|
+
}));
|
|
15186
|
+
if (response.Errors && response.Errors.length > 0) throw new Error(`Failed to delete ${response.Errors.length} S3 object(s) from bucket "${bucketName}".`);
|
|
15187
|
+
}
|
|
14490
15188
|
}
|
|
14491
15189
|
});
|
|
15190
|
+
};
|
|
15191
|
+
//#endregion
|
|
15192
|
+
//#region src/s3Storage.ts
|
|
15193
|
+
function s3Storage(config) {
|
|
15194
|
+
const { bucketName, basePath, getDownloadUrl, credentials, ...s3Config } = config;
|
|
15195
|
+
return createS3Storage({
|
|
15196
|
+
name: "s3Storage",
|
|
15197
|
+
protocol: "s3"
|
|
15198
|
+
}, {
|
|
15199
|
+
...applyS3RuntimeAwsConfig(s3Config),
|
|
15200
|
+
credentials,
|
|
15201
|
+
bucketName,
|
|
15202
|
+
basePath,
|
|
15203
|
+
getDownloadUrl
|
|
15204
|
+
});
|
|
14492
15205
|
}
|
|
14493
15206
|
//#endregion
|
|
14494
15207
|
//#region lambda/index.ts
|