naystack 1.4.6 → 1.4.9

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.
@@ -31,10 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/auth/email/client.tsx
32
32
  var client_exports = {};
33
33
  __export(client_exports, {
34
+ AuthWrapper: () => AuthWrapper,
34
35
  TokenContext: () => TokenContext,
35
- getAuthWrapper: () => getAuthWrapper,
36
- getEmailAuthUtils: () => getEmailAuthUtils,
36
+ useLoginWithEmail: () => useLoginWithEmail,
37
+ useLogout: () => useLogout,
37
38
  useSetToken: () => useSetToken,
39
+ useSignUpWithEmail: () => useSignUpWithEmail,
38
40
  useToken: () => useToken
39
41
  });
40
42
  module.exports = __toCommonJS(client_exports);
@@ -43,10 +45,10 @@ var TokenContext = (0, import_react.createContext)({
43
45
  token: null,
44
46
  setToken: () => null
45
47
  });
46
- var getAuthWrapper = (endpoint) => ({ children }) => {
48
+ var AuthWrapper = ({ children }) => {
47
49
  const [token, setToken] = (0, import_react.useState)(null);
48
50
  (0, import_react.useEffect)(() => {
49
- fetch(endpoint, {
51
+ fetch(process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT, {
50
52
  credentials: "include"
51
53
  }).then((res) => res.json()).then((data) => setToken(data.accessToken));
52
54
  }, []);
@@ -64,7 +66,7 @@ function useSignUpWithEmail(endpoint) {
64
66
  const setToken = useSetToken();
65
67
  return (0, import_react.useCallback)(
66
68
  async (data) => {
67
- const res = await fetch(endpoint, {
69
+ const res = await fetch(process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT, {
68
70
  method: "POST",
69
71
  body: JSON.stringify(data),
70
72
  credentials: "include"
@@ -79,11 +81,11 @@ function useSignUpWithEmail(endpoint) {
79
81
  [setToken]
80
82
  );
81
83
  }
82
- function useLoginWithEmail(endpoint) {
84
+ function useLoginWithEmail() {
83
85
  const setToken = useSetToken();
84
86
  return (0, import_react.useCallback)(
85
87
  async (data) => {
86
- const res = await fetch(endpoint, {
88
+ const res = await fetch(process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT, {
87
89
  method: "PUT",
88
90
  body: JSON.stringify(data),
89
91
  credentials: "include"
@@ -98,12 +100,12 @@ function useLoginWithEmail(endpoint) {
98
100
  [setToken]
99
101
  );
100
102
  }
101
- function useLogout(endpoint) {
103
+ function useLogout() {
102
104
  const setToken = useSetToken();
103
105
  return (0, import_react.useCallback)(
104
106
  async (data) => {
105
107
  setToken(null);
106
- await fetch(endpoint, {
108
+ await fetch(process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT, {
107
109
  method: "DELETE",
108
110
  credentials: "include",
109
111
  body: JSON.stringify(data)
@@ -112,18 +114,13 @@ function useLogout(endpoint) {
112
114
  [setToken]
113
115
  );
114
116
  }
115
- function getEmailAuthUtils(endpoint) {
116
- return {
117
- useSignUp: () => useSignUpWithEmail(endpoint),
118
- useLogin: () => useLoginWithEmail(endpoint),
119
- useLogout: () => useLogout(endpoint)
120
- };
121
- }
122
117
  // Annotate the CommonJS export names for ESM import in node:
123
118
  0 && (module.exports = {
119
+ AuthWrapper,
124
120
  TokenContext,
125
- getAuthWrapper,
126
- getEmailAuthUtils,
121
+ useLoginWithEmail,
122
+ useLogout,
127
123
  useSetToken,
124
+ useSignUpWithEmail,
128
125
  useToken
129
126
  });
@@ -4,15 +4,13 @@ declare const TokenContext: React__default.Context<{
4
4
  token: string | null;
5
5
  setToken: Dispatch<SetStateAction<string | null>>;
6
6
  }>;
7
- declare const getAuthWrapper: (endpoint: string) => ({ children }: {
7
+ declare const AuthWrapper: ({ children }: {
8
8
  children: React__default.ReactNode;
9
9
  }) => React__default.JSX.Element;
10
10
  declare function useToken(): string | null;
11
11
  declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
12
- declare function getEmailAuthUtils(endpoint: string): {
13
- useSignUp: () => (data: object) => Promise<string | null>;
14
- useLogin: () => (data: object) => Promise<string | null>;
15
- useLogout: () => (data?: object) => Promise<void>;
16
- };
12
+ declare function useSignUpWithEmail(endpoint: string): (data: object) => Promise<string | null>;
13
+ declare function useLoginWithEmail(): (data: object) => Promise<string | null>;
14
+ declare function useLogout(): (data?: object) => Promise<void>;
17
15
 
18
- export { TokenContext, getAuthWrapper, getEmailAuthUtils, useSetToken, useToken };
16
+ export { AuthWrapper, TokenContext, useLoginWithEmail, useLogout, useSetToken, useSignUpWithEmail, useToken };
@@ -4,15 +4,13 @@ declare const TokenContext: React__default.Context<{
4
4
  token: string | null;
5
5
  setToken: Dispatch<SetStateAction<string | null>>;
6
6
  }>;
7
- declare const getAuthWrapper: (endpoint: string) => ({ children }: {
7
+ declare const AuthWrapper: ({ children }: {
8
8
  children: React__default.ReactNode;
9
9
  }) => React__default.JSX.Element;
10
10
  declare function useToken(): string | null;
11
11
  declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
12
- declare function getEmailAuthUtils(endpoint: string): {
13
- useSignUp: () => (data: object) => Promise<string | null>;
14
- useLogin: () => (data: object) => Promise<string | null>;
15
- useLogout: () => (data?: object) => Promise<void>;
16
- };
12
+ declare function useSignUpWithEmail(endpoint: string): (data: object) => Promise<string | null>;
13
+ declare function useLoginWithEmail(): (data: object) => Promise<string | null>;
14
+ declare function useLogout(): (data?: object) => Promise<void>;
17
15
 
18
- export { TokenContext, getAuthWrapper, getEmailAuthUtils, useSetToken, useToken };
16
+ export { AuthWrapper, TokenContext, useLoginWithEmail, useLogout, useSetToken, useSignUpWithEmail, useToken };
@@ -12,10 +12,10 @@ var TokenContext = createContext({
12
12
  token: null,
13
13
  setToken: () => null
14
14
  });
15
- var getAuthWrapper = (endpoint) => ({ children }) => {
15
+ var AuthWrapper = ({ children }) => {
16
16
  const [token, setToken] = useState(null);
17
17
  useEffect(() => {
18
- fetch(endpoint, {
18
+ fetch(process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT, {
19
19
  credentials: "include"
20
20
  }).then((res) => res.json()).then((data) => setToken(data.accessToken));
21
21
  }, []);
@@ -33,7 +33,7 @@ function useSignUpWithEmail(endpoint) {
33
33
  const setToken = useSetToken();
34
34
  return useCallback(
35
35
  async (data) => {
36
- const res = await fetch(endpoint, {
36
+ const res = await fetch(process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT, {
37
37
  method: "POST",
38
38
  body: JSON.stringify(data),
39
39
  credentials: "include"
@@ -48,11 +48,11 @@ function useSignUpWithEmail(endpoint) {
48
48
  [setToken]
49
49
  );
50
50
  }
51
- function useLoginWithEmail(endpoint) {
51
+ function useLoginWithEmail() {
52
52
  const setToken = useSetToken();
53
53
  return useCallback(
54
54
  async (data) => {
55
- const res = await fetch(endpoint, {
55
+ const res = await fetch(process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT, {
56
56
  method: "PUT",
57
57
  body: JSON.stringify(data),
58
58
  credentials: "include"
@@ -67,12 +67,12 @@ function useLoginWithEmail(endpoint) {
67
67
  [setToken]
68
68
  );
69
69
  }
70
- function useLogout(endpoint) {
70
+ function useLogout() {
71
71
  const setToken = useSetToken();
72
72
  return useCallback(
73
73
  async (data) => {
74
74
  setToken(null);
75
- await fetch(endpoint, {
75
+ await fetch(process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT, {
76
76
  method: "DELETE",
77
77
  credentials: "include",
78
78
  body: JSON.stringify(data)
@@ -81,17 +81,12 @@ function useLogout(endpoint) {
81
81
  [setToken]
82
82
  );
83
83
  }
84
- function getEmailAuthUtils(endpoint) {
85
- return {
86
- useSignUp: () => useSignUpWithEmail(endpoint),
87
- useLogin: () => useLoginWithEmail(endpoint),
88
- useLogout: () => useLogout(endpoint)
89
- };
90
- }
91
84
  export {
85
+ AuthWrapper,
92
86
  TokenContext,
93
- getAuthWrapper,
94
- getEmailAuthUtils,
87
+ useLoginWithEmail,
88
+ useLogout,
95
89
  useSetToken,
90
+ useSignUpWithEmail,
96
91
  useToken
97
92
  };
@@ -47,11 +47,11 @@ var getGoogleGetRoute = ({
47
47
  getUserIdFromEmail,
48
48
  redirectURL,
49
49
  errorRedirectURL,
50
- url,
51
50
  clientId,
52
51
  clientSecret,
53
52
  keys
54
53
  }) => {
54
+ const url = process.env.NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT;
55
55
  const oauth2Client = new import_googleapis.google.auth.OAuth2(clientId, clientSecret, url);
56
56
  return async (req) => {
57
57
  const code = req.nextUrl.searchParams.get("code");
@@ -4,6 +4,6 @@ import 'googleapis';
4
4
  import '../email/types.mjs';
5
5
  import '../types.mjs';
6
6
 
7
- declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, url, clientId, clientSecret, keys, }: InitGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
7
+ declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, clientId, clientSecret, keys, }: InitGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
8
8
 
9
9
  export { getGoogleGetRoute };
@@ -4,6 +4,6 @@ import 'googleapis';
4
4
  import '../email/types.js';
5
5
  import '../types.js';
6
6
 
7
- declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, url, clientId, clientSecret, keys, }: InitGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
7
+ declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, clientId, clientSecret, keys, }: InitGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
8
8
 
9
9
  export { getGoogleGetRoute };
@@ -23,11 +23,11 @@ var getGoogleGetRoute = ({
23
23
  getUserIdFromEmail,
24
24
  redirectURL,
25
25
  errorRedirectURL,
26
- url,
27
26
  clientId,
28
27
  clientSecret,
29
28
  keys
30
29
  }) => {
30
+ const url = process.env.NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT;
31
31
  const oauth2Client = new google.auth.OAuth2(clientId, clientSecret, url);
32
32
  return async (req) => {
33
33
  const code = req.nextUrl.searchParams.get("code");
@@ -49,11 +49,11 @@ var getGoogleGetRoute = ({
49
49
  getUserIdFromEmail,
50
50
  redirectURL,
51
51
  errorRedirectURL,
52
- url,
53
52
  clientId,
54
53
  clientSecret,
55
54
  keys
56
55
  }) => {
56
+ const url = process.env.NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT;
57
57
  const oauth2Client = new import_googleapis.google.auth.OAuth2(clientId, clientSecret, url);
58
58
  return async (req) => {
59
59
  const code = req.nextUrl.searchParams.get("code");
@@ -8,7 +8,6 @@ interface InitGoogleAuthOptions {
8
8
  getUserIdFromEmail: (email: Schema$Userinfo) => Promise<number | null>;
9
9
  redirectURL: string;
10
10
  errorRedirectURL?: string;
11
- url: string;
12
11
  clientId: string;
13
12
  clientSecret: string;
14
13
  keys: AuthKeys;
@@ -8,7 +8,6 @@ interface InitGoogleAuthOptions {
8
8
  getUserIdFromEmail: (email: Schema$Userinfo) => Promise<number | null>;
9
9
  redirectURL: string;
10
10
  errorRedirectURL?: string;
11
- url: string;
12
11
  clientId: string;
13
12
  clientSecret: string;
14
13
  keys: AuthKeys;
@@ -23,11 +23,11 @@ var getGoogleGetRoute = ({
23
23
  getUserIdFromEmail,
24
24
  redirectURL,
25
25
  errorRedirectURL,
26
- url,
27
26
  clientId,
28
27
  clientSecret,
29
28
  keys
30
29
  }) => {
30
+ const url = process.env.NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT;
31
31
  const oauth2Client = new google.auth.OAuth2(clientId, clientSecret, url);
32
32
  return async (req) => {
33
33
  const code = req.nextUrl.searchParams.get("code");
@@ -277,11 +277,11 @@ var getGoogleGetRoute = ({
277
277
  getUserIdFromEmail,
278
278
  redirectURL,
279
279
  errorRedirectURL,
280
- url,
281
280
  clientId,
282
281
  clientSecret,
283
282
  keys
284
283
  }) => {
284
+ const url = process.env.NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT;
285
285
  const oauth2Client = new import_googleapis.google.auth.OAuth2(clientId, clientSecret, url);
286
286
  return async (req) => {
287
287
  const code = req.nextUrl.searchParams.get("code");
@@ -422,7 +422,6 @@ var getInstagramRoute = ({
422
422
  successRedirectURL,
423
423
  errorRedirectURL,
424
424
  onUser,
425
- authRoute,
426
425
  clientSecret,
427
426
  clientId
428
427
  }) => {
@@ -435,7 +434,7 @@ var getInstagramRoute = ({
435
434
  if (!stateToken || !accessCode) return handleError2("Invalid request");
436
435
  const instagramData = await getLongLivedToken(
437
436
  accessCode,
438
- authRoute,
437
+ process.env.NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT,
439
438
  clientId,
440
439
  clientSecret
441
440
  );
@@ -248,11 +248,11 @@ var getGoogleGetRoute = ({
248
248
  getUserIdFromEmail,
249
249
  redirectURL,
250
250
  errorRedirectURL,
251
- url,
252
251
  clientId,
253
252
  clientSecret,
254
253
  keys
255
254
  }) => {
255
+ const url = process.env.NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT;
256
256
  const oauth2Client = new google.auth.OAuth2(clientId, clientSecret, url);
257
257
  return async (req) => {
258
258
  const code = req.nextUrl.searchParams.get("code");
@@ -393,7 +393,6 @@ var getInstagramRoute = ({
393
393
  successRedirectURL,
394
394
  errorRedirectURL,
395
395
  onUser,
396
- authRoute,
397
396
  clientSecret,
398
397
  clientId
399
398
  }) => {
@@ -406,7 +405,7 @@ var getInstagramRoute = ({
406
405
  if (!stateToken || !accessCode) return handleError2("Invalid request");
407
406
  const instagramData = await getLongLivedToken(
408
407
  accessCode,
409
- authRoute,
408
+ process.env.NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT,
410
409
  clientId,
411
410
  clientSecret
412
411
  );
@@ -113,7 +113,6 @@ var getInstagramRoute = ({
113
113
  successRedirectURL,
114
114
  errorRedirectURL,
115
115
  onUser,
116
- authRoute,
117
116
  clientSecret,
118
117
  clientId
119
118
  }) => {
@@ -126,7 +125,7 @@ var getInstagramRoute = ({
126
125
  if (!stateToken || !accessCode) return handleError("Invalid request");
127
126
  const instagramData = await getLongLivedToken(
128
127
  accessCode,
129
- authRoute,
128
+ process.env.NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT,
130
129
  clientId,
131
130
  clientSecret
132
131
  );
@@ -6,7 +6,6 @@ interface InitInstagramAuthOptions {
6
6
  onUser: (data: InstagramUser, id: number | null, accessToken: string) => Promise<string | void>;
7
7
  successRedirectURL: string;
8
8
  errorRedirectURL: string;
9
- authRoute: string;
10
9
  clientId: string;
11
10
  clientSecret: string;
12
11
  refreshKey: string;
@@ -6,7 +6,6 @@ interface InitInstagramAuthOptions {
6
6
  onUser: (data: InstagramUser, id: number | null, accessToken: string) => Promise<string | void>;
7
7
  successRedirectURL: string;
8
8
  errorRedirectURL: string;
9
- authRoute: string;
10
9
  clientId: string;
11
10
  clientSecret: string;
12
11
  refreshKey: string;
@@ -87,7 +87,6 @@ var getInstagramRoute = ({
87
87
  successRedirectURL,
88
88
  errorRedirectURL,
89
89
  onUser,
90
- authRoute,
91
90
  clientSecret,
92
91
  clientId
93
92
  }) => {
@@ -100,7 +99,7 @@ var getInstagramRoute = ({
100
99
  if (!stateToken || !accessCode) return handleError("Invalid request");
101
100
  const instagramData = await getLongLivedToken(
102
101
  accessCode,
103
- authRoute,
102
+ process.env.NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT,
104
103
  clientId,
105
104
  clientSecret
106
105
  );
@@ -104,7 +104,6 @@ var getInstagramRoute = ({
104
104
  successRedirectURL,
105
105
  errorRedirectURL,
106
106
  onUser,
107
- authRoute,
108
107
  clientSecret,
109
108
  clientId
110
109
  }) => {
@@ -117,7 +116,7 @@ var getInstagramRoute = ({
117
116
  if (!stateToken || !accessCode) return handleError("Invalid request");
118
117
  const instagramData = await getLongLivedToken(
119
118
  accessCode,
120
- authRoute,
119
+ process.env.NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT,
121
120
  clientId,
122
121
  clientSecret
123
122
  );
@@ -3,6 +3,6 @@ import { InitInstagramAuthOptions } from './index.mjs';
3
3
  import './utils.mjs';
4
4
  import '../../socials/instagram/types.mjs';
5
5
 
6
- declare const getInstagramRoute: ({ successRedirectURL, errorRedirectURL, onUser, authRoute, clientSecret, clientId, }: InitInstagramAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
6
+ declare const getInstagramRoute: ({ successRedirectURL, errorRedirectURL, onUser, clientSecret, clientId, }: InitInstagramAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
7
7
 
8
8
  export { getInstagramRoute };
@@ -3,6 +3,6 @@ import { InitInstagramAuthOptions } from './index.js';
3
3
  import './utils.js';
4
4
  import '../../socials/instagram/types.js';
5
5
 
6
- declare const getInstagramRoute: ({ successRedirectURL, errorRedirectURL, onUser, authRoute, clientSecret, clientId, }: InitInstagramAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
6
+ declare const getInstagramRoute: ({ successRedirectURL, errorRedirectURL, onUser, clientSecret, clientId, }: InitInstagramAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
7
7
 
8
8
  export { getInstagramRoute };
@@ -80,7 +80,6 @@ var getInstagramRoute = ({
80
80
  successRedirectURL,
81
81
  errorRedirectURL,
82
82
  onUser,
83
- authRoute,
84
83
  clientSecret,
85
84
  clientId
86
85
  }) => {
@@ -93,7 +92,7 @@ var getInstagramRoute = ({
93
92
  if (!stateToken || !accessCode) return handleError("Invalid request");
94
93
  const instagramData = await getLongLivedToken(
95
94
  accessCode,
96
- authRoute,
95
+ process.env.NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT,
97
96
  clientId,
98
97
  clientSecret
99
98
  );
@@ -20,18 +20,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/file/client.ts
21
21
  var client_exports = {};
22
22
  __export(client_exports, {
23
- getUseFileUpload: () => getUseFileUpload
23
+ useFileUpload: () => useFileUpload
24
24
  });
25
25
  module.exports = __toCommonJS(client_exports);
26
26
  var import_client = require("naystack/auth/email/client");
27
- var getUseFileUpload = (route) => () => {
27
+ var useFileUpload = () => {
28
28
  const token = (0, import_client.useToken)();
29
29
  return (file, type, data) => {
30
30
  const formData = new FormData();
31
31
  formData.append("type", type);
32
32
  formData.append("file", file);
33
33
  if (data) formData.append("data", JSON.stringify(data));
34
- return fetch(route, {
34
+ return fetch(process.env.NEXT_PUBLIC_FILE_ENDPOINT, {
35
35
  method: "PUT",
36
36
  body: formData,
37
37
  headers: {
@@ -44,5 +44,5 @@ var getUseFileUpload = (route) => () => {
44
44
  };
45
45
  // Annotate the CommonJS export names for ESM import in node:
46
46
  0 && (module.exports = {
47
- getUseFileUpload
47
+ useFileUpload
48
48
  });
@@ -1,7 +1,7 @@
1
- declare const getUseFileUpload: (route: string) => () => (file: File | Blob, type: string, data?: object) => Promise<FileUploadResponseType>;
1
+ declare const useFileUpload: () => (file: File | Blob, type: string, data?: object) => Promise<FileUploadResponseType>;
2
2
  interface FileUploadResponseType {
3
3
  url?: string;
4
4
  onUploadResponse?: object;
5
5
  }
6
6
 
7
- export { getUseFileUpload };
7
+ export { useFileUpload };
@@ -1,7 +1,7 @@
1
- declare const getUseFileUpload: (route: string) => () => (file: File | Blob, type: string, data?: object) => Promise<FileUploadResponseType>;
1
+ declare const useFileUpload: () => (file: File | Blob, type: string, data?: object) => Promise<FileUploadResponseType>;
2
2
  interface FileUploadResponseType {
3
3
  url?: string;
4
4
  onUploadResponse?: object;
5
5
  }
6
6
 
7
- export { getUseFileUpload };
7
+ export { useFileUpload };
@@ -1,13 +1,13 @@
1
1
  // src/file/client.ts
2
2
  import { useToken } from "naystack/auth/email/client";
3
- var getUseFileUpload = (route) => () => {
3
+ var useFileUpload = () => {
4
4
  const token = useToken();
5
5
  return (file, type, data) => {
6
6
  const formData = new FormData();
7
7
  formData.append("type", type);
8
8
  formData.append("file", file);
9
9
  if (data) formData.append("data", JSON.stringify(data));
10
- return fetch(route, {
10
+ return fetch(process.env.NEXT_PUBLIC_FILE_ENDPOINT, {
11
11
  method: "PUT",
12
12
  body: formData,
13
13
  headers: {
@@ -19,5 +19,5 @@ var getUseFileUpload = (route) => () => {
19
19
  };
20
20
  };
21
21
  export {
22
- getUseFileUpload
22
+ useFileUpload
23
23
  };
@@ -31,7 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/graphql/client.tsx
32
32
  var client_exports = {};
33
33
  __export(client_exports, {
34
- getApolloWrapper: () => getApolloWrapper,
34
+ ApolloWrapper: () => ApolloWrapper,
35
35
  tokenContext: () => tokenContext,
36
36
  useAuthMutation: () => useAuthMutation,
37
37
  useAuthQuery: () => useAuthQuery
@@ -41,18 +41,16 @@ var import_client = require("@apollo/client");
41
41
  var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
42
42
  var import_client2 = require("naystack/auth/email/client");
43
43
  var import_react = __toESM(require("react"));
44
- var getApolloWrapper = (endpoint, options) => {
44
+ var ApolloWrapper = ({ children, cacheConfig }) => {
45
45
  function makeClient() {
46
46
  return new import_client_integration_nextjs.ApolloClient({
47
- cache: new import_client_integration_nextjs.InMemoryCache(options?.cacheConfig),
47
+ cache: new import_client_integration_nextjs.InMemoryCache(cacheConfig),
48
48
  link: new import_client.HttpLink({
49
- uri: endpoint
49
+ uri: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT
50
50
  })
51
51
  });
52
52
  }
53
- return ({ children }) => {
54
- return /* @__PURE__ */ import_react.default.createElement(import_client_integration_nextjs.ApolloNextAppProvider, { makeClient }, children);
55
- };
53
+ return /* @__PURE__ */ import_react.default.createElement(import_client_integration_nextjs.ApolloNextAppProvider, { makeClient }, children);
56
54
  };
57
55
  var tokenContext = (token) => {
58
56
  if (!token) return void 0;
@@ -91,8 +89,9 @@ function useAuthMutation(mutation, options) {
91
89
  const token = (0, import_client2.useToken)();
92
90
  const [mutate, result] = (0, import_client.useMutation)(mutation, options);
93
91
  const method = (0, import_react.useCallback)(
94
- (variables) => mutate({
95
- variables,
92
+ (input) => mutate({
93
+ // @ts-ignore
94
+ variables: { input },
96
95
  context: tokenContext(token)
97
96
  }),
98
97
  [token]
@@ -101,7 +100,7 @@ function useAuthMutation(mutation, options) {
101
100
  }
102
101
  // Annotate the CommonJS export names for ESM import in node:
103
102
  0 && (module.exports = {
104
- getApolloWrapper,
103
+ ApolloWrapper,
105
104
  tokenContext,
106
105
  useAuthMutation,
107
106
  useAuthQuery
@@ -3,9 +3,9 @@ import { InMemoryCacheConfig, OperationVariables, MutationHookOptions } from '@a
3
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
4
4
  import React__default, { PropsWithChildren } from 'react';
5
5
 
6
- declare const getApolloWrapper: (endpoint: string, options?: {
6
+ declare const ApolloWrapper: ({ children, cacheConfig }: PropsWithChildren<{
7
7
  cacheConfig?: InMemoryCacheConfig;
8
- }) => ({ children }: PropsWithChildren) => React__default.JSX.Element;
8
+ }>) => React__default.JSX.Element;
9
9
  declare const tokenContext: (token?: string | null) => {
10
10
  headers: {
11
11
  authorization: string;
@@ -13,6 +13,6 @@ declare const tokenContext: (token?: string | null) => {
13
13
  credentials: string;
14
14
  } | undefined;
15
15
  declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V): readonly [(v?: V) => Promise<_apollo_client.QueryResult<T, V>>, _apollo_client.QueryResult<T, V>];
16
- declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(variables?: V) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
16
+ declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(input: V["input"]) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
17
17
 
18
- export { getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
18
+ export { ApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
@@ -3,9 +3,9 @@ import { InMemoryCacheConfig, OperationVariables, MutationHookOptions } from '@a
3
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
4
4
  import React__default, { PropsWithChildren } from 'react';
5
5
 
6
- declare const getApolloWrapper: (endpoint: string, options?: {
6
+ declare const ApolloWrapper: ({ children, cacheConfig }: PropsWithChildren<{
7
7
  cacheConfig?: InMemoryCacheConfig;
8
- }) => ({ children }: PropsWithChildren) => React__default.JSX.Element;
8
+ }>) => React__default.JSX.Element;
9
9
  declare const tokenContext: (token?: string | null) => {
10
10
  headers: {
11
11
  authorization: string;
@@ -13,6 +13,6 @@ declare const tokenContext: (token?: string | null) => {
13
13
  credentials: string;
14
14
  } | undefined;
15
15
  declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V): readonly [(v?: V) => Promise<_apollo_client.QueryResult<T, V>>, _apollo_client.QueryResult<T, V>];
16
- declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(variables?: V) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
16
+ declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(input: V["input"]) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
17
17
 
18
- export { getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
18
+ export { ApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
@@ -17,18 +17,16 @@ import React, {
17
17
  useEffect,
18
18
  useState
19
19
  } from "react";
20
- var getApolloWrapper = (endpoint, options) => {
20
+ var ApolloWrapper = ({ children, cacheConfig }) => {
21
21
  function makeClient() {
22
22
  return new ApolloClient({
23
- cache: new InMemoryCache(options?.cacheConfig),
23
+ cache: new InMemoryCache(cacheConfig),
24
24
  link: new HttpLink({
25
- uri: endpoint
25
+ uri: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT
26
26
  })
27
27
  });
28
28
  }
29
- return ({ children }) => {
30
- return /* @__PURE__ */ React.createElement(ApolloNextAppProvider, { makeClient }, children);
31
- };
29
+ return /* @__PURE__ */ React.createElement(ApolloNextAppProvider, { makeClient }, children);
32
30
  };
33
31
  var tokenContext = (token) => {
34
32
  if (!token) return void 0;
@@ -67,8 +65,9 @@ function useAuthMutation(mutation, options) {
67
65
  const token = useToken();
68
66
  const [mutate, result] = useMutation(mutation, options);
69
67
  const method = useCallback(
70
- (variables) => mutate({
71
- variables,
68
+ (input) => mutate({
69
+ // @ts-ignore
70
+ variables: { input },
72
71
  context: tokenContext(token)
73
72
  }),
74
73
  [token]
@@ -76,7 +75,7 @@ function useAuthMutation(mutation, options) {
76
75
  return [method, result];
77
76
  }
78
77
  export {
79
- getApolloWrapper,
78
+ ApolloWrapper,
80
79
  tokenContext,
81
80
  useAuthMutation,
82
81
  useAuthQuery
@@ -21,7 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var server_exports = {};
22
22
  __export(server_exports, {
23
23
  Injector: () => Injector,
24
- getGraphQLQuery: () => getGraphQLQuery
24
+ query: () => query
25
25
  });
26
26
  module.exports = __toCommonJS(server_exports);
27
27
  var import_client = require("@apollo/client");
@@ -43,37 +43,35 @@ async function InjectorSuspensed({
43
43
  const data = await fetch();
44
44
  return /* @__PURE__ */ React.createElement(Component, { loading: false, ...props || {}, data });
45
45
  }
46
- var getGraphQLQuery = ({ uri }) => {
47
- const { query } = (0, import_client_integration_nextjs.registerApolloClient)(() => {
48
- return new import_client.ApolloClient({
49
- cache: new import_client.InMemoryCache(),
50
- link: new import_client.HttpLink({
51
- uri
52
- })
53
- });
46
+ var { query: gqlQuery } = (0, import_client_integration_nextjs.registerApolloClient)(() => {
47
+ return new import_client.ApolloClient({
48
+ cache: new import_client.InMemoryCache(),
49
+ link: new import_client.HttpLink({
50
+ uri: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT
51
+ })
54
52
  });
55
- return async (_query, options) => {
56
- const res = await query({
57
- query: _query,
58
- variables: options?.variables,
59
- context: {
60
- headers: {
61
- Cookie: options?.noCookie ? void 0 : await (0, import_headers.cookies)()
62
- },
63
- fetchOptions: {
64
- cache: options?.revalidate ? "force-cache" : void 0,
65
- next: {
66
- revalidate: options?.revalidate || 0,
67
- tags: options?.tags
68
- }
53
+ });
54
+ var query = async (_query, options) => {
55
+ const res = await gqlQuery({
56
+ query: _query,
57
+ variables: options?.variables,
58
+ context: {
59
+ headers: {
60
+ Cookie: options?.noCookie ? void 0 : await (0, import_headers.cookies)()
61
+ },
62
+ fetchOptions: {
63
+ cache: options?.revalidate ? "force-cache" : void 0,
64
+ next: {
65
+ revalidate: options?.revalidate || 0,
66
+ tags: options?.tags
69
67
  }
70
68
  }
71
- });
72
- return res.data;
73
- };
69
+ }
70
+ });
71
+ return res.data;
74
72
  };
75
73
  // Annotate the CommonJS export names for ESM import in node:
76
74
  0 && (module.exports = {
77
75
  Injector,
78
- getGraphQLQuery
76
+ query
79
77
  });
@@ -16,13 +16,11 @@ declare function Injector<T, Y>({ fetch, Component, props, }: {
16
16
  loading: boolean;
17
17
  } & Y>;
18
18
  } & ComponentProps<Y>): React.JSX.Element;
19
- declare const getGraphQLQuery: ({ uri }: {
20
- uri: string;
21
- }) => <T, V extends OperationVariables>(_query: TypedDocumentNode<T, V>, options?: {
19
+ declare const query: <T, V extends OperationVariables>(_query: TypedDocumentNode<T, V>, options?: {
22
20
  variables?: V;
23
21
  revalidate?: number;
24
22
  tags?: string[];
25
23
  noCookie?: boolean;
26
24
  }) => Promise<T>;
27
25
 
28
- export { Injector, getGraphQLQuery };
26
+ export { Injector, query };
@@ -16,13 +16,11 @@ declare function Injector<T, Y>({ fetch, Component, props, }: {
16
16
  loading: boolean;
17
17
  } & Y>;
18
18
  } & ComponentProps<Y>): React.JSX.Element;
19
- declare const getGraphQLQuery: ({ uri }: {
20
- uri: string;
21
- }) => <T, V extends OperationVariables>(_query: TypedDocumentNode<T, V>, options?: {
19
+ declare const query: <T, V extends OperationVariables>(_query: TypedDocumentNode<T, V>, options?: {
22
20
  variables?: V;
23
21
  revalidate?: number;
24
22
  tags?: string[];
25
23
  noCookie?: boolean;
26
24
  }) => Promise<T>;
27
25
 
28
- export { Injector, getGraphQLQuery };
26
+ export { Injector, query };
@@ -22,36 +22,34 @@ async function InjectorSuspensed({
22
22
  const data = await fetch();
23
23
  return /* @__PURE__ */ React.createElement(Component, { loading: false, ...props || {}, data });
24
24
  }
25
- var getGraphQLQuery = ({ uri }) => {
26
- const { query } = registerApolloClient(() => {
27
- return new ApolloClient({
28
- cache: new InMemoryCache(),
29
- link: new HttpLink({
30
- uri
31
- })
32
- });
25
+ var { query: gqlQuery } = registerApolloClient(() => {
26
+ return new ApolloClient({
27
+ cache: new InMemoryCache(),
28
+ link: new HttpLink({
29
+ uri: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT
30
+ })
33
31
  });
34
- return async (_query, options) => {
35
- const res = await query({
36
- query: _query,
37
- variables: options?.variables,
38
- context: {
39
- headers: {
40
- Cookie: options?.noCookie ? void 0 : await cookies()
41
- },
42
- fetchOptions: {
43
- cache: options?.revalidate ? "force-cache" : void 0,
44
- next: {
45
- revalidate: options?.revalidate || 0,
46
- tags: options?.tags
47
- }
32
+ });
33
+ var query = async (_query, options) => {
34
+ const res = await gqlQuery({
35
+ query: _query,
36
+ variables: options?.variables,
37
+ context: {
38
+ headers: {
39
+ Cookie: options?.noCookie ? void 0 : await cookies()
40
+ },
41
+ fetchOptions: {
42
+ cache: options?.revalidate ? "force-cache" : void 0,
43
+ next: {
44
+ revalidate: options?.revalidate || 0,
45
+ tags: options?.tags
48
46
  }
49
47
  }
50
- });
51
- return res.data;
52
- };
48
+ }
49
+ });
50
+ return res.data;
53
51
  };
54
52
  export {
55
53
  Injector,
56
- getGraphQLQuery
54
+ query
57
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.4.6",
3
+ "version": "1.4.9",
4
4
  "description": "A stack built with Next + GraphQL + S3 + Auth",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",