weave-typescript 0.27.0 → 0.29.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.
@@ -0,0 +1,284 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listUserSensitivityClearancesQuery = exports.revokeUserSensitivityClearanceQuery = exports.grantUserSensitivityClearanceQuery = exports.deactivateOrganizationSensitivityTagQuery = exports.listActiveOrganizationSensitivityTagsQuery = exports.listOrganizationSensitivityTagsQuery = exports.upsertOrganizationSensitivityTagQuery = exports.setDocumentSecurityQuery = void 0;
4
+ exports.setDocumentSecurity = setDocumentSecurity;
5
+ exports.upsertOrganizationSensitivityTag = upsertOrganizationSensitivityTag;
6
+ exports.listOrganizationSensitivityTags = listOrganizationSensitivityTags;
7
+ exports.listActiveOrganizationSensitivityTags = listActiveOrganizationSensitivityTags;
8
+ exports.deactivateOrganizationSensitivityTag = deactivateOrganizationSensitivityTag;
9
+ exports.grantUserSensitivityClearance = grantUserSensitivityClearance;
10
+ exports.listUserSensitivityClearances = listUserSensitivityClearances;
11
+ exports.setDocumentSecurityQuery = `-- name: SetDocumentSecurity :one
12
+ UPDATE weave.documents
13
+ SET
14
+ scope = $1,
15
+ sensitivity_tags = $2,
16
+ updated_at = now()
17
+ WHERE organization_id = $3
18
+ AND id = $4
19
+ RETURNING
20
+ id,
21
+ organization_id,
22
+ filename,
23
+ mime_type,
24
+ parser_name,
25
+ fingerprint,
26
+ storage_ref,
27
+ status,
28
+ scope,
29
+ sensitivity_tags,
30
+ uploaded_by_user_id,
31
+ uploaded_at,
32
+ updated_at,
33
+ page_count,
34
+ char_count,
35
+ metadata`;
36
+ async function setDocumentSecurity(client, args) {
37
+ const result = await client.query({
38
+ text: exports.setDocumentSecurityQuery,
39
+ values: [args.scope, args.sensitivityTags, args.organizationId, args.documentId],
40
+ rowMode: "array"
41
+ });
42
+ if (result.rows.length !== 1) {
43
+ return null;
44
+ }
45
+ const row = result.rows[0];
46
+ return {
47
+ id: row[0],
48
+ organizationId: row[1],
49
+ filename: row[2],
50
+ mimeType: row[3],
51
+ parserName: row[4],
52
+ fingerprint: row[5],
53
+ storageRef: row[6],
54
+ status: row[7],
55
+ scope: row[8],
56
+ sensitivityTags: row[9],
57
+ uploadedByUserId: row[10],
58
+ uploadedAt: row[11],
59
+ updatedAt: row[12],
60
+ pageCount: row[13],
61
+ charCount: row[14],
62
+ metadata: row[15]
63
+ };
64
+ }
65
+ exports.upsertOrganizationSensitivityTagQuery = `-- name: UpsertOrganizationSensitivityTag :one
66
+ INSERT INTO weave.org_sensitivity_tags (
67
+ organization_id,
68
+ slug,
69
+ label,
70
+ description,
71
+ extraction_hint,
72
+ active
73
+ ) VALUES (
74
+ $1,
75
+ $2,
76
+ $3,
77
+ $4,
78
+ $5,
79
+ $6
80
+ )
81
+ ON CONFLICT (organization_id, slug) DO UPDATE
82
+ SET
83
+ label = EXCLUDED.label,
84
+ description = EXCLUDED.description,
85
+ extraction_hint = EXCLUDED.extraction_hint,
86
+ active = EXCLUDED.active,
87
+ updated_at = now()
88
+ RETURNING
89
+ organization_id,
90
+ slug,
91
+ label,
92
+ description,
93
+ extraction_hint,
94
+ active,
95
+ created_at,
96
+ updated_at`;
97
+ async function upsertOrganizationSensitivityTag(client, args) {
98
+ const result = await client.query({
99
+ text: exports.upsertOrganizationSensitivityTagQuery,
100
+ values: [args.organizationId, args.slug, args.label, args.description, args.extractionHint, args.active],
101
+ rowMode: "array"
102
+ });
103
+ if (result.rows.length !== 1) {
104
+ return null;
105
+ }
106
+ const row = result.rows[0];
107
+ return {
108
+ organizationId: row[0],
109
+ slug: row[1],
110
+ label: row[2],
111
+ description: row[3],
112
+ extractionHint: row[4],
113
+ active: row[5],
114
+ createdAt: row[6],
115
+ updatedAt: row[7]
116
+ };
117
+ }
118
+ exports.listOrganizationSensitivityTagsQuery = `-- name: ListOrganizationSensitivityTags :many
119
+ SELECT
120
+ organization_id,
121
+ slug,
122
+ label,
123
+ description,
124
+ extraction_hint,
125
+ active,
126
+ created_at,
127
+ updated_at
128
+ FROM weave.org_sensitivity_tags
129
+ WHERE organization_id = $1
130
+ ORDER BY slug ASC`;
131
+ async function listOrganizationSensitivityTags(client, args) {
132
+ const result = await client.query({
133
+ text: exports.listOrganizationSensitivityTagsQuery,
134
+ values: [args.organizationId],
135
+ rowMode: "array"
136
+ });
137
+ return result.rows.map(row => {
138
+ return {
139
+ organizationId: row[0],
140
+ slug: row[1],
141
+ label: row[2],
142
+ description: row[3],
143
+ extractionHint: row[4],
144
+ active: row[5],
145
+ createdAt: row[6],
146
+ updatedAt: row[7]
147
+ };
148
+ });
149
+ }
150
+ exports.listActiveOrganizationSensitivityTagsQuery = `-- name: ListActiveOrganizationSensitivityTags :many
151
+ SELECT
152
+ organization_id,
153
+ slug,
154
+ label,
155
+ description,
156
+ extraction_hint,
157
+ active,
158
+ created_at,
159
+ updated_at
160
+ FROM weave.org_sensitivity_tags
161
+ WHERE organization_id = $1
162
+ AND active = TRUE
163
+ ORDER BY slug ASC`;
164
+ async function listActiveOrganizationSensitivityTags(client, args) {
165
+ const result = await client.query({
166
+ text: exports.listActiveOrganizationSensitivityTagsQuery,
167
+ values: [args.organizationId],
168
+ rowMode: "array"
169
+ });
170
+ return result.rows.map(row => {
171
+ return {
172
+ organizationId: row[0],
173
+ slug: row[1],
174
+ label: row[2],
175
+ description: row[3],
176
+ extractionHint: row[4],
177
+ active: row[5],
178
+ createdAt: row[6],
179
+ updatedAt: row[7]
180
+ };
181
+ });
182
+ }
183
+ exports.deactivateOrganizationSensitivityTagQuery = `-- name: DeactivateOrganizationSensitivityTag :one
184
+ UPDATE weave.org_sensitivity_tags
185
+ SET
186
+ active = FALSE,
187
+ updated_at = now()
188
+ WHERE organization_id = $1
189
+ AND slug = $2
190
+ RETURNING
191
+ organization_id,
192
+ slug,
193
+ label,
194
+ description,
195
+ extraction_hint,
196
+ active,
197
+ created_at,
198
+ updated_at`;
199
+ async function deactivateOrganizationSensitivityTag(client, args) {
200
+ const result = await client.query({
201
+ text: exports.deactivateOrganizationSensitivityTagQuery,
202
+ values: [args.organizationId, args.slug],
203
+ rowMode: "array"
204
+ });
205
+ if (result.rows.length !== 1) {
206
+ return null;
207
+ }
208
+ const row = result.rows[0];
209
+ return {
210
+ organizationId: row[0],
211
+ slug: row[1],
212
+ label: row[2],
213
+ description: row[3],
214
+ extractionHint: row[4],
215
+ active: row[5],
216
+ createdAt: row[6],
217
+ updatedAt: row[7]
218
+ };
219
+ }
220
+ exports.grantUserSensitivityClearanceQuery = `-- name: GrantUserSensitivityClearance :one
221
+ INSERT INTO weave.user_sensitivity_clearances (
222
+ organization_id,
223
+ user_id,
224
+ sensitivity_tag_slug
225
+ ) VALUES (
226
+ $1,
227
+ $2,
228
+ $3
229
+ )
230
+ ON CONFLICT (organization_id, user_id, sensitivity_tag_slug) DO UPDATE
231
+ SET
232
+ sensitivity_tag_slug = EXCLUDED.sensitivity_tag_slug
233
+ RETURNING
234
+ organization_id,
235
+ user_id,
236
+ sensitivity_tag_slug,
237
+ created_at`;
238
+ async function grantUserSensitivityClearance(client, args) {
239
+ const result = await client.query({
240
+ text: exports.grantUserSensitivityClearanceQuery,
241
+ values: [args.organizationId, args.userId, args.sensitivityTagSlug],
242
+ rowMode: "array"
243
+ });
244
+ if (result.rows.length !== 1) {
245
+ return null;
246
+ }
247
+ const row = result.rows[0];
248
+ return {
249
+ organizationId: row[0],
250
+ userId: row[1],
251
+ sensitivityTagSlug: row[2],
252
+ createdAt: row[3]
253
+ };
254
+ }
255
+ exports.revokeUserSensitivityClearanceQuery = `-- name: RevokeUserSensitivityClearance :execrows
256
+ DELETE FROM weave.user_sensitivity_clearances
257
+ WHERE organization_id = $1
258
+ AND user_id = $2
259
+ AND sensitivity_tag_slug = $3`;
260
+ exports.listUserSensitivityClearancesQuery = `-- name: ListUserSensitivityClearances :many
261
+ SELECT
262
+ organization_id,
263
+ user_id,
264
+ sensitivity_tag_slug,
265
+ created_at
266
+ FROM weave.user_sensitivity_clearances
267
+ WHERE organization_id = $1
268
+ AND user_id = $2
269
+ ORDER BY sensitivity_tag_slug ASC`;
270
+ async function listUserSensitivityClearances(client, args) {
271
+ const result = await client.query({
272
+ text: exports.listUserSensitivityClearancesQuery,
273
+ values: [args.organizationId, args.userId],
274
+ rowMode: "array"
275
+ });
276
+ return result.rows.map(row => {
277
+ return {
278
+ organizationId: row[0],
279
+ userId: row[1],
280
+ sensitivityTagSlug: row[2],
281
+ createdAt: row[3]
282
+ };
283
+ });
284
+ }