@sentry/junior 0.310.0 → 0.312.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-BhKpjpGD.js → adapter-context-BRjEWRy1.js} +2 -2
- package/dist/adapter-iIq7ihf7.js +259 -0
- package/dist/{admin-tgZEZAk2.js → admin-DhInw5K9.js} +1 -2
- package/dist/{agent-runner-D9cvNlQl.js → agent-runner-C9iDurwX.js} +6507 -7721
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -6
- package/dist/api.d.ts +21 -3
- package/dist/api.js +1625 -535
- package/dist/{app-B_7Wn0en.d.ts → app-DRFrC8Mw.d.ts} +14 -10
- package/dist/app.d.ts +2 -2
- package/dist/app.js +454 -994
- package/dist/{background-compaction-queue-BGHqkhkY.js → background-compaction-queue-DrKi7w3d.js} +10 -85
- package/dist/callback-mFlTUWWx.js +75 -0
- package/dist/{catalog-runtime-BxwzbLKY.js → catalog-runtime-D7xapBAX.js} +1 -1
- package/dist/channel-access-CJGfNTdn.js +221 -0
- package/dist/child-message-DcsritGf.js +179 -0
- package/dist/cli/chat.js +18 -19
- package/dist/cli/check.js +23 -29
- package/dist/cli/init.js +1 -7
- package/dist/cli/main.js +3 -7
- package/dist/cli/plugins.js +8 -7
- package/dist/cli/run.d.ts +1 -2
- package/dist/cli/run.js +1 -2
- 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-Dkt2Le2b.js → config-kXB2Y5tl.js} +294 -28
- package/dist/{continue-in-slack-BWVwePKD.js → continue-in-slack-O6pV5004.js} +7 -7
- package/dist/{conversation-feed-Ci6YD1N-.js → conversation-feed-uNOv_x68.js} +87 -24
- package/dist/{conversation-privacy-C39g8BY4.js → conversation-privacy-L4ja1_W6.js} +1 -1
- package/dist/{conversation-turn-CBlZIH02.js → conversation-turn-CeLbHqdw.js} +56 -49
- package/dist/{credential-sync-vGnrB0BY.js → credential-sync-I8VBGk05.js} +16 -16
- package/dist/{projection-jZSlEAXG.js → credentialed-Cb6E2phL.js} +16268 -16821
- package/dist/{db-B4Hjxr-u.d.ts → db-BbC5stfa.d.ts} +13 -6
- package/dist/{db-CFZggNoy.js → db-LAyyX8tk.js} +1698 -1046
- package/dist/{executor-BPkZDx5-.js → executor-SCub-fAq.js} +552 -181
- package/dist/{html-2r2KmLwi.js → html-BCZ3Xtb_.js} +6 -6
- package/dist/{session-stop-BfY4rhJs.js → ingest-BDf3D50j.js} +2134 -2553
- package/dist/{install-C-oE6C_u.js → install-DCFJFkC0.js} +2 -2
- package/dist/instrumentation.js +4 -4
- package/dist/{lineage-CsvrEFQe.js → lineage-B_m-4TJw.js} +2 -2
- package/dist/{stop-DYzjRf2U.js → list-CN2QA2R9.js} +1656 -685
- package/dist/{logging-D5gkyvnK.js → logging-dQ9ZRGQ8.js} +47 -9
- package/dist/media-CYm1QD8T.js +2356 -0
- package/dist/{message-DwvJ-I3w.js → message-DSXGj1hM.js} +19 -29
- package/dist/{model-input-MAq2881y.js → model-input--TrP9hYV.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +4 -3
- package/dist/{oauth-callback-server-DIF6Li06.js → oauth-callback-server-DHCZC6B4.js} +2 -2
- package/dist/{oauth-relay-DPE-wrwO.js → oauth-relay-pPMGnDZt.js} +1 -1
- package/dist/{registry-BBkWFCl8.js → registry-CZOzddwu.js} +5 -8
- package/dist/{resolve-B38MkHXE.js → resolve-cKOQ14Dh.js} +3 -3
- package/dist/{result-BaqSZcJb.js → result-DcvEOe1r.js} +119 -93
- package/dist/result-event-type-BdIJuZxg.js +48 -0
- package/dist/rule-DAxQY-1h.js +20 -0
- package/dist/{runner-11h8PrHh.js → runner-DBfUW44l.js} +14 -16
- package/dist/{sandbox-egress-signals-CTcACAtJ.js → sandbox-egress-signals-BVF_xAm1.js} +1 -1
- package/dist/{schema-DriSvB40.d.ts → schema-BEHKxr4I.d.ts} +861 -298
- package/dist/{schema-obw5jvR4.js → schema-Bk9Nm2E8.js} +344 -153
- package/dist/{service-account-Bx93N1n1.js → service-account-CVYsFjty.js} +3 -3
- package/dist/{service-account-Zc5bUcIJ.js → service-account-Ts4ulcrV.js} +68 -68
- package/dist/{skills-C8Npu5zO.js → skills-VTnhAJWm.js} +2 -2
- package/dist/{slack-conversation-unfurl-DlRVA02H.js → slack-conversation-unfurl-fuLnF1jE.js} +9 -11
- package/dist/{spawn-CXr58R0x.js → spawn-vxAarlX5.js} +6 -6
- package/dist/start-conversation-CEn2KH1A.js +941 -0
- package/dist/{state-CGrGVeQC.js → state-C1P3_Ywk.js} +4 -4
- package/dist/statuses-_cRJHXK7.js +150 -0
- package/dist/store-DFZaN-Ix.js +492 -0
- package/dist/task-queue-Cx4Lmjyk.js +90 -0
- package/dist/task-runner-CbTwFA6k.js +1432 -0
- package/dist/{thread-context-Dyj1KWaY.js → thread-context-BkAZDTX2.js} +13 -11
- package/dist/thread-state-DhPndWi1.js +5625 -0
- package/dist/{validation-DxVNIxA0.js → validation-nIzMtAVJ.js} +1 -1
- package/dist/{task-queue-CaZffYaH.js → vercel-queue-hW90XzbG.js} +93 -172
- package/dist/{version-Cr7Z71yG.js → version-Brbtz4Qf.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{warmup-C6LOZ2d2.js → warmup-BDA5myRK.js} +5832 -4567
- package/dist/web-message-id-C6P83ans.js +10 -0
- package/dist/{worker-CUBtu1Li.js → worker-D63RcaVD.js} +20 -8
- package/migrations/0126_artifact_drop_public.sql +8 -0
- package/migrations/0127_artifact_path.sql +4 -0
- package/migrations/0128_artifact_path_index.sql +1 -0
- package/migrations/0129_review_item_answered_index.sql +1 -0
- package/migrations/0130_review_item_status_index.sql +1 -0
- package/migrations/0131_brief_outcome_status.sql +1 -0
- package/migrations/0132_brief_outcome_status_backfill.sql +7 -0
- package/migrations/0133_brief_created_at_index.sql +1 -0
- package/migrations/0134_slack_person_search_index.sql +1 -0
- package/migrations/0135_code_change_size.sql +3 -0
- package/migrations/0136_merge_conflict_notice_dismiss.sql +16 -0
- package/migrations/0137_inbox_snoozes.sql +27 -0
- package/migrations/0138_code_change_search_index.sql +2 -0
- package/migrations/0139_review_item_owner.sql +22 -0
- package/migrations/0140_review_item_owner_index.sql +1 -0
- package/migrations/0141_memory_core_adoption.sql +89 -0
- package/migrations/0142_memory_core_indexes.sql +17 -0
- package/migrations/0143_todos.sql +14 -0
- package/migrations/0144_inbox_items.sql +32 -0
- package/migrations/0145_todo_changed_by_agent.sql +1 -0
- package/migrations/0146_inbox_item_subject_title_parts.sql +1 -0
- package/migrations/0147_inbox_snooze_wake_reason.sql +1 -0
- package/migrations/0148_authorization_request_index.sql +1 -0
- package/migrations/0149_conversation_metadata.sql +10 -0
- package/migrations/0150_conversation_metadata_fill.sql +39 -0
- package/migrations/0151_conversation_search_index.sql +1 -0
- package/migrations/0152_inbox_item_legacy_automation_keys.sql +21 -0
- package/migrations/0153_artifact_expiry.sql +1 -0
- package/migrations/0154_artifact_permanent_sha_index.sql +1 -0
- package/migrations/0155_artifact_drop_public_sha_index.sql +3 -0
- package/migrations/0156_conversation_kind_lead.sql +6 -0
- package/migrations/0157_conversation_lead_actor_index.sql +1 -0
- package/migrations/meta/0126_snapshot.json +5488 -0
- package/migrations/meta/0127_snapshot.json +5519 -0
- package/migrations/meta/0128_snapshot.json +5519 -0
- package/migrations/meta/0129_snapshot.json +5547 -0
- package/migrations/meta/0130_snapshot.json +5563 -0
- package/migrations/meta/0131_snapshot.json +5569 -0
- package/migrations/meta/0132_snapshot.json +5569 -0
- package/migrations/meta/0133_snapshot.json +5590 -0
- package/migrations/meta/0134_snapshot.json +5606 -0
- package/migrations/meta/0135_snapshot.json +5624 -0
- package/migrations/meta/0136_snapshot.json +5624 -0
- package/migrations/meta/0137_snapshot.json +5864 -0
- package/migrations/meta/0138_snapshot.json +5894 -0
- package/migrations/meta/0139_snapshot.json +5898 -0
- package/migrations/meta/0140_snapshot.json +5919 -0
- package/migrations/meta/0141_snapshot.json +6429 -0
- package/migrations/meta/0142_snapshot.json +6457 -0
- package/migrations/meta/0143_snapshot.json +6434 -0
- package/migrations/meta/0144_snapshot.json +6434 -0
- package/migrations/meta/0145_snapshot.json +6440 -0
- package/migrations/meta/0146_snapshot.json +6446 -0
- package/migrations/meta/0147_snapshot.json +6452 -0
- package/migrations/meta/0148_snapshot.json +6474 -0
- package/migrations/meta/0149_snapshot.json +6490 -0
- package/migrations/meta/0150_snapshot.json +6490 -0
- package/migrations/meta/0151_snapshot.json +6505 -0
- package/migrations/meta/0152_snapshot.json +6505 -0
- package/migrations/meta/0153_snapshot.json +6511 -0
- package/migrations/meta/0154_snapshot.json +6533 -0
- package/migrations/meta/0155_snapshot.json +6511 -0
- package/migrations/meta/0156_snapshot.json +6511 -0
- package/migrations/meta/0157_snapshot.json +6527 -0
- package/migrations/meta/_journal.json +224 -0
- package/package.json +7 -8
- package/skills/design-automation-skill/SKILL.md +108 -0
- package/dist/briefs-DKxkoruh.js +0 -395
- package/dist/conversation-M9KZ5JxF.js +0 -1024
- package/dist/prompt-CaMyeCpA.js +0 -910
- package/dist/schedule-DWxZ3kja.js +0 -1146
- package/dist/store-D4FQ1Nml.js +0 -335
- package/dist/task-runner-Dm7BHbGp.js +0 -287
- package/dist/turn-session-routing-CD0BRCex.js +0 -263
- package/dist/turn-user-message-9IxeEv5v.js +0 -364
- package/dist/users-CaUAYMb3.js +0 -181
- package/dist/viewer-AHldghAD.js +0 -212
- package/dist/web-message-id-BT8Mg8LL.js +0 -418
package/dist/users-CaUAYMb3.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { Cs as SlackActionError, Ds as getSlackClient, Ps as withSlackRetries } from "./projection-jZSlEAXG.js";
|
|
2
|
-
import * as z from "zod";
|
|
3
|
-
// src/chat/slack/users.ts
|
|
4
|
-
const profileFieldsSchema = z.object({ fields: z.record(z.string(), z.object({
|
|
5
|
-
value: z.string().optional(),
|
|
6
|
-
alt: z.string().optional(),
|
|
7
|
-
label: z.string().optional()
|
|
8
|
-
}).nullable()).nullish() });
|
|
9
|
-
function normalizeUser(raw) {
|
|
10
|
-
const rawFields = profileFieldsSchema.parse(raw.profile ?? {}).fields;
|
|
11
|
-
const profileFields = [];
|
|
12
|
-
if (rawFields) for (const [id, field] of Object.entries(rawFields)) {
|
|
13
|
-
if (!field) continue;
|
|
14
|
-
profileFields.push({
|
|
15
|
-
id,
|
|
16
|
-
label: field.label || void 0,
|
|
17
|
-
value: field.value || void 0,
|
|
18
|
-
alt: field.alt || void 0
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
id: raw.id ?? "",
|
|
23
|
-
team_id: raw.team_id || void 0,
|
|
24
|
-
name: raw.name || void 0,
|
|
25
|
-
real_name: raw.real_name || raw.profile?.real_name || void 0,
|
|
26
|
-
display_name: raw.profile?.display_name || void 0,
|
|
27
|
-
title: raw.profile?.title || void 0,
|
|
28
|
-
email: raw.profile?.email || void 0,
|
|
29
|
-
status_text: raw.profile?.status_text ?? void 0,
|
|
30
|
-
status_emoji: raw.profile?.status_emoji ?? void 0,
|
|
31
|
-
avatar_url: raw.profile?.image_512 || void 0,
|
|
32
|
-
is_bot: raw.is_bot ?? false,
|
|
33
|
-
is_deleted: raw.deleted ?? false,
|
|
34
|
-
timezone: raw.tz || void 0,
|
|
35
|
-
...profileFields.length > 0 ? { profile_fields: profileFields } : void 0
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function normalizeNameTokens(value) {
|
|
39
|
-
return value.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
40
|
-
}
|
|
41
|
-
function nameFields(user) {
|
|
42
|
-
return [
|
|
43
|
-
user.name ?? "",
|
|
44
|
-
user.profile?.display_name ?? "",
|
|
45
|
-
user.real_name ?? user.profile?.real_name ?? ""
|
|
46
|
-
].map((value) => value.toLowerCase().trim()).filter(Boolean);
|
|
47
|
-
}
|
|
48
|
-
/** Look up a Slack user by ID, returning the full profile including custom fields. */
|
|
49
|
-
async function lookupSlackUserProfile(userId) {
|
|
50
|
-
const client = getSlackClient();
|
|
51
|
-
const user = (await withSlackRetries(() => client.users.info({ user: userId }), 3, { action: "users.info" })).user;
|
|
52
|
-
if (!user) throw new Error(`Slack users.info returned no user for ${userId}`);
|
|
53
|
-
return normalizeUser(user);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Look up one Slack user who is a current human member of a workspace.
|
|
57
|
-
*
|
|
58
|
-
* Returns undefined for a user that Slack cannot find, a deleted user, a bot,
|
|
59
|
-
* or a user of another workspace. Other lookup errors propagate.
|
|
60
|
-
*/
|
|
61
|
-
async function lookupActiveSlackWorkspaceMember(userId, teamId) {
|
|
62
|
-
let user;
|
|
63
|
-
try {
|
|
64
|
-
user = await lookupSlackUserProfile(userId);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
if (error instanceof SlackActionError && error.apiError === "user_not_found") return;
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
return user.id === userId && user.team_id === teamId && !user.is_deleted && !user.is_bot ? user : void 0;
|
|
70
|
-
}
|
|
71
|
-
/** Look up a Slack bot by ID. Returns undefined when Slack has no such bot. */
|
|
72
|
-
async function lookupSlackBot(botId) {
|
|
73
|
-
try {
|
|
74
|
-
return (await withSlackRetries(() => getSlackClient().bots.info({ bot: botId }), 3, { action: "bots.info" })).bot;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
if (error instanceof SlackActionError && error.apiError === "bot_not_found") return;
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/** Look up a Slack user by email. Returns null when no user matches. */
|
|
81
|
-
async function lookupSlackUserByEmail(email) {
|
|
82
|
-
const client = getSlackClient();
|
|
83
|
-
let result;
|
|
84
|
-
try {
|
|
85
|
-
result = await withSlackRetries(() => client.users.lookupByEmail({ email }), 3, { action: "users.lookupByEmail" });
|
|
86
|
-
} catch (error) {
|
|
87
|
-
if (error instanceof SlackActionError && error.apiError === "users_not_found") return null;
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
const user = result.user;
|
|
91
|
-
if (!user) return null;
|
|
92
|
-
return normalizeUser(user);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Rank Slack name-search quality for one candidate.
|
|
96
|
-
* Exact field and token matches beat field prefixes so a display-name prefix
|
|
97
|
-
* cannot outrank a real-name first-name hit.
|
|
98
|
-
*/
|
|
99
|
-
function scoreNameMatch(user, query) {
|
|
100
|
-
const queryLower = query.toLowerCase().trim();
|
|
101
|
-
if (!queryLower) return 0;
|
|
102
|
-
const fields = nameFields(user);
|
|
103
|
-
if (fields.length === 0) return 0;
|
|
104
|
-
let best = 0;
|
|
105
|
-
const queryTokens = normalizeNameTokens(queryLower);
|
|
106
|
-
for (const field of fields) {
|
|
107
|
-
if (field === queryLower) {
|
|
108
|
-
best = Math.max(best, 100);
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (field.startsWith(queryLower)) best = Math.max(best, 70);
|
|
112
|
-
else if (field.includes(queryLower)) best = Math.max(best, 25);
|
|
113
|
-
const tokens = normalizeNameTokens(field);
|
|
114
|
-
for (const token of tokens) if (token === queryLower) best = Math.max(best, 85);
|
|
115
|
-
else if (token.startsWith(queryLower)) best = Math.max(best, 60);
|
|
116
|
-
if (queryTokens.length > 1 && queryTokens.every((queryToken) => tokens.some((token) => token === queryToken || token.startsWith(queryToken)))) best = Math.max(best, 95);
|
|
117
|
-
}
|
|
118
|
-
return best;
|
|
119
|
-
}
|
|
120
|
-
function compareNameMatches(left, right) {
|
|
121
|
-
if (right.score !== left.score) return right.score - left.score;
|
|
122
|
-
return (left.user.name ?? "").localeCompare(right.user.name ?? "");
|
|
123
|
-
}
|
|
124
|
-
async function listWorkspaceUsers(options) {
|
|
125
|
-
const client = getSlackClient();
|
|
126
|
-
const matches = [];
|
|
127
|
-
let cursor;
|
|
128
|
-
let pages = 0;
|
|
129
|
-
let totalScanned = 0;
|
|
130
|
-
while (pages < options.maxPages) {
|
|
131
|
-
pages++;
|
|
132
|
-
const result = await withSlackRetries(() => client.users.list({
|
|
133
|
-
limit: 200,
|
|
134
|
-
...cursor ? { cursor } : void 0
|
|
135
|
-
}), 3, { action: "users.list" });
|
|
136
|
-
const members = result.members ?? [];
|
|
137
|
-
totalScanned += members.length;
|
|
138
|
-
for (const member of members) {
|
|
139
|
-
if (!options.includeDeleted && member.deleted) continue;
|
|
140
|
-
if (!options.includeBots && member.is_bot) continue;
|
|
141
|
-
if (member.id === "USLACKBOT") continue;
|
|
142
|
-
const score = options.score(member);
|
|
143
|
-
if (score <= 0) continue;
|
|
144
|
-
matches.push({
|
|
145
|
-
user: member,
|
|
146
|
-
score
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
const nextCursor = result.response_metadata?.next_cursor;
|
|
150
|
-
if (!nextCursor) {
|
|
151
|
-
cursor = void 0;
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
cursor = nextCursor;
|
|
155
|
-
}
|
|
156
|
-
return {
|
|
157
|
-
matches,
|
|
158
|
-
searched_pages: pages,
|
|
159
|
-
searched_user_count: totalScanned,
|
|
160
|
-
truncated: pages >= options.maxPages && Boolean(cursor)
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
/** Search workspace users by name with bounded pagination through `users.list`. */
|
|
164
|
-
async function searchSlackUsers(options) {
|
|
165
|
-
const { query, limit = 10, maxPages = 3, includeDeleted = false, includeBots = false } = options;
|
|
166
|
-
const queryLower = query.toLowerCase().trim();
|
|
167
|
-
const listed = await listWorkspaceUsers({
|
|
168
|
-
maxPages,
|
|
169
|
-
includeDeleted,
|
|
170
|
-
includeBots,
|
|
171
|
-
score: (member) => scoreNameMatch(member, queryLower)
|
|
172
|
-
});
|
|
173
|
-
listed.matches.sort(compareNameMatches);
|
|
174
|
-
return {
|
|
175
|
-
users: listed.matches.slice(0, limit).map((m) => normalizeUser(m.user)),
|
|
176
|
-
searched_pages: listed.searched_pages,
|
|
177
|
-
searched_user_count: listed.searched_user_count,
|
|
178
|
-
truncated: listed.truncated
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
export { searchSlackUsers as a, lookupSlackUserProfile as i, lookupSlackBot as n, lookupSlackUserByEmail as r, lookupActiveSlackWorkspaceMember as t };
|
package/dist/viewer-AHldghAD.js
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { I as findActorIdentityId, X as readCachedUserByEmail, Y as clearCachedUser, o as getDb } from "./db-CFZggNoy.js";
|
|
2
|
-
import { B as juniorUsers, z as juniorIdentities } from "./executor-BPkZDx5-.js";
|
|
3
|
-
import { G as normalizeIdentityEmail, U as GOOGLE_IDENTITY_PROVIDER } from "./logging-D5gkyvnK.js";
|
|
4
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
-
import { identitySchema, userSchema } from "@sentry/junior-plugin-api";
|
|
6
|
-
import { and, asc, eq, inArray, isNotNull } from "drizzle-orm";
|
|
7
|
-
// src/chat/identities/avatar.ts
|
|
8
|
-
/**
|
|
9
|
-
* Profile photos of people, saved on their native Slack and Google
|
|
10
|
-
* identities. `/api/people/avatars/:identityId` serves each photo through
|
|
11
|
-
* the shared image route code, so browsers never load a photo from Slack or
|
|
12
|
-
* Google.
|
|
13
|
-
*/
|
|
14
|
-
const AVATAR_HOSTS = {
|
|
15
|
-
slack: ["avatars.slack-edge.com"],
|
|
16
|
-
[GOOGLE_IDENTITY_PROVIDER]: ["googleusercontent.com"]
|
|
17
|
-
};
|
|
18
|
-
const AVATAR_PROVIDERS = Object.keys(AVATAR_HOSTS);
|
|
19
|
-
/**
|
|
20
|
-
* Return the URL when it is HTTPS on a photo host of the provider or a
|
|
21
|
-
* subdomain. Junior fetches only these URLs.
|
|
22
|
-
*/
|
|
23
|
-
function parseAvatarUrl(value, provider) {
|
|
24
|
-
const hosts = AVATAR_HOSTS[provider];
|
|
25
|
-
if (!hosts || !value || !URL.canParse(value)) return void 0;
|
|
26
|
-
const url = new URL(value);
|
|
27
|
-
if (url.protocol !== "https:" || url.username || url.password) return;
|
|
28
|
-
const host = url.hostname.toLowerCase();
|
|
29
|
-
return hosts.some((allowed) => host === allowed || host.endsWith(`.${allowed}`)) ? url.href : void 0;
|
|
30
|
-
}
|
|
31
|
-
function avatarVersion(url) {
|
|
32
|
-
return createHash("sha256").update(url).digest("hex").slice(0, 16);
|
|
33
|
-
}
|
|
34
|
-
function avatarPath(identityId, avatarUrl) {
|
|
35
|
-
return `/api/people/avatars/${encodeURIComponent(identityId)}?v=${avatarVersion(avatarUrl)}`;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Read the photo path of each user: the Slack photo, then the Google photo.
|
|
39
|
-
* Users without a photo are not in the map.
|
|
40
|
-
*/
|
|
41
|
-
async function readUserAvatarUrls(db, userIds) {
|
|
42
|
-
if (userIds.length === 0) return /* @__PURE__ */ new Map();
|
|
43
|
-
return userAvatarUrlsFromIdentities(await db.select({
|
|
44
|
-
avatarUrl: juniorIdentities.avatarUrl,
|
|
45
|
-
identityId: juniorIdentities.id,
|
|
46
|
-
provider: juniorIdentities.provider,
|
|
47
|
-
updatedAt: juniorIdentities.updatedAt,
|
|
48
|
-
userId: juniorIdentities.userId
|
|
49
|
-
}).from(juniorIdentities).where(and(inArray(juniorIdentities.userId, [...new Set(userIds)]), eq(juniorIdentities.kind, "user"), inArray(juniorIdentities.provider, AVATAR_PROVIDERS), isNotNull(juniorIdentities.avatarUrl))));
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Pick the photo path of each user from their user Identities, for a caller
|
|
53
|
-
* that already read them: the Slack photo, then the Google photo.
|
|
54
|
-
*/
|
|
55
|
-
function userAvatarUrlsFromIdentities(rows) {
|
|
56
|
-
const rank = (row) => AVATAR_PROVIDERS.indexOf(row.provider);
|
|
57
|
-
const ranked = rows.filter((row) => rank(row) >= 0).sort((left, right) => rank(left) - rank(right) || right.updatedAt.getTime() - left.updatedAt.getTime());
|
|
58
|
-
const avatars = /* @__PURE__ */ new Map();
|
|
59
|
-
for (const row of ranked) if (row.userId && row.avatarUrl && !avatars.has(row.userId)) avatars.set(row.userId, avatarPath(row.identityId, row.avatarUrl));
|
|
60
|
-
return avatars;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Return the photo path for one Identity row. A linked Identity uses the
|
|
64
|
-
* photo of its user. An Identity without a user uses its own photo.
|
|
65
|
-
*/
|
|
66
|
-
function identityAvatarUrl(row, userAvatarUrls) {
|
|
67
|
-
if (row.userId) return userAvatarUrls.get(row.userId);
|
|
68
|
-
return row.avatarUrl ? avatarPath(row.identityId, row.avatarUrl) : void 0;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Return how to fetch the photo of one user Identity, or nothing when it has
|
|
72
|
-
* no photo on a photo host of its provider. A redirect cannot leave the
|
|
73
|
-
* photo hosts of the provider.
|
|
74
|
-
*/
|
|
75
|
-
async function readAvatarFetch(db, identityId) {
|
|
76
|
-
const [row] = await db.select({
|
|
77
|
-
avatarUrl: juniorIdentities.avatarUrl,
|
|
78
|
-
provider: juniorIdentities.provider
|
|
79
|
-
}).from(juniorIdentities).where(and(eq(juniorIdentities.id, identityId), eq(juniorIdentities.kind, "user"))).limit(1);
|
|
80
|
-
const url = row ? parseAvatarUrl(row.avatarUrl, row.provider) : void 0;
|
|
81
|
-
const hosts = row && AVATAR_HOSTS[row.provider];
|
|
82
|
-
return url && hosts ? {
|
|
83
|
-
hosts,
|
|
84
|
-
url
|
|
85
|
-
} : void 0;
|
|
86
|
-
}
|
|
87
|
-
// src/chat/plugins/viewer.ts
|
|
88
|
-
function identityFromRow(row) {
|
|
89
|
-
return identitySchema.parse({
|
|
90
|
-
id: row.id,
|
|
91
|
-
provider: row.provider,
|
|
92
|
-
providerSubjectId: row.providerSubjectId,
|
|
93
|
-
...row.providerTenantId ? { providerTenantId: row.providerTenantId } : void 0,
|
|
94
|
-
...row.displayName ? { displayName: row.displayName } : void 0,
|
|
95
|
-
...row.handle ? { handle: row.handle } : void 0
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
async function readUserById(db, userRow) {
|
|
99
|
-
return userFromRows(userRow, await db.select().from(juniorIdentities).where(and(eq(juniorIdentities.userId, userRow.id), eq(juniorIdentities.kind, "user"))).orderBy(asc(juniorIdentities.provider), asc(juniorIdentities.providerTenantId), asc(juniorIdentities.providerSubjectId)));
|
|
100
|
-
}
|
|
101
|
-
function userFromRows(userRow, identityRows) {
|
|
102
|
-
return userSchema.parse({
|
|
103
|
-
email: userRow.primaryEmail,
|
|
104
|
-
id: userRow.id,
|
|
105
|
-
identities: identityRows.map(identityFromRow),
|
|
106
|
-
...userRow.displayName ? { displayName: userRow.displayName } : void 0,
|
|
107
|
-
...userRow.isAdmin ? { isAdmin: true } : void 0
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
async function readUserByNormalizedEmail(db, normalizedEmail) {
|
|
111
|
-
const cached = await readCachedUserByEmail(db, normalizedEmail);
|
|
112
|
-
return cached ? userFromRows(cached.user, cached.identities) : void 0;
|
|
113
|
-
}
|
|
114
|
-
/** Resolve or create the canonical user for one verified viewer email. */
|
|
115
|
-
async function resolveViewerUserFromSql(db, email) {
|
|
116
|
-
const normalizedEmail = normalizeIdentityEmail(email);
|
|
117
|
-
if (!normalizedEmail) return void 0;
|
|
118
|
-
const existing = await readUserByNormalizedEmail(db, normalizedEmail);
|
|
119
|
-
if (existing) return existing;
|
|
120
|
-
const now = /* @__PURE__ */ new Date();
|
|
121
|
-
const userRow = (await db.insert(juniorUsers).values({
|
|
122
|
-
id: randomUUID(),
|
|
123
|
-
primaryEmail: email.trim(),
|
|
124
|
-
primaryEmailNormalized: normalizedEmail,
|
|
125
|
-
displayName: null,
|
|
126
|
-
createdAt: now,
|
|
127
|
-
updatedAt: now
|
|
128
|
-
}).onConflictDoNothing({ target: juniorUsers.primaryEmailNormalized }).returning())[0] ?? (await db.select().from(juniorUsers).where(eq(juniorUsers.primaryEmailNormalized, normalizedEmail)).limit(1))[0];
|
|
129
|
-
return userRow ? await readUserById(db, userRow) : void 0;
|
|
130
|
-
}
|
|
131
|
-
/** Resolve or create the canonical user for one authenticated viewer. */
|
|
132
|
-
async function resolveViewerUser(email) {
|
|
133
|
-
return await resolveViewerUserFromSql(getDb(), email);
|
|
134
|
-
}
|
|
135
|
-
/** Read one existing canonical user by verified email without creating a row. */
|
|
136
|
-
async function findUserByEmailFromSql(db, email) {
|
|
137
|
-
const normalizedEmail = normalizeIdentityEmail(email);
|
|
138
|
-
if (!normalizedEmail) return void 0;
|
|
139
|
-
return await readUserByNormalizedEmail(db, normalizedEmail);
|
|
140
|
-
}
|
|
141
|
-
/** Read one existing canonical user by verified email without creating a row. */
|
|
142
|
-
async function findUserByEmail(email) {
|
|
143
|
-
return await findUserByEmailFromSql(getDb(), email);
|
|
144
|
-
}
|
|
145
|
-
/** Update one canonical user's display name in SQL. */
|
|
146
|
-
async function updateViewerDisplayNameFromSql(db, userId, displayName) {
|
|
147
|
-
const rows = await db.update(juniorUsers).set({
|
|
148
|
-
displayName,
|
|
149
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
150
|
-
}).where(eq(juniorUsers.id, userId)).returning();
|
|
151
|
-
await clearCachedUser(userId);
|
|
152
|
-
const userRow = rows[0];
|
|
153
|
-
return userRow ? await readUserById(db, userRow) : void 0;
|
|
154
|
-
}
|
|
155
|
-
/** Read the photo path of one canonical user: Slack, then Google. */
|
|
156
|
-
async function readViewerAvatarUrl(userId) {
|
|
157
|
-
return (await readUserAvatarUrls(getDb(), [userId])).get(userId);
|
|
158
|
-
}
|
|
159
|
-
/** Update one canonical user's display name. */
|
|
160
|
-
async function updateViewerDisplayName(userId, displayName) {
|
|
161
|
-
return await updateViewerDisplayNameFromSql(getDb(), userId, displayName);
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Grant or revoke the Junior-wide admin role for one email.
|
|
165
|
-
*
|
|
166
|
-
* Granting creates the canonical user when needed, so an operator can grant
|
|
167
|
-
* admin before that person first signs in. Revoking never creates a user.
|
|
168
|
-
*/
|
|
169
|
-
async function setUserAdminFromSql(db, email, isAdmin) {
|
|
170
|
-
const user = isAdmin ? await resolveViewerUserFromSql(db, email) : await findUserByEmailFromSql(db, email);
|
|
171
|
-
if (!user) return void 0;
|
|
172
|
-
const rows = await db.update(juniorUsers).set({
|
|
173
|
-
isAdmin,
|
|
174
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
175
|
-
}).where(eq(juniorUsers.id, user.id)).returning();
|
|
176
|
-
await clearCachedUser(user.id);
|
|
177
|
-
const userRow = rows[0];
|
|
178
|
-
return userRow ? await readUserById(db, userRow) : void 0;
|
|
179
|
-
}
|
|
180
|
-
/** List every Junior admin by primary email. */
|
|
181
|
-
async function listAdminUsersFromSql(db) {
|
|
182
|
-
const rows = await db.select().from(juniorUsers).where(eq(juniorUsers.isAdmin, true)).orderBy(asc(juniorUsers.primaryEmailNormalized));
|
|
183
|
-
if (rows.length === 0) return [];
|
|
184
|
-
const identityRows = await db.select().from(juniorIdentities).where(and(inArray(juniorIdentities.userId, rows.map((row) => row.id)), eq(juniorIdentities.kind, "user"))).orderBy(asc(juniorIdentities.provider), asc(juniorIdentities.providerTenantId), asc(juniorIdentities.providerSubjectId));
|
|
185
|
-
return rows.map((row) => userFromRows(row, identityRows.filter((identity) => identity.userId === row.id)));
|
|
186
|
-
}
|
|
187
|
-
/** Resolve the stored identity and linked user for one runtime actor. */
|
|
188
|
-
async function readActorIdentityFromSql(db, actor) {
|
|
189
|
-
const identityId = await findActorIdentityId(db, actor);
|
|
190
|
-
return identityId ? await readIdentityByIdFromSql(db, identityId) : void 0;
|
|
191
|
-
}
|
|
192
|
-
/** Resolve the stored identity and linked user for one runtime actor. */
|
|
193
|
-
async function readActorIdentity(actor) {
|
|
194
|
-
return await readActorIdentityFromSql(getDb(), actor);
|
|
195
|
-
}
|
|
196
|
-
/** Read one stored identity and its linked user by identity id. */
|
|
197
|
-
async function readIdentityByIdFromSql(db, identityId) {
|
|
198
|
-
const row = (await db.select({
|
|
199
|
-
identity: juniorIdentities,
|
|
200
|
-
user: juniorUsers
|
|
201
|
-
}).from(juniorIdentities).leftJoin(juniorUsers, eq(juniorUsers.id, juniorIdentities.userId)).where(and(eq(juniorIdentities.id, identityId), eq(juniorIdentities.kind, "user"))).limit(1))[0];
|
|
202
|
-
if (!row) return void 0;
|
|
203
|
-
return {
|
|
204
|
-
identity: identityFromRow(row.identity),
|
|
205
|
-
...row.user ? { user: await readUserById(db, row.user) } : void 0
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
/** Read one stored identity and its linked user by identity id. */
|
|
209
|
-
async function readIdentityById(identityId) {
|
|
210
|
-
return await readIdentityByIdFromSql(getDb(), identityId);
|
|
211
|
-
}
|
|
212
|
-
export { readActorIdentityFromSql as a, readViewerAvatarUrl as c, updateViewerDisplayName as d, identityAvatarUrl as f, userAvatarUrlsFromIdentities as g, readUserAvatarUrls as h, readActorIdentity as i, resolveViewerUser as l, readAvatarFetch as m, findUserByEmailFromSql as n, readIdentityById as o, parseAvatarUrl as p, listAdminUsersFromSql as r, readIdentityByIdFromSql as s, findUserByEmail as t, setUserAdminFromSql as u };
|