@miniaxolotl/grove-server 1.11.16 → 1.11.20

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/migrate.js CHANGED
@@ -4,6 +4,21 @@ import { createRequire as __groveCreateRequire } from "node:module"; const requi
4
4
  import knex from "knex";
5
5
  import { Model, knexSnakeCaseMappers } from "objection";
6
6
 
7
+ // lib/database/src/writing-allowance-migration.ts
8
+ var writingAllowance = {
9
+ name: "20261107_041_writing_allowance",
10
+ async up(db2) {
11
+ await db2.raw(`
12
+ ALTER TABLE action_usage DROP CONSTRAINT action_usage_metric_check;
13
+ ALTER TABLE action_usage ADD CONSTRAINT action_usage_metric_check
14
+ CHECK(metric IN ('recall','ask','organization','assistance','writing'));
15
+ `);
16
+ },
17
+ async down() {
18
+ throw new Error("Use a forward migration");
19
+ }
20
+ };
21
+
7
22
  // lib/database/src/structured-document-migration.ts
8
23
  var structuredDocuments = {
9
24
  name: "20261105_036_structured_documents",
@@ -234,6 +249,71 @@ var nativeSharing = {
234
249
  }
235
250
  };
236
251
 
252
+ // lib/database/src/trial-migration.ts
253
+ var billingTrial = {
254
+ name: "20261107_040_billing_trial",
255
+ async up(db2) {
256
+ await db2.raw(`
257
+ CREATE TABLE billing_trials (
258
+ account_id uuid PRIMARY KEY REFERENCES accounts(id),
259
+ consumed_at timestamptz NOT NULL DEFAULT now(),
260
+ subscription_id text,
261
+ reset_by uuid REFERENCES accounts(id),
262
+ reset_at timestamptz
263
+ );
264
+ `);
265
+ await db2.raw(
266
+ "ALTER TABLE billing_trials ENABLE ROW LEVEL SECURITY"
267
+ );
268
+ await db2.raw("ALTER TABLE billing_trials FORCE ROW LEVEL SECURITY");
269
+ await db2.raw(
270
+ `CREATE POLICY tenant ON billing_trials USING (account_id = NULLIF(current_setting('grove.account_id',true),'')::uuid) WITH CHECK (account_id = NULLIF(current_setting('grove.account_id',true),'')::uuid)`
271
+ );
272
+ await db2.raw("GRANT SELECT, INSERT, UPDATE ON billing_trials TO grove_runtime");
273
+ await db2.raw("GRANT SELECT ON billing_trials TO grove_worker");
274
+ await db2.raw(`
275
+ CREATE FUNCTION grove_admin_trial_reset(target uuid, operation uuid, explanation text) RETURNS jsonb
276
+ LANGUAGE plpgsql SECURITY DEFINER SET search_path=pg_catalog,public,pg_temp AS $$
277
+ DECLARE actor uuid; previous public.system_admin_audit; original text; deleted integer;
278
+ BEGIN
279
+ actor := public.grove_admin_guard();
280
+ IF target IS NULL OR operation IS NULL OR explanation IS NULL OR length(trim(explanation)) NOT BETWEEN 3 AND 300 THEN
281
+ RAISE EXCEPTION 'invalid_request' USING ERRCODE='GA002';
282
+ END IF;
283
+ SELECT * INTO previous FROM public.system_admin_audit WHERE id=operation;
284
+ IF FOUND THEN
285
+ IF previous.kind<>'change' OR previous.actor_id IS DISTINCT FROM actor OR previous.account_id IS DISTINCT FROM target
286
+ OR previous.reason IS DISTINCT FROM explanation THEN
287
+ RAISE EXCEPTION 'operation_conflict' USING ERRCODE='GA003';
288
+ END IF;
289
+ RETURN previous.after;
290
+ END IF;
291
+ original := current_setting('grove.account_id',true);
292
+ PERFORM set_config('grove.account_id',target::text,true);
293
+ DELETE FROM public.billing_trials WHERE account_id=target;
294
+ GET DIAGNOSTICS deleted = ROW_COUNT;
295
+ PERFORM set_config('grove.account_id',COALESCE(original,''),true);
296
+ IF deleted = 0 THEN
297
+ RAISE EXCEPTION 'trial_not_consumed' USING ERRCODE='GA007';
298
+ END IF;
299
+ INSERT INTO public.system_admin_audit(id,actor_id,account_id,kind,reason,before,after)
300
+ VALUES(operation,actor,target,'change',explanation,
301
+ jsonb_build_object('trialEligible',false),
302
+ jsonb_build_object('trialEligible',true));
303
+ RETURN jsonb_build_object('accountId',target,'eligible',true);
304
+ EXCEPTION WHEN OTHERS THEN
305
+ IF original IS NOT NULL THEN PERFORM set_config('grove.account_id',original,true); END IF;
306
+ RAISE;
307
+ END $$;
308
+ REVOKE ALL ON FUNCTION grove_admin_trial_reset(uuid,uuid,text) FROM PUBLIC,grove_runtime,grove_worker;
309
+ GRANT EXECUTE ON FUNCTION grove_admin_trial_reset(uuid,uuid,text) TO grove_runtime;
310
+ `);
311
+ },
312
+ async down() {
313
+ throw new Error("Use a forward migration");
314
+ }
315
+ };
316
+
237
317
  // lib/database/src/action-usage-migration.ts
238
318
  var actionUsage = {
239
319
  name: "20261025_028_action_usage",
@@ -3617,7 +3697,9 @@ var migrations = [
3617
3697
  structuredDocuments,
3618
3698
  browserCapture,
3619
3699
  writingTools,
3620
- nativeSharing
3700
+ nativeSharing,
3701
+ billingTrial,
3702
+ writingAllowance
3621
3703
  ];
3622
3704
  var migrationSource = {
3623
3705
  getMigrations: async () => migrations,