@sentry/junior 0.305.0 → 0.306.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.
- package/dist/{adapter-context-BpvbUki8.js → adapter-context-CnY-i32r.js} +2 -2
- package/dist/{admin-CoDt35ny.js → admin-BLLdLnXh.js} +2 -2
- package/dist/{agent-runner-C5d6rY5g.js → agent-runner-BaLjEjPR.js} +261 -190
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -8
- package/dist/api.d.ts +19 -4
- package/dist/api.js +137 -40
- package/dist/{app-Cs157Zc5.d.ts → app-DvYbM9UD.d.ts} +2 -2
- package/dist/app.d.ts +1 -1
- package/dist/app.js +487 -434
- package/dist/{background-compaction-queue-BTqMIfTA.js → background-compaction-queue-D2wzxtGU.js} +2 -2
- package/dist/{briefs-BRdznF7c.js → briefs-DvyzXfrF.js} +3 -3
- package/dist/{catalog-runtime-J52Tej47.js → catalog-runtime-B1R-nHd3.js} +1 -1
- package/dist/cli/chat.js +15 -15
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{config-CBZp0udd.js → config-DUD-zMvp.js} +111 -13
- package/dist/{connections-BYmuJ6Vm.js → connections-CDhsqPcC.js} +6 -6
- package/dist/{continue-in-slack-Cvot6S38.js → continue-in-slack-BXQizz9o.js} +5 -5
- package/dist/{conversation-BOqdRtUx.js → conversation--f85g4zL.js} +132 -132
- package/dist/{conversation-feed-CgpgP7yi.js → conversation-feed-BNs9KiqC.js} +1 -1
- package/dist/{conversation-privacy-D2pOzBNl.js → conversation-privacy-YE54gMN8.js} +1 -1
- package/dist/{conversation-turn-CI8WDpnK.js → conversation-turn-BzdmrHb0.js} +22 -40
- package/dist/{credential-sync-COqnZ1Dx.js → credential-sync-Cdm-e1vJ.js} +14 -13
- package/dist/{db-DU84dCVu.js → db-DV2ZUb1Y.js} +90 -11
- package/dist/{db-zbN5ZV_o.d.ts → db-pH357Dkt.d.ts} +1 -1
- package/dist/{executor-CFyrgOu1.js → executor-CjNhwwnj.js} +47 -4
- package/dist/{history-m2-ceTTX.js → history-N7IVbUom.js} +5 -1
- package/dist/{install-CQ76CfRw.js → install-DbD7C5td.js} +2 -2
- package/dist/instrumentation.js +2 -2
- package/dist/{lineage-DLd2UxVP.js → lineage-BFdIPb3o.js} +2 -2
- package/dist/{logging-BPNTQVFu.js → logging-oYpJYr-S.js} +1 -1
- package/dist/{message-BWJLeQ5e.js → message-BBPcMKJY.js} +8 -8
- package/dist/{model-input-DoM9Ht-d.js → model-input-DYYF3a8B.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +4 -4
- package/dist/{oauth-callback-server-DeHbnAQl.js → oauth-callback-server-C7Q987su.js} +2 -2
- package/dist/{projection-CcFBVFUo.js → projection-CWXDE0f6.js} +7738 -6166
- package/dist/{prompt-C5LREK2p.js → prompt-P3eRqO8C.js} +15 -7
- package/dist/{queue-B2AAL3ym.js → queue-7FSijgqG.js} +4 -4
- package/dist/{registry-BjZZqKqi.js → registry-1pzXmplY.js} +1 -1
- package/dist/{resolve-CeJgXuH1.js → resolve-n87oXY-d.js} +3 -3
- package/dist/{result-icDrueyB.js → result-BmF9v9bv.js} +9 -9
- package/dist/{runner-nVfMkMMB.js → runner-4j7ZsxP5.js} +13 -15
- package/dist/{sandbox-egress-signals-H9vQ5qRf.js → sandbox-egress-signals-BRQI8HvT.js} +1 -1
- package/dist/{automation-CuA3yEcD.js → schedule-CHPWQn-x.js} +347 -5
- package/dist/{schema-CKcu-IK6.d.ts → schema-CVbIjrF3.d.ts} +71 -1
- package/dist/{schema-Bx0Mlo32.js → schema-D7iIEh6t.js} +52 -6
- package/dist/{service-account-Dw06p3zm.js → service-account-BDQ9xzta.js} +3 -3
- package/dist/{service-account-DU5865XA.js → service-account-DzQiOmqa.js} +5 -5
- package/dist/{session-stop-uotLtp4g.js → session-stop-BQxgHR4X.js} +854 -160
- package/dist/{skills-Bex1EaO5.js → skills-CPf4vNuC.js} +2 -2
- package/dist/{slack-conversation-unfurl-EPG3riWF.js → slack-conversation-unfurl-B1KEptUg.js} +10 -9
- package/dist/{spawn-CoD3vDuS.js → spawn-CjGddiAU.js} +6 -6
- package/dist/{state-nCR4Muhn.js → state-9wfj6aSD.js} +4 -4
- package/dist/{stop-BFVd0P0m.js → stop-CsQGuN5n.js} +62 -117
- package/dist/{store-Ca6G962n.js → store-Dz3YZ7gQ.js} +5 -5
- package/dist/{task-queue-BLPZU6kC.js → task-queue-CFlrJguF.js} +3 -3
- package/dist/{task-runner-xsOPIxCZ.js → task-runner-frzlUvFD.js} +8 -9
- package/dist/{thread-context-BOvZhsKK.js → thread-context-C4QuZlM8.js} +8 -91
- package/dist/turn-session-routing-BXaubz2w.js +244 -0
- package/dist/{turn-user-message-BrhuyYrH.js → turn-user-message-DNC0eRZ7.js} +3 -3
- package/dist/users-XCCKn3xW.js +181 -0
- package/dist/{validation-BnY9K5WB.js → validation-L5fdjmFX.js} +1 -1
- package/dist/{version-qROlRQGF.js → version-BFmuwgxP.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-CxUiOraX.js → viewer-DKOeHpv3.js} +3 -3
- package/dist/{warmup--Gkz7iB-.js → warmup-mTMIatCV.js} +267 -272
- package/dist/{web-message-id-lNodcCOI.js → web-message-id-CUaSiGme.js} +16 -1
- package/dist/{worker-DJ8d9fmD.js → worker-Bz4KNxjI.js} +7 -7
- package/migrations/0114_plan_items.sql +22 -0
- package/migrations/meta/0114_snapshot.json +5203 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +6 -6
- package/dist/schedule-cP0AACm1.js +0 -344
- package/dist/turn-session-routing-2bW2qfeb.js +0 -1792
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/junior",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.306.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@logtape/logtape": "^2.1.1",
|
|
65
65
|
"@modelcontextprotocol/sdk": "1.32.0",
|
|
66
66
|
"@neondatabase/serverless": "^1.1.0",
|
|
67
|
-
"@sentry/junior-plugin-api": "0.
|
|
67
|
+
"@sentry/junior-plugin-api": "0.306.0",
|
|
68
68
|
"@sentry/nitro": "11.10.0",
|
|
69
69
|
"@sentry/node": "11.10.0",
|
|
70
70
|
"@sentry/server-utils": "11.10.0",
|
|
@@ -115,10 +115,10 @@
|
|
|
115
115
|
"@emnapi/core": "^1.10.0",
|
|
116
116
|
"@emnapi/runtime": "^1.10.0",
|
|
117
117
|
"@hono/node-server": "2.1.3",
|
|
118
|
-
"@sentry/junior-github": "0.
|
|
119
|
-
"@sentry/junior-memory": "0.
|
|
120
|
-
"@sentry/junior-notion": "0.
|
|
121
|
-
"@sentry/junior-sentry": "0.
|
|
118
|
+
"@sentry/junior-github": "0.306.0",
|
|
119
|
+
"@sentry/junior-memory": "0.306.0",
|
|
120
|
+
"@sentry/junior-notion": "0.306.0",
|
|
121
|
+
"@sentry/junior-sentry": "0.306.0",
|
|
122
122
|
"@sentry/junior-testing": "0.0.0",
|
|
123
123
|
"@types/node": "^24.19.2",
|
|
124
124
|
"@types/pg": "^8.15.6",
|
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import * as z from "zod";
|
|
2
|
-
// src/chat/scheduled-automations/cadence.ts
|
|
3
|
-
const FORMATTERS = /* @__PURE__ */ new Map();
|
|
4
|
-
function getFormatter(timezone) {
|
|
5
|
-
const existing = FORMATTERS.get(timezone);
|
|
6
|
-
if (existing) return existing;
|
|
7
|
-
const formatter = new Intl.DateTimeFormat("en-US", {
|
|
8
|
-
timeZone: timezone,
|
|
9
|
-
hour12: false,
|
|
10
|
-
year: "numeric",
|
|
11
|
-
month: "2-digit",
|
|
12
|
-
day: "2-digit",
|
|
13
|
-
hour: "2-digit",
|
|
14
|
-
minute: "2-digit",
|
|
15
|
-
second: "2-digit"
|
|
16
|
-
});
|
|
17
|
-
FORMATTERS.set(timezone, formatter);
|
|
18
|
-
return formatter;
|
|
19
|
-
}
|
|
20
|
-
function normalizeHour(hour) {
|
|
21
|
-
return hour === 24 ? 0 : hour;
|
|
22
|
-
}
|
|
23
|
-
function getLocalDateWeekday(date) {
|
|
24
|
-
return new Date(Date.UTC(date.year, date.month - 1, date.day)).getUTCDay();
|
|
25
|
-
}
|
|
26
|
-
function getWeekStart(date) {
|
|
27
|
-
return addDays(date, -((getLocalDateWeekday(date) + 6) % 7));
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Check that a value is an IANA time zone that this runtime knows. This module
|
|
31
|
-
* has no runtime imports, so the dashboard client bundle can use it.
|
|
32
|
-
*/
|
|
33
|
-
function isValidTimeZone(timezone) {
|
|
34
|
-
try {
|
|
35
|
-
new Intl.DateTimeFormat("en-US", { timeZone: timezone }).format();
|
|
36
|
-
return true;
|
|
37
|
-
} catch {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/** Resolve a UTC timestamp into calendar parts for a named time zone. */
|
|
42
|
-
function getZonedDateTimeParts(timestampMs, timezone) {
|
|
43
|
-
const parts = getFormatter(timezone).formatToParts(new Date(timestampMs));
|
|
44
|
-
const values = new Map(parts.map((part) => [part.type, part.value]));
|
|
45
|
-
const year = Number(values.get("year"));
|
|
46
|
-
const month = Number(values.get("month"));
|
|
47
|
-
const day = Number(values.get("day"));
|
|
48
|
-
return {
|
|
49
|
-
year,
|
|
50
|
-
month,
|
|
51
|
-
day,
|
|
52
|
-
hour: normalizeHour(Number(values.get("hour"))),
|
|
53
|
-
minute: Number(values.get("minute")),
|
|
54
|
-
second: Number(values.get("second")),
|
|
55
|
-
weekday: getLocalDateWeekday({
|
|
56
|
-
year,
|
|
57
|
-
month,
|
|
58
|
-
day
|
|
59
|
-
})
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function getTimeZoneOffsetMs(timestampMs, timezone) {
|
|
63
|
-
const parts = getZonedDateTimeParts(timestampMs, timezone);
|
|
64
|
-
return Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second) - timestampMs;
|
|
65
|
-
}
|
|
66
|
-
function localDateTimeToTimestampMs(args) {
|
|
67
|
-
const localAsUtcMs = Date.UTC(args.date.year, args.date.month - 1, args.date.day, args.time.hour, args.time.minute, 0);
|
|
68
|
-
const offsets = /* @__PURE__ */ new Set();
|
|
69
|
-
for (const probeDeltaMs of [
|
|
70
|
-
-1296e5,
|
|
71
|
-
-432e5,
|
|
72
|
-
0,
|
|
73
|
-
432e5,
|
|
74
|
-
1296e5
|
|
75
|
-
]) offsets.add(getTimeZoneOffsetMs(localAsUtcMs + probeDeltaMs, args.timezone));
|
|
76
|
-
const matches = [...offsets].map((offsetMs) => localAsUtcMs - offsetMs).filter((timestampMs) => {
|
|
77
|
-
const parts = getZonedDateTimeParts(timestampMs, args.timezone);
|
|
78
|
-
return parts.year === args.date.year && parts.month === args.date.month && parts.day === args.date.day && parts.hour === args.time.hour && parts.minute === args.time.minute;
|
|
79
|
-
});
|
|
80
|
-
if (matches.length === 0) return;
|
|
81
|
-
return Math.min(...matches);
|
|
82
|
-
}
|
|
83
|
-
/** Resolve local time, rejecting DST gaps and choosing the earlier instant in a fold. */
|
|
84
|
-
function resolveLocalScheduleAtMs(args) {
|
|
85
|
-
const date = parseLocalDate(args.date);
|
|
86
|
-
if (!date) return;
|
|
87
|
-
return localDateTimeToTimestampMs({
|
|
88
|
-
date,
|
|
89
|
-
time: args.time,
|
|
90
|
-
timezone: args.timezone
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
function daysBetween(left, right) {
|
|
94
|
-
return Math.floor((Date.UTC(right.year, right.month - 1, right.day) - Date.UTC(left.year, left.month - 1, left.day)) / 864e5);
|
|
95
|
-
}
|
|
96
|
-
function weeklyRecurrenceMatchesDate(date, start, recurrence) {
|
|
97
|
-
if (compareDate(date, start) < 0) return false;
|
|
98
|
-
return normalizeWeekdays(recurrence.weekdays).includes(getLocalDateWeekday(date)) && Math.floor(daysBetween(getWeekStart(start), getWeekStart(date)) / 7) % recurrence.interval === 0;
|
|
99
|
-
}
|
|
100
|
-
function greatestCommonDivisor(left, right) {
|
|
101
|
-
let a = Math.abs(left);
|
|
102
|
-
let b = Math.abs(right);
|
|
103
|
-
while (b !== 0) [a, b] = [b, a % b];
|
|
104
|
-
return a;
|
|
105
|
-
}
|
|
106
|
-
function findNextRunAtMs(args) {
|
|
107
|
-
const start = parseLocalDate(args.recurrence.startDate);
|
|
108
|
-
const interval = args.recurrence.interval;
|
|
109
|
-
if (!start || !Number.isInteger(interval) || interval <= 0) return;
|
|
110
|
-
const searchFrom = compareDate(args.searchFrom, start) < 0 ? start : args.searchFrom;
|
|
111
|
-
if (args.recurrence.frequency === "daily") {
|
|
112
|
-
const offsetDays = daysBetween(start, searchFrom);
|
|
113
|
-
let candidateDate = addDays(start, Math.ceil(offsetDays / interval) * interval);
|
|
114
|
-
const gregorianCycleDays = 146097;
|
|
115
|
-
const candidateCount = gregorianCycleDays / greatestCommonDivisor(gregorianCycleDays, interval);
|
|
116
|
-
for (let attempts = 0; attempts < candidateCount; attempts += 1) {
|
|
117
|
-
const candidate = buildCandidate({
|
|
118
|
-
date: candidateDate,
|
|
119
|
-
recurrence: args.recurrence,
|
|
120
|
-
timezone: args.timezone
|
|
121
|
-
});
|
|
122
|
-
if (candidate !== void 0 && candidate > args.afterMs) return candidate;
|
|
123
|
-
candidateDate = addDays(candidateDate, interval);
|
|
124
|
-
}
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (args.recurrence.frequency === "weekly") {
|
|
128
|
-
if (normalizeWeekdays(args.recurrence.weekdays).length === 0) return;
|
|
129
|
-
let candidateDate = searchFrom;
|
|
130
|
-
const gregorianCycleDays = 146097;
|
|
131
|
-
const cadenceDays = interval * 7;
|
|
132
|
-
const searchDays = gregorianCycleDays * cadenceDays / greatestCommonDivisor(gregorianCycleDays, cadenceDays);
|
|
133
|
-
for (let attempts = 0; attempts < searchDays; attempts += 1) {
|
|
134
|
-
if (weeklyRecurrenceMatchesDate(candidateDate, start, args.recurrence)) {
|
|
135
|
-
const candidate = buildCandidate({
|
|
136
|
-
date: candidateDate,
|
|
137
|
-
recurrence: args.recurrence,
|
|
138
|
-
timezone: args.timezone
|
|
139
|
-
});
|
|
140
|
-
if (candidate !== void 0 && candidate > args.afterMs) return candidate;
|
|
141
|
-
}
|
|
142
|
-
candidateDate = addDays(candidateDate, 1);
|
|
143
|
-
}
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
if (args.recurrence.frequency === "monthly") {
|
|
147
|
-
const startMonth = start.year * 12 + start.month - 1;
|
|
148
|
-
const searchMonth = searchFrom.year * 12 + searchFrom.month - 1;
|
|
149
|
-
let candidateMonth = startMonth + Math.ceil((searchMonth - startMonth) / interval) * interval;
|
|
150
|
-
const gregorianCycleMonths = 4800;
|
|
151
|
-
const candidateCount = gregorianCycleMonths / greatestCommonDivisor(gregorianCycleMonths, interval);
|
|
152
|
-
for (let attempts = 0; attempts < candidateCount; attempts += 1) {
|
|
153
|
-
const candidateDate = {
|
|
154
|
-
year: Math.floor(candidateMonth / 12),
|
|
155
|
-
month: candidateMonth % 12 + 1,
|
|
156
|
-
day: args.recurrence.dayOfMonth ?? 0
|
|
157
|
-
};
|
|
158
|
-
if (compareDate(candidateDate, searchFrom) >= 0) {
|
|
159
|
-
const candidate = buildCandidate({
|
|
160
|
-
date: candidateDate,
|
|
161
|
-
recurrence: args.recurrence,
|
|
162
|
-
timezone: args.timezone
|
|
163
|
-
});
|
|
164
|
-
if (candidate !== void 0 && candidate > args.afterMs) return candidate;
|
|
165
|
-
}
|
|
166
|
-
candidateMonth += interval;
|
|
167
|
-
}
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
let candidateYear = start.year + Math.ceil((searchFrom.year - start.year) / interval) * interval;
|
|
171
|
-
const candidateCount = 400 / greatestCommonDivisor(400, interval);
|
|
172
|
-
for (let attempts = 0; attempts < candidateCount; attempts += 1) {
|
|
173
|
-
const candidateDate = {
|
|
174
|
-
year: candidateYear,
|
|
175
|
-
month: args.recurrence.month ?? 0,
|
|
176
|
-
day: args.recurrence.dayOfMonth ?? 0
|
|
177
|
-
};
|
|
178
|
-
if (compareDate(candidateDate, searchFrom) >= 0) {
|
|
179
|
-
const candidate = buildCandidate({
|
|
180
|
-
date: candidateDate,
|
|
181
|
-
recurrence: args.recurrence,
|
|
182
|
-
timezone: args.timezone
|
|
183
|
-
});
|
|
184
|
-
if (candidate !== void 0 && candidate > args.afterMs) return candidate;
|
|
185
|
-
}
|
|
186
|
-
candidateYear += interval;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
/** Compute the first recurring calendar occurrence strictly after a timestamp. */
|
|
190
|
-
function getFirstRunAtMs(args) {
|
|
191
|
-
return findNextRunAtMs({
|
|
192
|
-
...args,
|
|
193
|
-
searchFrom: getLocalDate(args.afterMs, args.timezone)
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
function compareDate(left, right) {
|
|
197
|
-
return Date.UTC(left.year, left.month - 1, left.day) - Date.UTC(right.year, right.month - 1, right.day);
|
|
198
|
-
}
|
|
199
|
-
function addDays(date, days) {
|
|
200
|
-
const next = new Date(Date.UTC(date.year, date.month - 1, date.day + days));
|
|
201
|
-
return {
|
|
202
|
-
year: next.getUTCFullYear(),
|
|
203
|
-
month: next.getUTCMonth() + 1,
|
|
204
|
-
day: next.getUTCDate()
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function daysInMonth(year, month) {
|
|
208
|
-
return new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
209
|
-
}
|
|
210
|
-
function parseLocalDate(value) {
|
|
211
|
-
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
212
|
-
if (!match) return;
|
|
213
|
-
const year = Number(match[1]);
|
|
214
|
-
const month = Number(match[2]);
|
|
215
|
-
const day = Number(match[3]);
|
|
216
|
-
if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day) || month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month)) return;
|
|
217
|
-
return {
|
|
218
|
-
year,
|
|
219
|
-
month,
|
|
220
|
-
day
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function getLocalDate(timestampMs, timezone) {
|
|
224
|
-
const parts = getZonedDateTimeParts(timestampMs, timezone);
|
|
225
|
-
return {
|
|
226
|
-
year: parts.year,
|
|
227
|
-
month: parts.month,
|
|
228
|
-
day: parts.day
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
function normalizeWeekdays(values) {
|
|
232
|
-
return [...new Set((values ?? []).filter((value) => value >= 0 && value <= 6))].sort((a, b) => a - b);
|
|
233
|
-
}
|
|
234
|
-
function buildCandidate(args) {
|
|
235
|
-
return localDateTimeToTimestampMs({
|
|
236
|
-
date: args.date,
|
|
237
|
-
time: args.recurrence.time,
|
|
238
|
-
timezone: args.timezone
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
/** Return the next fire time after a completed run, when the task recurs. */
|
|
242
|
-
function getNextRunAtMs(task, scheduledForMs, afterMs = scheduledForMs) {
|
|
243
|
-
if (task.schedule.kind !== "recurring") return;
|
|
244
|
-
const recurrence = task.schedule.recurrence;
|
|
245
|
-
if (!recurrence || !Number.isFinite(recurrence.interval) || recurrence.interval <= 0) return;
|
|
246
|
-
const timezone = task.schedule.timezone;
|
|
247
|
-
const afterDate = getLocalDate(afterMs, timezone);
|
|
248
|
-
const nextScheduledDate = addDays(getLocalDate(scheduledForMs, timezone), 1);
|
|
249
|
-
return findNextRunAtMs({
|
|
250
|
-
afterMs,
|
|
251
|
-
recurrence,
|
|
252
|
-
searchFrom: compareDate(afterDate, nextScheduledDate) < 0 ? nextScheduledDate : afterDate,
|
|
253
|
-
timezone
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
// src/chat/notifications/schedule.ts
|
|
257
|
-
/**
|
|
258
|
-
* Notification hours for one user.
|
|
259
|
-
*
|
|
260
|
-
* This module imports only zod and the browser-safe cadence helpers, so the
|
|
261
|
-
* dashboard client bundle can use it.
|
|
262
|
-
*/
|
|
263
|
-
const clockTimePattern = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
264
|
-
/** Saved notification hours. Weekdays use 0 for Sunday, like `Date#getDay`. */
|
|
265
|
-
const notificationScheduleSchema = z.object({
|
|
266
|
-
/**
|
|
267
|
-
* Follow the linked Slack user's notification schedule. The fields below
|
|
268
|
-
* apply only when Junior cannot read it. Absent means on.
|
|
269
|
-
*/
|
|
270
|
-
followSlack: z.boolean().optional(),
|
|
271
|
-
/** When false, Junior sends push notifications at any time. */
|
|
272
|
-
workingHoursOnly: z.boolean(),
|
|
273
|
-
days: z.array(z.number().int().min(0).max(6)).max(7).refine((days) => new Set(days).size === days.length, { message: "Days must be unique." }),
|
|
274
|
-
/** Local start time, `HH:MM`. */
|
|
275
|
-
start: z.string().regex(clockTimePattern),
|
|
276
|
-
/** Local end time, `HH:MM`. An end before the start crosses midnight. */
|
|
277
|
-
end: z.string().regex(clockTimePattern),
|
|
278
|
-
/** IANA timezone set by the user. Absent means the profile timezone. */
|
|
279
|
-
timezone: z.string().min(1).max(64).refine(isValidTimeZone, { message: "Unknown timezone." }).optional()
|
|
280
|
-
}).strict().refine((schedule) => schedule.start !== schedule.end, {
|
|
281
|
-
message: "Start and end must differ.",
|
|
282
|
-
path: ["end"]
|
|
283
|
-
});
|
|
284
|
-
/**
|
|
285
|
-
* Default when a user has not saved a schedule: follow Slack, else
|
|
286
|
-
* 09:00–18:00, Mon–Fri.
|
|
287
|
-
*/
|
|
288
|
-
const DEFAULT_NOTIFICATION_SCHEDULE = {
|
|
289
|
-
followSlack: true,
|
|
290
|
-
workingHoursOnly: true,
|
|
291
|
-
days: [
|
|
292
|
-
1,
|
|
293
|
-
2,
|
|
294
|
-
3,
|
|
295
|
-
4,
|
|
296
|
-
5
|
|
297
|
-
],
|
|
298
|
-
start: "09:00",
|
|
299
|
-
end: "18:00"
|
|
300
|
-
};
|
|
301
|
-
function clockMinutes(value) {
|
|
302
|
-
const [hours, minutes] = value.split(":").map(Number);
|
|
303
|
-
return hours * 60 + minutes;
|
|
304
|
-
}
|
|
305
|
-
const weekdayIndex = {
|
|
306
|
-
Sun: 0,
|
|
307
|
-
Mon: 1,
|
|
308
|
-
Tue: 2,
|
|
309
|
-
Wed: 3,
|
|
310
|
-
Thu: 4,
|
|
311
|
-
Fri: 5,
|
|
312
|
-
Sat: 6
|
|
313
|
-
};
|
|
314
|
-
function localWeekdayAndMinutes(nowMs, timezone) {
|
|
315
|
-
const parts = new Intl.DateTimeFormat("en-US", {
|
|
316
|
-
hour: "2-digit",
|
|
317
|
-
hourCycle: "h23",
|
|
318
|
-
minute: "2-digit",
|
|
319
|
-
timeZone: timezone,
|
|
320
|
-
weekday: "short"
|
|
321
|
-
}).formatToParts(new Date(nowMs));
|
|
322
|
-
const value = (type) => parts.find((part) => part.type === type)?.value ?? "";
|
|
323
|
-
const weekday = weekdayIndex[value("weekday")];
|
|
324
|
-
if (weekday === void 0) throw new Error(`Could not read the weekday for timezone ${timezone}`);
|
|
325
|
-
return {
|
|
326
|
-
minutes: Number(value("hour")) % 24 * 60 + Number(value("minute")),
|
|
327
|
-
weekday
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Return whether a notification may be sent now. A window that crosses
|
|
332
|
-
* midnight belongs to the day on which it starts.
|
|
333
|
-
*/
|
|
334
|
-
function isWithinNotificationSchedule(schedule, timezone, nowMs) {
|
|
335
|
-
if (!schedule.workingHoursOnly) return true;
|
|
336
|
-
const { minutes, weekday } = localWeekdayAndMinutes(nowMs, timezone);
|
|
337
|
-
const start = clockMinutes(schedule.start);
|
|
338
|
-
const end = clockMinutes(schedule.end);
|
|
339
|
-
if (start < end) return schedule.days.includes(weekday) && minutes >= start && minutes < end;
|
|
340
|
-
if (minutes >= start) return schedule.days.includes(weekday);
|
|
341
|
-
if (minutes < end) return schedule.days.includes((weekday + 6) % 7);
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
344
|
-
export { getNextRunAtMs as a, resolveLocalScheduleAtMs as c, getFirstRunAtMs as i, isWithinNotificationSchedule as n, getZonedDateTimeParts as o, notificationScheduleSchema as r, isValidTimeZone as s, DEFAULT_NOTIFICATION_SCHEDULE as t };
|