@hot-updater/aws 1.2.0-rc.4 → 1.2.0-rc.40
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 +960 -230
- 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.40";
|
|
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. */
|
|
@@ -5803,8 +6203,10 @@ const deleteBundle = async (tx, current) => {
|
|
|
5803
6203
|
/**
|
|
5804
6204
|
* Replaces a bundle's patches with `rows`: kept patches are updated where
|
|
5805
6205
|
* they changed, others deleted or created, so no key is written twice.
|
|
6206
|
+
* `checkNew` sees each patch it is about to create, and refuses one by
|
|
6207
|
+
* throwing, which leaves the transaction's writes undone.
|
|
5806
6208
|
*/
|
|
5807
|
-
const replaceBundlePatches = async (tx, bundle, rows) => {
|
|
6209
|
+
const replaceBundlePatches = async (tx, bundle, rows, checkNew) => {
|
|
5808
6210
|
const wanted = new Map(rows.map((row) => [row.id, row]));
|
|
5809
6211
|
const count = bundle._refs_bundle_patches_bundle_id ?? 0;
|
|
5810
6212
|
let cursor;
|
|
@@ -5829,6 +6231,7 @@ const replaceBundlePatches = async (tx, bundle, rows) => {
|
|
|
5829
6231
|
if (page.next === void 0) break;
|
|
5830
6232
|
cursor = page.next;
|
|
5831
6233
|
}
|
|
6234
|
+
if (checkNew !== void 0) for (const row of wanted.values()) await checkNew(row);
|
|
5832
6235
|
for (const row of wanted.values()) tx.create("bundle_patches", row);
|
|
5833
6236
|
};
|
|
5834
6237
|
/** A channel by name, created when missing; a concurrent creator's row is returned instead. */
|
|
@@ -5891,6 +6294,13 @@ const GIT_COMMIT_HASH_MAX_LENGTH = 255;
|
|
|
5891
6294
|
* and looks up nothing else.
|
|
5892
6295
|
*/
|
|
5893
6296
|
const BUILD_KEY = /^nbk1:[0-9a-f]{64}$/;
|
|
6297
|
+
/** `native_builds.sandbox_url_scheme`'s bound in core's schema. */
|
|
6298
|
+
const SANDBOX_URL_SCHEME_MAX_LENGTH = 255;
|
|
6299
|
+
/**
|
|
6300
|
+
* A URL scheme as RFC 3986 spells it, in lower case: what a sandbox build's
|
|
6301
|
+
* artifact registers, as `@hot-updater/protocol/native-artifact` reads it.
|
|
6302
|
+
*/
|
|
6303
|
+
const URL_SCHEME = new RegExp(`^[a-z][a-z0-9+.-]{0,254}$`);
|
|
5894
6304
|
/** A native build or scope core cannot store or look up: the caller's input. */
|
|
5895
6305
|
var NativeBuildInputError = class extends TypeError {
|
|
5896
6306
|
name = "NativeBuildInputError";
|
|
@@ -5912,13 +6322,33 @@ const pick = (row) => ({
|
|
|
5912
6322
|
build_number: row.build_number ?? null,
|
|
5913
6323
|
submitted_to: row.submitted_to ?? null,
|
|
5914
6324
|
submitted_at_ms: row.submitted_at_ms ?? null,
|
|
5915
|
-
submitted_version: row.submitted_version ?? null
|
|
6325
|
+
submitted_version: row.submitted_version ?? null,
|
|
6326
|
+
is_store_build: row.is_store_build === true,
|
|
6327
|
+
is_sandbox: row.is_sandbox === true,
|
|
6328
|
+
sandbox_url_scheme: row.sandbox_url_scheme ?? null,
|
|
6329
|
+
export_method: row.export_method ?? null,
|
|
6330
|
+
native_app_version: row.native_app_version ?? null
|
|
5916
6331
|
});
|
|
5917
|
-
/** The
|
|
5918
|
-
const
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
6332
|
+
/** The export methods an `.ipa` registers with. */
|
|
6333
|
+
const EXPORT_METHODS = /* @__PURE__ */ new Set([
|
|
6334
|
+
"app-store",
|
|
6335
|
+
"ad-hoc",
|
|
6336
|
+
"development",
|
|
6337
|
+
"enterprise"
|
|
6338
|
+
]);
|
|
6339
|
+
/**
|
|
6340
|
+
* The channels only sandbox builds register on: a registration's `sandbox`
|
|
6341
|
+
* must agree with it. The registry's convention, as
|
|
6342
|
+
* `@hot-updater/protocol/native-artifact` checks it for a build's artifact.
|
|
6343
|
+
*/
|
|
6344
|
+
const SANDBOX_CHANNEL_PREFIX = "sandbox-";
|
|
6345
|
+
/**
|
|
6346
|
+
* How many older builds of a scope one read takes, looking for one older than
|
|
6347
|
+
* a bundle when a build made after the bundle is the newest.
|
|
6348
|
+
*/
|
|
6349
|
+
const OLDER_BUILDS_PAGE = 20;
|
|
6350
|
+
/** How many times a mark runs again after losing its scope's mark to another. */
|
|
6351
|
+
const MARK_ATTEMPTS = 8;
|
|
5922
6352
|
/** `native_builds.build_number`'s bound in core's schema. */
|
|
5923
6353
|
const BUILD_NUMBER_MAX_LENGTH = 64;
|
|
5924
6354
|
/** `native_builds.submitted_version`'s bound in core's schema. */
|
|
@@ -5949,19 +6379,40 @@ const nativeBuildScopeKey = (scope) => {
|
|
|
5949
6379
|
if (scopeKey.length > SCOPE_KEY_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build scope: its key is longer than ${SCOPE_KEY_MAX_LENGTH} characters; shorten the channel or app version.`);
|
|
5950
6380
|
return scopeKey;
|
|
5951
6381
|
};
|
|
6382
|
+
/**
|
|
6383
|
+
* Refuses a patch from a sandbox build's built-in bundle: no deploy patches
|
|
6384
|
+
* from one, so no store or test install of the app gets a patch made for a
|
|
6385
|
+
* sandbox build. One unique read of the base.
|
|
6386
|
+
*/
|
|
6387
|
+
const refuseSandboxPatchBase = async (db, baseBundleId) => {
|
|
6388
|
+
if ((await db.findOne("native_builds", { min_bundle_id: baseBundleId }))?.is_sandbox === true) throw new NativeBuildInputError("A sandbox build's built-in bundle is no patch base.");
|
|
6389
|
+
};
|
|
5952
6390
|
/** Whether `bundleId` is a native build's built-in bundle: one unique read. */
|
|
5953
6391
|
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 }) => {
|
|
6392
|
+
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, nativeAppVersion, artifact }) => {
|
|
5955
6393
|
if (!isUUIDv7(id)) return "id must be a UUIDv7";
|
|
5956
6394
|
if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
|
|
5957
6395
|
if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
|
|
5958
6396
|
if (channel.trim().length === 0) return "channel is required";
|
|
6397
|
+
if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
|
|
6398
|
+
const reserved = channel.startsWith(SANDBOX_CHANNEL_PREFIX);
|
|
6399
|
+
if (isSandbox === true && !reserved) return `a sandbox build registers on a ${SANDBOX_CHANNEL_PREFIX}* channel, not ${channel}`;
|
|
6400
|
+
if (isSandbox !== true && reserved) return `channel ${channel} is reserved for sandbox builds`;
|
|
6401
|
+
if (sandboxUrlScheme !== void 0 && sandboxUrlScheme !== null) {
|
|
6402
|
+
if (isSandbox !== true) return "sandboxUrlScheme is a sandbox build's, and this isn't one";
|
|
6403
|
+
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`;
|
|
6404
|
+
}
|
|
5959
6405
|
if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
|
|
5960
6406
|
if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
|
|
5961
6407
|
if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
|
|
5962
6408
|
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`;
|
|
6409
|
+
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
6410
|
const kinds = ARTIFACT_KINDS[platform];
|
|
5964
6411
|
if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
|
|
6412
|
+
if (exportMethod !== void 0 && exportMethod !== null) {
|
|
6413
|
+
if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
|
|
6414
|
+
if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
|
|
6415
|
+
}
|
|
5965
6416
|
if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
|
|
5966
6417
|
return null;
|
|
5967
6418
|
};
|
|
@@ -5990,7 +6441,12 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
5990
6441
|
build_number: registration.buildNumber ?? null,
|
|
5991
6442
|
submitted_to: null,
|
|
5992
6443
|
submitted_at_ms: null,
|
|
5993
|
-
submitted_version: null
|
|
6444
|
+
submitted_version: null,
|
|
6445
|
+
is_store_build: false,
|
|
6446
|
+
is_sandbox: registration.isSandbox === true,
|
|
6447
|
+
sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
|
|
6448
|
+
export_method: registration.exportMethod ?? null,
|
|
6449
|
+
native_app_version: registration.nativeAppVersion ?? null
|
|
5994
6450
|
};
|
|
5995
6451
|
for (let attempt = 1;; attempt += 1) {
|
|
5996
6452
|
await insertChannel(db, {
|
|
@@ -6028,21 +6484,43 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
6028
6484
|
const scopeKey = nativeBuildScopeKey(scope);
|
|
6029
6485
|
const buildKey = options?.buildKey;
|
|
6030
6486
|
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
|
-
|
|
6487
|
+
if (options?.storeBuild) {
|
|
6488
|
+
const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
|
|
6489
|
+
return marked === null ? null : pick(marked);
|
|
6490
|
+
}
|
|
6491
|
+
const read = (limit, before) => {
|
|
6492
|
+
const page = {
|
|
6493
|
+
order: "desc",
|
|
6494
|
+
limit,
|
|
6495
|
+
...before === void 0 ? {} : { range: { lt: before } }
|
|
6496
|
+
};
|
|
6497
|
+
return buildKey === void 0 ? db.findMany("native_builds", {
|
|
6498
|
+
index: "byScope",
|
|
6499
|
+
where: { scope_key: scopeKey },
|
|
6500
|
+
...page
|
|
6501
|
+
}) : db.findMany("native_builds", {
|
|
6502
|
+
index: "byBuildKey",
|
|
6503
|
+
where: {
|
|
6504
|
+
scope_key: scopeKey,
|
|
6505
|
+
build_key: buildKey
|
|
6506
|
+
},
|
|
6507
|
+
...page
|
|
6508
|
+
});
|
|
6509
|
+
};
|
|
6510
|
+
const bundleId = options?.builtInOlderThan;
|
|
6511
|
+
if (bundleId !== void 0 && scope.channel.startsWith(SANDBOX_CHANNEL_PREFIX)) return null;
|
|
6512
|
+
const { rows } = await read(1);
|
|
6513
|
+
const newest = rows[0];
|
|
6514
|
+
if (newest === void 0) return null;
|
|
6515
|
+
if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
|
|
6516
|
+
for (let before = newest.id;;) {
|
|
6517
|
+
const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
|
|
6518
|
+
const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
|
|
6519
|
+
if (usable !== void 0) return pick(usable);
|
|
6520
|
+
const last = older.at(-1);
|
|
6521
|
+
if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
|
|
6522
|
+
before = last.id;
|
|
6523
|
+
}
|
|
6046
6524
|
},
|
|
6047
6525
|
async recordNativeBuildSubmission(id, { destination, version }) {
|
|
6048
6526
|
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 +6528,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
6050
6528
|
const row = await tx.findOne("native_builds", { id });
|
|
6051
6529
|
if (row === null) return null;
|
|
6052
6530
|
const build = pick(row);
|
|
6053
|
-
if (
|
|
6531
|
+
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}.`);
|
|
6532
|
+
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
6533
|
const set = {
|
|
6055
6534
|
submitted_to: destination,
|
|
6056
6535
|
submitted_at_ms: now(),
|
|
@@ -6063,6 +6542,46 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
6063
6542
|
};
|
|
6064
6543
|
});
|
|
6065
6544
|
},
|
|
6545
|
+
async markNativeBuild(id, { storeBuild }) {
|
|
6546
|
+
for (let attempt = 1;; attempt += 1) try {
|
|
6547
|
+
return await db.transaction(async (tx) => {
|
|
6548
|
+
const row = await tx.findOne("native_builds", { id });
|
|
6549
|
+
if (row === null) return null;
|
|
6550
|
+
const build = pick(row);
|
|
6551
|
+
if (!storeBuild) {
|
|
6552
|
+
if (build.is_store_build) tx.update("native_builds", row, { is_store_build: false });
|
|
6553
|
+
return {
|
|
6554
|
+
nativeBuild: {
|
|
6555
|
+
...build,
|
|
6556
|
+
is_store_build: false
|
|
6557
|
+
},
|
|
6558
|
+
previous: null
|
|
6559
|
+
};
|
|
6560
|
+
}
|
|
6561
|
+
if (build.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
|
|
6562
|
+
if (build.is_store_build) return {
|
|
6563
|
+
nativeBuild: build,
|
|
6564
|
+
previous: null
|
|
6565
|
+
};
|
|
6566
|
+
const holder = await tx.findOne("native_builds", { store_build_scope_key: build.scope_key });
|
|
6567
|
+
if (holder !== null) tx.update("native_builds", holder, { is_store_build: false });
|
|
6568
|
+
tx.update("native_builds", row, { is_store_build: true });
|
|
6569
|
+
return {
|
|
6570
|
+
nativeBuild: {
|
|
6571
|
+
...build,
|
|
6572
|
+
is_store_build: true
|
|
6573
|
+
},
|
|
6574
|
+
previous: holder === null ? null : {
|
|
6575
|
+
...pick(holder),
|
|
6576
|
+
is_store_build: false
|
|
6577
|
+
}
|
|
6578
|
+
};
|
|
6579
|
+
});
|
|
6580
|
+
} catch (error) {
|
|
6581
|
+
if (attempt < MARK_ATTEMPTS && error instanceof DatabaseConstraintError && error.reason === "unique") continue;
|
|
6582
|
+
throw error;
|
|
6583
|
+
}
|
|
6584
|
+
},
|
|
6066
6585
|
async deleteNativeBuild(id) {
|
|
6067
6586
|
return db.transaction(async (tx) => {
|
|
6068
6587
|
const row = await tx.findOne("native_builds", { id });
|
|
@@ -6409,7 +6928,11 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
6409
6928
|
for (const { release } of deployments) if (!channels.has(release.channel)) channels.set(release.channel, await ensureChannel(release.channel));
|
|
6410
6929
|
const platforms = /* @__PURE__ */ new Map();
|
|
6411
6930
|
for (const deployment of deployments) {
|
|
6412
|
-
if (!("bundleId" in deployment)
|
|
6931
|
+
if (!("bundleId" in deployment)) {
|
|
6932
|
+
for (const { baseBundleId } of deployment.bundle.patches ?? []) await refuseSandboxPatchBase(db, baseBundleId);
|
|
6933
|
+
continue;
|
|
6934
|
+
}
|
|
6935
|
+
if (platforms.has(deployment.bundleId)) continue;
|
|
6413
6936
|
const row = await db.findOne("bundles", { id: deployment.bundleId });
|
|
6414
6937
|
if (row === null) throw new DatabaseBundleNotFoundError(deployment.bundleId);
|
|
6415
6938
|
if (await isBuiltInBundle(db, deployment.bundleId)) throw new ReleaseManagementError("TARGET_RELEASE_INVALID", `Bundle "${deployment.bundleId}" is a native build's built-in bundle, which no release publishes.`);
|
|
@@ -6613,7 +7136,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
6613
7136
|
if (patches !== void 0) await replaceBundlePatches(tx, current, bundleToPatchRows({
|
|
6614
7137
|
...next,
|
|
6615
7138
|
patches
|
|
6616
|
-
}));
|
|
7139
|
+
}), (row) => refuseSandboxPatchBase(tx, row.base_bundle_id));
|
|
6617
7140
|
}),
|
|
6618
7141
|
deleteBundles: async (ids) => {
|
|
6619
7142
|
try {
|
|
@@ -6675,6 +7198,7 @@ const createCoreApi = (db, storage, options = {}) => {
|
|
|
6675
7198
|
...reads,
|
|
6676
7199
|
...createCoreOperations(purgingCachedRoutes(db, options.onCachedRoutesChange), options),
|
|
6677
7200
|
...createNativeBuildApi(db, options),
|
|
7201
|
+
...createIosDeviceApi(db, options),
|
|
6678
7202
|
/** One read, which checks the schema settings first. */
|
|
6679
7203
|
ready: async () => {
|
|
6680
7204
|
await reads.listReleaseCatalogs({ limit: 1 });
|
|
@@ -6894,10 +7418,12 @@ const keyset = (url, maxValue = LIMITS.maxValue) => {
|
|
|
6894
7418
|
const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
|
|
6895
7419
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
|
|
6896
7420
|
const cursor = url.searchParams.get("cursor");
|
|
7421
|
+
const through = url.searchParams.get("through");
|
|
6897
7422
|
return {
|
|
6898
7423
|
order,
|
|
6899
7424
|
limit,
|
|
6900
|
-
...cursor === null ? {} : { after: cursor }
|
|
7425
|
+
...cursor === null ? {} : { after: cursor },
|
|
7426
|
+
...through === null ? {} : { through }
|
|
6901
7427
|
};
|
|
6902
7428
|
};
|
|
6903
7429
|
/** A page and the cursor of the next one, when the page is full. */
|
|
@@ -7012,11 +7538,11 @@ const refusingInvalid = async (operation) => {
|
|
|
7012
7538
|
try {
|
|
7013
7539
|
return await operation();
|
|
7014
7540
|
} catch (error) {
|
|
7015
|
-
if (error instanceof NativeBuildInputError) throw new HandlerBadRequestError(error.message);
|
|
7541
|
+
if (error instanceof NativeBuildInputError || error instanceof IosDeviceInputError) throw new HandlerBadRequestError(error.message);
|
|
7016
7542
|
throw error;
|
|
7017
7543
|
}
|
|
7018
7544
|
};
|
|
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));
|
|
7545
|
+
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
7546
|
const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
|
|
7021
7547
|
/** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
|
|
7022
7548
|
const createAdminRouteHandlers = () => ({
|
|
@@ -7098,7 +7624,8 @@ const createAdminRouteHandlers = () => ({
|
|
|
7098
7624
|
rebuildReleaseCatalog: onCore(async (core, _request, params) => json$2({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
|
|
7099
7625
|
updateBundle: onCore(async (core, request, params) => {
|
|
7100
7626
|
const bundleId = requireRouteParam(params, "id");
|
|
7101
|
-
|
|
7627
|
+
const update = bundleUpdateOf(await request.json(), bundleId);
|
|
7628
|
+
await refusingInvalid(() => core.updateBundle(bundleId, update));
|
|
7102
7629
|
return noContent();
|
|
7103
7630
|
}),
|
|
7104
7631
|
countBundles: onCore(async (core, request) => json$2({ data: await core.countBundles(platformOf(new URL(request.url))) })),
|
|
@@ -7122,7 +7649,7 @@ const createAdminRouteHandlers = () => ({
|
|
|
7122
7649
|
deployReleases: onCore(async (core, request) => {
|
|
7123
7650
|
const { deployments } = await body(request);
|
|
7124
7651
|
if (!Array.isArray(deployments) || deployments.length === 0 || !deployments.every(isDeployment)) throw new HandlerBadRequestError("Deploy needs deployments, each a bundle and its release policy.");
|
|
7125
|
-
return json$2({ data: await core.deploy(deployments) }, 201);
|
|
7652
|
+
return json$2({ data: await refusingInvalid(() => core.deploy(deployments)) }, 201);
|
|
7126
7653
|
}),
|
|
7127
7654
|
promoteRelease: onCore(async (core, request, params) => {
|
|
7128
7655
|
const input = await body(request);
|
|
@@ -7145,7 +7672,13 @@ const createAdminRouteHandlers = () => ({
|
|
|
7145
7672
|
const url = new URL(request.url);
|
|
7146
7673
|
const scope = nativeBuildScopeOf(url);
|
|
7147
7674
|
const buildKey = url.searchParams.get("buildKey");
|
|
7148
|
-
|
|
7675
|
+
const builtInOlderThan = url.searchParams.get("builtInOlderThan");
|
|
7676
|
+
const options = {
|
|
7677
|
+
...buildKey === null ? {} : { buildKey },
|
|
7678
|
+
...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
|
|
7679
|
+
...builtInOlderThan === null ? {} : { builtInOlderThan }
|
|
7680
|
+
};
|
|
7681
|
+
return json$2({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
|
|
7149
7682
|
}),
|
|
7150
7683
|
getNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
|
|
7151
7684
|
listNativeBuilds: onCore(async (core, request) => {
|
|
@@ -7159,14 +7692,95 @@ const createAdminRouteHandlers = () => ({
|
|
|
7159
7692
|
}),
|
|
7160
7693
|
recordNativeBuildSubmission: onCore(async (core, request, params) => {
|
|
7161
7694
|
const input = await body(request);
|
|
7162
|
-
if (!isRecord$5(input) ||
|
|
7695
|
+
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
7696
|
const submission = {
|
|
7164
7697
|
destination: input.destination,
|
|
7165
7698
|
version: input.version
|
|
7166
7699
|
};
|
|
7167
7700
|
return json$2({ data: await refusingInvalid(() => core.recordNativeBuildSubmission(requireRouteParam(params, "id"), submission)) });
|
|
7168
7701
|
}),
|
|
7702
|
+
markNativeBuild: onCore(async (core, request, params) => {
|
|
7703
|
+
const input = await body(request);
|
|
7704
|
+
if (!isRecord$5(input) || typeof input.storeBuild !== "boolean") throw new HandlerBadRequestError("A native build's store build mark needs storeBuild, true or false.");
|
|
7705
|
+
const mark = { storeBuild: input.storeBuild };
|
|
7706
|
+
return json$2({ data: await refusingInvalid(() => core.markNativeBuild(requireRouteParam(params, "id"), mark)) });
|
|
7707
|
+
}),
|
|
7169
7708
|
deleteNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.deleteNativeBuild(requireRouteParam(params, "id")) })),
|
|
7709
|
+
listIosDevices: onCore(async (core, request) => {
|
|
7710
|
+
const url = new URL(request.url);
|
|
7711
|
+
const input = keyset(url);
|
|
7712
|
+
const status = url.searchParams.get("status");
|
|
7713
|
+
return page(await refusingInvalid(() => core.listIosDevices({
|
|
7714
|
+
...input,
|
|
7715
|
+
...status === null ? {} : { status }
|
|
7716
|
+
})), input, ({ id }) => id);
|
|
7717
|
+
}),
|
|
7718
|
+
findIosDevice: onCore(async (core, _request, params) => json$2({ data: await core.findIosDevice(requireRouteParam(params, "udid")) })),
|
|
7719
|
+
requestIosDevice: onCore(async (core, request) => {
|
|
7720
|
+
const input = await body(request);
|
|
7721
|
+
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.");
|
|
7722
|
+
const device = {
|
|
7723
|
+
udid: input.udid,
|
|
7724
|
+
name: input.name,
|
|
7725
|
+
requestedBy: input.requestedBy
|
|
7726
|
+
};
|
|
7727
|
+
return json$2({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
|
|
7728
|
+
}),
|
|
7729
|
+
approveIosDevice: onCore(async (core, request, params) => {
|
|
7730
|
+
const input = await body(request);
|
|
7731
|
+
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.");
|
|
7732
|
+
const approval = {
|
|
7733
|
+
approvedBy: input.approvedBy,
|
|
7734
|
+
...input.name === void 0 ? {} : { name: input.name }
|
|
7735
|
+
};
|
|
7736
|
+
return json$2({ data: await refusingInvalid(() => core.approveIosDevice(requireRouteParam(params, "id"), approval)) });
|
|
7737
|
+
}),
|
|
7738
|
+
renameIosDevice: onCore(async (core, request, params) => {
|
|
7739
|
+
const input = await body(request);
|
|
7740
|
+
if (!isText$2(input.name)) throw new HandlerBadRequestError("An iOS device's new name is required.");
|
|
7741
|
+
const name = input.name;
|
|
7742
|
+
return json$2({ data: await refusingInvalid(() => core.renameIosDevice(requireRouteParam(params, "id"), name)) });
|
|
7743
|
+
}),
|
|
7744
|
+
recordIosDeviceOutcome: onCore(async (core, request, params) => {
|
|
7745
|
+
const input = await body(request);
|
|
7746
|
+
const seen = input.seen;
|
|
7747
|
+
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.");
|
|
7748
|
+
const outcome = {
|
|
7749
|
+
id: requireRouteParam(params, "id"),
|
|
7750
|
+
seen: {
|
|
7751
|
+
status: seen.status,
|
|
7752
|
+
approvedAtMs: seen.approvedAtMs
|
|
7753
|
+
},
|
|
7754
|
+
issuerId: input.issuerId,
|
|
7755
|
+
outcome: input.outcome,
|
|
7756
|
+
...input.reason === void 0 ? {} : { reason: input.reason }
|
|
7757
|
+
};
|
|
7758
|
+
return json$2({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
|
|
7759
|
+
}),
|
|
7760
|
+
claimIosDeviceAccount: onCore(async (core, request) => {
|
|
7761
|
+
const { issuerId } = await body(request);
|
|
7762
|
+
if (!isText$2(issuerId)) throw new HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
|
|
7763
|
+
return json$2({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
|
|
7764
|
+
}),
|
|
7765
|
+
markIosDevicesInBuild: onCore(async (core, request) => {
|
|
7766
|
+
const { buildId, ids } = await body(request);
|
|
7767
|
+
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.");
|
|
7768
|
+
await core.markIosDevicesInBuild({
|
|
7769
|
+
buildId,
|
|
7770
|
+
ids
|
|
7771
|
+
});
|
|
7772
|
+
return noContent();
|
|
7773
|
+
}),
|
|
7774
|
+
deleteIosDevice: onCore(async (core, request, params) => {
|
|
7775
|
+
const url = new URL(request.url);
|
|
7776
|
+
const status = url.searchParams.get("status");
|
|
7777
|
+
const requestedBy = url.searchParams.get("requestedBy");
|
|
7778
|
+
const only = {
|
|
7779
|
+
...status === null ? {} : { status },
|
|
7780
|
+
...requestedBy === null ? {} : { requestedBy }
|
|
7781
|
+
};
|
|
7782
|
+
return json$2({ data: await refusingInvalid(() => Object.keys(only).length === 0 ? core.deleteIosDevice(requireRouteParam(params, "id")) : core.deleteIosDevice(requireRouteParam(params, "id"), only)) });
|
|
7783
|
+
}),
|
|
7170
7784
|
deleteBundles: onCore(async (core, request) => {
|
|
7171
7785
|
const { ids } = await body(request);
|
|
7172
7786
|
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new HandlerBadRequestError("Bundle deletion needs ids");
|
|
@@ -7311,10 +7925,60 @@ const ADMIN_ROUTES = [
|
|
|
7311
7925
|
path: "/native-builds/:id/submission",
|
|
7312
7926
|
handler: "recordNativeBuildSubmission"
|
|
7313
7927
|
},
|
|
7928
|
+
{
|
|
7929
|
+
method: "POST",
|
|
7930
|
+
path: "/native-builds/:id/store-build",
|
|
7931
|
+
handler: "markNativeBuild"
|
|
7932
|
+
},
|
|
7314
7933
|
{
|
|
7315
7934
|
method: "DELETE",
|
|
7316
7935
|
path: "/native-builds/:id",
|
|
7317
7936
|
handler: "deleteNativeBuild"
|
|
7937
|
+
},
|
|
7938
|
+
{
|
|
7939
|
+
method: "GET",
|
|
7940
|
+
path: "/ios-devices",
|
|
7941
|
+
handler: "listIosDevices"
|
|
7942
|
+
},
|
|
7943
|
+
{
|
|
7944
|
+
method: "POST",
|
|
7945
|
+
path: "/ios-devices",
|
|
7946
|
+
handler: "requestIosDevice"
|
|
7947
|
+
},
|
|
7948
|
+
{
|
|
7949
|
+
method: "GET",
|
|
7950
|
+
path: "/ios-devices/udid/:udid",
|
|
7951
|
+
handler: "findIosDevice"
|
|
7952
|
+
},
|
|
7953
|
+
{
|
|
7954
|
+
method: "POST",
|
|
7955
|
+
path: "/ios-devices/in-build",
|
|
7956
|
+
handler: "markIosDevicesInBuild"
|
|
7957
|
+
},
|
|
7958
|
+
{
|
|
7959
|
+
method: "POST",
|
|
7960
|
+
path: "/ios-devices/account",
|
|
7961
|
+
handler: "claimIosDeviceAccount"
|
|
7962
|
+
},
|
|
7963
|
+
{
|
|
7964
|
+
method: "POST",
|
|
7965
|
+
path: "/ios-devices/:id/approval",
|
|
7966
|
+
handler: "approveIosDevice"
|
|
7967
|
+
},
|
|
7968
|
+
{
|
|
7969
|
+
method: "POST",
|
|
7970
|
+
path: "/ios-devices/:id/outcome",
|
|
7971
|
+
handler: "recordIosDeviceOutcome"
|
|
7972
|
+
},
|
|
7973
|
+
{
|
|
7974
|
+
method: "PATCH",
|
|
7975
|
+
path: "/ios-devices/:id",
|
|
7976
|
+
handler: "renameIosDevice"
|
|
7977
|
+
},
|
|
7978
|
+
{
|
|
7979
|
+
method: "DELETE",
|
|
7980
|
+
path: "/ios-devices/:id",
|
|
7981
|
+
handler: "deleteIosDevice"
|
|
7318
7982
|
}
|
|
7319
7983
|
];
|
|
7320
7984
|
//#endregion
|
|
@@ -14295,10 +14959,30 @@ async apply() {
|
|
|
14295
14959
|
};
|
|
14296
14960
|
};
|
|
14297
14961
|
//#endregion
|
|
14962
|
+
//#region src/lazyCredentials.ts
|
|
14963
|
+
/**
|
|
14964
|
+
* `credentials` as the AWS SDK takes them: access keys with a lazy field
|
|
14965
|
+
* become a provider, which the SDK calls once, on its first request.
|
|
14966
|
+
*/
|
|
14967
|
+
const toSdkCredentials$1 = (credentials) => {
|
|
14968
|
+
if (credentials === void 0 || typeof credentials === "function") return credentials;
|
|
14969
|
+
const { accessKeyId, secretAccessKey, sessionToken, ...rest } = credentials;
|
|
14970
|
+
if (typeof accessKeyId !== "function" && typeof secretAccessKey !== "function" && typeof sessionToken !== "function") return credentials;
|
|
14971
|
+
return async () => ({
|
|
14972
|
+
...rest,
|
|
14973
|
+
accessKeyId: await resolveLazy(accessKeyId),
|
|
14974
|
+
secretAccessKey: await resolveLazy(secretAccessKey),
|
|
14975
|
+
...sessionToken === void 0 ? {} : { sessionToken: await resolveLazy(sessionToken) }
|
|
14976
|
+
});
|
|
14977
|
+
};
|
|
14978
|
+
//#endregion
|
|
14298
14979
|
//#region src/dynamoDB.ts
|
|
14299
14980
|
/** The DynamoDB client ignores the CloudFront and batching settings. */
|
|
14300
|
-
const adapterOf = ({ tableName, ...clientConfig }) => {
|
|
14301
|
-
const client = new _aws_sdk_client_dynamodb.DynamoDBClient(
|
|
14981
|
+
const adapterOf = ({ tableName, credentials, ...clientConfig }) => {
|
|
14982
|
+
const client = new _aws_sdk_client_dynamodb.DynamoDBClient({
|
|
14983
|
+
...clientConfig,
|
|
14984
|
+
credentials: toSdkCredentials$1(credentials)
|
|
14985
|
+
});
|
|
14302
14986
|
const store = createDynamoDBStore({
|
|
14303
14987
|
client,
|
|
14304
14988
|
tableName
|
|
@@ -14323,7 +15007,10 @@ const marked = (target) => ({ [DATABASE_TARGET]: target });
|
|
|
14323
15007
|
*/
|
|
14324
15008
|
const dynamoDB = (config) => {
|
|
14325
15009
|
const { client, adapter } = adapterOf(config);
|
|
14326
|
-
const cloudFront = createUpdateRouteInvalidation(
|
|
15010
|
+
const cloudFront = createUpdateRouteInvalidation({
|
|
15011
|
+
...config,
|
|
15012
|
+
credentials: toSdkCredentials$1(config.credentials)
|
|
15013
|
+
});
|
|
14327
15014
|
return {
|
|
14328
15015
|
...createEngineDatabase({
|
|
14329
15016
|
name: "dynamoDB",
|
|
@@ -14340,18 +15027,49 @@ const dynamoDB = (config) => {
|
|
|
14340
15027
|
};
|
|
14341
15028
|
};
|
|
14342
15029
|
//#endregion
|
|
14343
|
-
//#region
|
|
15030
|
+
//#region ../storage-s3/dist/index.mjs
|
|
15031
|
+
/**
|
|
15032
|
+
* `credentials` as the AWS SDK takes them: access keys with a lazy field
|
|
15033
|
+
* become a provider, which the SDK calls once, on its first request.
|
|
15034
|
+
*/
|
|
15035
|
+
const toSdkCredentials = (credentials) => {
|
|
15036
|
+
if (credentials === void 0 || typeof credentials === "function") return credentials;
|
|
15037
|
+
const { accessKeyId, secretAccessKey, sessionToken, ...rest } = credentials;
|
|
15038
|
+
if (typeof accessKeyId !== "function" && typeof secretAccessKey !== "function" && typeof sessionToken !== "function") return credentials;
|
|
15039
|
+
return async () => ({
|
|
15040
|
+
...rest,
|
|
15041
|
+
accessKeyId: await resolveLazy(accessKeyId),
|
|
15042
|
+
secretAccessKey: await resolveLazy(secretAccessKey),
|
|
15043
|
+
...sessionToken === void 0 ? {} : { sessionToken: await resolveLazy(sessionToken) }
|
|
15044
|
+
});
|
|
15045
|
+
};
|
|
14344
15046
|
/** Devices download right after the update check that returns the URL. */
|
|
14345
|
-
const
|
|
14346
|
-
|
|
14347
|
-
|
|
14348
|
-
|
|
14349
|
-
|
|
14350
|
-
|
|
15047
|
+
const DEFAULT_SIGNED_LIFETIME_SECONDS = 3600;
|
|
15048
|
+
/** SigV4's limit on a presigned URL. */
|
|
15049
|
+
const MAX_SIGNED_LIFETIME_SECONDS = 604800;
|
|
15050
|
+
/** DeleteObjects takes at most 1000 keys a request. */
|
|
15051
|
+
const DELETE_BATCH_SIZE = 1e3;
|
|
15052
|
+
const isObjectNotFoundError = (error) => {
|
|
15053
|
+
if (error instanceof Error && (error.name === "NotFound" || error.name === "NoSuchKey")) return true;
|
|
15054
|
+
return typeof error === "object" && error !== null && "$metadata" in error && error.$metadata?.httpStatusCode === 404;
|
|
15055
|
+
};
|
|
15056
|
+
const trimSlashes = (value) => value.replace(/^\/+|\/+$/g, "");
|
|
15057
|
+
/**
|
|
15058
|
+
* A storage adapter over a bucket's S3 API, which AWS S3, Cloudflare R2, and
|
|
15059
|
+
* Neon Object Storage all serve. Each provider package passes its own name,
|
|
15060
|
+
* URI protocol, and client defaults.
|
|
15061
|
+
*/
|
|
15062
|
+
const createS3Storage = ({ name, protocol }, config) => {
|
|
15063
|
+
const { bucketName, basePath, getDownloadUrl, signedUrlExpiresIn = DEFAULT_SIGNED_LIFETIME_SECONDS, credentials, ...clientConfig } = config;
|
|
15064
|
+
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).`);
|
|
15065
|
+
const client = new _aws_sdk_client_s3.S3Client({
|
|
15066
|
+
...clientConfig,
|
|
15067
|
+
credentials: toSdkCredentials(credentials)
|
|
15068
|
+
});
|
|
15069
|
+
const normalizedBasePath = trimSlashes(basePath ?? "");
|
|
14351
15070
|
const getStorageKey = createStorageKeyBuilder(normalizedBasePath);
|
|
14352
15071
|
const getListPrefix = (prefix = "") => {
|
|
14353
|
-
const
|
|
14354
|
-
const value = [normalizedBasePath, normalizedPrefix].filter(Boolean).join("/");
|
|
15072
|
+
const value = [normalizedBasePath, trimSlashes(prefix)].filter(Boolean).join("/");
|
|
14355
15073
|
return value ? `${value}/` : "";
|
|
14356
15074
|
};
|
|
14357
15075
|
/**
|
|
@@ -14363,7 +15081,7 @@ function s3Storage(config) {
|
|
|
14363
15081
|
return createStorageUri({
|
|
14364
15082
|
bucket: bucketName,
|
|
14365
15083
|
key,
|
|
14366
|
-
protocol
|
|
15084
|
+
protocol
|
|
14367
15085
|
});
|
|
14368
15086
|
} catch {
|
|
14369
15087
|
return null;
|
|
@@ -14375,55 +15093,16 @@ function s3Storage(config) {
|
|
|
14375
15093
|
return key.startsWith(basePrefix) ? key.slice(basePrefix.length) : key;
|
|
14376
15094
|
};
|
|
14377
15095
|
const parseAndValidate = (storageUri) => {
|
|
14378
|
-
const parsed = parseStorageUri(storageUri,
|
|
15096
|
+
const parsed = parseStorageUri(storageUri, protocol);
|
|
14379
15097
|
if (parsed.bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${parsed.bucket}".`);
|
|
14380
15098
|
return parsed;
|
|
14381
15099
|
};
|
|
14382
15100
|
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
|
-
},
|
|
15101
|
+
name,
|
|
15102
|
+
protocol,
|
|
14424
15103
|
async put({ key, body, contentLength, contentType }) {
|
|
14425
15104
|
const storageKey = getStorageKey(key);
|
|
14426
|
-
|
|
15105
|
+
await new _aws_sdk_lib_storage.Upload({
|
|
14427
15106
|
client,
|
|
14428
15107
|
params: {
|
|
14429
15108
|
Body: body,
|
|
@@ -14434,11 +15113,10 @@ function s3Storage(config) {
|
|
|
14434
15113
|
Key: storageKey
|
|
14435
15114
|
}
|
|
14436
15115
|
}).done();
|
|
14437
|
-
if (!response.Bucket || !response.Key) throw new Error("Upload failed");
|
|
14438
15116
|
return { storageUri: createStorageUri({
|
|
14439
15117
|
bucket: bucketName,
|
|
14440
15118
|
key: storageKey,
|
|
14441
|
-
protocol
|
|
15119
|
+
protocol
|
|
14442
15120
|
}) };
|
|
14443
15121
|
},
|
|
14444
15122
|
async get({ storageUri }) {
|
|
@@ -14461,11 +15139,10 @@ function s3Storage(config) {
|
|
|
14461
15139
|
async getDownloadUrl({ storageUri }) {
|
|
14462
15140
|
const { key } = parseAndValidate(storageUri);
|
|
14463
15141
|
if (getDownloadUrl) return getDownloadUrl({ storageUri });
|
|
14464
|
-
|
|
14465
|
-
return { url: await getSignedUrl(client, new _aws_sdk_client_s3.GetObjectCommand({
|
|
15142
|
+
return { url: await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(client, new _aws_sdk_client_s3.GetObjectCommand({
|
|
14466
15143
|
Bucket: bucketName,
|
|
14467
15144
|
Key: key
|
|
14468
|
-
}), { expiresIn:
|
|
15145
|
+
}), { expiresIn: signedUrlExpiresIn }) };
|
|
14469
15146
|
},
|
|
14470
15147
|
async exists({ storageUri }) {
|
|
14471
15148
|
const { key } = parseAndValidate(storageUri);
|
|
@@ -14487,8 +15164,61 @@ function s3Storage(config) {
|
|
|
14487
15164
|
Key: key
|
|
14488
15165
|
}));
|
|
14489
15166
|
return { deleted: true };
|
|
15167
|
+
},
|
|
15168
|
+
async listObjects(prefix) {
|
|
15169
|
+
const objects = [];
|
|
15170
|
+
let continuationToken;
|
|
15171
|
+
do {
|
|
15172
|
+
const response = await client.send(new _aws_sdk_client_s3.ListObjectsV2Command({
|
|
15173
|
+
Bucket: bucketName,
|
|
15174
|
+
ContinuationToken: continuationToken,
|
|
15175
|
+
Prefix: getListPrefix(prefix)
|
|
15176
|
+
}));
|
|
15177
|
+
for (const object of response.Contents ?? []) {
|
|
15178
|
+
if (!object.Key) continue;
|
|
15179
|
+
const storageUri = getListedStorageUri(object.Key);
|
|
15180
|
+
if (storageUri === null) continue;
|
|
15181
|
+
objects.push({
|
|
15182
|
+
key: getRelativeKey(object.Key),
|
|
15183
|
+
lastModifiedAt: object.LastModified,
|
|
15184
|
+
size: object.Size ?? 0,
|
|
15185
|
+
storageUri
|
|
15186
|
+
});
|
|
15187
|
+
}
|
|
15188
|
+
continuationToken = response.NextContinuationToken;
|
|
15189
|
+
} while (continuationToken);
|
|
15190
|
+
return objects;
|
|
15191
|
+
},
|
|
15192
|
+
async deleteObjects(relativeKeys) {
|
|
15193
|
+
const keys = relativeKeys.map((key) => getStorageKey(key));
|
|
15194
|
+
for (let offset = 0; offset < keys.length; offset += DELETE_BATCH_SIZE) {
|
|
15195
|
+
const batch = keys.slice(offset, offset + DELETE_BATCH_SIZE);
|
|
15196
|
+
const response = await client.send(new _aws_sdk_client_s3.DeleteObjectsCommand({
|
|
15197
|
+
Bucket: bucketName,
|
|
15198
|
+
Delete: {
|
|
15199
|
+
Objects: batch.map((Key) => ({ Key })),
|
|
15200
|
+
Quiet: true
|
|
15201
|
+
}
|
|
15202
|
+
}));
|
|
15203
|
+
if (response.Errors && response.Errors.length > 0) throw new Error(`Failed to delete ${response.Errors.length} S3 object(s) from bucket "${bucketName}".`);
|
|
15204
|
+
}
|
|
14490
15205
|
}
|
|
14491
15206
|
});
|
|
15207
|
+
};
|
|
15208
|
+
//#endregion
|
|
15209
|
+
//#region src/s3Storage.ts
|
|
15210
|
+
function s3Storage(config) {
|
|
15211
|
+
const { bucketName, basePath, getDownloadUrl, credentials, ...s3Config } = config;
|
|
15212
|
+
return createS3Storage({
|
|
15213
|
+
name: "s3Storage",
|
|
15214
|
+
protocol: "s3"
|
|
15215
|
+
}, {
|
|
15216
|
+
...applyS3RuntimeAwsConfig(s3Config),
|
|
15217
|
+
credentials,
|
|
15218
|
+
bucketName,
|
|
15219
|
+
basePath,
|
|
15220
|
+
getDownloadUrl
|
|
15221
|
+
});
|
|
14492
15222
|
}
|
|
14493
15223
|
//#endregion
|
|
14494
15224
|
//#region lambda/index.ts
|