weave-typescript 0.37.0 → 0.39.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.
@@ -1392,7 +1392,14 @@ exports.RetrievedThread = {
1392
1392
  },
1393
1393
  };
1394
1394
  function createBaseDocumentSearchFilters() {
1395
- return { tags: [], restrictedTags: [], scopes: [], uploadedAfter: undefined, uploadedBefore: undefined };
1395
+ return {
1396
+ tags: [],
1397
+ restrictedTags: [],
1398
+ scopes: [],
1399
+ uploadedAfter: undefined,
1400
+ uploadedBefore: undefined,
1401
+ restrictedGroupIds: [],
1402
+ };
1396
1403
  }
1397
1404
  exports.DocumentSearchFilters = {
1398
1405
  encode(message, writer = new wire_1.BinaryWriter()) {
@@ -1413,6 +1420,9 @@ exports.DocumentSearchFilters = {
1413
1420
  if (message.uploadedBefore !== undefined) {
1414
1421
  timestamp_pb_1.Timestamp.encode(toTimestamp(message.uploadedBefore), writer.uint32(42).fork()).join();
1415
1422
  }
1423
+ for (const v of message.restrictedGroupIds) {
1424
+ writer.uint32(50).string(v);
1425
+ }
1416
1426
  return writer;
1417
1427
  },
1418
1428
  decode(input, length) {
@@ -1464,6 +1474,13 @@ exports.DocumentSearchFilters = {
1464
1474
  message.uploadedBefore = fromTimestamp(timestamp_pb_1.Timestamp.decode(reader, reader.uint32()));
1465
1475
  continue;
1466
1476
  }
1477
+ case 6: {
1478
+ if (tag !== 50) {
1479
+ break;
1480
+ }
1481
+ message.restrictedGroupIds.push(reader.string());
1482
+ continue;
1483
+ }
1467
1484
  }
1468
1485
  if ((tag & 7) === 4 || tag === 0) {
1469
1486
  break;
@@ -1491,10 +1508,15 @@ exports.DocumentSearchFilters = {
1491
1508
  : isSet(object.uploaded_before)
1492
1509
  ? fromJsonTimestamp(object.uploaded_before)
1493
1510
  : undefined,
1511
+ restrictedGroupIds: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.restrictedGroupIds)
1512
+ ? object.restrictedGroupIds.map((e) => globalThis.String(e))
1513
+ : globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.restricted_group_ids)
1514
+ ? object.restricted_group_ids.map((e) => globalThis.String(e))
1515
+ : [],
1494
1516
  };
1495
1517
  },
1496
1518
  toJSON(message) {
1497
- var _a, _b, _c;
1519
+ var _a, _b, _c, _d;
1498
1520
  const obj = {};
1499
1521
  if ((_a = message.tags) === null || _a === void 0 ? void 0 : _a.length) {
1500
1522
  obj.tags = message.tags;
@@ -1511,20 +1533,24 @@ exports.DocumentSearchFilters = {
1511
1533
  if (message.uploadedBefore !== undefined) {
1512
1534
  obj.uploadedBefore = message.uploadedBefore.toISOString();
1513
1535
  }
1536
+ if ((_d = message.restrictedGroupIds) === null || _d === void 0 ? void 0 : _d.length) {
1537
+ obj.restrictedGroupIds = message.restrictedGroupIds;
1538
+ }
1514
1539
  return obj;
1515
1540
  },
1516
1541
  create(base) {
1517
1542
  return exports.DocumentSearchFilters.fromPartial(base !== null && base !== void 0 ? base : {});
1518
1543
  },
1519
1544
  fromPartial(object) {
1520
- var _a, _b, _c;
1521
- var _d, _e;
1545
+ var _a, _b, _c, _d;
1546
+ var _e, _f;
1522
1547
  const message = createBaseDocumentSearchFilters();
1523
1548
  message.tags = ((_a = object.tags) === null || _a === void 0 ? void 0 : _a.map((e) => e)) || [];
1524
1549
  message.restrictedTags = ((_b = object.restrictedTags) === null || _b === void 0 ? void 0 : _b.map((e) => e)) || [];
1525
1550
  message.scopes = ((_c = object.scopes) === null || _c === void 0 ? void 0 : _c.map((e) => e)) || [];
1526
- message.uploadedAfter = (_d = object.uploadedAfter) !== null && _d !== void 0 ? _d : undefined;
1527
- message.uploadedBefore = (_e = object.uploadedBefore) !== null && _e !== void 0 ? _e : undefined;
1551
+ message.uploadedAfter = (_e = object.uploadedAfter) !== null && _e !== void 0 ? _e : undefined;
1552
+ message.uploadedBefore = (_f = object.uploadedBefore) !== null && _f !== void 0 ? _f : undefined;
1553
+ message.restrictedGroupIds = ((_d = object.restrictedGroupIds) === null || _d === void 0 ? void 0 : _d.map((e) => e)) || [];
1528
1554
  return message;
1529
1555
  },
1530
1556
  };
@@ -1664,6 +1690,7 @@ function createBaseRetrievedDocument() {
1664
1690
  matchedThreadCount: 0,
1665
1691
  snippets: [],
1666
1692
  uploadedAt: undefined,
1693
+ restrictedGroups: [],
1667
1694
  };
1668
1695
  }
1669
1696
  exports.RetrievedDocument = {
@@ -1698,6 +1725,9 @@ exports.RetrievedDocument = {
1698
1725
  if (message.uploadedAt !== undefined) {
1699
1726
  timestamp_pb_1.Timestamp.encode(toTimestamp(message.uploadedAt), writer.uint32(82).fork()).join();
1700
1727
  }
1728
+ for (const v of message.restrictedGroups) {
1729
+ ingestion_pb_1.RestrictedGroup.encode(v, writer.uint32(90).fork()).join();
1730
+ }
1701
1731
  return writer;
1702
1732
  },
1703
1733
  decode(input, length) {
@@ -1777,6 +1807,13 @@ exports.RetrievedDocument = {
1777
1807
  message.uploadedAt = fromTimestamp(timestamp_pb_1.Timestamp.decode(reader, reader.uint32()));
1778
1808
  continue;
1779
1809
  }
1810
+ case 11: {
1811
+ if (tag !== 90) {
1812
+ break;
1813
+ }
1814
+ message.restrictedGroups.push(ingestion_pb_1.RestrictedGroup.decode(reader, reader.uint32()));
1815
+ continue;
1816
+ }
1780
1817
  }
1781
1818
  if ((tag & 7) === 4 || tag === 0) {
1782
1819
  break;
@@ -1823,10 +1860,15 @@ exports.RetrievedDocument = {
1823
1860
  : isSet(object.uploaded_at)
1824
1861
  ? fromJsonTimestamp(object.uploaded_at)
1825
1862
  : undefined,
1863
+ restrictedGroups: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.restrictedGroups)
1864
+ ? object.restrictedGroups.map((e) => ingestion_pb_1.RestrictedGroup.fromJSON(e))
1865
+ : globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.restricted_groups)
1866
+ ? object.restricted_groups.map((e) => ingestion_pb_1.RestrictedGroup.fromJSON(e))
1867
+ : [],
1826
1868
  };
1827
1869
  },
1828
1870
  toJSON(message) {
1829
- var _a, _b, _c;
1871
+ var _a, _b, _c, _d;
1830
1872
  const obj = {};
1831
1873
  if (message.documentId !== "") {
1832
1874
  obj.documentId = message.documentId;
@@ -1858,25 +1900,29 @@ exports.RetrievedDocument = {
1858
1900
  if (message.uploadedAt !== undefined) {
1859
1901
  obj.uploadedAt = message.uploadedAt.toISOString();
1860
1902
  }
1903
+ if ((_d = message.restrictedGroups) === null || _d === void 0 ? void 0 : _d.length) {
1904
+ obj.restrictedGroups = message.restrictedGroups.map((e) => ingestion_pb_1.RestrictedGroup.toJSON(e));
1905
+ }
1861
1906
  return obj;
1862
1907
  },
1863
1908
  create(base) {
1864
1909
  return exports.RetrievedDocument.fromPartial(base !== null && base !== void 0 ? base : {});
1865
1910
  },
1866
1911
  fromPartial(object) {
1867
- var _a, _b, _c;
1868
- var _d, _e, _f, _g, _h, _j, _k;
1912
+ var _a, _b, _c, _d;
1913
+ var _e, _f, _g, _h, _j, _k, _l;
1869
1914
  const message = createBaseRetrievedDocument();
1870
- message.documentId = (_d = object.documentId) !== null && _d !== void 0 ? _d : "";
1871
- message.documentName = (_e = object.documentName) !== null && _e !== void 0 ? _e : "";
1872
- message.mimeType = (_f = object.mimeType) !== null && _f !== void 0 ? _f : "";
1873
- message.scope = (_g = object.scope) !== null && _g !== void 0 ? _g : 0;
1915
+ message.documentId = (_e = object.documentId) !== null && _e !== void 0 ? _e : "";
1916
+ message.documentName = (_f = object.documentName) !== null && _f !== void 0 ? _f : "";
1917
+ message.mimeType = (_g = object.mimeType) !== null && _g !== void 0 ? _g : "";
1918
+ message.scope = (_h = object.scope) !== null && _h !== void 0 ? _h : 0;
1874
1919
  message.tags = ((_a = object.tags) === null || _a === void 0 ? void 0 : _a.map((e) => ingestion_pb_1.DocumentTag.fromPartial(e))) || [];
1875
1920
  message.sensitivityTags = ((_b = object.sensitivityTags) === null || _b === void 0 ? void 0 : _b.map((e) => e)) || [];
1876
- message.score = (_h = object.score) !== null && _h !== void 0 ? _h : 0;
1877
- message.matchedThreadCount = (_j = object.matchedThreadCount) !== null && _j !== void 0 ? _j : 0;
1921
+ message.score = (_j = object.score) !== null && _j !== void 0 ? _j : 0;
1922
+ message.matchedThreadCount = (_k = object.matchedThreadCount) !== null && _k !== void 0 ? _k : 0;
1878
1923
  message.snippets = ((_c = object.snippets) === null || _c === void 0 ? void 0 : _c.map((e) => exports.DocumentSearchSnippet.fromPartial(e))) || [];
1879
- message.uploadedAt = (_k = object.uploadedAt) !== null && _k !== void 0 ? _k : undefined;
1924
+ message.uploadedAt = (_l = object.uploadedAt) !== null && _l !== void 0 ? _l : undefined;
1925
+ message.restrictedGroups = ((_d = object.restrictedGroups) === null || _d === void 0 ? void 0 : _d.map((e) => ingestion_pb_1.RestrictedGroup.fromPartial(e))) || [];
1880
1926
  return message;
1881
1927
  },
1882
1928
  };
@@ -339,7 +339,7 @@ export interface ListOrganizationMembershipsForUserRow {
339
339
  updatedAt: Date;
340
340
  }
341
341
  export declare function listOrganizationMembershipsForUser(client: Client, args: ListOrganizationMembershipsForUserArgs): Promise<ListOrganizationMembershipsForUserRow[]>;
342
- export declare const listOrganizationMembersQuery = "-- name: ListOrganizationMembers :many\nSELECT\n m.id,\n m.user_id,\n m.organization_id,\n m.identity_link_id,\n l.stytch_member_id,\n m.status,\n m.role_ids,\n p.display_name,\n p.email,\n p.avatar_url,\n m.created_at,\n m.updated_at\nFROM weave.organization_memberships AS m\nJOIN weave.user_profiles AS p\n ON p.user_id = m.user_id\nLEFT JOIN weave.identity_links AS l\n ON l.id = m.identity_link_id\nWHERE m.organization_id = $1\nORDER BY p.display_name ASC, p.email ASC";
342
+ export declare const listOrganizationMembersQuery = "-- name: ListOrganizationMembers :many\nSELECT\n m.id,\n m.user_id,\n m.organization_id,\n m.identity_link_id,\n m.status,\n m.role_ids,\n p.display_name,\n p.email,\n p.avatar_url,\n m.created_at,\n m.updated_at\nFROM weave.organization_memberships AS m\nJOIN weave.user_profiles AS p\n ON p.user_id = m.user_id\nLEFT JOIN weave.identity_links AS l\n ON l.id = m.identity_link_id\nWHERE m.organization_id = $1\nORDER BY p.display_name ASC, p.email ASC";
343
343
  export interface ListOrganizationMembersArgs {
344
344
  organizationId: string;
345
345
  }
@@ -348,7 +348,6 @@ export interface ListOrganizationMembersRow {
348
348
  userId: string;
349
349
  organizationId: string;
350
350
  identityLinkId: string | null;
351
- stytchMemberId: string | null;
352
351
  status: string;
353
352
  roleIds: string[];
354
353
  displayName: string;
@@ -358,6 +357,28 @@ export interface ListOrganizationMembersRow {
358
357
  updatedAt: Date;
359
358
  }
360
359
  export declare function listOrganizationMembers(client: Client, args: ListOrganizationMembersArgs): Promise<ListOrganizationMembersRow[]>;
360
+ export declare const getOrganizationMemberAdminRecordQuery = "-- name: GetOrganizationMemberAdminRecord :one\nSELECT\n m.id AS organization_membership_id,\n m.user_id,\n m.organization_id,\n m.identity_link_id,\n m.status,\n m.role_ids,\n p.display_name,\n p.email,\n p.avatar_url,\n l.stytch_organization_id,\n l.stytch_member_id,\n l.stytch_member_email,\n m.created_at,\n m.updated_at\nFROM weave.organization_memberships AS m\nJOIN weave.user_profiles AS p\n ON p.user_id = m.user_id\nLEFT JOIN weave.identity_links AS l\n ON l.id = m.identity_link_id\nWHERE m.organization_id = $1\n AND m.id = $2";
361
+ export interface GetOrganizationMemberAdminRecordArgs {
362
+ organizationId: string;
363
+ organizationMembershipId: string;
364
+ }
365
+ export interface GetOrganizationMemberAdminRecordRow {
366
+ organizationMembershipId: string;
367
+ userId: string;
368
+ organizationId: string;
369
+ identityLinkId: string | null;
370
+ status: string;
371
+ roleIds: string[];
372
+ displayName: string;
373
+ email: string;
374
+ avatarUrl: string;
375
+ stytchOrganizationId: string | null;
376
+ stytchMemberId: string | null;
377
+ stytchMemberEmail: string | null;
378
+ createdAt: Date;
379
+ updatedAt: Date;
380
+ }
381
+ export declare function getOrganizationMemberAdminRecord(client: Client, args: GetOrganizationMemberAdminRecordArgs): Promise<GetOrganizationMemberAdminRecordRow | null>;
361
382
  export declare const listActivePlatformAdminGrantsForUserQuery = "-- name: ListActivePlatformAdminGrantsForUser :many\nSELECT\n id,\n user_id,\n platform_role,\n organization_id,\n all_organizations,\n allowed_actions,\n expires_at,\n status,\n created_at,\n updated_at\nFROM weave.platform_admin_grants\nWHERE user_id = $1\n AND status = 'active'\n AND (expires_at IS NULL OR expires_at > now())";
362
383
  export interface ListActivePlatformAdminGrantsForUserArgs {
363
384
  userId: string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deleteOrgTeamMembershipsQuery = exports.deleteOrgTeamQuery = exports.updateOrgTeamQuery = exports.listOrgTeamsQuery = exports.getOrgTeamQuery = exports.createOrgTeamQuery = exports.deleteExpiredAuthInviteSessionsQuery = exports.revokeAuthInviteSessionsByMemberQuery = exports.markAuthInviteSessionRecoveryRequiredQuery = exports.markAuthInviteSessionCompletedQuery = exports.setAuthInviteSessionOAuthStateQuery = exports.getAuthInviteSessionQuery = exports.createAuthInviteSessionQuery = exports.deleteExpiredApplicationSessionsQuery = exports.markApplicationSessionOrganizationSessionStateQuery = exports.listApplicationSessionOrganizationSessionStatesQuery = exports.getApplicationSessionOrganizationSessionQuery = exports.upsertApplicationSessionOrganizationSessionQuery = exports.revokeApplicationSessionQuery = exports.setApplicationSessionActiveOrganizationQuery = exports.getApplicationSessionQuery = exports.createApplicationSessionQuery = exports.insertAuthAuditEventQuery = exports.endSupportAccessSessionQuery = exports.createSupportAccessSessionQuery = exports.createPlatformAdminGrantQuery = exports.listActivePlatformAdminGrantsForUserQuery = exports.listOrganizationMembersQuery = exports.listOrganizationMembershipsForUserQuery = exports.getOrganizationMembershipQuery = exports.upsertOrganizationMembershipQuery = exports.upsertOrganizationAuthLinkQuery = exports.getOrganizationAuthLinkByOrganizationIDQuery = exports.getOrganizationAuthLinkByStytchIDQuery = exports.upsertIdentityLinkQuery = exports.getIdentityLinkByStytchMemberQuery = exports.getUserProfileQuery = exports.upsertUserProfileQuery = exports.deleteOrganizationAuthDomainQuery = exports.listOrganizationAuthDomainsQuery = exports.upsertOrganizationAuthDomainQuery = exports.resolvePrimaryOrganizationAuthLinkByDomainQuery = exports.updateUserProfileThemeQuery = exports.setUserOrganizationPagePositionQuery = exports.setUserLastOrganizationQuery = exports.getUserAuthPreferencesQuery = exports.getUserPrimaryOrganizationAuthLinkQuery = exports.setUserPrimaryOrganizationQuery = exports.getUserByIDQuery = exports.createUserQuery = void 0;
4
- exports.deleteOrgTeamMembershipsForOrganizationMemberQuery = exports.listEffectiveOrganizationRoleIDsQuery = exports.listOrgTeamRoleGrantsQuery = exports.listOrgTeamMembersQuery = exports.addOrgTeamRoleGrantQuery = exports.deleteOrgTeamRoleGrantsQuery = exports.addOrgTeamMembershipQuery = void 0;
3
+ exports.deleteOrgTeamQuery = exports.updateOrgTeamQuery = exports.listOrgTeamsQuery = exports.getOrgTeamQuery = exports.createOrgTeamQuery = exports.deleteExpiredAuthInviteSessionsQuery = exports.revokeAuthInviteSessionsByMemberQuery = exports.markAuthInviteSessionRecoveryRequiredQuery = exports.markAuthInviteSessionCompletedQuery = exports.setAuthInviteSessionOAuthStateQuery = exports.getAuthInviteSessionQuery = exports.createAuthInviteSessionQuery = exports.deleteExpiredApplicationSessionsQuery = exports.markApplicationSessionOrganizationSessionStateQuery = exports.listApplicationSessionOrganizationSessionStatesQuery = exports.getApplicationSessionOrganizationSessionQuery = exports.upsertApplicationSessionOrganizationSessionQuery = exports.revokeApplicationSessionQuery = exports.setApplicationSessionActiveOrganizationQuery = exports.getApplicationSessionQuery = exports.createApplicationSessionQuery = exports.insertAuthAuditEventQuery = exports.endSupportAccessSessionQuery = exports.createSupportAccessSessionQuery = exports.createPlatformAdminGrantQuery = exports.listActivePlatformAdminGrantsForUserQuery = exports.getOrganizationMemberAdminRecordQuery = exports.listOrganizationMembersQuery = exports.listOrganizationMembershipsForUserQuery = exports.getOrganizationMembershipQuery = exports.upsertOrganizationMembershipQuery = exports.upsertOrganizationAuthLinkQuery = exports.getOrganizationAuthLinkByOrganizationIDQuery = exports.getOrganizationAuthLinkByStytchIDQuery = exports.upsertIdentityLinkQuery = exports.getIdentityLinkByStytchMemberQuery = exports.getUserProfileQuery = exports.upsertUserProfileQuery = exports.deleteOrganizationAuthDomainQuery = exports.listOrganizationAuthDomainsQuery = exports.upsertOrganizationAuthDomainQuery = exports.resolvePrimaryOrganizationAuthLinkByDomainQuery = exports.updateUserProfileThemeQuery = exports.setUserOrganizationPagePositionQuery = exports.setUserLastOrganizationQuery = exports.getUserAuthPreferencesQuery = exports.getUserPrimaryOrganizationAuthLinkQuery = exports.setUserPrimaryOrganizationQuery = exports.getUserByIDQuery = exports.createUserQuery = void 0;
4
+ exports.deleteOrgTeamMembershipsForOrganizationMemberQuery = exports.listEffectiveOrganizationRoleIDsQuery = exports.listOrgTeamRoleGrantsQuery = exports.listOrgTeamMembersQuery = exports.addOrgTeamRoleGrantQuery = exports.deleteOrgTeamRoleGrantsQuery = exports.addOrgTeamMembershipQuery = exports.deleteOrgTeamMembershipsQuery = void 0;
5
5
  exports.createUser = createUser;
6
6
  exports.getUserByID = getUserByID;
7
7
  exports.setUserPrimaryOrganization = setUserPrimaryOrganization;
@@ -24,6 +24,7 @@ exports.upsertOrganizationMembership = upsertOrganizationMembership;
24
24
  exports.getOrganizationMembership = getOrganizationMembership;
25
25
  exports.listOrganizationMembershipsForUser = listOrganizationMembershipsForUser;
26
26
  exports.listOrganizationMembers = listOrganizationMembers;
27
+ exports.getOrganizationMemberAdminRecord = getOrganizationMemberAdminRecord;
27
28
  exports.listActivePlatformAdminGrantsForUser = listActivePlatformAdminGrantsForUser;
28
29
  exports.createPlatformAdminGrant = createPlatformAdminGrant;
29
30
  exports.createSupportAccessSession = createSupportAccessSession;
@@ -863,7 +864,6 @@ SELECT
863
864
  m.user_id,
864
865
  m.organization_id,
865
866
  m.identity_link_id,
866
- l.stytch_member_id,
867
867
  m.status,
868
868
  m.role_ids,
869
869
  p.display_name,
@@ -890,17 +890,66 @@ async function listOrganizationMembers(client, args) {
890
890
  userId: row[1],
891
891
  organizationId: row[2],
892
892
  identityLinkId: row[3],
893
- stytchMemberId: row[4],
894
- status: row[5],
895
- roleIds: row[6],
896
- displayName: row[7],
897
- email: row[8],
898
- avatarUrl: row[9],
899
- createdAt: row[10],
900
- updatedAt: row[11]
893
+ status: row[4],
894
+ roleIds: row[5],
895
+ displayName: row[6],
896
+ email: row[7],
897
+ avatarUrl: row[8],
898
+ createdAt: row[9],
899
+ updatedAt: row[10]
901
900
  };
902
901
  });
903
902
  }
903
+ exports.getOrganizationMemberAdminRecordQuery = `-- name: GetOrganizationMemberAdminRecord :one
904
+ SELECT
905
+ m.id AS organization_membership_id,
906
+ m.user_id,
907
+ m.organization_id,
908
+ m.identity_link_id,
909
+ m.status,
910
+ m.role_ids,
911
+ p.display_name,
912
+ p.email,
913
+ p.avatar_url,
914
+ l.stytch_organization_id,
915
+ l.stytch_member_id,
916
+ l.stytch_member_email,
917
+ m.created_at,
918
+ m.updated_at
919
+ FROM weave.organization_memberships AS m
920
+ JOIN weave.user_profiles AS p
921
+ ON p.user_id = m.user_id
922
+ LEFT JOIN weave.identity_links AS l
923
+ ON l.id = m.identity_link_id
924
+ WHERE m.organization_id = $1
925
+ AND m.id = $2`;
926
+ async function getOrganizationMemberAdminRecord(client, args) {
927
+ const result = await client.query({
928
+ text: exports.getOrganizationMemberAdminRecordQuery,
929
+ values: [args.organizationId, args.organizationMembershipId],
930
+ rowMode: "array"
931
+ });
932
+ if (result.rows.length !== 1) {
933
+ return null;
934
+ }
935
+ const row = result.rows[0];
936
+ return {
937
+ organizationMembershipId: row[0],
938
+ userId: row[1],
939
+ organizationId: row[2],
940
+ identityLinkId: row[3],
941
+ status: row[4],
942
+ roleIds: row[5],
943
+ displayName: row[6],
944
+ email: row[7],
945
+ avatarUrl: row[8],
946
+ stytchOrganizationId: row[9],
947
+ stytchMemberId: row[10],
948
+ stytchMemberEmail: row[11],
949
+ createdAt: row[12],
950
+ updatedAt: row[13]
951
+ };
952
+ }
904
953
  exports.listActivePlatformAdminGrantsForUserQuery = `-- name: ListActivePlatformAdminGrantsForUser :many
905
954
  SELECT
906
955
  id,
@@ -180,7 +180,7 @@ export interface ListConceptClustersByParentAndRealmRow {
180
180
  updatedAt: Date;
181
181
  }
182
182
  export declare function listConceptClustersByParentAndRealm(client: Client, args: ListConceptClustersByParentAndRealmArgs): Promise<ListConceptClustersByParentAndRealmRow[]>;
183
- export declare const listApprovedThreadsForConsolidationQuery = "-- name: ListApprovedThreadsForConsolidation :many\nSELECT\n t.id,\n t.organization_id,\n t.document_id,\n t.ingestion_run_id,\n t.text,\n t.knowledge_type,\n t.embedding::text AS embedding_text,\n t.approved_at,\n CASE\n WHEN d.scope = 'DOCUMENT_SCOPE_ORG'\n THEN 'KNOWLEDGE_REALM_KIND_ORG'::text\n WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n THEN 'KNOWLEDGE_REALM_KIND_TAG'::text\n WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n THEN 'KNOWLEDGE_REALM_KIND_USER'::text\n END AS realm_kind,\n CASE\n WHEN d.scope = 'DOCUMENT_SCOPE_ORG'\n THEN ''::text\n WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n THEN COALESCE(d.sensitivity_tags[1], ''::text)\n WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n THEN d.uploaded_by_user_id::text\n END AS realm_key\nFROM weave.threads t\nJOIN weave.documents d ON d.id = t.document_id\nWHERE t.organization_id = $1\n AND t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n AND t.embedding IS NOT NULL\nORDER BY t.approved_at DESC, t.id ASC\nLIMIT $3 OFFSET $2";
183
+ export declare const listApprovedThreadsForConsolidationQuery = "-- name: ListApprovedThreadsForConsolidation :many\nSELECT\n t.id,\n t.organization_id,\n t.document_id,\n t.ingestion_run_id,\n t.text,\n t.knowledge_type,\n t.embedding::text AS embedding_text,\n t.approved_at,\n CASE\n WHEN d.scope = 'DOCUMENT_SCOPE_ORG'\n THEN 'KNOWLEDGE_REALM_KIND_ORG'::text\n WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n THEN 'KNOWLEDGE_REALM_KIND_RESTRICTED_GROUP'::text\n WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n THEN 'KNOWLEDGE_REALM_KIND_USER'::text\n END AS realm_kind,\n CASE\n WHEN d.scope = 'DOCUMENT_SCOPE_ORG'\n THEN ''::text\n WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n THEN drg.restricted_group_id::text\n WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n THEN d.uploaded_by_user_id::text\n END AS realm_key\nFROM weave.threads t\nJOIN weave.documents d ON d.id = t.document_id\nLEFT JOIN weave.document_restricted_groups drg\n ON drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n AND d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\nWHERE t.organization_id = $1\n AND t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n AND t.embedding IS NOT NULL\n AND (d.scope <> 'DOCUMENT_SCOPE_RESTRICTED' OR drg.restricted_group_id IS NOT NULL)\nORDER BY t.approved_at DESC, t.id ASC\nLIMIT $3 OFFSET $2";
184
184
  export interface ListApprovedThreadsForConsolidationArgs {
185
185
  organizationId: string;
186
186
  pageOffset: string;
@@ -199,7 +199,7 @@ export interface ListApprovedThreadsForConsolidationRow {
199
199
  realmKey: string | null;
200
200
  }
201
201
  export declare function listApprovedThreadsForConsolidation(client: Client, args: ListApprovedThreadsForConsolidationArgs): Promise<ListApprovedThreadsForConsolidationRow[]>;
202
- export declare const assignThreadsToClusterQuery = "-- name: AssignThreadsToCluster :execrows\nUPDATE weave.threads AS t\nSET cluster_id = cc.id\nFROM weave.concept_clusters cc,\n weave.documents d\nWHERE t.organization_id = $1\n AND t.id = ANY($2::uuid[])\n AND cc.organization_id = t.organization_id\n AND cc.id = $3\n AND d.id = t.document_id\n AND (\n (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_ORG'\n AND cc.realm_key = ''\n AND d.scope = 'DOCUMENT_SCOPE_ORG')\n OR (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_TAG'\n AND d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n AND cardinality(d.sensitivity_tags) = 1\n AND cc.realm_key = d.sensitivity_tags[1])\n OR (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_USER'\n AND d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n AND cc.realm_key = d.uploaded_by_user_id::text)\n )";
202
+ export declare const assignThreadsToClusterQuery = "-- name: AssignThreadsToCluster :execrows\nUPDATE weave.threads AS t\nSET cluster_id = cc.id\nFROM weave.concept_clusters cc,\n weave.documents d\nWHERE t.organization_id = $1\n AND t.id = ANY($2::uuid[])\n AND cc.organization_id = t.organization_id\n AND cc.id = $3\n AND d.id = t.document_id\n AND (\n (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_ORG'\n AND cc.realm_key = ''\n AND d.scope = 'DOCUMENT_SCOPE_ORG')\n OR (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_RESTRICTED_GROUP'\n AND d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n AND EXISTS (\n SELECT 1\n FROM weave.document_restricted_groups drg\n WHERE drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n AND drg.restricted_group_id::text = cc.realm_key\n ))\n OR (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_USER'\n AND d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n AND cc.realm_key = d.uploaded_by_user_id::text)\n )";
203
203
  export interface AssignThreadsToClusterArgs {
204
204
  organizationId: string;
205
205
  threadIds: string[];
@@ -401,7 +401,7 @@ SELECT
401
401
  WHEN d.scope = 'DOCUMENT_SCOPE_ORG'
402
402
  THEN 'KNOWLEDGE_REALM_KIND_ORG'::text
403
403
  WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
404
- THEN 'KNOWLEDGE_REALM_KIND_TAG'::text
404
+ THEN 'KNOWLEDGE_REALM_KIND_RESTRICTED_GROUP'::text
405
405
  WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'
406
406
  THEN 'KNOWLEDGE_REALM_KIND_USER'::text
407
407
  END AS realm_kind,
@@ -409,15 +409,20 @@ SELECT
409
409
  WHEN d.scope = 'DOCUMENT_SCOPE_ORG'
410
410
  THEN ''::text
411
411
  WHEN d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
412
- THEN COALESCE(d.sensitivity_tags[1], ''::text)
412
+ THEN drg.restricted_group_id::text
413
413
  WHEN d.scope = 'DOCUMENT_SCOPE_PRIVATE'
414
414
  THEN d.uploaded_by_user_id::text
415
415
  END AS realm_key
416
416
  FROM weave.threads t
417
417
  JOIN weave.documents d ON d.id = t.document_id
418
+ LEFT JOIN weave.document_restricted_groups drg
419
+ ON drg.organization_id = d.organization_id
420
+ AND drg.document_id = d.id
421
+ AND d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
418
422
  WHERE t.organization_id = $1
419
423
  AND t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'
420
424
  AND t.embedding IS NOT NULL
425
+ AND (d.scope <> 'DOCUMENT_SCOPE_RESTRICTED' OR drg.restricted_group_id IS NOT NULL)
421
426
  ORDER BY t.approved_at DESC, t.id ASC
422
427
  LIMIT $3 OFFSET $2`;
423
428
  async function listApprovedThreadsForConsolidation(client, args) {
@@ -455,10 +460,15 @@ WHERE t.organization_id = $1
455
460
  (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_ORG'
456
461
  AND cc.realm_key = ''
457
462
  AND d.scope = 'DOCUMENT_SCOPE_ORG')
458
- OR (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_TAG'
463
+ OR (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_RESTRICTED_GROUP'
459
464
  AND d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
460
- AND cardinality(d.sensitivity_tags) = 1
461
- AND cc.realm_key = d.sensitivity_tags[1])
465
+ AND EXISTS (
466
+ SELECT 1
467
+ FROM weave.document_restricted_groups drg
468
+ WHERE drg.organization_id = d.organization_id
469
+ AND drg.document_id = d.id
470
+ AND drg.restricted_group_id::text = cc.realm_key
471
+ ))
462
472
  OR (cc.realm_kind = 'KNOWLEDGE_REALM_KIND_USER'
463
473
  AND d.scope = 'DOCUMENT_SCOPE_PRIVATE'
464
474
  AND cc.realm_key = d.uploaded_by_user_id::text)