weave-typescript 0.34.0 → 0.36.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/weaveapi/auth/v1/auth.pb.d.ts +33 -0
- package/dist/weaveapi/auth/v1/auth.pb.js +520 -3
- package/dist/weaveapi/auth/v1/service.pb.d.ts +49 -1
- package/dist/weaveapi/auth/v1/service.pb.js +391 -5
- package/dist/weavesql/weavedb/auth_identity_sql.d.ts +223 -0
- package/dist/weavesql/weavedb/auth_identity_sql.js +520 -1
- package/package.json +1 -1
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteExpiredApplicationSessionsQuery = exports.markApplicationSessionOrganizationSessionStateQuery = exports.listApplicationSessionOrganizationSessionStatesQuery = exports.getApplicationSessionOrganizationSessionQuery = exports.upsertApplicationSessionOrganizationSessionQuery = exports.revokeApplicationSessionQuery = exports.setApplicationSessionActiveOrganizationQuery = exports.getApplicationSessionQuery = exports.createApplicationSessionQuery = exports.insertAuthAuditEventQuery = exports.endSupportAccessSessionQuery = exports.createSupportAccessSessionQuery = exports.createPlatformAdminGrantQuery = exports.listActivePlatformAdminGrantsForUserQuery = exports.listOrganizationMembersQuery = exports.listOrganizationMembershipsForUserQuery = exports.getOrganizationMembershipQuery = exports.upsertOrganizationMembershipQuery = exports.upsertOrganizationAuthLinkQuery = exports.getOrganizationAuthLinkByOrganizationIDQuery = exports.getOrganizationAuthLinkByStytchIDQuery = exports.upsertIdentityLinkQuery = exports.getIdentityLinkByStytchMemberQuery = exports.getUserProfileQuery = exports.upsertUserProfileQuery = exports.deleteOrganizationAuthDomainQuery = exports.listOrganizationAuthDomainsQuery = exports.upsertOrganizationAuthDomainQuery = exports.resolvePrimaryOrganizationAuthLinkByDomainQuery = exports.getUserPrimaryOrganizationAuthLinkQuery = exports.setUserPrimaryOrganizationQuery = exports.getUserByIDQuery = exports.createUserQuery = void 0;
|
|
3
|
+
exports.deleteExpiredAuthInviteSessionsQuery = exports.revokeAuthInviteSessionsByMemberQuery = exports.markAuthInviteSessionRecoveryRequiredQuery = exports.markAuthInviteSessionCompletedQuery = exports.setAuthInviteSessionOAuthStateQuery = exports.getAuthInviteSessionQuery = exports.createAuthInviteSessionQuery = exports.deleteExpiredApplicationSessionsQuery = exports.markApplicationSessionOrganizationSessionStateQuery = exports.listApplicationSessionOrganizationSessionStatesQuery = exports.getApplicationSessionOrganizationSessionQuery = exports.upsertApplicationSessionOrganizationSessionQuery = exports.revokeApplicationSessionQuery = exports.setApplicationSessionActiveOrganizationQuery = exports.getApplicationSessionQuery = exports.createApplicationSessionQuery = exports.insertAuthAuditEventQuery = exports.endSupportAccessSessionQuery = exports.createSupportAccessSessionQuery = exports.createPlatformAdminGrantQuery = exports.listActivePlatformAdminGrantsForUserQuery = exports.listOrganizationMembersQuery = exports.listOrganizationMembershipsForUserQuery = exports.getOrganizationMembershipQuery = exports.upsertOrganizationMembershipQuery = exports.upsertOrganizationAuthLinkQuery = exports.getOrganizationAuthLinkByOrganizationIDQuery = exports.getOrganizationAuthLinkByStytchIDQuery = exports.upsertIdentityLinkQuery = exports.getIdentityLinkByStytchMemberQuery = exports.getUserProfileQuery = exports.upsertUserProfileQuery = exports.deleteOrganizationAuthDomainQuery = exports.listOrganizationAuthDomainsQuery = exports.upsertOrganizationAuthDomainQuery = exports.resolvePrimaryOrganizationAuthLinkByDomainQuery = exports.updateUserProfileThemeQuery = exports.setUserOrganizationPagePositionQuery = exports.setUserLastOrganizationQuery = exports.getUserAuthPreferencesQuery = exports.getUserPrimaryOrganizationAuthLinkQuery = exports.setUserPrimaryOrganizationQuery = exports.getUserByIDQuery = exports.createUserQuery = void 0;
|
|
4
4
|
exports.createUser = createUser;
|
|
5
5
|
exports.getUserByID = getUserByID;
|
|
6
6
|
exports.setUserPrimaryOrganization = setUserPrimaryOrganization;
|
|
7
7
|
exports.getUserPrimaryOrganizationAuthLink = getUserPrimaryOrganizationAuthLink;
|
|
8
|
+
exports.getUserAuthPreferences = getUserAuthPreferences;
|
|
9
|
+
exports.setUserLastOrganization = setUserLastOrganization;
|
|
10
|
+
exports.setUserOrganizationPagePosition = setUserOrganizationPagePosition;
|
|
11
|
+
exports.updateUserProfileTheme = updateUserProfileTheme;
|
|
8
12
|
exports.resolvePrimaryOrganizationAuthLinkByDomain = resolvePrimaryOrganizationAuthLinkByDomain;
|
|
9
13
|
exports.upsertOrganizationAuthDomain = upsertOrganizationAuthDomain;
|
|
10
14
|
exports.listOrganizationAuthDomains = listOrganizationAuthDomains;
|
|
@@ -30,6 +34,11 @@ exports.upsertApplicationSessionOrganizationSession = upsertApplicationSessionOr
|
|
|
30
34
|
exports.getApplicationSessionOrganizationSession = getApplicationSessionOrganizationSession;
|
|
31
35
|
exports.listApplicationSessionOrganizationSessionStates = listApplicationSessionOrganizationSessionStates;
|
|
32
36
|
exports.markApplicationSessionOrganizationSessionState = markApplicationSessionOrganizationSessionState;
|
|
37
|
+
exports.createAuthInviteSession = createAuthInviteSession;
|
|
38
|
+
exports.getAuthInviteSession = getAuthInviteSession;
|
|
39
|
+
exports.setAuthInviteSessionOAuthState = setAuthInviteSessionOAuthState;
|
|
40
|
+
exports.markAuthInviteSessionCompleted = markAuthInviteSessionCompleted;
|
|
41
|
+
exports.markAuthInviteSessionRecoveryRequired = markAuthInviteSessionRecoveryRequired;
|
|
33
42
|
exports.createUserQuery = `-- name: CreateUser :one
|
|
34
43
|
INSERT INTO weave.users (status)
|
|
35
44
|
VALUES ($1)
|
|
@@ -144,6 +153,155 @@ async function getUserPrimaryOrganizationAuthLink(client, args) {
|
|
|
144
153
|
updatedAt: row[9]
|
|
145
154
|
};
|
|
146
155
|
}
|
|
156
|
+
exports.getUserAuthPreferencesQuery = `-- name: GetUserAuthPreferences :one
|
|
157
|
+
SELECT
|
|
158
|
+
u.id AS user_id,
|
|
159
|
+
u.primary_organization_id AS default_organization_id,
|
|
160
|
+
default_org.slug AS default_organization_slug,
|
|
161
|
+
u.last_organization_id,
|
|
162
|
+
last_org.slug AS last_organization_slug,
|
|
163
|
+
u.organization_page_positions,
|
|
164
|
+
COALESCE(p.theme, 'system') AS theme,
|
|
165
|
+
u.updated_at
|
|
166
|
+
FROM weave.users AS u
|
|
167
|
+
LEFT JOIN weave.organizations AS default_org
|
|
168
|
+
ON default_org.id = u.primary_organization_id
|
|
169
|
+
LEFT JOIN weave.organizations AS last_org
|
|
170
|
+
ON last_org.id = u.last_organization_id
|
|
171
|
+
LEFT JOIN weave.user_profiles AS p
|
|
172
|
+
ON p.user_id = u.id
|
|
173
|
+
WHERE u.id = $1
|
|
174
|
+
AND u.status = 'active'`;
|
|
175
|
+
async function getUserAuthPreferences(client, args) {
|
|
176
|
+
const result = await client.query({
|
|
177
|
+
text: exports.getUserAuthPreferencesQuery,
|
|
178
|
+
values: [args.userId],
|
|
179
|
+
rowMode: "array"
|
|
180
|
+
});
|
|
181
|
+
if (result.rows.length !== 1) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const row = result.rows[0];
|
|
185
|
+
return {
|
|
186
|
+
userId: row[0],
|
|
187
|
+
defaultOrganizationId: row[1],
|
|
188
|
+
defaultOrganizationSlug: row[2],
|
|
189
|
+
lastOrganizationId: row[3],
|
|
190
|
+
lastOrganizationSlug: row[4],
|
|
191
|
+
organizationPagePositions: row[5],
|
|
192
|
+
theme: row[6],
|
|
193
|
+
updatedAt: row[7]
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
exports.setUserLastOrganizationQuery = `-- name: SetUserLastOrganization :one
|
|
197
|
+
UPDATE weave.users AS u
|
|
198
|
+
SET
|
|
199
|
+
last_organization_id = o.id,
|
|
200
|
+
updated_at = now()
|
|
201
|
+
FROM weave.organizations AS o
|
|
202
|
+
JOIN weave.organization_memberships AS m
|
|
203
|
+
ON m.organization_id = o.id
|
|
204
|
+
AND m.user_id = $1
|
|
205
|
+
AND m.status = 'active'
|
|
206
|
+
WHERE u.id = $1
|
|
207
|
+
AND u.status = 'active'
|
|
208
|
+
AND o.slug = $2
|
|
209
|
+
RETURNING
|
|
210
|
+
u.id AS user_id,
|
|
211
|
+
o.id AS last_organization_id,
|
|
212
|
+
o.slug AS last_organization_slug,
|
|
213
|
+
u.updated_at`;
|
|
214
|
+
async function setUserLastOrganization(client, args) {
|
|
215
|
+
const result = await client.query({
|
|
216
|
+
text: exports.setUserLastOrganizationQuery,
|
|
217
|
+
values: [args.userId, args.organizationSlug],
|
|
218
|
+
rowMode: "array"
|
|
219
|
+
});
|
|
220
|
+
if (result.rows.length !== 1) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
const row = result.rows[0];
|
|
224
|
+
return {
|
|
225
|
+
userId: row[0],
|
|
226
|
+
lastOrganizationId: row[1],
|
|
227
|
+
lastOrganizationSlug: row[2],
|
|
228
|
+
updatedAt: row[3]
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
exports.setUserOrganizationPagePositionQuery = `-- name: SetUserOrganizationPagePosition :one
|
|
232
|
+
UPDATE weave.users AS u
|
|
233
|
+
SET
|
|
234
|
+
organization_page_positions =
|
|
235
|
+
u.organization_page_positions || jsonb_build_object(o.slug, $1::text),
|
|
236
|
+
updated_at = now()
|
|
237
|
+
FROM weave.organizations AS o
|
|
238
|
+
JOIN weave.organization_memberships AS m
|
|
239
|
+
ON m.organization_id = o.id
|
|
240
|
+
AND m.user_id = $2
|
|
241
|
+
AND m.status = 'active'
|
|
242
|
+
WHERE u.id = $2
|
|
243
|
+
AND u.status = 'active'
|
|
244
|
+
AND o.slug = $3
|
|
245
|
+
RETURNING
|
|
246
|
+
u.id AS user_id,
|
|
247
|
+
o.id AS organization_id,
|
|
248
|
+
o.slug AS organization_slug,
|
|
249
|
+
u.organization_page_positions,
|
|
250
|
+
u.updated_at`;
|
|
251
|
+
async function setUserOrganizationPagePosition(client, args) {
|
|
252
|
+
const result = await client.query({
|
|
253
|
+
text: exports.setUserOrganizationPagePositionQuery,
|
|
254
|
+
values: [args.href, args.userId, args.organizationSlug],
|
|
255
|
+
rowMode: "array"
|
|
256
|
+
});
|
|
257
|
+
if (result.rows.length !== 1) {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
const row = result.rows[0];
|
|
261
|
+
return {
|
|
262
|
+
userId: row[0],
|
|
263
|
+
organizationId: row[1],
|
|
264
|
+
organizationSlug: row[2],
|
|
265
|
+
organizationPagePositions: row[3],
|
|
266
|
+
updatedAt: row[4]
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
exports.updateUserProfileThemeQuery = `-- name: UpdateUserProfileTheme :one
|
|
270
|
+
UPDATE weave.user_profiles
|
|
271
|
+
SET
|
|
272
|
+
theme = $1,
|
|
273
|
+
updated_at = now()
|
|
274
|
+
WHERE user_id = $2
|
|
275
|
+
RETURNING
|
|
276
|
+
user_id,
|
|
277
|
+
display_name,
|
|
278
|
+
job_title,
|
|
279
|
+
email,
|
|
280
|
+
avatar_url,
|
|
281
|
+
theme,
|
|
282
|
+
created_at,
|
|
283
|
+
updated_at`;
|
|
284
|
+
async function updateUserProfileTheme(client, args) {
|
|
285
|
+
const result = await client.query({
|
|
286
|
+
text: exports.updateUserProfileThemeQuery,
|
|
287
|
+
values: [args.theme, args.userId],
|
|
288
|
+
rowMode: "array"
|
|
289
|
+
});
|
|
290
|
+
if (result.rows.length !== 1) {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
const row = result.rows[0];
|
|
294
|
+
return {
|
|
295
|
+
userId: row[0],
|
|
296
|
+
displayName: row[1],
|
|
297
|
+
jobTitle: row[2],
|
|
298
|
+
email: row[3],
|
|
299
|
+
avatarUrl: row[4],
|
|
300
|
+
theme: row[5],
|
|
301
|
+
createdAt: row[6],
|
|
302
|
+
updatedAt: row[7]
|
|
303
|
+
};
|
|
304
|
+
}
|
|
147
305
|
exports.resolvePrimaryOrganizationAuthLinkByDomainQuery = `-- name: ResolvePrimaryOrganizationAuthLinkByDomain :one
|
|
148
306
|
SELECT
|
|
149
307
|
o.id AS organization_id,
|
|
@@ -1235,3 +1393,364 @@ exports.deleteExpiredApplicationSessionsQuery = `-- name: DeleteExpiredApplicati
|
|
|
1235
1393
|
DELETE FROM weave.application_sessions
|
|
1236
1394
|
WHERE expires_at <= now()
|
|
1237
1395
|
OR status IN ('revoked', 'expired')`;
|
|
1396
|
+
exports.createAuthInviteSessionQuery = `-- name: CreateAuthInviteSession :one
|
|
1397
|
+
INSERT INTO weave.auth_invite_sessions (
|
|
1398
|
+
organization_id,
|
|
1399
|
+
user_id,
|
|
1400
|
+
identity_link_id,
|
|
1401
|
+
stytch_organization_id,
|
|
1402
|
+
stytch_member_id,
|
|
1403
|
+
stytch_member_session_id,
|
|
1404
|
+
stytch_session_token_ciphertext,
|
|
1405
|
+
email,
|
|
1406
|
+
display_name,
|
|
1407
|
+
role_ids,
|
|
1408
|
+
return_url,
|
|
1409
|
+
expires_at
|
|
1410
|
+
) VALUES (
|
|
1411
|
+
$1,
|
|
1412
|
+
$2,
|
|
1413
|
+
$3,
|
|
1414
|
+
$4,
|
|
1415
|
+
$5,
|
|
1416
|
+
$6,
|
|
1417
|
+
$7,
|
|
1418
|
+
$8,
|
|
1419
|
+
$9,
|
|
1420
|
+
$10,
|
|
1421
|
+
$11,
|
|
1422
|
+
$12
|
|
1423
|
+
)
|
|
1424
|
+
RETURNING
|
|
1425
|
+
id,
|
|
1426
|
+
organization_id,
|
|
1427
|
+
user_id,
|
|
1428
|
+
identity_link_id,
|
|
1429
|
+
stytch_organization_id,
|
|
1430
|
+
stytch_member_id,
|
|
1431
|
+
stytch_member_session_id,
|
|
1432
|
+
stytch_session_token_ciphertext,
|
|
1433
|
+
email,
|
|
1434
|
+
display_name,
|
|
1435
|
+
role_ids,
|
|
1436
|
+
status,
|
|
1437
|
+
recovery_reason,
|
|
1438
|
+
return_url,
|
|
1439
|
+
oauth_provider,
|
|
1440
|
+
oauth_state,
|
|
1441
|
+
oauth_return_url,
|
|
1442
|
+
expires_at,
|
|
1443
|
+
completed_at,
|
|
1444
|
+
revoked_at,
|
|
1445
|
+
created_at,
|
|
1446
|
+
updated_at`;
|
|
1447
|
+
async function createAuthInviteSession(client, args) {
|
|
1448
|
+
const result = await client.query({
|
|
1449
|
+
text: exports.createAuthInviteSessionQuery,
|
|
1450
|
+
values: [args.organizationId, args.userId, args.identityLinkId, args.stytchOrganizationId, args.stytchMemberId, args.stytchMemberSessionId, args.stytchSessionTokenCiphertext, args.email, args.displayName, args.roleIds, args.returnUrl, args.expiresAt],
|
|
1451
|
+
rowMode: "array"
|
|
1452
|
+
});
|
|
1453
|
+
if (result.rows.length !== 1) {
|
|
1454
|
+
return null;
|
|
1455
|
+
}
|
|
1456
|
+
const row = result.rows[0];
|
|
1457
|
+
return {
|
|
1458
|
+
id: row[0],
|
|
1459
|
+
organizationId: row[1],
|
|
1460
|
+
userId: row[2],
|
|
1461
|
+
identityLinkId: row[3],
|
|
1462
|
+
stytchOrganizationId: row[4],
|
|
1463
|
+
stytchMemberId: row[5],
|
|
1464
|
+
stytchMemberSessionId: row[6],
|
|
1465
|
+
stytchSessionTokenCiphertext: row[7],
|
|
1466
|
+
email: row[8],
|
|
1467
|
+
displayName: row[9],
|
|
1468
|
+
roleIds: row[10],
|
|
1469
|
+
status: row[11],
|
|
1470
|
+
recoveryReason: row[12],
|
|
1471
|
+
returnUrl: row[13],
|
|
1472
|
+
oauthProvider: row[14],
|
|
1473
|
+
oauthState: row[15],
|
|
1474
|
+
oauthReturnUrl: row[16],
|
|
1475
|
+
expiresAt: row[17],
|
|
1476
|
+
completedAt: row[18],
|
|
1477
|
+
revokedAt: row[19],
|
|
1478
|
+
createdAt: row[20],
|
|
1479
|
+
updatedAt: row[21]
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
exports.getAuthInviteSessionQuery = `-- name: GetAuthInviteSession :one
|
|
1483
|
+
SELECT
|
|
1484
|
+
id,
|
|
1485
|
+
organization_id,
|
|
1486
|
+
user_id,
|
|
1487
|
+
identity_link_id,
|
|
1488
|
+
stytch_organization_id,
|
|
1489
|
+
stytch_member_id,
|
|
1490
|
+
stytch_member_session_id,
|
|
1491
|
+
stytch_session_token_ciphertext,
|
|
1492
|
+
email,
|
|
1493
|
+
display_name,
|
|
1494
|
+
role_ids,
|
|
1495
|
+
status,
|
|
1496
|
+
recovery_reason,
|
|
1497
|
+
return_url,
|
|
1498
|
+
oauth_provider,
|
|
1499
|
+
oauth_state,
|
|
1500
|
+
oauth_return_url,
|
|
1501
|
+
expires_at,
|
|
1502
|
+
completed_at,
|
|
1503
|
+
revoked_at,
|
|
1504
|
+
created_at,
|
|
1505
|
+
updated_at
|
|
1506
|
+
FROM weave.auth_invite_sessions
|
|
1507
|
+
WHERE id = $1`;
|
|
1508
|
+
async function getAuthInviteSession(client, args) {
|
|
1509
|
+
const result = await client.query({
|
|
1510
|
+
text: exports.getAuthInviteSessionQuery,
|
|
1511
|
+
values: [args.id],
|
|
1512
|
+
rowMode: "array"
|
|
1513
|
+
});
|
|
1514
|
+
if (result.rows.length !== 1) {
|
|
1515
|
+
return null;
|
|
1516
|
+
}
|
|
1517
|
+
const row = result.rows[0];
|
|
1518
|
+
return {
|
|
1519
|
+
id: row[0],
|
|
1520
|
+
organizationId: row[1],
|
|
1521
|
+
userId: row[2],
|
|
1522
|
+
identityLinkId: row[3],
|
|
1523
|
+
stytchOrganizationId: row[4],
|
|
1524
|
+
stytchMemberId: row[5],
|
|
1525
|
+
stytchMemberSessionId: row[6],
|
|
1526
|
+
stytchSessionTokenCiphertext: row[7],
|
|
1527
|
+
email: row[8],
|
|
1528
|
+
displayName: row[9],
|
|
1529
|
+
roleIds: row[10],
|
|
1530
|
+
status: row[11],
|
|
1531
|
+
recoveryReason: row[12],
|
|
1532
|
+
returnUrl: row[13],
|
|
1533
|
+
oauthProvider: row[14],
|
|
1534
|
+
oauthState: row[15],
|
|
1535
|
+
oauthReturnUrl: row[16],
|
|
1536
|
+
expiresAt: row[17],
|
|
1537
|
+
completedAt: row[18],
|
|
1538
|
+
revokedAt: row[19],
|
|
1539
|
+
createdAt: row[20],
|
|
1540
|
+
updatedAt: row[21]
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
exports.setAuthInviteSessionOAuthStateQuery = `-- name: SetAuthInviteSessionOAuthState :one
|
|
1544
|
+
UPDATE weave.auth_invite_sessions
|
|
1545
|
+
SET
|
|
1546
|
+
oauth_provider = $1,
|
|
1547
|
+
oauth_state = $2,
|
|
1548
|
+
oauth_return_url = $3,
|
|
1549
|
+
updated_at = now()
|
|
1550
|
+
WHERE id = $4
|
|
1551
|
+
AND status = 'ready'
|
|
1552
|
+
AND expires_at > now()
|
|
1553
|
+
RETURNING
|
|
1554
|
+
id,
|
|
1555
|
+
organization_id,
|
|
1556
|
+
user_id,
|
|
1557
|
+
identity_link_id,
|
|
1558
|
+
stytch_organization_id,
|
|
1559
|
+
stytch_member_id,
|
|
1560
|
+
stytch_member_session_id,
|
|
1561
|
+
stytch_session_token_ciphertext,
|
|
1562
|
+
email,
|
|
1563
|
+
display_name,
|
|
1564
|
+
role_ids,
|
|
1565
|
+
status,
|
|
1566
|
+
recovery_reason,
|
|
1567
|
+
return_url,
|
|
1568
|
+
oauth_provider,
|
|
1569
|
+
oauth_state,
|
|
1570
|
+
oauth_return_url,
|
|
1571
|
+
expires_at,
|
|
1572
|
+
completed_at,
|
|
1573
|
+
revoked_at,
|
|
1574
|
+
created_at,
|
|
1575
|
+
updated_at`;
|
|
1576
|
+
async function setAuthInviteSessionOAuthState(client, args) {
|
|
1577
|
+
const result = await client.query({
|
|
1578
|
+
text: exports.setAuthInviteSessionOAuthStateQuery,
|
|
1579
|
+
values: [args.oauthProvider, args.oauthState, args.oauthReturnUrl, args.id],
|
|
1580
|
+
rowMode: "array"
|
|
1581
|
+
});
|
|
1582
|
+
if (result.rows.length !== 1) {
|
|
1583
|
+
return null;
|
|
1584
|
+
}
|
|
1585
|
+
const row = result.rows[0];
|
|
1586
|
+
return {
|
|
1587
|
+
id: row[0],
|
|
1588
|
+
organizationId: row[1],
|
|
1589
|
+
userId: row[2],
|
|
1590
|
+
identityLinkId: row[3],
|
|
1591
|
+
stytchOrganizationId: row[4],
|
|
1592
|
+
stytchMemberId: row[5],
|
|
1593
|
+
stytchMemberSessionId: row[6],
|
|
1594
|
+
stytchSessionTokenCiphertext: row[7],
|
|
1595
|
+
email: row[8],
|
|
1596
|
+
displayName: row[9],
|
|
1597
|
+
roleIds: row[10],
|
|
1598
|
+
status: row[11],
|
|
1599
|
+
recoveryReason: row[12],
|
|
1600
|
+
returnUrl: row[13],
|
|
1601
|
+
oauthProvider: row[14],
|
|
1602
|
+
oauthState: row[15],
|
|
1603
|
+
oauthReturnUrl: row[16],
|
|
1604
|
+
expiresAt: row[17],
|
|
1605
|
+
completedAt: row[18],
|
|
1606
|
+
revokedAt: row[19],
|
|
1607
|
+
createdAt: row[20],
|
|
1608
|
+
updatedAt: row[21]
|
|
1609
|
+
};
|
|
1610
|
+
}
|
|
1611
|
+
exports.markAuthInviteSessionCompletedQuery = `-- name: MarkAuthInviteSessionCompleted :one
|
|
1612
|
+
UPDATE weave.auth_invite_sessions
|
|
1613
|
+
SET
|
|
1614
|
+
status = 'completed',
|
|
1615
|
+
completed_at = now(),
|
|
1616
|
+
updated_at = now()
|
|
1617
|
+
WHERE id = $1
|
|
1618
|
+
AND status = 'ready'
|
|
1619
|
+
AND expires_at > now()
|
|
1620
|
+
RETURNING
|
|
1621
|
+
id,
|
|
1622
|
+
organization_id,
|
|
1623
|
+
user_id,
|
|
1624
|
+
identity_link_id,
|
|
1625
|
+
stytch_organization_id,
|
|
1626
|
+
stytch_member_id,
|
|
1627
|
+
stytch_member_session_id,
|
|
1628
|
+
stytch_session_token_ciphertext,
|
|
1629
|
+
email,
|
|
1630
|
+
display_name,
|
|
1631
|
+
role_ids,
|
|
1632
|
+
status,
|
|
1633
|
+
recovery_reason,
|
|
1634
|
+
return_url,
|
|
1635
|
+
oauth_provider,
|
|
1636
|
+
oauth_state,
|
|
1637
|
+
oauth_return_url,
|
|
1638
|
+
expires_at,
|
|
1639
|
+
completed_at,
|
|
1640
|
+
revoked_at,
|
|
1641
|
+
created_at,
|
|
1642
|
+
updated_at`;
|
|
1643
|
+
async function markAuthInviteSessionCompleted(client, args) {
|
|
1644
|
+
const result = await client.query({
|
|
1645
|
+
text: exports.markAuthInviteSessionCompletedQuery,
|
|
1646
|
+
values: [args.id],
|
|
1647
|
+
rowMode: "array"
|
|
1648
|
+
});
|
|
1649
|
+
if (result.rows.length !== 1) {
|
|
1650
|
+
return null;
|
|
1651
|
+
}
|
|
1652
|
+
const row = result.rows[0];
|
|
1653
|
+
return {
|
|
1654
|
+
id: row[0],
|
|
1655
|
+
organizationId: row[1],
|
|
1656
|
+
userId: row[2],
|
|
1657
|
+
identityLinkId: row[3],
|
|
1658
|
+
stytchOrganizationId: row[4],
|
|
1659
|
+
stytchMemberId: row[5],
|
|
1660
|
+
stytchMemberSessionId: row[6],
|
|
1661
|
+
stytchSessionTokenCiphertext: row[7],
|
|
1662
|
+
email: row[8],
|
|
1663
|
+
displayName: row[9],
|
|
1664
|
+
roleIds: row[10],
|
|
1665
|
+
status: row[11],
|
|
1666
|
+
recoveryReason: row[12],
|
|
1667
|
+
returnUrl: row[13],
|
|
1668
|
+
oauthProvider: row[14],
|
|
1669
|
+
oauthState: row[15],
|
|
1670
|
+
oauthReturnUrl: row[16],
|
|
1671
|
+
expiresAt: row[17],
|
|
1672
|
+
completedAt: row[18],
|
|
1673
|
+
revokedAt: row[19],
|
|
1674
|
+
createdAt: row[20],
|
|
1675
|
+
updatedAt: row[21]
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
exports.markAuthInviteSessionRecoveryRequiredQuery = `-- name: MarkAuthInviteSessionRecoveryRequired :one
|
|
1679
|
+
UPDATE weave.auth_invite_sessions
|
|
1680
|
+
SET
|
|
1681
|
+
status = 'recovery_required',
|
|
1682
|
+
recovery_reason = $1,
|
|
1683
|
+
updated_at = now()
|
|
1684
|
+
WHERE id = $2
|
|
1685
|
+
AND status IN ('ready', 'expired', 'recovery_required')
|
|
1686
|
+
RETURNING
|
|
1687
|
+
id,
|
|
1688
|
+
organization_id,
|
|
1689
|
+
user_id,
|
|
1690
|
+
identity_link_id,
|
|
1691
|
+
stytch_organization_id,
|
|
1692
|
+
stytch_member_id,
|
|
1693
|
+
stytch_member_session_id,
|
|
1694
|
+
stytch_session_token_ciphertext,
|
|
1695
|
+
email,
|
|
1696
|
+
display_name,
|
|
1697
|
+
role_ids,
|
|
1698
|
+
status,
|
|
1699
|
+
recovery_reason,
|
|
1700
|
+
return_url,
|
|
1701
|
+
oauth_provider,
|
|
1702
|
+
oauth_state,
|
|
1703
|
+
oauth_return_url,
|
|
1704
|
+
expires_at,
|
|
1705
|
+
completed_at,
|
|
1706
|
+
revoked_at,
|
|
1707
|
+
created_at,
|
|
1708
|
+
updated_at`;
|
|
1709
|
+
async function markAuthInviteSessionRecoveryRequired(client, args) {
|
|
1710
|
+
const result = await client.query({
|
|
1711
|
+
text: exports.markAuthInviteSessionRecoveryRequiredQuery,
|
|
1712
|
+
values: [args.recoveryReason, args.id],
|
|
1713
|
+
rowMode: "array"
|
|
1714
|
+
});
|
|
1715
|
+
if (result.rows.length !== 1) {
|
|
1716
|
+
return null;
|
|
1717
|
+
}
|
|
1718
|
+
const row = result.rows[0];
|
|
1719
|
+
return {
|
|
1720
|
+
id: row[0],
|
|
1721
|
+
organizationId: row[1],
|
|
1722
|
+
userId: row[2],
|
|
1723
|
+
identityLinkId: row[3],
|
|
1724
|
+
stytchOrganizationId: row[4],
|
|
1725
|
+
stytchMemberId: row[5],
|
|
1726
|
+
stytchMemberSessionId: row[6],
|
|
1727
|
+
stytchSessionTokenCiphertext: row[7],
|
|
1728
|
+
email: row[8],
|
|
1729
|
+
displayName: row[9],
|
|
1730
|
+
roleIds: row[10],
|
|
1731
|
+
status: row[11],
|
|
1732
|
+
recoveryReason: row[12],
|
|
1733
|
+
returnUrl: row[13],
|
|
1734
|
+
oauthProvider: row[14],
|
|
1735
|
+
oauthState: row[15],
|
|
1736
|
+
oauthReturnUrl: row[16],
|
|
1737
|
+
expiresAt: row[17],
|
|
1738
|
+
completedAt: row[18],
|
|
1739
|
+
revokedAt: row[19],
|
|
1740
|
+
createdAt: row[20],
|
|
1741
|
+
updatedAt: row[21]
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
exports.revokeAuthInviteSessionsByMemberQuery = `-- name: RevokeAuthInviteSessionsByMember :execrows
|
|
1745
|
+
UPDATE weave.auth_invite_sessions
|
|
1746
|
+
SET
|
|
1747
|
+
status = 'revoked',
|
|
1748
|
+
revoked_at = now(),
|
|
1749
|
+
updated_at = now()
|
|
1750
|
+
WHERE stytch_organization_id = $1
|
|
1751
|
+
AND stytch_member_id = $2
|
|
1752
|
+
AND status = 'ready'`;
|
|
1753
|
+
exports.deleteExpiredAuthInviteSessionsQuery = `-- name: DeleteExpiredAuthInviteSessions :execrows
|
|
1754
|
+
DELETE FROM weave.auth_invite_sessions
|
|
1755
|
+
WHERE expires_at <= now()
|
|
1756
|
+
OR status IN ('completed', 'expired', 'revoked')`;
|