@nextblock-cms/db 0.0.3 → 0.0.5

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/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@supabase/ssr"),t=require("next/server"),p=require("@supabase/supabase-js"),u=()=>{const e=process.env.NEXT_PUBLIC_SUPABASE_URL,s=process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;if(!e||!s)throw new Error(`CRITICAL: Supabase URL or Anon Key is missing. Please ensure NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY are set in your production environment. URL_IS_SET: ${!!e}, ANON_KEY_IS_SET: ${!!s}`);return l.createBrowserClient(e,s)};async function S(e,s){const{data:r,error:n}=await e.from("profiles").select("id, full_name, avatar_url, role, updated_at, username, website").eq("id",s).single();return n||!r?null:r}async function E(){const e=u(),{data:s,error:r}=await e.from("languages").select("id, code, name, is_default, is_active, created_at, updated_at").order("name",{ascending:!0});return r?[]:s||[]}const A=async e=>{try{let s=t.NextResponse.next({request:{headers:e.headers}});const r=process.env.NEXT_PUBLIC_SUPABASE_URL,n=process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;if(!r||!n)throw new Error("Missing Supabase environment variables");const i=await l.createServerClient(r,n,{cookies:{getAll(){return e.cookies.getAll()},setAll(c){c.forEach(({name:a,value:o})=>e.cookies.set(a,o)),s=t.NextResponse.next({request:e}),c.forEach(({name:a,value:o,options:_})=>s.cookies.set(a,o,_))}}}).auth.getUser();return e.nextUrl.pathname.startsWith("/protected")&&i.error?t.NextResponse.redirect(new URL("/sign-in",e.url)):e.nextUrl.pathname==="/"&&!i.error?t.NextResponse.redirect(new URL("/protected",e.url)):s}catch{return t.NextResponse.next({request:{headers:e.headers}})}},d=()=>!process.env.NEXT_PUBLIC_SUPABASE_URL||!process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY?(console.warn("Supabase URL or Anon Key is missing for SSG client. Check .env.local"),{}):p.createClient(process.env.NEXT_PUBLIC_SUPABASE_URL,process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY),U={public:{Enums:{menu_location:["HEADER","FOOTER","SIDEBAR"],page_status:["draft","published","archived"],revision_type:["snapshot","diff"],user_role:["ADMIN","WRITER","USER"]}}};exports.Constants=U;exports.createClient=u;exports.getActiveLanguagesClientSide=E;exports.getProfileWithRoleClientSide=S;exports.getSsgSupabaseClient=d;exports.updateSession=A;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@supabase/ssr"),s=require("next/server"),_=require("./ssg-client-CiaENGEv.js"),u=()=>{const e=process.env.NEXT_PUBLIC_SUPABASE_URL,t=process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;if(!e||!t)throw new Error(`CRITICAL: Supabase URL or Anon Key is missing. Please ensure NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY are set in your production environment. URL_IS_SET: ${!!e}, ANON_KEY_IS_SET: ${!!t}`);return l.createBrowserClient(e,t)};async function d(e,t){const{data:r,error:n}=await e.from("profiles").select("id, full_name, avatar_url, role, updated_at, username, website").eq("id",t).single();return n||!r?null:r}async function S(){const e=u(),{data:t,error:r}=await e.from("languages").select("id, code, name, is_default, is_active, created_at, updated_at").order("name",{ascending:!0});return r?[]:t||[]}const E=async e=>{try{let t=s.NextResponse.next({request:{headers:e.headers}});const r=process.env.NEXT_PUBLIC_SUPABASE_URL,n=process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;if(!r||!n)throw new Error("Missing Supabase environment variables");const i=await l.createServerClient(r,n,{cookies:{getAll(){return e.cookies.getAll()},setAll(c){c.forEach(({name:a,value:o})=>e.cookies.set(a,o)),t=s.NextResponse.next({request:e}),c.forEach(({name:a,value:o,options:p})=>t.cookies.set(a,o,p))}}}).auth.getUser();return e.nextUrl.pathname.startsWith("/protected")&&i.error?s.NextResponse.redirect(new URL("/sign-in",e.url)):e.nextUrl.pathname==="/"&&!i.error?s.NextResponse.redirect(new URL("/protected",e.url)):t}catch{return s.NextResponse.next({request:{headers:e.headers}})}},A={public:{Enums:{menu_location:["HEADER","FOOTER","SIDEBAR"],page_status:["draft","published","archived"],revision_type:["snapshot","diff"],user_role:["ADMIN","WRITER","USER"]}}};exports.getSsgSupabaseClient=_.getSsgSupabaseClient;exports.Constants=A;exports.createClient=u;exports.getActiveLanguagesClientSide=S;exports.getProfileWithRoleClientSide=d;exports.updateSession=E;
package/index.es.js CHANGED
@@ -1,34 +1,34 @@
1
- import { createBrowserClient as l, createServerClient as u } from "@supabase/ssr";
2
- import { NextResponse as t } from "next/server";
3
- import { createClient as p } from "@supabase/supabase-js";
4
- const E = () => {
1
+ import { createBrowserClient as u, createServerClient as _ } from "@supabase/ssr";
2
+ import { NextResponse as n } from "next/server";
3
+ import { g as N } from "./ssg-client-DgUYZgPq.mjs";
4
+ const p = () => {
5
5
  const e = process.env.NEXT_PUBLIC_SUPABASE_URL, r = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
6
6
  if (!e || !r)
7
7
  throw new Error(
8
8
  `CRITICAL: Supabase URL or Anon Key is missing. Please ensure NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY are set in your production environment. URL_IS_SET: ${!!e}, ANON_KEY_IS_SET: ${!!r}`
9
9
  );
10
- return l(e, r);
10
+ return u(e, r);
11
11
  };
12
- async function f(e, r) {
13
- const { data: n, error: s } = await e.from("profiles").select("id, full_name, avatar_url, role, updated_at, username, website").eq("id", r).single();
14
- return s || !n ? null : n;
12
+ async function S(e, r) {
13
+ const { data: t, error: s } = await e.from("profiles").select("id, full_name, avatar_url, role, updated_at, username, website").eq("id", r).single();
14
+ return s || !t ? null : t;
15
15
  }
16
- async function N() {
17
- const e = E(), { data: r, error: n } = await e.from("languages").select("id, code, name, is_default, is_active, created_at, updated_at").order("name", { ascending: !0 });
18
- return n ? [] : r || [];
16
+ async function U() {
17
+ const e = p(), { data: r, error: t } = await e.from("languages").select("id, code, name, is_default, is_active, created_at, updated_at").order("name", { ascending: !0 });
18
+ return t ? [] : r || [];
19
19
  }
20
- const B = async (e) => {
20
+ const f = async (e) => {
21
21
  try {
22
- let r = t.next({
22
+ let r = n.next({
23
23
  request: {
24
24
  headers: e.headers
25
25
  }
26
26
  });
27
- const n = process.env.NEXT_PUBLIC_SUPABASE_URL, s = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
28
- if (!n || !s)
27
+ const t = process.env.NEXT_PUBLIC_SUPABASE_URL, s = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
28
+ if (!t || !s)
29
29
  throw new Error("Missing Supabase environment variables");
30
- const i = await u(
31
- n,
30
+ const i = await _(
31
+ t,
32
32
  s,
33
33
  {
34
34
  cookies: {
@@ -38,27 +38,24 @@ const B = async (e) => {
38
38
  setAll(c) {
39
39
  c.forEach(
40
40
  ({ name: a, value: o }) => e.cookies.set(a, o)
41
- ), r = t.next({
41
+ ), r = n.next({
42
42
  request: e
43
43
  }), c.forEach(
44
- ({ name: a, value: o, options: _ }) => r.cookies.set(a, o, _)
44
+ ({ name: a, value: o, options: l }) => r.cookies.set(a, o, l)
45
45
  );
46
46
  }
47
47
  }
48
48
  }
49
49
  ).auth.getUser();
50
- return e.nextUrl.pathname.startsWith("/protected") && i.error ? t.redirect(new URL("/sign-in", e.url)) : e.nextUrl.pathname === "/" && !i.error ? t.redirect(new URL("/protected", e.url)) : r;
50
+ return e.nextUrl.pathname.startsWith("/protected") && i.error ? n.redirect(new URL("/sign-in", e.url)) : e.nextUrl.pathname === "/" && !i.error ? n.redirect(new URL("/protected", e.url)) : r;
51
51
  } catch {
52
- return t.next({
52
+ return n.next({
53
53
  request: {
54
54
  headers: e.headers
55
55
  }
56
56
  });
57
57
  }
58
- }, C = () => !process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY ? (console.warn("Supabase URL or Anon Key is missing for SSG client. Check .env.local"), {}) : p(
59
- process.env.NEXT_PUBLIC_SUPABASE_URL,
60
- process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
61
- ), L = {
58
+ }, g = {
62
59
  public: {
63
60
  Enums: {
64
61
  menu_location: ["HEADER", "FOOTER", "SIDEBAR"],
@@ -69,10 +66,10 @@ const B = async (e) => {
69
66
  }
70
67
  };
71
68
  export {
72
- L as Constants,
73
- E as createClient,
74
- N as getActiveLanguagesClientSide,
75
- f as getProfileWithRoleClientSide,
76
- C as getSsgSupabaseClient,
77
- B as updateSession
69
+ g as Constants,
70
+ p as createClient,
71
+ U as getActiveLanguagesClientSide,
72
+ S as getProfileWithRoleClientSide,
73
+ N as getSsgSupabaseClient,
74
+ f as updateSession
78
75
  };
@@ -2,7 +2,7 @@ import { SupabaseClient } from '@supabase/supabase-js';
2
2
  import { Database } from './types';
3
3
  type Profile = Database['public']['Tables']['profiles']['Row'];
4
4
  type Language = Database['public']['Tables']['languages']['Row'];
5
- export declare const createClient: () => SupabaseClient<any, "public", any>;
5
+ export declare const createClient: () => SupabaseClient<any, "public", "public", any, any>;
6
6
  export declare function getProfileWithRoleClientSide(supabase: SupabaseClient, // Accept the client instance
7
7
  userId: string): Promise<Profile | null>;
8
8
  export declare function getActiveLanguagesClientSide(): Promise<Language[]>;
@@ -1,7 +1,7 @@
1
1
  import { Database } from './types';
2
2
  type Profile = Database['public']['Tables']['profiles']['Row'];
3
3
  type Language = Database['public']['Tables']['languages']['Row'];
4
- export declare const createClient: () => import('@supabase/supabase-js').SupabaseClient<any, "public", any>;
4
+ export declare const createClient: () => import('@supabase/supabase-js').SupabaseClient<any, "public", "public", any, any>;
5
5
  export declare function getProfileWithRoleServerSide(userId: string): Promise<Profile | null>;
6
6
  export declare function getActiveLanguagesServerSide(): Promise<Language[]>;
7
7
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextblock-cms/db",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "main": "index.cjs.js",
5
5
  "module": "index.es.js",
6
6
  "types": "index.d.ts",
package/server.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@supabase/ssr"),u=require("next/headers"),l=require("@supabase/supabase-js");var S={},i;function v(){if(i)return S;throw i=1,new Error("This module cannot be imported from a Client Component module. It should only be used from a Server Component.")}v();const a=()=>{const s=u.cookies(),t=process.env.NEXT_PUBLIC_SUPABASE_URL,r=process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;if(!t||!r)throw new Error("Missing Supabase environment variables");return c.createServerClient(t,r,{cookies:{async get(e){var o;return(o=(await s).get(e))==null?void 0:o.value},set(e,n,o){s.set({name:e,value:n,...o})},remove(e,n){s.set({name:e,value:"",...n})}}})};async function d(s){const t=a(),{data:r,error:e}=await t.from("profiles").select("id, full_name, avatar_url, role, updated_at, username, website").eq("id",s).single();return e||!r?(console.error("Error fetching profile (server-side):",e==null?void 0:e.message),null):r}async function g(){const s=a(),{data:t,error:r}=await s.from("languages").select("id, code, name, is_default, is_active, created_at, updated_at").order("name",{ascending:!0});return r?(console.error("Error fetching languages (server-side):",r.message),[]):t||[]}const _=()=>{if(!process.env.NEXT_PUBLIC_SUPABASE_URL||!process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY)throw new Error("Supabase URL or Anon Key is missing for SSG client. Check .env.local");return l.createClient(process.env.NEXT_PUBLIC_SUPABASE_URL,process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY)};exports.createClient=a;exports.getActiveLanguagesServerSide=g;exports.getProfileWithRoleServerSide=d;exports.getSsgSupabaseClient=_;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@supabase/ssr"),c=require("next/headers"),u=require("./ssg-client-CiaENGEv.js"),d="This module cannot be imported from a Client Component module. It should only be used from a Server Component.";if(typeof window<"u")throw new Error(d);const n=()=>{const r=process.env.NEXT_PUBLIC_SUPABASE_URL,t=process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;if(!r||!t)throw new Error("Missing Supabase environment variables");return l.createServerClient(r,t,{cookies:{getAll:async()=>{try{return(await c.cookies()).getAll()}catch{return[]}},setAll:async e=>{try{const o=await c.cookies();for(const{name:a,value:s,options:i}of e)s&&s.length>0?o.set({name:a,value:s,...i}):o.delete({name:a,...i})}catch{}}}})};async function g(r){const t=n(),{data:e,error:o}=await t.from("profiles").select("id, full_name, avatar_url, role, updated_at, username, website").eq("id",r).single();return o||!e?(console.error("Error fetching profile (server-side):",o?.message),null):e}async function S(){const r=n(),{data:t,error:e}=await r.from("languages").select("id, code, name, is_default, is_active, created_at, updated_at").order("name",{ascending:!0});return e?(console.error("Error fetching languages (server-side):",e.message),[]):t||[]}exports.getSsgSupabaseClient=u.getSsgSupabaseClient;exports.createClient=n;exports.getActiveLanguagesServerSide=S;exports.getProfileWithRoleServerSide=g;
package/server.d.ts CHANGED
@@ -1,9 +1,2 @@
1
- import { Database } from './lib/supabase/types';
2
- import { SupabaseClient } from '@supabase/supabase-js';
3
- type Profile = Database['public']['Tables']['profiles']['Row'];
4
- type Language = Database['public']['Tables']['languages']['Row'];
5
- export declare const createClient: () => SupabaseClient<any, "public", any>;
6
- export declare function getProfileWithRoleServerSide(userId: string): Promise<Profile | null>;
7
- export declare function getActiveLanguagesServerSide(): Promise<Language[]>;
8
- export declare const getSsgSupabaseClient: () => SupabaseClient;
9
- export {};
1
+ export * from './lib/supabase/server';
2
+ export { getSsgSupabaseClient } from './lib/supabase/ssg-client';
package/server.es.js CHANGED
@@ -1,56 +1,48 @@
1
- import { createServerClient as c } from "@supabase/ssr";
2
- import { cookies as l } from "next/headers";
3
- import { createClient as u } from "@supabase/supabase-js";
4
- var S = {}, a;
5
- function _() {
6
- if (a) return S;
7
- throw a = 1, new Error(
8
- "This module cannot be imported from a Client Component module. It should only be used from a Server Component."
9
- );
10
- }
11
- _();
12
- const i = () => {
13
- const o = l(), t = process.env.NEXT_PUBLIC_SUPABASE_URL, r = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
14
- if (!t || !r)
1
+ import { createServerClient as l } from "@supabase/ssr";
2
+ import { cookies as i } from "next/headers";
3
+ import { g as _ } from "./ssg-client-DgUYZgPq.mjs";
4
+ const u = "This module cannot be imported from a Client Component module. It should only be used from a Server Component.";
5
+ if (typeof window < "u")
6
+ throw new Error(u);
7
+ const c = () => {
8
+ const r = process.env.NEXT_PUBLIC_SUPABASE_URL, o = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
9
+ if (!r || !o)
15
10
  throw new Error("Missing Supabase environment variables");
16
- return c(
17
- t,
11
+ return l(
18
12
  r,
13
+ o,
19
14
  {
20
15
  cookies: {
21
- async get(e) {
22
- var s;
23
- return (s = (await o).get(e)) == null ? void 0 : s.value;
24
- },
25
- set(e, n, s) {
26
- o.set({ name: e, value: n, ...s });
16
+ getAll: async () => {
17
+ try {
18
+ return (await i()).getAll();
19
+ } catch {
20
+ return [];
21
+ }
27
22
  },
28
- remove(e, n) {
29
- o.set({ name: e, value: "", ...n });
23
+ setAll: async (e) => {
24
+ try {
25
+ const t = await i();
26
+ for (const { name: a, value: n, options: s } of e)
27
+ n && n.length > 0 ? t.set({ name: a, value: n, ...s }) : t.delete({ name: a, ...s });
28
+ } catch {
29
+ }
30
30
  }
31
31
  }
32
32
  }
33
33
  );
34
34
  };
35
- async function p(o) {
36
- const t = i(), { data: r, error: e } = await t.from("profiles").select("id, full_name, avatar_url, role, updated_at, username, website").eq("id", o).single();
37
- return e || !r ? (console.error("Error fetching profile (server-side):", e == null ? void 0 : e.message), null) : r;
35
+ async function p(r) {
36
+ const o = c(), { data: e, error: t } = await o.from("profiles").select("id, full_name, avatar_url, role, updated_at, username, website").eq("id", r).single();
37
+ return t || !e ? (console.error("Error fetching profile (server-side):", t?.message), null) : e;
38
38
  }
39
- async function f() {
40
- const o = i(), { data: t, error: r } = await o.from("languages").select("id, code, name, is_default, is_active, created_at, updated_at").order("name", { ascending: !0 });
41
- return r ? (console.error("Error fetching languages (server-side):", r.message), []) : t || [];
39
+ async function m() {
40
+ const r = c(), { data: o, error: e } = await r.from("languages").select("id, code, name, is_default, is_active, created_at, updated_at").order("name", { ascending: !0 });
41
+ return e ? (console.error("Error fetching languages (server-side):", e.message), []) : o || [];
42
42
  }
43
- const g = () => {
44
- if (!process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY)
45
- throw new Error("Supabase URL or Anon Key is missing for SSG client. Check .env.local");
46
- return u(
47
- process.env.NEXT_PUBLIC_SUPABASE_URL,
48
- process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
49
- );
50
- };
51
43
  export {
52
- i as createClient,
53
- f as getActiveLanguagesServerSide,
44
+ c as createClient,
45
+ m as getActiveLanguagesServerSide,
54
46
  p as getProfileWithRoleServerSide,
55
- g as getSsgSupabaseClient
47
+ _ as getSsgSupabaseClient
56
48
  };
@@ -0,0 +1 @@
1
+ "use strict";const e=require("@supabase/supabase-js"),s=()=>!process.env.NEXT_PUBLIC_SUPABASE_URL||!process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY?(console.warn("Supabase URL or Anon Key is missing for SSG client. Check .env.local"),{}):e.createClient(process.env.NEXT_PUBLIC_SUPABASE_URL,process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY);exports.getSsgSupabaseClient=s;
@@ -0,0 +1,8 @@
1
+ import { createClient as e } from "@supabase/supabase-js";
2
+ const n = () => !process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY ? (console.warn("Supabase URL or Anon Key is missing for SSG client. Check .env.local"), {}) : e(
3
+ process.env.NEXT_PUBLIC_SUPABASE_URL,
4
+ process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
5
+ );
6
+ export {
7
+ n as g
8
+ };