weave-typescript 0.30.0 → 0.31.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 +260 -0
- package/dist/weaveapi/auth/v1/auth.pb.js +3175 -0
- package/dist/weaveapi/auth/v1/service.pb.d.ts +761 -0
- package/dist/weaveapi/auth/v1/service.pb.js +6196 -0
- package/dist/weavesql/weavedb/auth_identity_sql.d.ts +295 -0
- package/dist/weavesql/weavedb/auth_identity_sql.js +690 -0
- package/package.json +1 -1
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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.getUserByIDQuery = exports.createUserQuery = void 0;
|
|
4
|
+
exports.createUser = createUser;
|
|
5
|
+
exports.getUserByID = getUserByID;
|
|
6
|
+
exports.upsertUserProfile = upsertUserProfile;
|
|
7
|
+
exports.getUserProfile = getUserProfile;
|
|
8
|
+
exports.getIdentityLinkByStytchMember = getIdentityLinkByStytchMember;
|
|
9
|
+
exports.upsertIdentityLink = upsertIdentityLink;
|
|
10
|
+
exports.getOrganizationAuthLinkByStytchID = getOrganizationAuthLinkByStytchID;
|
|
11
|
+
exports.getOrganizationAuthLinkByOrganizationID = getOrganizationAuthLinkByOrganizationID;
|
|
12
|
+
exports.upsertOrganizationAuthLink = upsertOrganizationAuthLink;
|
|
13
|
+
exports.upsertOrganizationMembership = upsertOrganizationMembership;
|
|
14
|
+
exports.getOrganizationMembership = getOrganizationMembership;
|
|
15
|
+
exports.listOrganizationMembershipsForUser = listOrganizationMembershipsForUser;
|
|
16
|
+
exports.listOrganizationMembers = listOrganizationMembers;
|
|
17
|
+
exports.listActivePlatformAdminGrantsForUser = listActivePlatformAdminGrantsForUser;
|
|
18
|
+
exports.createPlatformAdminGrant = createPlatformAdminGrant;
|
|
19
|
+
exports.createSupportAccessSession = createSupportAccessSession;
|
|
20
|
+
exports.insertAuthAuditEvent = insertAuthAuditEvent;
|
|
21
|
+
exports.createUserQuery = `-- name: CreateUser :one
|
|
22
|
+
INSERT INTO weave.users (status)
|
|
23
|
+
VALUES ($1)
|
|
24
|
+
RETURNING id, status, created_at, updated_at`;
|
|
25
|
+
async function createUser(client, args) {
|
|
26
|
+
const result = await client.query({
|
|
27
|
+
text: exports.createUserQuery,
|
|
28
|
+
values: [args.status],
|
|
29
|
+
rowMode: "array"
|
|
30
|
+
});
|
|
31
|
+
if (result.rows.length !== 1) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const row = result.rows[0];
|
|
35
|
+
return {
|
|
36
|
+
id: row[0],
|
|
37
|
+
status: row[1],
|
|
38
|
+
createdAt: row[2],
|
|
39
|
+
updatedAt: row[3]
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.getUserByIDQuery = `-- name: GetUserByID :one
|
|
43
|
+
SELECT id, status, created_at, updated_at
|
|
44
|
+
FROM weave.users
|
|
45
|
+
WHERE id = $1`;
|
|
46
|
+
async function getUserByID(client, args) {
|
|
47
|
+
const result = await client.query({
|
|
48
|
+
text: exports.getUserByIDQuery,
|
|
49
|
+
values: [args.id],
|
|
50
|
+
rowMode: "array"
|
|
51
|
+
});
|
|
52
|
+
if (result.rows.length !== 1) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const row = result.rows[0];
|
|
56
|
+
return {
|
|
57
|
+
id: row[0],
|
|
58
|
+
status: row[1],
|
|
59
|
+
createdAt: row[2],
|
|
60
|
+
updatedAt: row[3]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.upsertUserProfileQuery = `-- name: UpsertUserProfile :one
|
|
64
|
+
INSERT INTO weave.user_profiles (
|
|
65
|
+
user_id,
|
|
66
|
+
display_name,
|
|
67
|
+
job_title,
|
|
68
|
+
email,
|
|
69
|
+
avatar_url,
|
|
70
|
+
theme
|
|
71
|
+
) VALUES (
|
|
72
|
+
$1,
|
|
73
|
+
$2,
|
|
74
|
+
$3,
|
|
75
|
+
$4,
|
|
76
|
+
$5,
|
|
77
|
+
$6
|
|
78
|
+
)
|
|
79
|
+
ON CONFLICT (user_id) DO UPDATE
|
|
80
|
+
SET
|
|
81
|
+
display_name = EXCLUDED.display_name,
|
|
82
|
+
job_title = EXCLUDED.job_title,
|
|
83
|
+
email = EXCLUDED.email,
|
|
84
|
+
avatar_url = EXCLUDED.avatar_url,
|
|
85
|
+
theme = EXCLUDED.theme,
|
|
86
|
+
updated_at = now()
|
|
87
|
+
RETURNING
|
|
88
|
+
user_id,
|
|
89
|
+
display_name,
|
|
90
|
+
job_title,
|
|
91
|
+
email,
|
|
92
|
+
avatar_url,
|
|
93
|
+
theme,
|
|
94
|
+
created_at,
|
|
95
|
+
updated_at`;
|
|
96
|
+
async function upsertUserProfile(client, args) {
|
|
97
|
+
const result = await client.query({
|
|
98
|
+
text: exports.upsertUserProfileQuery,
|
|
99
|
+
values: [args.userId, args.displayName, args.jobTitle, args.email, args.avatarUrl, args.theme],
|
|
100
|
+
rowMode: "array"
|
|
101
|
+
});
|
|
102
|
+
if (result.rows.length !== 1) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const row = result.rows[0];
|
|
106
|
+
return {
|
|
107
|
+
userId: row[0],
|
|
108
|
+
displayName: row[1],
|
|
109
|
+
jobTitle: row[2],
|
|
110
|
+
email: row[3],
|
|
111
|
+
avatarUrl: row[4],
|
|
112
|
+
theme: row[5],
|
|
113
|
+
createdAt: row[6],
|
|
114
|
+
updatedAt: row[7]
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
exports.getUserProfileQuery = `-- name: GetUserProfile :one
|
|
118
|
+
SELECT
|
|
119
|
+
user_id,
|
|
120
|
+
display_name,
|
|
121
|
+
job_title,
|
|
122
|
+
email,
|
|
123
|
+
avatar_url,
|
|
124
|
+
theme,
|
|
125
|
+
created_at,
|
|
126
|
+
updated_at
|
|
127
|
+
FROM weave.user_profiles
|
|
128
|
+
WHERE user_id = $1`;
|
|
129
|
+
async function getUserProfile(client, args) {
|
|
130
|
+
const result = await client.query({
|
|
131
|
+
text: exports.getUserProfileQuery,
|
|
132
|
+
values: [args.userId],
|
|
133
|
+
rowMode: "array"
|
|
134
|
+
});
|
|
135
|
+
if (result.rows.length !== 1) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const row = result.rows[0];
|
|
139
|
+
return {
|
|
140
|
+
userId: row[0],
|
|
141
|
+
displayName: row[1],
|
|
142
|
+
jobTitle: row[2],
|
|
143
|
+
email: row[3],
|
|
144
|
+
avatarUrl: row[4],
|
|
145
|
+
theme: row[5],
|
|
146
|
+
createdAt: row[6],
|
|
147
|
+
updatedAt: row[7]
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
exports.getIdentityLinkByStytchMemberQuery = `-- name: GetIdentityLinkByStytchMember :one
|
|
151
|
+
SELECT
|
|
152
|
+
id,
|
|
153
|
+
user_id,
|
|
154
|
+
organization_id,
|
|
155
|
+
provider,
|
|
156
|
+
stytch_organization_id,
|
|
157
|
+
stytch_member_id,
|
|
158
|
+
stytch_member_email,
|
|
159
|
+
last_seen_at,
|
|
160
|
+
created_at,
|
|
161
|
+
updated_at
|
|
162
|
+
FROM weave.identity_links
|
|
163
|
+
WHERE provider = 'stytch_b2b'
|
|
164
|
+
AND stytch_organization_id = $1
|
|
165
|
+
AND stytch_member_id = $2`;
|
|
166
|
+
async function getIdentityLinkByStytchMember(client, args) {
|
|
167
|
+
const result = await client.query({
|
|
168
|
+
text: exports.getIdentityLinkByStytchMemberQuery,
|
|
169
|
+
values: [args.stytchOrganizationId, args.stytchMemberId],
|
|
170
|
+
rowMode: "array"
|
|
171
|
+
});
|
|
172
|
+
if (result.rows.length !== 1) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const row = result.rows[0];
|
|
176
|
+
return {
|
|
177
|
+
id: row[0],
|
|
178
|
+
userId: row[1],
|
|
179
|
+
organizationId: row[2],
|
|
180
|
+
provider: row[3],
|
|
181
|
+
stytchOrganizationId: row[4],
|
|
182
|
+
stytchMemberId: row[5],
|
|
183
|
+
stytchMemberEmail: row[6],
|
|
184
|
+
lastSeenAt: row[7],
|
|
185
|
+
createdAt: row[8],
|
|
186
|
+
updatedAt: row[9]
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
exports.upsertIdentityLinkQuery = `-- name: UpsertIdentityLink :one
|
|
190
|
+
INSERT INTO weave.identity_links (
|
|
191
|
+
user_id,
|
|
192
|
+
organization_id,
|
|
193
|
+
provider,
|
|
194
|
+
stytch_organization_id,
|
|
195
|
+
stytch_member_id,
|
|
196
|
+
stytch_member_email,
|
|
197
|
+
last_seen_at
|
|
198
|
+
) VALUES (
|
|
199
|
+
$1,
|
|
200
|
+
$2,
|
|
201
|
+
'stytch_b2b',
|
|
202
|
+
$3,
|
|
203
|
+
$4,
|
|
204
|
+
$5,
|
|
205
|
+
now()
|
|
206
|
+
)
|
|
207
|
+
ON CONFLICT (provider, stytch_organization_id, stytch_member_id) DO UPDATE
|
|
208
|
+
SET
|
|
209
|
+
user_id = EXCLUDED.user_id,
|
|
210
|
+
organization_id = EXCLUDED.organization_id,
|
|
211
|
+
stytch_member_email = EXCLUDED.stytch_member_email,
|
|
212
|
+
last_seen_at = now(),
|
|
213
|
+
updated_at = now()
|
|
214
|
+
RETURNING
|
|
215
|
+
id,
|
|
216
|
+
user_id,
|
|
217
|
+
organization_id,
|
|
218
|
+
provider,
|
|
219
|
+
stytch_organization_id,
|
|
220
|
+
stytch_member_id,
|
|
221
|
+
stytch_member_email,
|
|
222
|
+
last_seen_at,
|
|
223
|
+
created_at,
|
|
224
|
+
updated_at`;
|
|
225
|
+
async function upsertIdentityLink(client, args) {
|
|
226
|
+
const result = await client.query({
|
|
227
|
+
text: exports.upsertIdentityLinkQuery,
|
|
228
|
+
values: [args.userId, args.organizationId, args.stytchOrganizationId, args.stytchMemberId, args.stytchMemberEmail],
|
|
229
|
+
rowMode: "array"
|
|
230
|
+
});
|
|
231
|
+
if (result.rows.length !== 1) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
const row = result.rows[0];
|
|
235
|
+
return {
|
|
236
|
+
id: row[0],
|
|
237
|
+
userId: row[1],
|
|
238
|
+
organizationId: row[2],
|
|
239
|
+
provider: row[3],
|
|
240
|
+
stytchOrganizationId: row[4],
|
|
241
|
+
stytchMemberId: row[5],
|
|
242
|
+
stytchMemberEmail: row[6],
|
|
243
|
+
lastSeenAt: row[7],
|
|
244
|
+
createdAt: row[8],
|
|
245
|
+
updatedAt: row[9]
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
exports.getOrganizationAuthLinkByStytchIDQuery = `-- name: GetOrganizationAuthLinkByStytchID :one
|
|
249
|
+
SELECT
|
|
250
|
+
organization_id,
|
|
251
|
+
stytch_organization_id,
|
|
252
|
+
stytch_organization_slug,
|
|
253
|
+
stytch_organization_kind,
|
|
254
|
+
allowed_domains,
|
|
255
|
+
auth_policy_summary,
|
|
256
|
+
created_at,
|
|
257
|
+
updated_at
|
|
258
|
+
FROM weave.organization_auth_links
|
|
259
|
+
WHERE stytch_organization_id = $1`;
|
|
260
|
+
async function getOrganizationAuthLinkByStytchID(client, args) {
|
|
261
|
+
const result = await client.query({
|
|
262
|
+
text: exports.getOrganizationAuthLinkByStytchIDQuery,
|
|
263
|
+
values: [args.stytchOrganizationId],
|
|
264
|
+
rowMode: "array"
|
|
265
|
+
});
|
|
266
|
+
if (result.rows.length !== 1) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
const row = result.rows[0];
|
|
270
|
+
return {
|
|
271
|
+
organizationId: row[0],
|
|
272
|
+
stytchOrganizationId: row[1],
|
|
273
|
+
stytchOrganizationSlug: row[2],
|
|
274
|
+
stytchOrganizationKind: row[3],
|
|
275
|
+
allowedDomains: row[4],
|
|
276
|
+
authPolicySummary: row[5],
|
|
277
|
+
createdAt: row[6],
|
|
278
|
+
updatedAt: row[7]
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
exports.getOrganizationAuthLinkByOrganizationIDQuery = `-- name: GetOrganizationAuthLinkByOrganizationID :one
|
|
282
|
+
SELECT
|
|
283
|
+
organization_id,
|
|
284
|
+
stytch_organization_id,
|
|
285
|
+
stytch_organization_slug,
|
|
286
|
+
stytch_organization_kind,
|
|
287
|
+
allowed_domains,
|
|
288
|
+
auth_policy_summary,
|
|
289
|
+
created_at,
|
|
290
|
+
updated_at
|
|
291
|
+
FROM weave.organization_auth_links
|
|
292
|
+
WHERE organization_id = $1`;
|
|
293
|
+
async function getOrganizationAuthLinkByOrganizationID(client, args) {
|
|
294
|
+
const result = await client.query({
|
|
295
|
+
text: exports.getOrganizationAuthLinkByOrganizationIDQuery,
|
|
296
|
+
values: [args.organizationId],
|
|
297
|
+
rowMode: "array"
|
|
298
|
+
});
|
|
299
|
+
if (result.rows.length !== 1) {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
const row = result.rows[0];
|
|
303
|
+
return {
|
|
304
|
+
organizationId: row[0],
|
|
305
|
+
stytchOrganizationId: row[1],
|
|
306
|
+
stytchOrganizationSlug: row[2],
|
|
307
|
+
stytchOrganizationKind: row[3],
|
|
308
|
+
allowedDomains: row[4],
|
|
309
|
+
authPolicySummary: row[5],
|
|
310
|
+
createdAt: row[6],
|
|
311
|
+
updatedAt: row[7]
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
exports.upsertOrganizationAuthLinkQuery = `-- name: UpsertOrganizationAuthLink :one
|
|
315
|
+
INSERT INTO weave.organization_auth_links (
|
|
316
|
+
organization_id,
|
|
317
|
+
stytch_organization_id,
|
|
318
|
+
stytch_organization_slug,
|
|
319
|
+
stytch_organization_kind,
|
|
320
|
+
allowed_domains,
|
|
321
|
+
auth_policy_summary
|
|
322
|
+
) VALUES (
|
|
323
|
+
$1,
|
|
324
|
+
$2,
|
|
325
|
+
$3,
|
|
326
|
+
$4,
|
|
327
|
+
$5,
|
|
328
|
+
$6
|
|
329
|
+
)
|
|
330
|
+
ON CONFLICT (organization_id) DO UPDATE
|
|
331
|
+
SET
|
|
332
|
+
stytch_organization_id = EXCLUDED.stytch_organization_id,
|
|
333
|
+
stytch_organization_slug = EXCLUDED.stytch_organization_slug,
|
|
334
|
+
stytch_organization_kind = EXCLUDED.stytch_organization_kind,
|
|
335
|
+
allowed_domains = EXCLUDED.allowed_domains,
|
|
336
|
+
auth_policy_summary = EXCLUDED.auth_policy_summary,
|
|
337
|
+
updated_at = now()
|
|
338
|
+
RETURNING
|
|
339
|
+
organization_id,
|
|
340
|
+
stytch_organization_id,
|
|
341
|
+
stytch_organization_slug,
|
|
342
|
+
stytch_organization_kind,
|
|
343
|
+
allowed_domains,
|
|
344
|
+
auth_policy_summary,
|
|
345
|
+
created_at,
|
|
346
|
+
updated_at`;
|
|
347
|
+
async function upsertOrganizationAuthLink(client, args) {
|
|
348
|
+
const result = await client.query({
|
|
349
|
+
text: exports.upsertOrganizationAuthLinkQuery,
|
|
350
|
+
values: [args.organizationId, args.stytchOrganizationId, args.stytchOrganizationSlug, args.stytchOrganizationKind, args.allowedDomains, args.authPolicySummary],
|
|
351
|
+
rowMode: "array"
|
|
352
|
+
});
|
|
353
|
+
if (result.rows.length !== 1) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
const row = result.rows[0];
|
|
357
|
+
return {
|
|
358
|
+
organizationId: row[0],
|
|
359
|
+
stytchOrganizationId: row[1],
|
|
360
|
+
stytchOrganizationSlug: row[2],
|
|
361
|
+
stytchOrganizationKind: row[3],
|
|
362
|
+
allowedDomains: row[4],
|
|
363
|
+
authPolicySummary: row[5],
|
|
364
|
+
createdAt: row[6],
|
|
365
|
+
updatedAt: row[7]
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
exports.upsertOrganizationMembershipQuery = `-- name: UpsertOrganizationMembership :one
|
|
369
|
+
INSERT INTO weave.organization_memberships (
|
|
370
|
+
user_id,
|
|
371
|
+
organization_id,
|
|
372
|
+
identity_link_id,
|
|
373
|
+
status,
|
|
374
|
+
role_ids
|
|
375
|
+
) VALUES (
|
|
376
|
+
$1,
|
|
377
|
+
$2,
|
|
378
|
+
$3,
|
|
379
|
+
$4,
|
|
380
|
+
$5
|
|
381
|
+
)
|
|
382
|
+
ON CONFLICT (user_id, organization_id) DO UPDATE
|
|
383
|
+
SET
|
|
384
|
+
identity_link_id = EXCLUDED.identity_link_id,
|
|
385
|
+
status = EXCLUDED.status,
|
|
386
|
+
role_ids = EXCLUDED.role_ids,
|
|
387
|
+
updated_at = now()
|
|
388
|
+
RETURNING
|
|
389
|
+
id,
|
|
390
|
+
user_id,
|
|
391
|
+
organization_id,
|
|
392
|
+
identity_link_id,
|
|
393
|
+
status,
|
|
394
|
+
role_ids,
|
|
395
|
+
created_at,
|
|
396
|
+
updated_at`;
|
|
397
|
+
async function upsertOrganizationMembership(client, args) {
|
|
398
|
+
const result = await client.query({
|
|
399
|
+
text: exports.upsertOrganizationMembershipQuery,
|
|
400
|
+
values: [args.userId, args.organizationId, args.identityLinkId, args.status, args.roleIds],
|
|
401
|
+
rowMode: "array"
|
|
402
|
+
});
|
|
403
|
+
if (result.rows.length !== 1) {
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
const row = result.rows[0];
|
|
407
|
+
return {
|
|
408
|
+
id: row[0],
|
|
409
|
+
userId: row[1],
|
|
410
|
+
organizationId: row[2],
|
|
411
|
+
identityLinkId: row[3],
|
|
412
|
+
status: row[4],
|
|
413
|
+
roleIds: row[5],
|
|
414
|
+
createdAt: row[6],
|
|
415
|
+
updatedAt: row[7]
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
exports.getOrganizationMembershipQuery = `-- name: GetOrganizationMembership :one
|
|
419
|
+
SELECT
|
|
420
|
+
id,
|
|
421
|
+
user_id,
|
|
422
|
+
organization_id,
|
|
423
|
+
identity_link_id,
|
|
424
|
+
status,
|
|
425
|
+
role_ids,
|
|
426
|
+
created_at,
|
|
427
|
+
updated_at
|
|
428
|
+
FROM weave.organization_memberships
|
|
429
|
+
WHERE user_id = $1
|
|
430
|
+
AND organization_id = $2`;
|
|
431
|
+
async function getOrganizationMembership(client, args) {
|
|
432
|
+
const result = await client.query({
|
|
433
|
+
text: exports.getOrganizationMembershipQuery,
|
|
434
|
+
values: [args.userId, args.organizationId],
|
|
435
|
+
rowMode: "array"
|
|
436
|
+
});
|
|
437
|
+
if (result.rows.length !== 1) {
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
const row = result.rows[0];
|
|
441
|
+
return {
|
|
442
|
+
id: row[0],
|
|
443
|
+
userId: row[1],
|
|
444
|
+
organizationId: row[2],
|
|
445
|
+
identityLinkId: row[3],
|
|
446
|
+
status: row[4],
|
|
447
|
+
roleIds: row[5],
|
|
448
|
+
createdAt: row[6],
|
|
449
|
+
updatedAt: row[7]
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
exports.listOrganizationMembershipsForUserQuery = `-- name: ListOrganizationMembershipsForUser :many
|
|
453
|
+
SELECT
|
|
454
|
+
id,
|
|
455
|
+
user_id,
|
|
456
|
+
organization_id,
|
|
457
|
+
identity_link_id,
|
|
458
|
+
status,
|
|
459
|
+
role_ids,
|
|
460
|
+
created_at,
|
|
461
|
+
updated_at
|
|
462
|
+
FROM weave.organization_memberships
|
|
463
|
+
WHERE user_id = $1
|
|
464
|
+
ORDER BY created_at ASC`;
|
|
465
|
+
async function listOrganizationMembershipsForUser(client, args) {
|
|
466
|
+
const result = await client.query({
|
|
467
|
+
text: exports.listOrganizationMembershipsForUserQuery,
|
|
468
|
+
values: [args.userId],
|
|
469
|
+
rowMode: "array"
|
|
470
|
+
});
|
|
471
|
+
return result.rows.map(row => {
|
|
472
|
+
return {
|
|
473
|
+
id: row[0],
|
|
474
|
+
userId: row[1],
|
|
475
|
+
organizationId: row[2],
|
|
476
|
+
identityLinkId: row[3],
|
|
477
|
+
status: row[4],
|
|
478
|
+
roleIds: row[5],
|
|
479
|
+
createdAt: row[6],
|
|
480
|
+
updatedAt: row[7]
|
|
481
|
+
};
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
exports.listOrganizationMembersQuery = `-- name: ListOrganizationMembers :many
|
|
485
|
+
SELECT
|
|
486
|
+
m.id,
|
|
487
|
+
m.user_id,
|
|
488
|
+
m.organization_id,
|
|
489
|
+
m.identity_link_id,
|
|
490
|
+
m.status,
|
|
491
|
+
m.role_ids,
|
|
492
|
+
p.display_name,
|
|
493
|
+
p.email,
|
|
494
|
+
p.avatar_url,
|
|
495
|
+
m.created_at,
|
|
496
|
+
m.updated_at
|
|
497
|
+
FROM weave.organization_memberships AS m
|
|
498
|
+
JOIN weave.user_profiles AS p
|
|
499
|
+
ON p.user_id = m.user_id
|
|
500
|
+
WHERE m.organization_id = $1
|
|
501
|
+
ORDER BY p.display_name ASC, p.email ASC`;
|
|
502
|
+
async function listOrganizationMembers(client, args) {
|
|
503
|
+
const result = await client.query({
|
|
504
|
+
text: exports.listOrganizationMembersQuery,
|
|
505
|
+
values: [args.organizationId],
|
|
506
|
+
rowMode: "array"
|
|
507
|
+
});
|
|
508
|
+
return result.rows.map(row => {
|
|
509
|
+
return {
|
|
510
|
+
id: row[0],
|
|
511
|
+
userId: row[1],
|
|
512
|
+
organizationId: row[2],
|
|
513
|
+
identityLinkId: row[3],
|
|
514
|
+
status: row[4],
|
|
515
|
+
roleIds: row[5],
|
|
516
|
+
displayName: row[6],
|
|
517
|
+
email: row[7],
|
|
518
|
+
avatarUrl: row[8],
|
|
519
|
+
createdAt: row[9],
|
|
520
|
+
updatedAt: row[10]
|
|
521
|
+
};
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
exports.listActivePlatformAdminGrantsForUserQuery = `-- name: ListActivePlatformAdminGrantsForUser :many
|
|
525
|
+
SELECT
|
|
526
|
+
id,
|
|
527
|
+
user_id,
|
|
528
|
+
platform_role,
|
|
529
|
+
organization_id,
|
|
530
|
+
all_organizations,
|
|
531
|
+
allowed_actions,
|
|
532
|
+
expires_at,
|
|
533
|
+
status,
|
|
534
|
+
created_at,
|
|
535
|
+
updated_at
|
|
536
|
+
FROM weave.platform_admin_grants
|
|
537
|
+
WHERE user_id = $1
|
|
538
|
+
AND status = 'active'
|
|
539
|
+
AND (expires_at IS NULL OR expires_at > now())`;
|
|
540
|
+
async function listActivePlatformAdminGrantsForUser(client, args) {
|
|
541
|
+
const result = await client.query({
|
|
542
|
+
text: exports.listActivePlatformAdminGrantsForUserQuery,
|
|
543
|
+
values: [args.userId],
|
|
544
|
+
rowMode: "array"
|
|
545
|
+
});
|
|
546
|
+
return result.rows.map(row => {
|
|
547
|
+
return {
|
|
548
|
+
id: row[0],
|
|
549
|
+
userId: row[1],
|
|
550
|
+
platformRole: row[2],
|
|
551
|
+
organizationId: row[3],
|
|
552
|
+
allOrganizations: row[4],
|
|
553
|
+
allowedActions: row[5],
|
|
554
|
+
expiresAt: row[6],
|
|
555
|
+
status: row[7],
|
|
556
|
+
createdAt: row[8],
|
|
557
|
+
updatedAt: row[9]
|
|
558
|
+
};
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
exports.createPlatformAdminGrantQuery = `-- name: CreatePlatformAdminGrant :one
|
|
562
|
+
INSERT INTO weave.platform_admin_grants (
|
|
563
|
+
user_id,
|
|
564
|
+
platform_role,
|
|
565
|
+
organization_id,
|
|
566
|
+
all_organizations,
|
|
567
|
+
allowed_actions,
|
|
568
|
+
expires_at,
|
|
569
|
+
status
|
|
570
|
+
) VALUES (
|
|
571
|
+
$1,
|
|
572
|
+
$2,
|
|
573
|
+
$3,
|
|
574
|
+
$4,
|
|
575
|
+
$5,
|
|
576
|
+
$6,
|
|
577
|
+
$7
|
|
578
|
+
)
|
|
579
|
+
RETURNING
|
|
580
|
+
id,
|
|
581
|
+
user_id,
|
|
582
|
+
platform_role,
|
|
583
|
+
organization_id,
|
|
584
|
+
all_organizations,
|
|
585
|
+
allowed_actions,
|
|
586
|
+
expires_at,
|
|
587
|
+
status,
|
|
588
|
+
created_at,
|
|
589
|
+
updated_at`;
|
|
590
|
+
async function createPlatformAdminGrant(client, args) {
|
|
591
|
+
const result = await client.query({
|
|
592
|
+
text: exports.createPlatformAdminGrantQuery,
|
|
593
|
+
values: [args.userId, args.platformRole, args.organizationId, args.allOrganizations, args.allowedActions, args.expiresAt, args.status],
|
|
594
|
+
rowMode: "array"
|
|
595
|
+
});
|
|
596
|
+
if (result.rows.length !== 1) {
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
const row = result.rows[0];
|
|
600
|
+
return {
|
|
601
|
+
id: row[0],
|
|
602
|
+
userId: row[1],
|
|
603
|
+
platformRole: row[2],
|
|
604
|
+
organizationId: row[3],
|
|
605
|
+
allOrganizations: row[4],
|
|
606
|
+
allowedActions: row[5],
|
|
607
|
+
expiresAt: row[6],
|
|
608
|
+
status: row[7],
|
|
609
|
+
createdAt: row[8],
|
|
610
|
+
updatedAt: row[9]
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
exports.createSupportAccessSessionQuery = `-- name: CreateSupportAccessSession :one
|
|
614
|
+
INSERT INTO weave.support_access_sessions (
|
|
615
|
+
acting_user_id,
|
|
616
|
+
target_organization_id,
|
|
617
|
+
reason,
|
|
618
|
+
allowed_actions
|
|
619
|
+
) VALUES (
|
|
620
|
+
$1,
|
|
621
|
+
$2,
|
|
622
|
+
$3,
|
|
623
|
+
$4
|
|
624
|
+
)
|
|
625
|
+
RETURNING
|
|
626
|
+
id,
|
|
627
|
+
acting_user_id,
|
|
628
|
+
target_organization_id,
|
|
629
|
+
reason,
|
|
630
|
+
allowed_actions,
|
|
631
|
+
started_at,
|
|
632
|
+
ended_at,
|
|
633
|
+
created_at`;
|
|
634
|
+
async function createSupportAccessSession(client, args) {
|
|
635
|
+
const result = await client.query({
|
|
636
|
+
text: exports.createSupportAccessSessionQuery,
|
|
637
|
+
values: [args.actingUserId, args.targetOrganizationId, args.reason, args.allowedActions],
|
|
638
|
+
rowMode: "array"
|
|
639
|
+
});
|
|
640
|
+
if (result.rows.length !== 1) {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
const row = result.rows[0];
|
|
644
|
+
return {
|
|
645
|
+
id: row[0],
|
|
646
|
+
actingUserId: row[1],
|
|
647
|
+
targetOrganizationId: row[2],
|
|
648
|
+
reason: row[3],
|
|
649
|
+
allowedActions: row[4],
|
|
650
|
+
startedAt: row[5],
|
|
651
|
+
endedAt: row[6],
|
|
652
|
+
createdAt: row[7]
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
exports.endSupportAccessSessionQuery = `-- name: EndSupportAccessSession :execrows
|
|
656
|
+
UPDATE weave.support_access_sessions
|
|
657
|
+
SET ended_at = now()
|
|
658
|
+
WHERE id = $1
|
|
659
|
+
AND ended_at IS NULL`;
|
|
660
|
+
exports.insertAuthAuditEventQuery = `-- name: InsertAuthAuditEvent :exec
|
|
661
|
+
INSERT INTO weave.auth_audit_events (
|
|
662
|
+
organization_id,
|
|
663
|
+
acting_user_id,
|
|
664
|
+
target_user_id,
|
|
665
|
+
event_type,
|
|
666
|
+
auth_method,
|
|
667
|
+
stytch_request_id,
|
|
668
|
+
stytch_organization_id,
|
|
669
|
+
stytch_member_id,
|
|
670
|
+
support_access_session_id,
|
|
671
|
+
metadata
|
|
672
|
+
) VALUES (
|
|
673
|
+
$1,
|
|
674
|
+
$2,
|
|
675
|
+
$3,
|
|
676
|
+
$4,
|
|
677
|
+
$5,
|
|
678
|
+
$6,
|
|
679
|
+
$7,
|
|
680
|
+
$8,
|
|
681
|
+
$9,
|
|
682
|
+
$10
|
|
683
|
+
)`;
|
|
684
|
+
async function insertAuthAuditEvent(client, args) {
|
|
685
|
+
await client.query({
|
|
686
|
+
text: exports.insertAuthAuditEventQuery,
|
|
687
|
+
values: [args.organizationId, args.actingUserId, args.targetUserId, args.eventType, args.authMethod, args.stytchRequestId, args.stytchOrganizationId, args.stytchMemberId, args.supportAccessSessionId, args.metadata],
|
|
688
|
+
rowMode: "array"
|
|
689
|
+
});
|
|
690
|
+
}
|