weave-typescript 0.31.0 → 0.33.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.
Files changed (36) hide show
  1. package/dist/google/api/annotations.pb.js +1 -1
  2. package/dist/google/api/http.pb.js +1 -1
  3. package/dist/google/protobuf/descriptor.pb.js +1 -1
  4. package/dist/google/protobuf/struct.pb.js +1 -1
  5. package/dist/google/protobuf/timestamp.pb.js +1 -1
  6. package/dist/weaveapi/atc/v1/event.pb.js +1 -1
  7. package/dist/weaveapi/atc/v1/message.pb.js +1 -1
  8. package/dist/weaveapi/atc/v1/process.pb.js +1 -1
  9. package/dist/weaveapi/atc/v1/run.pb.js +1 -1
  10. package/dist/weaveapi/atc/v1/service.pb.js +1 -1
  11. package/dist/weaveapi/auth/v1/auth.pb.js +1 -1
  12. package/dist/weaveapi/auth/v1/service.pb.d.ts +49 -0
  13. package/dist/weaveapi/auth/v1/service.pb.js +461 -3
  14. package/dist/weaveapi/chat/v1/chat.pb.js +1 -1
  15. package/dist/weaveapi/chat/v1/service.pb.js +1 -1
  16. package/dist/weaveapi/consolidation/v1/consolidation.pb.js +1 -1
  17. package/dist/weaveapi/consolidation/v1/service.pb.js +1 -1
  18. package/dist/weaveapi/inference/v1/inference.pb.js +1 -1
  19. package/dist/weaveapi/inference/v1/service.pb.js +1 -1
  20. package/dist/weaveapi/ingestion/v1/ingestion.pb.js +1 -1
  21. package/dist/weaveapi/ingestion/v1/service.pb.js +1 -1
  22. package/dist/weaveapi/model/v1/model.pb.js +1 -1
  23. package/dist/weaveapi/model/v1/service.pb.js +1 -1
  24. package/dist/weaveapi/organization/v1/organization.pb.js +1 -1
  25. package/dist/weaveapi/organization/v1/service.pb.js +1 -1
  26. package/dist/weaveapi/project/v1/project.pb.js +1 -1
  27. package/dist/weaveapi/project/v1/service.pb.js +1 -1
  28. package/dist/weaveapi/provider/v1/provider.pb.js +1 -1
  29. package/dist/weaveapi/provider/v1/service.pb.js +1 -1
  30. package/dist/weaveapi/retrieval/v1/retrieval.pb.js +1 -1
  31. package/dist/weaveapi/retrieval/v1/service.pb.js +1 -1
  32. package/dist/weaveapi/task/v1/service.pb.js +1 -1
  33. package/dist/weaveapi/task/v1/task.pb.js +1 -1
  34. package/dist/weavesql/weavedb/auth_identity_sql.d.ts +232 -1
  35. package/dist/weavesql/weavedb/auth_identity_sql.js +555 -8
  36. package/package.json +2 -2
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.insertAuthAuditEventQuery = exports.endSupportAccessSessionQuery = exports.createSupportAccessSessionQuery = exports.createPlatformAdminGrantQuery = exports.listActivePlatformAdminGrantsForUserQuery = exports.listOrganizationMembersQuery = exports.listOrganizationMembershipsForUserQuery = exports.getOrganizationMembershipQuery = exports.upsertOrganizationMembershipQuery = exports.upsertOrganizationAuthLinkQuery = exports.getOrganizationAuthLinkByOrganizationIDQuery = exports.getOrganizationAuthLinkByStytchIDQuery = exports.upsertIdentityLinkQuery = exports.getIdentityLinkByStytchMemberQuery = exports.getUserProfileQuery = exports.upsertUserProfileQuery = exports.getUserByIDQuery = exports.createUserQuery = void 0;
3
+ exports.deleteExpiredApplicationSessionsQuery = exports.markApplicationSessionOrganizationSessionStateQuery = exports.listApplicationSessionOrganizationSessionStatesQuery = exports.getApplicationSessionOrganizationSessionQuery = exports.upsertApplicationSessionOrganizationSessionQuery = exports.revokeApplicationSessionQuery = exports.setApplicationSessionActiveOrganizationQuery = exports.getApplicationSessionQuery = exports.createApplicationSessionQuery = exports.insertAuthAuditEventQuery = exports.endSupportAccessSessionQuery = exports.createSupportAccessSessionQuery = exports.createPlatformAdminGrantQuery = exports.listActivePlatformAdminGrantsForUserQuery = exports.listOrganizationMembersQuery = exports.listOrganizationMembershipsForUserQuery = exports.getOrganizationMembershipQuery = exports.upsertOrganizationMembershipQuery = exports.upsertOrganizationAuthLinkQuery = exports.getOrganizationAuthLinkByOrganizationIDQuery = exports.getOrganizationAuthLinkByStytchIDQuery = exports.upsertIdentityLinkQuery = exports.getIdentityLinkByStytchMemberQuery = exports.getUserProfileQuery = exports.upsertUserProfileQuery = exports.deleteOrganizationAuthDomainQuery = exports.listOrganizationAuthDomainsQuery = exports.upsertOrganizationAuthDomainQuery = exports.resolvePrimaryOrganizationAuthLinkByDomainQuery = exports.getUserPrimaryOrganizationAuthLinkQuery = exports.setUserPrimaryOrganizationQuery = exports.getUserByIDQuery = exports.createUserQuery = void 0;
4
4
  exports.createUser = createUser;
5
5
  exports.getUserByID = getUserByID;
6
+ exports.setUserPrimaryOrganization = setUserPrimaryOrganization;
7
+ exports.getUserPrimaryOrganizationAuthLink = getUserPrimaryOrganizationAuthLink;
8
+ exports.resolvePrimaryOrganizationAuthLinkByDomain = resolvePrimaryOrganizationAuthLinkByDomain;
9
+ exports.upsertOrganizationAuthDomain = upsertOrganizationAuthDomain;
10
+ exports.listOrganizationAuthDomains = listOrganizationAuthDomains;
6
11
  exports.upsertUserProfile = upsertUserProfile;
7
12
  exports.getUserProfile = getUserProfile;
8
13
  exports.getIdentityLinkByStytchMember = getIdentityLinkByStytchMember;
@@ -18,6 +23,13 @@ exports.listActivePlatformAdminGrantsForUser = listActivePlatformAdminGrantsForU
18
23
  exports.createPlatformAdminGrant = createPlatformAdminGrant;
19
24
  exports.createSupportAccessSession = createSupportAccessSession;
20
25
  exports.insertAuthAuditEvent = insertAuthAuditEvent;
26
+ exports.createApplicationSession = createApplicationSession;
27
+ exports.getApplicationSession = getApplicationSession;
28
+ exports.setApplicationSessionActiveOrganization = setApplicationSessionActiveOrganization;
29
+ exports.upsertApplicationSessionOrganizationSession = upsertApplicationSessionOrganizationSession;
30
+ exports.getApplicationSessionOrganizationSession = getApplicationSessionOrganizationSession;
31
+ exports.listApplicationSessionOrganizationSessionStates = listApplicationSessionOrganizationSessionStates;
32
+ exports.markApplicationSessionOrganizationSessionState = markApplicationSessionOrganizationSessionState;
21
33
  exports.createUserQuery = `-- name: CreateUser :one
22
34
  INSERT INTO weave.users (status)
23
35
  VALUES ($1)
@@ -60,6 +72,202 @@ async function getUserByID(client, args) {
60
72
  updatedAt: row[3]
61
73
  };
62
74
  }
75
+ exports.setUserPrimaryOrganizationQuery = `-- name: SetUserPrimaryOrganization :one
76
+ UPDATE weave.users
77
+ SET
78
+ primary_organization_id = $1,
79
+ updated_at = now()
80
+ WHERE id = $2
81
+ RETURNING
82
+ id,
83
+ primary_organization_id,
84
+ status,
85
+ created_at,
86
+ updated_at`;
87
+ async function setUserPrimaryOrganization(client, args) {
88
+ const result = await client.query({
89
+ text: exports.setUserPrimaryOrganizationQuery,
90
+ values: [args.organizationId, args.userId],
91
+ rowMode: "array"
92
+ });
93
+ if (result.rows.length !== 1) {
94
+ return null;
95
+ }
96
+ const row = result.rows[0];
97
+ return {
98
+ id: row[0],
99
+ primaryOrganizationId: row[1],
100
+ status: row[2],
101
+ createdAt: row[3],
102
+ updatedAt: row[4]
103
+ };
104
+ }
105
+ exports.getUserPrimaryOrganizationAuthLinkQuery = `-- name: GetUserPrimaryOrganizationAuthLink :one
106
+ SELECT
107
+ o.id AS organization_id,
108
+ o.slug AS organization_slug,
109
+ o.name AS organization_name,
110
+ l.stytch_organization_id,
111
+ l.stytch_organization_slug,
112
+ l.stytch_organization_kind,
113
+ l.allowed_domains,
114
+ l.auth_policy_summary,
115
+ l.created_at,
116
+ l.updated_at
117
+ FROM weave.users AS u
118
+ JOIN weave.organizations AS o
119
+ ON o.id = u.primary_organization_id
120
+ JOIN weave.organization_auth_links AS l
121
+ ON l.organization_id = o.id
122
+ WHERE u.id = $1
123
+ AND u.status = 'active'`;
124
+ async function getUserPrimaryOrganizationAuthLink(client, args) {
125
+ const result = await client.query({
126
+ text: exports.getUserPrimaryOrganizationAuthLinkQuery,
127
+ values: [args.userId],
128
+ rowMode: "array"
129
+ });
130
+ if (result.rows.length !== 1) {
131
+ return null;
132
+ }
133
+ const row = result.rows[0];
134
+ return {
135
+ organizationId: row[0],
136
+ organizationSlug: row[1],
137
+ organizationName: row[2],
138
+ stytchOrganizationId: row[3],
139
+ stytchOrganizationSlug: row[4],
140
+ stytchOrganizationKind: row[5],
141
+ allowedDomains: row[6],
142
+ authPolicySummary: row[7],
143
+ createdAt: row[8],
144
+ updatedAt: row[9]
145
+ };
146
+ }
147
+ exports.resolvePrimaryOrganizationAuthLinkByDomainQuery = `-- name: ResolvePrimaryOrganizationAuthLinkByDomain :one
148
+ SELECT
149
+ o.id AS organization_id,
150
+ o.slug AS organization_slug,
151
+ o.name AS organization_name,
152
+ l.stytch_organization_id,
153
+ l.stytch_organization_slug,
154
+ l.stytch_organization_kind,
155
+ d.domain,
156
+ l.allowed_domains,
157
+ l.auth_policy_summary,
158
+ l.created_at,
159
+ l.updated_at
160
+ FROM weave.organization_auth_domains AS d
161
+ JOIN weave.organization_auth_links AS l
162
+ ON l.organization_id = d.organization_id
163
+ JOIN weave.organizations AS o
164
+ ON o.id = d.organization_id
165
+ WHERE d.domain = lower($1)
166
+ AND d.is_primary_login
167
+ AND d.status = 'active'`;
168
+ async function resolvePrimaryOrganizationAuthLinkByDomain(client, args) {
169
+ const result = await client.query({
170
+ text: exports.resolvePrimaryOrganizationAuthLinkByDomainQuery,
171
+ values: [args.domain],
172
+ rowMode: "array"
173
+ });
174
+ if (result.rows.length !== 1) {
175
+ return null;
176
+ }
177
+ const row = result.rows[0];
178
+ return {
179
+ organizationId: row[0],
180
+ organizationSlug: row[1],
181
+ organizationName: row[2],
182
+ stytchOrganizationId: row[3],
183
+ stytchOrganizationSlug: row[4],
184
+ stytchOrganizationKind: row[5],
185
+ domain: row[6],
186
+ allowedDomains: row[7],
187
+ authPolicySummary: row[8],
188
+ createdAt: row[9],
189
+ updatedAt: row[10]
190
+ };
191
+ }
192
+ exports.upsertOrganizationAuthDomainQuery = `-- name: UpsertOrganizationAuthDomain :one
193
+ INSERT INTO weave.organization_auth_domains (
194
+ organization_id,
195
+ domain,
196
+ is_primary_login,
197
+ status
198
+ ) VALUES (
199
+ $1,
200
+ lower($2),
201
+ $3,
202
+ $4
203
+ )
204
+ ON CONFLICT (organization_id, domain) DO UPDATE
205
+ SET
206
+ is_primary_login = EXCLUDED.is_primary_login,
207
+ status = EXCLUDED.status,
208
+ updated_at = now()
209
+ RETURNING
210
+ id,
211
+ organization_id,
212
+ domain,
213
+ is_primary_login,
214
+ status,
215
+ created_at,
216
+ updated_at`;
217
+ async function upsertOrganizationAuthDomain(client, args) {
218
+ const result = await client.query({
219
+ text: exports.upsertOrganizationAuthDomainQuery,
220
+ values: [args.organizationId, args.domain, args.isPrimaryLogin, args.status],
221
+ rowMode: "array"
222
+ });
223
+ if (result.rows.length !== 1) {
224
+ return null;
225
+ }
226
+ const row = result.rows[0];
227
+ return {
228
+ id: row[0],
229
+ organizationId: row[1],
230
+ domain: row[2],
231
+ isPrimaryLogin: row[3],
232
+ status: row[4],
233
+ createdAt: row[5],
234
+ updatedAt: row[6]
235
+ };
236
+ }
237
+ exports.listOrganizationAuthDomainsQuery = `-- name: ListOrganizationAuthDomains :many
238
+ SELECT
239
+ id,
240
+ organization_id,
241
+ domain,
242
+ is_primary_login,
243
+ status,
244
+ created_at,
245
+ updated_at
246
+ FROM weave.organization_auth_domains
247
+ WHERE organization_id = $1
248
+ ORDER BY is_primary_login DESC, domain ASC`;
249
+ async function listOrganizationAuthDomains(client, args) {
250
+ const result = await client.query({
251
+ text: exports.listOrganizationAuthDomainsQuery,
252
+ values: [args.organizationId],
253
+ rowMode: "array"
254
+ });
255
+ return result.rows.map(row => {
256
+ return {
257
+ id: row[0],
258
+ organizationId: row[1],
259
+ domain: row[2],
260
+ isPrimaryLogin: row[3],
261
+ status: row[4],
262
+ createdAt: row[5],
263
+ updatedAt: row[6]
264
+ };
265
+ });
266
+ }
267
+ exports.deleteOrganizationAuthDomainQuery = `-- name: DeleteOrganizationAuthDomain :execrows
268
+ DELETE FROM weave.organization_auth_domains
269
+ WHERE organization_id = $1
270
+ AND domain = lower($2)`;
63
271
  exports.upsertUserProfileQuery = `-- name: UpsertUserProfile :one
64
272
  INSERT INTO weave.user_profiles (
65
273
  user_id,
@@ -487,6 +695,7 @@ SELECT
487
695
  m.user_id,
488
696
  m.organization_id,
489
697
  m.identity_link_id,
698
+ l.stytch_member_id,
490
699
  m.status,
491
700
  m.role_ids,
492
701
  p.display_name,
@@ -497,6 +706,8 @@ SELECT
497
706
  FROM weave.organization_memberships AS m
498
707
  JOIN weave.user_profiles AS p
499
708
  ON p.user_id = m.user_id
709
+ LEFT JOIN weave.identity_links AS l
710
+ ON l.id = m.identity_link_id
500
711
  WHERE m.organization_id = $1
501
712
  ORDER BY p.display_name ASC, p.email ASC`;
502
713
  async function listOrganizationMembers(client, args) {
@@ -511,13 +722,14 @@ async function listOrganizationMembers(client, args) {
511
722
  userId: row[1],
512
723
  organizationId: row[2],
513
724
  identityLinkId: row[3],
514
- status: row[4],
515
- roleIds: row[5],
516
- displayName: row[6],
517
- email: row[7],
518
- avatarUrl: row[8],
519
- createdAt: row[9],
520
- updatedAt: row[10]
725
+ stytchMemberId: row[4],
726
+ status: row[5],
727
+ roleIds: row[6],
728
+ displayName: row[7],
729
+ email: row[8],
730
+ avatarUrl: row[9],
731
+ createdAt: row[10],
732
+ updatedAt: row[11]
521
733
  };
522
734
  });
523
735
  }
@@ -688,3 +900,338 @@ async function insertAuthAuditEvent(client, args) {
688
900
  rowMode: "array"
689
901
  });
690
902
  }
903
+ exports.createApplicationSessionQuery = `-- name: CreateApplicationSession :one
904
+ INSERT INTO weave.application_sessions (
905
+ user_id,
906
+ active_organization_id,
907
+ expires_at
908
+ ) VALUES (
909
+ $1,
910
+ $2,
911
+ $3
912
+ )
913
+ RETURNING
914
+ id,
915
+ user_id,
916
+ active_organization_id,
917
+ status,
918
+ expires_at,
919
+ revoked_at,
920
+ created_at,
921
+ updated_at`;
922
+ async function createApplicationSession(client, args) {
923
+ const result = await client.query({
924
+ text: exports.createApplicationSessionQuery,
925
+ values: [args.userId, args.activeOrganizationId, args.expiresAt],
926
+ rowMode: "array"
927
+ });
928
+ if (result.rows.length !== 1) {
929
+ return null;
930
+ }
931
+ const row = result.rows[0];
932
+ return {
933
+ id: row[0],
934
+ userId: row[1],
935
+ activeOrganizationId: row[2],
936
+ status: row[3],
937
+ expiresAt: row[4],
938
+ revokedAt: row[5],
939
+ createdAt: row[6],
940
+ updatedAt: row[7]
941
+ };
942
+ }
943
+ exports.getApplicationSessionQuery = `-- name: GetApplicationSession :one
944
+ SELECT
945
+ id,
946
+ user_id,
947
+ active_organization_id,
948
+ status,
949
+ expires_at,
950
+ revoked_at,
951
+ created_at,
952
+ updated_at
953
+ FROM weave.application_sessions
954
+ WHERE id = $1`;
955
+ async function getApplicationSession(client, args) {
956
+ const result = await client.query({
957
+ text: exports.getApplicationSessionQuery,
958
+ values: [args.id],
959
+ rowMode: "array"
960
+ });
961
+ if (result.rows.length !== 1) {
962
+ return null;
963
+ }
964
+ const row = result.rows[0];
965
+ return {
966
+ id: row[0],
967
+ userId: row[1],
968
+ activeOrganizationId: row[2],
969
+ status: row[3],
970
+ expiresAt: row[4],
971
+ revokedAt: row[5],
972
+ createdAt: row[6],
973
+ updatedAt: row[7]
974
+ };
975
+ }
976
+ exports.setApplicationSessionActiveOrganizationQuery = `-- name: SetApplicationSessionActiveOrganization :one
977
+ UPDATE weave.application_sessions
978
+ SET
979
+ active_organization_id = $1,
980
+ updated_at = now()
981
+ WHERE id = $2
982
+ AND status = 'active'
983
+ RETURNING
984
+ id,
985
+ user_id,
986
+ active_organization_id,
987
+ status,
988
+ expires_at,
989
+ revoked_at,
990
+ created_at,
991
+ updated_at`;
992
+ async function setApplicationSessionActiveOrganization(client, args) {
993
+ const result = await client.query({
994
+ text: exports.setApplicationSessionActiveOrganizationQuery,
995
+ values: [args.organizationId, args.id],
996
+ rowMode: "array"
997
+ });
998
+ if (result.rows.length !== 1) {
999
+ return null;
1000
+ }
1001
+ const row = result.rows[0];
1002
+ return {
1003
+ id: row[0],
1004
+ userId: row[1],
1005
+ activeOrganizationId: row[2],
1006
+ status: row[3],
1007
+ expiresAt: row[4],
1008
+ revokedAt: row[5],
1009
+ createdAt: row[6],
1010
+ updatedAt: row[7]
1011
+ };
1012
+ }
1013
+ exports.revokeApplicationSessionQuery = `-- name: RevokeApplicationSession :execrows
1014
+ UPDATE weave.application_sessions
1015
+ SET
1016
+ status = 'revoked',
1017
+ revoked_at = now(),
1018
+ updated_at = now()
1019
+ WHERE id = $1
1020
+ AND status = 'active'`;
1021
+ exports.upsertApplicationSessionOrganizationSessionQuery = `-- name: UpsertApplicationSessionOrganizationSession :one
1022
+ INSERT INTO weave.application_session_organization_sessions (
1023
+ application_session_id,
1024
+ organization_id,
1025
+ identity_link_id,
1026
+ stytch_organization_id,
1027
+ stytch_member_id,
1028
+ stytch_member_session_id,
1029
+ stytch_session_token_ciphertext,
1030
+ auth_state,
1031
+ expires_at,
1032
+ last_validated_at
1033
+ ) VALUES (
1034
+ $1,
1035
+ $2,
1036
+ $3,
1037
+ $4,
1038
+ $5,
1039
+ $6,
1040
+ $7,
1041
+ $8,
1042
+ $9,
1043
+ $10
1044
+ )
1045
+ ON CONFLICT (application_session_id, organization_id) DO UPDATE
1046
+ SET
1047
+ identity_link_id = EXCLUDED.identity_link_id,
1048
+ stytch_organization_id = EXCLUDED.stytch_organization_id,
1049
+ stytch_member_id = EXCLUDED.stytch_member_id,
1050
+ stytch_member_session_id = EXCLUDED.stytch_member_session_id,
1051
+ stytch_session_token_ciphertext = EXCLUDED.stytch_session_token_ciphertext,
1052
+ auth_state = EXCLUDED.auth_state,
1053
+ expires_at = EXCLUDED.expires_at,
1054
+ last_validated_at = EXCLUDED.last_validated_at,
1055
+ updated_at = now()
1056
+ RETURNING
1057
+ id,
1058
+ application_session_id,
1059
+ organization_id,
1060
+ identity_link_id,
1061
+ stytch_organization_id,
1062
+ stytch_member_id,
1063
+ stytch_member_session_id,
1064
+ stytch_session_token_ciphertext,
1065
+ auth_state,
1066
+ expires_at,
1067
+ last_validated_at,
1068
+ created_at,
1069
+ updated_at`;
1070
+ async function upsertApplicationSessionOrganizationSession(client, args) {
1071
+ const result = await client.query({
1072
+ text: exports.upsertApplicationSessionOrganizationSessionQuery,
1073
+ values: [args.applicationSessionId, args.organizationId, args.identityLinkId, args.stytchOrganizationId, args.stytchMemberId, args.stytchMemberSessionId, args.stytchSessionTokenCiphertext, args.authState, args.expiresAt, args.lastValidatedAt],
1074
+ rowMode: "array"
1075
+ });
1076
+ if (result.rows.length !== 1) {
1077
+ return null;
1078
+ }
1079
+ const row = result.rows[0];
1080
+ return {
1081
+ id: row[0],
1082
+ applicationSessionId: row[1],
1083
+ organizationId: row[2],
1084
+ identityLinkId: row[3],
1085
+ stytchOrganizationId: row[4],
1086
+ stytchMemberId: row[5],
1087
+ stytchMemberSessionId: row[6],
1088
+ stytchSessionTokenCiphertext: row[7],
1089
+ authState: row[8],
1090
+ expiresAt: row[9],
1091
+ lastValidatedAt: row[10],
1092
+ createdAt: row[11],
1093
+ updatedAt: row[12]
1094
+ };
1095
+ }
1096
+ exports.getApplicationSessionOrganizationSessionQuery = `-- name: GetApplicationSessionOrganizationSession :one
1097
+ SELECT
1098
+ id,
1099
+ application_session_id,
1100
+ organization_id,
1101
+ identity_link_id,
1102
+ stytch_organization_id,
1103
+ stytch_member_id,
1104
+ stytch_member_session_id,
1105
+ stytch_session_token_ciphertext,
1106
+ auth_state,
1107
+ expires_at,
1108
+ last_validated_at,
1109
+ created_at,
1110
+ updated_at
1111
+ FROM weave.application_session_organization_sessions
1112
+ WHERE application_session_id = $1
1113
+ AND organization_id = $2`;
1114
+ async function getApplicationSessionOrganizationSession(client, args) {
1115
+ const result = await client.query({
1116
+ text: exports.getApplicationSessionOrganizationSessionQuery,
1117
+ values: [args.applicationSessionId, args.organizationId],
1118
+ rowMode: "array"
1119
+ });
1120
+ if (result.rows.length !== 1) {
1121
+ return null;
1122
+ }
1123
+ const row = result.rows[0];
1124
+ return {
1125
+ id: row[0],
1126
+ applicationSessionId: row[1],
1127
+ organizationId: row[2],
1128
+ identityLinkId: row[3],
1129
+ stytchOrganizationId: row[4],
1130
+ stytchMemberId: row[5],
1131
+ stytchMemberSessionId: row[6],
1132
+ stytchSessionTokenCiphertext: row[7],
1133
+ authState: row[8],
1134
+ expiresAt: row[9],
1135
+ lastValidatedAt: row[10],
1136
+ createdAt: row[11],
1137
+ updatedAt: row[12]
1138
+ };
1139
+ }
1140
+ exports.listApplicationSessionOrganizationSessionStatesQuery = `-- name: ListApplicationSessionOrganizationSessionStates :many
1141
+ SELECT
1142
+ s.id,
1143
+ s.application_session_id,
1144
+ s.organization_id,
1145
+ o.slug AS organization_slug,
1146
+ o.name AS organization_name,
1147
+ s.identity_link_id,
1148
+ s.stytch_organization_id,
1149
+ s.stytch_member_id,
1150
+ s.stytch_member_session_id,
1151
+ s.auth_state,
1152
+ s.expires_at,
1153
+ s.last_validated_at,
1154
+ s.created_at,
1155
+ s.updated_at
1156
+ FROM weave.application_session_organization_sessions AS s
1157
+ JOIN weave.organizations AS o
1158
+ ON o.id = s.organization_id
1159
+ WHERE s.application_session_id = $1
1160
+ ORDER BY o.slug ASC`;
1161
+ async function listApplicationSessionOrganizationSessionStates(client, args) {
1162
+ const result = await client.query({
1163
+ text: exports.listApplicationSessionOrganizationSessionStatesQuery,
1164
+ values: [args.applicationSessionId],
1165
+ rowMode: "array"
1166
+ });
1167
+ return result.rows.map(row => {
1168
+ return {
1169
+ id: row[0],
1170
+ applicationSessionId: row[1],
1171
+ organizationId: row[2],
1172
+ organizationSlug: row[3],
1173
+ organizationName: row[4],
1174
+ identityLinkId: row[5],
1175
+ stytchOrganizationId: row[6],
1176
+ stytchMemberId: row[7],
1177
+ stytchMemberSessionId: row[8],
1178
+ authState: row[9],
1179
+ expiresAt: row[10],
1180
+ lastValidatedAt: row[11],
1181
+ createdAt: row[12],
1182
+ updatedAt: row[13]
1183
+ };
1184
+ });
1185
+ }
1186
+ exports.markApplicationSessionOrganizationSessionStateQuery = `-- name: MarkApplicationSessionOrganizationSessionState :one
1187
+ UPDATE weave.application_session_organization_sessions
1188
+ SET
1189
+ auth_state = $1,
1190
+ last_validated_at = now(),
1191
+ updated_at = now()
1192
+ WHERE application_session_id = $2
1193
+ AND organization_id = $3
1194
+ RETURNING
1195
+ id,
1196
+ application_session_id,
1197
+ organization_id,
1198
+ identity_link_id,
1199
+ stytch_organization_id,
1200
+ stytch_member_id,
1201
+ stytch_member_session_id,
1202
+ stytch_session_token_ciphertext,
1203
+ auth_state,
1204
+ expires_at,
1205
+ last_validated_at,
1206
+ created_at,
1207
+ updated_at`;
1208
+ async function markApplicationSessionOrganizationSessionState(client, args) {
1209
+ const result = await client.query({
1210
+ text: exports.markApplicationSessionOrganizationSessionStateQuery,
1211
+ values: [args.authState, args.applicationSessionId, args.organizationId],
1212
+ rowMode: "array"
1213
+ });
1214
+ if (result.rows.length !== 1) {
1215
+ return null;
1216
+ }
1217
+ const row = result.rows[0];
1218
+ return {
1219
+ id: row[0],
1220
+ applicationSessionId: row[1],
1221
+ organizationId: row[2],
1222
+ identityLinkId: row[3],
1223
+ stytchOrganizationId: row[4],
1224
+ stytchMemberId: row[5],
1225
+ stytchMemberSessionId: row[6],
1226
+ stytchSessionTokenCiphertext: row[7],
1227
+ authState: row[8],
1228
+ expiresAt: row[9],
1229
+ lastValidatedAt: row[10],
1230
+ createdAt: row[11],
1231
+ updatedAt: row[12]
1232
+ };
1233
+ }
1234
+ exports.deleteExpiredApplicationSessionsQuery = `-- name: DeleteExpiredApplicationSessions :execrows
1235
+ DELETE FROM weave.application_sessions
1236
+ WHERE expires_at <= now()
1237
+ OR status IN ('revoked', 'expired')`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weave-typescript",
3
- "version": "0.31.0",
3
+ "version": "0.33.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -31,7 +31,7 @@
31
31
  "devDependencies": {
32
32
  "@types/node": "^25.2.0",
33
33
  "@types/pg": "^8.15.5",
34
- "@typescript/native-preview": "7.0.0-dev.20260426.1"
34
+ "@typescript/native-preview": "7.0.0-dev.20260503.1"
35
35
  },
36
36
  "scripts": {
37
37
  "test": "node tools/sqlcgen.test.js",