@sequenceholdings/managed-functions 0.2.0 → 0.3.1

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/runtime.cjs CHANGED
@@ -26837,7 +26837,7 @@ var require_contracts = __commonJS({
26837
26837
  "../storage/dist/contracts.js"(exports2) {
26838
26838
  "use strict";
26839
26839
  Object.defineProperty(exports2, "__esModule", { value: true });
26840
- exports2.storageErrorSchema = exports2.storageAccessSchema = exports2.updateStorageAccessSchema = exports2.storagePrincipalSchema = exports2.uploadSessionSchema = exports2.completeUploadSchema = exports2.startUploadSchema = exports2.storageChecksum = exports2.updateNodeSchema = exports2.createFolderSchema = exports2.listStorageSchema = exports2.storagePage = exports2.listStorageOperationsSchema = exports2.storageOperationScope = exports2.operationSchema = exports2.versionSchema = exports2.nodeSchema = exports2.workspaceSchema = exports2.workspaceManifestSchema = exports2.storageMetadata = exports2.storagePath = exports2.storageName = exports2.storageLifecycle = exports2.storageRole = exports2.storageId = void 0;
26840
+ exports2.storageErrorSchema = exports2.storageAccessSchema = exports2.updateStorageAccessSchema = exports2.storagePrincipalSchema = exports2.reconcileUploadsResultSchema = exports2.reconcileUploadsSchema = exports2.uploadListSchema = exports2.uploadLimitsSchema = exports2.uploadListItemSchema = exports2.uploadSessionSchema = exports2.startUploadBatchSchema = exports2.completeUploadSchema = exports2.startUploadSchema = exports2.storageChecksum = exports2.STORAGE_IMPORT_CONCURRENCY_MAX = exports2.STORAGE_IMPORT_CONCURRENCY_DEFAULT = exports2.STORAGE_UPLOAD_BATCH_LIMIT = exports2.STORAGE_PENDING_UPLOADS_PER_WORKSPACE = exports2.STORAGE_PENDING_UPLOADS_PER_PRINCIPAL = exports2.updateNodeSchema = exports2.createFolderSchema = exports2.listStorageSchema = exports2.storagePage = exports2.listStorageOperationsSchema = exports2.storageOperationScope = exports2.operationSchema = exports2.versionSchema = exports2.nodeSchema = exports2.workspaceSchema = exports2.workspaceManifestSchema = exports2.storageMetadata = exports2.storagePath = exports2.storageName = exports2.storageLifecycle = exports2.storageRole = exports2.storageId = void 0;
26841
26841
  var zod_12 = require_zod();
26842
26842
  var paths_js_1 = require_paths();
26843
26843
  exports2.storageId = zod_12.z.uuid();
@@ -26956,6 +26956,11 @@ var require_contracts = __commonJS({
26956
26956
  parentId: exports2.storageId.nullable().optional(),
26957
26957
  metadata: exports2.storageMetadata.optional()
26958
26958
  });
26959
+ exports2.STORAGE_PENDING_UPLOADS_PER_PRINCIPAL = 20;
26960
+ exports2.STORAGE_PENDING_UPLOADS_PER_WORKSPACE = 100;
26961
+ exports2.STORAGE_UPLOAD_BATCH_LIMIT = exports2.STORAGE_PENDING_UPLOADS_PER_PRINCIPAL;
26962
+ exports2.STORAGE_IMPORT_CONCURRENCY_DEFAULT = 8;
26963
+ exports2.STORAGE_IMPORT_CONCURRENCY_MAX = 16;
26959
26964
  exports2.storageChecksum = zod_12.z.string().regex(/^[A-Za-z0-9+/]{6}==$/);
26960
26965
  exports2.startUploadSchema = zod_12.z.strictObject({
26961
26966
  parentId: exports2.storageId.nullable().default(null),
@@ -26978,6 +26983,9 @@ var require_contracts = __commonJS({
26978
26983
  */
26979
26984
  crc32c: exports2.storageChecksum.optional()
26980
26985
  });
26986
+ exports2.startUploadBatchSchema = zod_12.z.strictObject({
26987
+ items: zod_12.z.array(exports2.startUploadSchema).min(1).max(exports2.STORAGE_UPLOAD_BATCH_LIMIT)
26988
+ });
26981
26989
  exports2.uploadSessionSchema = zod_12.z.object({
26982
26990
  id: exports2.storageId,
26983
26991
  fileId: exports2.storageId,
@@ -26987,6 +26995,37 @@ var require_contracts = __commonJS({
26987
26995
  versionId: exports2.storageId.nullable(),
26988
26996
  maxBytes: zod_12.z.number().int()
26989
26997
  });
26998
+ exports2.uploadListItemSchema = zod_12.z.object({
26999
+ id: exports2.storageId,
27000
+ fileId: exports2.storageId,
27001
+ name: zod_12.z.string(),
27002
+ state: zod_12.z.enum(["pending", "complete", "aborted"]),
27003
+ expiresAt: zod_12.z.string(),
27004
+ maxBytes: zod_12.z.number().int(),
27005
+ expectedSize: zod_12.z.number().int().nullable(),
27006
+ versionId: exports2.storageId.nullable()
27007
+ });
27008
+ exports2.uploadLimitsSchema = zod_12.z.object({
27009
+ perPrincipal: zod_12.z.number().int(),
27010
+ perWorkspace: zod_12.z.number().int()
27011
+ });
27012
+ exports2.uploadListSchema = zod_12.z.object({
27013
+ items: zod_12.z.array(exports2.uploadListItemSchema),
27014
+ limits: exports2.uploadLimitsSchema
27015
+ });
27016
+ exports2.reconcileUploadsSchema = zod_12.z.strictObject({
27017
+ /** Abort sessions whose bytes never arrived. Terminal mismatches are already released. */
27018
+ abortIncomplete: zod_12.z.boolean().default(false)
27019
+ });
27020
+ var reconcileEntrySchema = exports2.uploadListItemSchema.extend({
27021
+ code: zod_12.z.string(),
27022
+ message: zod_12.z.string()
27023
+ });
27024
+ exports2.reconcileUploadsResultSchema = zod_12.z.object({
27025
+ completed: zod_12.z.array(reconcileEntrySchema),
27026
+ aborted: zod_12.z.array(reconcileEntrySchema),
27027
+ pending: zod_12.z.array(reconcileEntrySchema)
27028
+ });
26990
27029
  exports2.storagePrincipalSchema = zod_12.z.strictObject({
26991
27030
  type: zod_12.z.enum(["user", "group", "organization", "service_account"]),
26992
27031
  id: zod_12.z.string().min(1).max(255),
@@ -27182,7 +27221,7 @@ var require_transfer = __commonJS({
27182
27221
  const fetcher = options.fetch ?? globalThis.fetch;
27183
27222
  const total = source instanceof Blob ? source.size : size;
27184
27223
  if (total !== void 0 && (!Number.isSafeInteger(total) || total < 0 || total > maxBytes))
27185
- throw new StorageTransferError("Upload exceeds its reserved size");
27224
+ throw new StorageTransferError(`Upload source is ${total} bytes, above the ${maxBytes}-byte reservation`);
27186
27225
  let chunkBytes = options.chunkBytes ?? 8 * 1024 * 1024;
27187
27226
  if (chunkBytes < 262144 || chunkBytes > 32 * 1024 * 1024 || chunkBytes % 262144)
27188
27227
  throw new StorageTransferError("Invalid upload chunk size");
@@ -27226,7 +27265,7 @@ var require_transfer = __commonJS({
27226
27265
  }
27227
27266
  let offset = initial.offset;
27228
27267
  if (offset > maxBytes || total !== void 0 && offset > total)
27229
- throw new StorageTransferError("Upload offset exceeds the source size");
27268
+ throw new StorageTransferError(`Upload session offset is ${offset} bytes, past the source${total === void 0 ? "" : ` of ${total} bytes`} and the ${maxBytes}-byte reservation`);
27230
27269
  options.onProgress?.(offset);
27231
27270
  const hash = new crc32c_js_1.Crc32c();
27232
27271
  const iterable = chunks(source, chunkBytes, offset, hash, options.signal);
@@ -27241,7 +27280,7 @@ var require_transfer = __commonJS({
27241
27280
  if (total === void 0 && end > maxBytes)
27242
27281
  throw new StorageTransferError(`Upload stream exceeds its ${maxBytes}-byte reservation; declare \`size\` when starting the upload to send a larger file`);
27243
27282
  if (end > maxBytes || total !== void 0 && (end > total || last && end !== total))
27244
- throw new StorageTransferError("Upload source does not match its reserved size");
27283
+ throw new StorageTransferError(`Upload source does not match its reserved size: session offset ${offset} bytes, read ${end} bytes, reservation ${maxBytes} bytes${total === void 0 ? "" : `, declared ${total} bytes`}`);
27245
27284
  const length = total ?? (last ? end : "*");
27246
27285
  let acknowledged = offset;
27247
27286
  for (let attempt = 0; ; attempt++) {
@@ -27390,7 +27429,16 @@ var require_client = __commonJS({
27390
27429
  return {
27391
27430
  capabilities: () => replayable("GET", "/capabilities", zod_12.z.object({
27392
27431
  canProvision: zod_12.z.boolean(),
27393
- uploadMethods: zod_12.z.array(zod_12.z.string())
27432
+ uploadMethods: zod_12.z.array(zod_12.z.string()),
27433
+ pendingUploads: zod_12.z.object({
27434
+ perPrincipal: zod_12.z.number().int(),
27435
+ perWorkspace: zod_12.z.number().int()
27436
+ }),
27437
+ uploadBatchLimit: zod_12.z.number().int(),
27438
+ importConcurrency: zod_12.z.object({
27439
+ default: zod_12.z.number().int(),
27440
+ max: zod_12.z.number().int()
27441
+ })
27394
27442
  })),
27395
27443
  list: (options = {}) => replayable("GET", `/workspaces${query({ ...options })}`, (0, contracts_js_1.storagePage)(contracts_js_1.workspaceSchema)),
27396
27444
  shared: (options = {}) => replayable("GET", `/shared${query({ ...options })}`, (0, contracts_js_1.storagePage)(contracts_js_1.nodeSchema)),
@@ -27419,6 +27467,21 @@ var require_client = __commonJS({
27419
27467
  // Abort is idempotent: an aborted session stays aborted, and a completed
27420
27468
  // one deterministically rejects, so a replay cannot change the outcome.
27421
27469
  abort: (id2) => replayable("DELETE", session(id2), contracts_js_1.uploadSessionSchema),
27470
+ startBatch: (items) => send({
27471
+ method: "POST",
27472
+ path: `${root}/uploads/batch`,
27473
+ schema: zod_12.z.object({ items: zod_12.z.array(contracts_js_1.uploadSessionSchema) }),
27474
+ body: contracts_js_1.startUploadBatchSchema.parse({ items }),
27475
+ retryable: (error) => isRetryableConflict(error) || isUnacknowledged(error)
27476
+ }),
27477
+ list: () => replayable("GET", `${root}/uploads`, contracts_js_1.uploadListSchema),
27478
+ reconcile: (input = {}) => send({
27479
+ method: "POST",
27480
+ path: `${root}/uploads/reconcile`,
27481
+ schema: contracts_js_1.reconcileUploadsResultSchema,
27482
+ body: contracts_js_1.reconcileUploadsSchema.parse(input),
27483
+ retryable: isRetryableConflict
27484
+ }),
27422
27485
  async resume(id2, source, options = {}) {
27423
27486
  const current = await upload.get(id2);
27424
27487
  if (current.state === "complete")
@@ -27647,12 +27710,18 @@ var require_limits = __commonJS({
27647
27710
  },
27648
27711
  workload: {
27649
27712
  memory_mb: { min: 128, max: 2048, default: 256, unit: "MiB per instance" },
27650
- timeout_seconds: { min: 1, max: 540, default: 60, unit: "seconds" },
27713
+ timeout_seconds: { min: 1, max: 3600, default: 60, unit: "seconds" },
27651
27714
  min_instances: { min: 0, max: 10, default: 1, scope: "Cannot exceed max_instances; warm instances incur idle charges" },
27652
27715
  max_instances: { min: 2, max: 10, default: 3, scope: "Autoscaling ceiling; must allow at least two instances, and GCP may temporarily exceed it" },
27653
27716
  invoke_rate_per_minute: { min: 1, max: 600, default: 60, window_seconds: 60, scope: "Per function across all Atlas replicas in the environment; Redis-backed fixed window. Redis unavailability rejects invocations (503); key loss resets the window" },
27654
27717
  max_request_bytes: { max: 1024 * 1024, unit: "bytes", configurable: false },
27655
- max_response_bytes: { max: 4 * 1024 * 1024, unit: "bytes", configurable: false },
27718
+ max_response_bytes: {
27719
+ min: 1,
27720
+ max: 256 * 1024 * 1024,
27721
+ default: 4 * 1024 * 1024,
27722
+ unit: "bytes",
27723
+ configurable: true
27724
+ },
27656
27725
  cpu: {
27657
27726
  configurable: true,
27658
27727
  default: "auto",
@@ -27696,6 +27765,7 @@ var require_limits = __commonJS({
27696
27765
  ]).default(workload.cpu.default),
27697
27766
  concurrency: integerLimit(workload.concurrency),
27698
27767
  timeout_seconds: integerLimit(workload.timeout_seconds),
27768
+ max_response_bytes: integerLimit(workload.max_response_bytes),
27699
27769
  min_instances: integerLimit(workload.min_instances),
27700
27770
  max_instances: integerLimit(workload.max_instances),
27701
27771
  invoke_rate_per_minute: integerLimit(workload.invoke_rate_per_minute)
@@ -27741,17 +27811,531 @@ var require_limits = __commonJS({
27741
27811
  maxInstances: workload.max_instances.default,
27742
27812
  invokeRatePerMinute: workload.invoke_rate_per_minute.default,
27743
27813
  maxRequestBytes: workload.max_request_bytes.max,
27744
- maxResponseBytes: workload.max_response_bytes.max
27814
+ maxResponseBytes: workload.max_response_bytes.default
27745
27815
  };
27746
27816
  }
27747
27817
  });
27748
27818
 
27819
+ // dist/sdk-range.js
27820
+ var require_sdk_range = __commonJS({
27821
+ "dist/sdk-range.js"(exports2) {
27822
+ "use strict";
27823
+ Object.defineProperty(exports2, "__esModule", { value: true });
27824
+ exports2.concreteOrStaleSdkSpec = concreteOrStaleSdkSpec;
27825
+ exports2.sdkConstraintIsOlder = sdkConstraintIsOlder;
27826
+ function parseSemver(raw) {
27827
+ const match = /^v?(\d+)\.(\d+)\.(\d+)$/.exec(raw.trim());
27828
+ if (!match)
27829
+ return null;
27830
+ return [Number(match[1]), Number(match[2]), Number(match[3])];
27831
+ }
27832
+ function compare(left, right) {
27833
+ for (let index = 0; index < 3; index += 1) {
27834
+ const diff = left[index] - right[index];
27835
+ if (diff !== 0)
27836
+ return diff;
27837
+ }
27838
+ return 0;
27839
+ }
27840
+ function caretCeiling(version) {
27841
+ const [major2, minor, patch] = version;
27842
+ if (major2 > 0)
27843
+ return [major2 + 1, 0, 0];
27844
+ if (minor > 0)
27845
+ return [major2, minor + 1, 0];
27846
+ return [major2, minor, patch + 1];
27847
+ }
27848
+ function openBounds() {
27849
+ return { min: [0, 0, 0], minInclusive: true, max: null, maxInclusive: false };
27850
+ }
27851
+ function raiseFloor(bounds, version, inclusive) {
27852
+ const diff = compare(version, bounds.min);
27853
+ if (diff > 0 || diff === 0 && bounds.minInclusive && !inclusive) {
27854
+ bounds.min = version;
27855
+ bounds.minInclusive = inclusive;
27856
+ }
27857
+ }
27858
+ function lowerCeiling(bounds, version, inclusive) {
27859
+ if (!bounds.max) {
27860
+ bounds.max = version;
27861
+ bounds.maxInclusive = inclusive;
27862
+ return;
27863
+ }
27864
+ const diff = compare(version, bounds.max);
27865
+ if (diff < 0 || diff === 0 && bounds.maxInclusive && !inclusive) {
27866
+ bounds.max = version;
27867
+ bounds.maxInclusive = inclusive;
27868
+ }
27869
+ }
27870
+ function applyComparator(bounds, token) {
27871
+ const match = /^(>=|<=|>|<|\^|~|=)?v?(\d+\.\d+\.\d+)$/.exec(token);
27872
+ if (!match)
27873
+ return false;
27874
+ const version = parseSemver(match[2]);
27875
+ if (!version)
27876
+ return false;
27877
+ const operator = match[1] ?? "=";
27878
+ if (operator === "=") {
27879
+ raiseFloor(bounds, version, true);
27880
+ lowerCeiling(bounds, version, true);
27881
+ } else if (operator === ">" || operator === ">=") {
27882
+ raiseFloor(bounds, version, operator === ">=");
27883
+ } else if (operator === "<" || operator === "<=") {
27884
+ lowerCeiling(bounds, version, operator === "<=");
27885
+ } else if (operator === "^") {
27886
+ raiseFloor(bounds, version, true);
27887
+ lowerCeiling(bounds, caretCeiling(version), false);
27888
+ } else if (operator === "~") {
27889
+ raiseFloor(bounds, version, true);
27890
+ lowerCeiling(bounds, [version[0], version[1] + 1, 0], false);
27891
+ } else {
27892
+ return false;
27893
+ }
27894
+ return true;
27895
+ }
27896
+ function clauseBounds(clause) {
27897
+ const hyphen = /^v?(\d+\.\d+\.\d+)\s+-\s+v?(\d+\.\d+\.\d+)$/.exec(clause.trim());
27898
+ if (hyphen) {
27899
+ const low = parseSemver(hyphen[1]);
27900
+ const high = parseSemver(hyphen[2]);
27901
+ if (!low || !high)
27902
+ return null;
27903
+ const bounds2 = openBounds();
27904
+ raiseFloor(bounds2, low, true);
27905
+ lowerCeiling(bounds2, high, true);
27906
+ return bounds2;
27907
+ }
27908
+ const bounds = openBounds();
27909
+ for (const token of clause.trim().split(/\s+/)) {
27910
+ if (token.length === 0)
27911
+ continue;
27912
+ if (!applyComparator(bounds, token))
27913
+ return null;
27914
+ }
27915
+ return bounds;
27916
+ }
27917
+ function clauseIsEntirelyOlder(clause, minimum) {
27918
+ const bounds = clauseBounds(clause);
27919
+ if (!bounds)
27920
+ return null;
27921
+ if (!bounds.max)
27922
+ return false;
27923
+ if (compare(bounds.min, bounds.max) > 0)
27924
+ return true;
27925
+ const diff = compare(bounds.max, minimum);
27926
+ if (diff < 0)
27927
+ return true;
27928
+ return diff === 0 && !bounds.maxInclusive;
27929
+ }
27930
+ function concreteOrStaleSdkSpec(spec, minimum) {
27931
+ if (!spec)
27932
+ return null;
27933
+ const trimmed = spec.trim();
27934
+ if (trimmed === "" || trimmed === "*" || trimmed === "latest" || trimmed.startsWith("workspace:")) {
27935
+ return null;
27936
+ }
27937
+ const exact = /^=?v?(\d+\.\d+\.\d+)$/.exec(trimmed);
27938
+ if (exact)
27939
+ return exact[1] ?? null;
27940
+ const target = parseSemver(minimum);
27941
+ if (!target)
27942
+ return null;
27943
+ const alternatives = trimmed.split("||").map((part) => part.trim()).filter((part) => part.length > 0);
27944
+ if (alternatives.length === 0)
27945
+ return null;
27946
+ for (const alternative of alternatives) {
27947
+ const older = clauseIsEntirelyOlder(alternative, target);
27948
+ if (older !== true)
27949
+ return null;
27950
+ }
27951
+ return trimmed;
27952
+ }
27953
+ function sdkConstraintIsOlder(declared, minimum) {
27954
+ if (/^v?\d+\.\d+\.\d+$/.test(declared)) {
27955
+ const installed = parseSemver(declared);
27956
+ const required = parseSemver(minimum);
27957
+ if (!installed || !required)
27958
+ return false;
27959
+ return compare(installed, required) < 0;
27960
+ }
27961
+ return concreteOrStaleSdkSpec(declared, minimum) === declared;
27962
+ }
27963
+ }
27964
+ });
27965
+
27966
+ // dist/capabilities.js
27967
+ var require_capabilities = __commonJS({
27968
+ "dist/capabilities.js"(exports2) {
27969
+ "use strict";
27970
+ Object.defineProperty(exports2, "__esModule", { value: true });
27971
+ exports2.MANAGED_FUNCTION_CAPABILITIES = exports2.MANAGED_FUNCTION_SDK_PACKAGE = exports2.MANAGED_FUNCTION_CLI_PACKAGE = void 0;
27972
+ exports2.versionIsOlder = versionIsOlder;
27973
+ exports2.sdkVersionLowerBound = sdkVersionLowerBound;
27974
+ exports2.sdkVersionFromPackageJson = sdkVersionFromPackageJson;
27975
+ exports2.isPostgresEgress = isPostgresEgress;
27976
+ exports2.formatValidationDetail = formatValidationDetail;
27977
+ var sdk_range_1 = require_sdk_range();
27978
+ exports2.MANAGED_FUNCTION_CLI_PACKAGE = "@sequenceholdings/studio-cli";
27979
+ exports2.MANAGED_FUNCTION_SDK_PACKAGE = "@sequenceholdings/managed-functions";
27980
+ exports2.MANAGED_FUNCTION_CAPABILITIES = {
27981
+ tooling: {
27982
+ cli: { package: exports2.MANAGED_FUNCTION_CLI_PACKAGE, min: "0.4.0" },
27983
+ sdk: { package: exports2.MANAGED_FUNCTION_SDK_PACKAGE, min: "0.3.0" }
27984
+ },
27985
+ features: {
27986
+ postgres_egress: {
27987
+ field: "egress",
27988
+ supported: true,
27989
+ limit: "a credentials-free postgres:// or postgresql:// URL on port 5432 with sslmode=verify-full",
27990
+ min_cli: "0.4.0",
27991
+ min_sdk: "0.3.0"
27992
+ },
27993
+ http_headers: {
27994
+ field: "invocation.headers",
27995
+ max_bytes: 32 * 1024,
27996
+ limit: "32768 bytes (16384 bytes is Node's default and returns HTTP 431)",
27997
+ min_cli: "0.4.0",
27998
+ min_sdk: "0.3.0"
27999
+ },
28000
+ invoke_timeout: {
28001
+ field: "limits.timeout_seconds",
28002
+ max_seconds: 3600,
28003
+ legacy_sdk_max_seconds: 300,
28004
+ limit: "1 to 3600 seconds; SDK clients older than the minimum stop at 300 seconds",
28005
+ min_cli: "0.4.0",
28006
+ min_sdk: "0.3.0"
28007
+ }
28008
+ }
28009
+ };
28010
+ function versionIsOlder(installed, required) {
28011
+ const parse = (value) => value.replace(/^v/, "").split("-")[0].split(".").map((part) => {
28012
+ const parsed = Number.parseInt(part, 10);
28013
+ return Number.isFinite(parsed) ? parsed : 0;
28014
+ });
28015
+ const left = parse(installed);
28016
+ const right = parse(required);
28017
+ for (let index = 0; index < 3; index += 1) {
28018
+ const diff = (left[index] ?? 0) - (right[index] ?? 0);
28019
+ if (diff !== 0)
28020
+ return diff < 0;
28021
+ }
28022
+ return false;
28023
+ }
28024
+ function sdkVersionLowerBound(spec) {
28025
+ return (0, sdk_range_1.concreteOrStaleSdkSpec)(spec, exports2.MANAGED_FUNCTION_CAPABILITIES.features.invoke_timeout.min_sdk);
28026
+ }
28027
+ function sdkVersionFromPackageJson(raw) {
28028
+ let parsed;
28029
+ try {
28030
+ parsed = JSON.parse(raw);
28031
+ } catch {
28032
+ return null;
28033
+ }
28034
+ if (!parsed || typeof parsed !== "object")
28035
+ return null;
28036
+ const dependencies = Reflect.get(parsed, "dependencies");
28037
+ const devDependencies = Reflect.get(parsed, "devDependencies");
28038
+ return sdkVersionLowerBound(dependencySpec(dependencies) ?? dependencySpec(devDependencies));
28039
+ }
28040
+ function dependencySpec(block) {
28041
+ if (!block || typeof block !== "object")
28042
+ return void 0;
28043
+ const value = Reflect.get(block, exports2.MANAGED_FUNCTION_SDK_PACKAGE);
28044
+ return typeof value === "string" ? value : void 0;
28045
+ }
28046
+ function isPostgresEgress(entry) {
28047
+ return /^postgres(ql)?:/i.test(entry.trim());
28048
+ }
28049
+ function formatValidationDetail(issues) {
28050
+ const shown = issues.slice(0, 8).map((issue) => {
28051
+ const path = (issue.path ?? []).map((part) => String(part)).filter((part) => part.length > 0).join(".");
28052
+ const message = issue.message?.trim() || "invalid";
28053
+ return path ? `${path}: ${message}` : message;
28054
+ });
28055
+ if (shown.length === 0)
28056
+ return "Validation error";
28057
+ const extra = issues.length > shown.length ? ` (+${issues.length - shown.length} more)` : "";
28058
+ return `Validation error: ${shown.join("; ")}${extra}`;
28059
+ }
28060
+ }
28061
+ });
28062
+
28063
+ // dist/deployed-policy.js
28064
+ var require_deployed_policy = __commonJS({
28065
+ "dist/deployed-policy.js"(exports2) {
28066
+ "use strict";
28067
+ Object.defineProperty(exports2, "__esModule", { value: true });
28068
+ exports2.parseDeployedPolicy = parseDeployedPolicy;
28069
+ function isLimitCatalog(value) {
28070
+ if (!value || typeof value !== "object")
28071
+ return false;
28072
+ const workload = Reflect.get(value, "workload");
28073
+ return !!workload && typeof workload === "object";
28074
+ }
28075
+ function isCapabilities(value) {
28076
+ if (!value || typeof value !== "object")
28077
+ return false;
28078
+ const tooling = Reflect.get(value, "tooling");
28079
+ const features = Reflect.get(value, "features");
28080
+ if (!tooling || typeof tooling !== "object" || !features || typeof features !== "object")
28081
+ return false;
28082
+ const cli = Reflect.get(tooling, "cli");
28083
+ const sdk = Reflect.get(tooling, "sdk");
28084
+ return hasPackageMin(cli) && hasPackageMin(sdk);
28085
+ }
28086
+ function hasPackageMin(value) {
28087
+ if (!value || typeof value !== "object")
28088
+ return false;
28089
+ return typeof Reflect.get(value, "package") === "string" && typeof Reflect.get(value, "min") === "string";
28090
+ }
28091
+ function parseDeployedPolicy(body) {
28092
+ if (!body || typeof body !== "object")
28093
+ return { limits: null, capabilities: null };
28094
+ const limits = Reflect.get(body, "limits");
28095
+ const capabilities = Reflect.get(body, "capabilities");
28096
+ return {
28097
+ limits: isLimitCatalog(limits) ? limits : null,
28098
+ capabilities: isCapabilities(capabilities) ? normalizeCapabilities(capabilities) : null
28099
+ };
28100
+ }
28101
+ function normalizeCapabilities(value) {
28102
+ const features = value.features;
28103
+ return {
28104
+ tooling: value.tooling,
28105
+ features: {
28106
+ postgres_egress: normalizePostgres(features.postgres_egress),
28107
+ http_headers: normalizeHeaders(features.http_headers),
28108
+ invoke_timeout: normalizeTimeout(features.invoke_timeout)
28109
+ }
28110
+ };
28111
+ }
28112
+ function normalizePostgres(value) {
28113
+ if (!value || typeof value.supported !== "boolean" || typeof value.limit !== "string")
28114
+ return void 0;
28115
+ if (typeof value.min_cli !== "string" || typeof value.min_sdk !== "string")
28116
+ return void 0;
28117
+ return {
28118
+ field: typeof value.field === "string" ? value.field : "egress",
28119
+ supported: value.supported,
28120
+ limit: value.limit,
28121
+ min_cli: value.min_cli,
28122
+ min_sdk: value.min_sdk
28123
+ };
28124
+ }
28125
+ function normalizeHeaders(value) {
28126
+ if (!value || typeof value.max_bytes !== "number" || typeof value.limit !== "string")
28127
+ return void 0;
28128
+ if (typeof value.min_cli !== "string" || typeof value.min_sdk !== "string")
28129
+ return void 0;
28130
+ return {
28131
+ field: typeof value.field === "string" ? value.field : "invocation.headers",
28132
+ max_bytes: value.max_bytes,
28133
+ limit: value.limit,
28134
+ min_cli: value.min_cli,
28135
+ min_sdk: value.min_sdk
28136
+ };
28137
+ }
28138
+ function normalizeTimeout(value) {
28139
+ if (!value || typeof value.limit !== "string")
28140
+ return void 0;
28141
+ if (typeof value.max_seconds !== "number" || typeof value.legacy_sdk_max_seconds !== "number")
28142
+ return void 0;
28143
+ if (typeof value.min_cli !== "string" || typeof value.min_sdk !== "string")
28144
+ return void 0;
28145
+ return {
28146
+ field: typeof value.field === "string" ? value.field : "limits.timeout_seconds",
28147
+ max_seconds: value.max_seconds,
28148
+ legacy_sdk_max_seconds: value.legacy_sdk_max_seconds,
28149
+ limit: value.limit,
28150
+ min_cli: value.min_cli,
28151
+ min_sdk: value.min_sdk
28152
+ };
28153
+ }
28154
+ }
28155
+ });
28156
+
28157
+ // dist/preflight.js
28158
+ var require_preflight = __commonJS({
28159
+ "dist/preflight.js"(exports2) {
28160
+ "use strict";
28161
+ Object.defineProperty(exports2, "__esModule", { value: true });
28162
+ exports2.preflightManagedFunction = preflightManagedFunction;
28163
+ var capabilities_1 = require_capabilities();
28164
+ var sdk_range_1 = require_sdk_range();
28165
+ var WORKLOAD_FIELDS = [
28166
+ "memory_mb",
28167
+ "timeout_seconds",
28168
+ "min_instances",
28169
+ "max_instances",
28170
+ "invoke_rate_per_minute",
28171
+ "max_response_bytes",
28172
+ "concurrency"
28173
+ ];
28174
+ function preflightManagedFunction({ manifest, limits, capabilities, cliVersion, sdkVersion }) {
28175
+ const tooling = capabilities?.tooling ?? capabilities_1.MANAGED_FUNCTION_CAPABILITIES.tooling;
28176
+ const issues = [];
28177
+ checkWorkload({ manifest, limits, tooling, cliVersion, sdkVersion, issues });
28178
+ checkPostgres({ manifest, capabilities, tooling, cliVersion, sdkVersion, issues });
28179
+ checkHeaders({ manifest, capabilities, tooling, cliVersion, sdkVersion, issues });
28180
+ checkSdkTimeout({ manifest, limits, capabilities, tooling, cliVersion, sdkVersion, issues });
28181
+ return issues;
28182
+ }
28183
+ function issue({ field, problem, limit, tooling, requiredCli, requiredSdk, cliVersion, sdkVersion }) {
28184
+ const installedSdk = sdkVersion ?? "not declared";
28185
+ return {
28186
+ field,
28187
+ limit,
28188
+ requiredCli,
28189
+ requiredSdk,
28190
+ message: `${field}: ${problem} Supported limit: ${limit}. Requires ${tooling.cli.package} >= ${requiredCli} (installed ${cliVersion}) and ${tooling.sdk.package} >= ${requiredSdk} (installed ${installedSdk}).`
28191
+ };
28192
+ }
28193
+ function numericCap(entry) {
28194
+ if (!entry || typeof entry !== "object")
28195
+ return null;
28196
+ const min = Reflect.get(entry, "min");
28197
+ const max = Reflect.get(entry, "max");
28198
+ const unit = Reflect.get(entry, "unit");
28199
+ if (typeof min !== "number" || typeof max !== "number")
28200
+ return null;
28201
+ return { min, max, unit: typeof unit === "string" ? unit : void 0 };
28202
+ }
28203
+ function checkWorkload({ manifest, limits, tooling, cliVersion, sdkVersion, issues }) {
28204
+ const workload = limits?.workload;
28205
+ if (!workload)
28206
+ return;
28207
+ const declared = manifest.limits;
28208
+ if (!declared)
28209
+ return;
28210
+ for (const name of WORKLOAD_FIELDS) {
28211
+ const value = declared[name];
28212
+ if (typeof value !== "number")
28213
+ continue;
28214
+ const cap = numericCap(workload[name]);
28215
+ if (!cap)
28216
+ continue;
28217
+ if (Number.isInteger(value) && value >= cap.min && value <= cap.max)
28218
+ continue;
28219
+ const unit = cap.unit ? ` ${cap.unit}` : "";
28220
+ issues.push(issue({
28221
+ field: `limits.${name}`,
28222
+ problem: `${value} is outside the range this deployment enforces`,
28223
+ limit: `${cap.min} to ${cap.max}${unit}`,
28224
+ tooling,
28225
+ requiredCli: tooling.cli.min,
28226
+ requiredSdk: tooling.sdk.min,
28227
+ cliVersion,
28228
+ sdkVersion
28229
+ }));
28230
+ }
28231
+ const cpu = declared.cpu;
28232
+ const cpuCap = numericCap(workload.cpu);
28233
+ if (cpu === void 0 || cpu === "auto" || !cpuCap)
28234
+ return;
28235
+ if (typeof cpu === "number" && Number.isInteger(cpu) && cpu >= cpuCap.min && cpu <= cpuCap.max)
28236
+ return;
28237
+ issues.push(issue({
28238
+ field: "limits.cpu",
28239
+ problem: `${String(cpu)} is outside the range this deployment enforces`,
28240
+ limit: `${cpuCap.min} to ${cpuCap.max}, or auto`,
28241
+ tooling,
28242
+ requiredCli: tooling.cli.min,
28243
+ requiredSdk: tooling.sdk.min,
28244
+ cliVersion,
28245
+ sdkVersion
28246
+ }));
28247
+ }
28248
+ function checkPostgres({ manifest, capabilities, tooling, cliVersion, sdkVersion, issues }) {
28249
+ const feature = capabilities?.features.postgres_egress;
28250
+ if (!feature)
28251
+ return;
28252
+ const entries = manifest.egress ?? [];
28253
+ entries.forEach((entry, index) => {
28254
+ if (!(0, capabilities_1.isPostgresEgress)(entry))
28255
+ return;
28256
+ const field = `egress[${index}]`;
28257
+ if (!feature.supported) {
28258
+ issues.push(issue({
28259
+ field,
28260
+ problem: "PostgreSQL egress is not supported by this deployment",
28261
+ limit: "hostnames, http(s) URLs, and public IPv4 CIDRs",
28262
+ tooling,
28263
+ requiredCli: feature.min_cli,
28264
+ requiredSdk: feature.min_sdk,
28265
+ cliVersion,
28266
+ sdkVersion
28267
+ }));
28268
+ return;
28269
+ }
28270
+ if ((0, capabilities_1.versionIsOlder)(cliVersion, feature.min_cli)) {
28271
+ issues.push(issue({
28272
+ field,
28273
+ problem: "this CLI rejects PostgreSQL egress that this deployment supports",
28274
+ limit: feature.limit,
28275
+ tooling,
28276
+ requiredCli: feature.min_cli,
28277
+ requiredSdk: feature.min_sdk,
28278
+ cliVersion,
28279
+ sdkVersion
28280
+ }));
28281
+ }
28282
+ });
28283
+ }
28284
+ function needsWideHeaders(manifest) {
28285
+ const data = manifest.capabilities?.data;
28286
+ const storage = manifest.capabilities?.storage;
28287
+ const hasData = !!data && Object.keys(data).length > 0;
28288
+ const hasStorage = !!storage && typeof storage === "object" && Object.keys(storage).length > 0;
28289
+ return hasData || hasStorage;
28290
+ }
28291
+ function checkHeaders({ manifest, capabilities, tooling, cliVersion, sdkVersion, issues }) {
28292
+ const feature = capabilities?.features.http_headers;
28293
+ if (!feature || !needsWideHeaders(manifest))
28294
+ return;
28295
+ const supported = capabilities_1.MANAGED_FUNCTION_CAPABILITIES.features.http_headers.max_bytes;
28296
+ if (feature.max_bytes >= supported)
28297
+ return;
28298
+ issues.push(issue({
28299
+ field: feature.field,
28300
+ problem: `invocation headers for capabilities.data or capabilities.storage exceed ${feature.max_bytes} bytes and will fail with HTTP 431`,
28301
+ limit: feature.limit,
28302
+ tooling,
28303
+ requiredCli: feature.min_cli,
28304
+ requiredSdk: feature.min_sdk,
28305
+ cliVersion,
28306
+ sdkVersion
28307
+ }));
28308
+ }
28309
+ function checkSdkTimeout({ manifest, limits, capabilities, tooling, cliVersion, sdkVersion, issues }) {
28310
+ const timeout = manifest.limits?.timeout_seconds;
28311
+ if (typeof timeout !== "number" || !sdkVersion)
28312
+ return;
28313
+ const feature = capabilities?.features.invoke_timeout ?? capabilities_1.MANAGED_FUNCTION_CAPABILITIES.features.invoke_timeout;
28314
+ if (!(0, sdk_range_1.sdkConstraintIsOlder)(sdkVersion, feature.min_sdk))
28315
+ return;
28316
+ if (timeout <= feature.legacy_sdk_max_seconds)
28317
+ return;
28318
+ const platformMax = numericCap(limits?.workload?.timeout_seconds)?.max ?? feature.max_seconds;
28319
+ issues.push(issue({
28320
+ field: feature.field,
28321
+ problem: `${timeout} seconds exceeds the installed SDK's ${feature.legacy_sdk_max_seconds} second client cap, behind the platform limit of ${platformMax} seconds`,
28322
+ limit: feature.limit,
28323
+ tooling,
28324
+ requiredCli: feature.min_cli,
28325
+ requiredSdk: feature.min_sdk,
28326
+ cliVersion,
28327
+ sdkVersion
28328
+ }));
28329
+ }
28330
+ }
28331
+ });
28332
+
27749
28333
  // dist/config.js
27750
28334
  var require_config2 = __commonJS({
27751
28335
  "dist/config.js"(exports2) {
27752
28336
  "use strict";
27753
28337
  Object.defineProperty(exports2, "__esModule", { value: true });
27754
- exports2.cacheManifestSchema = exports2.CACHE_MAX_TTL_SECONDS = exports2.managedFunctionWorkloadLimitsSchema = exports2.MF_LIMITS_DEFAULTS = exports2.MF_LIMITS_CAPS = exports2.MANAGED_FUNCTION_LIMITS = exports2.shouldReportAtlasHttp = void 0;
28338
+ exports2.cacheManifestSchema = exports2.CACHE_MAX_TTL_SECONDS = exports2.preflightManagedFunction = exports2.parseDeployedPolicy = exports2.versionIsOlder = exports2.sdkVersionLowerBound = exports2.sdkVersionFromPackageJson = exports2.isPostgresEgress = exports2.formatValidationDetail = exports2.MANAGED_FUNCTION_SDK_PACKAGE = exports2.MANAGED_FUNCTION_CLI_PACKAGE = exports2.MANAGED_FUNCTION_CAPABILITIES = exports2.managedFunctionWorkloadLimitsSchema = exports2.MF_LIMITS_DEFAULTS = exports2.MF_LIMITS_CAPS = exports2.MANAGED_FUNCTION_LIMITS = exports2.shouldReportAtlasHttp = void 0;
27755
28339
  exports2.readCacheConfiguration = readCacheConfiguration;
27756
28340
  var http_tracing_1 = require_http_tracing();
27757
28341
  Object.defineProperty(exports2, "shouldReportAtlasHttp", { enumerable: true, get: function() {
@@ -27772,6 +28356,39 @@ var require_config2 = __commonJS({
27772
28356
  Object.defineProperty(exports2, "managedFunctionWorkloadLimitsSchema", { enumerable: true, get: function() {
27773
28357
  return limits_2.managedFunctionWorkloadLimitsSchema;
27774
28358
  } });
28359
+ var capabilities_1 = require_capabilities();
28360
+ Object.defineProperty(exports2, "MANAGED_FUNCTION_CAPABILITIES", { enumerable: true, get: function() {
28361
+ return capabilities_1.MANAGED_FUNCTION_CAPABILITIES;
28362
+ } });
28363
+ Object.defineProperty(exports2, "MANAGED_FUNCTION_CLI_PACKAGE", { enumerable: true, get: function() {
28364
+ return capabilities_1.MANAGED_FUNCTION_CLI_PACKAGE;
28365
+ } });
28366
+ Object.defineProperty(exports2, "MANAGED_FUNCTION_SDK_PACKAGE", { enumerable: true, get: function() {
28367
+ return capabilities_1.MANAGED_FUNCTION_SDK_PACKAGE;
28368
+ } });
28369
+ Object.defineProperty(exports2, "formatValidationDetail", { enumerable: true, get: function() {
28370
+ return capabilities_1.formatValidationDetail;
28371
+ } });
28372
+ Object.defineProperty(exports2, "isPostgresEgress", { enumerable: true, get: function() {
28373
+ return capabilities_1.isPostgresEgress;
28374
+ } });
28375
+ Object.defineProperty(exports2, "sdkVersionFromPackageJson", { enumerable: true, get: function() {
28376
+ return capabilities_1.sdkVersionFromPackageJson;
28377
+ } });
28378
+ Object.defineProperty(exports2, "sdkVersionLowerBound", { enumerable: true, get: function() {
28379
+ return capabilities_1.sdkVersionLowerBound;
28380
+ } });
28381
+ Object.defineProperty(exports2, "versionIsOlder", { enumerable: true, get: function() {
28382
+ return capabilities_1.versionIsOlder;
28383
+ } });
28384
+ var deployed_policy_1 = require_deployed_policy();
28385
+ Object.defineProperty(exports2, "parseDeployedPolicy", { enumerable: true, get: function() {
28386
+ return deployed_policy_1.parseDeployedPolicy;
28387
+ } });
28388
+ var preflight_1 = require_preflight();
28389
+ Object.defineProperty(exports2, "preflightManagedFunction", { enumerable: true, get: function() {
28390
+ return preflight_1.preflightManagedFunction;
28391
+ } });
27775
28392
  var limits = limits_1.MANAGED_FUNCTION_LIMITS.cache;
27776
28393
  exports2.CACHE_MAX_TTL_SECONDS = limits.default_ttl_seconds.max;
27777
28394
  exports2.cacheManifestSchema = zod_12.z.object({