weave-typescript 0.35.0 → 0.37.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 +54 -0
- package/dist/weaveapi/auth/v1/auth.pb.js +963 -97
- package/dist/weaveapi/auth/v1/service.pb.d.ts +173 -1
- package/dist/weaveapi/auth/v1/service.pb.js +3029 -1493
- package/dist/weavesql/weavedb/auth_identity_sql.d.ts +207 -0
- package/dist/weavesql/weavedb/auth_identity_sql.js +448 -1
- package/package.json +1 -1
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.getUserPrimaryOrganizationAuthLinkQuery = exports.setUserPrimaryOrganizationQuery = exports.getUserByIDQuery = exports.createUserQuery = void 0;
|
|
3
|
+
exports.deleteOrgTeamMembershipsQuery = exports.deleteOrgTeamQuery = exports.updateOrgTeamQuery = exports.listOrgTeamsQuery = exports.getOrgTeamQuery = exports.createOrgTeamQuery = 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
|
+
exports.deleteOrgTeamMembershipsForOrganizationMemberQuery = exports.listEffectiveOrganizationRoleIDsQuery = exports.listOrgTeamRoleGrantsQuery = exports.listOrgTeamMembersQuery = exports.addOrgTeamRoleGrantQuery = exports.deleteOrgTeamRoleGrantsQuery = exports.addOrgTeamMembershipQuery = void 0;
|
|
4
5
|
exports.createUser = createUser;
|
|
5
6
|
exports.getUserByID = getUserByID;
|
|
6
7
|
exports.setUserPrimaryOrganization = setUserPrimaryOrganization;
|
|
7
8
|
exports.getUserPrimaryOrganizationAuthLink = getUserPrimaryOrganizationAuthLink;
|
|
9
|
+
exports.getUserAuthPreferences = getUserAuthPreferences;
|
|
10
|
+
exports.setUserLastOrganization = setUserLastOrganization;
|
|
11
|
+
exports.setUserOrganizationPagePosition = setUserOrganizationPagePosition;
|
|
12
|
+
exports.updateUserProfileTheme = updateUserProfileTheme;
|
|
8
13
|
exports.resolvePrimaryOrganizationAuthLinkByDomain = resolvePrimaryOrganizationAuthLinkByDomain;
|
|
9
14
|
exports.upsertOrganizationAuthDomain = upsertOrganizationAuthDomain;
|
|
10
15
|
exports.listOrganizationAuthDomains = listOrganizationAuthDomains;
|
|
@@ -35,6 +40,15 @@ exports.getAuthInviteSession = getAuthInviteSession;
|
|
|
35
40
|
exports.setAuthInviteSessionOAuthState = setAuthInviteSessionOAuthState;
|
|
36
41
|
exports.markAuthInviteSessionCompleted = markAuthInviteSessionCompleted;
|
|
37
42
|
exports.markAuthInviteSessionRecoveryRequired = markAuthInviteSessionRecoveryRequired;
|
|
43
|
+
exports.createOrgTeam = createOrgTeam;
|
|
44
|
+
exports.getOrgTeam = getOrgTeam;
|
|
45
|
+
exports.listOrgTeams = listOrgTeams;
|
|
46
|
+
exports.updateOrgTeam = updateOrgTeam;
|
|
47
|
+
exports.addOrgTeamMembership = addOrgTeamMembership;
|
|
48
|
+
exports.addOrgTeamRoleGrant = addOrgTeamRoleGrant;
|
|
49
|
+
exports.listOrgTeamMembers = listOrgTeamMembers;
|
|
50
|
+
exports.listOrgTeamRoleGrants = listOrgTeamRoleGrants;
|
|
51
|
+
exports.listEffectiveOrganizationRoleIDs = listEffectiveOrganizationRoleIDs;
|
|
38
52
|
exports.createUserQuery = `-- name: CreateUser :one
|
|
39
53
|
INSERT INTO weave.users (status)
|
|
40
54
|
VALUES ($1)
|
|
@@ -149,6 +163,155 @@ async function getUserPrimaryOrganizationAuthLink(client, args) {
|
|
|
149
163
|
updatedAt: row[9]
|
|
150
164
|
};
|
|
151
165
|
}
|
|
166
|
+
exports.getUserAuthPreferencesQuery = `-- name: GetUserAuthPreferences :one
|
|
167
|
+
SELECT
|
|
168
|
+
u.id AS user_id,
|
|
169
|
+
u.primary_organization_id AS default_organization_id,
|
|
170
|
+
default_org.slug AS default_organization_slug,
|
|
171
|
+
u.last_organization_id,
|
|
172
|
+
last_org.slug AS last_organization_slug,
|
|
173
|
+
u.organization_page_positions,
|
|
174
|
+
COALESCE(p.theme, 'system') AS theme,
|
|
175
|
+
u.updated_at
|
|
176
|
+
FROM weave.users AS u
|
|
177
|
+
LEFT JOIN weave.organizations AS default_org
|
|
178
|
+
ON default_org.id = u.primary_organization_id
|
|
179
|
+
LEFT JOIN weave.organizations AS last_org
|
|
180
|
+
ON last_org.id = u.last_organization_id
|
|
181
|
+
LEFT JOIN weave.user_profiles AS p
|
|
182
|
+
ON p.user_id = u.id
|
|
183
|
+
WHERE u.id = $1
|
|
184
|
+
AND u.status = 'active'`;
|
|
185
|
+
async function getUserAuthPreferences(client, args) {
|
|
186
|
+
const result = await client.query({
|
|
187
|
+
text: exports.getUserAuthPreferencesQuery,
|
|
188
|
+
values: [args.userId],
|
|
189
|
+
rowMode: "array"
|
|
190
|
+
});
|
|
191
|
+
if (result.rows.length !== 1) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const row = result.rows[0];
|
|
195
|
+
return {
|
|
196
|
+
userId: row[0],
|
|
197
|
+
defaultOrganizationId: row[1],
|
|
198
|
+
defaultOrganizationSlug: row[2],
|
|
199
|
+
lastOrganizationId: row[3],
|
|
200
|
+
lastOrganizationSlug: row[4],
|
|
201
|
+
organizationPagePositions: row[5],
|
|
202
|
+
theme: row[6],
|
|
203
|
+
updatedAt: row[7]
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
exports.setUserLastOrganizationQuery = `-- name: SetUserLastOrganization :one
|
|
207
|
+
UPDATE weave.users AS u
|
|
208
|
+
SET
|
|
209
|
+
last_organization_id = o.id,
|
|
210
|
+
updated_at = now()
|
|
211
|
+
FROM weave.organizations AS o
|
|
212
|
+
JOIN weave.organization_memberships AS m
|
|
213
|
+
ON m.organization_id = o.id
|
|
214
|
+
AND m.user_id = $1
|
|
215
|
+
AND m.status = 'active'
|
|
216
|
+
WHERE u.id = $1
|
|
217
|
+
AND u.status = 'active'
|
|
218
|
+
AND o.slug = $2
|
|
219
|
+
RETURNING
|
|
220
|
+
u.id AS user_id,
|
|
221
|
+
o.id AS last_organization_id,
|
|
222
|
+
o.slug AS last_organization_slug,
|
|
223
|
+
u.updated_at`;
|
|
224
|
+
async function setUserLastOrganization(client, args) {
|
|
225
|
+
const result = await client.query({
|
|
226
|
+
text: exports.setUserLastOrganizationQuery,
|
|
227
|
+
values: [args.userId, args.organizationSlug],
|
|
228
|
+
rowMode: "array"
|
|
229
|
+
});
|
|
230
|
+
if (result.rows.length !== 1) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
const row = result.rows[0];
|
|
234
|
+
return {
|
|
235
|
+
userId: row[0],
|
|
236
|
+
lastOrganizationId: row[1],
|
|
237
|
+
lastOrganizationSlug: row[2],
|
|
238
|
+
updatedAt: row[3]
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
exports.setUserOrganizationPagePositionQuery = `-- name: SetUserOrganizationPagePosition :one
|
|
242
|
+
UPDATE weave.users AS u
|
|
243
|
+
SET
|
|
244
|
+
organization_page_positions =
|
|
245
|
+
u.organization_page_positions || jsonb_build_object(o.slug, $1::text),
|
|
246
|
+
updated_at = now()
|
|
247
|
+
FROM weave.organizations AS o
|
|
248
|
+
JOIN weave.organization_memberships AS m
|
|
249
|
+
ON m.organization_id = o.id
|
|
250
|
+
AND m.user_id = $2
|
|
251
|
+
AND m.status = 'active'
|
|
252
|
+
WHERE u.id = $2
|
|
253
|
+
AND u.status = 'active'
|
|
254
|
+
AND o.slug = $3
|
|
255
|
+
RETURNING
|
|
256
|
+
u.id AS user_id,
|
|
257
|
+
o.id AS organization_id,
|
|
258
|
+
o.slug AS organization_slug,
|
|
259
|
+
u.organization_page_positions,
|
|
260
|
+
u.updated_at`;
|
|
261
|
+
async function setUserOrganizationPagePosition(client, args) {
|
|
262
|
+
const result = await client.query({
|
|
263
|
+
text: exports.setUserOrganizationPagePositionQuery,
|
|
264
|
+
values: [args.href, args.userId, args.organizationSlug],
|
|
265
|
+
rowMode: "array"
|
|
266
|
+
});
|
|
267
|
+
if (result.rows.length !== 1) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
const row = result.rows[0];
|
|
271
|
+
return {
|
|
272
|
+
userId: row[0],
|
|
273
|
+
organizationId: row[1],
|
|
274
|
+
organizationSlug: row[2],
|
|
275
|
+
organizationPagePositions: row[3],
|
|
276
|
+
updatedAt: row[4]
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
exports.updateUserProfileThemeQuery = `-- name: UpdateUserProfileTheme :one
|
|
280
|
+
UPDATE weave.user_profiles
|
|
281
|
+
SET
|
|
282
|
+
theme = $1,
|
|
283
|
+
updated_at = now()
|
|
284
|
+
WHERE user_id = $2
|
|
285
|
+
RETURNING
|
|
286
|
+
user_id,
|
|
287
|
+
display_name,
|
|
288
|
+
job_title,
|
|
289
|
+
email,
|
|
290
|
+
avatar_url,
|
|
291
|
+
theme,
|
|
292
|
+
created_at,
|
|
293
|
+
updated_at`;
|
|
294
|
+
async function updateUserProfileTheme(client, args) {
|
|
295
|
+
const result = await client.query({
|
|
296
|
+
text: exports.updateUserProfileThemeQuery,
|
|
297
|
+
values: [args.theme, args.userId],
|
|
298
|
+
rowMode: "array"
|
|
299
|
+
});
|
|
300
|
+
if (result.rows.length !== 1) {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
const row = result.rows[0];
|
|
304
|
+
return {
|
|
305
|
+
userId: row[0],
|
|
306
|
+
displayName: row[1],
|
|
307
|
+
jobTitle: row[2],
|
|
308
|
+
email: row[3],
|
|
309
|
+
avatarUrl: row[4],
|
|
310
|
+
theme: row[5],
|
|
311
|
+
createdAt: row[6],
|
|
312
|
+
updatedAt: row[7]
|
|
313
|
+
};
|
|
314
|
+
}
|
|
152
315
|
exports.resolvePrimaryOrganizationAuthLinkByDomainQuery = `-- name: ResolvePrimaryOrganizationAuthLinkByDomain :one
|
|
153
316
|
SELECT
|
|
154
317
|
o.id AS organization_id,
|
|
@@ -1601,3 +1764,287 @@ exports.deleteExpiredAuthInviteSessionsQuery = `-- name: DeleteExpiredAuthInvite
|
|
|
1601
1764
|
DELETE FROM weave.auth_invite_sessions
|
|
1602
1765
|
WHERE expires_at <= now()
|
|
1603
1766
|
OR status IN ('completed', 'expired', 'revoked')`;
|
|
1767
|
+
exports.createOrgTeamQuery = `-- name: CreateOrgTeam :one
|
|
1768
|
+
INSERT INTO weave.org_teams (
|
|
1769
|
+
organization_id,
|
|
1770
|
+
slug,
|
|
1771
|
+
name,
|
|
1772
|
+
description
|
|
1773
|
+
) VALUES (
|
|
1774
|
+
$1,
|
|
1775
|
+
$2,
|
|
1776
|
+
$3,
|
|
1777
|
+
$4
|
|
1778
|
+
)
|
|
1779
|
+
RETURNING id, organization_id, slug, name, description, created_at, updated_at`;
|
|
1780
|
+
async function createOrgTeam(client, args) {
|
|
1781
|
+
const result = await client.query({
|
|
1782
|
+
text: exports.createOrgTeamQuery,
|
|
1783
|
+
values: [args.organizationId, args.slug, args.name, args.description],
|
|
1784
|
+
rowMode: "array"
|
|
1785
|
+
});
|
|
1786
|
+
if (result.rows.length !== 1) {
|
|
1787
|
+
return null;
|
|
1788
|
+
}
|
|
1789
|
+
const row = result.rows[0];
|
|
1790
|
+
return {
|
|
1791
|
+
id: row[0],
|
|
1792
|
+
organizationId: row[1],
|
|
1793
|
+
slug: row[2],
|
|
1794
|
+
name: row[3],
|
|
1795
|
+
description: row[4],
|
|
1796
|
+
createdAt: row[5],
|
|
1797
|
+
updatedAt: row[6]
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
exports.getOrgTeamQuery = `-- name: GetOrgTeam :one
|
|
1801
|
+
SELECT id, organization_id, slug, name, description, created_at, updated_at
|
|
1802
|
+
FROM weave.org_teams
|
|
1803
|
+
WHERE organization_id = $1
|
|
1804
|
+
AND id = $2`;
|
|
1805
|
+
async function getOrgTeam(client, args) {
|
|
1806
|
+
const result = await client.query({
|
|
1807
|
+
text: exports.getOrgTeamQuery,
|
|
1808
|
+
values: [args.organizationId, args.id],
|
|
1809
|
+
rowMode: "array"
|
|
1810
|
+
});
|
|
1811
|
+
if (result.rows.length !== 1) {
|
|
1812
|
+
return null;
|
|
1813
|
+
}
|
|
1814
|
+
const row = result.rows[0];
|
|
1815
|
+
return {
|
|
1816
|
+
id: row[0],
|
|
1817
|
+
organizationId: row[1],
|
|
1818
|
+
slug: row[2],
|
|
1819
|
+
name: row[3],
|
|
1820
|
+
description: row[4],
|
|
1821
|
+
createdAt: row[5],
|
|
1822
|
+
updatedAt: row[6]
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
exports.listOrgTeamsQuery = `-- name: ListOrgTeams :many
|
|
1826
|
+
SELECT id, organization_id, slug, name, description, created_at, updated_at
|
|
1827
|
+
FROM weave.org_teams
|
|
1828
|
+
WHERE organization_id = $1
|
|
1829
|
+
ORDER BY name ASC, slug ASC`;
|
|
1830
|
+
async function listOrgTeams(client, args) {
|
|
1831
|
+
const result = await client.query({
|
|
1832
|
+
text: exports.listOrgTeamsQuery,
|
|
1833
|
+
values: [args.organizationId],
|
|
1834
|
+
rowMode: "array"
|
|
1835
|
+
});
|
|
1836
|
+
return result.rows.map(row => {
|
|
1837
|
+
return {
|
|
1838
|
+
id: row[0],
|
|
1839
|
+
organizationId: row[1],
|
|
1840
|
+
slug: row[2],
|
|
1841
|
+
name: row[3],
|
|
1842
|
+
description: row[4],
|
|
1843
|
+
createdAt: row[5],
|
|
1844
|
+
updatedAt: row[6]
|
|
1845
|
+
};
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
exports.updateOrgTeamQuery = `-- name: UpdateOrgTeam :one
|
|
1849
|
+
UPDATE weave.org_teams
|
|
1850
|
+
SET
|
|
1851
|
+
slug = $1,
|
|
1852
|
+
name = $2,
|
|
1853
|
+
description = $3,
|
|
1854
|
+
updated_at = now()
|
|
1855
|
+
WHERE organization_id = $4
|
|
1856
|
+
AND id = $5
|
|
1857
|
+
RETURNING id, organization_id, slug, name, description, created_at, updated_at`;
|
|
1858
|
+
async function updateOrgTeam(client, args) {
|
|
1859
|
+
const result = await client.query({
|
|
1860
|
+
text: exports.updateOrgTeamQuery,
|
|
1861
|
+
values: [args.slug, args.name, args.description, args.organizationId, args.id],
|
|
1862
|
+
rowMode: "array"
|
|
1863
|
+
});
|
|
1864
|
+
if (result.rows.length !== 1) {
|
|
1865
|
+
return null;
|
|
1866
|
+
}
|
|
1867
|
+
const row = result.rows[0];
|
|
1868
|
+
return {
|
|
1869
|
+
id: row[0],
|
|
1870
|
+
organizationId: row[1],
|
|
1871
|
+
slug: row[2],
|
|
1872
|
+
name: row[3],
|
|
1873
|
+
description: row[4],
|
|
1874
|
+
createdAt: row[5],
|
|
1875
|
+
updatedAt: row[6]
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
exports.deleteOrgTeamQuery = `-- name: DeleteOrgTeam :execrows
|
|
1879
|
+
DELETE FROM weave.org_teams
|
|
1880
|
+
WHERE organization_id = $1
|
|
1881
|
+
AND id = $2`;
|
|
1882
|
+
exports.deleteOrgTeamMembershipsQuery = `-- name: DeleteOrgTeamMemberships :execrows
|
|
1883
|
+
DELETE FROM weave.org_team_memberships
|
|
1884
|
+
WHERE organization_id = $1
|
|
1885
|
+
AND org_team_id = $2`;
|
|
1886
|
+
exports.addOrgTeamMembershipQuery = `-- name: AddOrgTeamMembership :one
|
|
1887
|
+
INSERT INTO weave.org_team_memberships (
|
|
1888
|
+
organization_id,
|
|
1889
|
+
org_team_id,
|
|
1890
|
+
organization_membership_id,
|
|
1891
|
+
user_id
|
|
1892
|
+
) VALUES (
|
|
1893
|
+
$1,
|
|
1894
|
+
$2,
|
|
1895
|
+
$3,
|
|
1896
|
+
$4
|
|
1897
|
+
)
|
|
1898
|
+
RETURNING organization_id, org_team_id, organization_membership_id, user_id, created_at`;
|
|
1899
|
+
async function addOrgTeamMembership(client, args) {
|
|
1900
|
+
const result = await client.query({
|
|
1901
|
+
text: exports.addOrgTeamMembershipQuery,
|
|
1902
|
+
values: [args.organizationId, args.orgTeamId, args.organizationMembershipId, args.userId],
|
|
1903
|
+
rowMode: "array"
|
|
1904
|
+
});
|
|
1905
|
+
if (result.rows.length !== 1) {
|
|
1906
|
+
return null;
|
|
1907
|
+
}
|
|
1908
|
+
const row = result.rows[0];
|
|
1909
|
+
return {
|
|
1910
|
+
organizationId: row[0],
|
|
1911
|
+
orgTeamId: row[1],
|
|
1912
|
+
organizationMembershipId: row[2],
|
|
1913
|
+
userId: row[3],
|
|
1914
|
+
createdAt: row[4]
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
exports.deleteOrgTeamRoleGrantsQuery = `-- name: DeleteOrgTeamRoleGrants :execrows
|
|
1918
|
+
DELETE FROM weave.org_team_role_grants
|
|
1919
|
+
WHERE organization_id = $1
|
|
1920
|
+
AND org_team_id = $2`;
|
|
1921
|
+
exports.addOrgTeamRoleGrantQuery = `-- name: AddOrgTeamRoleGrant :one
|
|
1922
|
+
INSERT INTO weave.org_team_role_grants (
|
|
1923
|
+
organization_id,
|
|
1924
|
+
org_team_id,
|
|
1925
|
+
role_id
|
|
1926
|
+
) VALUES (
|
|
1927
|
+
$1,
|
|
1928
|
+
$2,
|
|
1929
|
+
$3
|
|
1930
|
+
)
|
|
1931
|
+
RETURNING organization_id, org_team_id, role_id, created_at`;
|
|
1932
|
+
async function addOrgTeamRoleGrant(client, args) {
|
|
1933
|
+
const result = await client.query({
|
|
1934
|
+
text: exports.addOrgTeamRoleGrantQuery,
|
|
1935
|
+
values: [args.organizationId, args.orgTeamId, args.roleId],
|
|
1936
|
+
rowMode: "array"
|
|
1937
|
+
});
|
|
1938
|
+
if (result.rows.length !== 1) {
|
|
1939
|
+
return null;
|
|
1940
|
+
}
|
|
1941
|
+
const row = result.rows[0];
|
|
1942
|
+
return {
|
|
1943
|
+
organizationId: row[0],
|
|
1944
|
+
orgTeamId: row[1],
|
|
1945
|
+
roleId: row[2],
|
|
1946
|
+
createdAt: row[3]
|
|
1947
|
+
};
|
|
1948
|
+
}
|
|
1949
|
+
exports.listOrgTeamMembersQuery = `-- name: ListOrgTeamMembers :many
|
|
1950
|
+
SELECT
|
|
1951
|
+
tm.organization_id,
|
|
1952
|
+
tm.org_team_id,
|
|
1953
|
+
tm.organization_membership_id,
|
|
1954
|
+
tm.user_id,
|
|
1955
|
+
p.display_name,
|
|
1956
|
+
p.email,
|
|
1957
|
+
p.avatar_url,
|
|
1958
|
+
m.status,
|
|
1959
|
+
tm.created_at
|
|
1960
|
+
FROM weave.org_team_memberships AS tm
|
|
1961
|
+
JOIN weave.organization_memberships AS m
|
|
1962
|
+
ON m.id = tm.organization_membership_id
|
|
1963
|
+
AND m.organization_id = tm.organization_id
|
|
1964
|
+
AND m.user_id = tm.user_id
|
|
1965
|
+
JOIN weave.user_profiles AS p
|
|
1966
|
+
ON p.user_id = tm.user_id
|
|
1967
|
+
WHERE tm.organization_id = $1
|
|
1968
|
+
AND tm.org_team_id = $2
|
|
1969
|
+
ORDER BY p.display_name ASC, p.email ASC`;
|
|
1970
|
+
async function listOrgTeamMembers(client, args) {
|
|
1971
|
+
const result = await client.query({
|
|
1972
|
+
text: exports.listOrgTeamMembersQuery,
|
|
1973
|
+
values: [args.organizationId, args.orgTeamId],
|
|
1974
|
+
rowMode: "array"
|
|
1975
|
+
});
|
|
1976
|
+
return result.rows.map(row => {
|
|
1977
|
+
return {
|
|
1978
|
+
organizationId: row[0],
|
|
1979
|
+
orgTeamId: row[1],
|
|
1980
|
+
organizationMembershipId: row[2],
|
|
1981
|
+
userId: row[3],
|
|
1982
|
+
displayName: row[4],
|
|
1983
|
+
email: row[5],
|
|
1984
|
+
avatarUrl: row[6],
|
|
1985
|
+
status: row[7],
|
|
1986
|
+
createdAt: row[8]
|
|
1987
|
+
};
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
exports.listOrgTeamRoleGrantsQuery = `-- name: ListOrgTeamRoleGrants :many
|
|
1991
|
+
SELECT organization_id, org_team_id, role_id, created_at
|
|
1992
|
+
FROM weave.org_team_role_grants
|
|
1993
|
+
WHERE organization_id = $1
|
|
1994
|
+
AND org_team_id = $2
|
|
1995
|
+
ORDER BY role_id ASC`;
|
|
1996
|
+
async function listOrgTeamRoleGrants(client, args) {
|
|
1997
|
+
const result = await client.query({
|
|
1998
|
+
text: exports.listOrgTeamRoleGrantsQuery,
|
|
1999
|
+
values: [args.organizationId, args.orgTeamId],
|
|
2000
|
+
rowMode: "array"
|
|
2001
|
+
});
|
|
2002
|
+
return result.rows.map(row => {
|
|
2003
|
+
return {
|
|
2004
|
+
organizationId: row[0],
|
|
2005
|
+
orgTeamId: row[1],
|
|
2006
|
+
roleId: row[2],
|
|
2007
|
+
createdAt: row[3]
|
|
2008
|
+
};
|
|
2009
|
+
});
|
|
2010
|
+
}
|
|
2011
|
+
exports.listEffectiveOrganizationRoleIDsQuery = `-- name: ListEffectiveOrganizationRoleIDs :many
|
|
2012
|
+
SELECT DISTINCT role_id
|
|
2013
|
+
FROM (
|
|
2014
|
+
SELECT unnest(m.role_ids) AS role_id
|
|
2015
|
+
FROM weave.organization_memberships AS m
|
|
2016
|
+
WHERE m.organization_id = $1
|
|
2017
|
+
AND m.user_id = $2
|
|
2018
|
+
AND m.status = 'active'
|
|
2019
|
+
UNION
|
|
2020
|
+
SELECT r.role_id
|
|
2021
|
+
FROM weave.org_team_memberships AS tm
|
|
2022
|
+
JOIN weave.organization_memberships AS team_member
|
|
2023
|
+
ON team_member.id = tm.organization_membership_id
|
|
2024
|
+
AND team_member.organization_id = tm.organization_id
|
|
2025
|
+
AND team_member.user_id = tm.user_id
|
|
2026
|
+
AND team_member.status = 'active'
|
|
2027
|
+
JOIN weave.org_team_role_grants AS r
|
|
2028
|
+
ON r.organization_id = tm.organization_id
|
|
2029
|
+
AND r.org_team_id = tm.org_team_id
|
|
2030
|
+
WHERE tm.organization_id = $1
|
|
2031
|
+
AND tm.user_id = $2
|
|
2032
|
+
) AS roles
|
|
2033
|
+
WHERE role_id <> ''
|
|
2034
|
+
ORDER BY role_id ASC`;
|
|
2035
|
+
async function listEffectiveOrganizationRoleIDs(client, args) {
|
|
2036
|
+
const result = await client.query({
|
|
2037
|
+
text: exports.listEffectiveOrganizationRoleIDsQuery,
|
|
2038
|
+
values: [args.organizationId, args.userId],
|
|
2039
|
+
rowMode: "array"
|
|
2040
|
+
});
|
|
2041
|
+
return result.rows.map(row => {
|
|
2042
|
+
return {
|
|
2043
|
+
roleId: row[0]
|
|
2044
|
+
};
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
exports.deleteOrgTeamMembershipsForOrganizationMemberQuery = `-- name: DeleteOrgTeamMembershipsForOrganizationMember :execrows
|
|
2048
|
+
DELETE FROM weave.org_team_memberships
|
|
2049
|
+
WHERE organization_id = $1
|
|
2050
|
+
AND organization_membership_id = $2`;
|