@kaanbiryol/crate-server 0.0.0-stage → 0.17.9
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/LICENSE +21 -0
- package/README.md +73 -2
- package/THIRD_PARTY_NOTICES.md +3664 -0
- package/assets/coordinator.mjs +116 -0
- package/assets/credential-revocation.mjs +18 -0
- package/assets/database-upgrade-rules.mjs +42 -0
- package/assets/migrations/README.md +19 -0
- package/assets/qrcode.mjs +1638 -0
- package/assets/schema.sql +368 -0
- package/assets/server-release.json +6 -0
- package/assets/worker-runtime.json +12 -0
- package/assets/worker.mjs +1458 -0
- package/npm-shrinkwrap.json +939 -0
- package/package.json +38 -4
- package/scripts/assets.mjs +33 -0
- package/scripts/commands/data.mjs +80 -0
- package/scripts/commands/devices.mjs +100 -0
- package/scripts/commands/doctor.mjs +127 -0
- package/scripts/commands/service.mjs +19 -0
- package/scripts/commands/setup.mjs +194 -0
- package/scripts/commands/start.mjs +171 -0
- package/scripts/commands/status.mjs +49 -0
- package/scripts/commands/update.mjs +138 -0
- package/scripts/crate-server.mjs +11 -0
- package/scripts/deployment-fingerprint.mjs +13 -0
- package/scripts/local-server-alerts.mjs +53 -0
- package/scripts/local-server-backup-schedule.mjs +153 -0
- package/scripts/local-server-backup.mjs +275 -0
- package/scripts/local-server-cloudflared.mjs +93 -0
- package/scripts/local-server-control.mjs +150 -0
- package/scripts/local-server-devices.mjs +71 -0
- package/scripts/local-server-host-status.mjs +72 -0
- package/scripts/local-server-http.mjs +120 -0
- package/scripts/local-server-install.mjs +22 -0
- package/scripts/local-server-lifecycle.mjs +54 -0
- package/scripts/local-server-lock.mjs +217 -0
- package/scripts/local-server-migrations.mjs +43 -0
- package/scripts/local-server-options.mjs +134 -0
- package/scripts/local-server-pairing.mjs +47 -0
- package/scripts/local-server-process.mjs +77 -0
- package/scripts/local-server-qr.mjs +34 -0
- package/scripts/local-server-quick.mjs +116 -0
- package/scripts/local-server-readiness.mjs +48 -0
- package/scripts/local-server-runtime.mjs +460 -0
- package/scripts/local-server-service.mjs +209 -0
- package/scripts/local-server-style.mjs +12 -0
- package/scripts/local-server-tailscale.mjs +122 -0
- package/scripts/local-server-tunnel.mjs +212 -0
- package/scripts/local-server-watchdog.mjs +37 -0
- package/scripts/local-server-wizard.mjs +100 -0
- package/scripts/local-server.mjs +100 -0
- package/vendor/miniflare/LICENSE +25 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/ArrowClockwise.es-Cs0EHtoR.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Breadcrumbs-BlzUUgNz.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CaretDown.es-r8EMGhHM.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CaretLeft.es-CCxvlwgr.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CaretRight.es-CWeeOO8C.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CaretUpDown.es-Bp73BWZN.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Check.es-B3dV_aVM.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Copy.es-DUyM7PbX.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CopyButton-DdMFsAgv.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CronTriggersContext-CtoQyHCH.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/CronTriggersPage-BC2FvZf5.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/DotsThree.es-B9u_qIrH.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Download.es-v8YTKdZh.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/List.es-GlowdvL8.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/ListBullets.es-DrJsrtCL.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/MagnifyingGlass.es-BzOo3pru.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/PaperPlaneTilt.es-DTLdWOnM.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Paperclip.es-6Ysj3lly.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Pencil.es-CDpuGAys.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Plus.es-xOjOjCs5.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/ResourceError-DNadec0F.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Spinner.es-oqUPe-aY.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/TableSelect-DgjN53ZF.js +25 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Trash.es-DTqwcb2_.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/Warning.es-CLa-n7LD.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/X.es-BiJFnG31.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_appId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_appId-TnuOHwOA.js +5 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_bucketName-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_bucketName-DMGTgdaZ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_bucketName-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_bucketName-DqCj-aYZ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_bucketName-uYCS7veQ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_captureId-Cb6ggQGG.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_captureId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_captureId-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-BW1__nAw.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-DCj9M_Uf.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-DMGTgdaZ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_className-uYCS7veQ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_databaseId-BEh2sOY5.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_databaseId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_instanceId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_instanceId-CxJm9jpK.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_instanceId-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_namespaceId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_namespaceId-HT9g0tMq.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_objectId-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_objectId-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_objectId-DdmD-NV1.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_workflowName-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_workflowName-DMGTgdaZ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_workflowName-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_workflowName-WgIBBs_w.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/_workflowName-uYCS7veQ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/ad-hoc-B9HL0oNk.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/async-t2_zA-v_.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/button-cdxnqcgzwko8ooha-CjoTKpgy.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/checkbox-kt1uojk2f9e0d0h1-D923QL-G.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/clipboard-text-vcbvmtne4zjk4b18-CEoJIuMe.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/configured-BGeRrlYf.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/cron-triggers-ZP5ClwAa.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/dialog-oqh8l3l3zutpibxx-nho54TMC.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/dropdown-ncwhcd912vmone8k-BAT0p_ep.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/email-B-IveBKB.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/events-ClnoiyGH.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/events-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/field-krp6z6vfbkrvufz2-DsLUBjzS.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/format-CjQ0gyEW.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/helpers-Bz2sloWm.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/index-BHW_FKpE.js +30 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/index-CiXL10aq.css +2 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/input-area-no30c09udyjxshu5-T786oEMj.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/input-group-lxdd09p60cf27pe1-BqVz8A4J.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/input-h48k3uagzrgb98au-BF-hE08e.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/label-latndvb1ngem7we8-mWoel0Kk.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/link-DadJAPnd.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/link-provider-mn2voeohon7cj9o4-CNosc_Ni.js +13 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/matchContext-C1eKDtty.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/object._-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/object._-DDwO6NT7.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/object._-Daanvg3W.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/observability-CC1mP6Xo.js +15 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/observability-CX-6-j6d.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/observability-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/react-BZY8YNV6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/redirect-CckYXsV1.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/routes-BlOyav-b.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/routing-CVthjHxr.js +2 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/routing-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/routing-DMGTgdaZ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/routing-uYCS7veQ.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/select-kva5ru5f673kah1m-DQuxH2_G.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/sending-BPjb3S3Y.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/sending-Cow8QNw6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/switch-ihaydbzem62bey4p-C9M-MPNS.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/table-inweecadl3her7pd-UWLv9e8D.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/text-nmyi1rkwdj37f30f-BLzIhmEO.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/types-DTx0hLYz.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/useCursorPaginatedList-BGUINn38.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/assets/useRouterState-BLq6Ai_6.js +1 -0
- package/vendor/miniflare/dist/local-explorer-ui/favicon.svg +3 -0
- package/vendor/miniflare/dist/local-explorer-ui/index.html +27 -0
- package/vendor/miniflare/dist/src/index.d.ts +14183 -0
- package/vendor/miniflare/dist/src/index.js +123738 -0
- package/vendor/miniflare/dist/src/mdream_edge_bg.wasm +0 -0
- package/vendor/miniflare/dist/src/plugins/artifacts/git-sidecar.js +21071 -0
- package/vendor/miniflare/dist/src/workers/access/access-identity.worker.js +10 -0
- package/vendor/miniflare/dist/src/workers/analytics-engine/analytics-engine.worker.js +21 -0
- package/vendor/miniflare/dist/src/workers/analytics-engine/remote.worker.js +2578 -0
- package/vendor/miniflare/dist/src/workers/artifacts/binding.worker.js +903 -0
- package/vendor/miniflare/dist/src/workers/artifacts/wrapped-binding.worker.js +52 -0
- package/vendor/miniflare/dist/src/workers/assets/assets-kv.worker.js +27 -0
- package/vendor/miniflare/dist/src/workers/assets/assets.worker.js +1525 -0
- package/vendor/miniflare/dist/src/workers/assets/router.worker.js +1883 -0
- package/vendor/miniflare/dist/src/workers/assets/rpc-proxy.worker.js +55 -0
- package/vendor/miniflare/dist/src/workers/browser-rendering/binding.worker.js +453 -0
- package/vendor/miniflare/dist/src/workers/cache/cache-entry-noop.worker.js +18 -0
- package/vendor/miniflare/dist/src/workers/cache/cache-entry.worker.js +24 -0
- package/vendor/miniflare/dist/src/workers/cache/cache.worker.js +652 -0
- package/vendor/miniflare/dist/src/workers/core/dev-control.worker.js +52 -0
- package/vendor/miniflare/dist/src/workers/core/dev-registry-proxy.worker.js +371 -0
- package/vendor/miniflare/dist/src/workers/core/do-wrapper.worker.js +67 -0
- package/vendor/miniflare/dist/src/workers/core/entry.worker.js +5516 -0
- package/vendor/miniflare/dist/src/workers/core/outbound.worker.js +147 -0
- package/vendor/miniflare/dist/src/workers/d1/database.worker.js +298 -0
- package/vendor/miniflare/dist/src/workers/d1/entry.worker.js +143 -0
- package/vendor/miniflare/dist/src/workers/dispatch-namespace/dispatch-namespace-proxy.worker.js +2574 -0
- package/vendor/miniflare/dist/src/workers/dispatch-namespace/dispatch-namespace.worker.js +11 -0
- package/vendor/miniflare/dist/src/workers/email/email-store.worker.js +606 -0
- package/vendor/miniflare/dist/src/workers/email/email.worker.js +26 -0
- package/vendor/miniflare/dist/src/workers/email/send_email.worker.js +3703 -0
- package/vendor/miniflare/dist/src/workers/flagship/binding.worker.js +394 -0
- package/vendor/miniflare/dist/src/workers/flagship/object.worker.js +349 -0
- package/vendor/miniflare/dist/src/workers/hello-world/binding.worker.js +18 -0
- package/vendor/miniflare/dist/src/workers/hello-world/object.worker.js +13 -0
- package/vendor/miniflare/dist/src/workers/images/images.worker.js +450 -0
- package/vendor/miniflare/dist/src/workers/k2/binding.worker.js +2583 -0
- package/vendor/miniflare/dist/src/workers/kv/namespace.worker.js +323 -0
- package/vendor/miniflare/dist/src/workers/kv/sites.worker.js +148 -0
- package/vendor/miniflare/dist/src/workers/local-explorer/explorer.worker.js +17275 -0
- package/vendor/miniflare/dist/src/workers/observability/collector.worker.js +725 -0
- package/vendor/miniflare/dist/src/workers/pipelines/pipeline.worker.js +9 -0
- package/vendor/miniflare/dist/src/workers/queues/broker.worker.js +391 -0
- package/vendor/miniflare/dist/src/workers/r2/bucket.worker.js +1171 -0
- package/vendor/miniflare/dist/src/workers/r2/public.worker.js +1319 -0
- package/vendor/miniflare/dist/src/workers/r2/s3/index.worker.js +11128 -0
- package/vendor/miniflare/dist/src/workers/ratelimit/ratelimit-object.worker.js +55 -0
- package/vendor/miniflare/dist/src/workers/ratelimit/ratelimit.worker.js +69 -0
- package/vendor/miniflare/dist/src/workers/secrets-store/secret.worker.js +64 -0
- package/vendor/miniflare/dist/src/workers/shared/index.worker.js +730 -0
- package/vendor/miniflare/dist/src/workers/shared/object-entry.worker.js +33 -0
- package/vendor/miniflare/dist/src/workers/shared/remote-proxy-client.worker.js +2698 -0
- package/vendor/miniflare/dist/src/workers/shared/zod.worker.js +15459 -0
- package/vendor/miniflare/dist/src/workers/stream/binding.worker.js +282 -0
- package/vendor/miniflare/dist/src/workers/stream/object.worker.js +479 -0
- package/vendor/miniflare/dist/src/workers/workflows/binding.worker.js +5137 -0
- package/vendor/miniflare/dist/src/workers/workflows/wrapped-binding.worker.js +111 -0
- package/vendor/miniflare/package.json +135 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
// src/workers/flagship/binding.worker.ts
|
|
2
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
3
|
+
|
|
4
|
+
// src/workers/flagship/constants.ts
|
|
5
|
+
var ADMIN_API = "FlagshipBinding::admin_api";
|
|
6
|
+
|
|
7
|
+
// src/workers/flagship/evaluate.ts
|
|
8
|
+
var TypeCastError = class extends Error {
|
|
9
|
+
constructor(flagKey, expectedType, actualValue) {
|
|
10
|
+
super(
|
|
11
|
+
`Flag '${flagKey}' has type '${typeof actualValue}', expected '${expectedType}'`
|
|
12
|
+
), this.name = "TypeCastError";
|
|
13
|
+
}
|
|
14
|
+
}, FlagConfigError = class extends Error {
|
|
15
|
+
constructor(flagKey, message) {
|
|
16
|
+
super(`Flag '${flagKey}' ${message}`), this.name = "FlagConfigError";
|
|
17
|
+
}
|
|
18
|
+
}, ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/, MAX_PATH_DEPTH = 5, encoder = new TextEncoder(), randomBuf = new Uint32Array(1), MAX_RETAINED_HASH_BYTES = 32 * 1024, HASH_QUOTIENT_RANGE = Math.ceil(2 ** 32 / 100), hashBuf = new Uint8Array(512);
|
|
19
|
+
function isPrimitive(value) {
|
|
20
|
+
return value === null || typeof value != "object" && typeof value != "function";
|
|
21
|
+
}
|
|
22
|
+
function isScalar(value) {
|
|
23
|
+
return typeof value == "string" || typeof value == "number" || typeof value == "boolean";
|
|
24
|
+
}
|
|
25
|
+
function getContextValue(context, attribute) {
|
|
26
|
+
if (Object.hasOwn(context, attribute))
|
|
27
|
+
return context[attribute];
|
|
28
|
+
if (!attribute.includes("."))
|
|
29
|
+
return;
|
|
30
|
+
let path = attribute.split(".");
|
|
31
|
+
if (path.length > MAX_PATH_DEPTH)
|
|
32
|
+
return;
|
|
33
|
+
let value = context;
|
|
34
|
+
for (let segment of path) {
|
|
35
|
+
if (isPrimitive(value) || !Object.hasOwn(value, segment))
|
|
36
|
+
return;
|
|
37
|
+
value = value[segment];
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
function murmurhash3(str, seed) {
|
|
42
|
+
let requiredBytes = str.length * 3, b, n;
|
|
43
|
+
requiredBytes > MAX_RETAINED_HASH_BYTES ? (b = encoder.encode(str), n = b.byteLength) : (hashBuf.byteLength < requiredBytes && (hashBuf = new Uint8Array(requiredBytes)), b = hashBuf, n = encoder.encodeInto(str, b).written);
|
|
44
|
+
let h = seed >>> 0, i = 0;
|
|
45
|
+
for (; i + 4 <= n; ) {
|
|
46
|
+
let k2 = b[i] | b[i + 1] << 8 | b[i + 2] << 16 | b[i + 3] << 24;
|
|
47
|
+
k2 = Math.imul(k2, 3432918353) >>> 0, k2 = (k2 << 15 | k2 >>> 17) >>> 0, k2 = Math.imul(k2, 461845907) >>> 0, h ^= k2, h = (h << 13 | h >>> 19) >>> 0, h = Math.imul(h, 5) + 3864292196 >>> 0, i += 4;
|
|
48
|
+
}
|
|
49
|
+
let k = 0;
|
|
50
|
+
return n - i >= 3 && (k ^= b[i + 2] << 16), n - i >= 2 && (k ^= b[i + 1] << 8), n > i && (k ^= b[i], k = Math.imul(k, 3432918353) >>> 0, k = (k << 15 | k >>> 17) >>> 0, k = Math.imul(k, 461845907) >>> 0, h ^= k), h ^= n, h ^= h >>> 16, h = Math.imul(h, 2246822507) >>> 0, h ^= h >>> 13, h = Math.imul(h, 3266489909) >>> 0, h ^= h >>> 16, h >>> 0;
|
|
51
|
+
}
|
|
52
|
+
function evaluateStringOperator(operator, attrValue, target) {
|
|
53
|
+
if (attrValue === null)
|
|
54
|
+
return operator === "not_equals";
|
|
55
|
+
if (!isScalar(attrValue) || !isPrimitive(target))
|
|
56
|
+
return !1;
|
|
57
|
+
let actual = String(attrValue), expected = String(target);
|
|
58
|
+
switch (operator) {
|
|
59
|
+
case "equals":
|
|
60
|
+
return actual === expected;
|
|
61
|
+
case "not_equals":
|
|
62
|
+
return actual !== expected;
|
|
63
|
+
case "contains":
|
|
64
|
+
return actual.includes(expected);
|
|
65
|
+
case "starts_with":
|
|
66
|
+
return actual.startsWith(expected);
|
|
67
|
+
case "ends_with":
|
|
68
|
+
return actual.endsWith(expected);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function toNumber(value) {
|
|
72
|
+
return typeof value == "string" && value.trim() === "" ? NaN : Number(value);
|
|
73
|
+
}
|
|
74
|
+
function compareValues(attrValue, target) {
|
|
75
|
+
if (!isScalar(attrValue) || !isScalar(target))
|
|
76
|
+
return;
|
|
77
|
+
let actual, expected;
|
|
78
|
+
if (typeof target == "string" && ISO_8601_REGEX.test(target) && typeof attrValue == "string" ? (actual = Date.parse(attrValue), Number.isNaN(actual) ? (actual = toNumber(attrValue), expected = toNumber(target)) : expected = Date.parse(target)) : (actual = toNumber(attrValue), expected = toNumber(target)), !(Number.isNaN(actual) || Number.isNaN(expected)))
|
|
79
|
+
return actual === expected ? 0 : actual < expected ? -1 : 1;
|
|
80
|
+
}
|
|
81
|
+
function evaluateOrderingOperator(operator, attrValue, target) {
|
|
82
|
+
let comparison = compareValues(attrValue, target);
|
|
83
|
+
if (comparison === void 0)
|
|
84
|
+
return !1;
|
|
85
|
+
switch (operator) {
|
|
86
|
+
case "greater_than":
|
|
87
|
+
return comparison > 0;
|
|
88
|
+
case "less_than":
|
|
89
|
+
return comparison < 0;
|
|
90
|
+
case "greater_than_or_equals":
|
|
91
|
+
return comparison >= 0;
|
|
92
|
+
case "less_than_or_equals":
|
|
93
|
+
return comparison <= 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function containsValue(values, target) {
|
|
97
|
+
let expected = String(target);
|
|
98
|
+
return values.some((value) => value !== null && String(value) === expected);
|
|
99
|
+
}
|
|
100
|
+
function containsPrimitiveValue(values, target) {
|
|
101
|
+
let expected = String(target);
|
|
102
|
+
return values.some((value) => isScalar(value) && String(value) === expected);
|
|
103
|
+
}
|
|
104
|
+
function evaluateCondition(condition, context) {
|
|
105
|
+
if ("logical_operator" in condition) {
|
|
106
|
+
let { logical_operator, clauses } = condition;
|
|
107
|
+
if (logical_operator === "AND") {
|
|
108
|
+
for (let clause of clauses)
|
|
109
|
+
if (!evaluateCondition(clause, context))
|
|
110
|
+
return !1;
|
|
111
|
+
return !0;
|
|
112
|
+
}
|
|
113
|
+
for (let clause of clauses)
|
|
114
|
+
if (evaluateCondition(clause, context))
|
|
115
|
+
return !0;
|
|
116
|
+
return !1;
|
|
117
|
+
}
|
|
118
|
+
let { attribute, operator, value: target } = condition, attrValue = getContextValue(context, attribute);
|
|
119
|
+
if (attrValue === void 0)
|
|
120
|
+
return !1;
|
|
121
|
+
switch (operator) {
|
|
122
|
+
case "equals":
|
|
123
|
+
case "not_equals":
|
|
124
|
+
case "contains":
|
|
125
|
+
case "starts_with":
|
|
126
|
+
case "ends_with":
|
|
127
|
+
return evaluateStringOperator(operator, attrValue, target);
|
|
128
|
+
case "greater_than":
|
|
129
|
+
case "less_than":
|
|
130
|
+
case "greater_than_or_equals":
|
|
131
|
+
case "less_than_or_equals":
|
|
132
|
+
return evaluateOrderingOperator(operator, attrValue, target);
|
|
133
|
+
case "in":
|
|
134
|
+
case "not_in":
|
|
135
|
+
return Array.isArray(target) ? attrValue === null ? operator === "not_in" : isScalar(attrValue) ? operator === "in" ? containsValue(target, attrValue) : !containsValue(target, attrValue) : !1 : !1;
|
|
136
|
+
case "has":
|
|
137
|
+
case "not_has":
|
|
138
|
+
return !Array.isArray(attrValue) || !isPrimitive(target) ? !1 : operator === "has" ? containsPrimitiveValue(attrValue, target) : !containsPrimitiveValue(attrValue, target);
|
|
139
|
+
default:
|
|
140
|
+
return !1;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function evaluateFlag(flagDef, context, accountId) {
|
|
144
|
+
let serve = (variant, reason) => {
|
|
145
|
+
if (!Object.hasOwn(flagDef.variations, variant))
|
|
146
|
+
throw new FlagConfigError(
|
|
147
|
+
flagDef.key,
|
|
148
|
+
`variation '${variant}' is not defined`
|
|
149
|
+
);
|
|
150
|
+
return {
|
|
151
|
+
value: flagDef.variations[variant],
|
|
152
|
+
variant,
|
|
153
|
+
reason,
|
|
154
|
+
...flagDef.metadata ? { metadata: flagDef.metadata } : {}
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
if (!flagDef.enabled)
|
|
158
|
+
return serve(flagDef.default_variation, "DISABLED");
|
|
159
|
+
if (flagDef.rules.length === 0)
|
|
160
|
+
return serve(flagDef.default_variation, "STATIC");
|
|
161
|
+
let seed, rules = [...flagDef.rules].sort((a, b) => {
|
|
162
|
+
let aPriority = "priority" in a ? a.priority : 0, bPriority = "priority" in b ? b.priority : 0;
|
|
163
|
+
return aPriority - bPriority;
|
|
164
|
+
});
|
|
165
|
+
for (let rule of rules) {
|
|
166
|
+
let ruleMatches = !0;
|
|
167
|
+
for (let condition of rule.conditions)
|
|
168
|
+
if (!evaluateCondition(condition, context)) {
|
|
169
|
+
ruleMatches = !1;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
let { rollout } = rule, isSplit = rollout !== void 0 && rollout.percentage < 100;
|
|
173
|
+
if (ruleMatches && rollout !== void 0) {
|
|
174
|
+
let attr = getContextValue(
|
|
175
|
+
context,
|
|
176
|
+
rollout.attribute || "targetingKey"
|
|
177
|
+
);
|
|
178
|
+
if (attr != null && !isScalar(attr))
|
|
179
|
+
ruleMatches = !1;
|
|
180
|
+
else if (isSplit) {
|
|
181
|
+
seed ??= murmurhash3(`${accountId}:${flagDef.key}`, 0) % 100;
|
|
182
|
+
let bucket;
|
|
183
|
+
if (isScalar(attr)) {
|
|
184
|
+
let hash = murmurhash3(String(attr), seed);
|
|
185
|
+
bucket = hash % 100 + Math.floor(hash / 100) / HASH_QUOTIENT_RANGE;
|
|
186
|
+
} else
|
|
187
|
+
bucket = crypto.getRandomValues(randomBuf)[0] / 4294967296 * 100;
|
|
188
|
+
bucket >= rollout.percentage && (ruleMatches = !1);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (ruleMatches)
|
|
192
|
+
return serve(rule.serve_variation, isSplit ? "SPLIT" : "TARGETING_MATCH");
|
|
193
|
+
}
|
|
194
|
+
return serve(flagDef.default_variation, "DEFAULT");
|
|
195
|
+
}
|
|
196
|
+
function matchesType(value, expectedType) {
|
|
197
|
+
switch (expectedType) {
|
|
198
|
+
case "boolean":
|
|
199
|
+
return typeof value == "boolean";
|
|
200
|
+
case "string":
|
|
201
|
+
return typeof value == "string";
|
|
202
|
+
case "number":
|
|
203
|
+
return typeof value == "number";
|
|
204
|
+
case "object":
|
|
205
|
+
return typeof value == "object" && value !== null;
|
|
206
|
+
default:
|
|
207
|
+
return !1;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/workers/flagship/flags.ts
|
|
212
|
+
function flagNotFoundMessage(flagKey) {
|
|
213
|
+
return `Flag '${flagKey}' not found`;
|
|
214
|
+
}
|
|
215
|
+
function flagConflictMessage(flagKey) {
|
|
216
|
+
return `Flag '${flagKey}' already exists`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/workers/flagship/binding.worker.ts
|
|
220
|
+
var FlagNotFoundError = class extends Error {
|
|
221
|
+
constructor(flagKey) {
|
|
222
|
+
super(flagNotFoundMessage(flagKey));
|
|
223
|
+
}
|
|
224
|
+
}, FlagConflictError = class extends Error {
|
|
225
|
+
constructor(flagKey) {
|
|
226
|
+
super(flagConflictMessage(flagKey));
|
|
227
|
+
}
|
|
228
|
+
}, warnedAboutUnseededRollout = !1;
|
|
229
|
+
function validateAccountTag(accountTag) {
|
|
230
|
+
if (typeof accountTag != "string" || accountTag === "")
|
|
231
|
+
throw new Error("accountTag must be a non-empty string");
|
|
232
|
+
}
|
|
233
|
+
function hasPartialRollout(flag) {
|
|
234
|
+
return flag.rules.some(
|
|
235
|
+
(rule) => rule.rollout !== void 0 && rule.rollout.percentage < 100
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
function warnIfBucketingUnseeded(flag) {
|
|
239
|
+
warnedAboutUnseededRollout || !hasPartialRollout(flag) || (warnedAboutUnseededRollout = !0, console.warn(
|
|
240
|
+
`Flagship: flag '${flag.key}' has a percentage rollout, but the local flag store has no account tag, so its buckets will not match your remote app. Run \`flagship flags pull\` to seed the store.`
|
|
241
|
+
));
|
|
242
|
+
}
|
|
243
|
+
function errorCodeFor(error) {
|
|
244
|
+
if (error instanceof FlagNotFoundError)
|
|
245
|
+
return "FLAG_NOT_FOUND";
|
|
246
|
+
if (error instanceof FlagConfigError)
|
|
247
|
+
return "PARSE_ERROR";
|
|
248
|
+
}
|
|
249
|
+
function getStub(env, appId) {
|
|
250
|
+
return env.store.get(env.store.idFromName(appId));
|
|
251
|
+
}
|
|
252
|
+
async function evaluate(stub, flagKey, context, fallbackAccountTag) {
|
|
253
|
+
if (typeof flagKey != "string" || flagKey === "")
|
|
254
|
+
throw new Error("flagKey must be a non-empty string");
|
|
255
|
+
let { flag, accountTag } = await stub.getForEvaluation(flagKey);
|
|
256
|
+
if (flag === null)
|
|
257
|
+
throw new FlagNotFoundError(flagKey);
|
|
258
|
+
return accountTag === null && warnIfBucketingUnseeded(flag), {
|
|
259
|
+
flagKey,
|
|
260
|
+
...evaluateFlag(flag, context, accountTag ?? fallbackAccountTag)
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function createAdmin(stub, fallbackAccountTag) {
|
|
264
|
+
function unwrap(result, flagKey) {
|
|
265
|
+
switch (result.status) {
|
|
266
|
+
case "written":
|
|
267
|
+
return result.flag;
|
|
268
|
+
case "missing":
|
|
269
|
+
throw new FlagNotFoundError(flagKey);
|
|
270
|
+
case "exists":
|
|
271
|
+
throw new FlagConflictError(flagKey);
|
|
272
|
+
case "invalid":
|
|
273
|
+
throw new Error(result.message);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
async function getFlag(flagKey) {
|
|
277
|
+
let flag = await stub.get(flagKey);
|
|
278
|
+
if (flag === null)
|
|
279
|
+
throw new FlagNotFoundError(flagKey);
|
|
280
|
+
return flag;
|
|
281
|
+
}
|
|
282
|
+
async function write(operation, flagKey) {
|
|
283
|
+
return unwrap(await operation, flagKey);
|
|
284
|
+
}
|
|
285
|
+
async function writeInput(operation, input) {
|
|
286
|
+
let flagKey = typeof input == "object" && input !== null && "key" in input && typeof input.key == "string" ? input.key : "";
|
|
287
|
+
return unwrap(await operation, flagKey);
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
listFlags: () => stub.list(),
|
|
291
|
+
getFlag,
|
|
292
|
+
getAccountTag: () => stub.getAccountTag(),
|
|
293
|
+
setAccountTag: (accountTag) => (validateAccountTag(accountTag), stub.setAccountTag(accountTag)),
|
|
294
|
+
createFlag: (input) => writeInput(stub.create(input), input),
|
|
295
|
+
updateFlag: (flagKey, input) => write(stub.update(flagKey, input), flagKey),
|
|
296
|
+
patchFlag: (flagKey, changes) => write(stub.patch(flagKey, changes), flagKey),
|
|
297
|
+
putFlag: (input) => writeInput(stub.put(input), input),
|
|
298
|
+
putFlags: async (inputs, accountTag) => {
|
|
299
|
+
validateAccountTag(accountTag);
|
|
300
|
+
let result = await stub.putAll(inputs, accountTag);
|
|
301
|
+
if (result.status === "invalid")
|
|
302
|
+
throw new Error(result.message);
|
|
303
|
+
},
|
|
304
|
+
deleteFlag: async (flagKey) => {
|
|
305
|
+
if (!await stub.delete(flagKey))
|
|
306
|
+
throw new FlagNotFoundError(flagKey);
|
|
307
|
+
},
|
|
308
|
+
evaluateFlag: (flagKey, context) => evaluate(stub, flagKey, context ?? {}, fallbackAccountTag)
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
var FlagshipBinding = class extends WorkerEntrypoint {
|
|
312
|
+
get #stub() {
|
|
313
|
+
return getStub(this.env, this.ctx.props.appId);
|
|
314
|
+
}
|
|
315
|
+
#evaluate(flagKey, context) {
|
|
316
|
+
return evaluate(this.#stub, flagKey, context, this.ctx.props.accountTag);
|
|
317
|
+
}
|
|
318
|
+
async #typedDetails(flagKey, defaultValue, expectedType, context) {
|
|
319
|
+
let failure = (errorCode, errorMessage) => ({
|
|
320
|
+
flagKey,
|
|
321
|
+
value: defaultValue,
|
|
322
|
+
variant: "default",
|
|
323
|
+
reason: "ERROR",
|
|
324
|
+
errorCode,
|
|
325
|
+
errorMessage
|
|
326
|
+
}), result;
|
|
327
|
+
try {
|
|
328
|
+
result = await this.#evaluate(flagKey, context ?? {});
|
|
329
|
+
} catch (error) {
|
|
330
|
+
let errorCode = errorCodeFor(error);
|
|
331
|
+
if (errorCode === void 0)
|
|
332
|
+
throw error;
|
|
333
|
+
return failure(errorCode, error.message);
|
|
334
|
+
}
|
|
335
|
+
let metadata = result.metadata ? { metadata: result.metadata } : {};
|
|
336
|
+
return matchesType(result.value, expectedType) ? {
|
|
337
|
+
flagKey,
|
|
338
|
+
value: result.value,
|
|
339
|
+
variant: result.variant,
|
|
340
|
+
reason: result.reason,
|
|
341
|
+
...metadata
|
|
342
|
+
} : {
|
|
343
|
+
...failure(
|
|
344
|
+
"TYPE_MISMATCH",
|
|
345
|
+
new TypeCastError(flagKey, expectedType, result.value).message
|
|
346
|
+
),
|
|
347
|
+
...metadata
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
async get(flagKey, defaultValue, context) {
|
|
351
|
+
try {
|
|
352
|
+
return (await this.#evaluate(flagKey, context ?? {})).value;
|
|
353
|
+
} catch (error) {
|
|
354
|
+
if (errorCodeFor(error) !== void 0 && defaultValue !== void 0)
|
|
355
|
+
return defaultValue;
|
|
356
|
+
throw error;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
async getBooleanValue(flagKey, defaultValue, context) {
|
|
360
|
+
return (await this.#typedDetails(flagKey, defaultValue, "boolean", context)).value;
|
|
361
|
+
}
|
|
362
|
+
async getStringValue(flagKey, defaultValue, context) {
|
|
363
|
+
return (await this.#typedDetails(flagKey, defaultValue, "string", context)).value;
|
|
364
|
+
}
|
|
365
|
+
async getNumberValue(flagKey, defaultValue, context) {
|
|
366
|
+
return (await this.#typedDetails(flagKey, defaultValue, "number", context)).value;
|
|
367
|
+
}
|
|
368
|
+
async getObjectValue(flagKey, defaultValue, context) {
|
|
369
|
+
return (await this.#typedDetails(flagKey, defaultValue, "object", context)).value;
|
|
370
|
+
}
|
|
371
|
+
async getBooleanDetails(flagKey, defaultValue, context) {
|
|
372
|
+
return this.#typedDetails(flagKey, defaultValue, "boolean", context);
|
|
373
|
+
}
|
|
374
|
+
async getStringDetails(flagKey, defaultValue, context) {
|
|
375
|
+
return this.#typedDetails(flagKey, defaultValue, "string", context);
|
|
376
|
+
}
|
|
377
|
+
async getNumberDetails(flagKey, defaultValue, context) {
|
|
378
|
+
return this.#typedDetails(flagKey, defaultValue, "number", context);
|
|
379
|
+
}
|
|
380
|
+
async getObjectDetails(flagKey, defaultValue, context) {
|
|
381
|
+
return this.#typedDetails(flagKey, defaultValue, "object", context);
|
|
382
|
+
}
|
|
383
|
+
[ADMIN_API]() {
|
|
384
|
+
return createAdmin(this.#stub, this.ctx.props.accountTag);
|
|
385
|
+
}
|
|
386
|
+
}, FlagshipExplorer = class extends WorkerEntrypoint {
|
|
387
|
+
[ADMIN_API](appId) {
|
|
388
|
+
return createAdmin(getStub(this.env, appId), this.ctx.props.accountTag);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
export {
|
|
392
|
+
FlagshipBinding,
|
|
393
|
+
FlagshipExplorer
|
|
394
|
+
};
|