@farm.js/supabase 0.1.0-beta.21 → 0.1.0-beta.22

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/index.d.ts CHANGED
@@ -1,9 +1,27 @@
1
+ import { createServerClient } from "@supabase/ssr";
1
2
  import { type FarmIntegrationHandlerContext, type FarmIntegrationLogger } from "@farm.js/core";
2
3
  export interface SupabaseIntegrationPages {
3
4
  signIn?: string;
4
5
  signUp?: string;
5
6
  }
7
+ export type SupabaseIntegrationClient = ReturnType<typeof createServerClient>;
8
+ export type SupabaseIntegrationClientOptions = Parameters<typeof createServerClient>[2];
9
+ export interface SupabaseIntegrationInstanceContext {
10
+ request: Request;
11
+ url?: string;
12
+ anonKey?: string;
13
+ createClient: typeof createServerClient;
14
+ options: SupabaseIntegrationClientOptions;
15
+ }
16
+ /**
17
+ * Creates a request-scoped Supabase client using Farm's cookie adapter.
18
+ *
19
+ * A factory is used instead of a shared client because Supabase SSR clients
20
+ * are bound to the cookies of the current request.
21
+ */
22
+ export type SupabaseIntegrationInstance = (context: SupabaseIntegrationInstanceContext) => SupabaseIntegrationClient;
6
23
  export interface SupabaseIntegrationInput {
24
+ instance?: SupabaseIntegrationInstance;
7
25
  url?: string;
8
26
  anonKey?: string;
9
27
  appBaseUrl?: string;
@@ -20,8 +38,8 @@ export interface SupabaseIntegrationInput {
20
38
  log?: FarmIntegrationLogger;
21
39
  }
22
40
  interface ResolvedSupabaseEnv {
23
- url: string;
24
- anonKey: string;
41
+ url?: string;
42
+ anonKey?: string;
25
43
  appBaseUrl?: string;
26
44
  }
27
45
  interface ResolvedSupabasePages {
@@ -32,7 +50,7 @@ export declare function supabase(input?: SupabaseIntegrationInput): import("@far
32
50
  category: "auth";
33
51
  type: string;
34
52
  instance: {
35
- url: string;
53
+ url: string | undefined;
36
54
  protectedRoutes: string[];
37
55
  providers: string[];
38
56
  pages: ResolvedSupabasePages;
@@ -1 +1 @@
1
- {"version":3,"file":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AC;IACpC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,wBAAwB,CAAC;IACjC,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC7B;AAED,UAAU,mBAAmB;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,qBAAqB;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAwuBD,wBAAgB,QAAQ,CAAC,KAAK,GAAE,wBAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAuE7B,OAAO,WAAW,6BAA6B;;;;0BAkbzC,OAAO,WAAW,6BAA6B;;GAkBpF"}
package/dist/index.js CHANGED
@@ -40,8 +40,8 @@ function resolveEnv(input) {
40
40
  process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY ??
41
41
  "";
42
42
  const appBaseUrl = input.appBaseUrl ?? process.env.APP_BASE_URL ?? undefined;
43
- if (!url || !anonKey) {
44
- throw new Error("Supabase integration requires SUPABASE_URL (or NEXT_PUBLIC_SUPABASE_URL) and SUPABASE_ANON_KEY (or a Supabase publishable key env).");
43
+ if (!input.instance && (!url || !anonKey)) {
44
+ throw new Error("Supabase integration requires an instance factory or SUPABASE_URL (or NEXT_PUBLIC_SUPABASE_URL) and SUPABASE_ANON_KEY (or a Supabase publishable key env).");
45
45
  }
46
46
  return {
47
47
  url,
@@ -576,9 +576,9 @@ function renderCheckEmailPage(context, signInViewPath, email, returnTo) {
576
576
  },
577
577
  });
578
578
  }
579
- function createSupabaseHandler(context, env) {
579
+ function createSupabaseHandler(context, env, instance) {
580
580
  const setCookies = [];
581
- const supabase = createServerClient(env.url, env.anonKey, {
581
+ const options = {
582
582
  auth: {
583
583
  flowType: "pkce",
584
584
  detectSessionInUrl: false,
@@ -594,7 +594,16 @@ function createSupabaseHandler(context, env) {
594
594
  context.req.set("supabase:set-cookies", [...setCookies]);
595
595
  },
596
596
  },
597
- });
597
+ };
598
+ const supabase = instance
599
+ ? instance({
600
+ request: context.request,
601
+ url: env.url,
602
+ anonKey: env.anonKey,
603
+ createClient: createServerClient,
604
+ options,
605
+ })
606
+ : createServerClient(env.url, env.anonKey, options);
598
607
  return {
599
608
  supabase,
600
609
  setCookies,
@@ -677,7 +686,7 @@ export function supabase(input = {}) {
677
686
  appBaseUrl: "APP_BASE_URL",
678
687
  },
679
688
  input: env,
680
- required: ["url", "anonKey"],
689
+ required: input.instance ? [] : ["url", "anonKey"],
681
690
  }),
682
691
  api,
683
692
  log: input.log,
@@ -723,7 +732,7 @@ export function supabase(input = {}) {
723
732
  },
724
733
  });
725
734
  }
726
- const { supabase, setCookies } = createSupabaseHandler(context, env);
735
+ const { supabase, setCookies } = createSupabaseHandler(context, env, input.instance);
727
736
  const { error } = await supabase.auth.signInWithPassword({
728
737
  email: parsedRequest.email,
729
738
  password: parsedRequest.password,
@@ -789,7 +798,7 @@ export function supabase(input = {}) {
789
798
  feedback: readPageFeedback(context),
790
799
  });
791
800
  }
792
- const { supabase, setCookies } = createSupabaseHandler(context, env);
801
+ const { supabase, setCookies } = createSupabaseHandler(context, env, input.instance);
793
802
  const { data, error } = await supabase.auth.signInWithOAuth({
794
803
  provider: provider,
795
804
  options: {
@@ -872,7 +881,7 @@ export function supabase(input = {}) {
872
881
  },
873
882
  });
874
883
  }
875
- const { supabase, setCookies } = createSupabaseHandler(context, env);
884
+ const { supabase, setCookies } = createSupabaseHandler(context, env, input.instance);
876
885
  const { data, error } = await supabase.auth.signUp({
877
886
  email: parsedRequest.email,
878
887
  password: parsedRequest.password,
@@ -954,7 +963,7 @@ export function supabase(input = {}) {
954
963
  if (!code) {
955
964
  return new Response("Missing Supabase authorization code.", { status: 400 });
956
965
  }
957
- const { supabase, setCookies } = createSupabaseHandler(context, env);
966
+ const { supabase, setCookies } = createSupabaseHandler(context, env, input.instance);
958
967
  const { error } = await supabase.auth.exchangeCodeForSession(code);
959
968
  if (error) {
960
969
  return new Response(error.message, { status: 500 });
@@ -983,7 +992,7 @@ export function supabase(input = {}) {
983
992
  returnTo = getReturnTo(payload.returnTo, returnTo);
984
993
  }
985
994
  }
986
- const { supabase, setCookies } = createSupabaseHandler(context, env);
995
+ const { supabase, setCookies } = createSupabaseHandler(context, env, input.instance);
987
996
  const { error } = await supabase.auth.signOut();
988
997
  if (error) {
989
998
  if (clientRequest) {
@@ -1010,7 +1019,7 @@ export function supabase(input = {}) {
1010
1019
  path: sessionPath,
1011
1020
  methods: ["GET"],
1012
1021
  async handler(_request, context) {
1013
- const { supabase, setCookies } = createSupabaseHandler(context, env);
1022
+ const { supabase, setCookies } = createSupabaseHandler(context, env, input.instance);
1014
1023
  const { data, error } = await supabase.auth.getUser();
1015
1024
  const headers = new Headers({
1016
1025
  "content-type": "application/json",
@@ -1037,7 +1046,7 @@ export function supabase(input = {}) {
1037
1046
  {
1038
1047
  matcher: protectedMatchers,
1039
1048
  async handler(_request, context) {
1040
- const { supabase } = createSupabaseHandler(context, env);
1049
+ const { supabase } = createSupabaseHandler(context, env, input.instance);
1041
1050
  const { data: { session }, } = await supabase.auth.getSession();
1042
1051
  if (session) {
1043
1052
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/supabase",
3
- "version": "0.1.0-beta.21",
3
+ "version": "0.1.0-beta.22",
4
4
  "description": "Supabase integration for Farm.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,8 +31,8 @@
31
31
  "dependencies": {
32
32
  "@supabase/ssr": "^0.9.0",
33
33
  "@supabase/supabase-js": "^2.99.2",
34
- "@farm.js/core": "0.1.0-beta.21",
35
- "@farm.js/integration-utils": "0.1.0-beta.21"
34
+ "@farm.js/core": "0.1.0-beta.22",
35
+ "@farm.js/integration-utils": "0.1.0-beta.22"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc",