@oneuptime/common 12.0.29 → 12.0.30
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/Models/DatabaseModels/Index.ts +11 -0
- package/Models/DatabaseModels/OnCallDutyPolicySchedule.ts +43 -0
- package/Models/DatabaseModels/OnCallDutyPolicyScheduleCalendarFeed.ts +662 -0
- package/Models/DatabaseModels/ProjectOnCallCalendarFeed.ts +584 -0
- package/Models/DatabaseModels/UserOnCallCalendarFeed.ts +546 -0
- package/Models/DatabaseModels/UserOnCallShiftReminder.ts +231 -0
- package/Models/DatabaseModels/UserOnCallShiftReminderLog.ts +331 -0
- package/Server/API/OnCallCalendarAPI.ts +2194 -0
- package/Server/EnvironmentConfig.ts +138 -0
- package/Server/Infrastructure/OnCallCalendarFeedCache.ts +1050 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1790400000000-AddOnCallCalendarFeeds.ts +253 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +2 -0
- package/Server/Middleware/OnCallCalendarFeedRateLimit.ts +487 -0
- package/Server/Services/Index.ts +12 -0
- package/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.ts +32 -0
- package/Server/Services/OnCallDutyPolicyScheduleCalendarFeedService.ts +260 -0
- package/Server/Services/OnCallDutyPolicyScheduleLayerService.ts +70 -3
- package/Server/Services/OnCallDutyPolicyScheduleLayerUserService.ts +138 -3
- package/Server/Services/OnCallDutyPolicyScheduleService.ts +1465 -134
- package/Server/Services/OnCallDutyPolicyUserOverrideService.ts +167 -31
- package/Server/Services/ProjectOnCallCalendarFeedService.ts +192 -0
- package/Server/Services/TeamMemberService.ts +489 -1
- package/Server/Services/TeamService.ts +50 -0
- package/Server/Services/UserNotificationSettingService.ts +44 -1
- package/Server/Services/UserOnCallCalendarFeedService.ts +159 -0
- package/Server/Services/UserOnCallShiftReminderLogService.ts +151 -0
- package/Server/Services/UserOnCallShiftReminderService.ts +112 -0
- package/Server/Utils/OnCall/CalendarFeedToken.ts +241 -0
- package/Server/Utils/OnCall/OnCallCalendarFeedRenderer.ts +1488 -0
- package/Server/Utils/OnCall/OnCallCalendarFeedUrls.ts +230 -0
- package/Server/Utils/OnCall/OnCallShiftChangeListeners.ts +227 -0
- package/Server/Utils/OnCall/OnCallShiftMaterializer.ts +1127 -0
- package/Server/Utils/OnCall/OnCallShiftReminderListener.ts +174 -0
- package/Server/Utils/OnCall/OnCallShiftReminderRunner.ts +2584 -0
- package/Server/Utils/Response.ts +134 -0
- package/Server/Utils/StartServer.ts +10 -0
- package/Server/Utils/Telemetry/AppMetrics.ts +51 -0
- package/Tests/App/Dashboard/OnCallCalendarFeedLinks.test.tsx +229 -0
- package/Tests/App/Dashboard/OnCallCalendarFeedPlanGate.test.tsx +489 -0
- package/Tests/App/Dashboard/OnCallCalendarFeedSideMenus.test.tsx +149 -0
- package/Tests/App/Dashboard/OnCallCalendarFeedUtil.test.ts +855 -0
- package/Tests/App/Dashboard/OnCallPersonalCalendarFeed.test.tsx +1209 -0
- package/Tests/App/Dashboard/OnCallSharedCalendarFeedCard.test.tsx +1019 -0
- package/Tests/App/Dashboard/OnCallShiftRemindersAndUpcomingShifts.test.tsx +655 -0
- package/Tests/App/Dashboard/UserSettingsSetupChecklistModel.test.ts +73 -0
- package/Tests/Models/OnCallCalendarFeedModels.test.ts +642 -0
- package/Tests/Models/OnCallDutyPolicyScheduleCalendarFeed.test.ts +288 -0
- package/Tests/Models/OnCallDutyPolicyScheduleShiftConfigVersion.test.ts +88 -0
- package/Tests/Models/UserOnCallShiftReminderModels.test.ts +368 -0
- package/Tests/Server/API/Helpers.ts +8 -0
- package/Tests/Server/API/OnCallCalendarAPI.test.ts +4461 -0
- package/Tests/Server/EnvironmentConfigOnCallCalendarFeed.test.ts +357 -0
- package/Tests/Server/Infrastructure/OnCallCalendarFeedCache.test.ts +1589 -0
- package/Tests/Server/Infrastructure/Postgres/AddOnCallCalendarFeedsMigration.test.ts +369 -0
- package/Tests/Server/Middleware/OnCallCalendarFeedRateLimit.test.ts +1365 -0
- package/Tests/Server/Services/FeedRetentionConsistency.test.ts +70 -0
- package/Tests/Server/Services/OnCallCalendarFeedServices.test.ts +1103 -0
- package/Tests/Server/Services/OnCallDutyPolicyScheduleResolver.test.ts +1037 -0
- package/Tests/Server/Services/OnCallShiftConfigPropagation.test.ts +1270 -0
- package/Tests/Server/Services/TeamDeleteMemberCleanup.test.ts +156 -0
- package/Tests/Server/Services/TeamMemberOnCallCleanup.test.ts +755 -0
- package/Tests/Server/Services/UserNotificationSettingShiftReminderDefaults.test.ts +267 -0
- package/Tests/Server/Services/UserOnCallShiftReminderServices.test.ts +583 -0
- package/Tests/Server/Types/Database/Permissions/OnCallCalendarFeedPermissions.test.ts +254 -0
- package/Tests/Server/Utils/OnCall/CalendarFeedToken.test.ts +467 -0
- package/Tests/Server/Utils/OnCall/OnCallCalendarFeedRenderer.test.ts +2142 -0
- package/Tests/Server/Utils/OnCall/OnCallCalendarFeedUrls.test.ts +278 -0
- package/Tests/Server/Utils/OnCall/OnCallResolverTestHarness.ts +440 -0
- package/Tests/Server/Utils/OnCall/OnCallShiftChangeListeners.test.ts +314 -0
- package/Tests/Server/Utils/OnCall/OnCallShiftMaterializer.test.ts +1502 -0
- package/Tests/Server/Utils/OnCall/OnCallShiftReminderListener.test.ts +491 -0
- package/Tests/Server/Utils/OnCall/OnCallShiftReminderRunner.test.ts +3088 -0
- package/Tests/Server/Utils/OnCall/OnCallShiftReminderTestHarness.ts +910 -0
- package/Tests/Server/Utils/ResponseSendCalendarResponse.test.ts +561 -0
- package/Tests/Server/Utils/StartServerEncryptionSecretWarning.test.ts +64 -0
- package/Tests/Server/Utils/Telemetry/AppMetrics.test.ts +29 -0
- package/Tests/Types/Calendar/ICalendar.test.ts +488 -0
- package/Tests/Types/NotificationSetting/NotificationSettingEventType.test.ts +53 -0
- package/Tests/Types/OnCallDutyPolicy/CalendarFeedTestFixtures.ts +310 -0
- package/Tests/Types/OnCallDutyPolicy/CalendarFeedWindow.test.ts +205 -0
- package/Tests/Types/OnCallDutyPolicy/LayerUtilLayerMetaAndIterationCap.test.ts +458 -0
- package/Tests/Types/OnCallDutyPolicy/MaterializedShift.test.ts +197 -0
- package/Tests/Types/OnCallDutyPolicy/OnCallCalendarFeedUtil.test.ts +1986 -0
- package/Tests/Types/OnCallDutyPolicy/ScheduleShiftUtilGroupKey.test.ts +678 -0
- package/Tests/Types/OnCallDutyPolicy/ShiftSeamUtil.test.ts +417 -0
- package/Tests/UI/Utils/Breadcrumb/fixtures/RealBreadcrumbTrails.ts +10 -0
- package/Tests/UI/Utils/Breadcrumb/fixtures/RealRoutePatterns.ts +2 -0
- package/Types/Calendar/ICalendar.ts +442 -0
- package/Types/Email/EmailTemplateType.ts +2 -0
- package/Types/NotificationSetting/NotificationSettingEventType.ts +4 -0
- package/Types/OnCallDutyPolicy/CalendarFeedWindow.ts +140 -0
- package/Types/OnCallDutyPolicy/Layer.ts +190 -35
- package/Types/OnCallDutyPolicy/MaterializedShift.ts +274 -0
- package/Types/OnCallDutyPolicy/OnCallCalendarFeedUtil.ts +1415 -0
- package/Types/OnCallDutyPolicy/ScheduleShiftUtil.ts +159 -4
- package/Types/OnCallDutyPolicy/ShiftSeamUtil.ts +106 -0
- package/build/dist/Models/DatabaseModels/Index.js +11 -0
- package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicySchedule.js +44 -0
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicySchedule.js.map +1 -1
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicyScheduleCalendarFeed.js +699 -0
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicyScheduleCalendarFeed.js.map +1 -0
- package/build/dist/Models/DatabaseModels/ProjectOnCallCalendarFeed.js +620 -0
- package/build/dist/Models/DatabaseModels/ProjectOnCallCalendarFeed.js.map +1 -0
- package/build/dist/Models/DatabaseModels/UserOnCallCalendarFeed.js +585 -0
- package/build/dist/Models/DatabaseModels/UserOnCallCalendarFeed.js.map +1 -0
- package/build/dist/Models/DatabaseModels/UserOnCallShiftReminder.js +247 -0
- package/build/dist/Models/DatabaseModels/UserOnCallShiftReminder.js.map +1 -0
- package/build/dist/Models/DatabaseModels/UserOnCallShiftReminderLog.js +355 -0
- package/build/dist/Models/DatabaseModels/UserOnCallShiftReminderLog.js.map +1 -0
- package/build/dist/Server/API/OnCallCalendarAPI.js +1371 -0
- package/build/dist/Server/API/OnCallCalendarAPI.js.map +1 -0
- package/build/dist/Server/EnvironmentConfig.js +102 -0
- package/build/dist/Server/EnvironmentConfig.js.map +1 -1
- package/build/dist/Server/Infrastructure/OnCallCalendarFeedCache.js +663 -0
- package/build/dist/Server/Infrastructure/OnCallCalendarFeedCache.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1790400000000-AddOnCallCalendarFeeds.js +103 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1790400000000-AddOnCallCalendarFeeds.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +2 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Middleware/OnCallCalendarFeedRateLimit.js +342 -0
- package/build/dist/Server/Middleware/OnCallCalendarFeedRateLimit.js.map +1 -0
- package/build/dist/Server/Services/Index.js +12 -0
- package/build/dist/Server/Services/Index.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.js +20 -0
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleCalendarFeedService.js +219 -0
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleCalendarFeedService.js.map +1 -0
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerService.js +47 -3
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerUserService.js +112 -3
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerUserService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js +955 -9
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyUserOverrideService.js +93 -6
- package/build/dist/Server/Services/OnCallDutyPolicyUserOverrideService.js.map +1 -1
- package/build/dist/Server/Services/ProjectOnCallCalendarFeedService.js +157 -0
- package/build/dist/Server/Services/ProjectOnCallCalendarFeedService.js.map +1 -0
- package/build/dist/Server/Services/TeamMemberService.js +396 -1
- package/build/dist/Server/Services/TeamMemberService.js.map +1 -1
- package/build/dist/Server/Services/TeamService.js +43 -0
- package/build/dist/Server/Services/TeamService.js.map +1 -1
- package/build/dist/Server/Services/UserNotificationSettingService.js +26 -1
- package/build/dist/Server/Services/UserNotificationSettingService.js.map +1 -1
- package/build/dist/Server/Services/UserOnCallCalendarFeedService.js +140 -0
- package/build/dist/Server/Services/UserOnCallCalendarFeedService.js.map +1 -0
- package/build/dist/Server/Services/UserOnCallShiftReminderLogService.js +116 -0
- package/build/dist/Server/Services/UserOnCallShiftReminderLogService.js.map +1 -0
- package/build/dist/Server/Services/UserOnCallShiftReminderService.js +92 -0
- package/build/dist/Server/Services/UserOnCallShiftReminderService.js.map +1 -0
- package/build/dist/Server/Utils/OnCall/CalendarFeedToken.js +161 -0
- package/build/dist/Server/Utils/OnCall/CalendarFeedToken.js.map +1 -0
- package/build/dist/Server/Utils/OnCall/OnCallCalendarFeedRenderer.js +983 -0
- package/build/dist/Server/Utils/OnCall/OnCallCalendarFeedRenderer.js.map +1 -0
- package/build/dist/Server/Utils/OnCall/OnCallCalendarFeedUrls.js +155 -0
- package/build/dist/Server/Utils/OnCall/OnCallCalendarFeedUrls.js.map +1 -0
- package/build/dist/Server/Utils/OnCall/OnCallShiftChangeListeners.js +145 -0
- package/build/dist/Server/Utils/OnCall/OnCallShiftChangeListeners.js.map +1 -0
- package/build/dist/Server/Utils/OnCall/OnCallShiftMaterializer.js +752 -0
- package/build/dist/Server/Utils/OnCall/OnCallShiftMaterializer.js.map +1 -0
- package/build/dist/Server/Utils/OnCall/OnCallShiftReminderListener.js +92 -0
- package/build/dist/Server/Utils/OnCall/OnCallShiftReminderListener.js.map +1 -0
- package/build/dist/Server/Utils/OnCall/OnCallShiftReminderRunner.js +1786 -0
- package/build/dist/Server/Utils/OnCall/OnCallShiftReminderRunner.js.map +1 -0
- package/build/dist/Server/Utils/Response.js +97 -0
- package/build/dist/Server/Utils/Response.js.map +1 -1
- package/build/dist/Server/Utils/StartServer.js +9 -1
- package/build/dist/Server/Utils/StartServer.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/AppMetrics.js +41 -0
- package/build/dist/Server/Utils/Telemetry/AppMetrics.js.map +1 -1
- package/build/dist/Types/Calendar/ICalendar.js +290 -0
- package/build/dist/Types/Calendar/ICalendar.js.map +1 -0
- package/build/dist/Types/Email/EmailTemplateType.js +2 -0
- package/build/dist/Types/Email/EmailTemplateType.js.map +1 -1
- package/build/dist/Types/NotificationSetting/NotificationSettingEventType.js +3 -0
- package/build/dist/Types/NotificationSetting/NotificationSettingEventType.js.map +1 -1
- package/build/dist/Types/OnCallDutyPolicy/CalendarFeedWindow.js +97 -0
- package/build/dist/Types/OnCallDutyPolicy/CalendarFeedWindow.js.map +1 -0
- package/build/dist/Types/OnCallDutyPolicy/Layer.js +113 -19
- package/build/dist/Types/OnCallDutyPolicy/Layer.js.map +1 -1
- package/build/dist/Types/OnCallDutyPolicy/MaterializedShift.js +134 -0
- package/build/dist/Types/OnCallDutyPolicy/MaterializedShift.js.map +1 -0
- package/build/dist/Types/OnCallDutyPolicy/OnCallCalendarFeedUtil.js +800 -0
- package/build/dist/Types/OnCallDutyPolicy/OnCallCalendarFeedUtil.js.map +1 -0
- package/build/dist/Types/OnCallDutyPolicy/ScheduleShiftUtil.js +97 -3
- package/build/dist/Types/OnCallDutyPolicy/ScheduleShiftUtil.js.map +1 -1
- package/build/dist/Types/OnCallDutyPolicy/ShiftSeamUtil.js +77 -0
- package/build/dist/Types/OnCallDutyPolicy/ShiftSeamUtil.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
import OneUptimeDate from "../../../Types/Date";
|
|
3
|
+
import { PREVIOUS_TOKEN_GRACE_DAYS } from "../../../Types/OnCallDutyPolicy/CalendarFeedWindow";
|
|
4
|
+
/*
|
|
5
|
+
* The capability token that addresses an on-call calendar feed.
|
|
6
|
+
*
|
|
7
|
+
* A calendar client keeps the feed URL forever and re-fetches it unattended,
|
|
8
|
+
* so the token has to be both unguessable and cheap to look up: 256 bits from
|
|
9
|
+
* the CSPRNG, carried in the URL as base64url (43 characters, no padding), and
|
|
10
|
+
* stored ONLY as its unkeyed SHA-256 hex digest. The digest is what the public
|
|
11
|
+
* route queries by, which keeps the plaintext out of the indexed column; a
|
|
12
|
+
* database dump therefore yields hashes, not working feed URLs.
|
|
13
|
+
*
|
|
14
|
+
* Unkeyed on purpose: a keyed hash (HMAC over EncryptionSecret, the backup-code
|
|
15
|
+
* recipe) would tie every feed to the instance secret, and rotating that secret
|
|
16
|
+
* would silently break every subscribed calendar in the world with no way to
|
|
17
|
+
* tell the user. The token already carries 256 bits of entropy, so a rainbow
|
|
18
|
+
* table buys nothing and the key adds no strength worth that failure mode.
|
|
19
|
+
*
|
|
20
|
+
* The hint is the last four characters - enough for the settings page to say
|
|
21
|
+
* "link ending in …k3Qx" so a user can tell two links apart, far too little to
|
|
22
|
+
* recover anything.
|
|
23
|
+
*/
|
|
24
|
+
// crypto.randomBytes(32) -> 32 bytes -> ceil(32 * 8 / 6) = 43 base64url chars.
|
|
25
|
+
const TOKEN_BYTE_LENGTH = 32;
|
|
26
|
+
export const CALENDAR_FEED_TOKEN_LENGTH = 43;
|
|
27
|
+
export const CALENDAR_FEED_TOKEN_HINT_LENGTH = 4;
|
|
28
|
+
/*
|
|
29
|
+
* Shape guard for the public route. Anything that does not match is answered
|
|
30
|
+
* 404 before any database work, so a scanner probing the path costs one regex.
|
|
31
|
+
*/
|
|
32
|
+
export const CALENDAR_FEED_TOKEN_REGEX = /^[A-Za-z0-9_-]{43}$/;
|
|
33
|
+
export default class CalendarFeedToken {
|
|
34
|
+
/**
|
|
35
|
+
* A fresh 43-character base64url token from 32 CSPRNG bytes.
|
|
36
|
+
*/
|
|
37
|
+
static mint() {
|
|
38
|
+
return crypto.randomBytes(TOKEN_BYTE_LENGTH).toString("base64url");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Unkeyed SHA-256 of the token, lowercase hex (64 characters). This is the
|
|
42
|
+
* value stored in `tokenHash` / `previousTokenHash` and the value the public
|
|
43
|
+
* route looks up by. Deterministic: the same token always hashes the same.
|
|
44
|
+
*/
|
|
45
|
+
static hash(token) {
|
|
46
|
+
return crypto.createHash("sha256").update(token, "utf8").digest("hex");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The display hint - the last four characters of the token. Never enough to
|
|
50
|
+
* reconstruct the token; enough to tell "…k3Qx" from "…Q9zA" in the UI.
|
|
51
|
+
*/
|
|
52
|
+
static hint(token) {
|
|
53
|
+
return token.slice(-CALENDAR_FEED_TOKEN_HINT_LENGTH);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* True when the string has exactly the shape a minted token has. Used as
|
|
57
|
+
* the shape guard on the public route so a malformed path never reaches the
|
|
58
|
+
* database.
|
|
59
|
+
*/
|
|
60
|
+
static isValidShape(token) {
|
|
61
|
+
return typeof token === "string" && CALENDAR_FEED_TOKEN_REGEX.test(token);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Everything a feed row needs when a token is minted or rotated.
|
|
65
|
+
*/
|
|
66
|
+
static mintSet() {
|
|
67
|
+
const token = CalendarFeedToken.mint();
|
|
68
|
+
return {
|
|
69
|
+
token: token,
|
|
70
|
+
tokenHash: CalendarFeedToken.hash(token),
|
|
71
|
+
tokenHint: CalendarFeedToken.hint(token),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The token columns a feed row should hold after minting or rotating.
|
|
76
|
+
*
|
|
77
|
+
* The hash the row held before (if any) moves to `previousTokenHash` and
|
|
78
|
+
* keeps serving an EMPTY calendar until `previousTokenExpiresAt`
|
|
79
|
+
* (PREVIOUS_TOKEN_GRACE_DAYS from now), so a still-subscribed client clears
|
|
80
|
+
* its copy instead of showing "could not fetch" until the user notices.
|
|
81
|
+
*/
|
|
82
|
+
static buildRotation(data) {
|
|
83
|
+
const now = data.now || OneUptimeDate.getCurrentDate();
|
|
84
|
+
const minted = CalendarFeedToken.mintSet();
|
|
85
|
+
const previousTokenHash = data.currentTokenHash || null;
|
|
86
|
+
return Object.assign(Object.assign({}, minted), { rotatedAt: now, previousTokenHash: previousTokenHash, previousTokenExpiresAt: previousTokenHash
|
|
87
|
+
? OneUptimeDate.addRemoveDays(now, PREVIOUS_TOKEN_GRACE_DAYS)
|
|
88
|
+
: null });
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Populate the token columns of a row about to be INSERTED.
|
|
92
|
+
*
|
|
93
|
+
* With `trustSuppliedToken`, a well-formed plaintext token already on the
|
|
94
|
+
* row (the calendar API mints one up front so it can build the URL in the
|
|
95
|
+
* same response) is kept and the hash and hint are DERIVED from it. Without
|
|
96
|
+
* it - every non-root create - whatever the request carried is discarded
|
|
97
|
+
* and a fresh token is minted. Either way a malformed token or a
|
|
98
|
+
* caller-chosen hash is replaced: there is no path to a row whose hash
|
|
99
|
+
* disagrees with its token, and no path for a request body to choose the
|
|
100
|
+
* secret. A brand-new row never carries a grace-period hash.
|
|
101
|
+
*/
|
|
102
|
+
static applyTokenColumnsOnCreate(data, options) {
|
|
103
|
+
let minted;
|
|
104
|
+
if (options.trustSuppliedToken &&
|
|
105
|
+
CalendarFeedToken.isValidShape(data.token)) {
|
|
106
|
+
minted = {
|
|
107
|
+
token: data.token,
|
|
108
|
+
tokenHash: CalendarFeedToken.hash(data.token),
|
|
109
|
+
tokenHint: CalendarFeedToken.hint(data.token),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
minted = CalendarFeedToken.mintSet();
|
|
114
|
+
}
|
|
115
|
+
data.token = minted.token;
|
|
116
|
+
data.tokenHash = minted.tokenHash;
|
|
117
|
+
data.tokenHint = minted.tokenHint;
|
|
118
|
+
data.rotatedAt = OneUptimeDate.getCurrentDate();
|
|
119
|
+
data.previousTokenHash = undefined;
|
|
120
|
+
data.previousTokenExpiresAt = undefined;
|
|
121
|
+
return minted;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The partial row a rotation writes. `previousTokenHash` /
|
|
125
|
+
* `previousTokenExpiresAt` are null on a first mint, which the update path
|
|
126
|
+
* has to be able to write; the model types them as optional strings/dates,
|
|
127
|
+
* hence the cast at this one boundary.
|
|
128
|
+
*/
|
|
129
|
+
static toRotationUpdateData(rotation) {
|
|
130
|
+
return {
|
|
131
|
+
token: rotation.token,
|
|
132
|
+
tokenHash: rotation.tokenHash,
|
|
133
|
+
tokenHint: rotation.tokenHint,
|
|
134
|
+
rotatedAt: rotation.rotatedAt,
|
|
135
|
+
previousTokenHash: rotation.previousTokenHash,
|
|
136
|
+
previousTokenExpiresAt: rotation.previousTokenExpiresAt,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Constant-time comparison of two hashes, for callers that compare a
|
|
141
|
+
* freshly computed digest against a stored one in memory rather than in a
|
|
142
|
+
* WHERE clause. Length mismatch is answered false without leaking timing on
|
|
143
|
+
* the content.
|
|
144
|
+
*/
|
|
145
|
+
static isHashEqual(a, b) {
|
|
146
|
+
/*
|
|
147
|
+
* Plain Uint8Arrays rather than Buffers: the two are interchangeable at
|
|
148
|
+
* runtime, but the App build's @types/node rejects Buffer where an
|
|
149
|
+
* ArrayBufferView is expected (the same mismatch PasswordHash and
|
|
150
|
+
* TwoFactorBackupCode trip over), and TextEncoder is global on every
|
|
151
|
+
* supported Node.
|
|
152
|
+
*/
|
|
153
|
+
const bytesA = new TextEncoder().encode(a);
|
|
154
|
+
const bytesB = new TextEncoder().encode(b);
|
|
155
|
+
if (bytesA.length !== bytesB.length) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return crypto.timingSafeEqual(bytesA, bytesB);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=CalendarFeedToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CalendarFeedToken.js","sourceRoot":"","sources":["../../../../../Server/Utils/OnCall/CalendarFeedToken.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAE/F;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,+EAA+E;AAC/E,MAAM,iBAAiB,GAAW,EAAE,CAAC;AAErC,MAAM,CAAC,MAAM,0BAA0B,GAAW,EAAE,CAAC;AAErD,MAAM,CAAC,MAAM,+BAA+B,GAAW,CAAC,CAAC;AAEzD;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAW,qBAAqB,CAAC;AA8CvE,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;OAEG;IACI,MAAM,CAAC,IAAI;QAChB,OAAO,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACrE,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAC,KAAa;QAC9B,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC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