@nextblock-cms/db 0.22.0 → 0.22.1

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 (26) hide show
  1. package/README.md +47 -47
  2. package/lib/supabase/server.d.ts +151 -2
  3. package/lib/supabase/types.d.ts +160 -2
  4. package/package.json +1 -1
  5. package/supabase/functions/nextblock-migration-ingest/index.ts +64 -1
  6. package/supabase/migrations/02000_catchup_gen1.sql +5880 -5880
  7. package/supabase/migrations/02001_baseline_schema.sql +2734 -2734
  8. package/supabase/migrations/02002_baseline_constraints_and_indexes.sql +1262 -1262
  9. package/supabase/migrations/02003_baseline_security_and_grants.sql +1577 -1577
  10. package/supabase/migrations/02004_baseline_seed.sql +565 -565
  11. package/supabase/migrations/02005_home_live_demo_promo_cadence_15min.sql +53 -53
  12. package/supabase/migrations/02006_home_marketing_contrast.sql +56 -56
  13. package/supabase/migrations/02007_home_pillar_caption_contrast.sql +44 -44
  14. package/supabase/migrations/02008_home_fr_parity.sql +89 -89
  15. package/supabase/migrations/02009_fr_cortex_posts.sql +67 -67
  16. package/supabase/migrations/02010_shop_hero_redesign.sql +72 -72
  17. package/supabase/migrations/02011_drop_backdrop_blur_on_pages.sql +26 -26
  18. package/supabase/migrations/02012_drop_variant_backdrop_blur.sql +17 -17
  19. package/supabase/migrations/02013_advisor_rls_and_trigger_grants.sql +102 -102
  20. package/supabase/migrations/02014_package_activations_staff_read.sql +18 -18
  21. package/supabase/migrations/02018_install_paths_and_seed_copy_accuracy.sql +1820 -1820
  22. package/supabase/migrations/02019_open_handed_licensing_and_mcp_clients.sql +448 -448
  23. package/supabase/migrations/02020_commerce_product_accuracy.sql +93 -93
  24. package/supabase/migrations/02021_profiles_staff_read_and_role_guard.sql +362 -362
  25. package/supabase/migrations/02022_security_hardening_writer_boundary_and_aal.sql +504 -0
  26. package/supabase/migrations/02023_aal2_for_orders_profiles_site_settings.sql +171 -0
package/README.md CHANGED
@@ -1,47 +1,47 @@
1
- # @nextblock-cms/db
2
-
3
- The database layer of [NextBlock](https://github.com/nextblock-cms/nextblock), the open-core CMS
4
- for Next.js and Supabase: Supabase clients for each trust level, the generated `Database` types,
5
- secret encryption, and the premium-package license check. It also ships the NextBlock database
6
- migrations.
7
-
8
- Projects created with `npm create nextblock@latest` already depend on it. It is built for
9
- NextBlock projects (Next.js 16, React 19, `@supabase/ssr`) rather than as a general-purpose
10
- library.
11
-
12
- ```bash
13
- npm install @nextblock-cms/db
14
- ```
15
-
16
- ## Entry points
17
-
18
- | Import | Use it from | What it holds |
19
- | :-- | :-- | :-- |
20
- | `@nextblock-cms/db` | client | The browser Supabase client (`createClient`), the `Database` types, and client-side profile and language lookups |
21
- | `@nextblock-cms/db/server` | server only | `createClient()` scoped to the request cookies, `getSsgSupabaseClient()` for public reads, `getServiceRoleSupabaseClient()` for admin work only (it bypasses Row Level Security), `verifyPackageOnline()`, secret encryption and config resolution |
22
- | `@nextblock-cms/db/secrets` | server only | Secret encryption (`encryptSecret`, `decryptSecret`) and config resolution, without the Supabase clients |
23
- | `@nextblock-cms/db/types` | types only | The generated `Database` types |
24
-
25
- Pick the server client by trust level. Use the service-role client only in code that has
26
- already checked the caller's role.
27
-
28
- ## Environment
29
-
30
- The clients read `NEXT_PUBLIC_SUPABASE_URL` or `SUPABASE_URL`, the publishable (anon) key under
31
- either its `NEXT_PUBLIC_` or its plain name, and, for the service-role client,
32
- `SUPABASE_SERVICE_ROLE_KEY` or `SUPABASE_SECRET_KEY`. The alternative names are the ones the
33
- Vercel Supabase integration injects.
34
-
35
- ## Migrations
36
-
37
- The package includes `supabase/` with the NextBlock migrations. `npm run update` in a NextBlock
38
- project copies them into the project's `supabase/migrations` and applies the pending ones.
39
-
40
- ## Documentation
41
-
42
- - [Database and auth](https://github.com/nextblock-cms/nextblock/blob/master/docs/04-DATABASE-AND-AUTH.md)
43
- - [Staying up to date](https://github.com/nextblock-cms/nextblock/blob/master/docs/13-STAYING-UP-TO-DATE.md)
44
-
45
- ## License
46
-
47
- AGPL-3.0-or-later.
1
+ # @nextblock-cms/db
2
+
3
+ The database layer of [NextBlock](https://github.com/nextblock-cms/nextblock), the open-core CMS
4
+ for Next.js and Supabase: Supabase clients for each trust level, the generated `Database` types,
5
+ secret encryption, and the premium-package license check. It also ships the NextBlock database
6
+ migrations.
7
+
8
+ Projects created with `npm create nextblock@latest` already depend on it. It is built for
9
+ NextBlock projects (Next.js 16, React 19, `@supabase/ssr`) rather than as a general-purpose
10
+ library.
11
+
12
+ ```bash
13
+ npm install @nextblock-cms/db
14
+ ```
15
+
16
+ ## Entry points
17
+
18
+ | Import | Use it from | What it holds |
19
+ | :-- | :-- | :-- |
20
+ | `@nextblock-cms/db` | client | The browser Supabase client (`createClient`), the `Database` types, and client-side profile and language lookups |
21
+ | `@nextblock-cms/db/server` | server only | `createClient()` scoped to the request cookies, `getSsgSupabaseClient()` for public reads, `getServiceRoleSupabaseClient()` for admin work only (it bypasses Row Level Security), `verifyPackageOnline()`, secret encryption and config resolution |
22
+ | `@nextblock-cms/db/secrets` | server only | Secret encryption (`encryptSecret`, `decryptSecret`) and config resolution, without the Supabase clients |
23
+ | `@nextblock-cms/db/types` | types only | The generated `Database` types |
24
+
25
+ Pick the server client by trust level. Use the service-role client only in code that has
26
+ already checked the caller's role.
27
+
28
+ ## Environment
29
+
30
+ The clients read `NEXT_PUBLIC_SUPABASE_URL` or `SUPABASE_URL`, the publishable (anon) key under
31
+ either its `NEXT_PUBLIC_` or its plain name, and, for the service-role client,
32
+ `SUPABASE_SERVICE_ROLE_KEY` or `SUPABASE_SECRET_KEY`. The alternative names are the ones the
33
+ Vercel Supabase integration injects.
34
+
35
+ ## Migrations
36
+
37
+ The package includes `supabase/` with the NextBlock migrations. `npm run update` in a NextBlock
38
+ project copies them into the project's `supabase/migrations` and applies the pending ones.
39
+
40
+ ## Documentation
41
+
42
+ - [Database and auth](https://github.com/nextblock-cms/nextblock/blob/master/docs/04-DATABASE-AND-AUTH.md)
43
+ - [Staying up to date](https://github.com/nextblock-cms/nextblock/blob/master/docs/13-STAYING-UP-TO-DATE.md)
44
+
45
+ ## License
46
+
47
+ AGPL-3.0-or-later.
@@ -118,6 +118,11 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
118
118
  type: Database["public"]["Enums"]["interaction_type"];
119
119
  updated_at: string;
120
120
  user_id: string;
121
+ author: {
122
+ avatar_url: string | null;
123
+ full_name: string | null;
124
+ id: string | null;
125
+ } | null;
121
126
  };
122
127
  Insert: {
123
128
  content: string;
@@ -165,6 +170,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
165
170
  isOneToOne: false;
166
171
  referencedRelation: "products";
167
172
  referencedColumns: ["id"];
173
+ }, {
174
+ foreignKeyName: "cms_interactions_user_id_profiles_fkey";
175
+ columns: ["user_id"];
176
+ isOneToOne: false;
177
+ referencedRelation: "profile_cards";
178
+ referencedColumns: ["id"];
168
179
  }, {
169
180
  foreignKeyName: "cms_interactions_user_id_profiles_fkey";
170
181
  columns: ["user_id"];
@@ -238,6 +249,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
238
249
  updated_at?: string;
239
250
  };
240
251
  Relationships: [{
252
+ foreignKeyName: "content_drafts_author_id_fkey";
253
+ columns: ["author_id"];
254
+ isOneToOne: false;
255
+ referencedRelation: "profile_cards";
256
+ referencedColumns: ["id"];
257
+ }, {
241
258
  foreignKeyName: "content_drafts_author_id_fkey";
242
259
  columns: ["author_id"];
243
260
  isOneToOne: false;
@@ -289,6 +306,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
289
306
  tool_name?: string;
290
307
  };
291
308
  Relationships: [{
309
+ foreignKeyName: "cortex_ai_db_mutation_audit_actor_user_id_fkey";
310
+ columns: ["actor_user_id"];
311
+ isOneToOne: false;
312
+ referencedRelation: "profile_cards";
313
+ referencedColumns: ["id"];
314
+ }, {
292
315
  foreignKeyName: "cortex_ai_db_mutation_audit_actor_user_id_fkey";
293
316
  columns: ["actor_user_id"];
294
317
  isOneToOne: false;
@@ -296,6 +319,27 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
296
319
  referencedColumns: ["id"];
297
320
  }];
298
321
  };
322
+ cortex_request_log: {
323
+ Row: {
324
+ created_at: string;
325
+ id: string;
326
+ route: string;
327
+ user_id: string;
328
+ };
329
+ Insert: {
330
+ created_at?: string;
331
+ id?: string;
332
+ route: string;
333
+ user_id: string;
334
+ };
335
+ Update: {
336
+ created_at?: string;
337
+ id?: string;
338
+ route?: string;
339
+ user_id?: string;
340
+ };
341
+ Relationships: [];
342
+ };
299
343
  coupon_freemius_mappings: {
300
344
  Row: {
301
345
  coupon_id: string;
@@ -577,6 +621,7 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
577
621
  };
578
622
  email_2fa_challenges: {
579
623
  Row: {
624
+ attempts: number;
580
625
  consumed_at: string | null;
581
626
  created_at: string;
582
627
  expires_at: string;
@@ -585,6 +630,7 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
585
630
  user_id: string;
586
631
  };
587
632
  Insert: {
633
+ attempts?: number;
588
634
  consumed_at?: string | null;
589
635
  created_at?: string;
590
636
  expires_at: string;
@@ -593,6 +639,7 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
593
639
  user_id: string;
594
640
  };
595
641
  Update: {
642
+ attempts?: number;
596
643
  consumed_at?: string | null;
597
644
  created_at?: string;
598
645
  expires_at?: string;
@@ -883,6 +930,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
883
930
  width?: number | null;
884
931
  };
885
932
  Relationships: [{
933
+ foreignKeyName: "media_uploader_id_fkey";
934
+ columns: ["uploader_id"];
935
+ isOneToOne: false;
936
+ referencedRelation: "profile_cards";
937
+ referencedColumns: ["id"];
938
+ }, {
886
939
  foreignKeyName: "media_uploader_id_fkey";
887
940
  columns: ["uploader_id"];
888
941
  isOneToOne: false;
@@ -1237,6 +1290,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
1237
1290
  version?: number;
1238
1291
  };
1239
1292
  Relationships: [{
1293
+ foreignKeyName: "page_revisions_author_id_fkey";
1294
+ columns: ["author_id"];
1295
+ isOneToOne: false;
1296
+ referencedRelation: "profile_cards";
1297
+ referencedColumns: ["id"];
1298
+ }, {
1240
1299
  foreignKeyName: "page_revisions_author_id_fkey";
1241
1300
  columns: ["author_id"];
1242
1301
  isOneToOne: false;
@@ -1303,6 +1362,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
1303
1362
  version?: number;
1304
1363
  };
1305
1364
  Relationships: [{
1365
+ foreignKeyName: "pages_author_id_fkey";
1366
+ columns: ["author_id"];
1367
+ isOneToOne: false;
1368
+ referencedRelation: "profile_cards";
1369
+ referencedColumns: ["id"];
1370
+ }, {
1306
1371
  foreignKeyName: "pages_author_id_fkey";
1307
1372
  columns: ["author_id"];
1308
1373
  isOneToOne: false;
@@ -1351,6 +1416,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
1351
1416
  version?: number;
1352
1417
  };
1353
1418
  Relationships: [{
1419
+ foreignKeyName: "post_revisions_author_id_fkey";
1420
+ columns: ["author_id"];
1421
+ isOneToOne: false;
1422
+ referencedRelation: "profile_cards";
1423
+ referencedColumns: ["id"];
1424
+ }, {
1354
1425
  foreignKeyName: "post_revisions_author_id_fkey";
1355
1426
  columns: ["author_id"];
1356
1427
  isOneToOne: false;
@@ -1426,6 +1497,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
1426
1497
  version?: number;
1427
1498
  };
1428
1499
  Relationships: [{
1500
+ foreignKeyName: "posts_author_id_fkey";
1501
+ columns: ["author_id"];
1502
+ isOneToOne: false;
1503
+ referencedRelation: "profile_cards";
1504
+ referencedColumns: ["id"];
1505
+ }, {
1429
1506
  foreignKeyName: "posts_author_id_fkey";
1430
1507
  columns: ["author_id"];
1431
1508
  isOneToOne: false;
@@ -1594,6 +1671,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
1594
1671
  updated_at?: string;
1595
1672
  };
1596
1673
  Relationships: [{
1674
+ foreignKeyName: "product_drafts_author_id_fkey";
1675
+ columns: ["author_id"];
1676
+ isOneToOne: false;
1677
+ referencedRelation: "profile_cards";
1678
+ referencedColumns: ["id"];
1679
+ }, {
1597
1680
  foreignKeyName: "product_drafts_author_id_fkey";
1598
1681
  columns: ["author_id"];
1599
1682
  isOneToOne: false;
@@ -1777,6 +1860,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
1777
1860
  version?: number;
1778
1861
  };
1779
1862
  Relationships: [{
1863
+ foreignKeyName: "product_revisions_author_id_fkey";
1864
+ columns: ["author_id"];
1865
+ isOneToOne: false;
1866
+ referencedRelation: "profile_cards";
1867
+ referencedColumns: ["id"];
1868
+ }, {
1780
1869
  foreignKeyName: "product_revisions_author_id_fkey";
1781
1870
  columns: ["author_id"];
1782
1871
  isOneToOne: false;
@@ -2431,6 +2520,7 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
2431
2520
  };
2432
2521
  ucp_cart_sessions: {
2433
2522
  Row: {
2523
+ access_token_hash: string | null;
2434
2524
  attribution: import('./types').Json;
2435
2525
  buyer_identity: import('./types').Json;
2436
2526
  checkout_url: string | null;
@@ -2448,6 +2538,7 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
2448
2538
  updated_at: string;
2449
2539
  };
2450
2540
  Insert: {
2541
+ access_token_hash?: string | null;
2451
2542
  attribution?: import('./types').Json;
2452
2543
  buyer_identity?: import('./types').Json;
2453
2544
  checkout_url?: string | null;
@@ -2465,6 +2556,7 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
2465
2556
  updated_at?: string;
2466
2557
  };
2467
2558
  Update: {
2559
+ access_token_hash?: string | null;
2468
2560
  attribution?: import('./types').Json;
2469
2561
  buyer_identity?: import('./types').Json;
2470
2562
  checkout_url?: string | null;
@@ -2533,6 +2625,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
2533
2625
  user_id?: string;
2534
2626
  };
2535
2627
  Relationships: [{
2628
+ foreignKeyName: "user_addresses_user_id_fkey";
2629
+ columns: ["user_id"];
2630
+ isOneToOne: false;
2631
+ referencedRelation: "profile_cards";
2632
+ referencedColumns: ["id"];
2633
+ }, {
2536
2634
  foreignKeyName: "user_addresses_user_id_fkey";
2537
2635
  columns: ["user_id"];
2538
2636
  isOneToOne: false;
@@ -2616,7 +2714,26 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
2616
2714
  }];
2617
2715
  };
2618
2716
  };
2619
- Views: { [_ in never]: never; };
2717
+ Views: {
2718
+ profile_cards: {
2719
+ Row: {
2720
+ avatar_url: string | null;
2721
+ full_name: string | null;
2722
+ id: string | null;
2723
+ };
2724
+ Insert: {
2725
+ avatar_url?: string | null;
2726
+ full_name?: string | null;
2727
+ id?: string | null;
2728
+ };
2729
+ Update: {
2730
+ avatar_url?: string | null;
2731
+ full_name?: string | null;
2732
+ id?: string | null;
2733
+ };
2734
+ Relationships: [];
2735
+ };
2736
+ };
2620
2737
  Functions: {
2621
2738
  apply_order_inventory_deduction: {
2622
2739
  Args: {
@@ -2634,6 +2751,28 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
2634
2751
  paid_at: string;
2635
2752
  }[];
2636
2753
  };
2754
+ author: {
2755
+ Args: {
2756
+ "": Database["public"]["Tables"]["cms_interactions"]["Row"];
2757
+ };
2758
+ Returns: {
2759
+ avatar_url: string | null;
2760
+ full_name: string | null;
2761
+ id: string | null;
2762
+ };
2763
+ SetofOptions: {
2764
+ from: "cms_interactions";
2765
+ to: "profile_cards";
2766
+ isOneToOne: true;
2767
+ isSetofReturn: true;
2768
+ };
2769
+ };
2770
+ bump_email_2fa_attempts: {
2771
+ Args: {
2772
+ p_user_id: string;
2773
+ };
2774
+ Returns: number;
2775
+ };
2637
2776
  clear_currency_price_overrides: {
2638
2777
  Args: {
2639
2778
  target_currency: string;
@@ -2692,6 +2831,10 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
2692
2831
  Args: never;
2693
2832
  Returns: boolean;
2694
2833
  };
2834
+ is_admin_mfa: {
2835
+ Args: never;
2836
+ Returns: boolean;
2837
+ };
2695
2838
  is_valid_currency_amount_map: {
2696
2839
  Args: {
2697
2840
  amounts: import('./types').Json;
@@ -2723,6 +2866,12 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
2723
2866
  };
2724
2867
  Returns: import('./types').Json;
2725
2868
  };
2869
+ redeem_coupon_atomically: {
2870
+ Args: {
2871
+ p_coupon_id: string;
2872
+ };
2873
+ Returns: boolean;
2874
+ };
2726
2875
  sync_inventory_cache_for_sku: {
2727
2876
  Args: {
2728
2877
  p_sku: string;
@@ -2752,6 +2901,6 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
2752
2901
  };
2753
2902
  CompositeTypes: { [_ in never]: never; };
2754
2903
  }, {
2755
- PostgrestVersion: "14.5";
2904
+ PostgrestVersion: "14.1";
2756
2905
  }>;
2757
2906
  export {};