@lightupai/polaris 0.0.41 → 0.0.43

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/.env.example CHANGED
@@ -15,3 +15,6 @@ SLACK_APP_TOKEN=xapp-...
15
15
 
16
16
  # Long message mode: snippet, thread, or inline
17
17
  POLARIS_LONG_MSG=snippet
18
+
19
+ # Signup notifications — posts to #alerts-mql-stream via Slack bot token (xoxb-...)
20
+ SIGNUP_SLACK_BOT_TOKEN=
@@ -45,6 +45,7 @@ services:
45
45
  SLACK_CLIENT_ID: ${SLACK_CLIENT_ID}
46
46
  SLACK_CLIENT_SECRET: ${SLACK_CLIENT_SECRET}
47
47
  SLACK_REDIRECT_URI: https://app.withpolaris.ai/slack/callback
48
+ SIGNUP_SLACK_BOT_TOKEN: ${SIGNUP_SLACK_BOT_TOKEN:-}
48
49
  depends_on:
49
50
  postgres:
50
51
  condition: service_healthy
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightupai/polaris",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "polaris": "bin/polaris",
package/src/service/db.ts CHANGED
@@ -194,6 +194,17 @@ export async function listUsers(sql: Sql, orgId: string): Promise<User[]> {
194
194
  return rows.map((r) => ({ ...r, created_at: r.created_at.toISOString() }) as User);
195
195
  }
196
196
 
197
+ export async function getRecentSignups(sql: Sql, since: Date, limit = 10): Promise<Array<User & { org_name: string }>> {
198
+ const rows = await sql`
199
+ SELECT u.*, o.name as org_name
200
+ FROM users u JOIN orgs o ON u.org_id = o.id
201
+ WHERE u.created_at >= ${since.toISOString()}
202
+ ORDER BY u.created_at DESC
203
+ LIMIT ${limit}
204
+ `;
205
+ return rows.map((r) => ({ ...r, created_at: r.created_at.toISOString(), org_name: r.org_name }) as User & { org_name: string });
206
+ }
207
+
197
208
  // --- Projects (org-scoped) ---
198
209
 
199
210
  export async function createProject(sql: Sql, orgId: string, name: string): Promise<Project> {
package/src/web/app.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  listSessions,
15
15
  getSessionPromptCounts,
16
16
  getProjectEvents,
17
+ getRecentSignups,
17
18
  type Sql,
18
19
  } from "../service/db";
19
20
  import { layout, nav } from "./layout";
@@ -30,6 +31,55 @@ import {
30
31
  mockDevices,
31
32
  } from "./fixtures";
32
33
 
34
+ // --- Signup notifications ---
35
+
36
+ const SIGNUP_CHANNEL = "#alerts-mql-stream";
37
+
38
+ function notifySignup(opts: { name: string; email: string; domain: string; orgName: string; isNewOrg: boolean }): void {
39
+ const botToken = process.env.SIGNUP_SLACK_BOT_TOKEN;
40
+ if (!botToken) return;
41
+
42
+ const emoji = opts.isNewOrg ? ":tada:" : ":wave:";
43
+ const action = opts.isNewOrg ? "signed up (new org)" : "joined";
44
+ const text = `${emoji} *${opts.name}* (${opts.email}) ${action} — ${opts.orgName} (${opts.domain})`;
45
+
46
+ fetch("https://slack.com/api/chat.postMessage", {
47
+ method: "POST",
48
+ headers: {
49
+ Authorization: `Bearer ${botToken}`,
50
+ "Content-Type": "application/json",
51
+ },
52
+ body: JSON.stringify({ channel: SIGNUP_CHANNEL, text }),
53
+ }).catch(() => {});
54
+ }
55
+
56
+ function startSignupRollup(sql: Sql): void {
57
+ const HOUR = 60 * 60 * 1000;
58
+
59
+ async function postRollup(): Promise<void> {
60
+ const botToken = process.env.SIGNUP_SLACK_BOT_TOKEN;
61
+ if (!botToken) return;
62
+
63
+ const since = new Date(Date.now() - HOUR);
64
+ const signups = await getRecentSignups(sql, since, 10);
65
+ if (signups.length === 0) return;
66
+
67
+ const lines = signups.map((s) => `• *${s.name}* (${s.email}) — ${s.org_name}`);
68
+ const text = `:chart_with_upwards_trend: *${signups.length} signup${signups.length === 1 ? "" : "s"} in the last hour*\n${lines.join("\n")}`;
69
+
70
+ fetch("https://slack.com/api/chat.postMessage", {
71
+ method: "POST",
72
+ headers: {
73
+ Authorization: `Bearer ${botToken}`,
74
+ "Content-Type": "application/json",
75
+ },
76
+ body: JSON.stringify({ channel: SIGNUP_CHANNEL, text }),
77
+ }).catch(() => {});
78
+ }
79
+
80
+ setInterval(postRollup, HOUR);
81
+ }
82
+
33
83
  // --- Google OAuth ---
34
84
 
35
85
  function getGoogle(): Google {
@@ -66,6 +116,9 @@ setInterval(() => {
66
116
  export function createApp(sql: Sql) {
67
117
  const app = new Hono();
68
118
 
119
+ // Start hourly signup rollup
120
+ startSignupRollup(sql);
121
+
69
122
  // --- Landing page ---
70
123
 
71
124
  app.get("/", (c) => {
@@ -129,6 +182,20 @@ export function createApp(sql: Sql) {
129
182
  const userId = crypto.randomUUID();
130
183
  const participantId = `user:${name.toLowerCase().replace(/\s+/g, ".")}`;
131
184
  await createUser(sql, userId, email, name, existingOrg.id, participantId);
185
+
186
+ // Notify org's Slack system channel
187
+ postSystemEvent({
188
+ sql,
189
+ orgId: existingOrg.id,
190
+ sender: participantId,
191
+ text: `:wave: *${name}* (${email}) joined the team`,
192
+ botToken: existingOrg.slack_bot_token ?? undefined,
193
+ channelId: existingOrg.slack_system_channel_id ?? undefined,
194
+ }).catch(() => {});
195
+
196
+ // Notify internal team
197
+ notifySignup({ name, email, domain, orgName: existingOrg.name, isNewOrg: false });
198
+
132
199
  const token = await createToken({ sub: userId, email, name, org_id: existingOrg.id, participant_id: participantId });
133
200
  return authRedirect(c, state, token);
134
201
  }
@@ -144,6 +211,10 @@ export function createApp(sql: Sql) {
144
211
  const userId = crypto.randomUUID();
145
212
  const participantId = `user:${name.toLowerCase().replace(/\s+/g, ".")}`;
146
213
  await createUser(sql, userId, email, name, orgId, participantId);
214
+
215
+ // Notify internal team
216
+ notifySignup({ name, email, domain, orgName, isNewOrg: true });
217
+
147
218
  const token = await createToken({ sub: userId, email, name, org_id: orgId, participant_id: participantId });
148
219
  return authRedirect(c, state, token);
149
220
  });