@wayai/cli 0.3.330 → 0.3.331

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.js CHANGED
@@ -6314,23 +6314,6 @@ var init_chunk_63UWXV4T = __esm({
6314
6314
  }
6315
6315
  });
6316
6316
 
6317
- // ../../packages/core/dist/chunk-WDAXZDJO.js
6318
- var TOOLSET_ANSWER_PERSON_PARTIES, toolsetAnswerPersonSchema, toolsetAnswerPersonsSchema;
6319
- var init_chunk_WDAXZDJO = __esm({
6320
- "../../packages/core/dist/chunk-WDAXZDJO.js"() {
6321
- "use strict";
6322
- init_chunk_SSPK6ISL();
6323
- init_chunk_AHISKXHA();
6324
- init_zod();
6325
- TOOLSET_ANSWER_PERSON_PARTIES = ["requester", "originator", "initiator", "delegator"];
6326
- toolsetAnswerPersonSchema = external_exports.object({
6327
- party: external_exports.enum(TOOLSET_ANSWER_PERSON_PARTIES),
6328
- person_id: rekorPersonIdSchema
6329
- }).strict();
6330
- toolsetAnswerPersonsSchema = external_exports.array(toolsetAnswerPersonSchema).min(1).max(REKOR_MAX_PERSON_PARTIES);
6331
- }
6332
- });
6333
-
6334
6317
  // ../../packages/core/dist/chunk-ZC6YGHNX.js
6335
6318
  var updateUserBody, updateProfileBody, pathnameRegex, updatePreferencesBody, registerPushTokenBody, deletePushTokenQuery, recordAiDisclosureAcceptanceBody, activityQuery, deletionModeSchema, deletionRequestBody;
6336
6319
  var init_chunk_ZC6YGHNX = __esm({
@@ -6414,976 +6397,291 @@ var init_chunk_HIGKBEPF = __esm({
6414
6397
  }
6415
6398
  });
6416
6399
 
6417
- // ../../packages/core/dist/chunk-5FO3GNKP.js
6418
- var DATA_PROXY_MOUNT, DATA_PROXY_PREFIX, BASE_DESTRUCTION_MOUNT, BASE_DESTRUCTION_PREFIX, BASE_DESTRUCTION_CONFIRM_PATH, COMMUNITY_EMAIL_UNSUBSCRIBE_PATH, CONTACT_BOOK_EMAIL_UNSUBSCRIBE_PATH, AUTOMATION_WEBHOOK_MOUNT, MANAGED_AGENTS_WEBHOOK_MOUNT, TELEGRAM_VAULT_WEBHOOK_PATH;
6419
- var init_chunk_5FO3GNKP = __esm({
6420
- "../../packages/core/dist/chunk-5FO3GNKP.js"() {
6400
+ // ../../packages/core/dist/chunk-IPDOHAZ5.js
6401
+ var reportSourceSchema, intakeReportSourceSchema, reportClassificationSchema, reportStatusSchema, reportLocaleSchema, reportMessageAuthorRoleSchema, reportMessageSchema, sentryRefStatusSchema, createReportBody, editReportBody, reporterReportSummarySchema, reporterListResponseSchema, getReportResponseSchema, reporterTransitionResponseSchema, contestReportBody, reporterListQuery, listReportsQuery, GITHUB_ISSUE_URL_REGEX, githubIssueUrlSchema, transitionReportBody, groupReportsBody, holdReportBody;
6402
+ var init_chunk_IPDOHAZ5 = __esm({
6403
+ "../../packages/core/dist/chunk-IPDOHAZ5.js"() {
6421
6404
  "use strict";
6422
- DATA_PROXY_MOUNT = "/data";
6423
- DATA_PROXY_PREFIX = `/api${DATA_PROXY_MOUNT}`;
6424
- BASE_DESTRUCTION_MOUNT = "/bases";
6425
- BASE_DESTRUCTION_PREFIX = `/api${BASE_DESTRUCTION_MOUNT}`;
6426
- BASE_DESTRUCTION_CONFIRM_PATH = `${BASE_DESTRUCTION_PREFIX}/destruction/confirm`;
6427
- COMMUNITY_EMAIL_UNSUBSCRIBE_PATH = "/api/communities/email-unsubscribe";
6428
- CONTACT_BOOK_EMAIL_UNSUBSCRIBE_PATH = "/api/contact-book/email-unsubscribe";
6429
- AUTOMATION_WEBHOOK_MOUNT = "/webhooks/automations";
6430
- MANAGED_AGENTS_WEBHOOK_MOUNT = "/webhooks/managed-agents";
6431
- TELEGRAM_VAULT_WEBHOOK_PATH = "/webhooks/telegram/vault";
6405
+ init_chunk_HZ6CADSY();
6406
+ init_zod();
6407
+ reportSourceSchema = external_exports.enum(["sentry", "cli", "review", "security_audit"]);
6408
+ intakeReportSourceSchema = external_exports.enum(["cli", "review", "security_audit"]);
6409
+ reportClassificationSchema = external_exports.enum(["bug", "flaky_test", "security", "enhancement"]);
6410
+ reportStatusSchema = external_exports.enum([
6411
+ "pending",
6412
+ "grouped",
6413
+ "escalated",
6414
+ "shipped",
6415
+ "contested",
6416
+ "addressed",
6417
+ "dismissed"
6418
+ ]);
6419
+ reportLocaleSchema = external_exports.enum(["en", "pt", "es"]);
6420
+ reportMessageAuthorRoleSchema = external_exports.enum(["reporter", "triage", "fixer", "system"]);
6421
+ reportMessageSchema = external_exports.object({
6422
+ message_id: external_exports.string(),
6423
+ author_role: reportMessageAuthorRoleSchema,
6424
+ /** The status transition this note accompanied (e.g. 'shipped'); null for a free/system note. */
6425
+ transition: external_exports.string().nullable(),
6426
+ body: external_exports.string(),
6427
+ created_at: timestampSchema,
6428
+ /**
6429
+ * Visibility: `false` = reporter-facing (the default for every narrative entry); `true` =
6430
+ * triage-internal (e.g. a `hold` rationale) — surfaced to platform admins only and NEVER
6431
+ * returned on the reporter read path. The reporter's `GET /api/reports/:id` filters these out.
6432
+ */
6433
+ internal: external_exports.boolean()
6434
+ });
6435
+ sentryRefStatusSchema = external_exports.enum(["valid", "not_found", "mismatch", "unverified"]);
6436
+ createReportBody = external_exports.object({
6437
+ title: external_exports.string().min(5).max(256),
6438
+ description: external_exports.string().min(10).max(5e3),
6439
+ steps_to_reproduce: external_exports.string().max(3e3).optional(),
6440
+ error_message: external_exports.string().max(2e3).optional(),
6441
+ // Taxonomy (server defaults: source=cli, classification=bug when absent).
6442
+ source: intakeReportSourceSchema.optional(),
6443
+ classification: reportClassificationSchema.optional(),
6444
+ // Stable dedup key (e.g. "<file>::<test>" for flaky, "<file>:<line>" for
6445
+ // security). When present, the fingerprint uses it instead of the body hash.
6446
+ dedup_key: external_exports.string().min(1).max(256).optional(),
6447
+ // Context fields (auto-captured by the CLI)
6448
+ organization_id: external_exports.string().optional(),
6449
+ hub_id: external_exports.string().uuid().optional(),
6450
+ hub_name: external_exports.string().max(256).optional(),
6451
+ conversation_id: external_exports.string().uuid().optional(),
6452
+ agent_id: external_exports.string().uuid().optional(),
6453
+ agent_name: external_exports.string().max(256).optional(),
6454
+ client_version: external_exports.string().max(64).optional(),
6455
+ additional_context: external_exports.string().max(2e3).optional()
6456
+ });
6457
+ editReportBody = external_exports.object({
6458
+ title: external_exports.string().min(5).max(256).optional(),
6459
+ description: external_exports.string().min(10).max(5e3).optional(),
6460
+ steps_to_reproduce: external_exports.string().max(3e3).optional(),
6461
+ error_message: external_exports.string().max(2e3).optional(),
6462
+ additional_context: external_exports.string().max(2e3).optional()
6463
+ }).strict().refine((b) => Object.keys(b).length > 0, {
6464
+ message: "at least one field must be provided"
6465
+ });
6466
+ reporterReportSummarySchema = external_exports.object({
6467
+ report_id: external_exports.string(),
6468
+ title: external_exports.string(),
6469
+ description: external_exports.string(),
6470
+ classification: reportClassificationSchema,
6471
+ status: reportStatusSchema,
6472
+ created_at: timestampSchema,
6473
+ triaged_at: timestampSchema.nullable(),
6474
+ resolved_at: timestampSchema.nullable(),
6475
+ /** How many times the reporter has contested (gates the hard cap). */
6476
+ contest_count: external_exports.number(),
6477
+ /** True once triage issued a non-contestable (final) dismissal. */
6478
+ dismissal_final: external_exports.boolean()
6479
+ });
6480
+ reporterListResponseSchema = external_exports.object({
6481
+ data: external_exports.array(reporterReportSummarySchema)
6482
+ });
6483
+ getReportResponseSchema = external_exports.object({
6484
+ report: reporterReportSummarySchema,
6485
+ messages: external_exports.array(reportMessageSchema)
6486
+ });
6487
+ reporterTransitionResponseSchema = external_exports.object({
6488
+ report: reporterReportSummarySchema
6489
+ });
6490
+ contestReportBody = external_exports.object({
6491
+ reason: external_exports.string().min(1).max(5e3)
6492
+ });
6493
+ reporterListQuery = external_exports.object({
6494
+ status: reportStatusSchema.optional()
6495
+ });
6496
+ listReportsQuery = external_exports.object({
6497
+ status: reportStatusSchema.optional(),
6498
+ source: reportSourceSchema.optional(),
6499
+ limit: external_exports.coerce.number().int().min(1).max(200).optional(),
6500
+ offset: external_exports.coerce.number().int().min(0).optional(),
6501
+ /** ISO 8601 lower bound on created_at. */
6502
+ since: external_exports.string().datetime().optional(),
6503
+ /**
6504
+ * ISO 8601 lower bound on resolution time — "what did we resolve recently", which `since`
6505
+ * (a created_at filter) cannot answer for a long-lived report resolved yesterday. Implies
6506
+ * a terminal status (`addressed`/`dismissed`) and orders on that same axis.
6507
+ */
6508
+ resolved_since: external_exports.string().datetime().optional()
6509
+ });
6510
+ GITHUB_ISSUE_URL_REGEX = /^https:\/\/github\.com\/[^/]+\/[^/]+\/issues\/\d+(?:[/?#]|$)/;
6511
+ githubIssueUrlSchema = external_exports.string().url().refine((u) => GITHUB_ISSUE_URL_REGEX.test(u), {
6512
+ message: "must be an https://github.com/<owner>/<repo>/issues/<number> URL"
6513
+ });
6514
+ transitionReportBody = external_exports.discriminatedUnion("target", [
6515
+ external_exports.object({
6516
+ target: external_exports.literal("escalated"),
6517
+ gh_issue_url: githubIssueUrlSchema,
6518
+ ai_verdict: external_exports.string().max(2e3).optional()
6519
+ }),
6520
+ external_exports.object({
6521
+ target: external_exports.literal("shipped"),
6522
+ note: external_exports.string().min(1).max(2e3).optional()
6523
+ }),
6524
+ external_exports.object({
6525
+ target: external_exports.literal("addressed")
6526
+ }),
6527
+ external_exports.object({
6528
+ target: external_exports.literal("dismissed"),
6529
+ dismissal_reason: external_exports.string().min(1).max(5e3),
6530
+ ai_verdict: external_exports.string().max(2e3).optional(),
6531
+ final: external_exports.boolean().optional()
6532
+ })
6533
+ ]);
6534
+ groupReportsBody = external_exports.object({
6535
+ member_ids: external_exports.array(external_exports.string().uuid()).min(1).max(100)
6536
+ });
6537
+ holdReportBody = external_exports.object({
6538
+ reason: external_exports.string().min(1).max(5e3)
6539
+ });
6432
6540
  }
6433
6541
  });
6434
6542
 
6435
- // ../../packages/core/dist/chunk-7AYJHO5P.js
6436
- function matchPath(pattern, path46) {
6437
- const pathSegments2 = path46.replace(/\/$/, "").split("/");
6438
- const isPrefix = pattern.endsWith("/*");
6439
- const patternSegments = (isPrefix ? pattern.slice(0, -2) : pattern).split("/");
6440
- if (isPrefix ? pathSegments2.length < patternSegments.length : pathSegments2.length !== patternSegments.length) {
6441
- return false;
6543
+ // ../../packages/core/dist/chunk-KEN2DASI.js
6544
+ var SECOND_FACTOR_TIERS, secondFactorTier, META_ENTITY_ID_PATTERN, metaEntityId, whatsappCallbackBody, authMeResponse, wsTicketResponse, sessionCheckResponse, logoutResponse, magicCodeSendBody, magicCodeSendResponse, magicCodeVerifyBody, magicCodeVerifyResponse, passwordLoginBody, normalizeEmail, REVIEW_ACCOUNT_EMAILS;
6545
+ var init_chunk_KEN2DASI = __esm({
6546
+ "../../packages/core/dist/chunk-KEN2DASI.js"() {
6547
+ "use strict";
6548
+ init_zod();
6549
+ SECOND_FACTOR_TIERS = ["off", "settings"];
6550
+ secondFactorTier = external_exports.enum(SECOND_FACTOR_TIERS);
6551
+ META_ENTITY_ID_PATTERN = /^\d{1,32}$/;
6552
+ metaEntityId = external_exports.string().regex(META_ENTITY_ID_PATTERN, "must be a numeric Meta entity id");
6553
+ whatsappCallbackBody = external_exports.object({
6554
+ state: external_exports.string().min(1, "state is required"),
6555
+ code: external_exports.string().optional(),
6556
+ access_token: external_exports.string().optional(),
6557
+ user_id: external_exports.string().optional(),
6558
+ /**
6559
+ * The phone number and WABA the operator actually picked in Meta's Embedded
6560
+ * Signup popup (posted to the opener as `WA_EMBEDDED_SIGNUP`). Optional:
6561
+ * older clients, and the redirect-based flow, never see that event and fall
6562
+ * back to discovery.
6563
+ */
6564
+ phone_number_id: metaEntityId.optional(),
6565
+ waba_id: metaEntityId.optional()
6566
+ }).refine(
6567
+ (data) => !!data.access_token || !!data.code,
6568
+ { message: "Missing required parameters: state and either access_token or code" }
6569
+ );
6570
+ authMeResponse = external_exports.object({
6571
+ user_id: external_exports.string(),
6572
+ email: external_exports.string(),
6573
+ org_id: external_exports.string().nullable(),
6574
+ is_platform_admin: external_exports.boolean()
6575
+ });
6576
+ wsTicketResponse = external_exports.object({
6577
+ ticket: external_exports.string(),
6578
+ /** Seconds until the ticket expires if unconsumed. */
6579
+ expires_in: external_exports.number()
6580
+ });
6581
+ sessionCheckResponse = external_exports.object({
6582
+ valid: external_exports.literal(true)
6583
+ });
6584
+ logoutResponse = external_exports.object({
6585
+ success: external_exports.literal(true)
6586
+ });
6587
+ magicCodeSendBody = external_exports.object({
6588
+ email: external_exports.string().email("Invalid email").max(254)
6589
+ // RFC 5321 max; bounds the request payload
6590
+ });
6591
+ magicCodeSendResponse = external_exports.object({
6592
+ success: external_exports.literal(true)
6593
+ });
6594
+ magicCodeVerifyBody = external_exports.object({
6595
+ email: external_exports.string().email("Invalid email").max(254),
6596
+ // RFC 5321 max; bounds the request payload
6597
+ code: external_exports.string().min(1, "Code is required").max(12)
6598
+ // WorkOS sends a 6-digit code; bound the input
6599
+ });
6600
+ magicCodeVerifyResponse = external_exports.object({
6601
+ access_token: external_exports.string(),
6602
+ refresh_token: external_exports.string()
6603
+ });
6604
+ passwordLoginBody = external_exports.object({
6605
+ email: external_exports.string().email("Invalid email").max(254),
6606
+ // RFC 5321 max; bounds the request payload
6607
+ password: external_exports.string().min(1, "Password is required").max(128)
6608
+ // bound the payload; WorkOS validates
6609
+ });
6610
+ normalizeEmail = (email) => email.trim().toLowerCase();
6611
+ REVIEW_ACCOUNT_EMAILS = new Set(
6612
+ ["apple.review@wayai.pro", "play.review@wayai.pro", "microsoft.review@wayai.pro", "meta.review@wayai.pro"].map(
6613
+ normalizeEmail
6614
+ )
6615
+ );
6442
6616
  }
6443
- return patternSegments.every((segment, i) => segment === "*" ? pathSegments2[i] !== "" : segment === pathSegments2[i]);
6444
- }
6445
- function getEndpointConfig(path46) {
6446
- for (const excluded of EXCLUDED_PATHS) {
6447
- if (matchPath(excluded, path46)) {
6448
- return null;
6449
- }
6617
+ });
6618
+
6619
+ // ../../packages/core/dist/chunk-PFGVH2CX.js
6620
+ var secondFactorCode, secondFactorRecoveryCode, secondFactorCodeBody, secondFactorRecoveryBody, secondFactorDisableBody, setOrgSecondFactorBody;
6621
+ var init_chunk_PFGVH2CX = __esm({
6622
+ "../../packages/core/dist/chunk-PFGVH2CX.js"() {
6623
+ "use strict";
6624
+ init_chunk_KEN2DASI();
6625
+ init_zod();
6626
+ secondFactorCode = external_exports.string().regex(/^\d{6}$/, "Enter the 6-digit code");
6627
+ secondFactorRecoveryCode = external_exports.string().min(1, "Enter a recovery code").max(64);
6628
+ secondFactorCodeBody = external_exports.object({ code: secondFactorCode });
6629
+ secondFactorRecoveryBody = external_exports.object({ recovery_code: secondFactorRecoveryCode });
6630
+ secondFactorDisableBody = external_exports.union([
6631
+ external_exports.object({ code: secondFactorCode, recovery_code: external_exports.undefined().optional() }),
6632
+ external_exports.object({ recovery_code: secondFactorRecoveryCode, code: external_exports.undefined().optional() })
6633
+ ]);
6634
+ setOrgSecondFactorBody = external_exports.object({ tier: secondFactorTier });
6450
6635
  }
6451
- const normalizedPath = path46.replace(/\/$/, "");
6452
- if (!normalizedPath.endsWith("/*") && Object.prototype.hasOwnProperty.call(ENDPOINT_CONFIGS, normalizedPath)) {
6453
- return ENDPOINT_CONFIGS[normalizedPath];
6636
+ });
6637
+
6638
+ // ../../packages/core/dist/chunk-TVUDMGWV.js
6639
+ var bootstrapQuery;
6640
+ var init_chunk_TVUDMGWV = __esm({
6641
+ "../../packages/core/dist/chunk-TVUDMGWV.js"() {
6642
+ "use strict";
6643
+ init_zod();
6644
+ bootstrapQuery = external_exports.object({
6645
+ active_hub_id: external_exports.string().uuid().optional(),
6646
+ active_conversation_id: external_exports.string().uuid().optional(),
6647
+ active_nav: external_exports.enum(["chat", "task", "support"]).optional(),
6648
+ /**
6649
+ * The people thread the URL names (`/chat/threads/:threadId`, gh #4661): the snapshot
6650
+ * preloads it as `people.active_thread` when the viewer is a member.
6651
+ */
6652
+ active_thread_id: external_exports.string().uuid().optional()
6653
+ });
6454
6654
  }
6455
- const sortedPatterns = Object.keys(ENDPOINT_CONFIGS).sort((a, b) => b.length - a.length);
6456
- for (const pattern of sortedPatterns) {
6457
- if (matchPath(pattern, path46)) {
6458
- return ENDPOINT_CONFIGS[pattern];
6459
- }
6655
+ });
6656
+
6657
+ // ../../packages/core/dist/chunk-S4HVRNEQ.js
6658
+ var PERMISSIONS;
6659
+ var init_chunk_S4HVRNEQ = __esm({
6660
+ "../../packages/core/dist/chunk-S4HVRNEQ.js"() {
6661
+ "use strict";
6662
+ PERMISSIONS = [
6663
+ "hub:read",
6664
+ "hub:write",
6665
+ "hub:admin",
6666
+ "conversation:read",
6667
+ "conversation:write",
6668
+ "analytics:read",
6669
+ "billing:read",
6670
+ "billing:write",
6671
+ "org:read",
6672
+ "org:write",
6673
+ "org:admin",
6674
+ "contacts:write",
6675
+ "platform:admin",
6676
+ "*"
6677
+ ];
6460
6678
  }
6461
- return { tier: "STANDARD" };
6462
- }
6463
- var ENDPOINT_CONFIGS, EXCLUDED_PATHS;
6464
- var init_chunk_7AYJHO5P = __esm({
6465
- "../../packages/core/dist/chunk-7AYJHO5P.js"() {
6466
- "use strict";
6467
- init_chunk_5FO3GNKP();
6468
- ENDPOINT_CONFIGS = {
6469
- // OAuth callbacks - strict, fail-closed (prevent brute force)
6470
- "/oauth/callback/*": { tier: "STRICT", failClosed: true },
6471
- // Auth endpoints - strict, fail-closed
6472
- "/auth/phone": { tier: "STRICT", failClosed: true },
6473
- "/auth/mcp/exchange": { tier: "MODERATE", failClosed: true },
6474
- // Native magic-code login (pre-auth) — STRICT per-IP bounds a single host; WorkOS owns
6475
- // the per-email lockout / TTL / single-use guarantees.
6476
- "/api/auth/magic-code/*": { tier: "STRICT", failClosed: true },
6477
- // Native password login (pre-auth) — same posture as magic-code above. STRICT per-IP bounds a
6478
- // single host but FAILS OPEN on a binding error (like every IP limit); the `failClosed` flag
6479
- // here is inert on a pre-auth route (it's only enforced on the per-user branch, which needs an
6480
- // authenticated caller). The fail-CLOSED brute-force guarantee for the static credential comes
6481
- // from the route's per-email caps (burst + cumulative hourly), not this flag.
6482
- "/api/auth/password/*": { tier: "STRICT", failClosed: true },
6483
- // Attempts at a two-step code. STRICT per IP; the routes add a per-user cap, the one that matters
6484
- // against guessing. The status read's exact key keeps it off that budget, which sign-in shares.
6485
- "/api/auth/second-factor": { tier: "STANDARD" },
6486
- "/api/auth/second-factor/*": { tier: "STRICT", failClosed: true },
6487
- // Every `/api/*` group whose paths carry ids pins `userLimitKey` (gh #4756), held there by
6488
- // `security/endpoint-invariants.test.ts`.
6489
- // Billing - moderate, fail-closed with user limits
6490
- "/api/billing/*": {
6491
- tier: "MODERATE",
6492
- userLimit: 100,
6493
- failClosed: true,
6494
- skipAuthenticatedUsers: true,
6495
- userLimitKey: "/api/billing/*"
6496
- },
6497
- "/webhooks/stripe": { tier: "MODERATE", failClosed: true },
6498
- "/webhooks/workos": { tier: "MODERATE", failClosed: true },
6499
- // API endpoints - standard with user limits
6500
- // 500 because the web's settings live updates refetch per hub in every open tab, whatever page
6501
- // it shows (`settingsLiveUpdateStore.ts`): one batch of changes costs about 10 + 4 per agent
6502
- // whose tools were opened + 2 per loaded resource, so a CLI push and publish (both hubs) with
6503
- // two tabs open passes 150 in a minute. A multi-file resource upload adds 2–5 per file.
6504
- "/api/setup/*": {
6505
- tier: "STANDARD",
6506
- userLimit: 500,
6507
- skipAuthenticatedUsers: true,
6508
- userLimitKey: "/api/setup/*"
6509
- },
6510
- // 500 because an eval run's drill-down (`SessionResults.tsx`) fetches its list and then every
6511
- // LLM turn's record at once: up to 201 requests (`OBSERVABILITY_LIST_CAP`, 200). Sending keeps
6512
- // the 150 it had when each path held its own budget, on the exact key below.
6513
- "/api/conversations/*": {
6514
- tier: "STANDARD",
6515
- userLimit: 500,
6516
- skipAuthenticatedUsers: true,
6517
- userLimitKey: "/api/conversations/*"
6518
- },
6519
- "/api/conversations/send-message": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
6520
- "/api/users/*": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
6521
- "/api/analytics/*": {
6522
- tier: "STANDARD",
6523
- userLimit: 150,
6524
- skipAuthenticatedUsers: true,
6525
- userLimitKey: "/api/analytics/*"
6526
- },
6527
- // 500 because `wayai eval-results --eval` reads completed sessions one by one, newest first,
6528
- // until one holds the eval (up to the 1000 the list returns). Tenant SQL keeps the 150 it had
6529
- // when each path held its own budget: each query may run 30 s on shared-tenant ClickHouse
6530
- // after its caller has gone (`sql-validator.ts`, stage 10b).
6531
- "/api/evals/*": {
6532
- tier: "STANDARD",
6533
- userLimit: 500,
6534
- skipAuthenticatedUsers: true,
6535
- userLimitKey: "/api/evals/*"
6536
- },
6537
- "/api/evals/sql": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
6538
- // An eval run's calls (gh #4418), kept off the end user's call budgets below. Create keeps the
6539
- // 150 it had: it opens a provider session on the org's own key, billed per second. The routes
6540
- // on one call take a budget of their own so no eval read can spend it: a refused hang-up
6541
- // leaves the call running, and billing. 500 because a call suite polls each run's record
6542
- // every second, about 64 requests a minute per suite.
6543
- "/api/evals/calls": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
6544
- "/api/evals/calls/*": {
6545
- tier: "STANDARD",
6546
- userLimit: 500,
6547
- skipAuthenticatedUsers: true,
6548
- userLimitKey: "/api/evals/calls/*"
6549
- },
6550
- "/api/files/*": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
6551
- // The org contact book (wayai#4931 PR 2b). A CSV import sends one request per
6552
- // `CONTACT_IMPORT_BATCH_MAX` rows, so 150 a minute imports 75,000 rows a minute.
6553
- "/api/contact-book/*": {
6554
- tier: "STANDARD",
6555
- userLimit: 150,
6556
- skipAuthenticatedUsers: true,
6557
- userLimitKey: "/api/contact-book/*"
6558
- },
6559
- // An automation email's one-click unsubscribe (wayai#4931 PR 2d) — public: its token is its one
6560
- // credential, so this per-IP limit is its one bound, and runs before the route reads anything.
6561
- // MODERATE (30/min per IP), as the community email's unsubscribe, for the same reason: mail
6562
- // clients' one-click unsubscribe POSTs it from their own servers, which many recipients' clicks
6563
- // share. An exact key, so it wins over the wildcard above.
6564
- [CONTACT_BOOK_EMAIL_UNSUBSCRIBE_PATH]: { tier: "MODERATE" },
6565
- "/api/automations/*": {
6566
- tier: "STANDARD",
6567
- userLimit: 150,
6568
- skipAuthenticatedUsers: true,
6569
- userLimitKey: "/api/automations/*"
6570
- },
6571
- // A hub's own contact lists (wayai#4931 PR 2c): config edits, at the automations' rate.
6572
- "/api/hub-contact-lists/*": {
6573
- tier: "STANDARD",
6574
- userLimit: 150,
6575
- skipAuthenticatedUsers: true,
6576
- userLimitKey: "/api/hub-contact-lists/*"
6577
- },
6578
- "/api/message-templates/*": {
6579
- tier: "STANDARD",
6580
- userLimit: 150,
6581
- skipAuthenticatedUsers: true,
6582
- userLimitKey: "/api/message-templates/*"
6583
- },
6584
- "/api/live-updates/*": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
6585
- "/api/hub-users/*": {
6586
- tier: "STANDARD",
6587
- userLimit: 150,
6588
- skipAuthenticatedUsers: true,
6589
- userLimitKey: "/api/hub-users/*"
6590
- },
6591
- "/api/conversation-state/*": {
6592
- tier: "STANDARD",
6593
- userLimit: 150,
6594
- skipAuthenticatedUsers: true,
6595
- userLimitKey: "/api/conversation-state/*"
6596
- },
6597
- // The authenticated byte route (`routes/files/r2.ts`), mounted after its `authMiddleware` so
6598
- // the caller is known: each request reads the HubDO its key names, and a hub id never created
6599
- // still wakes a Durable Object (gh #4747; since gh #4775 T5 one that writes nothing). The key is pinned
6600
- // because the paths are file keys, which would otherwise each get a fresh budget (and one
6601
- // over 256 characters would be refused outright, `checkUserLimitNative`).
6602
- //
6603
- // 500 a minute because the web chat fetches every attachment of every loaded message at
6604
- // once, with no list virtualization: up to 50 per 50-message page, 200 per ended
6605
- // conversation or history entry at one file per message, and 4 per message at most in its
6606
- // image grid. Repeats come from the browser's HTTP cache (`private, max-age=3600`); mobile
6607
- // renders through a disk cache and plays audio from `/files/signed`. The budget is shared by
6608
- // a caller's tabs and devices. The other two byte routes, `/files/signed/*` and
6609
- // `/files/public/*`, mount no limiter (the reason is at their entries in
6610
- // `security/endpoint-invariants.test.ts`'s route registry).
6611
- "/files/auth/*": {
6612
- tier: "STANDARD",
6613
- userLimit: 500,
6614
- skipAuthenticatedUsers: true,
6615
- userLimitKey: "/files/auth/*"
6616
- },
6617
- // Channel webhooks - high throughput (external systems, never authenticated)
6618
- "/webhooks/whatsapp/*": { tier: "HIGH" },
6619
- "/webhooks/instagram/*": { tier: "HIGH" },
6620
- // An automation's webhook deliveries (wayai#4931 D13) — no bearer token: the automation's
6621
- // secret is the credential, checked against one HubDO read. This per-IP limit runs first, before
6622
- // anything is read. HIGH, as the channel webhooks: senders are servers, and an integration
6623
- // platform's egress addresses carry many tenants' deliveries. The per-automation budget is
6624
- // `AUTOMATION_WEBHOOK_PER_AUTOMATION_LIMIT`, counted after the delivery is verified.
6625
- [`${AUTOMATION_WEBHOOK_MOUNT}/*`]: { tier: "HIGH" },
6626
- // Managed Agents session events (#5083 Phase 4): one delivery per hosted tool round, and one
6627
- // vendor address carries every tenant's, so BULK. The per-connection budget is
6628
- // `MANAGED_AGENTS_WEBHOOK_PER_CONNECTION_LIMIT`, counted after the delivery is verified.
6629
- [`${MANAGED_AGENTS_WEBHOOK_MOUNT}/*`]: { tier: "BULK" },
6630
- // Telegram updates the credentials vault forwards for the bots whose tokens it holds (wayai#5644):
6631
- // the vault's egress carries every such bot's, so BULK. Its signature is checked after this.
6632
- [TELEGRAM_VAULT_WEBHOOK_PATH]: { tier: "BULK" },
6633
- // Reports (CLI → platform_report triage queue). One per-user budget covers intake
6634
- // (POST), the content edit (PATCH /:id), the reporter read-back (GET, GET /:id), and the
6635
- // verification loop (POST /:id/accept, /:id/contest). The limiter is path-based, so a
6636
- // method-level split (loose reads, strict writes) isn't expressible — GET /:id and PATCH
6637
- // /:id share a path. So the budget is sized for the read-heavy poll loop (a reporter agent
6638
- // polling `report get`/`list` while it waits for the fix), at 60/hour. Intake-flooding stays
6639
- // bounded regardless: identical reports collapse on `fingerprint` (ON CONFLICT DO NOTHING),
6640
- // so a runaway create loop merges rather than floods. Still STRICT tier + failClosed so a
6641
- // genuinely runaway distinct-report loop surfaces as 429. The `/*` is load-bearing — an
6642
- // exact `/api/reports` key would leave the `/:id` paths unmatched (→ unthrottled).
6643
- // `userLimitKey` is equally load-bearing: without it, middleware falls back to each request's
6644
- // path and report IDs/actions receive independent counters instead of this shared budget.
6645
- "/api/reports/*": {
6646
- tier: "STRICT",
6647
- userLimit: 60,
6648
- userWindow: 3600,
6649
- failClosed: true,
6650
- skipAuthenticatedUsers: true,
6651
- userLimitKey: "/api/reports/*"
6652
- },
6653
- // Admin report mutations (transition/group/ungroup/edit) — platform-admin
6654
- // gated at the route, rate-limited here as defense-in-depth. Generous STANDARD
6655
- // cap so legitimate triage bursts aren't throttled (grouping is one request
6656
- // even for many members); deliberately NOT failClosed so a Redis blip never
6657
- // blocks an admin's triage. The bare GET reads share this budget harmlessly.
6658
- "/api/admin/reports/*": { tier: "STANDARD", userLimit: 150, userLimitKey: "/api/admin/reports/*" },
6659
- // GitHub webhook (issues.closed → platform_report addressed). MODERATE +
6660
- // fail-closed; GitHub retries on transient failures so a brief Redis blip
6661
- // doesn't lose state.
6662
- "/webhooks/github": { tier: "MODERATE", failClosed: true },
6663
- // Account deletion — strict on the destructive POST + public undo. The
6664
- // /api/users/* default tier above ALSO matches these, but `getEndpointConfig`
6665
- // returns the longest-prefix match, so the more specific entries here win.
6666
- // `skipAuthenticatedUsers` deliberately omitted: every caller is authenticated,
6667
- // so including it would make `userLimit` a no-op — the per-user cap IS the gate.
6668
- "/api/users/me/deletion": { tier: "STRICT", userLimit: 3, userWindow: 3600, failClosed: true },
6669
- "/api/users/me/deletion/preflight": { tier: "STANDARD", userLimit: 30, failClosed: true },
6670
- "/api/users/deletion/undo": { tier: "STRICT", failClosed: true },
6671
- // Production-base destruction.
6672
- //
6673
- // Keyed off the CONTRACT constants, not literals: `BASE_DESTRUCTION_CONFIRM_PATH`'s own
6674
- // docstring promises that the mount, the `AUTH_BYPASS_PATHS` entry, the rate-limit key and
6675
- // the URL the email embeds move together, and a literal here is exactly how that promise
6676
- // goes quietly false — leaving an unauthenticated HMAC endpoint on the default tier.
6677
- //
6678
- // The emailed GET is PUBLIC, so it gets the IP-tier bound the pre-auth routes get.
6679
- // `failClosed` is deliberately NOT set: it is only consulted on the per-USER branch, which
6680
- // needs an authenticated caller, so on a pre-auth route it is inert — the same thing
6681
- // `/api/auth/magic-code/send` above says about itself. The IP limiter fails OPEN on a
6682
- // limiter error by design (`packages/runtime/src/rate-limiter.ts`), and claiming otherwise
6683
- // would tell the next auditor a protection exists that does not.
6684
- [BASE_DESTRUCTION_CONFIRM_PATH]: { tier: "STRICT" },
6685
- // The console's read, which every production base's settings pane issues on mount. Without
6686
- // its own entry it inherits the mount-wide budget below, and an admin clicking through
6687
- // thirty bases in an hour would be 429'd by a limit sized for irreversible writes.
6688
- [`${BASE_DESTRUCTION_PREFIX}/destructions`]: { tier: "STANDARD", userLimit: 150 },
6689
- // The mutating routes: initiate, the authenticated confirm, and cancel. Per user rather than
6690
- // per IP — all three are authenticated and org-admin gated — and hourly, since a single human
6691
- // touching thirty production-deletion operations in an hour is already far past normal.
6692
- // Longest-prefix wins, so the two entries above are not widened by this one. The key is
6693
- // pinned so those thirty are counted across every base the caller touches (gh #4756).
6694
- [`${BASE_DESTRUCTION_PREFIX}/*`]: {
6695
- tier: "STANDARD",
6696
- userLimit: 30,
6697
- userWindow: 3600,
6698
- failClosed: true,
6699
- userLimitKey: `${BASE_DESTRUCTION_PREFIX}/*`
6700
- },
6701
- // Email-invite preview — public, fail-closed. MODERATE (30/min IP) leaves
6702
- // headroom for the signup-page server-fetch + reloads + prefetches; STRICT
6703
- // would throttle legitimate users opening the link in multiple tabs.
6704
- "/api/invites/preview": { tier: "MODERATE", failClosed: true },
6705
- // "Don't email me again" (gh #4661) — public; one POST per click on its confirm page. STRICT
6706
- // per IP. No `failClosed`: it is consulted only on the per-user branch, which a pre-auth route
6707
- // never reaches (see `BASE_DESTRUCTION_CONFIRM_PATH` above).
6708
- "/api/invites/unsubscribe": { tier: "STRICT" },
6709
- // Admin DO debug reads — the ONE deliberate deviation from the Data Explorer
6710
- // catch-all below, and the only reason a per-route key still exists here.
6711
- // Platform-admin is enforced at the route; this is the independent
6712
- // defense-in-depth signal so a runaway investigation script surfaces as 429.
6713
- //
6714
- // STRICT is kept ON PURPOSE even though the catch-all moved off it: per IP, at 5/min vs
6715
- // STANDARD's 100/min, walking 10k ids takes ~33h instead of ~100min — a detection window
6716
- // worth keeping on the routes that return RAW DO ROWS.
6717
- //
6718
- // The cost, stated rather than elided: STRICT is one bucket shared with
6719
- // `/oauth/callback/*` and `/api/auth/magic-code/*`, so a debug session from a
6720
- // NAT'd office IP can 429 a colleague's login for up to a minute. That trade is
6721
- // accepted for a rare, deliberate investigation surface — and is exactly why the
6722
- // browse routes below are NOT here.
6723
- //
6724
- // The key is pinned, so a sweep of `/debug/do/hub/<id>/tables` across ids spends one
6725
- // per-admin budget (gh #4756). 120 an hour: an agent's investigation of a dozen
6726
- // conversations made 37 debug reads in its busiest hour.
6727
- "/api/admin/data-explorer/debug/*": {
6728
- tier: "STRICT",
6729
- userLimit: 120,
6730
- userWindow: 3600,
6731
- failClosed: true,
6732
- userLimitKey: "/api/admin/data-explorer/debug/*"
6733
- },
6734
- // Catch-all for the rest of the Data Explorer (`/search`, `/entity/*`, `/do/*`,
6735
- // `/kv/*`, the DELETE routes). Added as a catch-all rather than another per-route
6736
- // key because this budget kept lagging behind routes joining the debug boundary:
6737
- // with no match the path falls to the default, which sets no `userLimit`, so the
6738
- // per-user layer never runs at all. `getEndpointConfig` takes the longest match,
6739
- // so `debug/*` above still wins.
6740
- //
6741
- // `/entity/*` deliberately has NO key of its own: it needs precisely this config,
6742
- // and a duplicate entry is how the two drift apart on the next edit.
6743
- //
6744
- // `tier` is deliberately STANDARD, not STRICT. `tier` is the per-IP knob and
6745
- // STRICT is 5/min keyed on IP ALONE — one bucket shared across every STRICT
6746
- // endpoint. On these browse routes that breaks the console (open Browse KV and
6747
- // inspect four values = 6 requests; expand six org rows in the search results =
6748
- // 6 `/entity/org/:id` calls) and would drain the same IP's budget for
6749
- // `/oauth/callback/*` and `/api/auth/magic-code/*`, which on a NAT'd office IP
6750
- // means all admins. The per-user hourly cap is the leg that matters here.
6751
- //
6752
- // The canonical key is deliberate: request paths contain DO ids and arbitrary
6753
- // malformed requests can contain credential material. Keying on the request path
6754
- // both stores that material in Redis/logs and gives every target a fresh counter.
6755
- // One stable identity makes every browse request consume the same per-admin
6756
- // budget without storing request targets.
6757
- //
6758
- // 600/hour preserves the original pagination requirement (about 30k rows at
6759
- // 50/page) while now genuinely bounding id/key enumeration across the surface.
6760
- "/api/admin/data-explorer/*": {
6761
- tier: "STANDARD",
6762
- userLimit: 600,
6763
- userWindow: 3600,
6764
- failClosed: true,
6765
- userLimitKey: "/api/admin/data-explorer/*"
6766
- },
6767
- // Admin harness incident-response (harness-agents PR 2.9b) — mass-destroy reaps
6768
- // EVERY live harness session/token/slot in scope, so it gets a strict budget
6769
- // (STRICT + a low per-user hourly cap + fail-closed). Platform-admin is enforced
6770
- // at the route; this is the independent defense-in-depth signal so a runaway
6771
- // reap loop surfaces as 429. The break-glass disable/enable rides through
6772
- // `/api/admin/config` (its own STANDARD budget), not this key.
6773
- "/api/admin/harness/*": {
6774
- tier: "STRICT",
6775
- userLimit: 10,
6776
- userWindow: 3600,
6777
- failClosed: true,
6778
- userLimitKey: "/api/admin/harness/*"
6779
- },
6780
- // Platform-wide team-orphan repair — a single call can WRITE across every hub of
6781
- // every org (HubDO purge + UserDO mirror fan-out), so it gets the same strict,
6782
- // fail-closed budget as the other cross-platform admin write. Exact path (not a
6783
- // prefix): the sibling `/api/admin/hubs/:hubId/harness` flag flips stay on the
6784
- // default admin budget. Platform-admin is enforced at the route; this is the
6785
- // defense-in-depth signal that a repair loop surfaces as 429.
6786
- "/api/admin/hubs/repair-team-orphans": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
6787
- // Branching-orphan repair (#4577) — deletes named production rows, and its report mode
6788
- // fans out over every production hub of every org, so it takes the same strict,
6789
- // fail-closed budget as the team-orphan repair. Exact path, for the same reason.
6790
- "/api/admin/hubs/repair-branching-orphans": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
6791
- // Knowledge-blob repair (#5142 step 5 C1) — deletes R2 objects across every hub of a scope, so it
6792
- // takes the same strict, fail-closed budget as the other hub repairs. Exact path, for the same reason.
6793
- "/api/admin/hubs/repair-knowledge-blobs": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
6794
- "/api/admin/hubs/repair-credential-links": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
6795
- // The org credential service backfill (#5644) writes org credentials, and its dry run reads every org: the same budget.
6796
- "/api/admin/organizations/repair-credential-services": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
6797
- // The WayAI-host token clear (#5644 steps 6–7) deletes connections and org credentials, and its dry run fans out over
6798
- // every hub of every org: the same strict, fail-closed budget.
6799
- "/api/admin/hubs/clear-wayai-host-tokens": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
6800
- // CI/GitOps endpoints - standard with user limits. 500 because `wayai push` makes four requests
6801
- // (pull, diff, push, pull) and a GitOps job may push every hub at once with one token; when
6802
- // each path held its own 100, that ran to 100 hubs a minute.
6803
- "/api/ci/*": { tier: "STANDARD", userLimit: 500, skipAuthenticatedUsers: true, userLimitKey: "/api/ci/*" },
6804
- // A hub's team pages and their bridge (#5333; owner decision of 2026-10-27): a signed-in caller is
6805
- // counted on one budget of their own across every hub's page routes instead of the per-IP tier,
6806
- // which a team behind one address shares. The bridge's own budgets still apply on top: 60 calls a
6807
- // minute per viewer and page (30 on a customer page), 150 per viewer across a hub's pages, 200 per hub
6808
- // across its customer pages and 500 per hub (`PAGE_BRIDGE_*` below).
6809
- "/api/hubs/*/pages/*": { tier: "STANDARD", userLimit: 500, skipAuthenticatedUsers: true, userLimitKey: "/api/hubs/*/pages/*" },
6810
- // Attested `/v1` proxy onto the data API's `AttestedEntrypoint`. `userLimitKey` is load-bearing here: the
6811
- // per-user budget defaults to the full request path, and this surface's paths carry base,
6812
- // record, and file ids — so without a pinned key every distinct resource would get its own
6813
- // fresh budget and the per-user limit would bound nothing. One shared budget across the
6814
- // whole data surface is the intent.
6815
- [`${DATA_PROXY_PREFIX}/*`]: {
6816
- tier: "STANDARD",
6817
- userLimit: 150,
6818
- skipAuthenticatedUsers: true,
6819
- userLimitKey: `${DATA_PROXY_PREFIX}/*`
6820
- },
6821
- // Voice calls — the end user's call routes (`routes/api/calls`). Every caller is signed
6822
- // in, so the per-IP tier is skipped for them: Brazilian mobile carriers put many callers
6823
- // behind one IP, and a shared bucket would refuse one caller for another's traffic.
6824
- //
6825
- // Create is the only route that spends: it opens a provider session on the org's own
6826
- // key, billed per second. So it takes its own exact key and an hourly per-user cap, which
6827
- // lives on Redis and is fail-closed like the other hourly caps. The exact key wins over
6828
- // the wildcard below, which also matches `/api/calls` (see `getEndpointConfig`).
6829
- "/api/calls": {
6830
- tier: "STANDARD",
6831
- userLimit: 30,
6832
- userWindow: 3600,
6833
- failClosed: true,
6834
- skipAuthenticatedUsers: true,
6835
- userLimitKey: "/api/calls"
6836
- },
6837
- // The routes on one call: `ready`, hang-up, the delegation report and the status read; and
6838
- // the opening read (`/api/calls/openings/:language`), one per call, before it exists.
6839
- // NEVER fail-closed: a refused hang-up leaves the call running, and billing, until a
6840
- // limit ends it. The 60 s budget runs on the native binding, which fails open. The key is
6841
- // pinned because the paths carry the call id, which would otherwise give every call a
6842
- // fresh budget.
6843
- "/api/calls/*": {
6844
- tier: "STANDARD",
6845
- userLimit: 150,
6846
- skipAuthenticatedUsers: true,
6847
- userLimitKey: "/api/calls/*"
6848
- },
6849
- // Contacts between accounts (gh #4661, `routes/api/contacts`). Every caller is signed in, so
6850
- // the per-IP tier is skipped. The keys are pinned because the paths carry user and invite
6851
- // ids, which would otherwise give each id a fresh budget. Blocks take their own, lower
6852
- // budget (#4661 Limits: blocks are rate-limited). The invites-per-day cap and every list
6853
- // cap are counted in the caller's UserDO, in the same write they bound, not here.
6854
- "/api/contacts/*": {
6855
- tier: "STANDARD",
6856
- userLimit: 60,
6857
- skipAuthenticatedUsers: true,
6858
- userLimitKey: "/api/contacts/*"
6859
- },
6860
- "/api/contacts/blocks/*": {
6861
- tier: "STANDARD",
6862
- userLimit: 30,
6863
- skipAuthenticatedUsers: true,
6864
- userLimitKey: "/api/contacts/blocks/*"
6865
- },
6866
- // Person-to-person threads (gh #4661, `routes/api/threads`): the per-user send limit, 60 a
6867
- // minute on the native binding. Every thread route shares the one budget, reads included:
6868
- // the paths carry thread and message ids, so the key is pinned, and a pattern here cannot
6869
- // tell a send from a read of the same path. Like every 60 s budget it fails open on a
6870
- // binding error, so it bounds sends in the steady state only.
6871
- "/api/threads/*": {
6872
- tier: "STANDARD",
6873
- userLimit: 60,
6874
- skipAuthenticatedUsers: true,
6875
- userLimitKey: "/api/threads/*"
6876
- },
6877
- // An org admin's erasure of one person's thread messages (gh #4661 owner decision 7): any user
6878
- // can own a free org, so each request arms that org's alarm, and this caps how fast one person
6879
- // can ask. The org's own daily cap (`PEOPLE_ORG_ERASURES_PER_DAY`, counted in its OrgDO in the
6880
- // write it bounds) is the fail-closed bound; this budget, on the native binding, fails open.
6881
- "/api/threads/org-erasures": {
6882
- tier: "STANDARD",
6883
- userLimit: 10,
6884
- skipAuthenticatedUsers: true,
6885
- userLimitKey: "/api/threads/org-erasures"
6886
- },
6887
- // A person's report of a message, thread or person (`people-reports.ts`): each one written
6888
- // arms the PlatformDO's alarm and emails the platform admins, so it takes its own, lower
6889
- // budget. The reporter's daily cap (`PEOPLE_REPORTS_PER_DAY`, counted in the report store in
6890
- // the write it bounds) is the fail-closed bound; this budget, on the native binding, fails open.
6891
- "/api/threads/reports": {
6892
- tier: "STANDARD",
6893
- userLimit: 10,
6894
- skipAuthenticatedUsers: true,
6895
- userLimitKey: "/api/threads/reports"
6896
- },
6897
- // Communities (gh #4872, `routes/api/communities`): every signed-in route under the mount (the
6898
- // preview below excepted) shares one per-user budget, which is also each member's send limit and
6899
- // bounds the reads that scan a community's rows (a title search, the stats); a community's own
6900
- // limits (its rate, the daily caps, slow mode) are counted in its CommunityDO, in the write they
6901
- // bound. Every caller is signed in, so the per-IP tier is skipped; the key is pinned because the
6902
- // paths carry community, room and message ids.
6903
- "/api/communities/*": {
6904
- tier: "STANDARD",
6905
- userLimit: 60,
6906
- skipAuthenticatedUsers: true,
6907
- userLimitKey: "/api/communities/*"
6908
- },
6909
- // The join page's preview of a link — public, fetched from the visitor's browser, so this
6910
- // per-IP limit is its one bound and runs before the route reads anything (#4872
6911
- // owner-delegated decision 9). MODERATE (30/min per IP) leaves room for reloads and several
6912
- // tabs. An exact key, so it wins over the wildcard above.
6913
- "/api/communities/join-preview": { tier: "MODERATE" },
6914
- // An announcement email's unsubscribe (#4872 PR 8a) — public: its token is its one credential, so
6915
- // this per-IP limit is its one bound, and runs before the route reads anything. MODERATE (30/min
6916
- // per IP), not STRICT: mail clients' one-click unsubscribe POSTs it from their own servers, which
6917
- // many members' clicks share, and STRICT's 5/min bucket is shared with sign-in. An exact key, so
6918
- // it wins over the wildcard above.
6919
- [COMMUNITY_EMAIL_UNSUBSCRIBE_PATH]: { tier: "MODERATE" },
6920
- // Case spaces (wayai#5921, `cases/routes.ts`): every route under the mount (the uploads, the received documents' upload,
6921
- // the compare, the comments and the cited passages below excepted) shares
6922
- // one per-user budget. Each is one person's page or write, at most a few hundred Durable Object reads (the
6923
- // list of their spaces); a space's own limits are counted in its CaseDO. Every caller is a web
6924
- // session, so the per-IP tier is skipped; the key is pinned because the paths carry org, space,
6925
- // person and team ids.
6926
- "/api/cases/*": {
6927
- tier: "STANDARD",
6928
- userLimit: 60,
6929
- skipAuthenticatedUsers: true,
6930
- userLimitKey: "/api/cases/*"
6931
- },
6932
- // A case file upload (`POST …/cases/:code/uploads`): each carries up to 20 MiB the Worker holds in memory, hashes
6933
- // and stores, so it takes its own, lower budget, keyed once for every case.
6934
- "/api/cases/*/*/cases/*/uploads": {
6935
- tier: "STANDARD",
6936
- userLimit: 10,
6937
- skipAuthenticatedUsers: true,
6938
- userLimitKey: "/api/cases/*/*/cases/*/uploads"
6939
- },
6940
- // A case space's style asset upload (`POST …/styles/:kind/uploads`): up to 20 MiB the Worker holds in memory, checks,
6941
- // hashes and stores, by an administrator, so it takes the case file upload's budget, keyed once for every space.
6942
- "/api/cases/*/*/styles/*/uploads": {
6943
- tier: "STANDARD",
6944
- userLimit: 10,
6945
- skipAuthenticatedUsers: true,
6946
- userLimitKey: "/api/cases/*/*/styles/*/uploads"
6947
- },
6948
- // A collection document's upload (`POST …/collection/uploads`, a new document; `POST …/collection/:document_id/uploads`,
6949
- // its next version): up to 20 MiB the Worker holds in memory, checks, hashes and stores, by a Registry holder, so each
6950
- // takes a budget the size of the case file upload's: two budgets, one for new documents keyed once for every space,
6951
- // one for new versions keyed once for every space and document.
6952
- "/api/cases/*/*/collection/uploads": {
6953
- tier: "STANDARD",
6954
- userLimit: 10,
6955
- skipAuthenticatedUsers: true,
6956
- userLimitKey: "/api/cases/*/*/collection/uploads"
6957
- },
6958
- "/api/cases/*/*/collection/*/uploads": {
6959
- tier: "STANDARD",
6960
- userLimit: 10,
6961
- skipAuthenticatedUsers: true,
6962
- userLimitKey: "/api/cases/*/*/collection/*/uploads"
6963
- },
6964
- // A case's received document (`POST …/cases/:code/received/uploads`): up to 20 MiB the Worker holds in memory, checks,
6965
- // hashes and stores, as a case file upload does, so it takes a budget that upload's size, keyed once for every case.
6966
- "/api/cases/*/*/cases/*/received/uploads": {
6967
- tier: "STANDARD",
6968
- userLimit: 10,
6969
- skipAuthenticatedUsers: true,
6970
- userLimitKey: "/api/cases/*/*/cases/*/received/uploads"
6971
- },
6972
- // A compare of two versions of a case file (`GET …/cases/:code/files/compare`): each reads up to 8 MiB from the
6973
- // bucket into the Worker and runs the block compare (under a second of CPU at its limits), so it takes its own
6974
- // budget, keyed once for every case.
6975
- "/api/cases/*/*/cases/*/files/compare": {
6976
- tier: "STANDARD",
6977
- userLimit: 30,
6978
- skipAuthenticatedUsers: true,
6979
- userLimitKey: "/api/cases/*/*/cases/*/files/compare"
6980
- },
6981
- // A case file's comments (`GET`/`POST …/cases/:code/files/comments`): a write reads up to 4 MiB of one version from the
6982
- // bucket into the Worker and hashes a passage of it, so they take a budget of their own, as a compare does, keyed once
6983
- // for every case; the page shares it.
6984
- "/api/cases/*/*/cases/*/files/comments": {
6985
- tier: "STANDARD",
6986
- userLimit: 30,
6987
- skipAuthenticatedUsers: true,
6988
- userLimitKey: "/api/cases/*/*/cases/*/files/comments"
6989
- },
6990
- // A cited passage (`POST …/cases/:code/inputs/:input_id/passages`): reads up to 4 MiB of a collection version's text from
6991
- // the bucket into the Worker and hashes a passage of it, as a comment's write does, so it takes the comments' budget
6992
- // size, keyed once for every case and input.
6993
- "/api/cases/*/*/cases/*/inputs/*/passages": {
6994
- tier: "STANDARD",
6995
- userLimit: 30,
6996
- skipAuthenticatedUsers: true,
6997
- userLimitKey: "/api/cases/*/*/cases/*/inputs/*/passages"
6998
- },
6999
- // The WayAI Guide's help entry (wayai#4948, `routes/api/guide.ts`): one POST per click by a viewer
7000
- // the snapshot does not show enrolled, which reads the person's row on the Guide hub and writes only
7001
- // what is missing (an enrolled viewer's click opens the hub without a request). Every caller is
7002
- // signed in, so the per-IP tier is skipped; 10 a minute per person on the native binding (fails
7003
- // open, like every 60 s budget) bounds what a looping client costs the one Guide HubDO.
7004
- "/api/guide/access": {
7005
- tier: "STANDARD",
7006
- userLimit: 10,
7007
- skipAuthenticatedUsers: true,
7008
- userLimitKey: "/api/guide/access"
7009
- },
7010
- // App channel - high throughput with user limits
7011
- "/channels/app/*": { tier: "HIGH", userLimit: 500, skipAuthenticatedUsers: true },
7012
- // API channel (api-channel-connector) - machine-to-machine, high throughput
7013
- "/channels/api/*": { tier: "HIGH", userLimit: 500, skipAuthenticatedUsers: true },
7014
- // System/scheduled - high throughput (internal)
7015
- "/channels/system/*": { tier: "HIGH", skipAuthenticatedUsers: true },
7016
- "/scheduled/*": { tier: "HIGH", skipAuthenticatedUsers: true },
7017
- // WebSocket - standard with user limit to prevent connection spam
7018
- "/live-updates/ws": { tier: "STANDARD", userLimit: 100, failClosed: true },
7019
- // A community's live socket (gh #4872 PR 5, `GET /communities/:communityId/live`): outside
7020
- // `/api/*`, with no bearer token, so its per-IP tier is its one bound before the CommunityDO
7021
- // checks the ticket. STANDARD, as `/live-updates/ws`: a client opens one per community it shows
7022
- // and reconnects within the hour.
7023
- "/communities/*": { tier: "STANDARD" },
7024
- // WS ticket mint - per-user 60/min accommodates aggressive reconnect patterns
7025
- // without opening abuse vectors; fail-closed so Redis outages don't let
7026
- // runaway clients mint unbounded tickets.
7027
- "/api/auth/ws-ticket": { tier: "MODERATE", userLimit: 60, failClosed: true, skipAuthenticatedUsers: true },
7028
- "/api/auth/session-check": { tier: "STANDARD", userLimit: 120, skipAuthenticatedUsers: true },
7029
- "/api/auth/logout": { tier: "MODERATE", userLimit: 10, failClosed: true, skipAuthenticatedUsers: true }
7030
- };
7031
- EXCLUDED_PATHS = /* @__PURE__ */ new Set(["/health"]);
7032
- }
7033
- });
7034
-
7035
- // ../../packages/core/dist/chunk-ITIQ7XWD.js
7036
- function fileSnapshotChanged(run) {
7037
- return run.written + run.removed > 0;
7038
- }
7039
- async function runFileSnapshot(opts) {
7040
- const run = { pages: 0, written: 0, removed: 0, unchanged: 0 };
7041
- const seen = /* @__PURE__ */ new Set();
7042
- let cursor;
7043
- while (run.pages < FILE_SNAPSHOT_MAX_PAGES) {
7044
- const page = await sendWithRetry(opts, cursor);
7045
- run.pages++;
7046
- run.written += page.written;
7047
- run.removed += page.removed;
7048
- run.unchanged += page.unchanged;
7049
- opts.onPage?.(page, run.pages);
7050
- if (page.next_cursor === null) return run;
7051
- if (seen.has(page.next_cursor)) {
7052
- throw new Error(`The preview file snapshot repeated its cursor after page ${run.pages}, so it would never end.`);
7053
- }
7054
- seen.add(page.next_cursor);
7055
- cursor = page.next_cursor;
7056
- }
7057
- throw new Error(`The preview file snapshot did not end after ${FILE_SNAPSHOT_MAX_PAGES} pages.`);
7058
- }
7059
- async function sendWithRetry(opts, cursor) {
7060
- for (let attempt = 1; ; attempt++) {
7061
- let body;
7062
- try {
7063
- body = await opts.sendPage(cursor);
7064
- } catch (error) {
7065
- if (attempt < FILE_SNAPSHOT_CONFLICT_ATTEMPTS && opts.isConflict(error)) continue;
7066
- throw error;
7067
- }
7068
- const parsed = rekorFileSnapshotAnswerSchema.safeParse(body);
7069
- if (!parsed.success) {
7070
- throw new Error("The data product answered a preview file snapshot page WayAI cannot read: nothing more was sent.");
7071
- }
7072
- return parsed.data.data;
7073
- }
7074
- }
7075
- var rekorFileSnapshotAnswerSchema, FILE_SNAPSHOT_MAX_PAGES, FILE_SNAPSHOT_CONFLICT_ATTEMPTS, FILE_SNAPSHOT_PAGE_SPACING_MS, FILE_SNAPSHOT_CONFLICT_STATUS;
7076
- var init_chunk_ITIQ7XWD = __esm({
7077
- "../../packages/core/dist/chunk-ITIQ7XWD.js"() {
7078
- "use strict";
7079
- init_chunk_7AYJHO5P();
7080
- init_chunk_5FO3GNKP();
7081
- init_zod();
7082
- rekorFileSnapshotAnswerSchema = external_exports.object({
7083
- data: external_exports.object({
7084
- next_cursor: external_exports.string().nullable(),
7085
- /** Files the page created or replaced on the preview. */
7086
- written: external_exports.number().int(),
7087
- /** The preview's own files, ones production does not hold, the page removed. */
7088
- removed: external_exports.number().int(),
7089
- /** Files the page found already equal to production's. */
7090
- unchanged: external_exports.number().int()
7091
- })
7092
- });
7093
- FILE_SNAPSHOT_MAX_PAGES = 1e4;
7094
- FILE_SNAPSHOT_CONFLICT_ATTEMPTS = 3;
7095
- FILE_SNAPSHOT_PAGE_SPACING_MS = Math.ceil(
7096
- 6e4 / Math.max(1, Math.floor((getEndpointConfig(`${DATA_PROXY_PREFIX}/files/snapshot`)?.userLimit ?? 60) * 4 / 5))
7097
- );
7098
- FILE_SNAPSHOT_CONFLICT_STATUS = 409;
7099
- }
7100
- });
7101
-
7102
- // ../../packages/core/dist/chunk-IPDOHAZ5.js
7103
- var reportSourceSchema, intakeReportSourceSchema, reportClassificationSchema, reportStatusSchema, reportLocaleSchema, reportMessageAuthorRoleSchema, reportMessageSchema, sentryRefStatusSchema, createReportBody, editReportBody, reporterReportSummarySchema, reporterListResponseSchema, getReportResponseSchema, reporterTransitionResponseSchema, contestReportBody, reporterListQuery, listReportsQuery, GITHUB_ISSUE_URL_REGEX, githubIssueUrlSchema, transitionReportBody, groupReportsBody, holdReportBody;
7104
- var init_chunk_IPDOHAZ5 = __esm({
7105
- "../../packages/core/dist/chunk-IPDOHAZ5.js"() {
7106
- "use strict";
7107
- init_chunk_HZ6CADSY();
7108
- init_zod();
7109
- reportSourceSchema = external_exports.enum(["sentry", "cli", "review", "security_audit"]);
7110
- intakeReportSourceSchema = external_exports.enum(["cli", "review", "security_audit"]);
7111
- reportClassificationSchema = external_exports.enum(["bug", "flaky_test", "security", "enhancement"]);
7112
- reportStatusSchema = external_exports.enum([
7113
- "pending",
7114
- "grouped",
7115
- "escalated",
7116
- "shipped",
7117
- "contested",
7118
- "addressed",
7119
- "dismissed"
7120
- ]);
7121
- reportLocaleSchema = external_exports.enum(["en", "pt", "es"]);
7122
- reportMessageAuthorRoleSchema = external_exports.enum(["reporter", "triage", "fixer", "system"]);
7123
- reportMessageSchema = external_exports.object({
7124
- message_id: external_exports.string(),
7125
- author_role: reportMessageAuthorRoleSchema,
7126
- /** The status transition this note accompanied (e.g. 'shipped'); null for a free/system note. */
7127
- transition: external_exports.string().nullable(),
7128
- body: external_exports.string(),
7129
- created_at: timestampSchema,
7130
- /**
7131
- * Visibility: `false` = reporter-facing (the default for every narrative entry); `true` =
7132
- * triage-internal (e.g. a `hold` rationale) — surfaced to platform admins only and NEVER
7133
- * returned on the reporter read path. The reporter's `GET /api/reports/:id` filters these out.
7134
- */
7135
- internal: external_exports.boolean()
7136
- });
7137
- sentryRefStatusSchema = external_exports.enum(["valid", "not_found", "mismatch", "unverified"]);
7138
- createReportBody = external_exports.object({
7139
- title: external_exports.string().min(5).max(256),
7140
- description: external_exports.string().min(10).max(5e3),
7141
- steps_to_reproduce: external_exports.string().max(3e3).optional(),
7142
- error_message: external_exports.string().max(2e3).optional(),
7143
- // Taxonomy (server defaults: source=cli, classification=bug when absent).
7144
- source: intakeReportSourceSchema.optional(),
7145
- classification: reportClassificationSchema.optional(),
7146
- // Stable dedup key (e.g. "<file>::<test>" for flaky, "<file>:<line>" for
7147
- // security). When present, the fingerprint uses it instead of the body hash.
7148
- dedup_key: external_exports.string().min(1).max(256).optional(),
7149
- // Context fields (auto-captured by the CLI)
7150
- organization_id: external_exports.string().optional(),
7151
- hub_id: external_exports.string().uuid().optional(),
7152
- hub_name: external_exports.string().max(256).optional(),
7153
- conversation_id: external_exports.string().uuid().optional(),
7154
- agent_id: external_exports.string().uuid().optional(),
7155
- agent_name: external_exports.string().max(256).optional(),
7156
- client_version: external_exports.string().max(64).optional(),
7157
- additional_context: external_exports.string().max(2e3).optional()
7158
- });
7159
- editReportBody = external_exports.object({
7160
- title: external_exports.string().min(5).max(256).optional(),
7161
- description: external_exports.string().min(10).max(5e3).optional(),
7162
- steps_to_reproduce: external_exports.string().max(3e3).optional(),
7163
- error_message: external_exports.string().max(2e3).optional(),
7164
- additional_context: external_exports.string().max(2e3).optional()
7165
- }).strict().refine((b) => Object.keys(b).length > 0, {
7166
- message: "at least one field must be provided"
7167
- });
7168
- reporterReportSummarySchema = external_exports.object({
7169
- report_id: external_exports.string(),
7170
- title: external_exports.string(),
7171
- description: external_exports.string(),
7172
- classification: reportClassificationSchema,
7173
- status: reportStatusSchema,
7174
- created_at: timestampSchema,
7175
- triaged_at: timestampSchema.nullable(),
7176
- resolved_at: timestampSchema.nullable(),
7177
- /** How many times the reporter has contested (gates the hard cap). */
7178
- contest_count: external_exports.number(),
7179
- /** True once triage issued a non-contestable (final) dismissal. */
7180
- dismissal_final: external_exports.boolean()
7181
- });
7182
- reporterListResponseSchema = external_exports.object({
7183
- data: external_exports.array(reporterReportSummarySchema)
7184
- });
7185
- getReportResponseSchema = external_exports.object({
7186
- report: reporterReportSummarySchema,
7187
- messages: external_exports.array(reportMessageSchema)
7188
- });
7189
- reporterTransitionResponseSchema = external_exports.object({
7190
- report: reporterReportSummarySchema
7191
- });
7192
- contestReportBody = external_exports.object({
7193
- reason: external_exports.string().min(1).max(5e3)
7194
- });
7195
- reporterListQuery = external_exports.object({
7196
- status: reportStatusSchema.optional()
7197
- });
7198
- listReportsQuery = external_exports.object({
7199
- status: reportStatusSchema.optional(),
7200
- source: reportSourceSchema.optional(),
7201
- limit: external_exports.coerce.number().int().min(1).max(200).optional(),
7202
- offset: external_exports.coerce.number().int().min(0).optional(),
7203
- /** ISO 8601 lower bound on created_at. */
7204
- since: external_exports.string().datetime().optional(),
7205
- /**
7206
- * ISO 8601 lower bound on resolution time — "what did we resolve recently", which `since`
7207
- * (a created_at filter) cannot answer for a long-lived report resolved yesterday. Implies
7208
- * a terminal status (`addressed`/`dismissed`) and orders on that same axis.
7209
- */
7210
- resolved_since: external_exports.string().datetime().optional()
7211
- });
7212
- GITHUB_ISSUE_URL_REGEX = /^https:\/\/github\.com\/[^/]+\/[^/]+\/issues\/\d+(?:[/?#]|$)/;
7213
- githubIssueUrlSchema = external_exports.string().url().refine((u) => GITHUB_ISSUE_URL_REGEX.test(u), {
7214
- message: "must be an https://github.com/<owner>/<repo>/issues/<number> URL"
7215
- });
7216
- transitionReportBody = external_exports.discriminatedUnion("target", [
7217
- external_exports.object({
7218
- target: external_exports.literal("escalated"),
7219
- gh_issue_url: githubIssueUrlSchema,
7220
- ai_verdict: external_exports.string().max(2e3).optional()
7221
- }),
7222
- external_exports.object({
7223
- target: external_exports.literal("shipped"),
7224
- note: external_exports.string().min(1).max(2e3).optional()
7225
- }),
7226
- external_exports.object({
7227
- target: external_exports.literal("addressed")
7228
- }),
7229
- external_exports.object({
7230
- target: external_exports.literal("dismissed"),
7231
- dismissal_reason: external_exports.string().min(1).max(5e3),
7232
- ai_verdict: external_exports.string().max(2e3).optional(),
7233
- final: external_exports.boolean().optional()
7234
- })
7235
- ]);
7236
- groupReportsBody = external_exports.object({
7237
- member_ids: external_exports.array(external_exports.string().uuid()).min(1).max(100)
7238
- });
7239
- holdReportBody = external_exports.object({
7240
- reason: external_exports.string().min(1).max(5e3)
7241
- });
7242
- }
7243
- });
7244
-
7245
- // ../../packages/core/dist/chunk-KEN2DASI.js
7246
- var SECOND_FACTOR_TIERS, secondFactorTier, META_ENTITY_ID_PATTERN, metaEntityId, whatsappCallbackBody, authMeResponse, wsTicketResponse, sessionCheckResponse, logoutResponse, magicCodeSendBody, magicCodeSendResponse, magicCodeVerifyBody, magicCodeVerifyResponse, passwordLoginBody, normalizeEmail, REVIEW_ACCOUNT_EMAILS;
7247
- var init_chunk_KEN2DASI = __esm({
7248
- "../../packages/core/dist/chunk-KEN2DASI.js"() {
7249
- "use strict";
7250
- init_zod();
7251
- SECOND_FACTOR_TIERS = ["off", "settings"];
7252
- secondFactorTier = external_exports.enum(SECOND_FACTOR_TIERS);
7253
- META_ENTITY_ID_PATTERN = /^\d{1,32}$/;
7254
- metaEntityId = external_exports.string().regex(META_ENTITY_ID_PATTERN, "must be a numeric Meta entity id");
7255
- whatsappCallbackBody = external_exports.object({
7256
- state: external_exports.string().min(1, "state is required"),
7257
- code: external_exports.string().optional(),
7258
- access_token: external_exports.string().optional(),
7259
- user_id: external_exports.string().optional(),
7260
- /**
7261
- * The phone number and WABA the operator actually picked in Meta's Embedded
7262
- * Signup popup (posted to the opener as `WA_EMBEDDED_SIGNUP`). Optional:
7263
- * older clients, and the redirect-based flow, never see that event and fall
7264
- * back to discovery.
7265
- */
7266
- phone_number_id: metaEntityId.optional(),
7267
- waba_id: metaEntityId.optional()
7268
- }).refine(
7269
- (data) => !!data.access_token || !!data.code,
7270
- { message: "Missing required parameters: state and either access_token or code" }
7271
- );
7272
- authMeResponse = external_exports.object({
7273
- user_id: external_exports.string(),
7274
- email: external_exports.string(),
7275
- org_id: external_exports.string().nullable(),
7276
- is_platform_admin: external_exports.boolean()
7277
- });
7278
- wsTicketResponse = external_exports.object({
7279
- ticket: external_exports.string(),
7280
- /** Seconds until the ticket expires if unconsumed. */
7281
- expires_in: external_exports.number()
7282
- });
7283
- sessionCheckResponse = external_exports.object({
7284
- valid: external_exports.literal(true)
7285
- });
7286
- logoutResponse = external_exports.object({
7287
- success: external_exports.literal(true)
7288
- });
7289
- magicCodeSendBody = external_exports.object({
7290
- email: external_exports.string().email("Invalid email").max(254)
7291
- // RFC 5321 max; bounds the request payload
7292
- });
7293
- magicCodeSendResponse = external_exports.object({
7294
- success: external_exports.literal(true)
7295
- });
7296
- magicCodeVerifyBody = external_exports.object({
7297
- email: external_exports.string().email("Invalid email").max(254),
7298
- // RFC 5321 max; bounds the request payload
7299
- code: external_exports.string().min(1, "Code is required").max(12)
7300
- // WorkOS sends a 6-digit code; bound the input
7301
- });
7302
- magicCodeVerifyResponse = external_exports.object({
7303
- access_token: external_exports.string(),
7304
- refresh_token: external_exports.string()
7305
- });
7306
- passwordLoginBody = external_exports.object({
7307
- email: external_exports.string().email("Invalid email").max(254),
7308
- // RFC 5321 max; bounds the request payload
7309
- password: external_exports.string().min(1, "Password is required").max(128)
7310
- // bound the payload; WorkOS validates
7311
- });
7312
- normalizeEmail = (email) => email.trim().toLowerCase();
7313
- REVIEW_ACCOUNT_EMAILS = new Set(
7314
- ["apple.review@wayai.pro", "play.review@wayai.pro", "microsoft.review@wayai.pro", "meta.review@wayai.pro"].map(
7315
- normalizeEmail
7316
- )
7317
- );
7318
- }
7319
- });
7320
-
7321
- // ../../packages/core/dist/chunk-PFGVH2CX.js
7322
- var secondFactorCode, secondFactorRecoveryCode, secondFactorCodeBody, secondFactorRecoveryBody, secondFactorDisableBody, setOrgSecondFactorBody;
7323
- var init_chunk_PFGVH2CX = __esm({
7324
- "../../packages/core/dist/chunk-PFGVH2CX.js"() {
7325
- "use strict";
7326
- init_chunk_KEN2DASI();
7327
- init_zod();
7328
- secondFactorCode = external_exports.string().regex(/^\d{6}$/, "Enter the 6-digit code");
7329
- secondFactorRecoveryCode = external_exports.string().min(1, "Enter a recovery code").max(64);
7330
- secondFactorCodeBody = external_exports.object({ code: secondFactorCode });
7331
- secondFactorRecoveryBody = external_exports.object({ recovery_code: secondFactorRecoveryCode });
7332
- secondFactorDisableBody = external_exports.union([
7333
- external_exports.object({ code: secondFactorCode, recovery_code: external_exports.undefined().optional() }),
7334
- external_exports.object({ recovery_code: secondFactorRecoveryCode, code: external_exports.undefined().optional() })
7335
- ]);
7336
- setOrgSecondFactorBody = external_exports.object({ tier: secondFactorTier });
7337
- }
7338
- });
7339
-
7340
- // ../../packages/core/dist/chunk-TVUDMGWV.js
7341
- var bootstrapQuery;
7342
- var init_chunk_TVUDMGWV = __esm({
7343
- "../../packages/core/dist/chunk-TVUDMGWV.js"() {
7344
- "use strict";
7345
- init_zod();
7346
- bootstrapQuery = external_exports.object({
7347
- active_hub_id: external_exports.string().uuid().optional(),
7348
- active_conversation_id: external_exports.string().uuid().optional(),
7349
- active_nav: external_exports.enum(["chat", "task", "support"]).optional(),
7350
- /**
7351
- * The people thread the URL names (`/chat/threads/:threadId`, gh #4661): the snapshot
7352
- * preloads it as `people.active_thread` when the viewer is a member.
7353
- */
7354
- active_thread_id: external_exports.string().uuid().optional()
7355
- });
7356
- }
7357
- });
7358
-
7359
- // ../../packages/core/dist/chunk-S4HVRNEQ.js
7360
- var PERMISSIONS;
7361
- var init_chunk_S4HVRNEQ = __esm({
7362
- "../../packages/core/dist/chunk-S4HVRNEQ.js"() {
7363
- "use strict";
7364
- PERMISSIONS = [
7365
- "hub:read",
7366
- "hub:write",
7367
- "hub:admin",
7368
- "conversation:read",
7369
- "conversation:write",
7370
- "analytics:read",
7371
- "billing:read",
7372
- "billing:write",
7373
- "org:read",
7374
- "org:write",
7375
- "org:admin",
7376
- "contacts:write",
7377
- "platform:admin",
7378
- "*"
7379
- ];
7380
- }
7381
- });
7382
-
7383
- // ../../packages/core/dist/chunk-WTIGECE5.js
7384
- var MAX_NAME_LENGTH, MAX_HUBS_PER_GRANT, MAX_HUB_TAGS_PER_GRANT, MAX_GRANTS, permissionEnum, grantScopeSchema, grantSchema, createTokenBody, tokenOrgIdParam;
7385
- var init_chunk_WTIGECE5 = __esm({
7386
- "../../packages/core/dist/chunk-WTIGECE5.js"() {
6679
+ });
6680
+
6681
+ // ../../packages/core/dist/chunk-WTIGECE5.js
6682
+ var MAX_NAME_LENGTH, MAX_HUBS_PER_GRANT, MAX_HUB_TAGS_PER_GRANT, MAX_GRANTS, permissionEnum, grantScopeSchema, grantSchema, createTokenBody, tokenOrgIdParam;
6683
+ var init_chunk_WTIGECE5 = __esm({
6684
+ "../../packages/core/dist/chunk-WTIGECE5.js"() {
7387
6685
  "use strict";
7388
6686
  init_chunk_S4HVRNEQ();
7389
6687
  init_chunk_HZ6CADSY();
@@ -7421,6 +6719,23 @@ var init_chunk_WTIGECE5 = __esm({
7421
6719
  }
7422
6720
  });
7423
6721
 
6722
+ // ../../packages/core/dist/chunk-WDAXZDJO.js
6723
+ var TOOLSET_ANSWER_PERSON_PARTIES, toolsetAnswerPersonSchema, toolsetAnswerPersonsSchema;
6724
+ var init_chunk_WDAXZDJO = __esm({
6725
+ "../../packages/core/dist/chunk-WDAXZDJO.js"() {
6726
+ "use strict";
6727
+ init_chunk_SSPK6ISL();
6728
+ init_chunk_AHISKXHA();
6729
+ init_zod();
6730
+ TOOLSET_ANSWER_PERSON_PARTIES = ["requester", "originator", "initiator", "delegator"];
6731
+ toolsetAnswerPersonSchema = external_exports.object({
6732
+ party: external_exports.enum(TOOLSET_ANSWER_PERSON_PARTIES),
6733
+ person_id: rekorPersonIdSchema
6734
+ }).strict();
6735
+ toolsetAnswerPersonsSchema = external_exports.array(toolsetAnswerPersonSchema).min(1).max(REKOR_MAX_PERSON_PARTIES);
6736
+ }
6737
+ });
6738
+
7424
6739
  // ../../packages/core/dist/chunk-ZVXO3XL6.js
7425
6740
  var PEOPLE_CONTACT_PAGE_MAX, PEOPLE_CONTACT_PAGE_DEFAULT, PEOPLE_CONTACT_EMAIL_MAX_LENGTH, peopleUserIdSchema, peopleInviteEmailSchema, peopleContactInviteBody, peopleContactInviteIdParam, peopleContactUserIdParam, peopleContactBlockBody, peopleContactPageQuery, peopleOutgoingInviteSchema, peopleContactPersonSchema, peopleContactSchema, peopleIncomingInviteSchema, peopleBlockedUserSchema;
7426
6741
  var init_chunk_ZVXO3XL6 = __esm({
@@ -7465,315 +6780,1000 @@ var init_chunk_ZVXO3XL6 = __esm({
7465
6780
  created_at: timestampSchema,
7466
6781
  expires_at: timestampSchema
7467
6782
  }).strict();
7468
- peopleBlockedUserSchema = peopleContactPersonSchema.extend({ blocked_at: timestampSchema, deleted_user: external_exports.boolean() }).strict();
6783
+ peopleBlockedUserSchema = peopleContactPersonSchema.extend({ blocked_at: timestampSchema, deleted_user: external_exports.boolean() }).strict();
6784
+ }
6785
+ });
6786
+
6787
+ // ../../packages/core/dist/chunk-ZXK6N2HN.js
6788
+ var PEOPLE_MODERATION_NOTE_MAX_LENGTH, ADMIN_PEOPLE_REPORTS_PAGE_MAX, ADMIN_PEOPLE_REPORTS_PAGE_DEFAULT, PEOPLE_SUSPENDED_REASON, peopleModerationActionSchema, moderationNoteSchema, adminPeopleReportListQuery, adminPeopleReportIdParam, adminPeopleMessageRemovalBody, adminPeopleSuspendBody, adminPeopleNoteBody;
6789
+ var init_chunk_ZXK6N2HN = __esm({
6790
+ "../../packages/core/dist/chunk-ZXK6N2HN.js"() {
6791
+ "use strict";
6792
+ init_chunk_ZVXO3XL6();
6793
+ init_chunk_HZ6CADSY();
6794
+ init_zod();
6795
+ PEOPLE_MODERATION_NOTE_MAX_LENGTH = 500;
6796
+ ADMIN_PEOPLE_REPORTS_PAGE_MAX = 100;
6797
+ ADMIN_PEOPLE_REPORTS_PAGE_DEFAULT = 50;
6798
+ PEOPLE_SUSPENDED_REASON = "suspended";
6799
+ peopleModerationActionSchema = external_exports.enum(["remove_message", "suspend", "unsuspend", "dismiss"]);
6800
+ moderationNoteSchema = optionalTrimmedText(PEOPLE_MODERATION_NOTE_MAX_LENGTH);
6801
+ adminPeopleReportListQuery = external_exports.object({
6802
+ pending: external_exports.enum(["true", "false"]).optional().transform((value) => value === "true"),
6803
+ /** Lower bound on `created_at`. */
6804
+ since: timestampSchema.optional(),
6805
+ limit: external_exports.coerce.number().int().min(1).max(ADMIN_PEOPLE_REPORTS_PAGE_MAX).default(ADMIN_PEOPLE_REPORTS_PAGE_DEFAULT),
6806
+ offset: external_exports.coerce.number().int().min(0).default(0)
6807
+ });
6808
+ adminPeopleReportIdParam = external_exports.object({ reportId: uuidSchema });
6809
+ adminPeopleMessageRemovalBody = external_exports.object({ report_id: uuidSchema, message_id: uuidSchema.optional(), note: moderationNoteSchema }).strict();
6810
+ adminPeopleSuspendBody = external_exports.object({ report_id: uuidSchema.optional(), note: moderationNoteSchema }).strict();
6811
+ adminPeopleNoteBody = external_exports.object({ note: moderationNoteSchema }).strict();
6812
+ }
6813
+ });
6814
+
6815
+ // ../../packages/core/dist/chunk-Y7CFCYX4.js
6816
+ var PEOPLE_REPORT_DETAILS_MAX_LENGTH, peopleReportReasonSchema, reportDetailsSchema, reportFields, peopleReportBody;
6817
+ var init_chunk_Y7CFCYX4 = __esm({
6818
+ "../../packages/core/dist/chunk-Y7CFCYX4.js"() {
6819
+ "use strict";
6820
+ init_chunk_ZVXO3XL6();
6821
+ init_chunk_HZ6CADSY();
6822
+ init_zod();
6823
+ PEOPLE_REPORT_DETAILS_MAX_LENGTH = 500;
6824
+ peopleReportReasonSchema = external_exports.enum(["spam", "harassment", "hate", "sexual", "violence", "other"]);
6825
+ reportDetailsSchema = optionalTrimmedText(PEOPLE_REPORT_DETAILS_MAX_LENGTH);
6826
+ reportFields = { reason: peopleReportReasonSchema, details: reportDetailsSchema };
6827
+ peopleReportBody = external_exports.discriminatedUnion("target", [
6828
+ external_exports.object({ target: external_exports.literal("message"), thread_id: uuidSchema, message_id: uuidSchema, ...reportFields }).strict(),
6829
+ external_exports.object({ target: external_exports.literal("thread"), thread_id: uuidSchema, ...reportFields }).strict(),
6830
+ external_exports.object({ target: external_exports.literal("user"), user_id: peopleUserIdSchema, thread_id: uuidSchema.optional(), ...reportFields }).strict(),
6831
+ external_exports.object({
6832
+ target: external_exports.literal("community_message"),
6833
+ community_id: uuidSchema,
6834
+ room_id: uuidSchema,
6835
+ message_id: uuidSchema,
6836
+ ...reportFields
6837
+ }).strict(),
6838
+ external_exports.object({ target: external_exports.literal("community_member"), community_id: uuidSchema, user_id: peopleUserIdSchema, ...reportFields }).strict()
6839
+ ]);
6840
+ }
6841
+ });
6842
+
6843
+ // ../../packages/core/dist/chunk-2YEGUQR7.js
6844
+ var PERSON_ID_PATTERN, CONTACT_PERSON_ID_PATTERN, PERSON_ID_FORM_MESSAGE, userPersonIdSchema, personIdSchema;
6845
+ var init_chunk_2YEGUQR7 = __esm({
6846
+ "../../packages/core/dist/chunk-2YEGUQR7.js"() {
6847
+ "use strict";
6848
+ init_zod();
6849
+ PERSON_ID_PATTERN = /^prs_[a-z2-7]{52}$/;
6850
+ CONTACT_PERSON_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
6851
+ PERSON_ID_FORM_MESSAGE = "Must be a person id (prs_\u2026) or a contact id (a lowercase UUID)";
6852
+ userPersonIdSchema = external_exports.string().regex(PERSON_ID_PATTERN, { message: "Must be a person id (prs_\u2026)" });
6853
+ personIdSchema = external_exports.string().refine(
6854
+ (value) => PERSON_ID_PATTERN.test(value) || CONTACT_PERSON_ID_PATTERN.test(value),
6855
+ { message: PERSON_ID_FORM_MESSAGE }
6856
+ );
6857
+ }
6858
+ });
6859
+
6860
+ // ../../packages/core/dist/chunk-UAOHHCW5.js
6861
+ function normalizeContactPhone(raw) {
6862
+ const compact = raw.trim().replace(/[\s\-.()]/g, "");
6863
+ const withPlus = compact.startsWith("00") ? `+${compact.slice(2)}` : compact;
6864
+ return /^\+[1-9]\d{7,14}$/.test(withPlus) ? withPlus : null;
6865
+ }
6866
+ function normalizeContactLabel(raw) {
6867
+ return raw.trim().replace(/\s+/g, " ").toLowerCase();
6868
+ }
6869
+ function importRowLabels(row, batchLabels) {
6870
+ return [.../* @__PURE__ */ new Set([...row.labels ?? [], ...batchLabels ?? []])];
6871
+ }
6872
+ var CONTACT_ENVIRONMENTS, CONTACT_NAME_MAX, CONTACT_EMAIL_MAX, CONTACT_PHONE_INPUT_MAX, CONTACT_INSTAGRAM_SID_MAX, CONTACT_METADATA_MAX_BYTES, CONTACT_LABEL_MAX, CONTACT_LABELS_MAX, CONTACT_SCOPE_TAGS_MAX, CONTACT_PAGE_MAX, CONTACT_IMPORT_BATCH_MAX, CONTACT_SEARCH_MAX, CONTACT_LIST_NAME_MAX, CONTACT_LIST_NAME_REGEX, CONTACT_LIST_DESCRIPTION_MAX, CONTACT_LIST_FILTER_MAX, CONTACT_LIST_PINS_PER_REQUEST_MAX, SUPPRESSION_SCOPES, SUPPRESSION_ID_REGEX, contactName, contactPhone, contactEmail, contactInstagramSid, contactLabel, contactLabels, contactMetadata, scopeTagIds, contactVisibilitySchema, hasIdentity, IDENTITY_REQUIRED, contactBookOrgQuery, contactBookContactParam, contactBookListParam, contactBookHubParam, contactBookPageQuery, listContactBookContactsQuery, listHubContactBookContactsQuery, contactBookLinkCandidatesQuery, listContactBookListMembersQuery, contactRowFields, createContactBookContactBody, updateContactBookContactBody, contactImportRowSchema, importContactBookContactsBody, linkContactBookContactBody, listName, contactListFilterSchema, createContactBookListBody, updateContactBookListBody, updateContactBookListPinsBody, suppressionIdentitySchema, createContactBookSuppressionBody, contactBookSuppressionParam, listContactBookSuppressionsQuery, contactBookEmailUnsubscribeTokenSchema, contactBookEmailUnsubscribeQuery, orgListReferenceSchema;
6873
+ var init_chunk_UAOHHCW5 = __esm({
6874
+ "../../packages/core/dist/chunk-UAOHHCW5.js"() {
6875
+ "use strict";
6876
+ init_zod();
6877
+ CONTACT_ENVIRONMENTS = ["production", "preview", "all"];
6878
+ CONTACT_NAME_MAX = 200;
6879
+ CONTACT_EMAIL_MAX = 320;
6880
+ CONTACT_PHONE_INPUT_MAX = 40;
6881
+ CONTACT_INSTAGRAM_SID_MAX = 64;
6882
+ CONTACT_METADATA_MAX_BYTES = 4096;
6883
+ CONTACT_LABEL_MAX = 64;
6884
+ CONTACT_LABELS_MAX = 20;
6885
+ CONTACT_SCOPE_TAGS_MAX = 20;
6886
+ CONTACT_PAGE_MAX = 100;
6887
+ CONTACT_IMPORT_BATCH_MAX = 500;
6888
+ CONTACT_SEARCH_MAX = 100;
6889
+ CONTACT_LIST_NAME_MAX = 64;
6890
+ CONTACT_LIST_NAME_REGEX = /^[a-z0-9]+(-[a-z0-9]+)*$/;
6891
+ CONTACT_LIST_DESCRIPTION_MAX = 1e3;
6892
+ CONTACT_LIST_FILTER_MAX = 20;
6893
+ CONTACT_LIST_PINS_PER_REQUEST_MAX = 100;
6894
+ SUPPRESSION_SCOPES = ["all", "marketing"];
6895
+ SUPPRESSION_ID_REGEX = /^[0-9a-f]{64}$/;
6896
+ contactName = external_exports.string().trim().min(1).max(CONTACT_NAME_MAX);
6897
+ contactPhone = external_exports.string().max(CONTACT_PHONE_INPUT_MAX).transform((raw, ctx) => {
6898
+ const phone = normalizeContactPhone(raw);
6899
+ if (phone === null) {
6900
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: "Phone must be an international number, e.g. +5511999999999" });
6901
+ return external_exports.NEVER;
6902
+ }
6903
+ return phone;
6904
+ });
6905
+ contactEmail = external_exports.string().trim().toLowerCase().max(CONTACT_EMAIL_MAX).email();
6906
+ contactInstagramSid = external_exports.string().trim().min(1).max(CONTACT_INSTAGRAM_SID_MAX);
6907
+ contactLabel = external_exports.string().max(CONTACT_LABEL_MAX).transform(normalizeContactLabel).refine((label3) => label3.length > 0, "A label cannot be empty").refine((label3) => !label3.includes(","), "A label cannot contain a comma");
6908
+ contactLabels = external_exports.array(contactLabel).max(CONTACT_LABELS_MAX).transform((labels) => [...new Set(labels)]);
6909
+ contactMetadata = external_exports.record(external_exports.unknown()).refine((metadata) => {
6910
+ try {
6911
+ return new TextEncoder().encode(JSON.stringify(metadata)).length <= CONTACT_METADATA_MAX_BYTES;
6912
+ } catch {
6913
+ return false;
6914
+ }
6915
+ }, `Metadata must serialize to at most ${CONTACT_METADATA_MAX_BYTES} bytes`);
6916
+ scopeTagIds = external_exports.array(external_exports.string().uuid()).min(1).max(CONTACT_SCOPE_TAGS_MAX).transform((ids) => [...new Set(ids)]);
6917
+ contactVisibilitySchema = external_exports.discriminatedUnion("scope", [
6918
+ external_exports.object({ scope: external_exports.literal("all_hubs") }).strict(),
6919
+ external_exports.object({ scope: external_exports.literal("tags"), tag_ids: scopeTagIds }).strict()
6920
+ ]);
6921
+ hasIdentity = (row) => Boolean(row.phone || row.email || row.instagram_sid);
6922
+ IDENTITY_REQUIRED = "A contact needs a phone, an email or an Instagram id";
6923
+ contactBookOrgQuery = external_exports.object({
6924
+ organization_id: external_exports.string().uuid()
6925
+ });
6926
+ contactBookContactParam = external_exports.object({
6927
+ contactId: external_exports.string().uuid()
6928
+ });
6929
+ contactBookListParam = external_exports.object({
6930
+ listId: external_exports.string().uuid()
6931
+ });
6932
+ contactBookHubParam = external_exports.object({
6933
+ hubId: external_exports.string().uuid()
6934
+ });
6935
+ contactBookPageQuery = external_exports.object({
6936
+ cursor: external_exports.string().max(2048).optional(),
6937
+ limit: external_exports.coerce.number().int().min(1).max(CONTACT_PAGE_MAX).default(50)
6938
+ });
6939
+ listContactBookContactsQuery = contactBookOrgQuery.merge(contactBookPageQuery).extend({
6940
+ q: external_exports.string().trim().max(CONTACT_SEARCH_MAX).optional(),
6941
+ label: external_exports.string().max(CONTACT_LABEL_MAX).transform(normalizeContactLabel).optional(),
6942
+ scope_tag_id: external_exports.string().uuid().optional()
6943
+ });
6944
+ listHubContactBookContactsQuery = contactBookPageQuery.extend({
6945
+ q: external_exports.string().trim().max(CONTACT_SEARCH_MAX).optional()
6946
+ });
6947
+ contactBookLinkCandidatesQuery = contactBookOrgQuery.extend({
6948
+ email: contactEmail
6949
+ });
6950
+ listContactBookListMembersQuery = contactBookOrgQuery.merge(contactBookPageQuery);
6951
+ contactRowFields = {
6952
+ name: contactName,
6953
+ phone: contactPhone.nullish(),
6954
+ email: contactEmail.nullish(),
6955
+ instagram_sid: contactInstagramSid.nullish(),
6956
+ labels: contactLabels.optional(),
6957
+ metadata: contactMetadata.optional()
6958
+ };
6959
+ createContactBookContactBody = external_exports.object({
6960
+ organization_id: external_exports.string().uuid(),
6961
+ ...contactRowFields,
6962
+ visibility: contactVisibilitySchema,
6963
+ environment: external_exports.enum(CONTACT_ENVIRONMENTS).optional()
6964
+ }).strict().refine(hasIdentity, IDENTITY_REQUIRED);
6965
+ updateContactBookContactBody = external_exports.object({
6966
+ name: contactName.optional(),
6967
+ phone: contactPhone.nullable().optional(),
6968
+ email: contactEmail.nullable().optional(),
6969
+ instagram_sid: contactInstagramSid.nullable().optional(),
6970
+ labels: contactLabels.optional(),
6971
+ metadata: contactMetadata.optional(),
6972
+ visibility: contactVisibilitySchema.optional(),
6973
+ environment: external_exports.enum(CONTACT_ENVIRONMENTS).optional()
6974
+ }).strict();
6975
+ contactImportRowSchema = external_exports.object(contactRowFields).strict().refine(hasIdentity, IDENTITY_REQUIRED);
6976
+ importContactBookContactsBody = external_exports.object({
6977
+ organization_id: external_exports.string().uuid(),
6978
+ visibility: contactVisibilitySchema,
6979
+ environment: external_exports.enum(CONTACT_ENVIRONMENTS).optional(),
6980
+ labels: contactLabels.optional(),
6981
+ rows: external_exports.array(contactImportRowSchema).min(1).max(CONTACT_IMPORT_BATCH_MAX)
6982
+ }).strict().superRefine((batch, ctx) => {
6983
+ batch.rows.forEach((row, index) => {
6984
+ if (importRowLabels(row, batch.labels).length > CONTACT_LABELS_MAX) {
6985
+ ctx.addIssue({
6986
+ code: external_exports.ZodIssueCode.custom,
6987
+ path: ["rows", index, "labels"],
6988
+ message: `A contact holds at most ${CONTACT_LABELS_MAX} labels, the batch's included`
6989
+ });
6990
+ }
6991
+ });
6992
+ });
6993
+ linkContactBookContactBody = external_exports.object({
6994
+ user_id: external_exports.string().min(1).max(128)
6995
+ }).strict();
6996
+ listName = external_exports.string().trim().min(1).max(CONTACT_LIST_NAME_MAX).regex(CONTACT_LIST_NAME_REGEX, {
6997
+ message: 'Must be lowercase alphanumeric with hyphens (e.g. "vip-customers")'
6998
+ });
6999
+ contactListFilterSchema = external_exports.object({
7000
+ labels: external_exports.array(contactLabel).max(CONTACT_LIST_FILTER_MAX).transform((l) => [...new Set(l)]).default([]),
7001
+ scope_tag_ids: external_exports.array(external_exports.string().uuid()).max(CONTACT_LIST_FILTER_MAX).transform((t) => [...new Set(t)]).default([])
7002
+ }).strict();
7003
+ createContactBookListBody = external_exports.object({
7004
+ organization_id: external_exports.string().uuid(),
7005
+ name: listName,
7006
+ description: external_exports.string().max(CONTACT_LIST_DESCRIPTION_MAX).nullish(),
7007
+ filter: contactListFilterSchema.optional()
7008
+ }).strict();
7009
+ updateContactBookListBody = external_exports.object({
7010
+ name: listName.optional(),
7011
+ description: external_exports.string().max(CONTACT_LIST_DESCRIPTION_MAX).nullable().optional(),
7012
+ filter: contactListFilterSchema.optional()
7013
+ }).strict();
7014
+ updateContactBookListPinsBody = external_exports.object({
7015
+ add: external_exports.array(external_exports.string().uuid()).max(CONTACT_LIST_PINS_PER_REQUEST_MAX).default([]),
7016
+ remove: external_exports.array(external_exports.string().uuid()).max(CONTACT_LIST_PINS_PER_REQUEST_MAX).default([])
7017
+ }).strict().refine((b) => b.add.length + b.remove.length > 0, "Add or remove at least one contact");
7018
+ suppressionIdentitySchema = external_exports.discriminatedUnion("kind", [
7019
+ external_exports.object({ kind: external_exports.literal("phone"), value: contactPhone }).strict(),
7020
+ external_exports.object({ kind: external_exports.literal("email"), value: contactEmail }).strict(),
7021
+ external_exports.object({ kind: external_exports.literal("instagram"), value: contactInstagramSid }).strict()
7022
+ ]);
7023
+ createContactBookSuppressionBody = external_exports.object({
7024
+ organization_id: external_exports.string().uuid(),
7025
+ identity: suppressionIdentitySchema,
7026
+ scope: external_exports.enum(SUPPRESSION_SCOPES)
7027
+ }).strict();
7028
+ contactBookSuppressionParam = external_exports.object({
7029
+ suppressionId: external_exports.string().regex(SUPPRESSION_ID_REGEX)
7030
+ });
7031
+ listContactBookSuppressionsQuery = contactBookOrgQuery.merge(contactBookPageQuery);
7032
+ contactBookEmailUnsubscribeTokenSchema = external_exports.string().max(200).regex(/^[0-9a-f-]{36}\.[0-9a-f]{64}\.[0-9a-f]{64}$/i);
7033
+ contactBookEmailUnsubscribeQuery = external_exports.object({ token: contactBookEmailUnsubscribeTokenSchema });
7034
+ orgListReferenceSchema = listName;
7469
7035
  }
7470
7036
  });
7471
7037
 
7472
- // ../../packages/core/dist/chunk-ZXK6N2HN.js
7473
- var PEOPLE_MODERATION_NOTE_MAX_LENGTH, ADMIN_PEOPLE_REPORTS_PAGE_MAX, ADMIN_PEOPLE_REPORTS_PAGE_DEFAULT, PEOPLE_SUSPENDED_REASON, peopleModerationActionSchema, moderationNoteSchema, adminPeopleReportListQuery, adminPeopleReportIdParam, adminPeopleMessageRemovalBody, adminPeopleSuspendBody, adminPeopleNoteBody;
7474
- var init_chunk_ZXK6N2HN = __esm({
7475
- "../../packages/core/dist/chunk-ZXK6N2HN.js"() {
7038
+ // ../../packages/core/dist/chunk-MGBAXT5Y.js
7039
+ var PERSON_LINKS_MAX, PERSON_DENY_PAGE_MAX, personParam, personLinkParam, deniedPersonParam, listDeniedPersonsQuery, conversationCustomerPersonParam;
7040
+ var init_chunk_MGBAXT5Y = __esm({
7041
+ "../../packages/core/dist/chunk-MGBAXT5Y.js"() {
7476
7042
  "use strict";
7477
- init_chunk_ZVXO3XL6();
7478
- init_chunk_HZ6CADSY();
7043
+ init_chunk_2YEGUQR7();
7044
+ init_chunk_UAOHHCW5();
7479
7045
  init_zod();
7480
- PEOPLE_MODERATION_NOTE_MAX_LENGTH = 500;
7481
- ADMIN_PEOPLE_REPORTS_PAGE_MAX = 100;
7482
- ADMIN_PEOPLE_REPORTS_PAGE_DEFAULT = 50;
7483
- PEOPLE_SUSPENDED_REASON = "suspended";
7484
- peopleModerationActionSchema = external_exports.enum(["remove_message", "suspend", "unsuspend", "dismiss"]);
7485
- moderationNoteSchema = optionalTrimmedText(PEOPLE_MODERATION_NOTE_MAX_LENGTH);
7486
- adminPeopleReportListQuery = external_exports.object({
7487
- pending: external_exports.enum(["true", "false"]).optional().transform((value) => value === "true"),
7488
- /** Lower bound on `created_at`. */
7489
- since: timestampSchema.optional(),
7490
- limit: external_exports.coerce.number().int().min(1).max(ADMIN_PEOPLE_REPORTS_PAGE_MAX).default(ADMIN_PEOPLE_REPORTS_PAGE_DEFAULT),
7491
- offset: external_exports.coerce.number().int().min(0).default(0)
7046
+ PERSON_LINKS_MAX = 15;
7047
+ PERSON_DENY_PAGE_MAX = 100;
7048
+ personParam = external_exports.object({
7049
+ personId: userPersonIdSchema
7050
+ });
7051
+ personLinkParam = personParam.extend({
7052
+ targetId: personIdSchema
7053
+ });
7054
+ deniedPersonParam = external_exports.object({
7055
+ personId: personIdSchema
7056
+ });
7057
+ listDeniedPersonsQuery = contactBookOrgQuery.extend({
7058
+ cursor: personIdSchema.optional(),
7059
+ limit: external_exports.coerce.number().int().min(1).max(PERSON_DENY_PAGE_MAX).default(50)
7060
+ });
7061
+ conversationCustomerPersonParam = external_exports.object({
7062
+ hubId: external_exports.string().uuid(),
7063
+ conversationId: external_exports.string().uuid()
7492
7064
  });
7493
- adminPeopleReportIdParam = external_exports.object({ reportId: uuidSchema });
7494
- adminPeopleMessageRemovalBody = external_exports.object({ report_id: uuidSchema, message_id: uuidSchema.optional(), note: moderationNoteSchema }).strict();
7495
- adminPeopleSuspendBody = external_exports.object({ report_id: uuidSchema.optional(), note: moderationNoteSchema }).strict();
7496
- adminPeopleNoteBody = external_exports.object({ note: moderationNoteSchema }).strict();
7497
7065
  }
7498
7066
  });
7499
7067
 
7500
- // ../../packages/core/dist/chunk-Y7CFCYX4.js
7501
- var PEOPLE_REPORT_DETAILS_MAX_LENGTH, peopleReportReasonSchema, reportDetailsSchema, reportFields, peopleReportBody;
7502
- var init_chunk_Y7CFCYX4 = __esm({
7503
- "../../packages/core/dist/chunk-Y7CFCYX4.js"() {
7068
+ // ../../packages/core/dist/chunk-5DGHIY7L.js
7069
+ var rekorBaseChangeMessageSchema;
7070
+ var init_chunk_5DGHIY7L = __esm({
7071
+ "../../packages/core/dist/chunk-5DGHIY7L.js"() {
7504
7072
  "use strict";
7505
- init_chunk_ZVXO3XL6();
7506
- init_chunk_HZ6CADSY();
7507
7073
  init_zod();
7508
- PEOPLE_REPORT_DETAILS_MAX_LENGTH = 500;
7509
- peopleReportReasonSchema = external_exports.enum(["spam", "harassment", "hate", "sexual", "violence", "other"]);
7510
- reportDetailsSchema = optionalTrimmedText(PEOPLE_REPORT_DETAILS_MAX_LENGTH);
7511
- reportFields = { reason: peopleReportReasonSchema, details: reportDetailsSchema };
7512
- peopleReportBody = external_exports.discriminatedUnion("target", [
7513
- external_exports.object({ target: external_exports.literal("message"), thread_id: uuidSchema, message_id: uuidSchema, ...reportFields }).strict(),
7514
- external_exports.object({ target: external_exports.literal("thread"), thread_id: uuidSchema, ...reportFields }).strict(),
7515
- external_exports.object({ target: external_exports.literal("user"), user_id: peopleUserIdSchema, thread_id: uuidSchema.optional(), ...reportFields }).strict(),
7516
- external_exports.object({
7517
- target: external_exports.literal("community_message"),
7518
- community_id: uuidSchema,
7519
- room_id: uuidSchema,
7520
- message_id: uuidSchema,
7521
- ...reportFields
7522
- }).strict(),
7523
- external_exports.object({ target: external_exports.literal("community_member"), community_id: uuidSchema, user_id: peopleUserIdSchema, ...reportFields }).strict()
7524
- ]);
7074
+ rekorBaseChangeMessageSchema = external_exports.object({
7075
+ /** The WayAI org UUID — one id namespace. */
7076
+ org_id: external_exports.string().uuid(),
7077
+ /**
7078
+ * Not a UUID: a preview base id is `{prod_base_id}--{slug}`. Immutable per base — a
7079
+ * preview clone is its OWN base_id — so `(base_id, scope)` keys never collide across
7080
+ * environments. Empty is never a real base id, so it is non-conforming rather than a
7081
+ * frame keyed on nothing.
7082
+ */
7083
+ base_id: external_exports.string().min(1),
7084
+ /**
7085
+ * Rides along so the client scopes its refetch without a lookup; the inspector scopes
7086
+ * by side.
7087
+ */
7088
+ environment: external_exports.enum(["production", "preview"]),
7089
+ /** Which pane refetches. `base` covers create/delete/promote/config changes. */
7090
+ scope: external_exports.enum(["records", "record_types", "files", "base"])
7091
+ });
7525
7092
  }
7526
7093
  });
7527
7094
 
7528
- // ../../packages/core/dist/chunk-2YEGUQR7.js
7529
- var PERSON_ID_PATTERN, CONTACT_PERSON_ID_PATTERN, PERSON_ID_FORM_MESSAGE, userPersonIdSchema, personIdSchema;
7530
- var init_chunk_2YEGUQR7 = __esm({
7531
- "../../packages/core/dist/chunk-2YEGUQR7.js"() {
7095
+ // ../../packages/core/dist/chunk-5FO3GNKP.js
7096
+ var DATA_PROXY_MOUNT, DATA_PROXY_PREFIX, BASE_DESTRUCTION_MOUNT, BASE_DESTRUCTION_PREFIX, BASE_DESTRUCTION_CONFIRM_PATH, COMMUNITY_EMAIL_UNSUBSCRIBE_PATH, CONTACT_BOOK_EMAIL_UNSUBSCRIBE_PATH, AUTOMATION_WEBHOOK_MOUNT, MANAGED_AGENTS_WEBHOOK_MOUNT, TELEGRAM_VAULT_WEBHOOK_PATH;
7097
+ var init_chunk_5FO3GNKP = __esm({
7098
+ "../../packages/core/dist/chunk-5FO3GNKP.js"() {
7532
7099
  "use strict";
7533
- init_zod();
7534
- PERSON_ID_PATTERN = /^prs_[a-z2-7]{52}$/;
7535
- CONTACT_PERSON_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
7536
- PERSON_ID_FORM_MESSAGE = "Must be a person id (prs_\u2026) or a contact id (a lowercase UUID)";
7537
- userPersonIdSchema = external_exports.string().regex(PERSON_ID_PATTERN, { message: "Must be a person id (prs_\u2026)" });
7538
- personIdSchema = external_exports.string().refine(
7539
- (value) => PERSON_ID_PATTERN.test(value) || CONTACT_PERSON_ID_PATTERN.test(value),
7540
- { message: PERSON_ID_FORM_MESSAGE }
7541
- );
7100
+ DATA_PROXY_MOUNT = "/data";
7101
+ DATA_PROXY_PREFIX = `/api${DATA_PROXY_MOUNT}`;
7102
+ BASE_DESTRUCTION_MOUNT = "/bases";
7103
+ BASE_DESTRUCTION_PREFIX = `/api${BASE_DESTRUCTION_MOUNT}`;
7104
+ BASE_DESTRUCTION_CONFIRM_PATH = `${BASE_DESTRUCTION_PREFIX}/destruction/confirm`;
7105
+ COMMUNITY_EMAIL_UNSUBSCRIBE_PATH = "/api/communities/email-unsubscribe";
7106
+ CONTACT_BOOK_EMAIL_UNSUBSCRIBE_PATH = "/api/contact-book/email-unsubscribe";
7107
+ AUTOMATION_WEBHOOK_MOUNT = "/webhooks/automations";
7108
+ MANAGED_AGENTS_WEBHOOK_MOUNT = "/webhooks/managed-agents";
7109
+ TELEGRAM_VAULT_WEBHOOK_PATH = "/webhooks/telegram/vault";
7110
+ }
7111
+ });
7112
+
7113
+ // ../../packages/core/dist/chunk-7AYJHO5P.js
7114
+ function matchPath(pattern, path46) {
7115
+ const pathSegments2 = path46.replace(/\/$/, "").split("/");
7116
+ const isPrefix = pattern.endsWith("/*");
7117
+ const patternSegments = (isPrefix ? pattern.slice(0, -2) : pattern).split("/");
7118
+ if (isPrefix ? pathSegments2.length < patternSegments.length : pathSegments2.length !== patternSegments.length) {
7119
+ return false;
7120
+ }
7121
+ return patternSegments.every((segment, i) => segment === "*" ? pathSegments2[i] !== "" : segment === pathSegments2[i]);
7122
+ }
7123
+ function getEndpointConfig(path46) {
7124
+ for (const excluded of EXCLUDED_PATHS) {
7125
+ if (matchPath(excluded, path46)) {
7126
+ return null;
7127
+ }
7128
+ }
7129
+ const normalizedPath = path46.replace(/\/$/, "");
7130
+ if (!normalizedPath.endsWith("/*") && Object.prototype.hasOwnProperty.call(ENDPOINT_CONFIGS, normalizedPath)) {
7131
+ return ENDPOINT_CONFIGS[normalizedPath];
7132
+ }
7133
+ const sortedPatterns = Object.keys(ENDPOINT_CONFIGS).sort((a, b) => b.length - a.length);
7134
+ for (const pattern of sortedPatterns) {
7135
+ if (matchPath(pattern, path46)) {
7136
+ return ENDPOINT_CONFIGS[pattern];
7137
+ }
7138
+ }
7139
+ return { tier: "STANDARD" };
7140
+ }
7141
+ var ENDPOINT_CONFIGS, EXCLUDED_PATHS;
7142
+ var init_chunk_7AYJHO5P = __esm({
7143
+ "../../packages/core/dist/chunk-7AYJHO5P.js"() {
7144
+ "use strict";
7145
+ init_chunk_5FO3GNKP();
7146
+ ENDPOINT_CONFIGS = {
7147
+ // OAuth callbacks - strict, fail-closed (prevent brute force)
7148
+ "/oauth/callback/*": { tier: "STRICT", failClosed: true },
7149
+ // Auth endpoints - strict, fail-closed
7150
+ "/auth/phone": { tier: "STRICT", failClosed: true },
7151
+ "/auth/mcp/exchange": { tier: "MODERATE", failClosed: true },
7152
+ // Native magic-code login (pre-auth) — STRICT per-IP bounds a single host; WorkOS owns
7153
+ // the per-email lockout / TTL / single-use guarantees.
7154
+ "/api/auth/magic-code/*": { tier: "STRICT", failClosed: true },
7155
+ // Native password login (pre-auth) — same posture as magic-code above. STRICT per-IP bounds a
7156
+ // single host but FAILS OPEN on a binding error (like every IP limit); the `failClosed` flag
7157
+ // here is inert on a pre-auth route (it's only enforced on the per-user branch, which needs an
7158
+ // authenticated caller). The fail-CLOSED brute-force guarantee for the static credential comes
7159
+ // from the route's per-email caps (burst + cumulative hourly), not this flag.
7160
+ "/api/auth/password/*": { tier: "STRICT", failClosed: true },
7161
+ // Attempts at a two-step code. STRICT per IP; the routes add a per-user cap, the one that matters
7162
+ // against guessing. The status read's exact key keeps it off that budget, which sign-in shares.
7163
+ "/api/auth/second-factor": { tier: "STANDARD" },
7164
+ "/api/auth/second-factor/*": { tier: "STRICT", failClosed: true },
7165
+ // Every `/api/*` group whose paths carry ids pins `userLimitKey` (gh #4756), held there by
7166
+ // `security/endpoint-invariants.test.ts`.
7167
+ // Billing - moderate, fail-closed with user limits
7168
+ "/api/billing/*": {
7169
+ tier: "MODERATE",
7170
+ userLimit: 100,
7171
+ failClosed: true,
7172
+ skipAuthenticatedUsers: true,
7173
+ userLimitKey: "/api/billing/*"
7174
+ },
7175
+ "/webhooks/stripe": { tier: "MODERATE", failClosed: true },
7176
+ "/webhooks/workos": { tier: "MODERATE", failClosed: true },
7177
+ // API endpoints - standard with user limits
7178
+ // 500 because the web's settings live updates refetch per hub in every open tab, whatever page
7179
+ // it shows (`settingsLiveUpdateStore.ts`): one batch of changes costs about 10 + 4 per agent
7180
+ // whose tools were opened + 2 per loaded resource, so a CLI push and publish (both hubs) with
7181
+ // two tabs open passes 150 in a minute. A multi-file resource upload adds 2–5 per file.
7182
+ "/api/setup/*": {
7183
+ tier: "STANDARD",
7184
+ userLimit: 500,
7185
+ skipAuthenticatedUsers: true,
7186
+ userLimitKey: "/api/setup/*"
7187
+ },
7188
+ // 500 because an eval run's drill-down (`SessionResults.tsx`) fetches its list and then every
7189
+ // LLM turn's record at once: up to 201 requests (`OBSERVABILITY_LIST_CAP`, 200). Sending keeps
7190
+ // the 150 it had when each path held its own budget, on the exact key below.
7191
+ "/api/conversations/*": {
7192
+ tier: "STANDARD",
7193
+ userLimit: 500,
7194
+ skipAuthenticatedUsers: true,
7195
+ userLimitKey: "/api/conversations/*"
7196
+ },
7197
+ "/api/conversations/send-message": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
7198
+ "/api/users/*": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
7199
+ "/api/analytics/*": {
7200
+ tier: "STANDARD",
7201
+ userLimit: 150,
7202
+ skipAuthenticatedUsers: true,
7203
+ userLimitKey: "/api/analytics/*"
7204
+ },
7205
+ // 500 because `wayai eval-results --eval` reads completed sessions one by one, newest first,
7206
+ // until one holds the eval (up to the 1000 the list returns). Tenant SQL keeps the 150 it had
7207
+ // when each path held its own budget: each query may run 30 s on shared-tenant ClickHouse
7208
+ // after its caller has gone (`sql-validator.ts`, stage 10b).
7209
+ "/api/evals/*": {
7210
+ tier: "STANDARD",
7211
+ userLimit: 500,
7212
+ skipAuthenticatedUsers: true,
7213
+ userLimitKey: "/api/evals/*"
7214
+ },
7215
+ "/api/evals/sql": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
7216
+ // An eval run's calls (gh #4418), kept off the end user's call budgets below. Create keeps the
7217
+ // 150 it had: it opens a provider session on the org's own key, billed per second. The routes
7218
+ // on one call take a budget of their own so no eval read can spend it: a refused hang-up
7219
+ // leaves the call running, and billing. 500 because a call suite polls each run's record
7220
+ // every second, about 64 requests a minute per suite.
7221
+ "/api/evals/calls": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
7222
+ "/api/evals/calls/*": {
7223
+ tier: "STANDARD",
7224
+ userLimit: 500,
7225
+ skipAuthenticatedUsers: true,
7226
+ userLimitKey: "/api/evals/calls/*"
7227
+ },
7228
+ "/api/files/*": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
7229
+ // The org contact book (wayai#4931 PR 2b). A CSV import sends one request per
7230
+ // `CONTACT_IMPORT_BATCH_MAX` rows, so 150 a minute imports 75,000 rows a minute.
7231
+ "/api/contact-book/*": {
7232
+ tier: "STANDARD",
7233
+ userLimit: 150,
7234
+ skipAuthenticatedUsers: true,
7235
+ userLimitKey: "/api/contact-book/*"
7236
+ },
7237
+ // An automation email's one-click unsubscribe (wayai#4931 PR 2d) — public: its token is its one
7238
+ // credential, so this per-IP limit is its one bound, and runs before the route reads anything.
7239
+ // MODERATE (30/min per IP), as the community email's unsubscribe, for the same reason: mail
7240
+ // clients' one-click unsubscribe POSTs it from their own servers, which many recipients' clicks
7241
+ // share. An exact key, so it wins over the wildcard above.
7242
+ [CONTACT_BOOK_EMAIL_UNSUBSCRIBE_PATH]: { tier: "MODERATE" },
7243
+ "/api/automations/*": {
7244
+ tier: "STANDARD",
7245
+ userLimit: 150,
7246
+ skipAuthenticatedUsers: true,
7247
+ userLimitKey: "/api/automations/*"
7248
+ },
7249
+ // A hub's own contact lists (wayai#4931 PR 2c): config edits, at the automations' rate.
7250
+ "/api/hub-contact-lists/*": {
7251
+ tier: "STANDARD",
7252
+ userLimit: 150,
7253
+ skipAuthenticatedUsers: true,
7254
+ userLimitKey: "/api/hub-contact-lists/*"
7255
+ },
7256
+ "/api/message-templates/*": {
7257
+ tier: "STANDARD",
7258
+ userLimit: 150,
7259
+ skipAuthenticatedUsers: true,
7260
+ userLimitKey: "/api/message-templates/*"
7261
+ },
7262
+ "/api/live-updates/*": { tier: "STANDARD", userLimit: 150, skipAuthenticatedUsers: true },
7263
+ "/api/hub-users/*": {
7264
+ tier: "STANDARD",
7265
+ userLimit: 150,
7266
+ skipAuthenticatedUsers: true,
7267
+ userLimitKey: "/api/hub-users/*"
7268
+ },
7269
+ "/api/conversation-state/*": {
7270
+ tier: "STANDARD",
7271
+ userLimit: 150,
7272
+ skipAuthenticatedUsers: true,
7273
+ userLimitKey: "/api/conversation-state/*"
7274
+ },
7275
+ // The authenticated byte route (`routes/files/r2.ts`), mounted after its `authMiddleware` so
7276
+ // the caller is known: each request reads the HubDO its key names, and a hub id never created
7277
+ // still wakes a Durable Object (gh #4747; since gh #4775 T5 one that writes nothing). The key is pinned
7278
+ // because the paths are file keys, which would otherwise each get a fresh budget (and one
7279
+ // over 256 characters would be refused outright, `checkUserLimitNative`).
7280
+ //
7281
+ // 500 a minute because the web chat fetches every attachment of every loaded message at
7282
+ // once, with no list virtualization: up to 50 per 50-message page, 200 per ended
7283
+ // conversation or history entry at one file per message, and 4 per message at most in its
7284
+ // image grid. Repeats come from the browser's HTTP cache (`private, max-age=3600`); mobile
7285
+ // renders through a disk cache and plays audio from `/files/signed`. The budget is shared by
7286
+ // a caller's tabs and devices. The other two byte routes, `/files/signed/*` and
7287
+ // `/files/public/*`, mount no limiter (the reason is at their entries in
7288
+ // `security/endpoint-invariants.test.ts`'s route registry).
7289
+ "/files/auth/*": {
7290
+ tier: "STANDARD",
7291
+ userLimit: 500,
7292
+ skipAuthenticatedUsers: true,
7293
+ userLimitKey: "/files/auth/*"
7294
+ },
7295
+ // Channel webhooks - high throughput (external systems, never authenticated)
7296
+ "/webhooks/whatsapp/*": { tier: "HIGH" },
7297
+ "/webhooks/instagram/*": { tier: "HIGH" },
7298
+ // An automation's webhook deliveries (wayai#4931 D13) — no bearer token: the automation's
7299
+ // secret is the credential, checked against one HubDO read. This per-IP limit runs first, before
7300
+ // anything is read. HIGH, as the channel webhooks: senders are servers, and an integration
7301
+ // platform's egress addresses carry many tenants' deliveries. The per-automation budget is
7302
+ // `AUTOMATION_WEBHOOK_PER_AUTOMATION_LIMIT`, counted after the delivery is verified.
7303
+ [`${AUTOMATION_WEBHOOK_MOUNT}/*`]: { tier: "HIGH" },
7304
+ // Managed Agents session events (#5083 Phase 4): one delivery per hosted tool round, and one
7305
+ // vendor address carries every tenant's, so BULK. The per-connection budget is
7306
+ // `MANAGED_AGENTS_WEBHOOK_PER_CONNECTION_LIMIT`, counted after the delivery is verified.
7307
+ [`${MANAGED_AGENTS_WEBHOOK_MOUNT}/*`]: { tier: "BULK" },
7308
+ // Telegram updates the credentials vault forwards for the bots whose tokens it holds (wayai#5644):
7309
+ // the vault's egress carries every such bot's, so BULK. Its signature is checked after this.
7310
+ [TELEGRAM_VAULT_WEBHOOK_PATH]: { tier: "BULK" },
7311
+ // Reports (CLI → platform_report triage queue). One per-user budget covers intake
7312
+ // (POST), the content edit (PATCH /:id), the reporter read-back (GET, GET /:id), and the
7313
+ // verification loop (POST /:id/accept, /:id/contest). The limiter is path-based, so a
7314
+ // method-level split (loose reads, strict writes) isn't expressible — GET /:id and PATCH
7315
+ // /:id share a path. So the budget is sized for the read-heavy poll loop (a reporter agent
7316
+ // polling `report get`/`list` while it waits for the fix), at 60/hour. Intake-flooding stays
7317
+ // bounded regardless: identical reports collapse on `fingerprint` (ON CONFLICT DO NOTHING),
7318
+ // so a runaway create loop merges rather than floods. Still STRICT tier + failClosed so a
7319
+ // genuinely runaway distinct-report loop surfaces as 429. The `/*` is load-bearing — an
7320
+ // exact `/api/reports` key would leave the `/:id` paths unmatched (→ unthrottled).
7321
+ // `userLimitKey` is equally load-bearing: without it, middleware falls back to each request's
7322
+ // path and report IDs/actions receive independent counters instead of this shared budget.
7323
+ "/api/reports/*": {
7324
+ tier: "STRICT",
7325
+ userLimit: 60,
7326
+ userWindow: 3600,
7327
+ failClosed: true,
7328
+ skipAuthenticatedUsers: true,
7329
+ userLimitKey: "/api/reports/*"
7330
+ },
7331
+ // Admin report mutations (transition/group/ungroup/edit) — platform-admin
7332
+ // gated at the route, rate-limited here as defense-in-depth. Generous STANDARD
7333
+ // cap so legitimate triage bursts aren't throttled (grouping is one request
7334
+ // even for many members); deliberately NOT failClosed so a Redis blip never
7335
+ // blocks an admin's triage. The bare GET reads share this budget harmlessly.
7336
+ "/api/admin/reports/*": { tier: "STANDARD", userLimit: 150, userLimitKey: "/api/admin/reports/*" },
7337
+ // GitHub webhook (issues.closed → platform_report addressed). MODERATE +
7338
+ // fail-closed; GitHub retries on transient failures so a brief Redis blip
7339
+ // doesn't lose state.
7340
+ "/webhooks/github": { tier: "MODERATE", failClosed: true },
7341
+ // Account deletion — strict on the destructive POST + public undo. The
7342
+ // /api/users/* default tier above ALSO matches these, but `getEndpointConfig`
7343
+ // returns the longest-prefix match, so the more specific entries here win.
7344
+ // `skipAuthenticatedUsers` deliberately omitted: every caller is authenticated,
7345
+ // so including it would make `userLimit` a no-op — the per-user cap IS the gate.
7346
+ "/api/users/me/deletion": { tier: "STRICT", userLimit: 3, userWindow: 3600, failClosed: true },
7347
+ "/api/users/me/deletion/preflight": { tier: "STANDARD", userLimit: 30, failClosed: true },
7348
+ "/api/users/deletion/undo": { tier: "STRICT", failClosed: true },
7349
+ // Production-base destruction.
7350
+ //
7351
+ // Keyed off the CONTRACT constants, not literals: `BASE_DESTRUCTION_CONFIRM_PATH`'s own
7352
+ // docstring promises that the mount, the `AUTH_BYPASS_PATHS` entry, the rate-limit key and
7353
+ // the URL the email embeds move together, and a literal here is exactly how that promise
7354
+ // goes quietly false — leaving an unauthenticated HMAC endpoint on the default tier.
7355
+ //
7356
+ // The emailed GET is PUBLIC, so it gets the IP-tier bound the pre-auth routes get.
7357
+ // `failClosed` is deliberately NOT set: it is only consulted on the per-USER branch, which
7358
+ // needs an authenticated caller, so on a pre-auth route it is inert — the same thing
7359
+ // `/api/auth/magic-code/send` above says about itself. The IP limiter fails OPEN on a
7360
+ // limiter error by design (`packages/runtime/src/rate-limiter.ts`), and claiming otherwise
7361
+ // would tell the next auditor a protection exists that does not.
7362
+ [BASE_DESTRUCTION_CONFIRM_PATH]: { tier: "STRICT" },
7363
+ // The console's read, which every production base's settings pane issues on mount. Without
7364
+ // its own entry it inherits the mount-wide budget below, and an admin clicking through
7365
+ // thirty bases in an hour would be 429'd by a limit sized for irreversible writes.
7366
+ [`${BASE_DESTRUCTION_PREFIX}/destructions`]: { tier: "STANDARD", userLimit: 150 },
7367
+ // The mutating routes: initiate, the authenticated confirm, and cancel. Per user rather than
7368
+ // per IP — all three are authenticated and org-admin gated — and hourly, since a single human
7369
+ // touching thirty production-deletion operations in an hour is already far past normal.
7370
+ // Longest-prefix wins, so the two entries above are not widened by this one. The key is
7371
+ // pinned so those thirty are counted across every base the caller touches (gh #4756).
7372
+ [`${BASE_DESTRUCTION_PREFIX}/*`]: {
7373
+ tier: "STANDARD",
7374
+ userLimit: 30,
7375
+ userWindow: 3600,
7376
+ failClosed: true,
7377
+ userLimitKey: `${BASE_DESTRUCTION_PREFIX}/*`
7378
+ },
7379
+ // Email-invite preview — public, fail-closed. MODERATE (30/min IP) leaves
7380
+ // headroom for the signup-page server-fetch + reloads + prefetches; STRICT
7381
+ // would throttle legitimate users opening the link in multiple tabs.
7382
+ "/api/invites/preview": { tier: "MODERATE", failClosed: true },
7383
+ // "Don't email me again" (gh #4661) — public; one POST per click on its confirm page. STRICT
7384
+ // per IP. No `failClosed`: it is consulted only on the per-user branch, which a pre-auth route
7385
+ // never reaches (see `BASE_DESTRUCTION_CONFIRM_PATH` above).
7386
+ "/api/invites/unsubscribe": { tier: "STRICT" },
7387
+ // Admin DO debug reads — the ONE deliberate deviation from the Data Explorer
7388
+ // catch-all below, and the only reason a per-route key still exists here.
7389
+ // Platform-admin is enforced at the route; this is the independent
7390
+ // defense-in-depth signal so a runaway investigation script surfaces as 429.
7391
+ //
7392
+ // STRICT is kept ON PURPOSE even though the catch-all moved off it: per IP, at 5/min vs
7393
+ // STANDARD's 100/min, walking 10k ids takes ~33h instead of ~100min — a detection window
7394
+ // worth keeping on the routes that return RAW DO ROWS.
7395
+ //
7396
+ // The cost, stated rather than elided: STRICT is one bucket shared with
7397
+ // `/oauth/callback/*` and `/api/auth/magic-code/*`, so a debug session from a
7398
+ // NAT'd office IP can 429 a colleague's login for up to a minute. That trade is
7399
+ // accepted for a rare, deliberate investigation surface — and is exactly why the
7400
+ // browse routes below are NOT here.
7401
+ //
7402
+ // The key is pinned, so a sweep of `/debug/do/hub/<id>/tables` across ids spends one
7403
+ // per-admin budget (gh #4756). 120 an hour: an agent's investigation of a dozen
7404
+ // conversations made 37 debug reads in its busiest hour.
7405
+ "/api/admin/data-explorer/debug/*": {
7406
+ tier: "STRICT",
7407
+ userLimit: 120,
7408
+ userWindow: 3600,
7409
+ failClosed: true,
7410
+ userLimitKey: "/api/admin/data-explorer/debug/*"
7411
+ },
7412
+ // Catch-all for the rest of the Data Explorer (`/search`, `/entity/*`, `/do/*`,
7413
+ // `/kv/*`, the DELETE routes). Added as a catch-all rather than another per-route
7414
+ // key because this budget kept lagging behind routes joining the debug boundary:
7415
+ // with no match the path falls to the default, which sets no `userLimit`, so the
7416
+ // per-user layer never runs at all. `getEndpointConfig` takes the longest match,
7417
+ // so `debug/*` above still wins.
7418
+ //
7419
+ // `/entity/*` deliberately has NO key of its own: it needs precisely this config,
7420
+ // and a duplicate entry is how the two drift apart on the next edit.
7421
+ //
7422
+ // `tier` is deliberately STANDARD, not STRICT. `tier` is the per-IP knob and
7423
+ // STRICT is 5/min keyed on IP ALONE — one bucket shared across every STRICT
7424
+ // endpoint. On these browse routes that breaks the console (open Browse KV and
7425
+ // inspect four values = 6 requests; expand six org rows in the search results =
7426
+ // 6 `/entity/org/:id` calls) and would drain the same IP's budget for
7427
+ // `/oauth/callback/*` and `/api/auth/magic-code/*`, which on a NAT'd office IP
7428
+ // means all admins. The per-user hourly cap is the leg that matters here.
7429
+ //
7430
+ // The canonical key is deliberate: request paths contain DO ids and arbitrary
7431
+ // malformed requests can contain credential material. Keying on the request path
7432
+ // both stores that material in Redis/logs and gives every target a fresh counter.
7433
+ // One stable identity makes every browse request consume the same per-admin
7434
+ // budget without storing request targets.
7435
+ //
7436
+ // 600/hour preserves the original pagination requirement (about 30k rows at
7437
+ // 50/page) while now genuinely bounding id/key enumeration across the surface.
7438
+ "/api/admin/data-explorer/*": {
7439
+ tier: "STANDARD",
7440
+ userLimit: 600,
7441
+ userWindow: 3600,
7442
+ failClosed: true,
7443
+ userLimitKey: "/api/admin/data-explorer/*"
7444
+ },
7445
+ // Admin harness incident-response (harness-agents PR 2.9b) — mass-destroy reaps
7446
+ // EVERY live harness session/token/slot in scope, so it gets a strict budget
7447
+ // (STRICT + a low per-user hourly cap + fail-closed). Platform-admin is enforced
7448
+ // at the route; this is the independent defense-in-depth signal so a runaway
7449
+ // reap loop surfaces as 429. The break-glass disable/enable rides through
7450
+ // `/api/admin/config` (its own STANDARD budget), not this key.
7451
+ "/api/admin/harness/*": {
7452
+ tier: "STRICT",
7453
+ userLimit: 10,
7454
+ userWindow: 3600,
7455
+ failClosed: true,
7456
+ userLimitKey: "/api/admin/harness/*"
7457
+ },
7458
+ // Platform-wide team-orphan repair — a single call can WRITE across every hub of
7459
+ // every org (HubDO purge + UserDO mirror fan-out), so it gets the same strict,
7460
+ // fail-closed budget as the other cross-platform admin write. Exact path (not a
7461
+ // prefix): the sibling `/api/admin/hubs/:hubId/harness` flag flips stay on the
7462
+ // default admin budget. Platform-admin is enforced at the route; this is the
7463
+ // defense-in-depth signal that a repair loop surfaces as 429.
7464
+ "/api/admin/hubs/repair-team-orphans": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
7465
+ // Branching-orphan repair (#4577) — deletes named production rows, and its report mode
7466
+ // fans out over every production hub of every org, so it takes the same strict,
7467
+ // fail-closed budget as the team-orphan repair. Exact path, for the same reason.
7468
+ "/api/admin/hubs/repair-branching-orphans": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
7469
+ // Knowledge-blob repair (#5142 step 5 C1) — deletes R2 objects across every hub of a scope, so it
7470
+ // takes the same strict, fail-closed budget as the other hub repairs. Exact path, for the same reason.
7471
+ "/api/admin/hubs/repair-knowledge-blobs": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
7472
+ "/api/admin/hubs/repair-credential-links": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
7473
+ // The org credential service backfill (#5644) writes org credentials, and its dry run reads every org: the same budget.
7474
+ "/api/admin/organizations/repair-credential-services": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
7475
+ // The WayAI-host token clear (#5644 steps 6–7) deletes connections and org credentials, and its dry run fans out over
7476
+ // every hub of every org: the same strict, fail-closed budget.
7477
+ "/api/admin/hubs/clear-wayai-host-tokens": { tier: "STRICT", userLimit: 10, userWindow: 3600, failClosed: true },
7478
+ // CI/GitOps endpoints - standard with user limits. 500 because `wayai push` makes four requests
7479
+ // (pull, diff, push, pull) and a GitOps job may push every hub at once with one token; when
7480
+ // each path held its own 100, that ran to 100 hubs a minute.
7481
+ "/api/ci/*": { tier: "STANDARD", userLimit: 500, skipAuthenticatedUsers: true, userLimitKey: "/api/ci/*" },
7482
+ // A hub's team pages and their bridge (#5333; owner decision of 2026-10-27): a signed-in caller is
7483
+ // counted on one budget of their own across every hub's page routes instead of the per-IP tier,
7484
+ // which a team behind one address shares. The bridge's own budgets still apply on top: 60 calls a
7485
+ // minute per viewer and page (30 on a customer page), 150 per viewer across a hub's pages, 200 per hub
7486
+ // across its customer pages and 500 per hub (`PAGE_BRIDGE_*` below).
7487
+ "/api/hubs/*/pages/*": { tier: "STANDARD", userLimit: 500, skipAuthenticatedUsers: true, userLimitKey: "/api/hubs/*/pages/*" },
7488
+ // Attested `/v1` proxy onto the data API's `AttestedEntrypoint`. `userLimitKey` is load-bearing here: the
7489
+ // per-user budget defaults to the full request path, and this surface's paths carry base,
7490
+ // record, and file ids — so without a pinned key every distinct resource would get its own
7491
+ // fresh budget and the per-user limit would bound nothing. One shared budget across the
7492
+ // whole data surface is the intent.
7493
+ [`${DATA_PROXY_PREFIX}/*`]: {
7494
+ tier: "STANDARD",
7495
+ userLimit: 150,
7496
+ skipAuthenticatedUsers: true,
7497
+ userLimitKey: `${DATA_PROXY_PREFIX}/*`
7498
+ },
7499
+ // Voice calls — the end user's call routes (`routes/api/calls`). Every caller is signed
7500
+ // in, so the per-IP tier is skipped for them: Brazilian mobile carriers put many callers
7501
+ // behind one IP, and a shared bucket would refuse one caller for another's traffic.
7502
+ //
7503
+ // Create is the only route that spends: it opens a provider session on the org's own
7504
+ // key, billed per second. So it takes its own exact key and an hourly per-user cap, which
7505
+ // lives on Redis and is fail-closed like the other hourly caps. The exact key wins over
7506
+ // the wildcard below, which also matches `/api/calls` (see `getEndpointConfig`).
7507
+ "/api/calls": {
7508
+ tier: "STANDARD",
7509
+ userLimit: 30,
7510
+ userWindow: 3600,
7511
+ failClosed: true,
7512
+ skipAuthenticatedUsers: true,
7513
+ userLimitKey: "/api/calls"
7514
+ },
7515
+ // The routes on one call: `ready`, hang-up, the delegation report and the status read; and
7516
+ // the opening read (`/api/calls/openings/:language`), one per call, before it exists.
7517
+ // NEVER fail-closed: a refused hang-up leaves the call running, and billing, until a
7518
+ // limit ends it. The 60 s budget runs on the native binding, which fails open. The key is
7519
+ // pinned because the paths carry the call id, which would otherwise give every call a
7520
+ // fresh budget.
7521
+ "/api/calls/*": {
7522
+ tier: "STANDARD",
7523
+ userLimit: 150,
7524
+ skipAuthenticatedUsers: true,
7525
+ userLimitKey: "/api/calls/*"
7526
+ },
7527
+ // Contacts between accounts (gh #4661, `routes/api/contacts`). Every caller is signed in, so
7528
+ // the per-IP tier is skipped. The keys are pinned because the paths carry user and invite
7529
+ // ids, which would otherwise give each id a fresh budget. Blocks take their own, lower
7530
+ // budget (#4661 Limits: blocks are rate-limited). The invites-per-day cap and every list
7531
+ // cap are counted in the caller's UserDO, in the same write they bound, not here.
7532
+ "/api/contacts/*": {
7533
+ tier: "STANDARD",
7534
+ userLimit: 60,
7535
+ skipAuthenticatedUsers: true,
7536
+ userLimitKey: "/api/contacts/*"
7537
+ },
7538
+ "/api/contacts/blocks/*": {
7539
+ tier: "STANDARD",
7540
+ userLimit: 30,
7541
+ skipAuthenticatedUsers: true,
7542
+ userLimitKey: "/api/contacts/blocks/*"
7543
+ },
7544
+ // Person-to-person threads (gh #4661, `routes/api/threads`): the per-user send limit, 60 a
7545
+ // minute on the native binding. Every thread route shares the one budget, reads included:
7546
+ // the paths carry thread and message ids, so the key is pinned, and a pattern here cannot
7547
+ // tell a send from a read of the same path. Like every 60 s budget it fails open on a
7548
+ // binding error, so it bounds sends in the steady state only.
7549
+ "/api/threads/*": {
7550
+ tier: "STANDARD",
7551
+ userLimit: 60,
7552
+ skipAuthenticatedUsers: true,
7553
+ userLimitKey: "/api/threads/*"
7554
+ },
7555
+ // An org admin's erasure of one person's thread messages (gh #4661 owner decision 7): any user
7556
+ // can own a free org, so each request arms that org's alarm, and this caps how fast one person
7557
+ // can ask. The org's own daily cap (`PEOPLE_ORG_ERASURES_PER_DAY`, counted in its OrgDO in the
7558
+ // write it bounds) is the fail-closed bound; this budget, on the native binding, fails open.
7559
+ "/api/threads/org-erasures": {
7560
+ tier: "STANDARD",
7561
+ userLimit: 10,
7562
+ skipAuthenticatedUsers: true,
7563
+ userLimitKey: "/api/threads/org-erasures"
7564
+ },
7565
+ // A person's report of a message, thread or person (`people-reports.ts`): each one written
7566
+ // arms the PlatformDO's alarm and emails the platform admins, so it takes its own, lower
7567
+ // budget. The reporter's daily cap (`PEOPLE_REPORTS_PER_DAY`, counted in the report store in
7568
+ // the write it bounds) is the fail-closed bound; this budget, on the native binding, fails open.
7569
+ "/api/threads/reports": {
7570
+ tier: "STANDARD",
7571
+ userLimit: 10,
7572
+ skipAuthenticatedUsers: true,
7573
+ userLimitKey: "/api/threads/reports"
7574
+ },
7575
+ // Communities (gh #4872, `routes/api/communities`): every signed-in route under the mount (the
7576
+ // preview below excepted) shares one per-user budget, which is also each member's send limit and
7577
+ // bounds the reads that scan a community's rows (a title search, the stats); a community's own
7578
+ // limits (its rate, the daily caps, slow mode) are counted in its CommunityDO, in the write they
7579
+ // bound. Every caller is signed in, so the per-IP tier is skipped; the key is pinned because the
7580
+ // paths carry community, room and message ids.
7581
+ "/api/communities/*": {
7582
+ tier: "STANDARD",
7583
+ userLimit: 60,
7584
+ skipAuthenticatedUsers: true,
7585
+ userLimitKey: "/api/communities/*"
7586
+ },
7587
+ // The join page's preview of a link — public, fetched from the visitor's browser, so this
7588
+ // per-IP limit is its one bound and runs before the route reads anything (#4872
7589
+ // owner-delegated decision 9). MODERATE (30/min per IP) leaves room for reloads and several
7590
+ // tabs. An exact key, so it wins over the wildcard above.
7591
+ "/api/communities/join-preview": { tier: "MODERATE" },
7592
+ // An announcement email's unsubscribe (#4872 PR 8a) — public: its token is its one credential, so
7593
+ // this per-IP limit is its one bound, and runs before the route reads anything. MODERATE (30/min
7594
+ // per IP), not STRICT: mail clients' one-click unsubscribe POSTs it from their own servers, which
7595
+ // many members' clicks share, and STRICT's 5/min bucket is shared with sign-in. An exact key, so
7596
+ // it wins over the wildcard above.
7597
+ [COMMUNITY_EMAIL_UNSUBSCRIBE_PATH]: { tier: "MODERATE" },
7598
+ // Case spaces (wayai#5921, `cases/routes.ts`): every route under the mount (the uploads, the received documents' upload,
7599
+ // the compare, the comments and the cited passages below excepted) shares
7600
+ // one per-user budget. Each is one person's page or write, at most a few hundred Durable Object reads (the
7601
+ // list of their spaces); a space's own limits are counted in its CaseDO. Every caller is a web
7602
+ // session, so the per-IP tier is skipped; the key is pinned because the paths carry org, space,
7603
+ // person and team ids.
7604
+ "/api/cases/*": {
7605
+ tier: "STANDARD",
7606
+ userLimit: 60,
7607
+ skipAuthenticatedUsers: true,
7608
+ userLimitKey: "/api/cases/*"
7609
+ },
7610
+ // A case file upload (`POST …/cases/:code/uploads`): each carries up to 20 MiB the Worker holds in memory, hashes
7611
+ // and stores, so it takes its own, lower budget, keyed once for every case.
7612
+ "/api/cases/*/*/cases/*/uploads": {
7613
+ tier: "STANDARD",
7614
+ userLimit: 10,
7615
+ skipAuthenticatedUsers: true,
7616
+ userLimitKey: "/api/cases/*/*/cases/*/uploads"
7617
+ },
7618
+ // A case space's style asset upload (`POST …/styles/:kind/uploads`): up to 20 MiB the Worker holds in memory, checks,
7619
+ // hashes and stores, by an administrator, so it takes the case file upload's budget, keyed once for every space.
7620
+ "/api/cases/*/*/styles/*/uploads": {
7621
+ tier: "STANDARD",
7622
+ userLimit: 10,
7623
+ skipAuthenticatedUsers: true,
7624
+ userLimitKey: "/api/cases/*/*/styles/*/uploads"
7625
+ },
7626
+ // A collection document's upload (`POST …/collection/uploads`, a new document; `POST …/collection/:document_id/uploads`,
7627
+ // its next version): up to 20 MiB the Worker holds in memory, checks, hashes and stores, by a Registry holder, so each
7628
+ // takes a budget the size of the case file upload's: two budgets, one for new documents keyed once for every space,
7629
+ // one for new versions keyed once for every space and document.
7630
+ "/api/cases/*/*/collection/uploads": {
7631
+ tier: "STANDARD",
7632
+ userLimit: 10,
7633
+ skipAuthenticatedUsers: true,
7634
+ userLimitKey: "/api/cases/*/*/collection/uploads"
7635
+ },
7636
+ "/api/cases/*/*/collection/*/uploads": {
7637
+ tier: "STANDARD",
7638
+ userLimit: 10,
7639
+ skipAuthenticatedUsers: true,
7640
+ userLimitKey: "/api/cases/*/*/collection/*/uploads"
7641
+ },
7642
+ // A case's received document (`POST …/cases/:code/received/uploads`): up to 20 MiB the Worker holds in memory, checks,
7643
+ // hashes and stores, as a case file upload does, so it takes a budget that upload's size, keyed once for every case.
7644
+ "/api/cases/*/*/cases/*/received/uploads": {
7645
+ tier: "STANDARD",
7646
+ userLimit: 10,
7647
+ skipAuthenticatedUsers: true,
7648
+ userLimitKey: "/api/cases/*/*/cases/*/received/uploads"
7649
+ },
7650
+ // A compare of two versions of a case file (`GET …/cases/:code/files/compare`): each reads up to 8 MiB from the
7651
+ // bucket into the Worker and runs the block compare (under a second of CPU at its limits), so it takes its own
7652
+ // budget, keyed once for every case.
7653
+ "/api/cases/*/*/cases/*/files/compare": {
7654
+ tier: "STANDARD",
7655
+ userLimit: 30,
7656
+ skipAuthenticatedUsers: true,
7657
+ userLimitKey: "/api/cases/*/*/cases/*/files/compare"
7658
+ },
7659
+ // A case file's comments (`GET`/`POST …/cases/:code/files/comments`): a write reads up to 4 MiB of one version from the
7660
+ // bucket into the Worker and hashes a passage of it, so they take a budget of their own, as a compare does, keyed once
7661
+ // for every case; the page shares it.
7662
+ "/api/cases/*/*/cases/*/files/comments": {
7663
+ tier: "STANDARD",
7664
+ userLimit: 30,
7665
+ skipAuthenticatedUsers: true,
7666
+ userLimitKey: "/api/cases/*/*/cases/*/files/comments"
7667
+ },
7668
+ // A cited passage (`POST …/cases/:code/inputs/:input_id/passages`): reads up to 4 MiB of a collection version's text from
7669
+ // the bucket into the Worker and hashes a passage of it, as a comment's write does, so it takes the comments' budget
7670
+ // size, keyed once for every case and input.
7671
+ "/api/cases/*/*/cases/*/inputs/*/passages": {
7672
+ tier: "STANDARD",
7673
+ userLimit: 30,
7674
+ skipAuthenticatedUsers: true,
7675
+ userLimitKey: "/api/cases/*/*/cases/*/inputs/*/passages"
7676
+ },
7677
+ // The WayAI Guide's help entry (wayai#4948, `routes/api/guide.ts`): one POST per click by a viewer
7678
+ // the snapshot does not show enrolled, which reads the person's row on the Guide hub and writes only
7679
+ // what is missing (an enrolled viewer's click opens the hub without a request). Every caller is
7680
+ // signed in, so the per-IP tier is skipped; 10 a minute per person on the native binding (fails
7681
+ // open, like every 60 s budget) bounds what a looping client costs the one Guide HubDO.
7682
+ "/api/guide/access": {
7683
+ tier: "STANDARD",
7684
+ userLimit: 10,
7685
+ skipAuthenticatedUsers: true,
7686
+ userLimitKey: "/api/guide/access"
7687
+ },
7688
+ // App channel - high throughput with user limits
7689
+ "/channels/app/*": { tier: "HIGH", userLimit: 500, skipAuthenticatedUsers: true },
7690
+ // API channel (api-channel-connector) - machine-to-machine, high throughput
7691
+ "/channels/api/*": { tier: "HIGH", userLimit: 500, skipAuthenticatedUsers: true },
7692
+ // System/scheduled - high throughput (internal)
7693
+ "/channels/system/*": { tier: "HIGH", skipAuthenticatedUsers: true },
7694
+ "/scheduled/*": { tier: "HIGH", skipAuthenticatedUsers: true },
7695
+ // WebSocket - standard with user limit to prevent connection spam
7696
+ "/live-updates/ws": { tier: "STANDARD", userLimit: 100, failClosed: true },
7697
+ // A community's live socket (gh #4872 PR 5, `GET /communities/:communityId/live`): outside
7698
+ // `/api/*`, with no bearer token, so its per-IP tier is its one bound before the CommunityDO
7699
+ // checks the ticket. STANDARD, as `/live-updates/ws`: a client opens one per community it shows
7700
+ // and reconnects within the hour.
7701
+ "/communities/*": { tier: "STANDARD" },
7702
+ // WS ticket mint - per-user 60/min accommodates aggressive reconnect patterns
7703
+ // without opening abuse vectors; fail-closed so Redis outages don't let
7704
+ // runaway clients mint unbounded tickets.
7705
+ "/api/auth/ws-ticket": { tier: "MODERATE", userLimit: 60, failClosed: true, skipAuthenticatedUsers: true },
7706
+ "/api/auth/session-check": { tier: "STANDARD", userLimit: 120, skipAuthenticatedUsers: true },
7707
+ "/api/auth/logout": { tier: "MODERATE", userLimit: 10, failClosed: true, skipAuthenticatedUsers: true }
7708
+ };
7709
+ EXCLUDED_PATHS = /* @__PURE__ */ new Set(["/health"]);
7542
7710
  }
7543
7711
  });
7544
7712
 
7545
- // ../../packages/core/dist/chunk-UAOHHCW5.js
7546
- function normalizeContactPhone(raw) {
7547
- const compact = raw.trim().replace(/[\s\-.()]/g, "");
7548
- const withPlus = compact.startsWith("00") ? `+${compact.slice(2)}` : compact;
7549
- return /^\+[1-9]\d{7,14}$/.test(withPlus) ? withPlus : null;
7550
- }
7551
- function normalizeContactLabel(raw) {
7552
- return raw.trim().replace(/\s+/g, " ").toLowerCase();
7553
- }
7554
- function importRowLabels(row, batchLabels) {
7555
- return [.../* @__PURE__ */ new Set([...row.labels ?? [], ...batchLabels ?? []])];
7713
+ // ../../packages/core/dist/chunk-ITIQ7XWD.js
7714
+ function fileSnapshotChanged(run) {
7715
+ return run.written + run.removed > 0;
7556
7716
  }
7557
- var CONTACT_ENVIRONMENTS, CONTACT_NAME_MAX, CONTACT_EMAIL_MAX, CONTACT_PHONE_INPUT_MAX, CONTACT_INSTAGRAM_SID_MAX, CONTACT_METADATA_MAX_BYTES, CONTACT_LABEL_MAX, CONTACT_LABELS_MAX, CONTACT_SCOPE_TAGS_MAX, CONTACT_PAGE_MAX, CONTACT_IMPORT_BATCH_MAX, CONTACT_SEARCH_MAX, CONTACT_LIST_NAME_MAX, CONTACT_LIST_NAME_REGEX, CONTACT_LIST_DESCRIPTION_MAX, CONTACT_LIST_FILTER_MAX, CONTACT_LIST_PINS_PER_REQUEST_MAX, SUPPRESSION_SCOPES, SUPPRESSION_ID_REGEX, contactName, contactPhone, contactEmail, contactInstagramSid, contactLabel, contactLabels, contactMetadata, scopeTagIds, contactVisibilitySchema, hasIdentity, IDENTITY_REQUIRED, contactBookOrgQuery, contactBookContactParam, contactBookListParam, contactBookHubParam, contactBookPageQuery, listContactBookContactsQuery, listHubContactBookContactsQuery, contactBookLinkCandidatesQuery, listContactBookListMembersQuery, contactRowFields, createContactBookContactBody, updateContactBookContactBody, contactImportRowSchema, importContactBookContactsBody, linkContactBookContactBody, listName, contactListFilterSchema, createContactBookListBody, updateContactBookListBody, updateContactBookListPinsBody, suppressionIdentitySchema, createContactBookSuppressionBody, contactBookSuppressionParam, listContactBookSuppressionsQuery, contactBookEmailUnsubscribeTokenSchema, contactBookEmailUnsubscribeQuery, orgListReferenceSchema;
7558
- var init_chunk_UAOHHCW5 = __esm({
7559
- "../../packages/core/dist/chunk-UAOHHCW5.js"() {
7560
- "use strict";
7561
- init_zod();
7562
- CONTACT_ENVIRONMENTS = ["production", "preview", "all"];
7563
- CONTACT_NAME_MAX = 200;
7564
- CONTACT_EMAIL_MAX = 320;
7565
- CONTACT_PHONE_INPUT_MAX = 40;
7566
- CONTACT_INSTAGRAM_SID_MAX = 64;
7567
- CONTACT_METADATA_MAX_BYTES = 4096;
7568
- CONTACT_LABEL_MAX = 64;
7569
- CONTACT_LABELS_MAX = 20;
7570
- CONTACT_SCOPE_TAGS_MAX = 20;
7571
- CONTACT_PAGE_MAX = 100;
7572
- CONTACT_IMPORT_BATCH_MAX = 500;
7573
- CONTACT_SEARCH_MAX = 100;
7574
- CONTACT_LIST_NAME_MAX = 64;
7575
- CONTACT_LIST_NAME_REGEX = /^[a-z0-9]+(-[a-z0-9]+)*$/;
7576
- CONTACT_LIST_DESCRIPTION_MAX = 1e3;
7577
- CONTACT_LIST_FILTER_MAX = 20;
7578
- CONTACT_LIST_PINS_PER_REQUEST_MAX = 100;
7579
- SUPPRESSION_SCOPES = ["all", "marketing"];
7580
- SUPPRESSION_ID_REGEX = /^[0-9a-f]{64}$/;
7581
- contactName = external_exports.string().trim().min(1).max(CONTACT_NAME_MAX);
7582
- contactPhone = external_exports.string().max(CONTACT_PHONE_INPUT_MAX).transform((raw, ctx) => {
7583
- const phone = normalizeContactPhone(raw);
7584
- if (phone === null) {
7585
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: "Phone must be an international number, e.g. +5511999999999" });
7586
- return external_exports.NEVER;
7587
- }
7588
- return phone;
7589
- });
7590
- contactEmail = external_exports.string().trim().toLowerCase().max(CONTACT_EMAIL_MAX).email();
7591
- contactInstagramSid = external_exports.string().trim().min(1).max(CONTACT_INSTAGRAM_SID_MAX);
7592
- contactLabel = external_exports.string().max(CONTACT_LABEL_MAX).transform(normalizeContactLabel).refine((label3) => label3.length > 0, "A label cannot be empty").refine((label3) => !label3.includes(","), "A label cannot contain a comma");
7593
- contactLabels = external_exports.array(contactLabel).max(CONTACT_LABELS_MAX).transform((labels) => [...new Set(labels)]);
7594
- contactMetadata = external_exports.record(external_exports.unknown()).refine((metadata) => {
7595
- try {
7596
- return new TextEncoder().encode(JSON.stringify(metadata)).length <= CONTACT_METADATA_MAX_BYTES;
7597
- } catch {
7598
- return false;
7599
- }
7600
- }, `Metadata must serialize to at most ${CONTACT_METADATA_MAX_BYTES} bytes`);
7601
- scopeTagIds = external_exports.array(external_exports.string().uuid()).min(1).max(CONTACT_SCOPE_TAGS_MAX).transform((ids) => [...new Set(ids)]);
7602
- contactVisibilitySchema = external_exports.discriminatedUnion("scope", [
7603
- external_exports.object({ scope: external_exports.literal("all_hubs") }).strict(),
7604
- external_exports.object({ scope: external_exports.literal("tags"), tag_ids: scopeTagIds }).strict()
7605
- ]);
7606
- hasIdentity = (row) => Boolean(row.phone || row.email || row.instagram_sid);
7607
- IDENTITY_REQUIRED = "A contact needs a phone, an email or an Instagram id";
7608
- contactBookOrgQuery = external_exports.object({
7609
- organization_id: external_exports.string().uuid()
7610
- });
7611
- contactBookContactParam = external_exports.object({
7612
- contactId: external_exports.string().uuid()
7613
- });
7614
- contactBookListParam = external_exports.object({
7615
- listId: external_exports.string().uuid()
7616
- });
7617
- contactBookHubParam = external_exports.object({
7618
- hubId: external_exports.string().uuid()
7619
- });
7620
- contactBookPageQuery = external_exports.object({
7621
- cursor: external_exports.string().max(2048).optional(),
7622
- limit: external_exports.coerce.number().int().min(1).max(CONTACT_PAGE_MAX).default(50)
7623
- });
7624
- listContactBookContactsQuery = contactBookOrgQuery.merge(contactBookPageQuery).extend({
7625
- q: external_exports.string().trim().max(CONTACT_SEARCH_MAX).optional(),
7626
- label: external_exports.string().max(CONTACT_LABEL_MAX).transform(normalizeContactLabel).optional(),
7627
- scope_tag_id: external_exports.string().uuid().optional()
7628
- });
7629
- listHubContactBookContactsQuery = contactBookPageQuery.extend({
7630
- q: external_exports.string().trim().max(CONTACT_SEARCH_MAX).optional()
7631
- });
7632
- contactBookLinkCandidatesQuery = contactBookOrgQuery.extend({
7633
- email: contactEmail
7634
- });
7635
- listContactBookListMembersQuery = contactBookOrgQuery.merge(contactBookPageQuery);
7636
- contactRowFields = {
7637
- name: contactName,
7638
- phone: contactPhone.nullish(),
7639
- email: contactEmail.nullish(),
7640
- instagram_sid: contactInstagramSid.nullish(),
7641
- labels: contactLabels.optional(),
7642
- metadata: contactMetadata.optional()
7643
- };
7644
- createContactBookContactBody = external_exports.object({
7645
- organization_id: external_exports.string().uuid(),
7646
- ...contactRowFields,
7647
- visibility: contactVisibilitySchema,
7648
- environment: external_exports.enum(CONTACT_ENVIRONMENTS).optional()
7649
- }).strict().refine(hasIdentity, IDENTITY_REQUIRED);
7650
- updateContactBookContactBody = external_exports.object({
7651
- name: contactName.optional(),
7652
- phone: contactPhone.nullable().optional(),
7653
- email: contactEmail.nullable().optional(),
7654
- instagram_sid: contactInstagramSid.nullable().optional(),
7655
- labels: contactLabels.optional(),
7656
- metadata: contactMetadata.optional(),
7657
- visibility: contactVisibilitySchema.optional(),
7658
- environment: external_exports.enum(CONTACT_ENVIRONMENTS).optional()
7659
- }).strict();
7660
- contactImportRowSchema = external_exports.object(contactRowFields).strict().refine(hasIdentity, IDENTITY_REQUIRED);
7661
- importContactBookContactsBody = external_exports.object({
7662
- organization_id: external_exports.string().uuid(),
7663
- visibility: contactVisibilitySchema,
7664
- environment: external_exports.enum(CONTACT_ENVIRONMENTS).optional(),
7665
- labels: contactLabels.optional(),
7666
- rows: external_exports.array(contactImportRowSchema).min(1).max(CONTACT_IMPORT_BATCH_MAX)
7667
- }).strict().superRefine((batch, ctx) => {
7668
- batch.rows.forEach((row, index) => {
7669
- if (importRowLabels(row, batch.labels).length > CONTACT_LABELS_MAX) {
7670
- ctx.addIssue({
7671
- code: external_exports.ZodIssueCode.custom,
7672
- path: ["rows", index, "labels"],
7673
- message: `A contact holds at most ${CONTACT_LABELS_MAX} labels, the batch's included`
7674
- });
7675
- }
7676
- });
7677
- });
7678
- linkContactBookContactBody = external_exports.object({
7679
- user_id: external_exports.string().min(1).max(128)
7680
- }).strict();
7681
- listName = external_exports.string().trim().min(1).max(CONTACT_LIST_NAME_MAX).regex(CONTACT_LIST_NAME_REGEX, {
7682
- message: 'Must be lowercase alphanumeric with hyphens (e.g. "vip-customers")'
7683
- });
7684
- contactListFilterSchema = external_exports.object({
7685
- labels: external_exports.array(contactLabel).max(CONTACT_LIST_FILTER_MAX).transform((l) => [...new Set(l)]).default([]),
7686
- scope_tag_ids: external_exports.array(external_exports.string().uuid()).max(CONTACT_LIST_FILTER_MAX).transform((t) => [...new Set(t)]).default([])
7687
- }).strict();
7688
- createContactBookListBody = external_exports.object({
7689
- organization_id: external_exports.string().uuid(),
7690
- name: listName,
7691
- description: external_exports.string().max(CONTACT_LIST_DESCRIPTION_MAX).nullish(),
7692
- filter: contactListFilterSchema.optional()
7693
- }).strict();
7694
- updateContactBookListBody = external_exports.object({
7695
- name: listName.optional(),
7696
- description: external_exports.string().max(CONTACT_LIST_DESCRIPTION_MAX).nullable().optional(),
7697
- filter: contactListFilterSchema.optional()
7698
- }).strict();
7699
- updateContactBookListPinsBody = external_exports.object({
7700
- add: external_exports.array(external_exports.string().uuid()).max(CONTACT_LIST_PINS_PER_REQUEST_MAX).default([]),
7701
- remove: external_exports.array(external_exports.string().uuid()).max(CONTACT_LIST_PINS_PER_REQUEST_MAX).default([])
7702
- }).strict().refine((b) => b.add.length + b.remove.length > 0, "Add or remove at least one contact");
7703
- suppressionIdentitySchema = external_exports.discriminatedUnion("kind", [
7704
- external_exports.object({ kind: external_exports.literal("phone"), value: contactPhone }).strict(),
7705
- external_exports.object({ kind: external_exports.literal("email"), value: contactEmail }).strict(),
7706
- external_exports.object({ kind: external_exports.literal("instagram"), value: contactInstagramSid }).strict()
7707
- ]);
7708
- createContactBookSuppressionBody = external_exports.object({
7709
- organization_id: external_exports.string().uuid(),
7710
- identity: suppressionIdentitySchema,
7711
- scope: external_exports.enum(SUPPRESSION_SCOPES)
7712
- }).strict();
7713
- contactBookSuppressionParam = external_exports.object({
7714
- suppressionId: external_exports.string().regex(SUPPRESSION_ID_REGEX)
7715
- });
7716
- listContactBookSuppressionsQuery = contactBookOrgQuery.merge(contactBookPageQuery);
7717
- contactBookEmailUnsubscribeTokenSchema = external_exports.string().max(200).regex(/^[0-9a-f-]{36}\.[0-9a-f]{64}\.[0-9a-f]{64}$/i);
7718
- contactBookEmailUnsubscribeQuery = external_exports.object({ token: contactBookEmailUnsubscribeTokenSchema });
7719
- orgListReferenceSchema = listName;
7717
+ async function runFileSnapshot(opts) {
7718
+ const run = { pages: 0, written: 0, removed: 0, unchanged: 0 };
7719
+ const seen = /* @__PURE__ */ new Set();
7720
+ let cursor;
7721
+ while (run.pages < FILE_SNAPSHOT_MAX_PAGES) {
7722
+ const page = await sendWithRetry(opts, cursor);
7723
+ run.pages++;
7724
+ run.written += page.written;
7725
+ run.removed += page.removed;
7726
+ run.unchanged += page.unchanged;
7727
+ opts.onPage?.(page, run.pages);
7728
+ if (page.next_cursor === null) return run;
7729
+ if (seen.has(page.next_cursor)) {
7730
+ throw new Error(`The preview file snapshot repeated its cursor after page ${run.pages}, so it would never end.`);
7731
+ }
7732
+ seen.add(page.next_cursor);
7733
+ cursor = page.next_cursor;
7720
7734
  }
7721
- });
7722
-
7723
- // ../../packages/core/dist/chunk-MGBAXT5Y.js
7724
- var PERSON_LINKS_MAX, PERSON_DENY_PAGE_MAX, personParam, personLinkParam, deniedPersonParam, listDeniedPersonsQuery, conversationCustomerPersonParam;
7725
- var init_chunk_MGBAXT5Y = __esm({
7726
- "../../packages/core/dist/chunk-MGBAXT5Y.js"() {
7727
- "use strict";
7728
- init_chunk_2YEGUQR7();
7729
- init_chunk_UAOHHCW5();
7730
- init_zod();
7731
- PERSON_LINKS_MAX = 15;
7732
- PERSON_DENY_PAGE_MAX = 100;
7733
- personParam = external_exports.object({
7734
- personId: userPersonIdSchema
7735
- });
7736
- personLinkParam = personParam.extend({
7737
- targetId: personIdSchema
7738
- });
7739
- deniedPersonParam = external_exports.object({
7740
- personId: personIdSchema
7741
- });
7742
- listDeniedPersonsQuery = contactBookOrgQuery.extend({
7743
- cursor: personIdSchema.optional(),
7744
- limit: external_exports.coerce.number().int().min(1).max(PERSON_DENY_PAGE_MAX).default(50)
7745
- });
7746
- conversationCustomerPersonParam = external_exports.object({
7747
- hubId: external_exports.string().uuid(),
7748
- conversationId: external_exports.string().uuid()
7749
- });
7735
+ throw new Error(`The preview file snapshot did not end after ${FILE_SNAPSHOT_MAX_PAGES} pages.`);
7736
+ }
7737
+ async function sendWithRetry(opts, cursor) {
7738
+ for (let attempt = 1; ; attempt++) {
7739
+ let body;
7740
+ try {
7741
+ body = await opts.sendPage(cursor);
7742
+ } catch (error) {
7743
+ if (attempt < FILE_SNAPSHOT_CONFLICT_ATTEMPTS && opts.isConflict(error)) continue;
7744
+ throw error;
7745
+ }
7746
+ const parsed = rekorFileSnapshotAnswerSchema.safeParse(body);
7747
+ if (!parsed.success) {
7748
+ throw new Error("The data product answered a preview file snapshot page WayAI cannot read: nothing more was sent.");
7749
+ }
7750
+ return parsed.data.data;
7750
7751
  }
7751
- });
7752
-
7753
- // ../../packages/core/dist/chunk-5DGHIY7L.js
7754
- var rekorBaseChangeMessageSchema;
7755
- var init_chunk_5DGHIY7L = __esm({
7756
- "../../packages/core/dist/chunk-5DGHIY7L.js"() {
7752
+ }
7753
+ var rekorFileSnapshotAnswerSchema, FILE_SNAPSHOT_MAX_PAGES, FILE_SNAPSHOT_CONFLICT_ATTEMPTS, FILE_SNAPSHOT_PAGE_SPACING_MS, FILE_SNAPSHOT_CONFLICT_STATUS;
7754
+ var init_chunk_ITIQ7XWD = __esm({
7755
+ "../../packages/core/dist/chunk-ITIQ7XWD.js"() {
7757
7756
  "use strict";
7757
+ init_chunk_7AYJHO5P();
7758
+ init_chunk_5FO3GNKP();
7758
7759
  init_zod();
7759
- rekorBaseChangeMessageSchema = external_exports.object({
7760
- /** The WayAI org UUID — one id namespace. */
7761
- org_id: external_exports.string().uuid(),
7762
- /**
7763
- * Not a UUID: a preview base id is `{prod_base_id}--{slug}`. Immutable per base — a
7764
- * preview clone is its OWN base_id — so `(base_id, scope)` keys never collide across
7765
- * environments. Empty is never a real base id, so it is non-conforming rather than a
7766
- * frame keyed on nothing.
7767
- */
7768
- base_id: external_exports.string().min(1),
7769
- /**
7770
- * Rides along so the client scopes its refetch without a lookup; the inspector scopes
7771
- * by side.
7772
- */
7773
- environment: external_exports.enum(["production", "preview"]),
7774
- /** Which pane refetches. `base` covers create/delete/promote/config changes. */
7775
- scope: external_exports.enum(["records", "record_types", "files", "base"])
7760
+ rekorFileSnapshotAnswerSchema = external_exports.object({
7761
+ data: external_exports.object({
7762
+ next_cursor: external_exports.string().nullable(),
7763
+ /** Files the page created or replaced on the preview. */
7764
+ written: external_exports.number().int(),
7765
+ /** The preview's own files, ones production does not hold, the page removed. */
7766
+ removed: external_exports.number().int(),
7767
+ /** Files the page found already equal to production's. */
7768
+ unchanged: external_exports.number().int()
7769
+ })
7776
7770
  });
7771
+ FILE_SNAPSHOT_MAX_PAGES = 1e4;
7772
+ FILE_SNAPSHOT_CONFLICT_ATTEMPTS = 3;
7773
+ FILE_SNAPSHOT_PAGE_SPACING_MS = Math.ceil(
7774
+ 6e4 / Math.max(1, Math.floor((getEndpointConfig(`${DATA_PROXY_PREFIX}/files/snapshot`)?.userLimit ?? 60) * 4 / 5))
7775
+ );
7776
+ FILE_SNAPSHOT_CONFLICT_STATUS = 409;
7777
7777
  }
7778
7778
  });
7779
7779
 
@@ -10576,20 +10576,6 @@ var init_chunk_OPETF4GS = __esm({
10576
10576
  }
10577
10577
  });
10578
10578
 
10579
- // ../../packages/core/dist/chunk-YULHXJ5M.js
10580
- var COMMUNITY_LESSON_TREE_MAX_BYTES, COMMUNITY_LESSON_LINK_PROTOCOLS, COMMUNITY_LESSON_TREE_TOO_LARGE_REASON, COMMUNITY_LESSON_TREE_TOO_DEEP_REASON, COMMUNITY_LESSON_LINE_PREFIX_TOO_WIDE_REASON, LINK_SCHEME;
10581
- var init_chunk_YULHXJ5M = __esm({
10582
- "../../packages/core/dist/chunk-YULHXJ5M.js"() {
10583
- "use strict";
10584
- COMMUNITY_LESSON_TREE_MAX_BYTES = 512 * 1024;
10585
- COMMUNITY_LESSON_LINK_PROTOCOLS = ["http", "https", "mailto"];
10586
- COMMUNITY_LESSON_TREE_TOO_LARGE_REASON = "lesson_tree_too_large";
10587
- COMMUNITY_LESSON_TREE_TOO_DEEP_REASON = "lesson_tree_too_deep";
10588
- COMMUNITY_LESSON_LINE_PREFIX_TOO_WIDE_REASON = "lesson_line_prefix_too_wide";
10589
- LINK_SCHEME = new RegExp(`^(${COMMUNITY_LESSON_LINK_PROTOCOLS.join("|")}):`, "i");
10590
- }
10591
- });
10592
-
10593
10579
  // ../../packages/core/dist/chunk-V4FRPRH5.js
10594
10580
  var CONSULT_THREAD_STATUSES, consultThreadStatus, CONSULT_THREAD_TITLE_MAX, consultThreadTitle, consultThreadSummary, listConsultThreadsQuery, listConsultThreadsResponse, createConsultThreadBody, createConsultThreadResponse, consultThreadIdParam, updateConsultThreadBody, updateConsultThreadResponse, CONSULT_AWAIT_TIMEOUT_MS;
10595
10581
  var init_chunk_V4FRPRH5 = __esm({
@@ -15524,6 +15510,155 @@ var init_chunk_JDJ4EUOL = __esm({
15524
15510
  }
15525
15511
  });
15526
15512
 
15513
+ // ../../packages/core/dist/chunk-YULHXJ5M.js
15514
+ var COMMUNITY_LESSON_TREE_MAX_BYTES, COMMUNITY_LESSON_LINK_PROTOCOLS, COMMUNITY_LESSON_TREE_TOO_LARGE_REASON, COMMUNITY_LESSON_TREE_TOO_DEEP_REASON, COMMUNITY_LESSON_LINE_PREFIX_TOO_WIDE_REASON, LINK_SCHEME;
15515
+ var init_chunk_YULHXJ5M = __esm({
15516
+ "../../packages/core/dist/chunk-YULHXJ5M.js"() {
15517
+ "use strict";
15518
+ COMMUNITY_LESSON_TREE_MAX_BYTES = 512 * 1024;
15519
+ COMMUNITY_LESSON_LINK_PROTOCOLS = ["http", "https", "mailto"];
15520
+ COMMUNITY_LESSON_TREE_TOO_LARGE_REASON = "lesson_tree_too_large";
15521
+ COMMUNITY_LESSON_TREE_TOO_DEEP_REASON = "lesson_tree_too_deep";
15522
+ COMMUNITY_LESSON_LINE_PREFIX_TOO_WIDE_REASON = "lesson_line_prefix_too_wide";
15523
+ LINK_SCHEME = new RegExp(`^(${COMMUNITY_LESSON_LINK_PROTOCOLS.join("|")}):`, "i");
15524
+ }
15525
+ });
15526
+
15527
+ // ../../packages/core/dist/chunk-K3PD6AOF.js
15528
+ var NEVER2;
15529
+ var init_chunk_K3PD6AOF = __esm({
15530
+ "../../packages/core/dist/chunk-K3PD6AOF.js"() {
15531
+ "use strict";
15532
+ init_chunk_MIWZOSPI();
15533
+ NEVER2 = Number.POSITIVE_INFINITY;
15534
+ }
15535
+ });
15536
+
15537
+ // ../../packages/core/dist/chunk-VYINA6YP.js
15538
+ function formatterOf(zone) {
15539
+ const held = formatters.get(zone);
15540
+ if (held) return held;
15541
+ if (zone.length === 0 || zone.length > TIME_ZONE_NAME_MAX_LENGTH) return null;
15542
+ let formatter;
15543
+ try {
15544
+ formatter = new Intl.DateTimeFormat("en-US", {
15545
+ timeZone: zone,
15546
+ calendar: "iso8601",
15547
+ numberingSystem: "latn",
15548
+ year: "numeric",
15549
+ month: "2-digit",
15550
+ day: "2-digit"
15551
+ });
15552
+ } catch {
15553
+ return null;
15554
+ }
15555
+ const resolved = formatter.resolvedOptions().timeZone;
15556
+ if (!/^[A-Za-z]/.test(resolved)) return null;
15557
+ if (resolved === zone) formatters.set(zone, formatter);
15558
+ return formatter;
15559
+ }
15560
+ function isTimeZone(zone) {
15561
+ return formatterOf(zone) !== null;
15562
+ }
15563
+ var TIME_ZONE_NAME_MAX_LENGTH, formatters;
15564
+ var init_chunk_VYINA6YP = __esm({
15565
+ "../../packages/core/dist/chunk-VYINA6YP.js"() {
15566
+ "use strict";
15567
+ TIME_ZONE_NAME_MAX_LENGTH = 64;
15568
+ formatters = /* @__PURE__ */ new Map();
15569
+ }
15570
+ });
15571
+
15572
+ // ../../packages/core/dist/chunk-3T3D7LTE.js
15573
+ var CASE_SPACE_NAME_MAX_LENGTH, CASE_SPACE_DEFAULT_TIME_ZONE, CASE_TEAM_NAME_MAX_LENGTH, CASE_TEAM_MEMBERS_MAX, CASE_TEAM_SCOPES_MAX, CASE_MEMBERS_PAGE_MAX, CASE_PAGE_CURSOR_MAX_LENGTH, CASE_LEVELS, CASE_TEAM_TARGET_KINDS, CASE_REGISTRY_CLOSED_REASON, caseSpaceNameSchema, caseSpaceTimeZoneSchema, updateCaseSpaceSettingsBody, adminCreateCaseSpaceBody, caseOrgParam, caseSpaceParam, caseMemberParam, caseAdministratorParam, caseTeamParam, casePageQuery, saveCaseMemberBody, caseTeamScopeSchema, caseTeamMemberInput, caseTeamFields, createCaseTeamBody, updateCaseTeamBody;
15574
+ var init_chunk_3T3D7LTE = __esm({
15575
+ "../../packages/core/dist/chunk-3T3D7LTE.js"() {
15576
+ "use strict";
15577
+ init_chunk_VYINA6YP();
15578
+ init_chunk_ZVXO3XL6();
15579
+ init_chunk_HZ6CADSY();
15580
+ init_zod();
15581
+ CASE_SPACE_NAME_MAX_LENGTH = 200;
15582
+ CASE_SPACE_DEFAULT_TIME_ZONE = "America/Sao_Paulo";
15583
+ CASE_TEAM_NAME_MAX_LENGTH = 200;
15584
+ CASE_TEAM_MEMBERS_MAX = 1e3;
15585
+ CASE_TEAM_SCOPES_MAX = 200;
15586
+ CASE_MEMBERS_PAGE_MAX = 200;
15587
+ CASE_PAGE_CURSOR_MAX_LENGTH = 2048;
15588
+ CASE_LEVELS = ["read", "edit", "conduct"];
15589
+ CASE_TEAM_TARGET_KINDS = ["party_group", "party", "instrument", "case_type", "case"];
15590
+ CASE_REGISTRY_CLOSED_REASON = "case_registry_closed";
15591
+ caseSpaceNameSchema = external_exports.string().trim().min(1).max(CASE_SPACE_NAME_MAX_LENGTH);
15592
+ caseSpaceTimeZoneSchema = external_exports.string().trim().min(1).max(TIME_ZONE_NAME_MAX_LENGTH).refine(isTimeZone, "Not a time zone (an IANA name such as America/Sao_Paulo)");
15593
+ updateCaseSpaceSettingsBody = external_exports.object({ timezone: caseSpaceTimeZoneSchema }).strict();
15594
+ adminCreateCaseSpaceBody = external_exports.object({
15595
+ org_id: uuidSchema,
15596
+ name: caseSpaceNameSchema,
15597
+ timezone: caseSpaceTimeZoneSchema.optional()
15598
+ }).strict();
15599
+ caseOrgParam = external_exports.object({ org_id: uuidSchema });
15600
+ caseSpaceParam = caseOrgParam.extend({ space_id: uuidSchema });
15601
+ caseMemberParam = caseSpaceParam.extend({ person_id: uuidSchema });
15602
+ caseAdministratorParam = caseSpaceParam.extend({ user_id: peopleUserIdSchema });
15603
+ caseTeamParam = caseSpaceParam.extend({ team_id: uuidSchema });
15604
+ casePageQuery = external_exports.object({
15605
+ limit: external_exports.coerce.number().int().min(1).max(CASE_MEMBERS_PAGE_MAX).optional(),
15606
+ cursor: external_exports.string().min(1).max(CASE_PAGE_CURSOR_MAX_LENGTH).optional()
15607
+ });
15608
+ saveCaseMemberBody = external_exports.object({
15609
+ user_id: peopleUserIdSchema,
15610
+ guest: external_exports.boolean().default(false),
15611
+ registry: external_exports.boolean().default(false),
15612
+ existing: external_exports.boolean().optional()
15613
+ }).strict().refine((body) => !(body.guest && body.registry), { message: "A guest cannot hold the Registry flag", path: ["registry"] });
15614
+ caseTeamScopeSchema = external_exports.discriminatedUnion("kind", [
15615
+ external_exports.object({ kind: external_exports.literal("space"), target_id: external_exports.null() }).strict(),
15616
+ external_exports.object({ kind: external_exports.enum(CASE_TEAM_TARGET_KINDS), target_id: uuidSchema }).strict()
15617
+ ]);
15618
+ caseTeamMemberInput = external_exports.object({
15619
+ person_id: uuidSchema,
15620
+ level: external_exports.enum(CASE_LEVELS),
15621
+ approve: external_exports.boolean(),
15622
+ confidential: external_exports.boolean()
15623
+ }).strict();
15624
+ caseTeamFields = {
15625
+ name: external_exports.string().trim().min(1).max(CASE_TEAM_NAME_MAX_LENGTH),
15626
+ active: external_exports.boolean(),
15627
+ scopes: external_exports.array(caseTeamScopeSchema).max(CASE_TEAM_SCOPES_MAX),
15628
+ members: external_exports.array(caseTeamMemberInput).max(CASE_TEAM_MEMBERS_MAX)
15629
+ };
15630
+ createCaseTeamBody = external_exports.object(caseTeamFields).strict();
15631
+ updateCaseTeamBody = external_exports.object({ ...caseTeamFields, expected_updated_at: timestampSchema.optional() }).strict();
15632
+ }
15633
+ });
15634
+
15635
+ // ../../packages/core/dist/chunk-KVMROYDC.js
15636
+ var caseTeamPreviewBody;
15637
+ var init_chunk_KVMROYDC = __esm({
15638
+ "../../packages/core/dist/chunk-KVMROYDC.js"() {
15639
+ "use strict";
15640
+ init_chunk_3T3D7LTE();
15641
+ init_chunk_HZ6CADSY();
15642
+ caseTeamPreviewBody = createCaseTeamBody.pick({ active: true, scopes: true, members: true }).extend({ team_id: uuidSchema.optional() }).strict();
15643
+ }
15644
+ });
15645
+
15646
+ // ../../packages/core/dist/chunk-M2IF4G6X.js
15647
+ var CASE_TIMELINE_PAGE_MAX, caseTimelineQuery;
15648
+ var init_chunk_M2IF4G6X = __esm({
15649
+ "../../packages/core/dist/chunk-M2IF4G6X.js"() {
15650
+ "use strict";
15651
+ init_chunk_3T3D7LTE();
15652
+ init_zod();
15653
+ CASE_TIMELINE_PAGE_MAX = 100;
15654
+ caseTimelineQuery = external_exports.object({
15655
+ limit: external_exports.coerce.number().int().min(1).max(CASE_TIMELINE_PAGE_MAX).optional(),
15656
+ /** An entry's `id`: the page after it (the header's IDS AND THE OPAQUE CURSOR). */
15657
+ after: external_exports.string().min(1).max(CASE_PAGE_CURSOR_MAX_LENGTH).optional()
15658
+ });
15659
+ }
15660
+ });
15661
+
15527
15662
  // ../../packages/core/dist/chunk-5Y2NNQHX.js
15528
15663
  var CASE_SUBMISSION_ISSUED_KINDS, CASE_SUBMISSION_RENDER_STUCK_MS, CASE_SUBMISSION_MARK_ID_PATTERN, CASE_CORRECTION_REASON_MAX_LENGTH, submitCaseBody, correctCaseSubmissionBody, caseDeliveryQuery;
15529
15664
  var init_chunk_5Y2NNQHX = __esm({
@@ -15549,6 +15684,31 @@ var init_chunk_5Y2NNQHX = __esm({
15549
15684
  }
15550
15685
  });
15551
15686
 
15687
+ // ../../packages/core/dist/chunk-NNC2ZECG.js
15688
+ var caseVerifyQuery;
15689
+ var init_chunk_NNC2ZECG = __esm({
15690
+ "../../packages/core/dist/chunk-NNC2ZECG.js"() {
15691
+ "use strict";
15692
+ init_chunk_5Y2NNQHX();
15693
+ init_zod();
15694
+ caseVerifyQuery = external_exports.object({ id: external_exports.string().regex(CASE_SUBMISSION_MARK_ID_PATTERN) }).strict();
15695
+ }
15696
+ });
15697
+
15698
+ // ../../packages/core/dist/chunk-7CZSLDOE.js
15699
+ var CASE_MEMBER_CASES_PAGE_MAX, caseMemberReachQuery;
15700
+ var init_chunk_7CZSLDOE = __esm({
15701
+ "../../packages/core/dist/chunk-7CZSLDOE.js"() {
15702
+ "use strict";
15703
+ init_chunk_3T3D7LTE();
15704
+ init_zod();
15705
+ CASE_MEMBER_CASES_PAGE_MAX = 50;
15706
+ caseMemberReachQuery = casePageQuery.extend({
15707
+ limit: external_exports.coerce.number().int().min(1).max(CASE_MEMBER_CASES_PAGE_MAX).optional()
15708
+ }).strict();
15709
+ }
15710
+ });
15711
+
15552
15712
  // ../../packages/core/dist/chunk-KWRHZBGU.js
15553
15713
  function fold(segment) {
15554
15714
  return segment.toUpperCase().toLowerCase().replace(/ς/g, "\u03C3").replace(/ß/g, "ss").normalize("NFC");
@@ -15658,108 +15818,10 @@ var init_chunk_KWRHZBGU = __esm({
15658
15818
  }
15659
15819
  });
15660
15820
 
15661
- // ../../packages/core/dist/chunk-VYINA6YP.js
15662
- function formatterOf(zone) {
15663
- const held = formatters.get(zone);
15664
- if (held) return held;
15665
- if (zone.length === 0 || zone.length > TIME_ZONE_NAME_MAX_LENGTH) return null;
15666
- let formatter;
15667
- try {
15668
- formatter = new Intl.DateTimeFormat("en-US", {
15669
- timeZone: zone,
15670
- calendar: "iso8601",
15671
- numberingSystem: "latn",
15672
- year: "numeric",
15673
- month: "2-digit",
15674
- day: "2-digit"
15675
- });
15676
- } catch {
15677
- return null;
15678
- }
15679
- const resolved = formatter.resolvedOptions().timeZone;
15680
- if (!/^[A-Za-z]/.test(resolved)) return null;
15681
- if (resolved === zone) formatters.set(zone, formatter);
15682
- return formatter;
15683
- }
15684
- function isTimeZone(zone) {
15685
- return formatterOf(zone) !== null;
15686
- }
15687
- var TIME_ZONE_NAME_MAX_LENGTH, formatters;
15688
- var init_chunk_VYINA6YP = __esm({
15689
- "../../packages/core/dist/chunk-VYINA6YP.js"() {
15690
- "use strict";
15691
- TIME_ZONE_NAME_MAX_LENGTH = 64;
15692
- formatters = /* @__PURE__ */ new Map();
15693
- }
15694
- });
15695
-
15696
- // ../../packages/core/dist/chunk-3T3D7LTE.js
15697
- var CASE_SPACE_NAME_MAX_LENGTH, CASE_SPACE_DEFAULT_TIME_ZONE, CASE_TEAM_NAME_MAX_LENGTH, CASE_TEAM_MEMBERS_MAX, CASE_TEAM_SCOPES_MAX, CASE_MEMBERS_PAGE_MAX, CASE_PAGE_CURSOR_MAX_LENGTH, CASE_LEVELS, CASE_TEAM_TARGET_KINDS, CASE_REGISTRY_CLOSED_REASON, caseSpaceNameSchema, caseSpaceTimeZoneSchema, updateCaseSpaceSettingsBody, adminCreateCaseSpaceBody, caseOrgParam, caseSpaceParam, caseMemberParam, caseAdministratorParam, caseTeamParam, casePageQuery, saveCaseMemberBody, caseTeamScopeSchema, caseTeamMemberInput, caseTeamFields, createCaseTeamBody, updateCaseTeamBody;
15698
- var init_chunk_3T3D7LTE = __esm({
15699
- "../../packages/core/dist/chunk-3T3D7LTE.js"() {
15700
- "use strict";
15701
- init_chunk_VYINA6YP();
15702
- init_chunk_ZVXO3XL6();
15703
- init_chunk_HZ6CADSY();
15704
- init_zod();
15705
- CASE_SPACE_NAME_MAX_LENGTH = 200;
15706
- CASE_SPACE_DEFAULT_TIME_ZONE = "America/Sao_Paulo";
15707
- CASE_TEAM_NAME_MAX_LENGTH = 200;
15708
- CASE_TEAM_MEMBERS_MAX = 1e3;
15709
- CASE_TEAM_SCOPES_MAX = 200;
15710
- CASE_MEMBERS_PAGE_MAX = 200;
15711
- CASE_PAGE_CURSOR_MAX_LENGTH = 2048;
15712
- CASE_LEVELS = ["read", "edit", "conduct"];
15713
- CASE_TEAM_TARGET_KINDS = ["party_group", "party", "instrument", "case_type", "case"];
15714
- CASE_REGISTRY_CLOSED_REASON = "case_registry_closed";
15715
- caseSpaceNameSchema = external_exports.string().trim().min(1).max(CASE_SPACE_NAME_MAX_LENGTH);
15716
- caseSpaceTimeZoneSchema = external_exports.string().trim().min(1).max(TIME_ZONE_NAME_MAX_LENGTH).refine(isTimeZone, "Not a time zone (an IANA name such as America/Sao_Paulo)");
15717
- updateCaseSpaceSettingsBody = external_exports.object({ timezone: caseSpaceTimeZoneSchema }).strict();
15718
- adminCreateCaseSpaceBody = external_exports.object({
15719
- org_id: uuidSchema,
15720
- name: caseSpaceNameSchema,
15721
- timezone: caseSpaceTimeZoneSchema.optional()
15722
- }).strict();
15723
- caseOrgParam = external_exports.object({ org_id: uuidSchema });
15724
- caseSpaceParam = caseOrgParam.extend({ space_id: uuidSchema });
15725
- caseMemberParam = caseSpaceParam.extend({ person_id: uuidSchema });
15726
- caseAdministratorParam = caseSpaceParam.extend({ user_id: peopleUserIdSchema });
15727
- caseTeamParam = caseSpaceParam.extend({ team_id: uuidSchema });
15728
- casePageQuery = external_exports.object({
15729
- limit: external_exports.coerce.number().int().min(1).max(CASE_MEMBERS_PAGE_MAX).optional(),
15730
- cursor: external_exports.string().min(1).max(CASE_PAGE_CURSOR_MAX_LENGTH).optional()
15731
- });
15732
- saveCaseMemberBody = external_exports.object({
15733
- user_id: peopleUserIdSchema,
15734
- guest: external_exports.boolean().default(false),
15735
- registry: external_exports.boolean().default(false),
15736
- existing: external_exports.boolean().optional()
15737
- }).strict().refine((body) => !(body.guest && body.registry), { message: "A guest cannot hold the Registry flag", path: ["registry"] });
15738
- caseTeamScopeSchema = external_exports.discriminatedUnion("kind", [
15739
- external_exports.object({ kind: external_exports.literal("space"), target_id: external_exports.null() }).strict(),
15740
- external_exports.object({ kind: external_exports.enum(CASE_TEAM_TARGET_KINDS), target_id: uuidSchema }).strict()
15741
- ]);
15742
- caseTeamMemberInput = external_exports.object({
15743
- person_id: uuidSchema,
15744
- level: external_exports.enum(CASE_LEVELS),
15745
- approve: external_exports.boolean(),
15746
- confidential: external_exports.boolean()
15747
- }).strict();
15748
- caseTeamFields = {
15749
- name: external_exports.string().trim().min(1).max(CASE_TEAM_NAME_MAX_LENGTH),
15750
- active: external_exports.boolean(),
15751
- scopes: external_exports.array(caseTeamScopeSchema).max(CASE_TEAM_SCOPES_MAX),
15752
- members: external_exports.array(caseTeamMemberInput).max(CASE_TEAM_MEMBERS_MAX)
15753
- };
15754
- createCaseTeamBody = external_exports.object(caseTeamFields).strict();
15755
- updateCaseTeamBody = external_exports.object({ ...caseTeamFields, expected_updated_at: timestampSchema.optional() }).strict();
15756
- }
15757
- });
15758
-
15759
- // ../../packages/core/dist/chunk-U7GWWTPM.js
15821
+ // ../../packages/core/dist/chunk-VROZDNLV.js
15760
15822
  var CASE_FILE_SHA_PATTERN, caseFileShaSchema, CASE_REVISION_MESSAGE_MAX_LENGTH, CASE_REVISION_SESSION_MAX_LENGTH, CASE_REVISION_ENTRIES_MAX, caseRevisionEntryShape, caseRevisionShape, CASE_UPLOAD_BODY_MAX_BYTES, CASE_UPLOAD_REVISION_FIELD, isBlob, caseUploadForm, CASE_FILES_PAGE_MAX, caseFilesQuery, caseFileReadPath, CASE_FILE_VERSIONS_PAGE_MAX, caseFileVersionsQuery, caseFileContentQuery, CASE_REVISIONS_PAGE_MAX, caseRevisionsQuery, CASE_FILE_COMPARE_MAX_BYTES, caseFileCompareQuery;
15761
- var init_chunk_U7GWWTPM = __esm({
15762
- "../../packages/core/dist/chunk-U7GWWTPM.js"() {
15823
+ var init_chunk_VROZDNLV = __esm({
15824
+ "../../packages/core/dist/chunk-VROZDNLV.js"() {
15763
15825
  "use strict";
15764
15826
  init_chunk_KWRHZBGU();
15765
15827
  init_chunk_3T3D7LTE();
@@ -15830,11 +15892,38 @@ var init_chunk_U7GWWTPM = __esm({
15830
15892
  caseRevisionsQuery = casePageQuery.extend({
15831
15893
  limit: external_exports.coerce.number().int().min(1).max(CASE_REVISIONS_PAGE_MAX).optional()
15832
15894
  });
15833
- CASE_FILE_COMPARE_MAX_BYTES = 4 * 1024 * 1024;
15834
- caseFileCompareQuery = external_exports.object({
15835
- path: caseFileReadPath,
15836
- from: uuidSchema,
15837
- to: uuidSchema
15895
+ CASE_FILE_COMPARE_MAX_BYTES = 4 * 1024 * 1024;
15896
+ caseFileCompareQuery = external_exports.object({
15897
+ path: caseFileReadPath,
15898
+ from: uuidSchema,
15899
+ to: uuidSchema
15900
+ });
15901
+ }
15902
+ });
15903
+
15904
+ // ../../packages/core/dist/chunk-U3X3BIQH.js
15905
+ var CASE_STYLE_KINDS, caseStyleParam, CASE_STYLE_VERSIONS_PAGE_MAX, caseStyleVersionsQuery, caseStyleContentQuery, CASE_STYLE_UPLOAD_BODY_MAX_BYTES, CASE_STYLE_FILE_FIELD, CASE_STYLE_EXPECT_FIELD, caseStyleUploadForm;
15906
+ var init_chunk_U3X3BIQH = __esm({
15907
+ "../../packages/core/dist/chunk-U3X3BIQH.js"() {
15908
+ "use strict";
15909
+ init_chunk_VROZDNLV();
15910
+ init_chunk_3T3D7LTE();
15911
+ init_chunk_HZ6CADSY();
15912
+ init_zod();
15913
+ CASE_STYLE_KINDS = ["pdf_stylesheet", "word_reference"];
15914
+ caseStyleParam = caseSpaceParam.extend({ kind: external_exports.enum(CASE_STYLE_KINDS) });
15915
+ CASE_STYLE_VERSIONS_PAGE_MAX = 100;
15916
+ caseStyleVersionsQuery = casePageQuery.extend({
15917
+ limit: external_exports.coerce.number().int().min(1).max(CASE_STYLE_VERSIONS_PAGE_MAX).optional()
15918
+ });
15919
+ caseStyleContentQuery = external_exports.object({ version_id: uuidSchema.optional() });
15920
+ CASE_STYLE_UPLOAD_BODY_MAX_BYTES = 20 * 1024 * 1024;
15921
+ CASE_STYLE_FILE_FIELD = "file";
15922
+ CASE_STYLE_EXPECT_FIELD = "expect_version_id";
15923
+ caseStyleUploadForm = external_exports.object({
15924
+ [CASE_STYLE_FILE_FIELD]: external_exports.custom(isBlob, "The file is required"),
15925
+ /** Empty: the uploader read no current version. */
15926
+ [CASE_STYLE_EXPECT_FIELD]: external_exports.union([uuidSchema, external_exports.literal("")]).transform((value) => value || null)
15838
15927
  });
15839
15928
  }
15840
15929
  });
@@ -15921,6 +16010,234 @@ var init_chunk_M2T55BV6 = __esm({
15921
16010
  }
15922
16011
  });
15923
16012
 
16013
+ // ../../packages/core/dist/chunk-3LMWOJQX.js
16014
+ function withProblem(shape, problemOf) {
16015
+ return shape.superRefine((value, ctx) => {
16016
+ const found = problemOf(value);
16017
+ if (found) {
16018
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: found.reason, path: found.at.split("."), params: { case_registry_reason: found.reason } });
16019
+ }
16020
+ });
16021
+ }
16022
+ function caseRegistryTypeProblem(type) {
16023
+ const found = caseAttributesSchemaProblem(type.attributes);
16024
+ if (found) return { reason: found.reason, at: `attributes.${found.at}` };
16025
+ if (JSON.stringify(type.attributes).length > CASE_REGISTRY_TYPE_SCHEMA_MAX_CHARS) return { reason: "attributes_schema_too_large", at: "attributes" };
16026
+ return null;
16027
+ }
16028
+ function casePartyProblem(party) {
16029
+ if (party.document_kind === null !== (party.document_number === null)) return { reason: "document_incomplete", at: "document_number" };
16030
+ if (party.document_kind === "cpf" || party.document_kind === "cnpj") {
16031
+ if (party.person_kind !== (party.document_kind === "cpf" ? "natural" : "legal")) return { reason: "document_person_mismatch", at: "document_kind" };
16032
+ if (!(party.document_kind === "cpf" ? /^[0-9]{11}$/ : /^[0-9]{14}$/).test(party.document_number ?? "")) {
16033
+ return { reason: "document_digits", at: "document_number" };
16034
+ }
16035
+ }
16036
+ return null;
16037
+ }
16038
+ function casePartyGroupProblem(group) {
16039
+ return new Set(group.party_ids).size === group.party_ids.length ? null : { reason: "party_repeated", at: "party_ids" };
16040
+ }
16041
+ function caseInstrumentProblem(instrument) {
16042
+ if (instrument.effective_from !== null && instrument.effective_until !== null && instrument.effective_until < instrument.effective_from) {
16043
+ return { reason: "effective_dates_reversed", at: "effective_until" };
16044
+ }
16045
+ const keys = instrument.parties.map((party) => `${party.party_id}
16046
+ ${party.role}`);
16047
+ return new Set(keys).size === keys.length ? null : { reason: "instrument_party_repeated", at: "parties" };
16048
+ }
16049
+ var CASE_REGISTRY_TYPE_CODE_PATTERN, CASE_REGISTRY_TYPE_CODE_MAX_LENGTH, CASE_REGISTRY_NAME_MAX_LENGTH, CASE_REGISTRY_TYPE_SCHEMA_MAX_CHARS, CASE_PARTY_ABBREVIATION_PATTERN, CASE_PARTY_PERSON_KINDS, CASE_PARTY_DOCUMENT_KINDS, CASE_PARTY_DOCUMENT_MAX_LENGTH, CASE_PARTY_GROUP_MEMBERS_MAX, CASE_INSTRUMENT_NUMBER_MAX_LENGTH, CASE_INSTRUMENT_ROLE_MAX_LENGTH, CASE_INSTRUMENT_PARTIES_MAX, CASE_REGISTRY_PAGE_MAX, CASE_REGISTRY_QUERY_MAX_LENGTH, trimmedName, dateSchema, attributesValues, registryTypeFields, createCaseRegistryTypeShape, updateCaseRegistryTypeShape, createCaseRegistryTypeBody, updateCaseRegistryTypeBody, saveCasePartyShape, saveCasePartyBody, saveCasePartyGroupShape, saveCasePartyGroupBody, caseInstrumentPartyInput, saveCaseInstrumentShape, saveCaseInstrumentBody, registryPage, searchText, casePartiesQuery, casePartyGroupsQuery, caseInstrumentsQuery, caseRegistryTypeParam, casePartyParam, casePartyGroupParam, caseInstrumentParam;
16050
+ var init_chunk_3LMWOJQX = __esm({
16051
+ "../../packages/core/dist/chunk-3LMWOJQX.js"() {
16052
+ "use strict";
16053
+ init_chunk_3T3D7LTE();
16054
+ init_chunk_M2T55BV6();
16055
+ init_chunk_HZ6CADSY();
16056
+ init_zod();
16057
+ CASE_REGISTRY_TYPE_CODE_PATTERN = /^[a-z0-9]+(_[a-z0-9]+)*$/;
16058
+ CASE_REGISTRY_TYPE_CODE_MAX_LENGTH = 64;
16059
+ CASE_REGISTRY_NAME_MAX_LENGTH = 200;
16060
+ CASE_REGISTRY_TYPE_SCHEMA_MAX_CHARS = 64 * 1024;
16061
+ CASE_PARTY_ABBREVIATION_PATTERN = /^[A-Z0-9]{2,12}$/;
16062
+ CASE_PARTY_PERSON_KINDS = ["natural", "legal"];
16063
+ CASE_PARTY_DOCUMENT_KINDS = ["cpf", "cnpj", "other"];
16064
+ CASE_PARTY_DOCUMENT_MAX_LENGTH = 64;
16065
+ CASE_PARTY_GROUP_MEMBERS_MAX = 2e3;
16066
+ CASE_INSTRUMENT_NUMBER_MAX_LENGTH = 200;
16067
+ CASE_INSTRUMENT_ROLE_MAX_LENGTH = 200;
16068
+ CASE_INSTRUMENT_PARTIES_MAX = 50;
16069
+ CASE_REGISTRY_PAGE_MAX = 100;
16070
+ CASE_REGISTRY_QUERY_MAX_LENGTH = 200;
16071
+ trimmedName = external_exports.string().trim().min(1).max(CASE_REGISTRY_NAME_MAX_LENGTH);
16072
+ dateSchema = caseDateSchema;
16073
+ attributesValues = external_exports.record(external_exports.string(), external_exports.unknown()).default({});
16074
+ registryTypeFields = {
16075
+ name: trimmedName,
16076
+ attributes: caseAttributesSchemaSchema.default(EMPTY_CASE_ATTRIBUTES_SCHEMA),
16077
+ active: external_exports.boolean().default(true)
16078
+ };
16079
+ createCaseRegistryTypeShape = external_exports.object({
16080
+ code: external_exports.string().trim().max(CASE_REGISTRY_TYPE_CODE_MAX_LENGTH).regex(CASE_REGISTRY_TYPE_CODE_PATTERN),
16081
+ ...registryTypeFields
16082
+ }).strict();
16083
+ updateCaseRegistryTypeShape = external_exports.object({
16084
+ ...registryTypeFields,
16085
+ expected_updated_at: timestampSchema.optional()
16086
+ }).strict();
16087
+ createCaseRegistryTypeBody = withProblem(createCaseRegistryTypeShape, caseRegistryTypeProblem);
16088
+ updateCaseRegistryTypeBody = withProblem(updateCaseRegistryTypeShape, caseRegistryTypeProblem);
16089
+ saveCasePartyShape = external_exports.object({
16090
+ type_id: uuidSchema,
16091
+ name: trimmedName,
16092
+ abbreviation: external_exports.string().trim().transform((value) => value.toUpperCase()).pipe(external_exports.string().regex(CASE_PARTY_ABBREVIATION_PATTERN)).nullable().default(null),
16093
+ person_kind: external_exports.enum(CASE_PARTY_PERSON_KINDS),
16094
+ document_kind: external_exports.enum(CASE_PARTY_DOCUMENT_KINDS).nullable().default(null),
16095
+ document_number: external_exports.string().trim().min(1).max(CASE_PARTY_DOCUMENT_MAX_LENGTH).nullable().default(null),
16096
+ attributes: attributesValues,
16097
+ active: external_exports.boolean().default(true),
16098
+ expected_updated_at: timestampSchema.optional()
16099
+ }).strict();
16100
+ saveCasePartyBody = withProblem(saveCasePartyShape, casePartyProblem);
16101
+ saveCasePartyGroupShape = external_exports.object({
16102
+ name: trimmedName,
16103
+ party_ids: external_exports.array(uuidSchema).max(CASE_PARTY_GROUP_MEMBERS_MAX).default([]),
16104
+ expected_updated_at: timestampSchema.optional()
16105
+ }).strict();
16106
+ saveCasePartyGroupBody = withProblem(saveCasePartyGroupShape, casePartyGroupProblem);
16107
+ caseInstrumentPartyInput = external_exports.object({
16108
+ party_id: uuidSchema,
16109
+ role: external_exports.string().trim().min(1).max(CASE_INSTRUMENT_ROLE_MAX_LENGTH)
16110
+ }).strict();
16111
+ saveCaseInstrumentShape = external_exports.object({
16112
+ type_id: uuidSchema,
16113
+ number: external_exports.string().trim().min(1).max(CASE_INSTRUMENT_NUMBER_MAX_LENGTH),
16114
+ signed_on: dateSchema.nullable().default(null),
16115
+ effective_from: dateSchema.nullable().default(null),
16116
+ effective_until: dateSchema.nullable().default(null),
16117
+ attributes: attributesValues,
16118
+ /** Each party in a role; one party may hold several roles. */
16119
+ parties: external_exports.array(caseInstrumentPartyInput).max(CASE_INSTRUMENT_PARTIES_MAX).default([]),
16120
+ expected_updated_at: timestampSchema.optional()
16121
+ }).strict();
16122
+ saveCaseInstrumentBody = withProblem(saveCaseInstrumentShape, caseInstrumentProblem);
16123
+ registryPage = casePageQuery.extend({
16124
+ limit: external_exports.coerce.number().int().min(1).max(CASE_REGISTRY_PAGE_MAX).optional()
16125
+ });
16126
+ searchText = external_exports.string().trim().min(1).max(CASE_REGISTRY_QUERY_MAX_LENGTH).optional();
16127
+ casePartiesQuery = registryPage.extend({
16128
+ q: searchText,
16129
+ type_id: uuidSchema.optional(),
16130
+ active: external_exports.enum(["true", "false"]).transform((value) => value === "true").optional()
16131
+ });
16132
+ casePartyGroupsQuery = registryPage.extend({ q: searchText });
16133
+ caseInstrumentsQuery = registryPage.extend({
16134
+ q: searchText,
16135
+ type_id: uuidSchema.optional(),
16136
+ party_id: uuidSchema.optional()
16137
+ });
16138
+ caseRegistryTypeParam = caseSpaceParam.extend({ type_id: uuidSchema });
16139
+ casePartyParam = caseSpaceParam.extend({ party_id: uuidSchema });
16140
+ casePartyGroupParam = caseSpaceParam.extend({ group_id: uuidSchema });
16141
+ caseInstrumentParam = caseSpaceParam.extend({ instrument_id: uuidSchema });
16142
+ }
16143
+ });
16144
+
16145
+ // ../../packages/core/dist/chunk-PMBOHJKA.js
16146
+ function collectionUploadForm(field, shape) {
16147
+ return external_exports.record(external_exports.string(), external_exports.unknown()).transform((form2, ctx) => {
16148
+ const refuse2 = (message, path46) => {
16149
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message, path: [path46] });
16150
+ return external_exports.NEVER;
16151
+ };
16152
+ const text5 = form2[field];
16153
+ if (typeof text5 !== "string") return refuse2(`The field ${field} is required`, field);
16154
+ let body;
16155
+ try {
16156
+ body = JSON.parse(text5);
16157
+ } catch {
16158
+ return refuse2(`The field ${field} is not JSON`, field);
16159
+ }
16160
+ const parsed = shape.safeParse(body);
16161
+ if (!parsed.success) return refuse2(parsed.error.issues[0]?.message ?? `The field ${field} is not of its shape`, field);
16162
+ const parts = [];
16163
+ for (const [name, value] of Object.entries(form2)) {
16164
+ if (name === field) continue;
16165
+ if (!isCaseCollectionPart(name) || !isBlob(value)) {
16166
+ return refuse2("A part is the file, its Word copy or its text, sent once", name);
16167
+ }
16168
+ const sentName = value.name;
16169
+ parts.push({ part: name, bytes: value, name: typeof sentName === "string" ? sentName : "" });
16170
+ }
16171
+ if (!parts.some((part) => part.part === "file")) return refuse2("The file is required", "file");
16172
+ return { body, fields: parsed.data, parts };
16173
+ });
16174
+ }
16175
+ var CASE_COLLECTION_FOLDERS, CASE_COLLECTION_PARTS, isCaseCollectionPart, CASE_COLLECTION_TITLE_MAX_LENGTH, CASE_COLLECTION_TYPE_MAX_LENGTH, CASE_COLLECTION_REASON_MAX_LENGTH, caseCollectionDocumentParam, dateOnly, title, registerCaseCollectionDocumentShape, addCaseCollectionVersionShape, CASE_COLLECTION_UPLOAD_BODY_MAX_BYTES, CASE_COLLECTION_DOCUMENT_FIELD, CASE_COLLECTION_VERSION_FIELD, caseCollectionDocumentUploadForm, caseCollectionVersionUploadForm, CASE_COLLECTION_PAGE_MAX, CASE_COLLECTION_CURSOR_MAX_LENGTH, caseCollectionQuery, CASE_COLLECTION_VERSIONS_PAGE_MAX, caseCollectionVersionsQuery, caseCollectionContentQuery;
16176
+ var init_chunk_PMBOHJKA = __esm({
16177
+ "../../packages/core/dist/chunk-PMBOHJKA.js"() {
16178
+ "use strict";
16179
+ init_chunk_U3X3BIQH();
16180
+ init_chunk_3LMWOJQX();
16181
+ init_chunk_VROZDNLV();
16182
+ init_chunk_3T3D7LTE();
16183
+ init_chunk_M2T55BV6();
16184
+ init_chunk_HZ6CADSY();
16185
+ init_zod();
16186
+ CASE_COLLECTION_FOLDERS = ["norms", "internal_norms", "instruments", "data"];
16187
+ CASE_COLLECTION_PARTS = ["file", "word", "text"];
16188
+ isCaseCollectionPart = (part) => CASE_COLLECTION_PARTS.includes(part);
16189
+ CASE_COLLECTION_TITLE_MAX_LENGTH = 300;
16190
+ CASE_COLLECTION_TYPE_MAX_LENGTH = 100;
16191
+ CASE_COLLECTION_REASON_MAX_LENGTH = 2e3;
16192
+ caseCollectionDocumentParam = caseSpaceParam.extend({ document_id: uuidSchema });
16193
+ dateOnly = caseDateSchema;
16194
+ title = external_exports.string().trim().min(1).max(CASE_COLLECTION_TITLE_MAX_LENGTH);
16195
+ registerCaseCollectionDocumentShape = external_exports.object({
16196
+ title,
16197
+ folder: external_exports.enum(CASE_COLLECTION_FOLDERS),
16198
+ type: external_exports.string().trim().min(1).max(CASE_COLLECTION_TYPE_MAX_LENGTH),
16199
+ party_id: uuidSchema.nullable().default(null),
16200
+ instrument_id: uuidSchema.nullable().default(null),
16201
+ group_id: uuidSchema.nullable().default(null),
16202
+ confidential: external_exports.boolean().default(false),
16203
+ effective_from: dateOnly.nullable().default(null)
16204
+ }).strict();
16205
+ addCaseCollectionVersionShape = external_exports.object({
16206
+ /** The version its writer read as current. */
16207
+ expect_version_id: uuidSchema,
16208
+ reason: external_exports.string().trim().min(1).max(CASE_COLLECTION_REASON_MAX_LENGTH),
16209
+ /** Null keeps the current version's title. */
16210
+ title: title.nullable().default(null),
16211
+ effective_from: dateOnly.nullable().default(null)
16212
+ }).strict();
16213
+ CASE_COLLECTION_UPLOAD_BODY_MAX_BYTES = 20 * 1024 * 1024;
16214
+ CASE_COLLECTION_DOCUMENT_FIELD = "document";
16215
+ CASE_COLLECTION_VERSION_FIELD = "version";
16216
+ caseCollectionDocumentUploadForm = collectionUploadForm(CASE_COLLECTION_DOCUMENT_FIELD, registerCaseCollectionDocumentShape);
16217
+ caseCollectionVersionUploadForm = collectionUploadForm(CASE_COLLECTION_VERSION_FIELD, addCaseCollectionVersionShape);
16218
+ CASE_COLLECTION_PAGE_MAX = 100;
16219
+ CASE_COLLECTION_CURSOR_MAX_LENGTH = Math.ceil((2 * CASE_COLLECTION_TITLE_MAX_LENGTH * 6 + 36 + 7) / 3) * 4;
16220
+ caseCollectionQuery = casePageQuery.extend({
16221
+ limit: external_exports.coerce.number().int().min(1).max(CASE_COLLECTION_PAGE_MAX).optional(),
16222
+ cursor: external_exports.string().min(1).max(CASE_COLLECTION_CURSOR_MAX_LENGTH).optional(),
16223
+ q: external_exports.string().trim().min(1).max(CASE_REGISTRY_QUERY_MAX_LENGTH).optional(),
16224
+ folder: external_exports.enum(CASE_COLLECTION_FOLDERS).optional(),
16225
+ type: external_exports.string().trim().min(1).max(CASE_COLLECTION_TYPE_MAX_LENGTH).optional(),
16226
+ group: uuidSchema.optional(),
16227
+ party: uuidSchema.optional(),
16228
+ instrument: uuidSchema.optional()
16229
+ });
16230
+ CASE_COLLECTION_VERSIONS_PAGE_MAX = 100;
16231
+ caseCollectionVersionsQuery = casePageQuery.extend({
16232
+ limit: external_exports.coerce.number().int().min(1).max(CASE_COLLECTION_VERSIONS_PAGE_MAX).optional()
16233
+ });
16234
+ caseCollectionContentQuery = external_exports.object({
16235
+ part: external_exports.enum(CASE_COLLECTION_PARTS).default("file"),
16236
+ version_id: uuidSchema.optional()
16237
+ });
16238
+ }
16239
+ });
16240
+
15924
16241
  // ../../packages/core/dist/chunk-PFPADFUC.js
15925
16242
  function resolveItemLink(phaseFolder, target) {
15926
16243
  const slash = target.lastIndexOf("/");
@@ -16308,567 +16625,137 @@ var init_chunk_PFPADFUC = __esm({
16308
16625
  optional: external_exports.boolean().default(false),
16309
16626
  on_demand: external_exports.boolean().default(false),
16310
16627
  joint_delivery: external_exports.boolean().default(false),
16311
- review_mode: external_exports.enum(CASE_REVIEW_MODES).default("conduct"),
16312
- /** The team that signs off, in `team` mode and only there. */
16313
- review_team_id: uuidSchema.nullable().default(null),
16314
- case_inputs_allowed: external_exports.boolean().default(false),
16315
- phase_outputs: external_exports.array(casePhaseOutputSchema).max(30).default([]),
16316
- phase_inputs: external_exports.array(casePhaseInputSchema).max(50).default([]),
16317
- type_tasks: external_exports.array(caseTypeTaskSchema).max(100).default([]),
16318
- agenda_groups: external_exports.array(caseAgendaGroupSchema).max(20).default([])
16319
- }).strict();
16320
- caseTypeDefinitionShape = external_exports.object({
16321
- type_party_roles: external_exports.array(caseTypePartyRoleSchema).max(50).default([]),
16322
- type_outcomes: external_exports.array(caseTypeOutcomeSchema).max(50).default([]),
16323
- type_phases: external_exports.array(caseTypePhaseSchema).min(1).max(50),
16324
- /** The JSON Schema of its cases' `attributes`: their custom fields. Absent, none. */
16325
- attributes: caseAttributesSchemaSchema.default(() => ({ ...EMPTY_CASE_ATTRIBUTES_SCHEMA }))
16326
- }).strict();
16327
- caseValuesRepeated = (values) => new Set(values).size !== values.length;
16328
- CHAPTER_PROBE = "00-chapter.md";
16329
- caseTypeDefinitionSchema = caseTypeDefinitionShape.superRefine((definition, ctx) => {
16330
- const found = caseTypeDefinitionProblem(definition);
16331
- if (found) {
16332
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: found.reason, path: found.at.split("."), params: { case_type_reason: found.reason } });
16333
- }
16334
- });
16335
- caseTypeAbbreviationSchema = external_exports.string().trim().transform((value) => value.toUpperCase()).pipe(external_exports.string().regex(CASE_TYPE_ABBREVIATION_PATTERN));
16336
- caseTypeNameSchema = external_exports.string().trim().min(1).max(CASE_TYPE_NAME_MAX_LENGTH);
16337
- createCaseTypeBody = external_exports.object({
16338
- abbreviation: caseTypeAbbreviationSchema,
16339
- name: caseTypeNameSchema,
16340
- definition: caseTypeDefinitionSchema
16341
- }).strict();
16342
- publishCaseTypeVersionBody = external_exports.object({
16343
- expected_version: external_exports.number().int().min(1).max(CASE_TYPE_VERSIONS_MAX),
16344
- name: caseTypeNameSchema,
16345
- definition: caseTypeDefinitionSchema
16346
- }).strict();
16347
- setCaseTypeActiveBody = external_exports.object({ active: external_exports.boolean() }).strict();
16348
- caseTypeParam = caseSpaceParam.extend({ type_id: uuidSchema });
16349
- caseTypesPageQuery = casePageQuery.extend({
16350
- limit: external_exports.coerce.number().int().min(1).max(CASE_TYPES_PAGE_MAX).optional()
16351
- });
16352
- caseTypeVersionQuery = external_exports.object({
16353
- version: external_exports.coerce.number().int().min(1).max(CASE_TYPE_VERSIONS_MAX).optional()
16354
- });
16355
- }
16356
- });
16357
-
16358
- // ../../packages/core/dist/chunk-733K4J4G.js
16359
- function openCaseProblem(body) {
16360
- const pairs = /* @__PURE__ */ new Set();
16361
- for (const [index, party] of body.parties.entries()) {
16362
- const key = `${party.party_id}
16363
- ${party.role}`;
16364
- if (pairs.has(key)) return { reason: "party_role_repeated", at: `parties.${index}` };
16365
- pairs.add(key);
16366
- }
16367
- if (new Set(body.instrument_ids).size !== body.instrument_ids.length) return { reason: "instrument_repeated", at: "instrument_ids" };
16368
- return null;
16369
- }
16370
- var CASE_RECORD_CODE_PATTERN, CASE_RECORD_CODE_MAX_LENGTH, CASE_RECORD_PARTIES_MAX, CASE_RECORD_INSTRUMENTS_MAX, CASE_RECORD_ROLE_MAX_LENGTH, CASE_RECORDS_PAGE_MAX, CASE_RECORDS_QUERY_MAX_LENGTH, caseRecordPartySchema, openCaseShape, openCaseBody, previewOpenCaseShape, caseRecordParam, CASE_RECORD_STATUSES, caseRecordsQuery, CASE_STATE_SUMMARIES_MAX, caseStatesQuery, CASE_CLOSURE_REASON_MAX_LENGTH, closeCaseBody, setCaseConfidentialityBody;
16371
- var init_chunk_733K4J4G = __esm({
16372
- "../../packages/core/dist/chunk-733K4J4G.js"() {
16373
- "use strict";
16374
- init_chunk_PFPADFUC();
16375
- init_chunk_3T3D7LTE();
16376
- init_chunk_HZ6CADSY();
16377
- init_chunk_ZTNFLGW5();
16378
- init_zod();
16379
- CASE_RECORD_CODE_PATTERN = new RegExp(`^${CASE_TYPE_ABBREVIATION_PATTERN.source.slice(1, -1)}-[0-9]{4}-[0-9]{4,}$`);
16380
- CASE_RECORD_CODE_MAX_LENGTH = 32;
16381
- CASE_RECORD_PARTIES_MAX = 50;
16382
- CASE_RECORD_INSTRUMENTS_MAX = 50;
16383
- CASE_RECORD_ROLE_MAX_LENGTH = 64;
16384
- CASE_RECORDS_PAGE_MAX = 100;
16385
- CASE_RECORDS_QUERY_MAX_LENGTH = 32;
16386
- caseRecordPartySchema = external_exports.object({
16387
- party_id: uuidSchema,
16388
- role: external_exports.string().min(1).max(CASE_RECORD_ROLE_MAX_LENGTH)
16389
- }).strict();
16390
- openCaseShape = external_exports.object({
16391
- type_id: uuidSchema,
16392
- /** The year in its code: within a year of today's year in the space's time zone. */
16393
- year: external_exports.number().int().min(2e3).max(2100),
16394
- parties: external_exports.array(caseRecordPartySchema).max(CASE_RECORD_PARTIES_MAX).default([]),
16395
- instrument_ids: external_exports.array(uuidSchema).max(CASE_RECORD_INSTRUMENTS_MAX).default([]),
16396
- /** The custom field values, checked against the version's schema in the space. */
16397
- attributes: external_exports.record(external_exports.string(), external_exports.unknown()).default({}),
16398
- confidential: external_exports.boolean().default(false),
16399
- /** The code the opener was shown: another case holding it opens nothing. */
16400
- expected_code: external_exports.string().max(CASE_RECORD_CODE_MAX_LENGTH).regex(CASE_RECORD_CODE_PATTERN).optional()
16401
- }).strict();
16402
- openCaseBody = openCaseShape.superRefine((body, ctx) => {
16403
- const found = openCaseProblem(body);
16404
- if (found) {
16405
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: found.reason, path: found.at.split("."), params: { case_record_reason: found.reason } });
16406
- }
16407
- });
16408
- previewOpenCaseShape = openCaseShape.pick({ type_id: true, year: true, parties: true, instrument_ids: true, confidential: true }).strict();
16409
- caseRecordParam = caseSpaceParam.extend({
16410
- code: external_exports.string().max(CASE_RECORD_CODE_MAX_LENGTH).regex(CASE_RECORD_CODE_PATTERN)
16411
- });
16412
- CASE_RECORD_STATUSES = ["open", "closed"];
16413
- caseRecordsQuery = casePageQuery.extend({
16414
- limit: external_exports.coerce.number().int().min(1).max(CASE_RECORDS_PAGE_MAX).optional(),
16415
- type_id: uuidSchema.optional(),
16416
- q: external_exports.string().trim().min(1).max(CASE_RECORDS_QUERY_MAX_LENGTH).optional(),
16417
- search: external_exports.string().trim().min(1).max(CASE_RECORDS_QUERY_MAX_LENGTH).optional(),
16418
- group_id: uuidSchema.optional(),
16419
- status: external_exports.enum(CASE_RECORD_STATUSES).optional()
16420
- });
16421
- CASE_STATE_SUMMARIES_MAX = CASE_RECORDS_PAGE_MAX;
16422
- caseStatesQuery = external_exports.object({
16423
- codes: external_exports.string().max(CASE_STATE_SUMMARIES_MAX * (CASE_RECORD_CODE_MAX_LENGTH + 1)).transform((codes) => codes.split(",")).pipe(external_exports.array(external_exports.string().max(CASE_RECORD_CODE_MAX_LENGTH).regex(CASE_RECORD_CODE_PATTERN)).min(1).max(CASE_STATE_SUMMARIES_MAX))
16424
- });
16425
- CASE_CLOSURE_REASON_MAX_LENGTH = 2e3;
16426
- closeCaseBody = external_exports.object({
16427
- outcome_code: external_exports.string().max(CASE_CODE_MAX_LENGTH).regex(CASE_CODE_PATTERN),
16428
- reason: external_exports.string().trim().min(1).max(CASE_CLOSURE_REASON_MAX_LENGTH)
16429
- }).strict();
16430
- setCaseConfidentialityBody = external_exports.object({ confidential: external_exports.boolean() }).strict();
16431
- }
16432
- });
16433
-
16434
- // ../../packages/core/dist/chunk-4HBSIBSD.js
16435
- var CASE_OFFICIAL_FILE_KINDS, CASE_OFFICIAL_FILE_NAME_PATTERN, publishCaseSubmissionBody, caseOfficialVersionParam, caseOfficialFileQuery;
16436
- var init_chunk_4HBSIBSD = __esm({
16437
- "../../packages/core/dist/chunk-4HBSIBSD.js"() {
16438
- "use strict";
16439
- init_chunk_5Y2NNQHX();
16440
- init_chunk_U7GWWTPM();
16441
- init_chunk_733K4J4G();
16442
- init_chunk_HZ6CADSY();
16443
- init_zod();
16444
- CASE_OFFICIAL_FILE_KINDS = [...CASE_SUBMISSION_ISSUED_KINDS, "file"];
16445
- CASE_OFFICIAL_FILE_NAME_PATTERN = /^[^/\\\u0000-\u001f]{1,255}$/;
16446
- publishCaseSubmissionBody = external_exports.object({
16447
- /** The final digest its publisher saw (`CaseDelivery.final_digest`). */
16448
- digest: caseFileShaSchema
16449
- }).strict();
16450
- caseOfficialVersionParam = caseRecordParam.extend({ official_version_id: uuidSchema });
16451
- caseOfficialFileQuery = external_exports.object({ name: external_exports.string().regex(CASE_OFFICIAL_FILE_NAME_PATTERN) }).strict();
16452
- }
16453
- });
16454
-
16455
- // ../../packages/core/dist/chunk-BT77VXJU.js
16456
- var casePhaseParam;
16457
- var init_chunk_BT77VXJU = __esm({
16458
- "../../packages/core/dist/chunk-BT77VXJU.js"() {
16459
- "use strict";
16460
- init_chunk_733K4J4G();
16461
- init_chunk_HZ6CADSY();
16462
- casePhaseParam = caseRecordParam.extend({ phase_id: uuidSchema });
16463
- }
16464
- });
16465
-
16466
- // ../../packages/core/dist/chunk-RHXF6X2Y.js
16467
- var CASE_CHECK_CSV_MAX_BYTES, caseChecksQuery;
16468
- var init_chunk_RHXF6X2Y = __esm({
16469
- "../../packages/core/dist/chunk-RHXF6X2Y.js"() {
16470
- "use strict";
16471
- init_chunk_5Y2NNQHX();
16472
- init_chunk_HZ6CADSY();
16473
- init_zod();
16474
- CASE_CHECK_CSV_MAX_BYTES = 4 * 1024 * 1024;
16475
- caseChecksQuery = external_exports.object({
16476
- output_id: uuidSchema.optional()
16477
- }).strict();
16478
- }
16479
- });
16480
-
16481
- // ../../packages/core/dist/chunk-P53C23HN.js
16482
- var CASE_REVIEW_DECISIONS, CASE_ISSUED_FORMATS, CASE_REVIEW_COMMENT_MAX_LENGTH, CASE_REVIEW_JUSTIFICATION_MAX_LENGTH, text2, caseSubmissionParam, decideCaseSubmissionBody, caseIssuedQuery, CASE_APPROVALS_STATES, caseApprovalsQuery, caseCompareDefaultQuery, caseApprovalsAgendaQuery;
16483
- var init_chunk_P53C23HN = __esm({
16484
- "../../packages/core/dist/chunk-P53C23HN.js"() {
16485
- "use strict";
16486
- init_chunk_4HBSIBSD();
16487
- init_chunk_BT77VXJU();
16488
- init_chunk_RHXF6X2Y();
16489
- init_chunk_5Y2NNQHX();
16490
- init_chunk_U7GWWTPM();
16491
- init_chunk_733K4J4G();
16492
- init_chunk_3T3D7LTE();
16493
- init_chunk_HZ6CADSY();
16494
- init_zod();
16495
- CASE_REVIEW_DECISIONS = ["sign_off", "approve", "return"];
16496
- CASE_ISSUED_FORMATS = ["pdf", "docx"];
16497
- CASE_REVIEW_COMMENT_MAX_LENGTH = 2e3;
16498
- CASE_REVIEW_JUSTIFICATION_MAX_LENGTH = 2e3;
16499
- text2 = (max) => external_exports.string().trim().min(1).max(max);
16500
- caseSubmissionParam = caseRecordParam.extend({ submission_id: uuidSchema });
16501
- decideCaseSubmissionBody = external_exports.object({
16502
- decision: external_exports.enum(CASE_REVIEW_DECISIONS),
16503
- /** The final digest its decider saw (`CaseDelivery.final_digest`). */
16504
- digest: caseFileShaSchema,
16505
- /** Required to return. */
16506
- comment: text2(CASE_REVIEW_COMMENT_MAX_LENGTH).nullable().default(null),
16507
- /** Why one approves or signs off their own work; kept only then. */
16508
- justification: text2(CASE_REVIEW_JUSTIFICATION_MAX_LENGTH).nullable().default(null)
16509
- }).strict().superRefine((body, ctx) => {
16510
- if (body.decision === "return" && body.comment === null) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: "A return needs its comment", path: ["comment"] });
16511
- });
16512
- caseIssuedQuery = external_exports.object({
16513
- number: external_exports.coerce.number().int().min(1).max(1e3),
16514
- format: external_exports.enum(CASE_ISSUED_FORMATS)
16515
- }).strict();
16516
- CASE_APPROVALS_STATES = ["waiting", "open", "ended"];
16517
- caseApprovalsQuery = external_exports.object({
16518
- state: external_exports.enum(CASE_APPROVALS_STATES).default("open"),
16519
- cursor: external_exports.string().min(1).max(CASE_PAGE_CURSOR_MAX_LENGTH).optional()
16520
- }).strict();
16521
- caseCompareDefaultQuery = external_exports.object({ path: caseFileReadPath }).strict();
16522
- caseApprovalsAgendaQuery = external_exports.object({
16523
- cursor: external_exports.string().min(1).max(CASE_PAGE_CURSOR_MAX_LENGTH).optional()
16524
- }).strict();
16525
- }
16526
- });
16527
-
16528
- // ../../packages/core/dist/chunk-K3PD6AOF.js
16529
- var NEVER2;
16530
- var init_chunk_K3PD6AOF = __esm({
16531
- "../../packages/core/dist/chunk-K3PD6AOF.js"() {
16532
- "use strict";
16533
- init_chunk_MIWZOSPI();
16534
- NEVER2 = Number.POSITIVE_INFINITY;
16535
- }
16536
- });
16537
-
16538
- // ../../packages/core/dist/chunk-KVMROYDC.js
16539
- var caseTeamPreviewBody;
16540
- var init_chunk_KVMROYDC = __esm({
16541
- "../../packages/core/dist/chunk-KVMROYDC.js"() {
16542
- "use strict";
16543
- init_chunk_3T3D7LTE();
16544
- init_chunk_HZ6CADSY();
16545
- caseTeamPreviewBody = createCaseTeamBody.pick({ active: true, scopes: true, members: true }).extend({ team_id: uuidSchema.optional() }).strict();
16546
- }
16547
- });
16548
-
16549
- // ../../packages/core/dist/chunk-M2IF4G6X.js
16550
- var CASE_TIMELINE_PAGE_MAX, caseTimelineQuery;
16551
- var init_chunk_M2IF4G6X = __esm({
16552
- "../../packages/core/dist/chunk-M2IF4G6X.js"() {
16553
- "use strict";
16554
- init_chunk_3T3D7LTE();
16555
- init_zod();
16556
- CASE_TIMELINE_PAGE_MAX = 100;
16557
- caseTimelineQuery = external_exports.object({
16558
- limit: external_exports.coerce.number().int().min(1).max(CASE_TIMELINE_PAGE_MAX).optional(),
16559
- /** An entry's `id`: the page after it (the header's IDS AND THE OPAQUE CURSOR). */
16560
- after: external_exports.string().min(1).max(CASE_PAGE_CURSOR_MAX_LENGTH).optional()
16561
- });
16562
- }
16563
- });
16564
-
16565
- // ../../packages/core/dist/chunk-NNC2ZECG.js
16566
- var caseVerifyQuery;
16567
- var init_chunk_NNC2ZECG = __esm({
16568
- "../../packages/core/dist/chunk-NNC2ZECG.js"() {
16569
- "use strict";
16570
- init_chunk_5Y2NNQHX();
16571
- init_zod();
16572
- caseVerifyQuery = external_exports.object({ id: external_exports.string().regex(CASE_SUBMISSION_MARK_ID_PATTERN) }).strict();
16573
- }
16574
- });
16575
-
16576
- // ../../packages/core/dist/chunk-UOPCLXCU.js
16577
- var CASE_CHANGE_TOPICS, caseChangedFrameSchema;
16578
- var init_chunk_UOPCLXCU = __esm({
16579
- "../../packages/core/dist/chunk-UOPCLXCU.js"() {
16580
- "use strict";
16581
- init_chunk_733K4J4G();
16582
- init_chunk_HZ6CADSY();
16583
- init_zod();
16584
- CASE_CHANGE_TOPICS = ["submission", "agenda", "access"];
16585
- caseChangedFrameSchema = external_exports.object({
16586
- org_id: uuidSchema,
16587
- space_id: uuidSchema,
16588
- /** The case, by its code; null for an `access` change, which names none. */
16589
- code: caseRecordParam.shape.code.nullable(),
16590
- topic: external_exports.enum(CASE_CHANGE_TOPICS)
16628
+ review_mode: external_exports.enum(CASE_REVIEW_MODES).default("conduct"),
16629
+ /** The team that signs off, in `team` mode and only there. */
16630
+ review_team_id: uuidSchema.nullable().default(null),
16631
+ case_inputs_allowed: external_exports.boolean().default(false),
16632
+ phase_outputs: external_exports.array(casePhaseOutputSchema).max(30).default([]),
16633
+ phase_inputs: external_exports.array(casePhaseInputSchema).max(50).default([]),
16634
+ type_tasks: external_exports.array(caseTypeTaskSchema).max(100).default([]),
16635
+ agenda_groups: external_exports.array(caseAgendaGroupSchema).max(20).default([])
16591
16636
  }).strict();
16592
- }
16593
- });
16594
-
16595
- // ../../packages/core/dist/chunk-7CZSLDOE.js
16596
- var CASE_MEMBER_CASES_PAGE_MAX, caseMemberReachQuery;
16597
- var init_chunk_7CZSLDOE = __esm({
16598
- "../../packages/core/dist/chunk-7CZSLDOE.js"() {
16599
- "use strict";
16600
- init_chunk_3T3D7LTE();
16601
- init_zod();
16602
- CASE_MEMBER_CASES_PAGE_MAX = 50;
16603
- caseMemberReachQuery = casePageQuery.extend({
16604
- limit: external_exports.coerce.number().int().min(1).max(CASE_MEMBER_CASES_PAGE_MAX).optional()
16637
+ caseTypeDefinitionShape = external_exports.object({
16638
+ type_party_roles: external_exports.array(caseTypePartyRoleSchema).max(50).default([]),
16639
+ type_outcomes: external_exports.array(caseTypeOutcomeSchema).max(50).default([]),
16640
+ type_phases: external_exports.array(caseTypePhaseSchema).min(1).max(50),
16641
+ /** The JSON Schema of its cases' `attributes`: their custom fields. Absent, none. */
16642
+ attributes: caseAttributesSchemaSchema.default(() => ({ ...EMPTY_CASE_ATTRIBUTES_SCHEMA }))
16605
16643
  }).strict();
16606
- }
16607
- });
16608
-
16609
- // ../../packages/core/dist/chunk-E7JRMKV5.js
16610
- var CASE_STYLE_KINDS, caseStyleParam, CASE_STYLE_VERSIONS_PAGE_MAX, caseStyleVersionsQuery, caseStyleContentQuery, CASE_STYLE_UPLOAD_BODY_MAX_BYTES, CASE_STYLE_FILE_FIELD, CASE_STYLE_EXPECT_FIELD, caseStyleUploadForm;
16611
- var init_chunk_E7JRMKV5 = __esm({
16612
- "../../packages/core/dist/chunk-E7JRMKV5.js"() {
16613
- "use strict";
16614
- init_chunk_U7GWWTPM();
16615
- init_chunk_3T3D7LTE();
16616
- init_chunk_HZ6CADSY();
16617
- init_zod();
16618
- CASE_STYLE_KINDS = ["pdf_stylesheet", "word_reference"];
16619
- caseStyleParam = caseSpaceParam.extend({ kind: external_exports.enum(CASE_STYLE_KINDS) });
16620
- CASE_STYLE_VERSIONS_PAGE_MAX = 100;
16621
- caseStyleVersionsQuery = casePageQuery.extend({
16622
- limit: external_exports.coerce.number().int().min(1).max(CASE_STYLE_VERSIONS_PAGE_MAX).optional()
16644
+ caseValuesRepeated = (values) => new Set(values).size !== values.length;
16645
+ CHAPTER_PROBE = "00-chapter.md";
16646
+ caseTypeDefinitionSchema = caseTypeDefinitionShape.superRefine((definition, ctx) => {
16647
+ const found = caseTypeDefinitionProblem(definition);
16648
+ if (found) {
16649
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: found.reason, path: found.at.split("."), params: { case_type_reason: found.reason } });
16650
+ }
16623
16651
  });
16624
- caseStyleContentQuery = external_exports.object({ version_id: uuidSchema.optional() });
16625
- CASE_STYLE_UPLOAD_BODY_MAX_BYTES = 20 * 1024 * 1024;
16626
- CASE_STYLE_FILE_FIELD = "file";
16627
- CASE_STYLE_EXPECT_FIELD = "expect_version_id";
16628
- caseStyleUploadForm = external_exports.object({
16629
- [CASE_STYLE_FILE_FIELD]: external_exports.custom(isBlob, "The file is required"),
16630
- /** Empty: the uploader read no current version. */
16631
- [CASE_STYLE_EXPECT_FIELD]: external_exports.union([uuidSchema, external_exports.literal("")]).transform((value) => value || null)
16652
+ caseTypeAbbreviationSchema = external_exports.string().trim().transform((value) => value.toUpperCase()).pipe(external_exports.string().regex(CASE_TYPE_ABBREVIATION_PATTERN));
16653
+ caseTypeNameSchema = external_exports.string().trim().min(1).max(CASE_TYPE_NAME_MAX_LENGTH);
16654
+ createCaseTypeBody = external_exports.object({
16655
+ abbreviation: caseTypeAbbreviationSchema,
16656
+ name: caseTypeNameSchema,
16657
+ definition: caseTypeDefinitionSchema
16658
+ }).strict();
16659
+ publishCaseTypeVersionBody = external_exports.object({
16660
+ expected_version: external_exports.number().int().min(1).max(CASE_TYPE_VERSIONS_MAX),
16661
+ name: caseTypeNameSchema,
16662
+ definition: caseTypeDefinitionSchema
16663
+ }).strict();
16664
+ setCaseTypeActiveBody = external_exports.object({ active: external_exports.boolean() }).strict();
16665
+ caseTypeParam = caseSpaceParam.extend({ type_id: uuidSchema });
16666
+ caseTypesPageQuery = casePageQuery.extend({
16667
+ limit: external_exports.coerce.number().int().min(1).max(CASE_TYPES_PAGE_MAX).optional()
16668
+ });
16669
+ caseTypeVersionQuery = external_exports.object({
16670
+ version: external_exports.coerce.number().int().min(1).max(CASE_TYPE_VERSIONS_MAX).optional()
16632
16671
  });
16633
16672
  }
16634
16673
  });
16635
16674
 
16636
- // ../../packages/core/dist/chunk-3LMWOJQX.js
16637
- function withProblem(shape, problemOf) {
16638
- return shape.superRefine((value, ctx) => {
16639
- const found = problemOf(value);
16640
- if (found) {
16641
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: found.reason, path: found.at.split("."), params: { case_registry_reason: found.reason } });
16642
- }
16643
- });
16644
- }
16645
- function caseRegistryTypeProblem(type) {
16646
- const found = caseAttributesSchemaProblem(type.attributes);
16647
- if (found) return { reason: found.reason, at: `attributes.${found.at}` };
16648
- if (JSON.stringify(type.attributes).length > CASE_REGISTRY_TYPE_SCHEMA_MAX_CHARS) return { reason: "attributes_schema_too_large", at: "attributes" };
16649
- return null;
16650
- }
16651
- function casePartyProblem(party) {
16652
- if (party.document_kind === null !== (party.document_number === null)) return { reason: "document_incomplete", at: "document_number" };
16653
- if (party.document_kind === "cpf" || party.document_kind === "cnpj") {
16654
- if (party.person_kind !== (party.document_kind === "cpf" ? "natural" : "legal")) return { reason: "document_person_mismatch", at: "document_kind" };
16655
- if (!(party.document_kind === "cpf" ? /^[0-9]{11}$/ : /^[0-9]{14}$/).test(party.document_number ?? "")) {
16656
- return { reason: "document_digits", at: "document_number" };
16657
- }
16675
+ // ../../packages/core/dist/chunk-733K4J4G.js
16676
+ function openCaseProblem(body) {
16677
+ const pairs = /* @__PURE__ */ new Set();
16678
+ for (const [index, party] of body.parties.entries()) {
16679
+ const key = `${party.party_id}
16680
+ ${party.role}`;
16681
+ if (pairs.has(key)) return { reason: "party_role_repeated", at: `parties.${index}` };
16682
+ pairs.add(key);
16658
16683
  }
16684
+ if (new Set(body.instrument_ids).size !== body.instrument_ids.length) return { reason: "instrument_repeated", at: "instrument_ids" };
16659
16685
  return null;
16660
16686
  }
16661
- function casePartyGroupProblem(group) {
16662
- return new Set(group.party_ids).size === group.party_ids.length ? null : { reason: "party_repeated", at: "party_ids" };
16663
- }
16664
- function caseInstrumentProblem(instrument) {
16665
- if (instrument.effective_from !== null && instrument.effective_until !== null && instrument.effective_until < instrument.effective_from) {
16666
- return { reason: "effective_dates_reversed", at: "effective_until" };
16667
- }
16668
- const keys = instrument.parties.map((party) => `${party.party_id}
16669
- ${party.role}`);
16670
- return new Set(keys).size === keys.length ? null : { reason: "instrument_party_repeated", at: "parties" };
16671
- }
16672
- var CASE_REGISTRY_TYPE_CODE_PATTERN, CASE_REGISTRY_TYPE_CODE_MAX_LENGTH, CASE_REGISTRY_NAME_MAX_LENGTH, CASE_REGISTRY_TYPE_SCHEMA_MAX_CHARS, CASE_PARTY_ABBREVIATION_PATTERN, CASE_PARTY_PERSON_KINDS, CASE_PARTY_DOCUMENT_KINDS, CASE_PARTY_DOCUMENT_MAX_LENGTH, CASE_PARTY_GROUP_MEMBERS_MAX, CASE_INSTRUMENT_NUMBER_MAX_LENGTH, CASE_INSTRUMENT_ROLE_MAX_LENGTH, CASE_INSTRUMENT_PARTIES_MAX, CASE_REGISTRY_PAGE_MAX, CASE_REGISTRY_QUERY_MAX_LENGTH, trimmedName, dateSchema, attributesValues, registryTypeFields, createCaseRegistryTypeShape, updateCaseRegistryTypeShape, createCaseRegistryTypeBody, updateCaseRegistryTypeBody, saveCasePartyShape, saveCasePartyBody, saveCasePartyGroupShape, saveCasePartyGroupBody, caseInstrumentPartyInput, saveCaseInstrumentShape, saveCaseInstrumentBody, registryPage, searchText, casePartiesQuery, casePartyGroupsQuery, caseInstrumentsQuery, caseRegistryTypeParam, casePartyParam, casePartyGroupParam, caseInstrumentParam;
16673
- var init_chunk_3LMWOJQX = __esm({
16674
- "../../packages/core/dist/chunk-3LMWOJQX.js"() {
16687
+ var CASE_RECORD_CODE_PATTERN, CASE_RECORD_CODE_MAX_LENGTH, CASE_RECORD_PARTIES_MAX, CASE_RECORD_INSTRUMENTS_MAX, CASE_RECORD_ROLE_MAX_LENGTH, CASE_RECORDS_PAGE_MAX, CASE_RECORDS_QUERY_MAX_LENGTH, caseRecordPartySchema, openCaseShape, openCaseBody, previewOpenCaseShape, caseRecordParam, CASE_RECORD_STATUSES, caseRecordsQuery, CASE_STATE_SUMMARIES_MAX, caseStatesQuery, CASE_CLOSURE_REASON_MAX_LENGTH, closeCaseBody, setCaseConfidentialityBody;
16688
+ var init_chunk_733K4J4G = __esm({
16689
+ "../../packages/core/dist/chunk-733K4J4G.js"() {
16675
16690
  "use strict";
16691
+ init_chunk_PFPADFUC();
16676
16692
  init_chunk_3T3D7LTE();
16677
- init_chunk_M2T55BV6();
16678
16693
  init_chunk_HZ6CADSY();
16694
+ init_chunk_ZTNFLGW5();
16679
16695
  init_zod();
16680
- CASE_REGISTRY_TYPE_CODE_PATTERN = /^[a-z0-9]+(_[a-z0-9]+)*$/;
16681
- CASE_REGISTRY_TYPE_CODE_MAX_LENGTH = 64;
16682
- CASE_REGISTRY_NAME_MAX_LENGTH = 200;
16683
- CASE_REGISTRY_TYPE_SCHEMA_MAX_CHARS = 64 * 1024;
16684
- CASE_PARTY_ABBREVIATION_PATTERN = /^[A-Z0-9]{2,12}$/;
16685
- CASE_PARTY_PERSON_KINDS = ["natural", "legal"];
16686
- CASE_PARTY_DOCUMENT_KINDS = ["cpf", "cnpj", "other"];
16687
- CASE_PARTY_DOCUMENT_MAX_LENGTH = 64;
16688
- CASE_PARTY_GROUP_MEMBERS_MAX = 2e3;
16689
- CASE_INSTRUMENT_NUMBER_MAX_LENGTH = 200;
16690
- CASE_INSTRUMENT_ROLE_MAX_LENGTH = 200;
16691
- CASE_INSTRUMENT_PARTIES_MAX = 50;
16692
- CASE_REGISTRY_PAGE_MAX = 100;
16693
- CASE_REGISTRY_QUERY_MAX_LENGTH = 200;
16694
- trimmedName = external_exports.string().trim().min(1).max(CASE_REGISTRY_NAME_MAX_LENGTH);
16695
- dateSchema = caseDateSchema;
16696
- attributesValues = external_exports.record(external_exports.string(), external_exports.unknown()).default({});
16697
- registryTypeFields = {
16698
- name: trimmedName,
16699
- attributes: caseAttributesSchemaSchema.default(EMPTY_CASE_ATTRIBUTES_SCHEMA),
16700
- active: external_exports.boolean().default(true)
16701
- };
16702
- createCaseRegistryTypeShape = external_exports.object({
16703
- code: external_exports.string().trim().max(CASE_REGISTRY_TYPE_CODE_MAX_LENGTH).regex(CASE_REGISTRY_TYPE_CODE_PATTERN),
16704
- ...registryTypeFields
16705
- }).strict();
16706
- updateCaseRegistryTypeShape = external_exports.object({
16707
- ...registryTypeFields,
16708
- expected_updated_at: timestampSchema.optional()
16709
- }).strict();
16710
- createCaseRegistryTypeBody = withProblem(createCaseRegistryTypeShape, caseRegistryTypeProblem);
16711
- updateCaseRegistryTypeBody = withProblem(updateCaseRegistryTypeShape, caseRegistryTypeProblem);
16712
- saveCasePartyShape = external_exports.object({
16713
- type_id: uuidSchema,
16714
- name: trimmedName,
16715
- abbreviation: external_exports.string().trim().transform((value) => value.toUpperCase()).pipe(external_exports.string().regex(CASE_PARTY_ABBREVIATION_PATTERN)).nullable().default(null),
16716
- person_kind: external_exports.enum(CASE_PARTY_PERSON_KINDS),
16717
- document_kind: external_exports.enum(CASE_PARTY_DOCUMENT_KINDS).nullable().default(null),
16718
- document_number: external_exports.string().trim().min(1).max(CASE_PARTY_DOCUMENT_MAX_LENGTH).nullable().default(null),
16719
- attributes: attributesValues,
16720
- active: external_exports.boolean().default(true),
16721
- expected_updated_at: timestampSchema.optional()
16722
- }).strict();
16723
- saveCasePartyBody = withProblem(saveCasePartyShape, casePartyProblem);
16724
- saveCasePartyGroupShape = external_exports.object({
16725
- name: trimmedName,
16726
- party_ids: external_exports.array(uuidSchema).max(CASE_PARTY_GROUP_MEMBERS_MAX).default([]),
16727
- expected_updated_at: timestampSchema.optional()
16728
- }).strict();
16729
- saveCasePartyGroupBody = withProblem(saveCasePartyGroupShape, casePartyGroupProblem);
16730
- caseInstrumentPartyInput = external_exports.object({
16696
+ CASE_RECORD_CODE_PATTERN = new RegExp(`^${CASE_TYPE_ABBREVIATION_PATTERN.source.slice(1, -1)}-[0-9]{4}-[0-9]{4,}$`);
16697
+ CASE_RECORD_CODE_MAX_LENGTH = 32;
16698
+ CASE_RECORD_PARTIES_MAX = 50;
16699
+ CASE_RECORD_INSTRUMENTS_MAX = 50;
16700
+ CASE_RECORD_ROLE_MAX_LENGTH = 64;
16701
+ CASE_RECORDS_PAGE_MAX = 100;
16702
+ CASE_RECORDS_QUERY_MAX_LENGTH = 32;
16703
+ caseRecordPartySchema = external_exports.object({
16731
16704
  party_id: uuidSchema,
16732
- role: external_exports.string().trim().min(1).max(CASE_INSTRUMENT_ROLE_MAX_LENGTH)
16705
+ role: external_exports.string().min(1).max(CASE_RECORD_ROLE_MAX_LENGTH)
16733
16706
  }).strict();
16734
- saveCaseInstrumentShape = external_exports.object({
16707
+ openCaseShape = external_exports.object({
16735
16708
  type_id: uuidSchema,
16736
- number: external_exports.string().trim().min(1).max(CASE_INSTRUMENT_NUMBER_MAX_LENGTH),
16737
- signed_on: dateSchema.nullable().default(null),
16738
- effective_from: dateSchema.nullable().default(null),
16739
- effective_until: dateSchema.nullable().default(null),
16740
- attributes: attributesValues,
16741
- /** Each party in a role; one party may hold several roles. */
16742
- parties: external_exports.array(caseInstrumentPartyInput).max(CASE_INSTRUMENT_PARTIES_MAX).default([]),
16743
- expected_updated_at: timestampSchema.optional()
16709
+ /** The year in its code: within a year of today's year in the space's time zone. */
16710
+ year: external_exports.number().int().min(2e3).max(2100),
16711
+ parties: external_exports.array(caseRecordPartySchema).max(CASE_RECORD_PARTIES_MAX).default([]),
16712
+ instrument_ids: external_exports.array(uuidSchema).max(CASE_RECORD_INSTRUMENTS_MAX).default([]),
16713
+ /** The custom field values, checked against the version's schema in the space. */
16714
+ attributes: external_exports.record(external_exports.string(), external_exports.unknown()).default({}),
16715
+ confidential: external_exports.boolean().default(false),
16716
+ /** The code the opener was shown: another case holding it opens nothing. */
16717
+ expected_code: external_exports.string().max(CASE_RECORD_CODE_MAX_LENGTH).regex(CASE_RECORD_CODE_PATTERN).optional()
16744
16718
  }).strict();
16745
- saveCaseInstrumentBody = withProblem(saveCaseInstrumentShape, caseInstrumentProblem);
16746
- registryPage = casePageQuery.extend({
16747
- limit: external_exports.coerce.number().int().min(1).max(CASE_REGISTRY_PAGE_MAX).optional()
16719
+ openCaseBody = openCaseShape.superRefine((body, ctx) => {
16720
+ const found = openCaseProblem(body);
16721
+ if (found) {
16722
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: found.reason, path: found.at.split("."), params: { case_record_reason: found.reason } });
16723
+ }
16748
16724
  });
16749
- searchText = external_exports.string().trim().min(1).max(CASE_REGISTRY_QUERY_MAX_LENGTH).optional();
16750
- casePartiesQuery = registryPage.extend({
16751
- q: searchText,
16752
- type_id: uuidSchema.optional(),
16753
- active: external_exports.enum(["true", "false"]).transform((value) => value === "true").optional()
16725
+ previewOpenCaseShape = openCaseShape.pick({ type_id: true, year: true, parties: true, instrument_ids: true, confidential: true }).strict();
16726
+ caseRecordParam = caseSpaceParam.extend({
16727
+ code: external_exports.string().max(CASE_RECORD_CODE_MAX_LENGTH).regex(CASE_RECORD_CODE_PATTERN)
16754
16728
  });
16755
- casePartyGroupsQuery = registryPage.extend({ q: searchText });
16756
- caseInstrumentsQuery = registryPage.extend({
16757
- q: searchText,
16729
+ CASE_RECORD_STATUSES = ["open", "closed"];
16730
+ caseRecordsQuery = casePageQuery.extend({
16731
+ limit: external_exports.coerce.number().int().min(1).max(CASE_RECORDS_PAGE_MAX).optional(),
16758
16732
  type_id: uuidSchema.optional(),
16759
- party_id: uuidSchema.optional()
16760
- });
16761
- caseRegistryTypeParam = caseSpaceParam.extend({ type_id: uuidSchema });
16762
- casePartyParam = caseSpaceParam.extend({ party_id: uuidSchema });
16763
- casePartyGroupParam = caseSpaceParam.extend({ group_id: uuidSchema });
16764
- caseInstrumentParam = caseSpaceParam.extend({ instrument_id: uuidSchema });
16765
- }
16766
- });
16767
-
16768
- // ../../packages/core/dist/chunk-53B7O5LO.js
16769
- function collectionUploadForm(field, shape) {
16770
- return external_exports.record(external_exports.string(), external_exports.unknown()).transform((form2, ctx) => {
16771
- const refuse2 = (message, path46) => {
16772
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message, path: [path46] });
16773
- return external_exports.NEVER;
16774
- };
16775
- const text5 = form2[field];
16776
- if (typeof text5 !== "string") return refuse2(`The field ${field} is required`, field);
16777
- let body;
16778
- try {
16779
- body = JSON.parse(text5);
16780
- } catch {
16781
- return refuse2(`The field ${field} is not JSON`, field);
16782
- }
16783
- const parsed = shape.safeParse(body);
16784
- if (!parsed.success) return refuse2(parsed.error.issues[0]?.message ?? `The field ${field} is not of its shape`, field);
16785
- const parts = [];
16786
- for (const [name, value] of Object.entries(form2)) {
16787
- if (name === field) continue;
16788
- if (!isCaseCollectionPart(name) || !isBlob(value)) {
16789
- return refuse2("A part is the file, its Word copy or its text, sent once", name);
16790
- }
16791
- const sentName = value.name;
16792
- parts.push({ part: name, bytes: value, name: typeof sentName === "string" ? sentName : "" });
16793
- }
16794
- if (!parts.some((part) => part.part === "file")) return refuse2("The file is required", "file");
16795
- return { body, fields: parsed.data, parts };
16796
- });
16797
- }
16798
- var CASE_COLLECTION_FOLDERS, CASE_COLLECTION_PARTS, isCaseCollectionPart, CASE_COLLECTION_TITLE_MAX_LENGTH, CASE_COLLECTION_TYPE_MAX_LENGTH, CASE_COLLECTION_REASON_MAX_LENGTH, caseCollectionDocumentParam, dateOnly, title, registerCaseCollectionDocumentShape, addCaseCollectionVersionShape, CASE_COLLECTION_UPLOAD_BODY_MAX_BYTES, CASE_COLLECTION_DOCUMENT_FIELD, CASE_COLLECTION_VERSION_FIELD, caseCollectionDocumentUploadForm, caseCollectionVersionUploadForm, CASE_COLLECTION_PAGE_MAX, CASE_COLLECTION_CURSOR_MAX_LENGTH, caseCollectionQuery, CASE_COLLECTION_VERSIONS_PAGE_MAX, caseCollectionVersionsQuery, caseCollectionContentQuery;
16799
- var init_chunk_53B7O5LO = __esm({
16800
- "../../packages/core/dist/chunk-53B7O5LO.js"() {
16801
- "use strict";
16802
- init_chunk_E7JRMKV5();
16803
- init_chunk_3LMWOJQX();
16804
- init_chunk_U7GWWTPM();
16805
- init_chunk_3T3D7LTE();
16806
- init_chunk_M2T55BV6();
16807
- init_chunk_HZ6CADSY();
16808
- init_zod();
16809
- CASE_COLLECTION_FOLDERS = ["norms", "internal_norms", "instruments", "data"];
16810
- CASE_COLLECTION_PARTS = ["file", "word", "text"];
16811
- isCaseCollectionPart = (part) => CASE_COLLECTION_PARTS.includes(part);
16812
- CASE_COLLECTION_TITLE_MAX_LENGTH = 300;
16813
- CASE_COLLECTION_TYPE_MAX_LENGTH = 100;
16814
- CASE_COLLECTION_REASON_MAX_LENGTH = 2e3;
16815
- caseCollectionDocumentParam = caseSpaceParam.extend({ document_id: uuidSchema });
16816
- dateOnly = caseDateSchema;
16817
- title = external_exports.string().trim().min(1).max(CASE_COLLECTION_TITLE_MAX_LENGTH);
16818
- registerCaseCollectionDocumentShape = external_exports.object({
16819
- title,
16820
- folder: external_exports.enum(CASE_COLLECTION_FOLDERS),
16821
- type: external_exports.string().trim().min(1).max(CASE_COLLECTION_TYPE_MAX_LENGTH),
16822
- party_id: uuidSchema.nullable().default(null),
16823
- instrument_id: uuidSchema.nullable().default(null),
16824
- group_id: uuidSchema.nullable().default(null),
16825
- confidential: external_exports.boolean().default(false),
16826
- effective_from: dateOnly.nullable().default(null)
16827
- }).strict();
16828
- addCaseCollectionVersionShape = external_exports.object({
16829
- /** The version its writer read as current. */
16830
- expect_version_id: uuidSchema,
16831
- reason: external_exports.string().trim().min(1).max(CASE_COLLECTION_REASON_MAX_LENGTH),
16832
- /** Null keeps the current version's title. */
16833
- title: title.nullable().default(null),
16834
- effective_from: dateOnly.nullable().default(null)
16835
- }).strict();
16836
- CASE_COLLECTION_UPLOAD_BODY_MAX_BYTES = 20 * 1024 * 1024;
16837
- CASE_COLLECTION_DOCUMENT_FIELD = "document";
16838
- CASE_COLLECTION_VERSION_FIELD = "version";
16839
- caseCollectionDocumentUploadForm = collectionUploadForm(CASE_COLLECTION_DOCUMENT_FIELD, registerCaseCollectionDocumentShape);
16840
- caseCollectionVersionUploadForm = collectionUploadForm(CASE_COLLECTION_VERSION_FIELD, addCaseCollectionVersionShape);
16841
- CASE_COLLECTION_PAGE_MAX = 100;
16842
- CASE_COLLECTION_CURSOR_MAX_LENGTH = Math.ceil((2 * CASE_COLLECTION_TITLE_MAX_LENGTH * 6 + 36 + 7) / 3) * 4;
16843
- caseCollectionQuery = casePageQuery.extend({
16844
- limit: external_exports.coerce.number().int().min(1).max(CASE_COLLECTION_PAGE_MAX).optional(),
16845
- cursor: external_exports.string().min(1).max(CASE_COLLECTION_CURSOR_MAX_LENGTH).optional(),
16846
- q: external_exports.string().trim().min(1).max(CASE_REGISTRY_QUERY_MAX_LENGTH).optional(),
16847
- folder: external_exports.enum(CASE_COLLECTION_FOLDERS).optional(),
16848
- type: external_exports.string().trim().min(1).max(CASE_COLLECTION_TYPE_MAX_LENGTH).optional(),
16849
- group: uuidSchema.optional(),
16850
- party: uuidSchema.optional(),
16851
- instrument: uuidSchema.optional()
16852
- });
16853
- CASE_COLLECTION_VERSIONS_PAGE_MAX = 100;
16854
- caseCollectionVersionsQuery = casePageQuery.extend({
16855
- limit: external_exports.coerce.number().int().min(1).max(CASE_COLLECTION_VERSIONS_PAGE_MAX).optional()
16733
+ q: external_exports.string().trim().min(1).max(CASE_RECORDS_QUERY_MAX_LENGTH).optional(),
16734
+ search: external_exports.string().trim().min(1).max(CASE_RECORDS_QUERY_MAX_LENGTH).optional(),
16735
+ group_id: uuidSchema.optional(),
16736
+ status: external_exports.enum(CASE_RECORD_STATUSES).optional()
16856
16737
  });
16857
- caseCollectionContentQuery = external_exports.object({
16858
- part: external_exports.enum(CASE_COLLECTION_PARTS).default("file"),
16859
- version_id: uuidSchema.optional()
16738
+ CASE_STATE_SUMMARIES_MAX = CASE_RECORDS_PAGE_MAX;
16739
+ caseStatesQuery = external_exports.object({
16740
+ codes: external_exports.string().max(CASE_STATE_SUMMARIES_MAX * (CASE_RECORD_CODE_MAX_LENGTH + 1)).transform((codes) => codes.split(",")).pipe(external_exports.array(external_exports.string().max(CASE_RECORD_CODE_MAX_LENGTH).regex(CASE_RECORD_CODE_PATTERN)).min(1).max(CASE_STATE_SUMMARIES_MAX))
16860
16741
  });
16742
+ CASE_CLOSURE_REASON_MAX_LENGTH = 2e3;
16743
+ closeCaseBody = external_exports.object({
16744
+ outcome_code: external_exports.string().max(CASE_CODE_MAX_LENGTH).regex(CASE_CODE_PATTERN),
16745
+ reason: external_exports.string().trim().min(1).max(CASE_CLOSURE_REASON_MAX_LENGTH)
16746
+ }).strict();
16747
+ setCaseConfidentialityBody = external_exports.object({ confidential: external_exports.boolean() }).strict();
16861
16748
  }
16862
16749
  });
16863
16750
 
16864
- // ../../packages/core/dist/chunk-TECYEMQ2.js
16751
+ // ../../packages/core/dist/chunk-ZB7W3DKK.js
16865
16752
  var CASE_RECEIVED_PARTS, CASE_RECEIVED_TITLE_MAX_LENGTH, CASE_RECEIVED_TYPE_MAX_LENGTH, CASE_RECEIVED_TEXT_MAX_BYTES, CASE_RECEIVED_UPLOAD_BODY_MAX_BYTES, CASE_RECEIVED_DOCUMENT_FIELD, caseReceivedParam, registerCaseReceivedDocumentShape, caseReceivedUploadForm, ZIP_DIRECTORY_MAX_BYTES, CONTENT_TYPES_MAX_BYTES, CONTENT_TYPES_INFLATED_MAX_BYTES, CASE_RECEIVED_PAGE_MAX, caseReceivedQuery, caseReceivedContentQuery;
16866
- var init_chunk_TECYEMQ2 = __esm({
16867
- "../../packages/core/dist/chunk-TECYEMQ2.js"() {
16753
+ var init_chunk_ZB7W3DKK = __esm({
16754
+ "../../packages/core/dist/chunk-ZB7W3DKK.js"() {
16868
16755
  "use strict";
16869
- init_chunk_53B7O5LO();
16870
- init_chunk_E7JRMKV5();
16871
- init_chunk_U7GWWTPM();
16756
+ init_chunk_PMBOHJKA();
16757
+ init_chunk_U3X3BIQH();
16758
+ init_chunk_VROZDNLV();
16872
16759
  init_chunk_733K4J4G();
16873
16760
  init_chunk_3T3D7LTE();
16874
16761
  init_chunk_HZ6CADSY();
@@ -16927,150 +16814,97 @@ var init_chunk_TECYEMQ2 = __esm({
16927
16814
  }
16928
16815
  });
16929
16816
 
16930
- // ../../packages/core/dist/chunk-7TQYAKCB.js
16931
- function addCaseNoteProblem(note) {
16932
- return note.origin !== null && note.kind !== "contribution" ? { reason: "origin_not_contribution", at: "origin" } : null;
16933
- }
16934
- var CASE_NOTE_KINDS, CASE_NOTE_TEXT_MAX_LENGTH, CASE_NOTE_ORIGIN_MAX_LENGTH, CASE_NOTES_PAGE_MAX, addCaseNoteShape, addCaseNoteBody, caseNoteParam, caseTaskParam, caseNotesQuery;
16935
- var init_chunk_7TQYAKCB = __esm({
16936
- "../../packages/core/dist/chunk-7TQYAKCB.js"() {
16817
+ // ../../packages/core/dist/chunk-2YVCHUBL.js
16818
+ var CASE_OFFICIAL_FILE_KINDS, CASE_OFFICIAL_FILE_NAME_PATTERN, publishCaseSubmissionBody, caseOfficialVersionParam, caseOfficialFileQuery;
16819
+ var init_chunk_2YVCHUBL = __esm({
16820
+ "../../packages/core/dist/chunk-2YVCHUBL.js"() {
16937
16821
  "use strict";
16822
+ init_chunk_5Y2NNQHX();
16823
+ init_chunk_VROZDNLV();
16938
16824
  init_chunk_733K4J4G();
16939
- init_chunk_3T3D7LTE();
16940
16825
  init_chunk_HZ6CADSY();
16941
16826
  init_zod();
16942
- CASE_NOTE_KINDS = ["observation", "next_step", "pending", "contribution"];
16943
- CASE_NOTE_TEXT_MAX_LENGTH = 64 * 1024;
16944
- CASE_NOTE_ORIGIN_MAX_LENGTH = 200;
16945
- CASE_NOTES_PAGE_MAX = 100;
16946
- addCaseNoteShape = external_exports.object({
16947
- kind: external_exports.enum(CASE_NOTE_KINDS),
16948
- text: external_exports.string().trim().min(1).max(CASE_NOTE_TEXT_MAX_LENGTH),
16949
- /** A contribution's external author. */
16950
- origin: external_exports.string().trim().min(1).max(CASE_NOTE_ORIGIN_MAX_LENGTH).nullable().default(null),
16951
- /** A phase of the case (its version's phase id). */
16952
- phase_id: uuidSchema.nullable().default(null),
16953
- /** A task of the case, whose phase the note takes. */
16954
- case_task_id: uuidSchema.nullable().default(null)
16827
+ CASE_OFFICIAL_FILE_KINDS = [...CASE_SUBMISSION_ISSUED_KINDS, "file"];
16828
+ CASE_OFFICIAL_FILE_NAME_PATTERN = /^[^/\\\u0000-\u001f]{1,255}$/;
16829
+ publishCaseSubmissionBody = external_exports.object({
16830
+ /** The final digest its publisher saw (`CaseDelivery.final_digest`). */
16831
+ digest: caseFileShaSchema
16955
16832
  }).strict();
16956
- addCaseNoteBody = addCaseNoteShape.superRefine((note, ctx) => {
16957
- const found = addCaseNoteProblem(note);
16958
- if (found) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: found.reason, path: [found.at], params: { case_note_reason: found.reason } });
16959
- });
16960
- caseNoteParam = caseRecordParam.extend({ note_id: uuidSchema });
16961
- caseTaskParam = caseRecordParam.extend({ case_task_id: uuidSchema });
16962
- caseNotesQuery = casePageQuery.extend({
16963
- limit: external_exports.coerce.number().int().min(1).max(CASE_NOTES_PAGE_MAX).optional()
16964
- });
16833
+ caseOfficialVersionParam = caseRecordParam.extend({ official_version_id: uuidSchema });
16834
+ caseOfficialFileQuery = external_exports.object({ name: external_exports.string().regex(CASE_OFFICIAL_FILE_NAME_PATTERN) }).strict();
16965
16835
  }
16966
16836
  });
16967
16837
 
16968
- // ../../packages/core/dist/chunk-NQGO3NQ2.js
16969
- var CASE_COMMENT_TEXT_MAX_LENGTH, CASE_COMMENTS_PAGE_MAX, CASE_COMMENT_LINE_MAX, casePassageLineSchema, lineNumber, addCaseCommentShape, CASE_COMMENT_REVERSED_REASON, addCaseCommentBody, caseCommentsQuery;
16970
- var init_chunk_NQGO3NQ2 = __esm({
16971
- "../../packages/core/dist/chunk-NQGO3NQ2.js"() {
16838
+ // ../../packages/core/dist/chunk-BT77VXJU.js
16839
+ var casePhaseParam;
16840
+ var init_chunk_BT77VXJU = __esm({
16841
+ "../../packages/core/dist/chunk-BT77VXJU.js"() {
16972
16842
  "use strict";
16973
- init_chunk_7TQYAKCB();
16974
- init_chunk_U7GWWTPM();
16975
- init_chunk_3T3D7LTE();
16843
+ init_chunk_733K4J4G();
16976
16844
  init_chunk_HZ6CADSY();
16977
- init_zod();
16978
- CASE_COMMENT_TEXT_MAX_LENGTH = CASE_NOTE_TEXT_MAX_LENGTH;
16979
- CASE_COMMENTS_PAGE_MAX = 100;
16980
- CASE_COMMENT_LINE_MAX = CASE_FILE_COMPARE_MAX_BYTES;
16981
- casePassageLineSchema = external_exports.number().int().min(1).max(CASE_COMMENT_LINE_MAX);
16982
- lineNumber = casePassageLineSchema;
16983
- addCaseCommentShape = external_exports.object({
16984
- path: caseFileReadPath,
16985
- /** The version: the revision that wrote it to `path`. */
16986
- revision_id: uuidSchema,
16987
- /** The passage's first and last lines, from 1, of the version's text ({@link casePassageLines}). */
16988
- line_start: lineNumber,
16989
- line_end: lineNumber,
16990
- text: external_exports.string().trim().min(1).max(CASE_COMMENT_TEXT_MAX_LENGTH),
16991
- /** Hidden from every reader without the Confidential right; only a holder of it may set it. */
16992
- confidential: external_exports.boolean().default(false)
16993
- }).strict();
16994
- CASE_COMMENT_REVERSED_REASON = "passage_reversed";
16995
- addCaseCommentBody = addCaseCommentShape.superRefine((comment2, ctx) => {
16996
- if (comment2.line_end < comment2.line_start) {
16997
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: CASE_COMMENT_REVERSED_REASON, path: ["line_end"] });
16998
- }
16999
- });
17000
- caseCommentsQuery = casePageQuery.extend({
17001
- path: caseFileReadPath,
17002
- /** Absent: every version's comments on the path. */
17003
- revision_id: uuidSchema.optional(),
17004
- limit: external_exports.coerce.number().int().min(1).max(CASE_COMMENTS_PAGE_MAX).optional()
17005
- });
16845
+ casePhaseParam = caseRecordParam.extend({ phase_id: uuidSchema });
17006
16846
  }
17007
16847
  });
17008
16848
 
17009
- // ../../packages/core/dist/chunk-5PUYXYGT.js
17010
- var CASE_VERSION_DECISION_REASON_MAX_LENGTH, CASE_VERSION_DECISIONS, caseVersionDecisionReason, reason, lineNumber2, recordCaseReferenceBody, CASE_PASSAGE_REVERSED_REASON, citeCasePassageBody, decideCaseVersionBody;
17011
- var init_chunk_5PUYXYGT = __esm({
17012
- "../../packages/core/dist/chunk-5PUYXYGT.js"() {
16849
+ // ../../packages/core/dist/chunk-RHXF6X2Y.js
16850
+ var CASE_CHECK_CSV_MAX_BYTES, caseChecksQuery;
16851
+ var init_chunk_RHXF6X2Y = __esm({
16852
+ "../../packages/core/dist/chunk-RHXF6X2Y.js"() {
17013
16853
  "use strict";
17014
- init_chunk_NQGO3NQ2();
16854
+ init_chunk_5Y2NNQHX();
17015
16855
  init_chunk_HZ6CADSY();
17016
16856
  init_zod();
17017
- CASE_VERSION_DECISION_REASON_MAX_LENGTH = 2e3;
17018
- CASE_VERSION_DECISIONS = ["adopt", "keep"];
17019
- caseVersionDecisionReason = external_exports.string().trim().min(1).max(CASE_VERSION_DECISION_REASON_MAX_LENGTH);
17020
- reason = caseVersionDecisionReason;
17021
- lineNumber2 = casePassageLineSchema;
17022
- recordCaseReferenceBody = external_exports.object({
17023
- document_id: uuidSchema,
17024
- /** The document's version its writer read as current. */
17025
- version_id: uuidSchema
16857
+ CASE_CHECK_CSV_MAX_BYTES = 4 * 1024 * 1024;
16858
+ caseChecksQuery = external_exports.object({
16859
+ output_id: uuidSchema.optional()
17026
16860
  }).strict();
17027
- CASE_PASSAGE_REVERSED_REASON = CASE_COMMENT_REVERSED_REASON;
17028
- citeCasePassageBody = external_exports.object({
17029
- document_id: uuidSchema,
17030
- version_id: uuidSchema,
17031
- line_start: lineNumber2,
17032
- line_end: lineNumber2
17033
- }).strict().superRefine((body, ctx) => {
17034
- if (body.line_end < body.line_start) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: CASE_PASSAGE_REVERSED_REASON, path: ["line_end"] });
17035
- });
17036
- decideCaseVersionBody = external_exports.object({
17037
- decision: external_exports.enum(CASE_VERSION_DECISIONS),
17038
- /** The newer version its decider read as current. */
17039
- expect_version_id: uuidSchema,
17040
- reason: reason.nullable().default(null)
17041
- }).strict().superRefine((body, ctx) => {
17042
- if (body.decision === "keep" && body.reason === null) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: "A version kept needs its reason", path: ["reason"] });
17043
- });
17044
16861
  }
17045
16862
  });
17046
16863
 
17047
- // ../../packages/core/dist/chunk-NIYQBLMR.js
17048
- var caseInputLinkParam, linkCaseInputBody, CASE_COLLECTION_CASES_PAGE_MAX, caseCollectionCasesQuery, CASE_REFERENCES_PAGE_MAX, caseReferencesQuery;
17049
- var init_chunk_NIYQBLMR = __esm({
17050
- "../../packages/core/dist/chunk-NIYQBLMR.js"() {
16864
+ // ../../packages/core/dist/chunk-Q7NWJA2G.js
16865
+ var CASE_REVIEW_DECISIONS, CASE_ISSUED_FORMATS, CASE_REVIEW_COMMENT_MAX_LENGTH, CASE_REVIEW_JUSTIFICATION_MAX_LENGTH, text2, caseSubmissionParam, decideCaseSubmissionBody, caseIssuedQuery, CASE_APPROVALS_STATES, caseApprovalsQuery, caseCompareDefaultQuery, caseApprovalsAgendaQuery;
16866
+ var init_chunk_Q7NWJA2G = __esm({
16867
+ "../../packages/core/dist/chunk-Q7NWJA2G.js"() {
17051
16868
  "use strict";
17052
- init_chunk_53B7O5LO();
17053
- init_chunk_5PUYXYGT();
16869
+ init_chunk_2YVCHUBL();
16870
+ init_chunk_BT77VXJU();
16871
+ init_chunk_RHXF6X2Y();
16872
+ init_chunk_5Y2NNQHX();
16873
+ init_chunk_VROZDNLV();
17054
16874
  init_chunk_733K4J4G();
17055
16875
  init_chunk_3T3D7LTE();
17056
16876
  init_chunk_HZ6CADSY();
17057
16877
  init_zod();
17058
- caseInputLinkParam = caseRecordParam.extend({ input_id: uuidSchema });
17059
- linkCaseInputBody = external_exports.object({
17060
- document_id: uuidSchema,
17061
- /** The document's version its writer read as current, or an earlier one it keeps, with its `reason`. */
17062
- version_id: uuidSchema,
17063
- /** Why an earlier version is kept: a version decision. Unread when `version_id` is the current one. */
17064
- reason: caseVersionDecisionReason.optional()
17065
- }).strict();
17066
- CASE_COLLECTION_CASES_PAGE_MAX = 100;
17067
- caseCollectionCasesQuery = casePageQuery.extend({
17068
- limit: external_exports.coerce.number().int().min(1).max(CASE_COLLECTION_CASES_PAGE_MAX).optional()
17069
- });
17070
- CASE_REFERENCES_PAGE_MAX = 100;
17071
- caseReferencesQuery = casePageQuery.extend({
17072
- limit: external_exports.coerce.number().int().min(1).max(CASE_REFERENCES_PAGE_MAX).optional()
16878
+ CASE_REVIEW_DECISIONS = ["sign_off", "approve", "return"];
16879
+ CASE_ISSUED_FORMATS = ["pdf", "docx"];
16880
+ CASE_REVIEW_COMMENT_MAX_LENGTH = 2e3;
16881
+ CASE_REVIEW_JUSTIFICATION_MAX_LENGTH = 2e3;
16882
+ text2 = (max) => external_exports.string().trim().min(1).max(max);
16883
+ caseSubmissionParam = caseRecordParam.extend({ submission_id: uuidSchema });
16884
+ decideCaseSubmissionBody = external_exports.object({
16885
+ decision: external_exports.enum(CASE_REVIEW_DECISIONS),
16886
+ /** The final digest its decider saw (`CaseDelivery.final_digest`). */
16887
+ digest: caseFileShaSchema,
16888
+ /** Required to return. */
16889
+ comment: text2(CASE_REVIEW_COMMENT_MAX_LENGTH).nullable().default(null),
16890
+ /** Why one approves or signs off their own work; kept only then. */
16891
+ justification: text2(CASE_REVIEW_JUSTIFICATION_MAX_LENGTH).nullable().default(null)
16892
+ }).strict().superRefine((body, ctx) => {
16893
+ if (body.decision === "return" && body.comment === null) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: "A return needs its comment", path: ["comment"] });
17073
16894
  });
16895
+ caseIssuedQuery = external_exports.object({
16896
+ number: external_exports.coerce.number().int().min(1).max(1e3),
16897
+ format: external_exports.enum(CASE_ISSUED_FORMATS)
16898
+ }).strict();
16899
+ CASE_APPROVALS_STATES = ["waiting", "open", "ended"];
16900
+ caseApprovalsQuery = external_exports.object({
16901
+ state: external_exports.enum(CASE_APPROVALS_STATES).default("open"),
16902
+ cursor: external_exports.string().min(1).max(CASE_PAGE_CURSOR_MAX_LENGTH).optional()
16903
+ }).strict();
16904
+ caseCompareDefaultQuery = external_exports.object({ path: caseFileReadPath }).strict();
16905
+ caseApprovalsAgendaQuery = external_exports.object({
16906
+ cursor: external_exports.string().min(1).max(CASE_PAGE_CURSOR_MAX_LENGTH).optional()
16907
+ }).strict();
17074
16908
  }
17075
16909
  });
17076
16910
 
@@ -17192,6 +17026,25 @@ var init_chunk_BVQCYBU6 = __esm({
17192
17026
  }
17193
17027
  });
17194
17028
 
17029
+ // ../../packages/core/dist/chunk-UOPCLXCU.js
17030
+ var CASE_CHANGE_TOPICS, caseChangedFrameSchema;
17031
+ var init_chunk_UOPCLXCU = __esm({
17032
+ "../../packages/core/dist/chunk-UOPCLXCU.js"() {
17033
+ "use strict";
17034
+ init_chunk_733K4J4G();
17035
+ init_chunk_HZ6CADSY();
17036
+ init_zod();
17037
+ CASE_CHANGE_TOPICS = ["submission", "agenda", "access"];
17038
+ caseChangedFrameSchema = external_exports.object({
17039
+ org_id: uuidSchema,
17040
+ space_id: uuidSchema,
17041
+ /** The case, by its code; null for an `access` change, which names none. */
17042
+ code: caseRecordParam.shape.code.nullable(),
17043
+ topic: external_exports.enum(CASE_CHANGE_TOPICS)
17044
+ }).strict();
17045
+ }
17046
+ });
17047
+
17195
17048
  // ../../packages/core/dist/chunk-Z3SV3XTC.js
17196
17049
  var caseAccessQuery;
17197
17050
  var init_chunk_Z3SV3XTC = __esm({
@@ -17204,7 +17057,7 @@ var init_chunk_Z3SV3XTC = __esm({
17204
17057
  });
17205
17058
 
17206
17059
  // ../../packages/core/dist/chunk-NHC27NIE.js
17207
- var CASE_ADJUSTMENT_REASON_MAX_LENGTH, CASE_ADJUSTMENT_DISPENSATION_KINDS, reason2, activateCasePhaseBody, dispenseCaseBody, addCaseTaskBody, addCaseInputBody, caseOwnItemSchema, addCaseItemBody;
17060
+ var CASE_ADJUSTMENT_REASON_MAX_LENGTH, CASE_ADJUSTMENT_DISPENSATION_KINDS, reason, activateCasePhaseBody, dispenseCaseBody, addCaseTaskBody, addCaseInputBody, caseOwnItemSchema, addCaseItemBody;
17208
17061
  var init_chunk_NHC27NIE = __esm({
17209
17062
  "../../packages/core/dist/chunk-NHC27NIE.js"() {
17210
17063
  "use strict";
@@ -17213,9 +17066,9 @@ var init_chunk_NHC27NIE = __esm({
17213
17066
  init_zod();
17214
17067
  CASE_ADJUSTMENT_REASON_MAX_LENGTH = 2e3;
17215
17068
  CASE_ADJUSTMENT_DISPENSATION_KINDS = ["phase", "item", "output", "input"];
17216
- reason2 = external_exports.string().trim().min(1).max(CASE_ADJUSTMENT_REASON_MAX_LENGTH);
17217
- activateCasePhaseBody = external_exports.object({ phase_id: uuidSchema, reason: reason2 }).strict();
17218
- dispenseCaseBody = external_exports.object({ kind: external_exports.enum(CASE_ADJUSTMENT_DISPENSATION_KINDS), target_id: uuidSchema, reason: reason2 }).strict();
17069
+ reason = external_exports.string().trim().min(1).max(CASE_ADJUSTMENT_REASON_MAX_LENGTH);
17070
+ activateCasePhaseBody = external_exports.object({ phase_id: uuidSchema, reason }).strict();
17071
+ dispenseCaseBody = external_exports.object({ kind: external_exports.enum(CASE_ADJUSTMENT_DISPENSATION_KINDS), target_id: uuidSchema, reason }).strict();
17219
17072
  addCaseTaskBody = external_exports.object({
17220
17073
  phase_id: uuidSchema,
17221
17074
  name: external_exports.string().trim().min(1).max(CASE_TASK_NAME_MAX_LENGTH),
@@ -17226,7 +17079,7 @@ var init_chunk_NHC27NIE = __esm({
17226
17079
  addCaseInputBody = external_exports.object({
17227
17080
  phase_id: uuidSchema,
17228
17081
  input: casePhaseInputSchema.extend({ agenda_group: caseAgendaGroupCodeSchema.nullable().default(null) }),
17229
- reason: reason2
17082
+ reason
17230
17083
  }).strict();
17231
17084
  caseOwnItemSchema = caseOutputItemSchema.omit({ waivable: true, template_mode: true, fixed_text: true }).extend({ agenda_group: caseAgendaGroupCodeSchema.nullable().default(null) });
17232
17085
  addCaseItemBody = external_exports.object({
@@ -17234,7 +17087,7 @@ var init_chunk_NHC27NIE = __esm({
17234
17087
  /** The phase's output it goes in. */
17235
17088
  output_id: uuidSchema,
17236
17089
  item: caseOwnItemSchema,
17237
- reason: reason2
17090
+ reason
17238
17091
  }).strict();
17239
17092
  }
17240
17093
  });
@@ -17286,113 +17139,149 @@ var init_chunk_UMAPAGFH = __esm({
17286
17139
  }
17287
17140
  });
17288
17141
 
17289
- // ../../packages/core/dist/chunk-2PZIF56U.js
17290
- var analyticsHubIdParam, analyticsVariableIdParam, updateVariablePinBody, updateAnalyticsViewBody, NUMERIC_FILTER_OPS, TEXT_FILTER_OPS, CATEGORICAL_FILTER_OPS, VARIABLE_FILTER_OPS, STRUCTURED_QUERY_OPS, STRUCTURED_QUERY_AGGREGATIONS, filterValueSchema, conversationsBody, analyticsConversationIdParam, messagesQuery, conversationDetailDataQuery, analyticsDataBody, structuredQueryBody, analyticsSqlBody, analyticsSqlTable, analyticsSqlSchemaQuery;
17291
- var init_chunk_2PZIF56U = __esm({
17292
- "../../packages/core/dist/chunk-2PZIF56U.js"() {
17142
+ // ../../packages/core/dist/chunk-7TQYAKCB.js
17143
+ function addCaseNoteProblem(note) {
17144
+ return note.origin !== null && note.kind !== "contribution" ? { reason: "origin_not_contribution", at: "origin" } : null;
17145
+ }
17146
+ var CASE_NOTE_KINDS, CASE_NOTE_TEXT_MAX_LENGTH, CASE_NOTE_ORIGIN_MAX_LENGTH, CASE_NOTES_PAGE_MAX, addCaseNoteShape, addCaseNoteBody, caseNoteParam, caseTaskParam, caseNotesQuery;
17147
+ var init_chunk_7TQYAKCB = __esm({
17148
+ "../../packages/core/dist/chunk-7TQYAKCB.js"() {
17293
17149
  "use strict";
17150
+ init_chunk_733K4J4G();
17151
+ init_chunk_3T3D7LTE();
17152
+ init_chunk_HZ6CADSY();
17294
17153
  init_zod();
17295
- analyticsHubIdParam = external_exports.object({
17296
- hubId: external_exports.string().uuid()
17297
- });
17298
- analyticsVariableIdParam = external_exports.object({
17299
- variableId: external_exports.string().uuid()
17300
- });
17301
- updateVariablePinBody = external_exports.object({
17302
- pin: external_exports.union([external_exports.boolean(), external_exports.string()])
17303
- });
17304
- updateAnalyticsViewBody = external_exports.object({
17305
- // 64 covers UUIDs (36) and the `sys:{name}` synthetic IDs for system variables.
17306
- selected_variable_ids: external_exports.array(external_exports.string().min(1).max(64)).max(200)
17307
- });
17308
- NUMERIC_FILTER_OPS = ["eq", "neq", "gt", "gte", "lt", "lte"];
17309
- TEXT_FILTER_OPS = ["equals", "not_equals", "contains", "not_contains", "starts_with", "ends_with"];
17310
- CATEGORICAL_FILTER_OPS = ["is", "is_not", "in", "not_in"];
17311
- VARIABLE_FILTER_OPS = [
17312
- ...NUMERIC_FILTER_OPS,
17313
- ...TEXT_FILTER_OPS,
17314
- ...CATEGORICAL_FILTER_OPS
17315
- ];
17316
- STRUCTURED_QUERY_OPS = ["eq", "neq", "gt", "gte", "lt", "lte", "in", "not_in", "like"];
17317
- STRUCTURED_QUERY_AGGREGATIONS = ["avg", "sum", "min", "max", "count", "quantile", "stddevPop", "corr", "uniq"];
17318
- filterValueSchema = external_exports.object({
17319
- variable_id: external_exports.string(),
17320
- filter_type: external_exports.enum(VARIABLE_FILTER_OPS),
17321
- filter_value: external_exports.union([external_exports.string(), external_exports.number()])
17322
- });
17323
- conversationsBody = external_exports.object({
17324
- hub_id: external_exports.string().uuid(),
17325
- time_interval: external_exports.object({
17326
- start: external_exports.string().optional(),
17327
- end: external_exports.string().optional()
17328
- }).optional(),
17329
- filters: external_exports.array(filterValueSchema).optional(),
17330
- limit: external_exports.number().int().positive().max(500).default(50),
17331
- offset: external_exports.number().int().min(0).default(0)
17154
+ CASE_NOTE_KINDS = ["observation", "next_step", "pending", "contribution"];
17155
+ CASE_NOTE_TEXT_MAX_LENGTH = 64 * 1024;
17156
+ CASE_NOTE_ORIGIN_MAX_LENGTH = 200;
17157
+ CASE_NOTES_PAGE_MAX = 100;
17158
+ addCaseNoteShape = external_exports.object({
17159
+ kind: external_exports.enum(CASE_NOTE_KINDS),
17160
+ text: external_exports.string().trim().min(1).max(CASE_NOTE_TEXT_MAX_LENGTH),
17161
+ /** A contribution's external author. */
17162
+ origin: external_exports.string().trim().min(1).max(CASE_NOTE_ORIGIN_MAX_LENGTH).nullable().default(null),
17163
+ /** A phase of the case (its version's phase id). */
17164
+ phase_id: uuidSchema.nullable().default(null),
17165
+ /** A task of the case, whose phase the note takes. */
17166
+ case_task_id: uuidSchema.nullable().default(null)
17167
+ }).strict();
17168
+ addCaseNoteBody = addCaseNoteShape.superRefine((note, ctx) => {
17169
+ const found = addCaseNoteProblem(note);
17170
+ if (found) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: found.reason, path: [found.at], params: { case_note_reason: found.reason } });
17332
17171
  });
17333
- analyticsConversationIdParam = external_exports.object({
17334
- conversationId: external_exports.string().uuid()
17172
+ caseNoteParam = caseRecordParam.extend({ note_id: uuidSchema });
17173
+ caseTaskParam = caseRecordParam.extend({ case_task_id: uuidSchema });
17174
+ caseNotesQuery = casePageQuery.extend({
17175
+ limit: external_exports.coerce.number().int().min(1).max(CASE_NOTES_PAGE_MAX).optional()
17335
17176
  });
17336
- messagesQuery = external_exports.object({
17337
- hub_id: external_exports.string().uuid(),
17338
- limit: external_exports.string().regex(/^\d+$/).optional(),
17339
- offset: external_exports.string().regex(/^\d+$/).optional()
17177
+ }
17178
+ });
17179
+
17180
+ // ../../packages/core/dist/chunk-S7UAXLHJ.js
17181
+ var CASE_COMMENT_TEXT_MAX_LENGTH, CASE_COMMENTS_PAGE_MAX, CASE_COMMENT_LINE_MAX, casePassageLineSchema, lineNumber, addCaseCommentShape, CASE_COMMENT_REVERSED_REASON, addCaseCommentBody, caseCommentsQuery;
17182
+ var init_chunk_S7UAXLHJ = __esm({
17183
+ "../../packages/core/dist/chunk-S7UAXLHJ.js"() {
17184
+ "use strict";
17185
+ init_chunk_7TQYAKCB();
17186
+ init_chunk_VROZDNLV();
17187
+ init_chunk_3T3D7LTE();
17188
+ init_chunk_HZ6CADSY();
17189
+ init_zod();
17190
+ CASE_COMMENT_TEXT_MAX_LENGTH = CASE_NOTE_TEXT_MAX_LENGTH;
17191
+ CASE_COMMENTS_PAGE_MAX = 100;
17192
+ CASE_COMMENT_LINE_MAX = CASE_FILE_COMPARE_MAX_BYTES;
17193
+ casePassageLineSchema = external_exports.number().int().min(1).max(CASE_COMMENT_LINE_MAX);
17194
+ lineNumber = casePassageLineSchema;
17195
+ addCaseCommentShape = external_exports.object({
17196
+ path: caseFileReadPath,
17197
+ /** The version: the revision that wrote it to `path`. */
17198
+ revision_id: uuidSchema,
17199
+ /** The passage's first and last lines, from 1, of the version's text ({@link casePassageLines}). */
17200
+ line_start: lineNumber,
17201
+ line_end: lineNumber,
17202
+ text: external_exports.string().trim().min(1).max(CASE_COMMENT_TEXT_MAX_LENGTH),
17203
+ /** Hidden from every reader without the Confidential right; only a holder of it may set it. */
17204
+ confidential: external_exports.boolean().default(false)
17205
+ }).strict();
17206
+ CASE_COMMENT_REVERSED_REASON = "passage_reversed";
17207
+ addCaseCommentBody = addCaseCommentShape.superRefine((comment2, ctx) => {
17208
+ if (comment2.line_end < comment2.line_start) {
17209
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: CASE_COMMENT_REVERSED_REASON, path: ["line_end"] });
17210
+ }
17340
17211
  });
17341
- conversationDetailDataQuery = external_exports.object({
17342
- hub_id: external_exports.string().uuid()
17212
+ caseCommentsQuery = casePageQuery.extend({
17213
+ path: caseFileReadPath,
17214
+ /** Absent: every version's comments on the path. */
17215
+ revision_id: uuidSchema.optional(),
17216
+ limit: external_exports.coerce.number().int().min(1).max(CASE_COMMENTS_PAGE_MAX).optional()
17343
17217
  });
17344
- analyticsDataBody = external_exports.object({
17345
- hub_id: external_exports.string().uuid(),
17346
- periodicity: external_exports.enum(["daily", "weekly", "monthly", "yearly"]),
17347
- time_interval: external_exports.object({
17348
- start: external_exports.string(),
17349
- end: external_exports.string()
17350
- }),
17351
- trend_analysis: external_exports.boolean(),
17352
- filters: external_exports.array(filterValueSchema).optional(),
17353
- selected_variables: external_exports.array(external_exports.string()),
17354
- include_summary: external_exports.boolean().optional(),
17355
- include_variables: external_exports.boolean().optional(),
17356
- variable_origin: external_exports.enum(["agent", "system", "annotation"]).optional(),
17357
- variable_category: external_exports.string().optional(),
17358
- variables_only: external_exports.boolean().optional()
17218
+ }
17219
+ });
17220
+
17221
+ // ../../packages/core/dist/chunk-S4NDHW3Q.js
17222
+ var CASE_VERSION_DECISION_REASON_MAX_LENGTH, CASE_VERSION_DECISIONS, caseVersionDecisionReason, reason2, lineNumber2, recordCaseReferenceBody, CASE_PASSAGE_REVERSED_REASON, citeCasePassageBody, decideCaseVersionBody;
17223
+ var init_chunk_S4NDHW3Q = __esm({
17224
+ "../../packages/core/dist/chunk-S4NDHW3Q.js"() {
17225
+ "use strict";
17226
+ init_chunk_S7UAXLHJ();
17227
+ init_chunk_HZ6CADSY();
17228
+ init_zod();
17229
+ CASE_VERSION_DECISION_REASON_MAX_LENGTH = 2e3;
17230
+ CASE_VERSION_DECISIONS = ["adopt", "keep"];
17231
+ caseVersionDecisionReason = external_exports.string().trim().min(1).max(CASE_VERSION_DECISION_REASON_MAX_LENGTH);
17232
+ reason2 = caseVersionDecisionReason;
17233
+ lineNumber2 = casePassageLineSchema;
17234
+ recordCaseReferenceBody = external_exports.object({
17235
+ document_id: uuidSchema,
17236
+ /** The document's version its writer read as current. */
17237
+ version_id: uuidSchema
17238
+ }).strict();
17239
+ CASE_PASSAGE_REVERSED_REASON = CASE_COMMENT_REVERSED_REASON;
17240
+ citeCasePassageBody = external_exports.object({
17241
+ document_id: uuidSchema,
17242
+ version_id: uuidSchema,
17243
+ line_start: lineNumber2,
17244
+ line_end: lineNumber2
17245
+ }).strict().superRefine((body, ctx) => {
17246
+ if (body.line_end < body.line_start) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: CASE_PASSAGE_REVERSED_REASON, path: ["line_end"] });
17359
17247
  });
17360
- structuredQueryBody = external_exports.object({
17361
- hub_id: external_exports.string().uuid(),
17362
- metrics: external_exports.array(external_exports.object({
17363
- column: external_exports.string(),
17364
- aggregation: external_exports.enum(STRUCTURED_QUERY_AGGREGATIONS),
17365
- alias: external_exports.string().optional(),
17366
- corr_with: external_exports.string().optional(),
17367
- quantile_level: external_exports.number().min(0).max(1).optional()
17368
- })).min(1),
17369
- group_by: external_exports.array(external_exports.string()).optional(),
17370
- order_by: external_exports.array(external_exports.object({
17371
- column: external_exports.string(),
17372
- direction: external_exports.enum(["asc", "desc"]).optional()
17373
- })).optional(),
17374
- filters: external_exports.array(external_exports.object({
17375
- column: external_exports.string(),
17376
- operator: external_exports.enum(STRUCTURED_QUERY_OPS),
17377
- value: external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean()])
17378
- })).optional(),
17379
- time_range: external_exports.object({
17380
- start: external_exports.string(),
17381
- end: external_exports.string()
17382
- }).optional(),
17383
- limit: external_exports.number().int().positive().max(1e4).optional()
17248
+ decideCaseVersionBody = external_exports.object({
17249
+ decision: external_exports.enum(CASE_VERSION_DECISIONS),
17250
+ /** The newer version its decider read as current. */
17251
+ expect_version_id: uuidSchema,
17252
+ reason: reason2.nullable().default(null)
17253
+ }).strict().superRefine((body, ctx) => {
17254
+ if (body.decision === "keep" && body.reason === null) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: "A version kept needs its reason", path: ["reason"] });
17384
17255
  });
17385
- analyticsSqlBody = external_exports.object({
17386
- hub_id: external_exports.string().uuid(),
17387
- // Hard size cap before the validator runs — keeps lex/parse work bounded.
17388
- sql: external_exports.string().min(1).max(8e3),
17389
- limit: external_exports.number().int().positive().max(1e4).optional()
17256
+ }
17257
+ });
17258
+
17259
+ // ../../packages/core/dist/chunk-W4XY3TYX.js
17260
+ var caseInputLinkParam, linkCaseInputBody, CASE_COLLECTION_CASES_PAGE_MAX, caseCollectionCasesQuery, CASE_REFERENCES_PAGE_MAX, caseReferencesQuery;
17261
+ var init_chunk_W4XY3TYX = __esm({
17262
+ "../../packages/core/dist/chunk-W4XY3TYX.js"() {
17263
+ "use strict";
17264
+ init_chunk_PMBOHJKA();
17265
+ init_chunk_S4NDHW3Q();
17266
+ init_chunk_733K4J4G();
17267
+ init_chunk_3T3D7LTE();
17268
+ init_chunk_HZ6CADSY();
17269
+ init_zod();
17270
+ caseInputLinkParam = caseRecordParam.extend({ input_id: uuidSchema });
17271
+ linkCaseInputBody = external_exports.object({
17272
+ document_id: uuidSchema,
17273
+ /** The document's version its writer read as current, or an earlier one it keeps, with its `reason`. */
17274
+ version_id: uuidSchema,
17275
+ /** Why an earlier version is kept: a version decision. Unread when `version_id` is the current one. */
17276
+ reason: caseVersionDecisionReason.optional()
17277
+ }).strict();
17278
+ CASE_COLLECTION_CASES_PAGE_MAX = 100;
17279
+ caseCollectionCasesQuery = casePageQuery.extend({
17280
+ limit: external_exports.coerce.number().int().min(1).max(CASE_COLLECTION_CASES_PAGE_MAX).optional()
17390
17281
  });
17391
- analyticsSqlTable = external_exports.enum(["conversation", "message"]);
17392
- analyticsSqlSchemaQuery = external_exports.object({
17393
- hub_id: external_exports.string().uuid(),
17394
- // Defaulted so a client that predates the message table keeps its old response.
17395
- table: analyticsSqlTable.default("conversation")
17282
+ CASE_REFERENCES_PAGE_MAX = 100;
17283
+ caseReferencesQuery = casePageQuery.extend({
17284
+ limit: external_exports.coerce.number().int().min(1).max(CASE_REFERENCES_PAGE_MAX).optional()
17396
17285
  });
17397
17286
  }
17398
17287
  });
@@ -17877,7 +17766,7 @@ var init_chunk_OMPT4ZHR = __esm({
17877
17766
  }
17878
17767
  });
17879
17768
 
17880
- // ../../packages/core/dist/chunk-5BQN36EH.js
17769
+ // ../../packages/core/dist/chunk-GCDEP3KA.js
17881
17770
  function refineScopedTarget(data, ctx) {
17882
17771
  if (data.scope === "org") {
17883
17772
  if (!data.org_id) {
@@ -17903,8 +17792,8 @@ function refineScopedTarget(data, ctx) {
17903
17792
  }
17904
17793
  }
17905
17794
  var adminOrgIdParam, adminOrgAdminIdParam, adminUserIdParam, PRICING_PLAN_ID_RE, adminPlanIdParam, adminOrganizationsQuery, adminUserSearchQuery, kanbanSlugMigrationQuery, adjustQuotaBody, updatePlanBody, addAdminUserBody, MAX_VOICE_CALL_MINUTE_OPS, voiceCallMinuteOps, AUTOMATION_GATE_EVALUATIONS_PER_OPERATION_BOUND, automationGateEvaluationsPerOperation, AUTOMATION_RUN_RETENTION_DAYS_MAX, automationRunRetentionDays, turnDeadlineSeconds, casesLimit, updatePlatformConfigBody, updateFreeOrgLimitBody, adminScopedTargetShape, adminScopedTargetBody, adminDryRunByDefaultTargetBody, WAYAI_HOST_TOKEN_TARGET_KINDS, WAYAI_HOST_TOKEN_MAX_TARGETS, adminClearWayaiHostTokensBody, BRANCHING_ORPHAN_ENTITY_TYPES, BRANCHING_ORPHAN_MAX_TARGETS, adminRepairBranchingOrphansBody, adminRepairLegacyOrgGrantsBody, adminRepairCredentialServicesBody, adminRepairCompedPlansBody, updatePricingPlanBody, dataExplorerSearchQuery, dataExplorerOrgIdParam, dataExplorerHubIdParam, dataExplorerConvIdParam, dataExplorerDoInstancesQuery, dataExplorerNsIdParam, dataExplorerKvKeysBody, dataExplorerKvKeyBody, uuidOrHexId, dataExplorerDeleteOrgParam, dataExplorerDeleteHubParam, dataExplorerDeleteConvParam, dataExplorerDeleteUserParam, dataExplorerDeleteQuery, dataExplorerKvDeleteBody, pitrDoNamespace, pitrBookmarkParam, pitrRestoreBody, healthSamplingTriggerBody, DEBUG_DO_HEX_PREFIX, debugDoEntityId, debugTableName, dataExplorerDebugTablesParam, dataExplorerDebugRowsParam, dataExplorerDebugRowsQuery, dataExplorerDebugAnalyticsTable, debugUuid, dataExplorerDebugAnalyticsRowsParam, dataExplorerDebugAnalyticsRowsQuery, dataExplorerDebugCountsDoType, dataExplorerDebugCountsParam, debugHubConvParam, debugMessageIdQuery;
17906
- var init_chunk_5BQN36EH = __esm({
17907
- "../../packages/core/dist/chunk-5BQN36EH.js"() {
17795
+ var init_chunk_GCDEP3KA = __esm({
17796
+ "../../packages/core/dist/chunk-GCDEP3KA.js"() {
17908
17797
  "use strict";
17909
17798
  init_chunk_FECLIZTY();
17910
17799
  init_chunk_BFG4ZWR4();
@@ -18073,8 +17962,8 @@ var init_chunk_5BQN36EH = __esm({
18073
17962
  turn_deadline_seconds: turnDeadlineSeconds.optional(),
18074
17963
  /**
18075
17964
  * The credentials vault's gate list (wayai#5644): catalog connectors (`connector_id`), replacing
18076
- * the whole list; empty is the default. On the production Worker it decides only Instagram's gate,
18077
- * every other vault gate being held open there whatever it lists; the rule, and the conditions it
17965
+ * the whole list; empty is the default. On the production Worker it decides only Instagram's gate and
17966
+ * base credentials' (wayai#6142), every other vault gate being held open there whatever it lists; the rule, and the conditions it
18078
17967
  * holds under, are `apps/backend/src/durable-objects/platform-do/vault-gate.ts`'s. The route stores
18079
17968
  * it as JSON. An id no connector has matches nothing, so it leaves that connector off.
18080
17969
  */
@@ -18299,6 +18188,117 @@ var init_chunk_5BQN36EH = __esm({
18299
18188
  }
18300
18189
  });
18301
18190
 
18191
+ // ../../packages/core/dist/chunk-2PZIF56U.js
18192
+ var analyticsHubIdParam, analyticsVariableIdParam, updateVariablePinBody, updateAnalyticsViewBody, NUMERIC_FILTER_OPS, TEXT_FILTER_OPS, CATEGORICAL_FILTER_OPS, VARIABLE_FILTER_OPS, STRUCTURED_QUERY_OPS, STRUCTURED_QUERY_AGGREGATIONS, filterValueSchema, conversationsBody, analyticsConversationIdParam, messagesQuery, conversationDetailDataQuery, analyticsDataBody, structuredQueryBody, analyticsSqlBody, analyticsSqlTable, analyticsSqlSchemaQuery;
18193
+ var init_chunk_2PZIF56U = __esm({
18194
+ "../../packages/core/dist/chunk-2PZIF56U.js"() {
18195
+ "use strict";
18196
+ init_zod();
18197
+ analyticsHubIdParam = external_exports.object({
18198
+ hubId: external_exports.string().uuid()
18199
+ });
18200
+ analyticsVariableIdParam = external_exports.object({
18201
+ variableId: external_exports.string().uuid()
18202
+ });
18203
+ updateVariablePinBody = external_exports.object({
18204
+ pin: external_exports.union([external_exports.boolean(), external_exports.string()])
18205
+ });
18206
+ updateAnalyticsViewBody = external_exports.object({
18207
+ // 64 covers UUIDs (36) and the `sys:{name}` synthetic IDs for system variables.
18208
+ selected_variable_ids: external_exports.array(external_exports.string().min(1).max(64)).max(200)
18209
+ });
18210
+ NUMERIC_FILTER_OPS = ["eq", "neq", "gt", "gte", "lt", "lte"];
18211
+ TEXT_FILTER_OPS = ["equals", "not_equals", "contains", "not_contains", "starts_with", "ends_with"];
18212
+ CATEGORICAL_FILTER_OPS = ["is", "is_not", "in", "not_in"];
18213
+ VARIABLE_FILTER_OPS = [
18214
+ ...NUMERIC_FILTER_OPS,
18215
+ ...TEXT_FILTER_OPS,
18216
+ ...CATEGORICAL_FILTER_OPS
18217
+ ];
18218
+ STRUCTURED_QUERY_OPS = ["eq", "neq", "gt", "gte", "lt", "lte", "in", "not_in", "like"];
18219
+ STRUCTURED_QUERY_AGGREGATIONS = ["avg", "sum", "min", "max", "count", "quantile", "stddevPop", "corr", "uniq"];
18220
+ filterValueSchema = external_exports.object({
18221
+ variable_id: external_exports.string(),
18222
+ filter_type: external_exports.enum(VARIABLE_FILTER_OPS),
18223
+ filter_value: external_exports.union([external_exports.string(), external_exports.number()])
18224
+ });
18225
+ conversationsBody = external_exports.object({
18226
+ hub_id: external_exports.string().uuid(),
18227
+ time_interval: external_exports.object({
18228
+ start: external_exports.string().optional(),
18229
+ end: external_exports.string().optional()
18230
+ }).optional(),
18231
+ filters: external_exports.array(filterValueSchema).optional(),
18232
+ limit: external_exports.number().int().positive().max(500).default(50),
18233
+ offset: external_exports.number().int().min(0).default(0)
18234
+ });
18235
+ analyticsConversationIdParam = external_exports.object({
18236
+ conversationId: external_exports.string().uuid()
18237
+ });
18238
+ messagesQuery = external_exports.object({
18239
+ hub_id: external_exports.string().uuid(),
18240
+ limit: external_exports.string().regex(/^\d+$/).optional(),
18241
+ offset: external_exports.string().regex(/^\d+$/).optional()
18242
+ });
18243
+ conversationDetailDataQuery = external_exports.object({
18244
+ hub_id: external_exports.string().uuid()
18245
+ });
18246
+ analyticsDataBody = external_exports.object({
18247
+ hub_id: external_exports.string().uuid(),
18248
+ periodicity: external_exports.enum(["daily", "weekly", "monthly", "yearly"]),
18249
+ time_interval: external_exports.object({
18250
+ start: external_exports.string(),
18251
+ end: external_exports.string()
18252
+ }),
18253
+ trend_analysis: external_exports.boolean(),
18254
+ filters: external_exports.array(filterValueSchema).optional(),
18255
+ selected_variables: external_exports.array(external_exports.string()),
18256
+ include_summary: external_exports.boolean().optional(),
18257
+ include_variables: external_exports.boolean().optional(),
18258
+ variable_origin: external_exports.enum(["agent", "system", "annotation"]).optional(),
18259
+ variable_category: external_exports.string().optional(),
18260
+ variables_only: external_exports.boolean().optional()
18261
+ });
18262
+ structuredQueryBody = external_exports.object({
18263
+ hub_id: external_exports.string().uuid(),
18264
+ metrics: external_exports.array(external_exports.object({
18265
+ column: external_exports.string(),
18266
+ aggregation: external_exports.enum(STRUCTURED_QUERY_AGGREGATIONS),
18267
+ alias: external_exports.string().optional(),
18268
+ corr_with: external_exports.string().optional(),
18269
+ quantile_level: external_exports.number().min(0).max(1).optional()
18270
+ })).min(1),
18271
+ group_by: external_exports.array(external_exports.string()).optional(),
18272
+ order_by: external_exports.array(external_exports.object({
18273
+ column: external_exports.string(),
18274
+ direction: external_exports.enum(["asc", "desc"]).optional()
18275
+ })).optional(),
18276
+ filters: external_exports.array(external_exports.object({
18277
+ column: external_exports.string(),
18278
+ operator: external_exports.enum(STRUCTURED_QUERY_OPS),
18279
+ value: external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean()])
18280
+ })).optional(),
18281
+ time_range: external_exports.object({
18282
+ start: external_exports.string(),
18283
+ end: external_exports.string()
18284
+ }).optional(),
18285
+ limit: external_exports.number().int().positive().max(1e4).optional()
18286
+ });
18287
+ analyticsSqlBody = external_exports.object({
18288
+ hub_id: external_exports.string().uuid(),
18289
+ // Hard size cap before the validator runs — keeps lex/parse work bounded.
18290
+ sql: external_exports.string().min(1).max(8e3),
18291
+ limit: external_exports.number().int().positive().max(1e4).optional()
18292
+ });
18293
+ analyticsSqlTable = external_exports.enum(["conversation", "message"]);
18294
+ analyticsSqlSchemaQuery = external_exports.object({
18295
+ hub_id: external_exports.string().uuid(),
18296
+ // Defaulted so a client that predates the message table keeps its old response.
18297
+ table: analyticsSqlTable.default("conversation")
18298
+ });
18299
+ }
18300
+ });
18301
+
18302
18302
  // ../../packages/core/dist/chunk-ZRXP6OOJ.js
18303
18303
  function capped(max, field) {
18304
18304
  return (value, ctx) => {
@@ -18359,18 +18359,18 @@ var init_contracts = __esm({
18359
18359
  init_chunk_C7UAGRXF();
18360
18360
  init_chunk_IPXBFWUU();
18361
18361
  init_chunk_63UWXV4T();
18362
- init_chunk_WDAXZDJO();
18363
18362
  init_chunk_ZC6YGHNX();
18364
18363
  init_chunk_HIGKBEPF();
18365
- init_chunk_ITIQ7XWD();
18366
18364
  init_chunk_IPDOHAZ5();
18367
18365
  init_chunk_PFGVH2CX();
18368
18366
  init_chunk_TVUDMGWV();
18369
18367
  init_chunk_WTIGECE5();
18368
+ init_chunk_WDAXZDJO();
18370
18369
  init_chunk_ZXK6N2HN();
18371
18370
  init_chunk_Y7CFCYX4();
18372
18371
  init_chunk_MGBAXT5Y();
18373
18372
  init_chunk_5DGHIY7L();
18373
+ init_chunk_ITIQ7XWD();
18374
18374
  init_chunk_I3O2RACG();
18375
18375
  init_chunk_CMRECH67();
18376
18376
  init_chunk_34LE6P7E();
@@ -18385,7 +18385,6 @@ var init_contracts = __esm({
18385
18385
  init_chunk_C4HEZ7ZI();
18386
18386
  init_chunk_IR2NOSI3();
18387
18387
  init_chunk_OPETF4GS();
18388
- init_chunk_YULHXJ5M();
18389
18388
  init_chunk_V4FRPRH5();
18390
18389
  init_chunk_LWMLR2WI();
18391
18390
  init_chunk_ACGAI25T();
@@ -18403,29 +18402,28 @@ var init_contracts = __esm({
18403
18402
  init_chunk_JDJ4EUOL();
18404
18403
  init_chunk_UCYWGWQT();
18405
18404
  init_chunk_6AYIXGDT();
18406
- init_chunk_P53C23HN();
18405
+ init_chunk_YULHXJ5M();
18407
18406
  init_chunk_K3PD6AOF();
18408
18407
  init_chunk_KVMROYDC();
18409
18408
  init_chunk_M2IF4G6X();
18410
18409
  init_chunk_NNC2ZECG();
18411
- init_chunk_UOPCLXCU();
18412
18410
  init_chunk_7CZSLDOE();
18413
- init_chunk_4HBSIBSD();
18411
+ init_chunk_ZB7W3DKK();
18412
+ init_chunk_Q7NWJA2G();
18413
+ init_chunk_2YVCHUBL();
18414
18414
  init_chunk_BT77VXJU();
18415
- init_chunk_TECYEMQ2();
18416
- init_chunk_NIYQBLMR();
18417
- init_chunk_53B7O5LO();
18418
- init_chunk_E7JRMKV5();
18419
- init_chunk_3LMWOJQX();
18420
18415
  init_chunk_H6V7NEWR();
18421
18416
  init_chunk_ZVIMTUGZ();
18422
18417
  init_chunk_BVQCYBU6();
18423
- init_chunk_5PKKFSSF();
18418
+ init_chunk_UOPCLXCU();
18424
18419
  init_chunk_Z3SV3XTC();
18425
18420
  init_chunk_NHC27NIE();
18426
18421
  init_chunk_UMAPAGFH();
18427
- init_chunk_5PUYXYGT();
18428
- init_chunk_2PZIF56U();
18422
+ init_chunk_W4XY3TYX();
18423
+ init_chunk_PMBOHJKA();
18424
+ init_chunk_U3X3BIQH();
18425
+ init_chunk_3LMWOJQX();
18426
+ init_chunk_S4NDHW3Q();
18429
18427
  init_chunk_UEJOG2Q7();
18430
18428
  init_chunk_KEN2DASI();
18431
18429
  init_chunk_YFNR2VM4();
@@ -18437,8 +18435,9 @@ var init_contracts = __esm({
18437
18435
  init_chunk_PZPOUXJR();
18438
18436
  init_chunk_LBDH7LCG();
18439
18437
  init_chunk_4LXDRTO4();
18438
+ init_chunk_5PKKFSSF();
18440
18439
  init_chunk_NVKU5PPQ();
18441
- init_chunk_5BQN36EH();
18440
+ init_chunk_GCDEP3KA();
18442
18441
  init_chunk_FECLIZTY();
18443
18442
  init_chunk_BFG4ZWR4();
18444
18443
  init_chunk_UY32MQHG();
@@ -18447,6 +18446,7 @@ var init_contracts = __esm({
18447
18446
  init_chunk_X5PZZVTS();
18448
18447
  init_chunk_PIZTARVG();
18449
18448
  init_chunk_OMPT4ZHR();
18449
+ init_chunk_2PZIF56U();
18450
18450
  init_chunk_6J742GLA();
18451
18451
  init_chunk_ZRXP6OOJ();
18452
18452
  init_chunk_BGNWWR6B();
@@ -18470,9 +18470,9 @@ var init_contracts = __esm({
18470
18470
  init_chunk_C2UEA2KW();
18471
18471
  init_chunk_RHXF6X2Y();
18472
18472
  init_chunk_5Y2NNQHX();
18473
- init_chunk_NQGO3NQ2();
18473
+ init_chunk_S7UAXLHJ();
18474
18474
  init_chunk_7TQYAKCB();
18475
- init_chunk_U7GWWTPM();
18475
+ init_chunk_VROZDNLV();
18476
18476
  init_chunk_733K4J4G();
18477
18477
  init_chunk_PFPADFUC();
18478
18478
  init_chunk_KWRHZBGU();
@@ -42069,7 +42069,7 @@ async function runVaultGateChange(change, positional, flagArgs) {
42069
42069
  if (!jsonOutput) console.log(`Before: ${describeVaultGateList(before)}`);
42070
42070
  if (!yes && !jsonOutput) {
42071
42071
  console.log(change === "add" ? `About to add ${toChange.map(describeVaultGateEntry).join(", ")}: their connections' new credentials go to the credentials vault.` : `About to remove ${toChange.map(describeVaultGateEntry).join(", ")}: their connections' new credentials no longer go to the vault; ones the vault already holds stay there.`);
42072
- console.log("In production only Instagram's gate reads this list: every other vault gate stays open, listed or not.");
42072
+ console.log("In production only Instagram's gate and base credentials' gate read this list: every other vault gate stays open, listed or not.");
42073
42073
  const ok = await confirm("Proceed?");
42074
42074
  if (!ok) {
42075
42075
  console.log("Aborted.");
@@ -42743,11 +42743,11 @@ Usage:
42743
42743
  wayai admin guide clear [--json] Turn the Guide off: nobody new is enrolled and the help entry is hidden
42744
42744
  wayai admin guide status [--json] Print which hub is the Guide, and its facts
42745
42745
 
42746
- wayai admin vault-gate status [--json] Print the vault_connector_ids list (on production it decides only Instagram's gate: the backend's vault-gate.ts)
42746
+ wayai admin vault-gate status [--json] Print the vault_connector_ids list (on production it decides only Instagram's and base credentials' gates: the backend's vault-gate.ts)
42747
42747
  wayai admin vault-gate add <connector> [--yes] [--json]
42748
42748
  List a connector: a vault connector's name (e.g. telegram, whatsapp, instagram, or openai for its LLM, STT and TTS ids, never GPT-Live's) or one catalog id (GPT-Live's only so); prints before and after, confirms unless --yes
42749
42749
  wayai admin vault-gate remove <connector> [--yes] [--json]
42750
- Stop listing it: its new credentials no longer go to the vault (on production only Instagram's gate reads the list)
42750
+ Stop listing it: its new credentials no longer go to the vault (on production only Instagram's and base credentials' gates read the list)
42751
42751
 
42752
42752
  Sources:
42753
42753
  do Live DO SQLite (existing conversation, hub config, etc.).
@@ -42867,8 +42867,8 @@ Sources:
42867
42867
  enrollment and hides the help entry; people already enrolled keep their row.
42868
42868
  Changes land within about 60 s.
42869
42869
  vault-gate The credentials vault's gate, per connector and never per org: the PLATFORM-wide
42870
- vault_connector_ids list. In production every vault gate but Instagram's is open
42871
- whatever it lists, so there it decides only Instagram's (the backend's
42870
+ vault_connector_ids list. In production every vault gate but Instagram's and base
42871
+ credentials' is open whatever it lists, so there it decides only those two (the backend's
42872
42872
  vault-gate.ts states the rule). A listed connector's new credentials go to the vault,
42873
42873
  the row keeping only a reference; credentials the vault already holds stay there
42874
42874
  whichever way the gate is set. Only connectors the vault holds anything of are