@vercel/board 0.16.0 → 0.18.0

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.
Files changed (130) hide show
  1. package/README.md +27 -27
  2. package/dist/{a2-C41hD8SF.mjs → a2-ChRLRupa.mjs} +969 -25
  3. package/dist/access.d.mts +1 -1
  4. package/dist/access.mjs +3 -3
  5. package/dist/{actors-DjMeZpnU.mjs → actors-BOamkEuz.mjs} +3 -73
  6. package/dist/attempts-CLG840Oj.mjs +20 -0
  7. package/dist/{auth-COzc09sn.mjs → auth-Drg9FiC2.mjs} +225 -2
  8. package/dist/backend-B-SJ7p6p.d.mts +680 -0
  9. package/dist/backend-a2/contract.d.mts +873 -2
  10. package/dist/backend-a2/contract.mjs +2 -2
  11. package/dist/backend-a2/scheduler-local.d.mts +1 -1
  12. package/dist/backend-a2/scheduler-local.mjs +1 -1
  13. package/dist/backend-a2/scheduler-qstash.d.mts +78 -1
  14. package/dist/backend-a2/scheduler-qstash.mjs +521 -1
  15. package/dist/backend-a2/scheduler-vercel.d.mts +37 -1
  16. package/dist/backend-a2/scheduler-vercel.mjs +203 -1
  17. package/dist/backend-a2/store-memory.d.mts +2 -2
  18. package/dist/backend-a2/store-memory.mjs +3 -3
  19. package/dist/backend-a2/store-postgres.d.mts +1 -1
  20. package/dist/backend-a2/store-postgres.mjs +2850 -2
  21. package/dist/backend-a2/store-redis-http.d.mts +1 -1
  22. package/dist/backend-a2/store-redis-http.mjs +490 -2
  23. package/dist/backend-a2/store-redis.d.mts +10 -2
  24. package/dist/backend-a2/store-redis.mjs +51 -2
  25. package/dist/backend-a2/store-sqlite.d.mts +1 -1
  26. package/dist/backend-a2/store-sqlite.mjs +3 -3
  27. package/dist/backend-a2.d.mts +2706 -3
  28. package/dist/backend-a2.mjs +1 -1
  29. package/dist/{backend-http-Bid7RIpC.d.mts → backend-http-7cNb8nJI.d.mts} +10 -3
  30. package/dist/{backend-http-0roEmjl0.mjs → backend-http-CMlL3yq3.mjs} +2 -2
  31. package/dist/{backend-http-BVRno-ca.mjs → backend-http-Ddzd5kTS.mjs} +32 -3
  32. package/dist/backend-http.d.mts +1 -1
  33. package/dist/backend-http.mjs +1 -1
  34. package/dist/backend-http.node.d.mts +1 -1
  35. package/dist/backend-http.node.mjs +1 -1
  36. package/dist/{chat-provider-XCnQlxq6.d.mts → chat-provider-DNJQyajS.d.mts} +16 -4
  37. package/dist/{chat-provider-jFSeyNmB.mjs → chat-provider-YHy-WbrB.mjs} +15 -9
  38. package/dist/cli.mjs +30 -10
  39. package/dist/{client-DGDPaN7U.mjs → client-BA-J7usH.mjs} +10 -2
  40. package/dist/{conformance-DRR23YNy.mjs → conformance-CT5EeHeC.mjs} +5 -2
  41. package/dist/conformance.d.mts +1 -1
  42. package/dist/conformance.mjs +1 -1
  43. package/dist/{engine-Bir5s8ts.mjs → engine-D0oBUBEK.mjs} +249 -163
  44. package/dist/events-CewD4kw7.mjs +75 -0
  45. package/dist/{exports-Dvc1o52I.mjs → exports-CgjfMrQ-.mjs} +35 -32
  46. package/dist/exports-ZsgjzEnM.d.mts +4 -0
  47. package/dist/external-BV_cUncs.mjs +151 -0
  48. package/dist/folds-CRYY14kc.d.mts +534 -0
  49. package/dist/{reducers-mUPFuFJV.mjs → folds-Dyjput8M.mjs} +6 -73
  50. package/dist/ids-C6AYo1bu.mjs +31 -0
  51. package/dist/index.d.mts +4 -4
  52. package/dist/{index.default-Bkg77Pxn.mjs → index.default-C5Cpz3sa.mjs} +1 -1
  53. package/dist/index.mjs +5 -5
  54. package/dist/index.node.d.mts +4 -4
  55. package/dist/index.node.mjs +3 -3
  56. package/dist/inspect/app.js +31 -31
  57. package/dist/inspect/engine.js +5 -5
  58. package/dist/internal-CvsrprnU-CRY89I-b.mjs +203 -0
  59. package/dist/{local-Cr_dSjvs.mjs → local-DhkrAqPP.mjs} +1 -1
  60. package/dist/mentions-CB6ShY4R.mjs +72 -0
  61. package/dist/{targets-yM5JBUgr.mjs → middleware-CqaCwucP.mjs} +1 -33
  62. package/dist/platform-B4TnJtWu-CwcTyKg2.mjs +32 -0
  63. package/dist/{project-CFiArraX.mjs → project-DMDST9kl.mjs} +1 -1
  64. package/dist/{provider-BGjz-mDa.d.mts → provider-B0b9Qxw4.d.mts} +170 -40
  65. package/dist/provider-B3DpYSDq.mjs +220 -0
  66. package/dist/redis-tables-DN9PfIDi.mjs +3897 -0
  67. package/dist/reducer-CYPHsSmd-BQIfozGi.d.mts +170 -0
  68. package/dist/reducer-CjmvZSAb-D_OSISmj.mjs +74 -0
  69. package/dist/{contract-CuJmlrhw.mjs → reducers-BFmIXilu.mjs} +260 -287
  70. package/dist/retryable-lazy-DZWmHpii-Bye-W8q7.mjs +19 -0
  71. package/dist/scheduler-task-X1SToDjP-BVoWuInI.mjs +69 -0
  72. package/dist/{serve-BsOOc-6_.mjs → serve-BGYw0uNL.mjs} +5 -5
  73. package/dist/{server-jwPY7_wi.mjs → server-DPxBSogx.mjs} +4 -4
  74. package/dist/server-DtFrWxi3-Boa6gdWO.mjs +3602 -0
  75. package/dist/server-qgez0Xny-D5mLfqFQ.d.mts +385 -0
  76. package/dist/{serving-BNbzc96L.mjs → serving-CNkgUPW1.mjs} +1 -1
  77. package/dist/session-clear-wHd5GCpZ-BnKSxReK.mjs +51 -0
  78. package/dist/{sql-DbiEnqM0.mjs → sql-U9WTxrwJ.mjs} +2 -2
  79. package/dist/{sqlite-db-Cbj03vmp.mjs → sqlite-db-Ds4majtT.mjs} +1 -1
  80. package/dist/store-D0MhBvg6-4Z2L0Kqd.d.mts +530 -0
  81. package/dist/store-N8PXxDAS-BWBgzBHp.mjs +5 -0
  82. package/dist/store-codec-DwrWlgQx-CYxGW0aD.mjs +61 -0
  83. package/dist/store-memory-Bas9Uq5C.mjs +872 -0
  84. package/dist/store-memory-ZLiZbH3R.mjs +2 -0
  85. package/dist/store-polling-BZt2Rf3D-BiEM6_HB.mjs +148 -0
  86. package/dist/store-presence-polling-JuAy2Ck2-CYpuK75X.mjs +109 -0
  87. package/dist/store-sqlite-BmwL3pUR.mjs +2 -0
  88. package/dist/store-sqlite-CxxPCcCT.mjs +1053 -0
  89. package/dist/stream-buffer-DrTyiIuo-BKy-vI14.mjs +53 -0
  90. package/dist/sync-github.d.mts +24 -17
  91. package/dist/sync-github.mjs +89 -22
  92. package/dist/sync-kapso.d.mts +15 -13
  93. package/dist/sync-kapso.mjs +17 -14
  94. package/dist/sync-linear.d.mts +219 -0
  95. package/dist/sync-linear.mjs +311 -0
  96. package/dist/sync-slack.d.mts +12 -17
  97. package/dist/sync-slack.mjs +54 -42
  98. package/dist/sync.chat.d.mts +1 -1
  99. package/dist/sync.chat.mjs +1 -1
  100. package/dist/sync.d.mts +3 -3
  101. package/dist/sync.mjs +5 -4
  102. package/dist/targets-C-wdR5wP.mjs +33 -0
  103. package/dist/{tokens-DKLn5P9B.mjs → tokens-DhuzKzAl.mjs} +1 -1
  104. package/dist/{types-BHCjTZdB.d.mts → types-8yq2VnKI.d.mts} +2 -2
  105. package/dist/{users-Dls7_ANV.mjs → users-yryHKFMo.mjs} +2 -2
  106. package/dist/{watch-spec-W0c7ypHJ.mjs → watchers-hash-RLtnSF-t.mjs} +233 -28
  107. package/docs/01-board/01-mounting.md +1 -1
  108. package/docs/02-sync/01-overview.md +72 -48
  109. package/docs/02-sync/02-functions.md +398 -0
  110. package/docs/02-sync/03-slack.md +30 -25
  111. package/docs/02-sync/04-github.md +62 -26
  112. package/docs/02-sync/05-whatsapp.md +23 -19
  113. package/docs/02-sync/06-providers.md +60 -27
  114. package/docs/02-sync/07-linear.md +129 -0
  115. package/docs/03-guides/04-triage.md +1 -1
  116. package/docs/04-reference/01-cli.md +26 -6
  117. package/docs/04-reference/02-board.md +18 -5
  118. package/docs/04-reference/03-http.md +5 -2
  119. package/docs/04-reference/05-conformance.md +1 -1
  120. package/docs/index.md +5 -10
  121. package/package.json +31 -6
  122. package/dist/a2-D24cvwpN.d.mts +0 -3359
  123. package/dist/access-CJU2-vaa.mjs +0 -226
  124. package/dist/attempts-Bxp9KgPf.mjs +0 -919
  125. package/dist/exports-DLiE7fLY.d.mts +0 -4
  126. package/dist/provider-CuewcDNZ.mjs +0 -205
  127. package/dist/redis-tables-B35vv4CZ.mjs +0 -842
  128. package/dist/reducers-B_vUGQRp.d.mts +0 -1172
  129. package/dist/watchers-hash-CLjsa6od.mjs +0 -225
  130. package/docs/02-sync/02-callbacks.md +0 -265
@@ -1,5 +1,5 @@
1
1
  import { n as DIRECT_UPLOAD_BYTES_MAX, r as IMPORT_BYTES_MAX, t as ATTACHMENT_BYTES_MAX } from "../files-SniSmeEr.mjs";
2
2
  import { a as AttachmentId, c as ChannelPath, d as LabelKey, f as LabelValue, g as MessageText, h as MessageId, i as Attachment, l as Emoji, m as MESSAGE_TEXT_MAX, n as ActorId, o as Author, p as Labels, r as ActorKind, s as CHANNEL_PATH_MAX, t as ATTACHMENTS_PER_MESSAGE_MAX, u as Handle } from "../schemas-Be08nyfW.mjs";
3
- import { f as boardContract, l as Origin, t as BOARD_SESSION } from "../contract-CuJmlrhw.mjs";
4
- import { d as messagesReducer, n as channelsReducer, t as actorsReducer } from "../reducers-mUPFuFJV.mjs";
3
+ import { o as Origin } from "../external-BV_cUncs.mjs";
4
+ import { _ as BOARD_SESSION, i as messagesReducer, l as boardContract, n as channelsReducer, t as actorsReducer } from "../reducers-BFmIXilu.mjs";
5
5
  export { ATTACHMENTS_PER_MESSAGE_MAX, ATTACHMENT_BYTES_MAX, ActorId, ActorKind, Attachment, AttachmentId, Author, BOARD_SESSION, CHANNEL_PATH_MAX, ChannelPath, DIRECT_UPLOAD_BYTES_MAX, Emoji, Handle, IMPORT_BYTES_MAX, LabelKey, LabelValue, Labels, MESSAGE_TEXT_MAX, MessageId, MessageText, Origin, actorsReducer, boardContract, channelsReducer, messagesReducer };
@@ -1,4 +1,4 @@
1
- import { A2Scheduler } from "experimental-a2/server";
1
+ import { t as A2Scheduler } from "../server-qgez0Xny-D5mLfqFQ.mjs";
2
2
  //#region src/scheduler/local.d.ts
3
3
  /**
4
4
  * A scheduler in this process (`@vercel/board/backend-a2/scheduler-local`): each task runs at its time on
@@ -1,2 +1,2 @@
1
- import { t as localScheduler } from "../local-Cr_dSjvs.mjs";
1
+ import { t as localScheduler } from "../local-DhkrAqPP.mjs";
2
2
  export { localScheduler };
@@ -1,2 +1,79 @@
1
- import { QStashSchedulerOptions, qstash } from "experimental-a2/scheduler-qstash";
1
+ import { n as Clock } from "../store-D0MhBvg6-4Z2L0Kqd.mjs";
2
+ import { i as SchedulerTask, t as A2Scheduler } from "../server-qgez0Xny-D5mLfqFQ.mjs";
3
+ //#region ../../node_modules/.pnpm/experimental-a2@0.22.0_@upstash+qstash@2.12.0_@vercel+queue@0.7.0_ai@7.0.130_zod@4.6.5__52060f00b21aecfab049c27fa3abd2f9/node_modules/experimental-a2/dist/scheduler-qstash.d.ts
4
+ //#region src/scheduler-qstash.d.ts
5
+ type QStashStoreOutage = {
6
+ version: 1;
7
+ /** Zero is the first successor created for a store outage. */
8
+ generation: number;
9
+ /** The first failing drain task's due time. Append and clear identity lives on the task. */
10
+ rootDueAt?: number;
11
+ };
12
+ type QStashMessage = SchedulerTask & {
13
+ /** Provider-private state authenticated as part of QStash's signed body. */
14
+ _a2QStash?: QStashStoreOutage;
15
+ };
16
+ type QStashPublishRequest = {
17
+ url: string;
18
+ body: QStashMessage;
19
+ /** Headers the transport must deliver to the callback. */
20
+ headers?: Readonly<Record<string, string>>;
21
+ /** Header names the transport must redact from provider dashboard/API views. */
22
+ redact?: {
23
+ header: readonly string[];
24
+ };
25
+ /** Whole-second Unix timestamp. Omitted for an immediate delivery. */
26
+ notBefore?: number;
27
+ deduplicationId: string;
28
+ /** Delivery retries after the initial attempt. */
29
+ retries?: number;
30
+ };
31
+ /** The request shape passed to an injected `@upstash/qstash` client. */
32
+ type QStashClientPublishRequest = Omit<QStashPublishRequest, "headers" | "redact"> & {
33
+ headers?: Record<string, string>;
34
+ redact?: {
35
+ header: string[];
36
+ };
37
+ };
38
+ /** The outbound part of `@upstash/qstash` used by the built-in transport. */
39
+ type QStashPublishingClient = {
40
+ publishJSON(request: QStashClientPublishRequest): Promise<unknown>;
41
+ };
42
+ type QStashVerifyRequest = {
43
+ signature: string;
44
+ /** The untouched request body covered by the signature. */
45
+ body: string;
46
+ /** Exact destination URL, checked against the signature subject. */
47
+ url: string;
48
+ upstashRegion?: string;
49
+ };
50
+ /** The small part of `@upstash/qstash` this adapter needs. */
51
+ type QStashTransport = {
52
+ publish(request: QStashPublishRequest): Promise<unknown>;
53
+ verify(request: QStashVerifyRequest): Promise<boolean>;
54
+ };
55
+ type QStashSchedulerOptions = {
56
+ /** Exact URL mounted with `scheduler.handler(...)`. Inferred in local dev and on Vercel. */
57
+ url?: string;
58
+ /** QStash API token. Default: `QSTASH_TOKEN`. */
59
+ token?: string;
60
+ /** QStash signing key. Default: `QSTASH_CURRENT_SIGNING_KEY`. */
61
+ currentSigningKey?: string;
62
+ /** Next QStash signing key. Default: `QSTASH_NEXT_SIGNING_KEY`. */
63
+ nextSigningKey?: string;
64
+ /** Delivery retries after the initial attempt. Default: provider default. */
65
+ retries?: number;
66
+ /** Maximum callback body and outbound task with outage headroom. Default 1 MiB. */
67
+ maxBodyBytes?: number;
68
+ /** Static callback headers. QStash receives them; A2 requests dashboard/API redaction. */
69
+ headers?: Readonly<Record<string, string>>;
70
+ /** Injectable publishing client. The built-in receiver still verifies callbacks. */
71
+ client?: QStashPublishingClient;
72
+ /** Injectable transport (tests). Default: `@upstash/qstash`. */
73
+ transport?: QStashTransport;
74
+ /** Injectable clock for due-time calculations (tests). */
75
+ clock?: Clock;
76
+ };
77
+ declare function qstash(options?: QStashSchedulerOptions): A2Scheduler;
78
+ //#endregion
2
79
  export { type QStashSchedulerOptions, qstash };
@@ -1,2 +1,522 @@
1
- import { qstash } from "experimental-a2/scheduler-qstash";
1
+ import { t as A2Error } from "../session-clear-wHd5GCpZ-BnKSxReK.mjs";
2
+ import { i as deliverSchedulerClear, r as deliverSchedulerAppend } from "../server-DtFrWxi3-Boa6gdWO.mjs";
3
+ import { _ as serverInternals, l as assertSchedulerTargets, t as DRAIN_TIMINGS, u as classifySchedulerSendFailure } from "../internal-CvsrprnU-CRY89I-b.mjs";
4
+ import { n as platformVercelOidcToken } from "../platform-B4TnJtWu-CwcTyKg2.mjs";
5
+ import { t as retryableLazy } from "../retryable-lazy-DZWmHpii-Bye-W8q7.mjs";
6
+ import { n as SYSTEM_CLOCK } from "../store-N8PXxDAS-BWBgzBHp.mjs";
7
+ import { t as normalizeSchedulerTask } from "../scheduler-task-X1SToDjP-BVoWuInI.mjs";
8
+ //#region ../../node_modules/.pnpm/experimental-a2@0.22.0_@upstash+qstash@2.12.0_@vercel+queue@0.7.0_ai@7.0.130_zod@4.6.5__52060f00b21aecfab049c27fa3abd2f9/node_modules/experimental-a2/dist/scheduler-qstash.js
9
+ /**
10
+ * experimental-a2/scheduler-qstash — HTTP scheduler over Upstash QStash.
11
+ *
12
+ * QStash publishes one signed HTTP delivery per scheduler task. Drain tasks
13
+ * use an absolute, whole-second `notBefore` and a fixed-size deduplication id;
14
+ * append and clear tasks hash their stable task id with the callback URL, each
15
+ * under its own version tag.
16
+ * Store-outage successors carry a signed private generation and back off to
17
+ * one day without deriving their deduplication identity from the local clock.
18
+ * `handler(...servers)` verifies the signature over the raw request body
19
+ * before parsing it, then applies the same drain protocol as the Vercel
20
+ * scheduler adapter.
21
+ *
22
+ * `@upstash/qstash` is an optional peer dependency, imported lazily. The
23
+ * structural `transport` option keeps its types out of A2's public surface and
24
+ * gives tests a provider-faithful injection seam.
25
+ */
26
+ const qstashTransport = async (options, developmentMode) => {
27
+ const sdk = await import("@upstash/qstash").catch(() => {
28
+ throw classifySchedulerSendFailure(/* @__PURE__ */ new Error("experimental-a2/scheduler-qstash needs the '@upstash/qstash' package (optional peer dependency) — install it, or inject a transport"), "terminal");
29
+ });
30
+ const developmentOverride = developmentMode === void 0 ? {} : { devMode: developmentMode };
31
+ const client = options.client ?? new sdk.Client({
32
+ ...options.token === void 0 ? {} : { token: options.token },
33
+ ...developmentOverride
34
+ });
35
+ const receiver = new sdk.Receiver({
36
+ ...options.currentSigningKey === void 0 ? {} : { currentSigningKey: options.currentSigningKey },
37
+ ...options.nextSigningKey === void 0 ? {} : { nextSigningKey: options.nextSigningKey },
38
+ ...developmentOverride
39
+ });
40
+ return {
41
+ publish: (request) => {
42
+ const clientRequest = {
43
+ url: request.url,
44
+ body: request.body,
45
+ ...request.headers === void 0 ? {} : { headers: { ...request.headers } },
46
+ ...request.redact === void 0 ? {} : { redact: { header: [...request.redact.header] } },
47
+ deduplicationId: request.deduplicationId,
48
+ ...request.retries === void 0 ? {} : { retries: request.retries },
49
+ ...request.notBefore === void 0 ? {} : { notBefore: request.notBefore }
50
+ };
51
+ return client.publishJSON(clientRequest);
52
+ },
53
+ verify: (request) => receiver.verify(request)
54
+ };
55
+ };
56
+ const digestId = async (parts) => {
57
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(parts)));
58
+ return `a2_${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
59
+ };
60
+ const recordOf = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
61
+ const TRUSTED_SOURCE_HEADER = "x-vercel-trusted-oidc-idp-token";
62
+ const TRUSTED_SOURCE_DELIVERY_MARGIN_MS = 6e4;
63
+ const RESERVED_CALLBACK_HEADERS = /* @__PURE__ */ new Set([
64
+ "connection",
65
+ "content-length",
66
+ "host",
67
+ "keep-alive",
68
+ "proxy-authenticate",
69
+ "proxy-authorization",
70
+ "te",
71
+ "trailer",
72
+ "transfer-encoding",
73
+ "upgrade",
74
+ "x-vercel-oidc-token",
75
+ TRUSTED_SOURCE_HEADER
76
+ ]);
77
+ const callbackHeaders = (value) => {
78
+ if (value === void 0) return void 0;
79
+ let entries;
80
+ try {
81
+ entries = Object.entries(value);
82
+ } catch {
83
+ throw new TypeError("qstash() headers must be an HTTP header record");
84
+ }
85
+ const normalized = [];
86
+ const seen = /* @__PURE__ */ new Set();
87
+ for (const [name, headerValue] of entries) {
88
+ if (typeof headerValue !== "string") throw new TypeError("qstash() header values must be strings");
89
+ let entry;
90
+ try {
91
+ entry = [...new Headers([[name, headerValue]]).entries()][0];
92
+ } catch {
93
+ throw new TypeError("qstash() headers must contain valid HTTP header names and values");
94
+ }
95
+ if (entry === void 0) throw new TypeError("qstash() headers must contain valid HTTP header names and values");
96
+ const [normalizedName, normalizedValue] = entry;
97
+ if (seen.has(normalizedName)) throw new TypeError(`qstash() headers contain duplicate name '${normalizedName}'`);
98
+ if (normalizedName.startsWith("upstash-") || normalizedName.startsWith("content-type") || RESERVED_CALLBACK_HEADERS.has(normalizedName)) throw new TypeError(`qstash() headers cannot set reserved header '${normalizedName}'`);
99
+ seen.add(normalizedName);
100
+ normalized.push([normalizedName, normalizedValue]);
101
+ }
102
+ return normalized.length === 0 ? void 0 : Object.freeze(Object.fromEntries(normalized));
103
+ };
104
+ const publishHeaders = (configured, generated) => {
105
+ if (configured === void 0 && generated === void 0) return void 0;
106
+ const headers = new Headers();
107
+ const redacted = /* @__PURE__ */ new Set();
108
+ for (const [name, value] of Object.entries(configured ?? {})) {
109
+ headers.set(name, value);
110
+ redacted.add(name);
111
+ }
112
+ for (const [name, value] of Object.entries(generated?.headers ?? {})) {
113
+ headers.set(name, value);
114
+ redacted.add(name);
115
+ }
116
+ for (const name of generated?.redact?.header ?? []) {
117
+ const normalized = [...new Headers([[name, "redacted"]]).keys()][0];
118
+ if (normalized === void 0) throw new TypeError("qstash generated an invalid redaction header");
119
+ redacted.add(normalized);
120
+ }
121
+ const headerEntries = [...headers.entries()];
122
+ return {
123
+ ...headerEntries.length === 0 ? {} : { headers: Object.fromEntries(headerEntries) },
124
+ ...redacted.size === 0 ? {} : { redact: { header: [...redacted].toSorted() } }
125
+ };
126
+ };
127
+ const jwtExpirationMs = (token) => {
128
+ const parts = token.split(".");
129
+ const payloadPart = parts.length === 3 ? parts[1] : void 0;
130
+ if (payloadPart === void 0 || payloadPart.length === 0 || !/^[A-Za-z0-9_-]+$/.test(payloadPart) || payloadPart.length % 4 === 1) return null;
131
+ try {
132
+ const decode = globalThis.atob;
133
+ if (typeof decode !== "function") return null;
134
+ const binary = decode(payloadPart.replaceAll("-", "+").replaceAll("_", "/").padEnd(payloadPart.length + (4 - payloadPart.length % 4) % 4, "="));
135
+ const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
136
+ const expiration = recordOf(JSON.parse(new TextDecoder().decode(bytes)))?.["exp"];
137
+ if (typeof expiration !== "number" || !Number.isSafeInteger(expiration) || expiration <= 0 || expiration > Number.MAX_SAFE_INTEGER / 1e3) return null;
138
+ return expiration * 1e3;
139
+ } catch {
140
+ return null;
141
+ }
142
+ };
143
+ const previewTrustedSource = (firstDeliveryAt) => {
144
+ const token = platformVercelOidcToken();
145
+ if (token === null) return void 0;
146
+ const expiration = jwtExpirationMs(token);
147
+ if (expiration === null || firstDeliveryAt + TRUSTED_SOURCE_DELIVERY_MARGIN_MS > expiration) return;
148
+ return {
149
+ headers: { [TRUSTED_SOURCE_HEADER]: token },
150
+ redact: { header: [TRUSTED_SOURCE_HEADER] }
151
+ };
152
+ };
153
+ const RETRYABLE_HTTP_CLIENT_STATUSES = /* @__PURE__ */ new Set([
154
+ 408,
155
+ 409,
156
+ 425,
157
+ 429
158
+ ]);
159
+ const httpStatusOf = (error) => {
160
+ try {
161
+ const record = recordOf(error);
162
+ if (!record) return void 0;
163
+ const response = recordOf(record["response"]);
164
+ const statuses = [
165
+ record["status"],
166
+ record["statusCode"],
167
+ response?.["status"]
168
+ ].filter((value) => typeof value === "number" && Number.isInteger(value) && value >= 100 && value <= 599);
169
+ const [status] = statuses;
170
+ if (status === void 0) return void 0;
171
+ return statuses.every((candidate) => candidate === status) ? status : void 0;
172
+ } catch {
173
+ return;
174
+ }
175
+ };
176
+ const classifyQStashPublishFailure = (error) => {
177
+ const status = httpStatusOf(error);
178
+ const terminal = status !== void 0 && status >= 400 && status < 500 && !RETRYABLE_HTTP_CLIENT_STATUSES.has(status);
179
+ return classifySchedulerSendFailure(error, terminal ? "terminal" : "retryable");
180
+ };
181
+ const parseTask = (body) => {
182
+ let value;
183
+ try {
184
+ value = JSON.parse(body);
185
+ } catch {
186
+ return null;
187
+ }
188
+ const task = normalizeSchedulerTask(value);
189
+ const record = recordOf(value);
190
+ if (!task || !record) return null;
191
+ const encodedOutage = record["_a2QStash"];
192
+ if (encodedOutage === void 0) return { task };
193
+ const outage = recordOf(encodedOutage);
194
+ const generation = outage?.["generation"];
195
+ if (!outage || outage["version"] !== 1 || typeof generation !== "number" || !Number.isSafeInteger(generation) || generation < 0 || generation >= Number.MAX_SAFE_INTEGER) return null;
196
+ const rootDueAt = outage["rootDueAt"];
197
+ if (task.kind === "drain") {
198
+ if (typeof rootDueAt !== "number" || !Number.isInteger(rootDueAt) || rootDueAt % 1e3 !== 0) return null;
199
+ } else if (rootDueAt !== void 0) return null;
200
+ return {
201
+ task,
202
+ outage: {
203
+ version: 1,
204
+ generation,
205
+ ...rootDueAt === void 0 ? {} : { rootDueAt }
206
+ }
207
+ };
208
+ };
209
+ const DEFAULT_MAX_BODY_BYTES = 1048576;
210
+ const STORE_OUTAGE_BASE_DELAY_MS = 3e4;
211
+ const STORE_OUTAGE_MAX_DELAY_MS = 864e5;
212
+ const readBoundedBody = async (request, maxBytes) => {
213
+ const declared = request.headers.get("content-length");
214
+ if (declared !== null && /^\d+$/.test(declared) && Number(declared) > maxBytes) return null;
215
+ if (request.body === null) return "";
216
+ const reader = request.body.getReader();
217
+ const chunks = [];
218
+ let length = 0;
219
+ try {
220
+ for (;;) {
221
+ const { done, value } = await reader.read();
222
+ if (done) break;
223
+ length += value.byteLength;
224
+ if (length > maxBytes) {
225
+ await reader.cancel().catch(() => {});
226
+ return null;
227
+ }
228
+ chunks.push(value);
229
+ }
230
+ } finally {
231
+ reader.releaseLock();
232
+ }
233
+ const bytes = new Uint8Array(length);
234
+ let offset = 0;
235
+ for (const chunk of chunks) {
236
+ bytes.set(chunk, offset);
237
+ offset += chunk.byteLength;
238
+ }
239
+ return new TextDecoder().decode(bytes);
240
+ };
241
+ const storeOutage = (error) => error instanceof A2Error && (error.code === "STORE_UNAVAILABLE" || error.code === "STORE_NOT_CONFIGURED");
242
+ const response = {
243
+ ok: () => new Response("ok"),
244
+ unauthorized: () => new Response("unauthorized", { status: 401 }),
245
+ malformed: () => new Response("invalid a2 scheduler message", {
246
+ status: 489,
247
+ headers: { "Upstash-NonRetryable-Error": "true" }
248
+ }),
249
+ tooLarge: () => new Response("a2 scheduler message is too large", {
250
+ status: 489,
251
+ headers: { "Upstash-NonRetryable-Error": "true" }
252
+ })
253
+ };
254
+ const CALLBACK_PATH = "/api/a2/scheduler";
255
+ const DEFAULT_DEVELOPMENT_PORT = 3e3;
256
+ const developmentCallbackUrl = (portValue) => {
257
+ const port = portValue === void 0 || portValue === "" ? DEFAULT_DEVELOPMENT_PORT : Number(portValue);
258
+ if (!Number.isSafeInteger(port) || port < 1 || port > 65535 || portValue !== void 0 && portValue !== "" && !/^\d+$/.test(portValue)) throw new TypeError("qstash() could not infer url: PORT must be an integer from 1 to 65535 for local development");
259
+ return `http://localhost:${String(port)}${CALLBACK_PATH}`;
260
+ };
261
+ const inferCallbackUrl = () => {
262
+ const env = typeof process === "undefined" ? void 0 : process.env;
263
+ const vercelEnv = env?.["VERCEL_ENV"];
264
+ const variable = env?.["VERCEL"] !== "1" ? null : vercelEnv === "production" ? "VERCEL_PROJECT_PRODUCTION_URL" : vercelEnv === "preview" ? "VERCEL_BRANCH_URL" : null;
265
+ if (variable !== null) {
266
+ const host = env?.[variable];
267
+ if (!host) throw new TypeError(`qstash() could not infer url: ${variable} is missing`);
268
+ let origin;
269
+ try {
270
+ origin = new URL(`https://${host}`);
271
+ } catch {
272
+ throw new TypeError(`qstash() could not infer url: ${variable} must be a hostname`);
273
+ }
274
+ if (origin.host !== host || origin.pathname !== "/" || origin.search !== "" || origin.hash !== "" || origin.username !== "" || origin.password !== "" || origin.port !== "") throw new TypeError(`qstash() could not infer url: ${variable} must be a hostname`);
275
+ return {
276
+ callbackUrl: new URL(CALLBACK_PATH, origin).toString(),
277
+ developmentMode: false,
278
+ ...vercelEnv === "preview" ? { inferredVercelPreview: true } : {}
279
+ };
280
+ }
281
+ if (env === void 0) throw new TypeError("qstash() needs url when the runtime cannot identify local development");
282
+ if (env["NODE_ENV"] === "production") throw new TypeError("qstash() needs url in production outside a Vercel production or preview deployment");
283
+ return {
284
+ callbackUrl: developmentCallbackUrl(env["PORT"]),
285
+ developmentMode: true
286
+ };
287
+ };
288
+ function qstash(options = {}) {
289
+ const env = typeof process === "undefined" ? void 0 : process.env;
290
+ const { callbackUrl, developmentMode, inferredVercelPreview } = options.url === void 0 ? inferCallbackUrl() : {
291
+ callbackUrl: options.url,
292
+ ...env?.["NODE_ENV"] === "production" ? { developmentMode: false } : {}
293
+ };
294
+ let parsedUrl;
295
+ try {
296
+ parsedUrl = new URL(callbackUrl);
297
+ } catch {
298
+ throw new TypeError("qstash() needs an absolute callback url");
299
+ }
300
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") throw new TypeError("qstash() callback url must use http or https");
301
+ if (options.client !== void 0 && options.transport !== void 0) throw new TypeError("qstash() cannot combine client and transport");
302
+ if (options.client !== void 0 && options.token !== void 0) throw new TypeError("qstash() cannot combine client and token");
303
+ const url = parsedUrl.toString();
304
+ const configuredHeaders = callbackHeaders(options.headers);
305
+ const { retries } = options;
306
+ if (retries !== void 0 && (!Number.isSafeInteger(retries) || retries < 0)) throw new TypeError("qstash() retries must be a non-negative integer");
307
+ const maxBodyBytes = options.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES;
308
+ if (!Number.isSafeInteger(maxBodyBytes) || maxBodyBytes < 1) throw new TypeError("qstash() maxBodyBytes must be a positive integer");
309
+ const clock = options.clock ?? SYSTEM_CLOCK;
310
+ const transport = retryableLazy(() => options.transport ? Promise.resolve(options.transport) : qstashTransport(options, developmentMode)).get;
311
+ const storeOutageDeduplicationId = (task, outage) => {
312
+ if (task.kind === "clear") return digestId([
313
+ "a2:scheduler-qstash:store-outage:clear:v1",
314
+ url,
315
+ task.contract,
316
+ task.sessionId,
317
+ task.id,
318
+ outage.generation
319
+ ]);
320
+ if (task.kind === "append") return digestId([
321
+ "a2:scheduler-qstash:store-outage:append:v1",
322
+ url,
323
+ task.contract,
324
+ task.sessionId,
325
+ task.id,
326
+ outage.generation
327
+ ]);
328
+ const { rootDueAt } = outage;
329
+ if (rootDueAt === void 0) throw new TypeError("qstash store-outage drain needs a root dueAt");
330
+ return digestId([
331
+ "a2:scheduler-qstash:store-outage:drain:v1",
332
+ url,
333
+ task.contract,
334
+ task.sessionId,
335
+ rootDueAt,
336
+ outage.generation
337
+ ]);
338
+ };
339
+ const sendTask = async (task, outage) => {
340
+ const nowMs = clock.now().getTime();
341
+ const requestedDueAt = task.dueAt;
342
+ if (!Number.isFinite(requestedDueAt)) throw classifySchedulerSendFailure(/* @__PURE__ */ new TypeError("qstash scheduler dueAt must be a finite number"), "terminal");
343
+ const dueAt = requestedDueAt <= nowMs ? Math.floor(nowMs / 1e3) * 1e3 : Math.ceil(requestedDueAt / 1e3) * 1e3;
344
+ const normalizedTask = task.kind === "append" ? {
345
+ version: 1,
346
+ kind: "append",
347
+ id: task.id,
348
+ contract: task.contract,
349
+ sessionId: task.sessionId,
350
+ dueAt,
351
+ events: task.events,
352
+ ...task.originIndex === void 0 ? {} : { originIndex: task.originIndex }
353
+ } : task.kind === "clear" ? {
354
+ version: 1,
355
+ kind: "clear",
356
+ id: task.id,
357
+ contract: task.contract,
358
+ sessionId: task.sessionId,
359
+ dueAt,
360
+ ifLastIndex: task.ifLastIndex
361
+ } : {
362
+ version: 1,
363
+ kind: "drain",
364
+ contract: task.contract,
365
+ sessionId: task.sessionId,
366
+ dueAt
367
+ };
368
+ const message = {
369
+ ...normalizedTask,
370
+ ...outage === void 0 ? {} : { _a2QStash: outage }
371
+ };
372
+ const sizeCheckedMessage = outage === void 0 ? {
373
+ ...normalizedTask,
374
+ _a2QStash: normalizedTask.kind !== "drain" ? {
375
+ version: 1,
376
+ generation: Number.MAX_SAFE_INTEGER
377
+ } : {
378
+ version: 1,
379
+ generation: Number.MAX_SAFE_INTEGER,
380
+ rootDueAt: dueAt
381
+ }
382
+ } : message;
383
+ let bodyBytes;
384
+ try {
385
+ bodyBytes = new TextEncoder().encode(JSON.stringify(sizeCheckedMessage)).byteLength;
386
+ } catch (error) {
387
+ throw classifySchedulerSendFailure(error, "terminal");
388
+ }
389
+ if (bodyBytes > maxBodyBytes) throw classifySchedulerSendFailure(/* @__PURE__ */ new RangeError("qstash scheduler message exceeds maxBodyBytes"), "terminal");
390
+ const deduplicationId = outage !== void 0 ? await storeOutageDeduplicationId(task, outage) : task.kind === "append" ? await digestId([
391
+ "a2:scheduler-qstash:append:v1",
392
+ url,
393
+ task.id
394
+ ]) : task.kind === "clear" ? await digestId([
395
+ "a2:scheduler-qstash:clear:v1",
396
+ url,
397
+ task.id
398
+ ]) : await digestId([
399
+ "a2:scheduler-qstash:v1",
400
+ url,
401
+ task.contract,
402
+ task.sessionId,
403
+ dueAt
404
+ ]);
405
+ const trustedSource = inferredVercelPreview === true ? previewTrustedSource(Math.max(nowMs, dueAt)) : void 0;
406
+ const deliveryHeaders = publishHeaders(configuredHeaders, trustedSource);
407
+ const t = await transport();
408
+ try {
409
+ await t.publish({
410
+ url,
411
+ body: message,
412
+ ...deliveryHeaders,
413
+ ...dueAt <= nowMs ? {} : { notBefore: dueAt / 1e3 },
414
+ deduplicationId,
415
+ ...retries === void 0 ? {} : { retries }
416
+ });
417
+ } catch (error) {
418
+ throw classifyQStashPublishFailure(error);
419
+ }
420
+ };
421
+ const sendStoreOutageSuccessor = async (task, outage) => {
422
+ const generation = (outage?.generation ?? -1) + 1;
423
+ const delayMs = Math.min(STORE_OUTAGE_MAX_DELAY_MS, STORE_OUTAGE_BASE_DELAY_MS * 4 ** Math.min(generation, 6));
424
+ const nowMs = clock.now().getTime();
425
+ const dueAt = Math.ceil((nowMs + delayMs) / 1e3) * 1e3;
426
+ const nextOutage = task.kind !== "drain" ? {
427
+ version: 1,
428
+ generation
429
+ } : {
430
+ version: 1,
431
+ generation,
432
+ rootDueAt: outage?.rootDueAt ?? task.dueAt
433
+ };
434
+ await sendTask({
435
+ ...task,
436
+ dueAt
437
+ }, nextOutage);
438
+ };
439
+ const successorDueAt = (message) => {
440
+ const minimumDueAt = clock.now().getTime() + DRAIN_TIMINGS.claimTtlMs + DRAIN_TIMINGS.watchdogGraceMs;
441
+ const beats = Math.max(1, Math.ceil((minimumDueAt - message.dueAt) / DRAIN_TIMINGS.claimHeartbeatMs));
442
+ return message.dueAt + beats * DRAIN_TIMINGS.claimHeartbeatMs;
443
+ };
444
+ return {
445
+ async schedule(task) {
446
+ await sendTask(task);
447
+ },
448
+ handler(...servers) {
449
+ assertSchedulerTargets(servers);
450
+ const byContract = /* @__PURE__ */ new Map();
451
+ for (const server of servers) byContract.set(server.contract.name, server);
452
+ return async (req) => {
453
+ const signature = req.headers.get("upstash-signature");
454
+ if (!signature) return response.unauthorized();
455
+ const body = await readBoundedBody(req, maxBodyBytes);
456
+ if (body === null) return response.tooLarge();
457
+ const upstashRegion = req.headers.get("upstash-region");
458
+ const t = await transport();
459
+ try {
460
+ if (!await t.verify({
461
+ signature,
462
+ body,
463
+ url,
464
+ ...upstashRegion === null ? {} : { upstashRegion }
465
+ })) return response.unauthorized();
466
+ } catch {
467
+ return response.unauthorized();
468
+ }
469
+ const parsed = parseTask(body);
470
+ if (!parsed) return response.malformed();
471
+ const { task, outage } = parsed;
472
+ const server = byContract.get(task.contract);
473
+ if (!server) throw new Error(`a2 scheduler: no server for contract '${task.contract}' — pass it to scheduler.handler(...)`);
474
+ const internals = serverInternals.get(server);
475
+ if (task.kind !== "drain") {
476
+ try {
477
+ if (task.kind === "append") await deliverSchedulerAppend(server, task);
478
+ else await deliverSchedulerClear(server, task);
479
+ } catch (error) {
480
+ if (!storeOutage(error)) throw error;
481
+ await sendStoreOutageSuccessor(task, outage);
482
+ }
483
+ return response.ok();
484
+ }
485
+ const nextDueAt = successorDueAt(task);
486
+ let result;
487
+ try {
488
+ result = internals ? await internals.schedulerDrain(task.sessionId, { watchdogDueAt: nextDueAt }) : {
489
+ ...await server.drain(task.sessionId),
490
+ outcome: "unknown"
491
+ };
492
+ } catch (error) {
493
+ if (!storeOutage(error)) throw error;
494
+ await sendStoreOutageSuccessor(task, outage);
495
+ return response.ok();
496
+ }
497
+ if (result.settled) return response.ok();
498
+ if (result.outcome === "busy" || result.outcome === "stalled" || result.outcome === "failed") {
499
+ if (result.schedulerArm) await result.schedulerArm;
500
+ else await sendTask({
501
+ version: 1,
502
+ kind: "drain",
503
+ contract: task.contract,
504
+ sessionId: task.sessionId,
505
+ dueAt: nextDueAt
506
+ });
507
+ return response.ok();
508
+ }
509
+ await sendTask({
510
+ version: 1,
511
+ kind: "drain",
512
+ contract: task.contract,
513
+ sessionId: task.sessionId,
514
+ dueAt: nextDueAt
515
+ });
516
+ return response.ok();
517
+ };
518
+ }
519
+ };
520
+ }
521
+ //#endregion
2
522
  export { qstash };
@@ -1,2 +1,38 @@
1
- import { VercelQueuesOptions, vercelQueues } from "experimental-a2/scheduler-vercel";
1
+ import { n as Clock } from "../store-D0MhBvg6-4Z2L0Kqd.mjs";
2
+ import { i as SchedulerTask, t as A2Scheduler } from "../server-qgez0Xny-D5mLfqFQ.mjs";
3
+ //#region ../../node_modules/.pnpm/experimental-a2@0.22.0_@upstash+qstash@2.12.0_@vercel+queue@0.7.0_ai@7.0.130_zod@4.6.5__52060f00b21aecfab049c27fa3abd2f9/node_modules/experimental-a2/dist/scheduler-vercel.d.ts
4
+ type QueueDeliveryMetadata = {
5
+ messageId: string;
6
+ deliveryCount: number;
7
+ };
8
+ /** What this module needs from a Vercel Queues-compatible transport. */
9
+ type QueueTransport = {
10
+ send(topic: string, message: SchedulerTask, options?: {
11
+ delaySeconds?: number;
12
+ idempotencyKey?: string;
13
+ retentionSeconds?: number;
14
+ }): Promise<unknown>;
15
+ /**
16
+ * Wrap the delivery handler into a route. The handler throws
17
+ * `DrainUnsettled` when the session needs redelivery — transports
18
+ * with a polite reschedule (visibility change) should use it there
19
+ * instead of surfacing an error; anything else thrown is a genuine
20
+ * failure and should stay loud.
21
+ */
22
+ handleCallback(handler: (message: unknown, metadata: QueueDeliveryMetadata) => Promise<void>): (req: Request) => Promise<Response>;
23
+ /** Is this send error the idempotency-key collision? (= success) */
24
+ isDuplicate(error: unknown): boolean;
25
+ };
26
+ type VercelQueuesOptions = {
27
+ /** Queue topic matching `[A-Za-z0-9_-]+`. Default `'a2'`. */
28
+ topic?: string;
29
+ /** Queue SDK deployment scope for all tasks. Default: VERCEL_DEPLOYMENT_ID; null opts out. */
30
+ deploymentId?: string | null;
31
+ /** Injectable transport (tests). Default: `@vercel/queue`. */
32
+ transport?: QueueTransport;
33
+ /** Injectable clock for due-time calculations (tests). */
34
+ clock?: Clock;
35
+ };
36
+ declare function vercelQueues(options?: VercelQueuesOptions): A2Scheduler;
37
+ //#endregion
2
38
  export { type VercelQueuesOptions, vercelQueues };