weave-typescript 0.51.3 → 0.52.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/google/protobuf/duration.pb.d.ts +99 -0
- package/dist/google/protobuf/duration.pb.js +93 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/weave/authz/v1/index.d.ts +1 -0
- package/dist/weave/authz/v1/index.js +38 -0
- package/dist/weave/authz/v1/options.pb.d.ts +52 -0
- package/dist/weave/authz/v1/options.pb.js +403 -0
- package/dist/weave/filter/v1/index.d.ts +1 -0
- package/dist/weave/filter/v1/index.js +38 -0
- package/dist/{weaveapi/atc/v1/message.pb.d.ts → weave/filter/v1/options.pb.d.ts} +33 -21
- package/dist/weave/filter/v1/options.pb.js +417 -0
- package/dist/weave/index.d.ts +2 -0
- package/dist/weave/index.js +39 -0
- package/dist/weaveapi/agent/v1/agent.pb.d.ts +137 -188
- package/dist/weaveapi/agent/v1/agent.pb.js +891 -2151
- package/dist/weaveapi/agent/v1/index.d.ts +1 -1
- package/dist/weaveapi/agent/v1/index.js +2 -2
- package/dist/weaveapi/agent/v1/run.pb.d.ts +289 -0
- package/dist/weaveapi/agent/v1/run.pb.js +2763 -0
- package/dist/weaveapi/auth/v1/auth.pb.d.ts +67 -14
- package/dist/weaveapi/auth/v1/auth.pb.js +829 -89
- package/dist/weaveapi/auth/v1/index.d.ts +4 -1
- package/dist/weaveapi/auth/v1/index.js +5 -2
- package/dist/weaveapi/auth/v1/{service.pb.d.ts → organization_admin.pb.d.ts} +39 -530
- package/dist/weaveapi/auth/v1/{service.pb.js → organization_admin.pb.js} +2978 -5812
- package/dist/weaveapi/auth/v1/personal_access_token.pb.d.ts +114 -0
- package/dist/weaveapi/auth/v1/personal_access_token.pb.js +750 -0
- package/dist/weaveapi/auth/v1/profile.pb.d.ts +161 -0
- package/dist/weaveapi/auth/v1/profile.pb.js +1007 -0
- package/dist/weaveapi/auth/v1/session.pb.d.ts +460 -0
- package/dist/weaveapi/auth/v1/session.pb.js +3544 -0
- package/dist/weaveapi/chat/v1/chat.pb.d.ts +377 -149
- package/dist/weaveapi/chat/v1/chat.pb.js +3492 -1614
- package/dist/weaveapi/chat/v1/index.d.ts +0 -1
- package/dist/weaveapi/chat/v1/index.js +1 -2
- package/dist/weaveapi/consolidation/v1/consolidation.pb.d.ts +95 -0
- package/dist/weaveapi/consolidation/v1/consolidation.pb.js +770 -1
- package/dist/weaveapi/consolidation/v1/index.d.ts +0 -1
- package/dist/weaveapi/consolidation/v1/index.js +1 -2
- package/dist/weaveapi/content/v1/content.pb.d.ts +63 -0
- package/dist/weaveapi/content/v1/content.pb.js +470 -0
- package/dist/weaveapi/content/v1/index.d.ts +1 -0
- package/dist/weaveapi/content/v1/index.js +38 -0
- package/dist/weaveapi/gateway/v1/gateway.pb.d.ts +247 -523
- package/dist/weaveapi/gateway/v1/gateway.pb.js +1648 -5783
- package/dist/weaveapi/gateway/v1/index.d.ts +0 -1
- package/dist/weaveapi/gateway/v1/index.js +1 -2
- package/dist/weaveapi/index.d.ts +5 -5
- package/dist/weaveapi/index.js +6 -6
- package/dist/weaveapi/inference/v1/generate.pb.d.ts +120 -0
- package/dist/weaveapi/inference/v1/generate.pb.js +1159 -0
- package/dist/weaveapi/inference/v1/index.d.ts +4 -0
- package/dist/weaveapi/{provider → inference}/v1/index.js +4 -2
- package/dist/weaveapi/{model → inference}/v1/model.pb.d.ts +52 -15
- package/dist/weaveapi/{model → inference}/v1/model.pb.js +529 -116
- package/dist/weaveapi/{model/v1/service.pb.d.ts → inference/v1/model_route.pb.d.ts} +182 -110
- package/dist/weaveapi/{model/v1/service.pb.js → inference/v1/model_route.pb.js} +2197 -1061
- package/dist/weaveapi/inference/v1/provider.pb.d.ts +264 -0
- package/dist/weaveapi/inference/v1/provider.pb.js +2590 -0
- package/dist/weaveapi/ingestion/v1/index.d.ts +0 -2
- package/dist/weaveapi/ingestion/v1/index.js +1 -3
- package/dist/weaveapi/ingestion/v1/ingestion.pb.d.ts +543 -0
- package/dist/weaveapi/ingestion/v1/ingestion.pb.js +5550 -16
- package/dist/weaveapi/initialization/v1/index.d.ts +1 -0
- package/dist/weaveapi/initialization/v1/index.js +38 -0
- package/dist/weaveapi/initialization/v1/initialization.pb.d.ts +99 -0
- package/dist/weaveapi/initialization/v1/initialization.pb.js +510 -0
- package/dist/weaveapi/organization/v1/index.d.ts +0 -1
- package/dist/weaveapi/organization/v1/index.js +1 -2
- package/dist/weaveapi/organization/v1/organization.pb.d.ts +241 -0
- package/dist/weaveapi/organization/v1/organization.pb.js +1838 -1
- package/dist/weaveapi/reporting/index.d.ts +1 -0
- package/dist/weaveapi/reporting/index.js +38 -0
- package/dist/weaveapi/{task → reporting}/v1/index.d.ts +1 -1
- package/dist/weaveapi/{model → reporting}/v1/index.js +2 -2
- package/dist/weaveapi/reporting/v1/service.pb.d.ts +38 -0
- package/dist/weaveapi/reporting/v1/service.pb.js +167 -0
- package/dist/weaveapi/reporting/v1/usage.pb.d.ts +150 -0
- package/dist/weaveapi/reporting/v1/usage.pb.js +1837 -0
- package/dist/weaveapi/retrieval/v1/index.d.ts +0 -1
- package/dist/weaveapi/retrieval/v1/index.js +1 -2
- package/dist/weaveapi/retrieval/v1/retrieval.pb.d.ts +96 -2
- package/dist/weaveapi/retrieval/v1/retrieval.pb.js +690 -10
- package/dist/weaveapi/tool/index.d.ts +1 -0
- package/dist/weaveapi/tool/index.js +38 -0
- package/dist/weaveapi/tool/v1/index.d.ts +1 -0
- package/dist/weaveapi/tool/v1/index.js +38 -0
- package/dist/weaveapi/tool/v1/tool.pb.d.ts +370 -0
- package/dist/weaveapi/tool/v1/tool.pb.js +2717 -0
- package/dist/weaveapi/workflow/v1/index.d.ts +1 -1
- package/dist/weaveapi/workflow/v1/index.js +2 -2
- package/dist/weaveapi/workflow/v1/run.pb.d.ts +244 -0
- package/dist/weaveapi/workflow/v1/run.pb.js +2084 -0
- package/dist/weaveapi/workflow/v1/workflow.pb.d.ts +122 -275
- package/dist/weaveapi/workflow/v1/workflow.pb.js +790 -3261
- package/dist/weavesql/weavedb/agent_sql.d.ts +173 -477
- package/dist/weavesql/weavedb/agent_sql.js +281 -758
- package/dist/weavesql/weavedb/authorization_outbox_sql.d.ts +261 -0
- package/dist/weavesql/weavedb/authorization_outbox_sql.js +445 -0
- package/dist/weavesql/weavedb/chat_sql.d.ts +103 -345
- package/dist/weavesql/weavedb/chat_sql.js +312 -597
- package/dist/weavesql/weavedb/document_consolidation_sql.d.ts +217 -0
- package/dist/weavesql/weavedb/document_consolidation_sql.js +486 -0
- package/dist/weavesql/weavedb/document_ingestion_sql.d.ts +1433 -0
- package/dist/weavesql/weavedb/document_ingestion_sql.js +3488 -0
- package/dist/weavesql/weavedb/document_retrieval_sql.d.ts +314 -0
- package/dist/weavesql/weavedb/document_retrieval_sql.js +965 -0
- package/dist/weavesql/weavedb/document_table_sql.d.ts +6 -6
- package/dist/weavesql/weavedb/document_table_sql.js +12 -12
- package/dist/weavesql/weavedb/identity_sql.d.ts +1014 -0
- package/dist/weavesql/weavedb/identity_sql.js +1811 -0
- package/dist/weavesql/weavedb/inference_model_route_sql.d.ts +161 -0
- package/dist/weavesql/weavedb/inference_model_route_sql.js +408 -0
- package/dist/weavesql/weavedb/inference_provider_sql.d.ts +125 -0
- package/dist/weavesql/weavedb/inference_provider_sql.js +228 -0
- package/dist/weavesql/weavedb/initialization_sql.d.ts +15 -0
- package/dist/weavesql/weavedb/initialization_sql.js +33 -0
- package/dist/weavesql/weavedb/model_catalog_sql.d.ts +6 -6
- package/dist/weavesql/weavedb/model_catalog_sql.js +6 -6
- package/dist/weavesql/weavedb/organization_sql.d.ts +22 -102
- package/dist/weavesql/weavedb/organization_sql.js +54 -262
- package/dist/weavesql/weavedb/tool_sql.d.ts +209 -0
- package/dist/weavesql/weavedb/tool_sql.js +407 -0
- package/dist/weavesql/weavedb/usage_sql.d.ts +356 -0
- package/dist/weavesql/weavedb/usage_sql.js +568 -0
- package/dist/weavesql/weavedb/workflow_sql.d.ts +159 -546
- package/dist/weavesql/weavedb/workflow_sql.js +281 -909
- package/package.json +1 -1
- package/dist/weaveapi/agent/v1/service.pb.d.ts +0 -397
- package/dist/weaveapi/agent/v1/service.pb.js +0 -3152
- package/dist/weaveapi/atc/v1/event.pb.d.ts +0 -134
- package/dist/weaveapi/atc/v1/event.pb.js +0 -1124
- package/dist/weaveapi/atc/v1/index.d.ts +0 -5
- package/dist/weaveapi/atc/v1/index.js +0 -42
- package/dist/weaveapi/atc/v1/message.pb.js +0 -287
- package/dist/weaveapi/atc/v1/process.pb.d.ts +0 -91
- package/dist/weaveapi/atc/v1/process.pb.js +0 -658
- package/dist/weaveapi/atc/v1/run.pb.d.ts +0 -71
- package/dist/weaveapi/atc/v1/run.pb.js +0 -525
- package/dist/weaveapi/atc/v1/service.pb.d.ts +0 -472
- package/dist/weaveapi/atc/v1/service.pb.js +0 -3093
- package/dist/weaveapi/chat/v1/service.pb.d.ts +0 -345
- package/dist/weaveapi/chat/v1/service.pb.js +0 -2545
- package/dist/weaveapi/consolidation/v1/service.pb.d.ts +0 -93
- package/dist/weaveapi/consolidation/v1/service.pb.js +0 -427
- package/dist/weaveapi/gateway/v1/service.pb.d.ts +0 -235
- package/dist/weaveapi/gateway/v1/service.pb.js +0 -651
- package/dist/weaveapi/ingestion/v1/service.pb.d.ts +0 -420
- package/dist/weaveapi/ingestion/v1/service.pb.js +0 -2311
- package/dist/weaveapi/ingestion/v1/table.pb.d.ts +0 -121
- package/dist/weaveapi/ingestion/v1/table.pb.js +0 -1478
- package/dist/weaveapi/model/v1/index.d.ts +0 -2
- package/dist/weaveapi/organization/v1/service.pb.d.ts +0 -261
- package/dist/weaveapi/organization/v1/service.pb.js +0 -1561
- package/dist/weaveapi/project/v1/index.d.ts +0 -2
- package/dist/weaveapi/project/v1/index.js +0 -39
- package/dist/weaveapi/project/v1/project.pb.d.ts +0 -105
- package/dist/weaveapi/project/v1/project.pb.js +0 -1004
- package/dist/weaveapi/project/v1/service.pb.d.ts +0 -247
- package/dist/weaveapi/project/v1/service.pb.js +0 -1994
- package/dist/weaveapi/provider/v1/index.d.ts +0 -2
- package/dist/weaveapi/provider/v1/provider.pb.d.ts +0 -137
- package/dist/weaveapi/provider/v1/provider.pb.js +0 -1000
- package/dist/weaveapi/provider/v1/service.pb.d.ts +0 -223
- package/dist/weaveapi/provider/v1/service.pb.js +0 -1888
- package/dist/weaveapi/retrieval/v1/service.pb.d.ts +0 -93
- package/dist/weaveapi/retrieval/v1/service.pb.js +0 -385
- package/dist/weaveapi/task/v1/index.js +0 -39
- package/dist/weaveapi/task/v1/service.pb.d.ts +0 -172
- package/dist/weaveapi/task/v1/service.pb.js +0 -1436
- package/dist/weaveapi/task/v1/task.pb.d.ts +0 -85
- package/dist/weaveapi/task/v1/task.pb.js +0 -802
- package/dist/weaveapi/workflow/v1/service.pb.d.ts +0 -392
- package/dist/weaveapi/workflow/v1/service.pb.js +0 -3146
- /package/dist/{weaveapi/atc → weave/authz}/index.d.ts +0 -0
- /package/dist/{weaveapi/atc → weave/authz}/index.js +0 -0
- /package/dist/{weaveapi/model → weave/filter}/index.d.ts +0 -0
- /package/dist/{weaveapi/model → weave/filter}/index.js +0 -0
- /package/dist/weaveapi/{project → content}/index.d.ts +0 -0
- /package/dist/weaveapi/{project → content}/index.js +0 -0
- /package/dist/weaveapi/{provider → inference}/index.d.ts +0 -0
- /package/dist/weaveapi/{provider → inference}/index.js +0 -0
- /package/dist/weaveapi/{task → initialization}/index.d.ts +0 -0
- /package/dist/weaveapi/{task → initialization}/index.js +0 -0
|
@@ -0,0 +1,1811 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPersonalAccessTokenQuery = exports.createPersonalAccessTokenQuery = exports.revokeAuthInviteSessionQuery = exports.completeAuthInviteSessionQuery = exports.updateAuthInviteSessionOAuthQuery = exports.getAuthInviteSessionByMembershipQuery = exports.getAuthInviteSessionQuery = exports.updateAuthInviteSessionTokenQuery = exports.createAuthInviteSessionQuery = exports.deleteExpiredApplicationSessionsQuery = exports.revokeApplicationSessionQuery = exports.updateApplicationSessionOrganizationQuery = exports.getPrincipalByApplicationSessionQuery = exports.getApplicationSessionQuery = exports.createApplicationSessionQuery = exports.getOrganizationIdentityLinkByOrganizationIDQuery = exports.updateOrganizationScimGroupMappingQuery = exports.listOrganizationScimGroupMappingsQuery = exports.upsertOrganizationScimGroupMappingQuery = exports.listOrganizationTeamRoleGrantsQuery = exports.addOrganizationTeamRoleGrantQuery = exports.deleteOrganizationTeamRoleGrantsQuery = exports.listOrganizationTeamMembersQuery = exports.addOrganizationTeamMembershipQuery = exports.deleteOrganizationTeamMembershipsQuery = exports.deleteOrganizationTeamQuery = exports.updateOrganizationTeamQuery = exports.listOrganizationTeamsQuery = exports.getOrganizationTeamQuery = exports.createOrganizationTeamQuery = exports.updateOrganizationMembershipByIDQuery = exports.listOrganizationMembersQuery = exports.getOrganizationMemberQuery = exports.getOrganizationMembershipQuery = exports.upsertOrganizationMembershipQuery = exports.upsertUserIdentityLinkQuery = exports.getPrincipalByExternalIdentityQuery = exports.updateUserPreferencesQuery = exports.updateUserProfileQuery = exports.getUserQuery = exports.getUserByExternalIdentityQuery = exports.upsertUserQuery = exports.upsertOrganizationIdentityLinkQuery = exports.getOrganizationByExternalIdentityQuery = exports.getOrganizationForUserBySlugQuery = exports.listOrganizationsForUserQuery = exports.listOrganizationsQuery = exports.getOrganizationBySlugQuery = exports.getOrganizationQuery = exports.createOrganizationQuery = void 0;
|
|
4
|
+
exports.revokePersonalAccessTokenForUserQuery = exports.revokePersonalAccessTokenQuery = exports.markPersonalAccessTokenUsedQuery = exports.getPrincipalByPersonalAccessTokenQuery = exports.listPersonalAccessTokensQuery = void 0;
|
|
5
|
+
exports.createOrganization = createOrganization;
|
|
6
|
+
exports.getOrganization = getOrganization;
|
|
7
|
+
exports.getOrganizationBySlug = getOrganizationBySlug;
|
|
8
|
+
exports.listOrganizations = listOrganizations;
|
|
9
|
+
exports.listOrganizationsForUser = listOrganizationsForUser;
|
|
10
|
+
exports.getOrganizationForUserBySlug = getOrganizationForUserBySlug;
|
|
11
|
+
exports.getOrganizationByExternalIdentity = getOrganizationByExternalIdentity;
|
|
12
|
+
exports.upsertOrganizationIdentityLink = upsertOrganizationIdentityLink;
|
|
13
|
+
exports.upsertUser = upsertUser;
|
|
14
|
+
exports.getUserByExternalIdentity = getUserByExternalIdentity;
|
|
15
|
+
exports.getUser = getUser;
|
|
16
|
+
exports.updateUserProfile = updateUserProfile;
|
|
17
|
+
exports.updateUserPreferences = updateUserPreferences;
|
|
18
|
+
exports.getPrincipalByExternalIdentity = getPrincipalByExternalIdentity;
|
|
19
|
+
exports.upsertUserIdentityLink = upsertUserIdentityLink;
|
|
20
|
+
exports.upsertOrganizationMembership = upsertOrganizationMembership;
|
|
21
|
+
exports.getOrganizationMembership = getOrganizationMembership;
|
|
22
|
+
exports.getOrganizationMember = getOrganizationMember;
|
|
23
|
+
exports.listOrganizationMembers = listOrganizationMembers;
|
|
24
|
+
exports.updateOrganizationMembershipByID = updateOrganizationMembershipByID;
|
|
25
|
+
exports.createOrganizationTeam = createOrganizationTeam;
|
|
26
|
+
exports.getOrganizationTeam = getOrganizationTeam;
|
|
27
|
+
exports.listOrganizationTeams = listOrganizationTeams;
|
|
28
|
+
exports.updateOrganizationTeam = updateOrganizationTeam;
|
|
29
|
+
exports.addOrganizationTeamMembership = addOrganizationTeamMembership;
|
|
30
|
+
exports.listOrganizationTeamMembers = listOrganizationTeamMembers;
|
|
31
|
+
exports.addOrganizationTeamRoleGrant = addOrganizationTeamRoleGrant;
|
|
32
|
+
exports.listOrganizationTeamRoleGrants = listOrganizationTeamRoleGrants;
|
|
33
|
+
exports.upsertOrganizationScimGroupMapping = upsertOrganizationScimGroupMapping;
|
|
34
|
+
exports.listOrganizationScimGroupMappings = listOrganizationScimGroupMappings;
|
|
35
|
+
exports.updateOrganizationScimGroupMapping = updateOrganizationScimGroupMapping;
|
|
36
|
+
exports.getOrganizationIdentityLinkByOrganizationID = getOrganizationIdentityLinkByOrganizationID;
|
|
37
|
+
exports.createApplicationSession = createApplicationSession;
|
|
38
|
+
exports.getApplicationSession = getApplicationSession;
|
|
39
|
+
exports.getPrincipalByApplicationSession = getPrincipalByApplicationSession;
|
|
40
|
+
exports.updateApplicationSessionOrganization = updateApplicationSessionOrganization;
|
|
41
|
+
exports.createAuthInviteSession = createAuthInviteSession;
|
|
42
|
+
exports.updateAuthInviteSessionToken = updateAuthInviteSessionToken;
|
|
43
|
+
exports.getAuthInviteSession = getAuthInviteSession;
|
|
44
|
+
exports.getAuthInviteSessionByMembership = getAuthInviteSessionByMembership;
|
|
45
|
+
exports.updateAuthInviteSessionOAuth = updateAuthInviteSessionOAuth;
|
|
46
|
+
exports.completeAuthInviteSession = completeAuthInviteSession;
|
|
47
|
+
exports.revokeAuthInviteSession = revokeAuthInviteSession;
|
|
48
|
+
exports.createPersonalAccessToken = createPersonalAccessToken;
|
|
49
|
+
exports.getPersonalAccessToken = getPersonalAccessToken;
|
|
50
|
+
exports.listPersonalAccessTokens = listPersonalAccessTokens;
|
|
51
|
+
exports.getPrincipalByPersonalAccessToken = getPrincipalByPersonalAccessToken;
|
|
52
|
+
exports.revokePersonalAccessTokenForUser = revokePersonalAccessTokenForUser;
|
|
53
|
+
exports.createOrganizationQuery = `-- name: CreateOrganization :one
|
|
54
|
+
INSERT INTO weave.organization (
|
|
55
|
+
slug,
|
|
56
|
+
name,
|
|
57
|
+
description,
|
|
58
|
+
primary_color,
|
|
59
|
+
logo,
|
|
60
|
+
logo_content_type,
|
|
61
|
+
timezone,
|
|
62
|
+
location,
|
|
63
|
+
status
|
|
64
|
+
) VALUES (
|
|
65
|
+
$1,
|
|
66
|
+
$2,
|
|
67
|
+
COALESCE($3::text, ''),
|
|
68
|
+
COALESCE($4::text, '#22d3ee'),
|
|
69
|
+
$5,
|
|
70
|
+
$6,
|
|
71
|
+
COALESCE($7::text, 'UTC'),
|
|
72
|
+
COALESCE($8::text, ''),
|
|
73
|
+
COALESCE($9::text, 'active')
|
|
74
|
+
)
|
|
75
|
+
RETURNING id, slug, name, description, primary_color, logo, logo_content_type, timezone, location, status, default_chat_agent_id, default_chat_model_route_id, created_at, updated_at`;
|
|
76
|
+
async function createOrganization(client, args) {
|
|
77
|
+
const result = await client.query({
|
|
78
|
+
text: exports.createOrganizationQuery,
|
|
79
|
+
values: [args.slug, args.name, args.description, args.primaryColor, args.logo, args.logoContentType, args.timezone, args.location, args.status],
|
|
80
|
+
rowMode: "array"
|
|
81
|
+
});
|
|
82
|
+
if (result.rows.length !== 1) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const row = result.rows[0];
|
|
86
|
+
return {
|
|
87
|
+
id: row[0],
|
|
88
|
+
slug: row[1],
|
|
89
|
+
name: row[2],
|
|
90
|
+
description: row[3],
|
|
91
|
+
primaryColor: row[4],
|
|
92
|
+
logo: row[5],
|
|
93
|
+
logoContentType: row[6],
|
|
94
|
+
timezone: row[7],
|
|
95
|
+
location: row[8],
|
|
96
|
+
status: row[9],
|
|
97
|
+
defaultChatAgentId: row[10],
|
|
98
|
+
defaultChatModelRouteId: row[11],
|
|
99
|
+
createdAt: row[12],
|
|
100
|
+
updatedAt: row[13]
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
exports.getOrganizationQuery = `-- name: GetOrganization :one
|
|
104
|
+
SELECT id, slug, name, description, primary_color, logo, logo_content_type, timezone, location, status, default_chat_agent_id, default_chat_model_route_id, created_at, updated_at
|
|
105
|
+
FROM weave.organization
|
|
106
|
+
WHERE id = $1`;
|
|
107
|
+
async function getOrganization(client, args) {
|
|
108
|
+
const result = await client.query({
|
|
109
|
+
text: exports.getOrganizationQuery,
|
|
110
|
+
values: [args.organizationId],
|
|
111
|
+
rowMode: "array"
|
|
112
|
+
});
|
|
113
|
+
if (result.rows.length !== 1) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const row = result.rows[0];
|
|
117
|
+
return {
|
|
118
|
+
id: row[0],
|
|
119
|
+
slug: row[1],
|
|
120
|
+
name: row[2],
|
|
121
|
+
description: row[3],
|
|
122
|
+
primaryColor: row[4],
|
|
123
|
+
logo: row[5],
|
|
124
|
+
logoContentType: row[6],
|
|
125
|
+
timezone: row[7],
|
|
126
|
+
location: row[8],
|
|
127
|
+
status: row[9],
|
|
128
|
+
defaultChatAgentId: row[10],
|
|
129
|
+
defaultChatModelRouteId: row[11],
|
|
130
|
+
createdAt: row[12],
|
|
131
|
+
updatedAt: row[13]
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
exports.getOrganizationBySlugQuery = `-- name: GetOrganizationBySlug :one
|
|
135
|
+
SELECT id, slug, name, description, primary_color, logo, logo_content_type, timezone, location, status, default_chat_agent_id, default_chat_model_route_id, created_at, updated_at
|
|
136
|
+
FROM weave.organization
|
|
137
|
+
WHERE slug = $1`;
|
|
138
|
+
async function getOrganizationBySlug(client, args) {
|
|
139
|
+
const result = await client.query({
|
|
140
|
+
text: exports.getOrganizationBySlugQuery,
|
|
141
|
+
values: [args.slug],
|
|
142
|
+
rowMode: "array"
|
|
143
|
+
});
|
|
144
|
+
if (result.rows.length !== 1) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const row = result.rows[0];
|
|
148
|
+
return {
|
|
149
|
+
id: row[0],
|
|
150
|
+
slug: row[1],
|
|
151
|
+
name: row[2],
|
|
152
|
+
description: row[3],
|
|
153
|
+
primaryColor: row[4],
|
|
154
|
+
logo: row[5],
|
|
155
|
+
logoContentType: row[6],
|
|
156
|
+
timezone: row[7],
|
|
157
|
+
location: row[8],
|
|
158
|
+
status: row[9],
|
|
159
|
+
defaultChatAgentId: row[10],
|
|
160
|
+
defaultChatModelRouteId: row[11],
|
|
161
|
+
createdAt: row[12],
|
|
162
|
+
updatedAt: row[13]
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
exports.listOrganizationsQuery = `-- name: ListOrganizations :many
|
|
166
|
+
SELECT id, slug, name, description, primary_color, logo, logo_content_type, timezone, location, status, default_chat_agent_id, default_chat_model_route_id, created_at, updated_at
|
|
167
|
+
FROM weave.organization
|
|
168
|
+
WHERE status = 'active'
|
|
169
|
+
ORDER BY created_at DESC, id DESC`;
|
|
170
|
+
async function listOrganizations(client) {
|
|
171
|
+
const result = await client.query({
|
|
172
|
+
text: exports.listOrganizationsQuery,
|
|
173
|
+
values: [],
|
|
174
|
+
rowMode: "array"
|
|
175
|
+
});
|
|
176
|
+
return result.rows.map(row => {
|
|
177
|
+
return {
|
|
178
|
+
id: row[0],
|
|
179
|
+
slug: row[1],
|
|
180
|
+
name: row[2],
|
|
181
|
+
description: row[3],
|
|
182
|
+
primaryColor: row[4],
|
|
183
|
+
logo: row[5],
|
|
184
|
+
logoContentType: row[6],
|
|
185
|
+
timezone: row[7],
|
|
186
|
+
location: row[8],
|
|
187
|
+
status: row[9],
|
|
188
|
+
defaultChatAgentId: row[10],
|
|
189
|
+
defaultChatModelRouteId: row[11],
|
|
190
|
+
createdAt: row[12],
|
|
191
|
+
updatedAt: row[13]
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
exports.listOrganizationsForUserQuery = `-- name: ListOrganizationsForUser :many
|
|
196
|
+
SELECT o.id, o.slug, o.name, o.description, o.primary_color, o.logo, o.logo_content_type, o.timezone, o.location, o.status, o.default_chat_agent_id, o.default_chat_model_route_id, o.created_at, o.updated_at
|
|
197
|
+
FROM weave.organization o
|
|
198
|
+
JOIN weave.organization_membership om
|
|
199
|
+
ON om.organization_id = o.id
|
|
200
|
+
WHERE om.user_id = $1
|
|
201
|
+
AND om.status = 'active'
|
|
202
|
+
AND o.status = 'active'
|
|
203
|
+
ORDER BY o.created_at DESC, o.id DESC`;
|
|
204
|
+
async function listOrganizationsForUser(client, args) {
|
|
205
|
+
const result = await client.query({
|
|
206
|
+
text: exports.listOrganizationsForUserQuery,
|
|
207
|
+
values: [args.userId],
|
|
208
|
+
rowMode: "array"
|
|
209
|
+
});
|
|
210
|
+
return result.rows.map(row => {
|
|
211
|
+
return {
|
|
212
|
+
id: row[0],
|
|
213
|
+
slug: row[1],
|
|
214
|
+
name: row[2],
|
|
215
|
+
description: row[3],
|
|
216
|
+
primaryColor: row[4],
|
|
217
|
+
logo: row[5],
|
|
218
|
+
logoContentType: row[6],
|
|
219
|
+
timezone: row[7],
|
|
220
|
+
location: row[8],
|
|
221
|
+
status: row[9],
|
|
222
|
+
defaultChatAgentId: row[10],
|
|
223
|
+
defaultChatModelRouteId: row[11],
|
|
224
|
+
createdAt: row[12],
|
|
225
|
+
updatedAt: row[13]
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
exports.getOrganizationForUserBySlugQuery = `-- name: GetOrganizationForUserBySlug :one
|
|
230
|
+
SELECT o.id, o.slug, o.name, o.description, o.primary_color, o.logo, o.logo_content_type, o.timezone, o.location, o.status, o.default_chat_agent_id, o.default_chat_model_route_id, o.created_at, o.updated_at
|
|
231
|
+
FROM weave.organization o
|
|
232
|
+
JOIN weave.organization_membership om
|
|
233
|
+
ON om.organization_id = o.id
|
|
234
|
+
WHERE o.slug = $1
|
|
235
|
+
AND om.user_id = $2
|
|
236
|
+
AND om.status = 'active'
|
|
237
|
+
AND o.status = 'active'`;
|
|
238
|
+
async function getOrganizationForUserBySlug(client, args) {
|
|
239
|
+
const result = await client.query({
|
|
240
|
+
text: exports.getOrganizationForUserBySlugQuery,
|
|
241
|
+
values: [args.slug, args.userId],
|
|
242
|
+
rowMode: "array"
|
|
243
|
+
});
|
|
244
|
+
if (result.rows.length !== 1) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
const row = result.rows[0];
|
|
248
|
+
return {
|
|
249
|
+
id: row[0],
|
|
250
|
+
slug: row[1],
|
|
251
|
+
name: row[2],
|
|
252
|
+
description: row[3],
|
|
253
|
+
primaryColor: row[4],
|
|
254
|
+
logo: row[5],
|
|
255
|
+
logoContentType: row[6],
|
|
256
|
+
timezone: row[7],
|
|
257
|
+
location: row[8],
|
|
258
|
+
status: row[9],
|
|
259
|
+
defaultChatAgentId: row[10],
|
|
260
|
+
defaultChatModelRouteId: row[11],
|
|
261
|
+
createdAt: row[12],
|
|
262
|
+
updatedAt: row[13]
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
exports.getOrganizationByExternalIdentityQuery = `-- name: GetOrganizationByExternalIdentity :one
|
|
266
|
+
SELECT o.id, o.slug, o.name, o.description, o.primary_color, o.logo, o.logo_content_type, o.timezone, o.location, o.status, o.default_chat_agent_id, o.default_chat_model_route_id, o.created_at, o.updated_at
|
|
267
|
+
FROM weave.organization o
|
|
268
|
+
JOIN weave.organization_identity_link oil
|
|
269
|
+
ON oil.organization_id = o.id
|
|
270
|
+
WHERE oil.auth_provider = $1
|
|
271
|
+
AND oil.external_organization_id = $2`;
|
|
272
|
+
async function getOrganizationByExternalIdentity(client, args) {
|
|
273
|
+
const result = await client.query({
|
|
274
|
+
text: exports.getOrganizationByExternalIdentityQuery,
|
|
275
|
+
values: [args.authProvider, args.externalOrganizationId],
|
|
276
|
+
rowMode: "array"
|
|
277
|
+
});
|
|
278
|
+
if (result.rows.length !== 1) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
const row = result.rows[0];
|
|
282
|
+
return {
|
|
283
|
+
id: row[0],
|
|
284
|
+
slug: row[1],
|
|
285
|
+
name: row[2],
|
|
286
|
+
description: row[3],
|
|
287
|
+
primaryColor: row[4],
|
|
288
|
+
logo: row[5],
|
|
289
|
+
logoContentType: row[6],
|
|
290
|
+
timezone: row[7],
|
|
291
|
+
location: row[8],
|
|
292
|
+
status: row[9],
|
|
293
|
+
defaultChatAgentId: row[10],
|
|
294
|
+
defaultChatModelRouteId: row[11],
|
|
295
|
+
createdAt: row[12],
|
|
296
|
+
updatedAt: row[13]
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
exports.upsertOrganizationIdentityLinkQuery = `-- name: UpsertOrganizationIdentityLink :one
|
|
300
|
+
INSERT INTO weave.organization_identity_link (
|
|
301
|
+
organization_id,
|
|
302
|
+
auth_provider,
|
|
303
|
+
external_organization_id,
|
|
304
|
+
last_seen_at
|
|
305
|
+
) VALUES (
|
|
306
|
+
$1,
|
|
307
|
+
$2,
|
|
308
|
+
$3,
|
|
309
|
+
now()
|
|
310
|
+
)
|
|
311
|
+
ON CONFLICT (auth_provider, external_organization_id)
|
|
312
|
+
DO UPDATE SET
|
|
313
|
+
last_seen_at = EXCLUDED.last_seen_at
|
|
314
|
+
RETURNING id, organization_id, auth_provider, external_organization_id, last_seen_at, created_at, updated_at`;
|
|
315
|
+
async function upsertOrganizationIdentityLink(client, args) {
|
|
316
|
+
const result = await client.query({
|
|
317
|
+
text: exports.upsertOrganizationIdentityLinkQuery,
|
|
318
|
+
values: [args.organizationId, args.authProvider, args.externalOrganizationId],
|
|
319
|
+
rowMode: "array"
|
|
320
|
+
});
|
|
321
|
+
if (result.rows.length !== 1) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
const row = result.rows[0];
|
|
325
|
+
return {
|
|
326
|
+
id: row[0],
|
|
327
|
+
organizationId: row[1],
|
|
328
|
+
authProvider: row[2],
|
|
329
|
+
externalOrganizationId: row[3],
|
|
330
|
+
lastSeenAt: row[4],
|
|
331
|
+
createdAt: row[5],
|
|
332
|
+
updatedAt: row[6]
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
exports.upsertUserQuery = `-- name: UpsertUser :one
|
|
336
|
+
INSERT INTO weave.user (
|
|
337
|
+
email,
|
|
338
|
+
name,
|
|
339
|
+
job_title,
|
|
340
|
+
avatar_url,
|
|
341
|
+
status
|
|
342
|
+
) VALUES (
|
|
343
|
+
$1,
|
|
344
|
+
$2,
|
|
345
|
+
COALESCE($3::text, ''),
|
|
346
|
+
COALESCE($4::text, ''),
|
|
347
|
+
COALESCE($5::text, 'active')
|
|
348
|
+
)
|
|
349
|
+
ON CONFLICT (email)
|
|
350
|
+
DO UPDATE SET
|
|
351
|
+
name = EXCLUDED.name,
|
|
352
|
+
status = EXCLUDED.status
|
|
353
|
+
RETURNING id, email, name, job_title, avatar_url, preferences, status, created_at, updated_at`;
|
|
354
|
+
async function upsertUser(client, args) {
|
|
355
|
+
const result = await client.query({
|
|
356
|
+
text: exports.upsertUserQuery,
|
|
357
|
+
values: [args.email, args.name, args.jobTitle, args.avatarUrl, args.status],
|
|
358
|
+
rowMode: "array"
|
|
359
|
+
});
|
|
360
|
+
if (result.rows.length !== 1) {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
const row = result.rows[0];
|
|
364
|
+
return {
|
|
365
|
+
id: row[0],
|
|
366
|
+
email: row[1],
|
|
367
|
+
name: row[2],
|
|
368
|
+
jobTitle: row[3],
|
|
369
|
+
avatarUrl: row[4],
|
|
370
|
+
preferences: row[5],
|
|
371
|
+
status: row[6],
|
|
372
|
+
createdAt: row[7],
|
|
373
|
+
updatedAt: row[8]
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
exports.getUserByExternalIdentityQuery = `-- name: GetUserByExternalIdentity :one
|
|
377
|
+
SELECT u.id, u.email, u.name, u.job_title, u.avatar_url, u.preferences, u.status, u.created_at, u.updated_at
|
|
378
|
+
FROM weave.user u
|
|
379
|
+
JOIN weave.user_identity_link uil
|
|
380
|
+
ON uil.user_id = u.id
|
|
381
|
+
JOIN weave.organization_identity_link oil
|
|
382
|
+
ON oil.id = uil.organization_identity_link_id
|
|
383
|
+
WHERE oil.auth_provider = $1
|
|
384
|
+
AND oil.external_organization_id = $2
|
|
385
|
+
AND uil.external_subject_id = $3`;
|
|
386
|
+
async function getUserByExternalIdentity(client, args) {
|
|
387
|
+
const result = await client.query({
|
|
388
|
+
text: exports.getUserByExternalIdentityQuery,
|
|
389
|
+
values: [args.authProvider, args.externalOrganizationId, args.externalSubjectId],
|
|
390
|
+
rowMode: "array"
|
|
391
|
+
});
|
|
392
|
+
if (result.rows.length !== 1) {
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
const row = result.rows[0];
|
|
396
|
+
return {
|
|
397
|
+
id: row[0],
|
|
398
|
+
email: row[1],
|
|
399
|
+
name: row[2],
|
|
400
|
+
jobTitle: row[3],
|
|
401
|
+
avatarUrl: row[4],
|
|
402
|
+
preferences: row[5],
|
|
403
|
+
status: row[6],
|
|
404
|
+
createdAt: row[7],
|
|
405
|
+
updatedAt: row[8]
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
exports.getUserQuery = `-- name: GetUser :one
|
|
409
|
+
SELECT id, email, name, job_title, avatar_url, preferences, status, created_at, updated_at
|
|
410
|
+
FROM weave.user
|
|
411
|
+
WHERE id = $1`;
|
|
412
|
+
async function getUser(client, args) {
|
|
413
|
+
const result = await client.query({
|
|
414
|
+
text: exports.getUserQuery,
|
|
415
|
+
values: [args.userId],
|
|
416
|
+
rowMode: "array"
|
|
417
|
+
});
|
|
418
|
+
if (result.rows.length !== 1) {
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
const row = result.rows[0];
|
|
422
|
+
return {
|
|
423
|
+
id: row[0],
|
|
424
|
+
email: row[1],
|
|
425
|
+
name: row[2],
|
|
426
|
+
jobTitle: row[3],
|
|
427
|
+
avatarUrl: row[4],
|
|
428
|
+
preferences: row[5],
|
|
429
|
+
status: row[6],
|
|
430
|
+
createdAt: row[7],
|
|
431
|
+
updatedAt: row[8]
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
exports.updateUserProfileQuery = `-- name: UpdateUserProfile :one
|
|
435
|
+
UPDATE weave.user
|
|
436
|
+
SET
|
|
437
|
+
name = COALESCE($1::text, name),
|
|
438
|
+
job_title = COALESCE($2::text, job_title),
|
|
439
|
+
avatar_url = COALESCE($3::text, avatar_url)
|
|
440
|
+
WHERE id = $4
|
|
441
|
+
RETURNING id, email, name, job_title, avatar_url, preferences, status, created_at, updated_at`;
|
|
442
|
+
async function updateUserProfile(client, args) {
|
|
443
|
+
const result = await client.query({
|
|
444
|
+
text: exports.updateUserProfileQuery,
|
|
445
|
+
values: [args.name, args.jobTitle, args.avatarUrl, args.userId],
|
|
446
|
+
rowMode: "array"
|
|
447
|
+
});
|
|
448
|
+
if (result.rows.length !== 1) {
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
const row = result.rows[0];
|
|
452
|
+
return {
|
|
453
|
+
id: row[0],
|
|
454
|
+
email: row[1],
|
|
455
|
+
name: row[2],
|
|
456
|
+
jobTitle: row[3],
|
|
457
|
+
avatarUrl: row[4],
|
|
458
|
+
preferences: row[5],
|
|
459
|
+
status: row[6],
|
|
460
|
+
createdAt: row[7],
|
|
461
|
+
updatedAt: row[8]
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
exports.updateUserPreferencesQuery = `-- name: UpdateUserPreferences :one
|
|
465
|
+
UPDATE weave.user
|
|
466
|
+
SET preferences = $1::jsonb
|
|
467
|
+
WHERE id = $2
|
|
468
|
+
RETURNING id, email, name, job_title, avatar_url, preferences, status, created_at, updated_at`;
|
|
469
|
+
async function updateUserPreferences(client, args) {
|
|
470
|
+
const result = await client.query({
|
|
471
|
+
text: exports.updateUserPreferencesQuery,
|
|
472
|
+
values: [args.preferences, args.userId],
|
|
473
|
+
rowMode: "array"
|
|
474
|
+
});
|
|
475
|
+
if (result.rows.length !== 1) {
|
|
476
|
+
return null;
|
|
477
|
+
}
|
|
478
|
+
const row = result.rows[0];
|
|
479
|
+
return {
|
|
480
|
+
id: row[0],
|
|
481
|
+
email: row[1],
|
|
482
|
+
name: row[2],
|
|
483
|
+
jobTitle: row[3],
|
|
484
|
+
avatarUrl: row[4],
|
|
485
|
+
preferences: row[5],
|
|
486
|
+
status: row[6],
|
|
487
|
+
createdAt: row[7],
|
|
488
|
+
updatedAt: row[8]
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
exports.getPrincipalByExternalIdentityQuery = `-- name: GetPrincipalByExternalIdentity :one
|
|
492
|
+
SELECT
|
|
493
|
+
o.id AS organization_id,
|
|
494
|
+
o.slug AS organization_slug,
|
|
495
|
+
o.name AS organization_name,
|
|
496
|
+
o.status AS organization_status,
|
|
497
|
+
u.id AS user_id,
|
|
498
|
+
u.email AS user_email,
|
|
499
|
+
u.name AS user_name,
|
|
500
|
+
u.job_title AS user_job_title,
|
|
501
|
+
u.avatar_url AS user_avatar_url,
|
|
502
|
+
u.preferences AS user_preferences,
|
|
503
|
+
u.status AS user_status,
|
|
504
|
+
om.id AS organization_membership_id,
|
|
505
|
+
om.role AS organization_membership_role,
|
|
506
|
+
om.status AS organization_membership_status,
|
|
507
|
+
oil.id AS organization_identity_link_id,
|
|
508
|
+
uil.id AS user_identity_link_id
|
|
509
|
+
FROM weave.organization_identity_link oil
|
|
510
|
+
JOIN weave.organization o
|
|
511
|
+
ON o.id = oil.organization_id
|
|
512
|
+
JOIN weave.user_identity_link uil
|
|
513
|
+
ON uil.organization_identity_link_id = oil.id
|
|
514
|
+
JOIN weave.user u
|
|
515
|
+
ON u.id = uil.user_id
|
|
516
|
+
JOIN weave.organization_membership om
|
|
517
|
+
ON om.organization_id = o.id
|
|
518
|
+
AND om.user_id = u.id
|
|
519
|
+
WHERE oil.auth_provider = $1
|
|
520
|
+
AND oil.external_organization_id = $2
|
|
521
|
+
AND uil.external_subject_id = $3`;
|
|
522
|
+
async function getPrincipalByExternalIdentity(client, args) {
|
|
523
|
+
const result = await client.query({
|
|
524
|
+
text: exports.getPrincipalByExternalIdentityQuery,
|
|
525
|
+
values: [args.authProvider, args.externalOrganizationId, args.externalSubjectId],
|
|
526
|
+
rowMode: "array"
|
|
527
|
+
});
|
|
528
|
+
if (result.rows.length !== 1) {
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
const row = result.rows[0];
|
|
532
|
+
return {
|
|
533
|
+
organizationId: row[0],
|
|
534
|
+
organizationSlug: row[1],
|
|
535
|
+
organizationName: row[2],
|
|
536
|
+
organizationStatus: row[3],
|
|
537
|
+
userId: row[4],
|
|
538
|
+
userEmail: row[5],
|
|
539
|
+
userName: row[6],
|
|
540
|
+
userJobTitle: row[7],
|
|
541
|
+
userAvatarUrl: row[8],
|
|
542
|
+
userPreferences: row[9],
|
|
543
|
+
userStatus: row[10],
|
|
544
|
+
organizationMembershipId: row[11],
|
|
545
|
+
organizationMembershipRole: row[12],
|
|
546
|
+
organizationMembershipStatus: row[13],
|
|
547
|
+
organizationIdentityLinkId: row[14],
|
|
548
|
+
userIdentityLinkId: row[15]
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
exports.upsertUserIdentityLinkQuery = `-- name: UpsertUserIdentityLink :one
|
|
552
|
+
INSERT INTO weave.user_identity_link (
|
|
553
|
+
user_id,
|
|
554
|
+
organization_identity_link_id,
|
|
555
|
+
external_subject_id,
|
|
556
|
+
last_seen_at
|
|
557
|
+
) VALUES (
|
|
558
|
+
$1,
|
|
559
|
+
$2,
|
|
560
|
+
$3,
|
|
561
|
+
now()
|
|
562
|
+
)
|
|
563
|
+
ON CONFLICT (organization_identity_link_id, external_subject_id)
|
|
564
|
+
DO UPDATE SET
|
|
565
|
+
user_id = EXCLUDED.user_id,
|
|
566
|
+
last_seen_at = EXCLUDED.last_seen_at
|
|
567
|
+
RETURNING id, user_id, organization_identity_link_id, external_subject_id, last_seen_at, created_at, updated_at`;
|
|
568
|
+
async function upsertUserIdentityLink(client, args) {
|
|
569
|
+
const result = await client.query({
|
|
570
|
+
text: exports.upsertUserIdentityLinkQuery,
|
|
571
|
+
values: [args.userId, args.organizationIdentityLinkId, args.externalSubjectId],
|
|
572
|
+
rowMode: "array"
|
|
573
|
+
});
|
|
574
|
+
if (result.rows.length !== 1) {
|
|
575
|
+
return null;
|
|
576
|
+
}
|
|
577
|
+
const row = result.rows[0];
|
|
578
|
+
return {
|
|
579
|
+
id: row[0],
|
|
580
|
+
userId: row[1],
|
|
581
|
+
organizationIdentityLinkId: row[2],
|
|
582
|
+
externalSubjectId: row[3],
|
|
583
|
+
lastSeenAt: row[4],
|
|
584
|
+
createdAt: row[5],
|
|
585
|
+
updatedAt: row[6]
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
exports.upsertOrganizationMembershipQuery = `-- name: UpsertOrganizationMembership :one
|
|
589
|
+
INSERT INTO weave.organization_membership (
|
|
590
|
+
organization_id,
|
|
591
|
+
user_id,
|
|
592
|
+
status,
|
|
593
|
+
role
|
|
594
|
+
) VALUES (
|
|
595
|
+
$1,
|
|
596
|
+
$2,
|
|
597
|
+
COALESCE($3::text, 'active'),
|
|
598
|
+
COALESCE($4::text, 'member')
|
|
599
|
+
)
|
|
600
|
+
ON CONFLICT (user_id, organization_id)
|
|
601
|
+
DO UPDATE SET
|
|
602
|
+
status = EXCLUDED.status,
|
|
603
|
+
role = EXCLUDED.role
|
|
604
|
+
RETURNING id, organization_id, user_id, status, role, created_at, updated_at`;
|
|
605
|
+
async function upsertOrganizationMembership(client, args) {
|
|
606
|
+
const result = await client.query({
|
|
607
|
+
text: exports.upsertOrganizationMembershipQuery,
|
|
608
|
+
values: [args.organizationId, args.userId, args.status, args.role],
|
|
609
|
+
rowMode: "array"
|
|
610
|
+
});
|
|
611
|
+
if (result.rows.length !== 1) {
|
|
612
|
+
return null;
|
|
613
|
+
}
|
|
614
|
+
const row = result.rows[0];
|
|
615
|
+
return {
|
|
616
|
+
id: row[0],
|
|
617
|
+
organizationId: row[1],
|
|
618
|
+
userId: row[2],
|
|
619
|
+
status: row[3],
|
|
620
|
+
role: row[4],
|
|
621
|
+
createdAt: row[5],
|
|
622
|
+
updatedAt: row[6]
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
exports.getOrganizationMembershipQuery = `-- name: GetOrganizationMembership :one
|
|
626
|
+
SELECT id, organization_id, user_id, status, role, created_at, updated_at
|
|
627
|
+
FROM weave.organization_membership
|
|
628
|
+
WHERE organization_id = $1
|
|
629
|
+
AND user_id = $2`;
|
|
630
|
+
async function getOrganizationMembership(client, args) {
|
|
631
|
+
const result = await client.query({
|
|
632
|
+
text: exports.getOrganizationMembershipQuery,
|
|
633
|
+
values: [args.organizationId, args.userId],
|
|
634
|
+
rowMode: "array"
|
|
635
|
+
});
|
|
636
|
+
if (result.rows.length !== 1) {
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
const row = result.rows[0];
|
|
640
|
+
return {
|
|
641
|
+
id: row[0],
|
|
642
|
+
organizationId: row[1],
|
|
643
|
+
userId: row[2],
|
|
644
|
+
status: row[3],
|
|
645
|
+
role: row[4],
|
|
646
|
+
createdAt: row[5],
|
|
647
|
+
updatedAt: row[6]
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
exports.getOrganizationMemberQuery = `-- name: GetOrganizationMember :one
|
|
651
|
+
SELECT
|
|
652
|
+
om.id,
|
|
653
|
+
om.organization_id,
|
|
654
|
+
om.user_id,
|
|
655
|
+
om.status,
|
|
656
|
+
om.role,
|
|
657
|
+
om.created_at,
|
|
658
|
+
om.updated_at,
|
|
659
|
+
u.email,
|
|
660
|
+
u.name,
|
|
661
|
+
u.job_title,
|
|
662
|
+
u.avatar_url
|
|
663
|
+
FROM weave.organization_membership om
|
|
664
|
+
JOIN weave.user u
|
|
665
|
+
ON u.id = om.user_id
|
|
666
|
+
WHERE om.organization_id = $1
|
|
667
|
+
AND om.id = $2`;
|
|
668
|
+
async function getOrganizationMember(client, args) {
|
|
669
|
+
const result = await client.query({
|
|
670
|
+
text: exports.getOrganizationMemberQuery,
|
|
671
|
+
values: [args.organizationId, args.organizationMembershipId],
|
|
672
|
+
rowMode: "array"
|
|
673
|
+
});
|
|
674
|
+
if (result.rows.length !== 1) {
|
|
675
|
+
return null;
|
|
676
|
+
}
|
|
677
|
+
const row = result.rows[0];
|
|
678
|
+
return {
|
|
679
|
+
id: row[0],
|
|
680
|
+
organizationId: row[1],
|
|
681
|
+
userId: row[2],
|
|
682
|
+
status: row[3],
|
|
683
|
+
role: row[4],
|
|
684
|
+
createdAt: row[5],
|
|
685
|
+
updatedAt: row[6],
|
|
686
|
+
email: row[7],
|
|
687
|
+
name: row[8],
|
|
688
|
+
jobTitle: row[9],
|
|
689
|
+
avatarUrl: row[10]
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
exports.listOrganizationMembersQuery = `-- name: ListOrganizationMembers :many
|
|
693
|
+
SELECT
|
|
694
|
+
om.id,
|
|
695
|
+
om.organization_id,
|
|
696
|
+
om.user_id,
|
|
697
|
+
om.status,
|
|
698
|
+
om.role,
|
|
699
|
+
om.created_at,
|
|
700
|
+
om.updated_at,
|
|
701
|
+
u.email,
|
|
702
|
+
u.name,
|
|
703
|
+
u.job_title,
|
|
704
|
+
u.avatar_url
|
|
705
|
+
FROM weave.organization_membership om
|
|
706
|
+
JOIN weave.user u
|
|
707
|
+
ON u.id = om.user_id
|
|
708
|
+
WHERE om.organization_id = $1
|
|
709
|
+
AND ($2::text IS NULL OR om.status = $2::text)
|
|
710
|
+
AND (
|
|
711
|
+
COALESCE($3::text, '') = ''
|
|
712
|
+
OR u.email ILIKE '%' || $3::text || '%'
|
|
713
|
+
OR u.name ILIKE '%' || $3::text || '%'
|
|
714
|
+
)
|
|
715
|
+
ORDER BY u.email ASC, om.id ASC
|
|
716
|
+
LIMIT $5
|
|
717
|
+
OFFSET $4`;
|
|
718
|
+
async function listOrganizationMembers(client, args) {
|
|
719
|
+
const result = await client.query({
|
|
720
|
+
text: exports.listOrganizationMembersQuery,
|
|
721
|
+
values: [args.organizationId, args.statusFilter, args.search, args.offsetCount, args.limitCount],
|
|
722
|
+
rowMode: "array"
|
|
723
|
+
});
|
|
724
|
+
return result.rows.map(row => {
|
|
725
|
+
return {
|
|
726
|
+
id: row[0],
|
|
727
|
+
organizationId: row[1],
|
|
728
|
+
userId: row[2],
|
|
729
|
+
status: row[3],
|
|
730
|
+
role: row[4],
|
|
731
|
+
createdAt: row[5],
|
|
732
|
+
updatedAt: row[6],
|
|
733
|
+
email: row[7],
|
|
734
|
+
name: row[8],
|
|
735
|
+
jobTitle: row[9],
|
|
736
|
+
avatarUrl: row[10]
|
|
737
|
+
};
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
exports.updateOrganizationMembershipByIDQuery = `-- name: UpdateOrganizationMembershipByID :one
|
|
741
|
+
UPDATE weave.organization_membership
|
|
742
|
+
SET
|
|
743
|
+
status = COALESCE($1::text, status),
|
|
744
|
+
role = COALESCE($2::text, role)
|
|
745
|
+
WHERE organization_id = $3
|
|
746
|
+
AND id = $4
|
|
747
|
+
RETURNING id, organization_id, user_id, status, role, created_at, updated_at`;
|
|
748
|
+
async function updateOrganizationMembershipByID(client, args) {
|
|
749
|
+
const result = await client.query({
|
|
750
|
+
text: exports.updateOrganizationMembershipByIDQuery,
|
|
751
|
+
values: [args.status, args.role, args.organizationId, args.organizationMembershipId],
|
|
752
|
+
rowMode: "array"
|
|
753
|
+
});
|
|
754
|
+
if (result.rows.length !== 1) {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
const row = result.rows[0];
|
|
758
|
+
return {
|
|
759
|
+
id: row[0],
|
|
760
|
+
organizationId: row[1],
|
|
761
|
+
userId: row[2],
|
|
762
|
+
status: row[3],
|
|
763
|
+
role: row[4],
|
|
764
|
+
createdAt: row[5],
|
|
765
|
+
updatedAt: row[6]
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
exports.createOrganizationTeamQuery = `-- name: CreateOrganizationTeam :one
|
|
769
|
+
INSERT INTO weave.organization_team (
|
|
770
|
+
organization_id,
|
|
771
|
+
slug,
|
|
772
|
+
name,
|
|
773
|
+
description
|
|
774
|
+
) VALUES (
|
|
775
|
+
$1,
|
|
776
|
+
$2,
|
|
777
|
+
$3,
|
|
778
|
+
COALESCE($4::text, '')
|
|
779
|
+
)
|
|
780
|
+
RETURNING id, organization_id, slug, name, description, created_at, updated_at`;
|
|
781
|
+
async function createOrganizationTeam(client, args) {
|
|
782
|
+
const result = await client.query({
|
|
783
|
+
text: exports.createOrganizationTeamQuery,
|
|
784
|
+
values: [args.organizationId, args.slug, args.name, args.description],
|
|
785
|
+
rowMode: "array"
|
|
786
|
+
});
|
|
787
|
+
if (result.rows.length !== 1) {
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
const row = result.rows[0];
|
|
791
|
+
return {
|
|
792
|
+
id: row[0],
|
|
793
|
+
organizationId: row[1],
|
|
794
|
+
slug: row[2],
|
|
795
|
+
name: row[3],
|
|
796
|
+
description: row[4],
|
|
797
|
+
createdAt: row[5],
|
|
798
|
+
updatedAt: row[6]
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
exports.getOrganizationTeamQuery = `-- name: GetOrganizationTeam :one
|
|
802
|
+
SELECT id, organization_id, slug, name, description, created_at, updated_at
|
|
803
|
+
FROM weave.organization_team
|
|
804
|
+
WHERE organization_id = $1
|
|
805
|
+
AND id = $2`;
|
|
806
|
+
async function getOrganizationTeam(client, args) {
|
|
807
|
+
const result = await client.query({
|
|
808
|
+
text: exports.getOrganizationTeamQuery,
|
|
809
|
+
values: [args.organizationId, args.organizationTeamId],
|
|
810
|
+
rowMode: "array"
|
|
811
|
+
});
|
|
812
|
+
if (result.rows.length !== 1) {
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
const row = result.rows[0];
|
|
816
|
+
return {
|
|
817
|
+
id: row[0],
|
|
818
|
+
organizationId: row[1],
|
|
819
|
+
slug: row[2],
|
|
820
|
+
name: row[3],
|
|
821
|
+
description: row[4],
|
|
822
|
+
createdAt: row[5],
|
|
823
|
+
updatedAt: row[6]
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
exports.listOrganizationTeamsQuery = `-- name: ListOrganizationTeams :many
|
|
827
|
+
SELECT id, organization_id, slug, name, description, created_at, updated_at
|
|
828
|
+
FROM weave.organization_team
|
|
829
|
+
WHERE organization_id = $1
|
|
830
|
+
ORDER BY name ASC, slug ASC, id ASC`;
|
|
831
|
+
async function listOrganizationTeams(client, args) {
|
|
832
|
+
const result = await client.query({
|
|
833
|
+
text: exports.listOrganizationTeamsQuery,
|
|
834
|
+
values: [args.organizationId],
|
|
835
|
+
rowMode: "array"
|
|
836
|
+
});
|
|
837
|
+
return result.rows.map(row => {
|
|
838
|
+
return {
|
|
839
|
+
id: row[0],
|
|
840
|
+
organizationId: row[1],
|
|
841
|
+
slug: row[2],
|
|
842
|
+
name: row[3],
|
|
843
|
+
description: row[4],
|
|
844
|
+
createdAt: row[5],
|
|
845
|
+
updatedAt: row[6]
|
|
846
|
+
};
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
exports.updateOrganizationTeamQuery = `-- name: UpdateOrganizationTeam :one
|
|
850
|
+
UPDATE weave.organization_team
|
|
851
|
+
SET
|
|
852
|
+
slug = $1,
|
|
853
|
+
name = $2,
|
|
854
|
+
description = COALESCE($3::text, '')
|
|
855
|
+
WHERE organization_id = $4
|
|
856
|
+
AND id = $5
|
|
857
|
+
RETURNING id, organization_id, slug, name, description, created_at, updated_at`;
|
|
858
|
+
async function updateOrganizationTeam(client, args) {
|
|
859
|
+
const result = await client.query({
|
|
860
|
+
text: exports.updateOrganizationTeamQuery,
|
|
861
|
+
values: [args.slug, args.name, args.description, args.organizationId, args.organizationTeamId],
|
|
862
|
+
rowMode: "array"
|
|
863
|
+
});
|
|
864
|
+
if (result.rows.length !== 1) {
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
867
|
+
const row = result.rows[0];
|
|
868
|
+
return {
|
|
869
|
+
id: row[0],
|
|
870
|
+
organizationId: row[1],
|
|
871
|
+
slug: row[2],
|
|
872
|
+
name: row[3],
|
|
873
|
+
description: row[4],
|
|
874
|
+
createdAt: row[5],
|
|
875
|
+
updatedAt: row[6]
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
exports.deleteOrganizationTeamQuery = `-- name: DeleteOrganizationTeam :execrows
|
|
879
|
+
DELETE FROM weave.organization_team
|
|
880
|
+
WHERE organization_id = $1
|
|
881
|
+
AND id = $2`;
|
|
882
|
+
exports.deleteOrganizationTeamMembershipsQuery = `-- name: DeleteOrganizationTeamMemberships :execrows
|
|
883
|
+
DELETE FROM weave.organization_team_membership
|
|
884
|
+
WHERE organization_id = $1
|
|
885
|
+
AND organization_team_id = $2`;
|
|
886
|
+
exports.addOrganizationTeamMembershipQuery = `-- name: AddOrganizationTeamMembership :one
|
|
887
|
+
INSERT INTO weave.organization_team_membership (
|
|
888
|
+
organization_id,
|
|
889
|
+
organization_team_id,
|
|
890
|
+
organization_membership_id,
|
|
891
|
+
user_id
|
|
892
|
+
) VALUES (
|
|
893
|
+
$1,
|
|
894
|
+
$2,
|
|
895
|
+
$3,
|
|
896
|
+
$4
|
|
897
|
+
)
|
|
898
|
+
RETURNING organization_id, organization_team_id, organization_membership_id, user_id, created_at`;
|
|
899
|
+
async function addOrganizationTeamMembership(client, args) {
|
|
900
|
+
const result = await client.query({
|
|
901
|
+
text: exports.addOrganizationTeamMembershipQuery,
|
|
902
|
+
values: [args.organizationId, args.organizationTeamId, args.organizationMembershipId, args.userId],
|
|
903
|
+
rowMode: "array"
|
|
904
|
+
});
|
|
905
|
+
if (result.rows.length !== 1) {
|
|
906
|
+
return null;
|
|
907
|
+
}
|
|
908
|
+
const row = result.rows[0];
|
|
909
|
+
return {
|
|
910
|
+
organizationId: row[0],
|
|
911
|
+
organizationTeamId: row[1],
|
|
912
|
+
organizationMembershipId: row[2],
|
|
913
|
+
userId: row[3],
|
|
914
|
+
createdAt: row[4]
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
exports.listOrganizationTeamMembersQuery = `-- name: ListOrganizationTeamMembers :many
|
|
918
|
+
SELECT
|
|
919
|
+
otm.organization_id,
|
|
920
|
+
otm.organization_team_id,
|
|
921
|
+
otm.organization_membership_id,
|
|
922
|
+
otm.user_id,
|
|
923
|
+
otm.created_at,
|
|
924
|
+
u.email,
|
|
925
|
+
u.name,
|
|
926
|
+
u.avatar_url,
|
|
927
|
+
om.status
|
|
928
|
+
FROM weave.organization_team_membership otm
|
|
929
|
+
JOIN weave.organization_membership om
|
|
930
|
+
ON om.organization_id = otm.organization_id
|
|
931
|
+
AND om.id = otm.organization_membership_id
|
|
932
|
+
AND om.user_id = otm.user_id
|
|
933
|
+
JOIN weave.user u
|
|
934
|
+
ON u.id = otm.user_id
|
|
935
|
+
WHERE otm.organization_id = $1
|
|
936
|
+
AND otm.organization_team_id = $2
|
|
937
|
+
ORDER BY u.name ASC, u.email ASC, otm.organization_membership_id ASC`;
|
|
938
|
+
async function listOrganizationTeamMembers(client, args) {
|
|
939
|
+
const result = await client.query({
|
|
940
|
+
text: exports.listOrganizationTeamMembersQuery,
|
|
941
|
+
values: [args.organizationId, args.organizationTeamId],
|
|
942
|
+
rowMode: "array"
|
|
943
|
+
});
|
|
944
|
+
return result.rows.map(row => {
|
|
945
|
+
return {
|
|
946
|
+
organizationId: row[0],
|
|
947
|
+
organizationTeamId: row[1],
|
|
948
|
+
organizationMembershipId: row[2],
|
|
949
|
+
userId: row[3],
|
|
950
|
+
createdAt: row[4],
|
|
951
|
+
email: row[5],
|
|
952
|
+
name: row[6],
|
|
953
|
+
avatarUrl: row[7],
|
|
954
|
+
status: row[8]
|
|
955
|
+
};
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
exports.deleteOrganizationTeamRoleGrantsQuery = `-- name: DeleteOrganizationTeamRoleGrants :execrows
|
|
959
|
+
DELETE FROM weave.organization_team_role_grant
|
|
960
|
+
WHERE organization_id = $1
|
|
961
|
+
AND organization_team_id = $2`;
|
|
962
|
+
exports.addOrganizationTeamRoleGrantQuery = `-- name: AddOrganizationTeamRoleGrant :one
|
|
963
|
+
INSERT INTO weave.organization_team_role_grant (
|
|
964
|
+
organization_id,
|
|
965
|
+
organization_team_id,
|
|
966
|
+
role_id
|
|
967
|
+
) VALUES (
|
|
968
|
+
$1,
|
|
969
|
+
$2,
|
|
970
|
+
$3
|
|
971
|
+
)
|
|
972
|
+
RETURNING organization_id, organization_team_id, role_id, created_at`;
|
|
973
|
+
async function addOrganizationTeamRoleGrant(client, args) {
|
|
974
|
+
const result = await client.query({
|
|
975
|
+
text: exports.addOrganizationTeamRoleGrantQuery,
|
|
976
|
+
values: [args.organizationId, args.organizationTeamId, args.roleId],
|
|
977
|
+
rowMode: "array"
|
|
978
|
+
});
|
|
979
|
+
if (result.rows.length !== 1) {
|
|
980
|
+
return null;
|
|
981
|
+
}
|
|
982
|
+
const row = result.rows[0];
|
|
983
|
+
return {
|
|
984
|
+
organizationId: row[0],
|
|
985
|
+
organizationTeamId: row[1],
|
|
986
|
+
roleId: row[2],
|
|
987
|
+
createdAt: row[3]
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
exports.listOrganizationTeamRoleGrantsQuery = `-- name: ListOrganizationTeamRoleGrants :many
|
|
991
|
+
SELECT organization_id, organization_team_id, role_id, created_at
|
|
992
|
+
FROM weave.organization_team_role_grant
|
|
993
|
+
WHERE organization_id = $1
|
|
994
|
+
AND organization_team_id = $2
|
|
995
|
+
ORDER BY role_id ASC`;
|
|
996
|
+
async function listOrganizationTeamRoleGrants(client, args) {
|
|
997
|
+
const result = await client.query({
|
|
998
|
+
text: exports.listOrganizationTeamRoleGrantsQuery,
|
|
999
|
+
values: [args.organizationId, args.organizationTeamId],
|
|
1000
|
+
rowMode: "array"
|
|
1001
|
+
});
|
|
1002
|
+
return result.rows.map(row => {
|
|
1003
|
+
return {
|
|
1004
|
+
organizationId: row[0],
|
|
1005
|
+
organizationTeamId: row[1],
|
|
1006
|
+
roleId: row[2],
|
|
1007
|
+
createdAt: row[3]
|
|
1008
|
+
};
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
exports.upsertOrganizationScimGroupMappingQuery = `-- name: UpsertOrganizationScimGroupMapping :one
|
|
1012
|
+
INSERT INTO weave.organization_scim_group_mapping (
|
|
1013
|
+
organization_id,
|
|
1014
|
+
scim_group_id,
|
|
1015
|
+
scim_group_name,
|
|
1016
|
+
mapping_status
|
|
1017
|
+
) VALUES (
|
|
1018
|
+
$1,
|
|
1019
|
+
$2,
|
|
1020
|
+
$3,
|
|
1021
|
+
COALESCE($4::text, 'unmapped')
|
|
1022
|
+
)
|
|
1023
|
+
ON CONFLICT (organization_id, scim_group_id)
|
|
1024
|
+
DO UPDATE SET
|
|
1025
|
+
scim_group_name = EXCLUDED.scim_group_name
|
|
1026
|
+
RETURNING id, organization_id, scim_group_id, scim_group_name, organization_team_id, mapping_status, created_at, updated_at`;
|
|
1027
|
+
async function upsertOrganizationScimGroupMapping(client, args) {
|
|
1028
|
+
const result = await client.query({
|
|
1029
|
+
text: exports.upsertOrganizationScimGroupMappingQuery,
|
|
1030
|
+
values: [args.organizationId, args.scimGroupId, args.scimGroupName, args.mappingStatus],
|
|
1031
|
+
rowMode: "array"
|
|
1032
|
+
});
|
|
1033
|
+
if (result.rows.length !== 1) {
|
|
1034
|
+
return null;
|
|
1035
|
+
}
|
|
1036
|
+
const row = result.rows[0];
|
|
1037
|
+
return {
|
|
1038
|
+
id: row[0],
|
|
1039
|
+
organizationId: row[1],
|
|
1040
|
+
scimGroupId: row[2],
|
|
1041
|
+
scimGroupName: row[3],
|
|
1042
|
+
organizationTeamId: row[4],
|
|
1043
|
+
mappingStatus: row[5],
|
|
1044
|
+
createdAt: row[6],
|
|
1045
|
+
updatedAt: row[7]
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
exports.listOrganizationScimGroupMappingsQuery = `-- name: ListOrganizationScimGroupMappings :many
|
|
1049
|
+
SELECT id, organization_id, scim_group_id, scim_group_name, organization_team_id, mapping_status, created_at, updated_at
|
|
1050
|
+
FROM weave.organization_scim_group_mapping
|
|
1051
|
+
WHERE organization_id = $1
|
|
1052
|
+
ORDER BY scim_group_name ASC, scim_group_id ASC, id ASC`;
|
|
1053
|
+
async function listOrganizationScimGroupMappings(client, args) {
|
|
1054
|
+
const result = await client.query({
|
|
1055
|
+
text: exports.listOrganizationScimGroupMappingsQuery,
|
|
1056
|
+
values: [args.organizationId],
|
|
1057
|
+
rowMode: "array"
|
|
1058
|
+
});
|
|
1059
|
+
return result.rows.map(row => {
|
|
1060
|
+
return {
|
|
1061
|
+
id: row[0],
|
|
1062
|
+
organizationId: row[1],
|
|
1063
|
+
scimGroupId: row[2],
|
|
1064
|
+
scimGroupName: row[3],
|
|
1065
|
+
organizationTeamId: row[4],
|
|
1066
|
+
mappingStatus: row[5],
|
|
1067
|
+
createdAt: row[6],
|
|
1068
|
+
updatedAt: row[7]
|
|
1069
|
+
};
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
exports.updateOrganizationScimGroupMappingQuery = `-- name: UpdateOrganizationScimGroupMapping :one
|
|
1073
|
+
UPDATE weave.organization_scim_group_mapping
|
|
1074
|
+
SET
|
|
1075
|
+
organization_team_id = $1,
|
|
1076
|
+
mapping_status = COALESCE($2::text, mapping_status)
|
|
1077
|
+
WHERE organization_id = $3
|
|
1078
|
+
AND id = $4
|
|
1079
|
+
RETURNING id, organization_id, scim_group_id, scim_group_name, organization_team_id, mapping_status, created_at, updated_at`;
|
|
1080
|
+
async function updateOrganizationScimGroupMapping(client, args) {
|
|
1081
|
+
const result = await client.query({
|
|
1082
|
+
text: exports.updateOrganizationScimGroupMappingQuery,
|
|
1083
|
+
values: [args.organizationTeamId, args.mappingStatus, args.organizationId, args.organizationScimGroupMappingId],
|
|
1084
|
+
rowMode: "array"
|
|
1085
|
+
});
|
|
1086
|
+
if (result.rows.length !== 1) {
|
|
1087
|
+
return null;
|
|
1088
|
+
}
|
|
1089
|
+
const row = result.rows[0];
|
|
1090
|
+
return {
|
|
1091
|
+
id: row[0],
|
|
1092
|
+
organizationId: row[1],
|
|
1093
|
+
scimGroupId: row[2],
|
|
1094
|
+
scimGroupName: row[3],
|
|
1095
|
+
organizationTeamId: row[4],
|
|
1096
|
+
mappingStatus: row[5],
|
|
1097
|
+
createdAt: row[6],
|
|
1098
|
+
updatedAt: row[7]
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
exports.getOrganizationIdentityLinkByOrganizationIDQuery = `-- name: GetOrganizationIdentityLinkByOrganizationID :one
|
|
1102
|
+
SELECT id, organization_id, auth_provider, external_organization_id, last_seen_at, created_at, updated_at
|
|
1103
|
+
FROM weave.organization_identity_link
|
|
1104
|
+
WHERE organization_id = $1
|
|
1105
|
+
AND auth_provider = $2`;
|
|
1106
|
+
async function getOrganizationIdentityLinkByOrganizationID(client, args) {
|
|
1107
|
+
const result = await client.query({
|
|
1108
|
+
text: exports.getOrganizationIdentityLinkByOrganizationIDQuery,
|
|
1109
|
+
values: [args.organizationId, args.authProvider],
|
|
1110
|
+
rowMode: "array"
|
|
1111
|
+
});
|
|
1112
|
+
if (result.rows.length !== 1) {
|
|
1113
|
+
return null;
|
|
1114
|
+
}
|
|
1115
|
+
const row = result.rows[0];
|
|
1116
|
+
return {
|
|
1117
|
+
id: row[0],
|
|
1118
|
+
organizationId: row[1],
|
|
1119
|
+
authProvider: row[2],
|
|
1120
|
+
externalOrganizationId: row[3],
|
|
1121
|
+
lastSeenAt: row[4],
|
|
1122
|
+
createdAt: row[5],
|
|
1123
|
+
updatedAt: row[6]
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
exports.createApplicationSessionQuery = `-- name: CreateApplicationSession :one
|
|
1127
|
+
INSERT INTO weave.application_session (
|
|
1128
|
+
user_id,
|
|
1129
|
+
active_organization_id,
|
|
1130
|
+
identity_link_id,
|
|
1131
|
+
external_session_id,
|
|
1132
|
+
session_token_box,
|
|
1133
|
+
last_validated_at,
|
|
1134
|
+
expires_at
|
|
1135
|
+
) VALUES (
|
|
1136
|
+
$1,
|
|
1137
|
+
$2,
|
|
1138
|
+
$3,
|
|
1139
|
+
COALESCE($4::text, ''),
|
|
1140
|
+
$5,
|
|
1141
|
+
$6,
|
|
1142
|
+
$7
|
|
1143
|
+
)
|
|
1144
|
+
RETURNING id, user_id, active_organization_id, identity_link_id, external_session_id, session_token_box, last_validated_at, status, expires_at, revoked_at, created_at, updated_at`;
|
|
1145
|
+
async function createApplicationSession(client, args) {
|
|
1146
|
+
const result = await client.query({
|
|
1147
|
+
text: exports.createApplicationSessionQuery,
|
|
1148
|
+
values: [args.userId, args.activeOrganizationId, args.identityLinkId, args.externalSessionId, args.sessionTokenBox, args.lastValidatedAt, args.expiresAt],
|
|
1149
|
+
rowMode: "array"
|
|
1150
|
+
});
|
|
1151
|
+
if (result.rows.length !== 1) {
|
|
1152
|
+
return null;
|
|
1153
|
+
}
|
|
1154
|
+
const row = result.rows[0];
|
|
1155
|
+
return {
|
|
1156
|
+
id: row[0],
|
|
1157
|
+
userId: row[1],
|
|
1158
|
+
activeOrganizationId: row[2],
|
|
1159
|
+
identityLinkId: row[3],
|
|
1160
|
+
externalSessionId: row[4],
|
|
1161
|
+
sessionTokenBox: row[5],
|
|
1162
|
+
lastValidatedAt: row[6],
|
|
1163
|
+
status: row[7],
|
|
1164
|
+
expiresAt: row[8],
|
|
1165
|
+
revokedAt: row[9],
|
|
1166
|
+
createdAt: row[10],
|
|
1167
|
+
updatedAt: row[11]
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
exports.getApplicationSessionQuery = `-- name: GetApplicationSession :one
|
|
1171
|
+
SELECT id, user_id, active_organization_id, identity_link_id, external_session_id, session_token_box, last_validated_at, status, expires_at, revoked_at, created_at, updated_at
|
|
1172
|
+
FROM weave.application_session
|
|
1173
|
+
WHERE id = $1`;
|
|
1174
|
+
async function getApplicationSession(client, args) {
|
|
1175
|
+
const result = await client.query({
|
|
1176
|
+
text: exports.getApplicationSessionQuery,
|
|
1177
|
+
values: [args.applicationSessionId],
|
|
1178
|
+
rowMode: "array"
|
|
1179
|
+
});
|
|
1180
|
+
if (result.rows.length !== 1) {
|
|
1181
|
+
return null;
|
|
1182
|
+
}
|
|
1183
|
+
const row = result.rows[0];
|
|
1184
|
+
return {
|
|
1185
|
+
id: row[0],
|
|
1186
|
+
userId: row[1],
|
|
1187
|
+
activeOrganizationId: row[2],
|
|
1188
|
+
identityLinkId: row[3],
|
|
1189
|
+
externalSessionId: row[4],
|
|
1190
|
+
sessionTokenBox: row[5],
|
|
1191
|
+
lastValidatedAt: row[6],
|
|
1192
|
+
status: row[7],
|
|
1193
|
+
expiresAt: row[8],
|
|
1194
|
+
revokedAt: row[9],
|
|
1195
|
+
createdAt: row[10],
|
|
1196
|
+
updatedAt: row[11]
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
exports.getPrincipalByApplicationSessionQuery = `-- name: GetPrincipalByApplicationSession :one
|
|
1200
|
+
SELECT
|
|
1201
|
+
s.id AS application_session_id,
|
|
1202
|
+
s.status AS application_session_status,
|
|
1203
|
+
s.expires_at AS application_session_expires_at,
|
|
1204
|
+
s.identity_link_id AS application_session_identity_link_id,
|
|
1205
|
+
s.external_session_id AS application_session_external_session_id,
|
|
1206
|
+
s.session_token_box AS application_session_token_box,
|
|
1207
|
+
o.id AS organization_id,
|
|
1208
|
+
o.slug AS organization_slug,
|
|
1209
|
+
o.name AS organization_name,
|
|
1210
|
+
o.status AS organization_status,
|
|
1211
|
+
u.id AS user_id,
|
|
1212
|
+
u.email AS user_email,
|
|
1213
|
+
u.name AS user_name,
|
|
1214
|
+
u.job_title AS user_job_title,
|
|
1215
|
+
u.avatar_url AS user_avatar_url,
|
|
1216
|
+
u.preferences AS user_preferences,
|
|
1217
|
+
u.status AS user_status,
|
|
1218
|
+
om.id AS organization_membership_id,
|
|
1219
|
+
om.role AS organization_membership_role,
|
|
1220
|
+
om.status AS organization_membership_status
|
|
1221
|
+
FROM weave.application_session s
|
|
1222
|
+
JOIN weave.organization o
|
|
1223
|
+
ON o.id = s.active_organization_id
|
|
1224
|
+
JOIN weave.user u
|
|
1225
|
+
ON u.id = s.user_id
|
|
1226
|
+
JOIN weave.organization_membership om
|
|
1227
|
+
ON om.organization_id = o.id
|
|
1228
|
+
AND om.user_id = u.id
|
|
1229
|
+
WHERE s.id = $1`;
|
|
1230
|
+
async function getPrincipalByApplicationSession(client, args) {
|
|
1231
|
+
const result = await client.query({
|
|
1232
|
+
text: exports.getPrincipalByApplicationSessionQuery,
|
|
1233
|
+
values: [args.applicationSessionId],
|
|
1234
|
+
rowMode: "array"
|
|
1235
|
+
});
|
|
1236
|
+
if (result.rows.length !== 1) {
|
|
1237
|
+
return null;
|
|
1238
|
+
}
|
|
1239
|
+
const row = result.rows[0];
|
|
1240
|
+
return {
|
|
1241
|
+
applicationSessionId: row[0],
|
|
1242
|
+
applicationSessionStatus: row[1],
|
|
1243
|
+
applicationSessionExpiresAt: row[2],
|
|
1244
|
+
applicationSessionIdentityLinkId: row[3],
|
|
1245
|
+
applicationSessionExternalSessionId: row[4],
|
|
1246
|
+
applicationSessionTokenBox: row[5],
|
|
1247
|
+
organizationId: row[6],
|
|
1248
|
+
organizationSlug: row[7],
|
|
1249
|
+
organizationName: row[8],
|
|
1250
|
+
organizationStatus: row[9],
|
|
1251
|
+
userId: row[10],
|
|
1252
|
+
userEmail: row[11],
|
|
1253
|
+
userName: row[12],
|
|
1254
|
+
userJobTitle: row[13],
|
|
1255
|
+
userAvatarUrl: row[14],
|
|
1256
|
+
userPreferences: row[15],
|
|
1257
|
+
userStatus: row[16],
|
|
1258
|
+
organizationMembershipId: row[17],
|
|
1259
|
+
organizationMembershipRole: row[18],
|
|
1260
|
+
organizationMembershipStatus: row[19]
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
exports.updateApplicationSessionOrganizationQuery = `-- name: UpdateApplicationSessionOrganization :one
|
|
1264
|
+
UPDATE weave.application_session
|
|
1265
|
+
SET
|
|
1266
|
+
active_organization_id = $1,
|
|
1267
|
+
identity_link_id = $2,
|
|
1268
|
+
external_session_id = COALESCE($3::text, ''),
|
|
1269
|
+
session_token_box = $4,
|
|
1270
|
+
last_validated_at = $5
|
|
1271
|
+
WHERE id = $6
|
|
1272
|
+
AND user_id = $7
|
|
1273
|
+
AND status = 'active'
|
|
1274
|
+
RETURNING id, user_id, active_organization_id, identity_link_id, external_session_id, session_token_box, last_validated_at, status, expires_at, revoked_at, created_at, updated_at`;
|
|
1275
|
+
async function updateApplicationSessionOrganization(client, args) {
|
|
1276
|
+
const result = await client.query({
|
|
1277
|
+
text: exports.updateApplicationSessionOrganizationQuery,
|
|
1278
|
+
values: [args.activeOrganizationId, args.identityLinkId, args.externalSessionId, args.sessionTokenBox, args.lastValidatedAt, args.applicationSessionId, args.userId],
|
|
1279
|
+
rowMode: "array"
|
|
1280
|
+
});
|
|
1281
|
+
if (result.rows.length !== 1) {
|
|
1282
|
+
return null;
|
|
1283
|
+
}
|
|
1284
|
+
const row = result.rows[0];
|
|
1285
|
+
return {
|
|
1286
|
+
id: row[0],
|
|
1287
|
+
userId: row[1],
|
|
1288
|
+
activeOrganizationId: row[2],
|
|
1289
|
+
identityLinkId: row[3],
|
|
1290
|
+
externalSessionId: row[4],
|
|
1291
|
+
sessionTokenBox: row[5],
|
|
1292
|
+
lastValidatedAt: row[6],
|
|
1293
|
+
status: row[7],
|
|
1294
|
+
expiresAt: row[8],
|
|
1295
|
+
revokedAt: row[9],
|
|
1296
|
+
createdAt: row[10],
|
|
1297
|
+
updatedAt: row[11]
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
exports.revokeApplicationSessionQuery = `-- name: RevokeApplicationSession :execrows
|
|
1301
|
+
UPDATE weave.application_session
|
|
1302
|
+
SET
|
|
1303
|
+
status = 'revoked',
|
|
1304
|
+
revoked_at = now()
|
|
1305
|
+
WHERE id = $1
|
|
1306
|
+
AND status = 'active'`;
|
|
1307
|
+
exports.deleteExpiredApplicationSessionsQuery = `-- name: DeleteExpiredApplicationSessions :execrows
|
|
1308
|
+
DELETE FROM weave.application_session
|
|
1309
|
+
WHERE expires_at <= now()
|
|
1310
|
+
OR status IN ('revoked', 'expired')`;
|
|
1311
|
+
exports.createAuthInviteSessionQuery = `-- name: CreateAuthInviteSession :one
|
|
1312
|
+
INSERT INTO weave.auth_invite_session (
|
|
1313
|
+
organization_id,
|
|
1314
|
+
user_id,
|
|
1315
|
+
organization_membership_id,
|
|
1316
|
+
organization_identity_link_id,
|
|
1317
|
+
external_subject_id,
|
|
1318
|
+
session_token_box,
|
|
1319
|
+
email,
|
|
1320
|
+
name,
|
|
1321
|
+
status,
|
|
1322
|
+
recovery_reason,
|
|
1323
|
+
recovery_hint,
|
|
1324
|
+
expires_at
|
|
1325
|
+
) VALUES (
|
|
1326
|
+
$1,
|
|
1327
|
+
$2,
|
|
1328
|
+
$3,
|
|
1329
|
+
$4,
|
|
1330
|
+
$5,
|
|
1331
|
+
$6,
|
|
1332
|
+
$7,
|
|
1333
|
+
$8,
|
|
1334
|
+
COALESCE($9::text, 'ready'),
|
|
1335
|
+
COALESCE($10::text, ''),
|
|
1336
|
+
COALESCE($11::text, ''),
|
|
1337
|
+
$12
|
|
1338
|
+
)
|
|
1339
|
+
RETURNING id, organization_id, user_id, organization_membership_id, organization_identity_link_id, external_subject_id, session_token_box, email, name, status, recovery_reason, recovery_hint, oauth_provider, oauth_state, oauth_return_url, expires_at, completed_at, revoked_at, created_at, updated_at`;
|
|
1340
|
+
async function createAuthInviteSession(client, args) {
|
|
1341
|
+
const result = await client.query({
|
|
1342
|
+
text: exports.createAuthInviteSessionQuery,
|
|
1343
|
+
values: [args.organizationId, args.userId, args.organizationMembershipId, args.organizationIdentityLinkId, args.externalSubjectId, args.sessionTokenBox, args.email, args.name, args.status, args.recoveryReason, args.recoveryHint, args.expiresAt],
|
|
1344
|
+
rowMode: "array"
|
|
1345
|
+
});
|
|
1346
|
+
if (result.rows.length !== 1) {
|
|
1347
|
+
return null;
|
|
1348
|
+
}
|
|
1349
|
+
const row = result.rows[0];
|
|
1350
|
+
return {
|
|
1351
|
+
id: row[0],
|
|
1352
|
+
organizationId: row[1],
|
|
1353
|
+
userId: row[2],
|
|
1354
|
+
organizationMembershipId: row[3],
|
|
1355
|
+
organizationIdentityLinkId: row[4],
|
|
1356
|
+
externalSubjectId: row[5],
|
|
1357
|
+
sessionTokenBox: row[6],
|
|
1358
|
+
email: row[7],
|
|
1359
|
+
name: row[8],
|
|
1360
|
+
status: row[9],
|
|
1361
|
+
recoveryReason: row[10],
|
|
1362
|
+
recoveryHint: row[11],
|
|
1363
|
+
oauthProvider: row[12],
|
|
1364
|
+
oauthState: row[13],
|
|
1365
|
+
oauthReturnUrl: row[14],
|
|
1366
|
+
expiresAt: row[15],
|
|
1367
|
+
completedAt: row[16],
|
|
1368
|
+
revokedAt: row[17],
|
|
1369
|
+
createdAt: row[18],
|
|
1370
|
+
updatedAt: row[19]
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
exports.updateAuthInviteSessionTokenQuery = `-- name: UpdateAuthInviteSessionToken :one
|
|
1374
|
+
UPDATE weave.auth_invite_session
|
|
1375
|
+
SET session_token_box = $1
|
|
1376
|
+
WHERE id = $2
|
|
1377
|
+
AND status <> 'completed'
|
|
1378
|
+
AND status <> 'revoked'
|
|
1379
|
+
RETURNING id, organization_id, user_id, organization_membership_id, organization_identity_link_id, external_subject_id, session_token_box, email, name, status, recovery_reason, recovery_hint, oauth_provider, oauth_state, oauth_return_url, expires_at, completed_at, revoked_at, created_at, updated_at`;
|
|
1380
|
+
async function updateAuthInviteSessionToken(client, args) {
|
|
1381
|
+
const result = await client.query({
|
|
1382
|
+
text: exports.updateAuthInviteSessionTokenQuery,
|
|
1383
|
+
values: [args.sessionTokenBox, args.authInviteSessionId],
|
|
1384
|
+
rowMode: "array"
|
|
1385
|
+
});
|
|
1386
|
+
if (result.rows.length !== 1) {
|
|
1387
|
+
return null;
|
|
1388
|
+
}
|
|
1389
|
+
const row = result.rows[0];
|
|
1390
|
+
return {
|
|
1391
|
+
id: row[0],
|
|
1392
|
+
organizationId: row[1],
|
|
1393
|
+
userId: row[2],
|
|
1394
|
+
organizationMembershipId: row[3],
|
|
1395
|
+
organizationIdentityLinkId: row[4],
|
|
1396
|
+
externalSubjectId: row[5],
|
|
1397
|
+
sessionTokenBox: row[6],
|
|
1398
|
+
email: row[7],
|
|
1399
|
+
name: row[8],
|
|
1400
|
+
status: row[9],
|
|
1401
|
+
recoveryReason: row[10],
|
|
1402
|
+
recoveryHint: row[11],
|
|
1403
|
+
oauthProvider: row[12],
|
|
1404
|
+
oauthState: row[13],
|
|
1405
|
+
oauthReturnUrl: row[14],
|
|
1406
|
+
expiresAt: row[15],
|
|
1407
|
+
completedAt: row[16],
|
|
1408
|
+
revokedAt: row[17],
|
|
1409
|
+
createdAt: row[18],
|
|
1410
|
+
updatedAt: row[19]
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1413
|
+
exports.getAuthInviteSessionQuery = `-- name: GetAuthInviteSession :one
|
|
1414
|
+
SELECT id, organization_id, user_id, organization_membership_id, organization_identity_link_id, external_subject_id, session_token_box, email, name, status, recovery_reason, recovery_hint, oauth_provider, oauth_state, oauth_return_url, expires_at, completed_at, revoked_at, created_at, updated_at
|
|
1415
|
+
FROM weave.auth_invite_session
|
|
1416
|
+
WHERE id = $1`;
|
|
1417
|
+
async function getAuthInviteSession(client, args) {
|
|
1418
|
+
const result = await client.query({
|
|
1419
|
+
text: exports.getAuthInviteSessionQuery,
|
|
1420
|
+
values: [args.authInviteSessionId],
|
|
1421
|
+
rowMode: "array"
|
|
1422
|
+
});
|
|
1423
|
+
if (result.rows.length !== 1) {
|
|
1424
|
+
return null;
|
|
1425
|
+
}
|
|
1426
|
+
const row = result.rows[0];
|
|
1427
|
+
return {
|
|
1428
|
+
id: row[0],
|
|
1429
|
+
organizationId: row[1],
|
|
1430
|
+
userId: row[2],
|
|
1431
|
+
organizationMembershipId: row[3],
|
|
1432
|
+
organizationIdentityLinkId: row[4],
|
|
1433
|
+
externalSubjectId: row[5],
|
|
1434
|
+
sessionTokenBox: row[6],
|
|
1435
|
+
email: row[7],
|
|
1436
|
+
name: row[8],
|
|
1437
|
+
status: row[9],
|
|
1438
|
+
recoveryReason: row[10],
|
|
1439
|
+
recoveryHint: row[11],
|
|
1440
|
+
oauthProvider: row[12],
|
|
1441
|
+
oauthState: row[13],
|
|
1442
|
+
oauthReturnUrl: row[14],
|
|
1443
|
+
expiresAt: row[15],
|
|
1444
|
+
completedAt: row[16],
|
|
1445
|
+
revokedAt: row[17],
|
|
1446
|
+
createdAt: row[18],
|
|
1447
|
+
updatedAt: row[19]
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
exports.getAuthInviteSessionByMembershipQuery = `-- name: GetAuthInviteSessionByMembership :one
|
|
1451
|
+
SELECT id, organization_id, user_id, organization_membership_id, organization_identity_link_id, external_subject_id, session_token_box, email, name, status, recovery_reason, recovery_hint, oauth_provider, oauth_state, oauth_return_url, expires_at, completed_at, revoked_at, created_at, updated_at
|
|
1452
|
+
FROM weave.auth_invite_session
|
|
1453
|
+
WHERE organization_id = $1
|
|
1454
|
+
AND organization_membership_id = $2
|
|
1455
|
+
AND status <> 'completed'
|
|
1456
|
+
ORDER BY created_at DESC
|
|
1457
|
+
LIMIT 1`;
|
|
1458
|
+
async function getAuthInviteSessionByMembership(client, args) {
|
|
1459
|
+
const result = await client.query({
|
|
1460
|
+
text: exports.getAuthInviteSessionByMembershipQuery,
|
|
1461
|
+
values: [args.organizationId, args.organizationMembershipId],
|
|
1462
|
+
rowMode: "array"
|
|
1463
|
+
});
|
|
1464
|
+
if (result.rows.length !== 1) {
|
|
1465
|
+
return null;
|
|
1466
|
+
}
|
|
1467
|
+
const row = result.rows[0];
|
|
1468
|
+
return {
|
|
1469
|
+
id: row[0],
|
|
1470
|
+
organizationId: row[1],
|
|
1471
|
+
userId: row[2],
|
|
1472
|
+
organizationMembershipId: row[3],
|
|
1473
|
+
organizationIdentityLinkId: row[4],
|
|
1474
|
+
externalSubjectId: row[5],
|
|
1475
|
+
sessionTokenBox: row[6],
|
|
1476
|
+
email: row[7],
|
|
1477
|
+
name: row[8],
|
|
1478
|
+
status: row[9],
|
|
1479
|
+
recoveryReason: row[10],
|
|
1480
|
+
recoveryHint: row[11],
|
|
1481
|
+
oauthProvider: row[12],
|
|
1482
|
+
oauthState: row[13],
|
|
1483
|
+
oauthReturnUrl: row[14],
|
|
1484
|
+
expiresAt: row[15],
|
|
1485
|
+
completedAt: row[16],
|
|
1486
|
+
revokedAt: row[17],
|
|
1487
|
+
createdAt: row[18],
|
|
1488
|
+
updatedAt: row[19]
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
exports.updateAuthInviteSessionOAuthQuery = `-- name: UpdateAuthInviteSessionOAuth :one
|
|
1492
|
+
UPDATE weave.auth_invite_session
|
|
1493
|
+
SET
|
|
1494
|
+
oauth_provider = $1,
|
|
1495
|
+
oauth_state = $2,
|
|
1496
|
+
oauth_return_url = $3
|
|
1497
|
+
WHERE id = $4
|
|
1498
|
+
AND status <> 'completed'
|
|
1499
|
+
AND status <> 'revoked'
|
|
1500
|
+
RETURNING id, organization_id, user_id, organization_membership_id, organization_identity_link_id, external_subject_id, session_token_box, email, name, status, recovery_reason, recovery_hint, oauth_provider, oauth_state, oauth_return_url, expires_at, completed_at, revoked_at, created_at, updated_at`;
|
|
1501
|
+
async function updateAuthInviteSessionOAuth(client, args) {
|
|
1502
|
+
const result = await client.query({
|
|
1503
|
+
text: exports.updateAuthInviteSessionOAuthQuery,
|
|
1504
|
+
values: [args.oauthProvider, args.oauthState, args.oauthReturnUrl, args.authInviteSessionId],
|
|
1505
|
+
rowMode: "array"
|
|
1506
|
+
});
|
|
1507
|
+
if (result.rows.length !== 1) {
|
|
1508
|
+
return null;
|
|
1509
|
+
}
|
|
1510
|
+
const row = result.rows[0];
|
|
1511
|
+
return {
|
|
1512
|
+
id: row[0],
|
|
1513
|
+
organizationId: row[1],
|
|
1514
|
+
userId: row[2],
|
|
1515
|
+
organizationMembershipId: row[3],
|
|
1516
|
+
organizationIdentityLinkId: row[4],
|
|
1517
|
+
externalSubjectId: row[5],
|
|
1518
|
+
sessionTokenBox: row[6],
|
|
1519
|
+
email: row[7],
|
|
1520
|
+
name: row[8],
|
|
1521
|
+
status: row[9],
|
|
1522
|
+
recoveryReason: row[10],
|
|
1523
|
+
recoveryHint: row[11],
|
|
1524
|
+
oauthProvider: row[12],
|
|
1525
|
+
oauthState: row[13],
|
|
1526
|
+
oauthReturnUrl: row[14],
|
|
1527
|
+
expiresAt: row[15],
|
|
1528
|
+
completedAt: row[16],
|
|
1529
|
+
revokedAt: row[17],
|
|
1530
|
+
createdAt: row[18],
|
|
1531
|
+
updatedAt: row[19]
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
exports.completeAuthInviteSessionQuery = `-- name: CompleteAuthInviteSession :one
|
|
1535
|
+
UPDATE weave.auth_invite_session
|
|
1536
|
+
SET
|
|
1537
|
+
status = 'completed',
|
|
1538
|
+
completed_at = now()
|
|
1539
|
+
WHERE id = $1
|
|
1540
|
+
AND status <> 'completed'
|
|
1541
|
+
AND status <> 'revoked'
|
|
1542
|
+
RETURNING id, organization_id, user_id, organization_membership_id, organization_identity_link_id, external_subject_id, session_token_box, email, name, status, recovery_reason, recovery_hint, oauth_provider, oauth_state, oauth_return_url, expires_at, completed_at, revoked_at, created_at, updated_at`;
|
|
1543
|
+
async function completeAuthInviteSession(client, args) {
|
|
1544
|
+
const result = await client.query({
|
|
1545
|
+
text: exports.completeAuthInviteSessionQuery,
|
|
1546
|
+
values: [args.authInviteSessionId],
|
|
1547
|
+
rowMode: "array"
|
|
1548
|
+
});
|
|
1549
|
+
if (result.rows.length !== 1) {
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
const row = result.rows[0];
|
|
1553
|
+
return {
|
|
1554
|
+
id: row[0],
|
|
1555
|
+
organizationId: row[1],
|
|
1556
|
+
userId: row[2],
|
|
1557
|
+
organizationMembershipId: row[3],
|
|
1558
|
+
organizationIdentityLinkId: row[4],
|
|
1559
|
+
externalSubjectId: row[5],
|
|
1560
|
+
sessionTokenBox: row[6],
|
|
1561
|
+
email: row[7],
|
|
1562
|
+
name: row[8],
|
|
1563
|
+
status: row[9],
|
|
1564
|
+
recoveryReason: row[10],
|
|
1565
|
+
recoveryHint: row[11],
|
|
1566
|
+
oauthProvider: row[12],
|
|
1567
|
+
oauthState: row[13],
|
|
1568
|
+
oauthReturnUrl: row[14],
|
|
1569
|
+
expiresAt: row[15],
|
|
1570
|
+
completedAt: row[16],
|
|
1571
|
+
revokedAt: row[17],
|
|
1572
|
+
createdAt: row[18],
|
|
1573
|
+
updatedAt: row[19]
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
exports.revokeAuthInviteSessionQuery = `-- name: RevokeAuthInviteSession :one
|
|
1577
|
+
UPDATE weave.auth_invite_session
|
|
1578
|
+
SET
|
|
1579
|
+
status = 'revoked',
|
|
1580
|
+
revoked_at = now()
|
|
1581
|
+
WHERE id = $1
|
|
1582
|
+
AND status <> 'completed'
|
|
1583
|
+
AND status <> 'revoked'
|
|
1584
|
+
RETURNING id, organization_id, user_id, organization_membership_id, organization_identity_link_id, external_subject_id, session_token_box, email, name, status, recovery_reason, recovery_hint, oauth_provider, oauth_state, oauth_return_url, expires_at, completed_at, revoked_at, created_at, updated_at`;
|
|
1585
|
+
async function revokeAuthInviteSession(client, args) {
|
|
1586
|
+
const result = await client.query({
|
|
1587
|
+
text: exports.revokeAuthInviteSessionQuery,
|
|
1588
|
+
values: [args.authInviteSessionId],
|
|
1589
|
+
rowMode: "array"
|
|
1590
|
+
});
|
|
1591
|
+
if (result.rows.length !== 1) {
|
|
1592
|
+
return null;
|
|
1593
|
+
}
|
|
1594
|
+
const row = result.rows[0];
|
|
1595
|
+
return {
|
|
1596
|
+
id: row[0],
|
|
1597
|
+
organizationId: row[1],
|
|
1598
|
+
userId: row[2],
|
|
1599
|
+
organizationMembershipId: row[3],
|
|
1600
|
+
organizationIdentityLinkId: row[4],
|
|
1601
|
+
externalSubjectId: row[5],
|
|
1602
|
+
sessionTokenBox: row[6],
|
|
1603
|
+
email: row[7],
|
|
1604
|
+
name: row[8],
|
|
1605
|
+
status: row[9],
|
|
1606
|
+
recoveryReason: row[10],
|
|
1607
|
+
recoveryHint: row[11],
|
|
1608
|
+
oauthProvider: row[12],
|
|
1609
|
+
oauthState: row[13],
|
|
1610
|
+
oauthReturnUrl: row[14],
|
|
1611
|
+
expiresAt: row[15],
|
|
1612
|
+
completedAt: row[16],
|
|
1613
|
+
revokedAt: row[17],
|
|
1614
|
+
createdAt: row[18],
|
|
1615
|
+
updatedAt: row[19]
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
exports.createPersonalAccessTokenQuery = `-- name: CreatePersonalAccessToken :one
|
|
1619
|
+
INSERT INTO weave.personal_access_token (
|
|
1620
|
+
organization_id,
|
|
1621
|
+
user_id,
|
|
1622
|
+
name,
|
|
1623
|
+
token_hash,
|
|
1624
|
+
expires_at
|
|
1625
|
+
) VALUES (
|
|
1626
|
+
$1,
|
|
1627
|
+
$2,
|
|
1628
|
+
$3,
|
|
1629
|
+
$4,
|
|
1630
|
+
$5
|
|
1631
|
+
)
|
|
1632
|
+
RETURNING id, organization_id, user_id, name, token_hash, status, expires_at, last_used_at, revoked_at, created_at, updated_at`;
|
|
1633
|
+
async function createPersonalAccessToken(client, args) {
|
|
1634
|
+
const result = await client.query({
|
|
1635
|
+
text: exports.createPersonalAccessTokenQuery,
|
|
1636
|
+
values: [args.organizationId, args.userId, args.name, args.tokenHash, args.expiresAt],
|
|
1637
|
+
rowMode: "array"
|
|
1638
|
+
});
|
|
1639
|
+
if (result.rows.length !== 1) {
|
|
1640
|
+
return null;
|
|
1641
|
+
}
|
|
1642
|
+
const row = result.rows[0];
|
|
1643
|
+
return {
|
|
1644
|
+
id: row[0],
|
|
1645
|
+
organizationId: row[1],
|
|
1646
|
+
userId: row[2],
|
|
1647
|
+
name: row[3],
|
|
1648
|
+
tokenHash: row[4],
|
|
1649
|
+
status: row[5],
|
|
1650
|
+
expiresAt: row[6],
|
|
1651
|
+
lastUsedAt: row[7],
|
|
1652
|
+
revokedAt: row[8],
|
|
1653
|
+
createdAt: row[9],
|
|
1654
|
+
updatedAt: row[10]
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
exports.getPersonalAccessTokenQuery = `-- name: GetPersonalAccessToken :one
|
|
1658
|
+
SELECT id, organization_id, user_id, name, token_hash, status, expires_at, last_used_at, revoked_at, created_at, updated_at
|
|
1659
|
+
FROM weave.personal_access_token
|
|
1660
|
+
WHERE id = $1`;
|
|
1661
|
+
async function getPersonalAccessToken(client, args) {
|
|
1662
|
+
const result = await client.query({
|
|
1663
|
+
text: exports.getPersonalAccessTokenQuery,
|
|
1664
|
+
values: [args.personalAccessTokenId],
|
|
1665
|
+
rowMode: "array"
|
|
1666
|
+
});
|
|
1667
|
+
if (result.rows.length !== 1) {
|
|
1668
|
+
return null;
|
|
1669
|
+
}
|
|
1670
|
+
const row = result.rows[0];
|
|
1671
|
+
return {
|
|
1672
|
+
id: row[0],
|
|
1673
|
+
organizationId: row[1],
|
|
1674
|
+
userId: row[2],
|
|
1675
|
+
name: row[3],
|
|
1676
|
+
tokenHash: row[4],
|
|
1677
|
+
status: row[5],
|
|
1678
|
+
expiresAt: row[6],
|
|
1679
|
+
lastUsedAt: row[7],
|
|
1680
|
+
revokedAt: row[8],
|
|
1681
|
+
createdAt: row[9],
|
|
1682
|
+
updatedAt: row[10]
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
exports.listPersonalAccessTokensQuery = `-- name: ListPersonalAccessTokens :many
|
|
1686
|
+
SELECT id, organization_id, user_id, name, token_hash, status, expires_at, last_used_at, revoked_at, created_at, updated_at
|
|
1687
|
+
FROM weave.personal_access_token
|
|
1688
|
+
WHERE organization_id = $1
|
|
1689
|
+
AND user_id = $2
|
|
1690
|
+
ORDER BY created_at DESC, id DESC
|
|
1691
|
+
LIMIT $4
|
|
1692
|
+
OFFSET $3`;
|
|
1693
|
+
async function listPersonalAccessTokens(client, args) {
|
|
1694
|
+
const result = await client.query({
|
|
1695
|
+
text: exports.listPersonalAccessTokensQuery,
|
|
1696
|
+
values: [args.organizationId, args.userId, args.offsetCount, args.limitCount],
|
|
1697
|
+
rowMode: "array"
|
|
1698
|
+
});
|
|
1699
|
+
return result.rows.map(row => {
|
|
1700
|
+
return {
|
|
1701
|
+
id: row[0],
|
|
1702
|
+
organizationId: row[1],
|
|
1703
|
+
userId: row[2],
|
|
1704
|
+
name: row[3],
|
|
1705
|
+
tokenHash: row[4],
|
|
1706
|
+
status: row[5],
|
|
1707
|
+
expiresAt: row[6],
|
|
1708
|
+
lastUsedAt: row[7],
|
|
1709
|
+
revokedAt: row[8],
|
|
1710
|
+
createdAt: row[9],
|
|
1711
|
+
updatedAt: row[10]
|
|
1712
|
+
};
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
exports.getPrincipalByPersonalAccessTokenQuery = `-- name: GetPrincipalByPersonalAccessToken :one
|
|
1716
|
+
SELECT
|
|
1717
|
+
pat.id AS personal_access_token_id,
|
|
1718
|
+
pat.status AS personal_access_token_status,
|
|
1719
|
+
pat.expires_at AS personal_access_token_expires_at,
|
|
1720
|
+
o.id AS organization_id,
|
|
1721
|
+
o.slug AS organization_slug,
|
|
1722
|
+
o.name AS organization_name,
|
|
1723
|
+
o.status AS organization_status,
|
|
1724
|
+
u.id AS user_id,
|
|
1725
|
+
u.email AS user_email,
|
|
1726
|
+
u.name AS user_name,
|
|
1727
|
+
u.status AS user_status,
|
|
1728
|
+
om.id AS organization_membership_id,
|
|
1729
|
+
om.role AS organization_membership_role,
|
|
1730
|
+
om.status AS organization_membership_status
|
|
1731
|
+
FROM weave.personal_access_token pat
|
|
1732
|
+
JOIN weave.organization o
|
|
1733
|
+
ON o.id = pat.organization_id
|
|
1734
|
+
JOIN weave.user u
|
|
1735
|
+
ON u.id = pat.user_id
|
|
1736
|
+
JOIN weave.organization_membership om
|
|
1737
|
+
ON om.organization_id = o.id
|
|
1738
|
+
AND om.user_id = u.id
|
|
1739
|
+
WHERE pat.token_hash = $1`;
|
|
1740
|
+
async function getPrincipalByPersonalAccessToken(client, args) {
|
|
1741
|
+
const result = await client.query({
|
|
1742
|
+
text: exports.getPrincipalByPersonalAccessTokenQuery,
|
|
1743
|
+
values: [args.tokenHash],
|
|
1744
|
+
rowMode: "array"
|
|
1745
|
+
});
|
|
1746
|
+
if (result.rows.length !== 1) {
|
|
1747
|
+
return null;
|
|
1748
|
+
}
|
|
1749
|
+
const row = result.rows[0];
|
|
1750
|
+
return {
|
|
1751
|
+
personalAccessTokenId: row[0],
|
|
1752
|
+
personalAccessTokenStatus: row[1],
|
|
1753
|
+
personalAccessTokenExpiresAt: row[2],
|
|
1754
|
+
organizationId: row[3],
|
|
1755
|
+
organizationSlug: row[4],
|
|
1756
|
+
organizationName: row[5],
|
|
1757
|
+
organizationStatus: row[6],
|
|
1758
|
+
userId: row[7],
|
|
1759
|
+
userEmail: row[8],
|
|
1760
|
+
userName: row[9],
|
|
1761
|
+
userStatus: row[10],
|
|
1762
|
+
organizationMembershipId: row[11],
|
|
1763
|
+
organizationMembershipRole: row[12],
|
|
1764
|
+
organizationMembershipStatus: row[13]
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
exports.markPersonalAccessTokenUsedQuery = `-- name: MarkPersonalAccessTokenUsed :execrows
|
|
1768
|
+
UPDATE weave.personal_access_token
|
|
1769
|
+
SET last_used_at = now()
|
|
1770
|
+
WHERE id = $1`;
|
|
1771
|
+
exports.revokePersonalAccessTokenQuery = `-- name: RevokePersonalAccessToken :execrows
|
|
1772
|
+
UPDATE weave.personal_access_token
|
|
1773
|
+
SET
|
|
1774
|
+
status = 'revoked',
|
|
1775
|
+
revoked_at = now()
|
|
1776
|
+
WHERE id = $1
|
|
1777
|
+
AND status = 'active'`;
|
|
1778
|
+
exports.revokePersonalAccessTokenForUserQuery = `-- name: RevokePersonalAccessTokenForUser :one
|
|
1779
|
+
UPDATE weave.personal_access_token
|
|
1780
|
+
SET
|
|
1781
|
+
status = 'revoked',
|
|
1782
|
+
revoked_at = now()
|
|
1783
|
+
WHERE id = $1
|
|
1784
|
+
AND organization_id = $2
|
|
1785
|
+
AND user_id = $3
|
|
1786
|
+
AND status = 'active'
|
|
1787
|
+
RETURNING id, organization_id, user_id, name, token_hash, status, expires_at, last_used_at, revoked_at, created_at, updated_at`;
|
|
1788
|
+
async function revokePersonalAccessTokenForUser(client, args) {
|
|
1789
|
+
const result = await client.query({
|
|
1790
|
+
text: exports.revokePersonalAccessTokenForUserQuery,
|
|
1791
|
+
values: [args.personalAccessTokenId, args.organizationId, args.userId],
|
|
1792
|
+
rowMode: "array"
|
|
1793
|
+
});
|
|
1794
|
+
if (result.rows.length !== 1) {
|
|
1795
|
+
return null;
|
|
1796
|
+
}
|
|
1797
|
+
const row = result.rows[0];
|
|
1798
|
+
return {
|
|
1799
|
+
id: row[0],
|
|
1800
|
+
organizationId: row[1],
|
|
1801
|
+
userId: row[2],
|
|
1802
|
+
name: row[3],
|
|
1803
|
+
tokenHash: row[4],
|
|
1804
|
+
status: row[5],
|
|
1805
|
+
expiresAt: row[6],
|
|
1806
|
+
lastUsedAt: row[7],
|
|
1807
|
+
revokedAt: row[8],
|
|
1808
|
+
createdAt: row[9],
|
|
1809
|
+
updatedAt: row[10]
|
|
1810
|
+
};
|
|
1811
|
+
}
|