naystack 1.7.24 → 1.7.26

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.
@@ -152,7 +152,7 @@ function generateRefreshToken(id) {
152
152
  function getTokenizedResponse(id) {
153
153
  const accessToken = id ? generateAccessToken(id) : void 0;
154
154
  const refreshToken = id ? generateRefreshToken(id) : void 0;
155
- const response = import_server2.NextResponse.json(accessToken, {
155
+ const response = new import_server2.NextResponse(accessToken, {
156
156
  status: 200
157
157
  });
158
158
  if (!accessToken) {
@@ -50,10 +50,10 @@ import '../../graphql/types.mjs';
50
50
  */
51
51
  declare function setupEmailAuth(options: SetupEmailAuthOptions): {
52
52
  OPTIONS?: ((req: NextRequest) => NextResponse<unknown>) | undefined;
53
- GET: (req: NextRequest) => Promise<NextResponse<string | undefined>>;
53
+ GET: (req: NextRequest) => Promise<NextResponse<unknown>>;
54
54
  POST: (req: NextRequest) => Promise<NextResponse<unknown> | undefined>;
55
55
  PUT: (req: NextRequest) => Promise<NextResponse<unknown> | undefined>;
56
- DELETE: (req: NextRequest) => Promise<NextResponse<string | undefined>>;
56
+ DELETE: (req: NextRequest) => Promise<NextResponse<unknown>>;
57
57
  };
58
58
 
59
59
  export { setupEmailAuth };
@@ -50,10 +50,10 @@ import '../../graphql/types.js';
50
50
  */
51
51
  declare function setupEmailAuth(options: SetupEmailAuthOptions): {
52
52
  OPTIONS?: ((req: NextRequest) => NextResponse<unknown>) | undefined;
53
- GET: (req: NextRequest) => Promise<NextResponse<string | undefined>>;
53
+ GET: (req: NextRequest) => Promise<NextResponse<unknown>>;
54
54
  POST: (req: NextRequest) => Promise<NextResponse<unknown> | undefined>;
55
55
  PUT: (req: NextRequest) => Promise<NextResponse<unknown> | undefined>;
56
- DELETE: (req: NextRequest) => Promise<NextResponse<string | undefined>>;
56
+ DELETE: (req: NextRequest) => Promise<NextResponse<unknown>>;
57
57
  };
58
58
 
59
59
  export { setupEmailAuth };
@@ -113,7 +113,7 @@ function generateRefreshToken(id) {
113
113
  function getTokenizedResponse(id) {
114
114
  const accessToken = id ? generateAccessToken(id) : void 0;
115
115
  const refreshToken = id ? generateRefreshToken(id) : void 0;
116
- const response = NextResponse2.json(accessToken, {
116
+ const response = new NextResponse2(accessToken, {
117
117
  status: 200
118
118
  });
119
119
  if (!accessToken) {
@@ -96,7 +96,7 @@ function generateRefreshToken(id) {
96
96
  function getTokenizedResponse(id) {
97
97
  const accessToken = id ? generateAccessToken(id) : void 0;
98
98
  const refreshToken = id ? generateRefreshToken(id) : void 0;
99
- const response = import_server.NextResponse.json(accessToken, {
99
+ const response = new import_server.NextResponse(accessToken, {
100
100
  status: 200
101
101
  });
102
102
  if (!accessToken) {
@@ -8,6 +8,6 @@ import '../../types.mjs';
8
8
  * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getDeleteRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<string | undefined>>;
11
+ declare const getDeleteRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<unknown>>;
12
12
 
13
13
  export { getDeleteRoute };
@@ -8,6 +8,6 @@ import '../../types.js';
8
8
  * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getDeleteRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<string | undefined>>;
11
+ declare const getDeleteRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<unknown>>;
12
12
 
13
13
  export { getDeleteRoute };
@@ -70,7 +70,7 @@ function generateRefreshToken(id) {
70
70
  function getTokenizedResponse(id) {
71
71
  const accessToken = id ? generateAccessToken(id) : void 0;
72
72
  const refreshToken = id ? generateRefreshToken(id) : void 0;
73
- const response = NextResponse.json(accessToken, {
73
+ const response = new NextResponse(accessToken, {
74
74
  status: 200
75
75
  });
76
76
  if (!accessToken) {
@@ -96,7 +96,7 @@ function generateRefreshToken(id) {
96
96
  function getTokenizedResponse(id) {
97
97
  const accessToken = id ? generateAccessToken(id) : void 0;
98
98
  const refreshToken = id ? generateRefreshToken(id) : void 0;
99
- const response = import_server.NextResponse.json(accessToken, {
99
+ const response = new import_server.NextResponse(accessToken, {
100
100
  status: 200
101
101
  });
102
102
  if (!accessToken) {
@@ -8,6 +8,6 @@ import '../../types.mjs';
8
8
  * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getGetRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<string | undefined>>;
11
+ declare const getGetRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<unknown>>;
12
12
 
13
13
  export { getGetRoute };
@@ -8,6 +8,6 @@ import '../../types.js';
8
8
  * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getGetRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<string | undefined>>;
11
+ declare const getGetRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<unknown>>;
12
12
 
13
13
  export { getGetRoute };
@@ -70,7 +70,7 @@ function generateRefreshToken(id) {
70
70
  function getTokenizedResponse(id) {
71
71
  const accessToken = id ? generateAccessToken(id) : void 0;
72
72
  const refreshToken = id ? generateRefreshToken(id) : void 0;
73
- const response = NextResponse.json(accessToken, {
73
+ const response = new NextResponse(accessToken, {
74
74
  status: 200
75
75
  });
76
76
  if (!accessToken) {
@@ -105,7 +105,7 @@ function generateRefreshToken(id) {
105
105
  function getTokenizedResponse(id) {
106
106
  const accessToken = id ? generateAccessToken(id) : void 0;
107
107
  const refreshToken = id ? generateRefreshToken(id) : void 0;
108
- const response = import_server2.NextResponse.json(accessToken, {
108
+ const response = new import_server2.NextResponse(accessToken, {
109
109
  status: 200
110
110
  });
111
111
  if (!accessToken) {
@@ -81,7 +81,7 @@ function generateRefreshToken(id) {
81
81
  function getTokenizedResponse(id) {
82
82
  const accessToken = id ? generateAccessToken(id) : void 0;
83
83
  const refreshToken = id ? generateRefreshToken(id) : void 0;
84
- const response = NextResponse2.json(accessToken, {
84
+ const response = new NextResponse2(accessToken, {
85
85
  status: 200
86
86
  });
87
87
  if (!accessToken) {
@@ -104,7 +104,7 @@ function generateRefreshToken(id) {
104
104
  function getTokenizedResponse(id) {
105
105
  const accessToken = id ? generateAccessToken(id) : void 0;
106
106
  const refreshToken = id ? generateRefreshToken(id) : void 0;
107
- const response = import_server2.NextResponse.json(accessToken, {
107
+ const response = new import_server2.NextResponse(accessToken, {
108
108
  status: 200
109
109
  });
110
110
  if (!accessToken) {
@@ -78,7 +78,7 @@ function generateRefreshToken(id) {
78
78
  function getTokenizedResponse(id) {
79
79
  const accessToken = id ? generateAccessToken(id) : void 0;
80
80
  const refreshToken = id ? generateRefreshToken(id) : void 0;
81
- const response = NextResponse2.json(accessToken, {
81
+ const response = new NextResponse2(accessToken, {
82
82
  status: 200
83
83
  });
84
84
  if (!accessToken) {
@@ -100,7 +100,7 @@ function generateRefreshToken(id) {
100
100
  function getTokenizedResponse(id) {
101
101
  const accessToken = id ? generateAccessToken(id) : void 0;
102
102
  const refreshToken = id ? generateRefreshToken(id) : void 0;
103
- const response = import_server.NextResponse.json(accessToken, {
103
+ const response = new import_server.NextResponse(accessToken, {
104
104
  status: 200
105
105
  });
106
106
  if (!accessToken) {
@@ -26,7 +26,7 @@ declare function generateRefreshToken(id: number): string;
26
26
  * @returns NextResponse with JSON body and Set-Cookie headers.
27
27
  * @category Auth
28
28
  */
29
- declare function getTokenizedResponse(id?: number): NextResponse<string | undefined>;
29
+ declare function getTokenizedResponse(id?: number): NextResponse<unknown>;
30
30
  /**
31
31
  * Decodes a refresh token and returns the user id from the JWT payload.
32
32
  * @param refreshToken - JWT refresh token string.
@@ -26,7 +26,7 @@ declare function generateRefreshToken(id: number): string;
26
26
  * @returns NextResponse with JSON body and Set-Cookie headers.
27
27
  * @category Auth
28
28
  */
29
- declare function getTokenizedResponse(id?: number): NextResponse<string | undefined>;
29
+ declare function getTokenizedResponse(id?: number): NextResponse<unknown>;
30
30
  /**
31
31
  * Decodes a refresh token and returns the user id from the JWT payload.
32
32
  * @param refreshToken - JWT refresh token string.
@@ -70,7 +70,7 @@ function generateRefreshToken(id) {
70
70
  function getTokenizedResponse(id) {
71
71
  const accessToken = id ? generateAccessToken(id) : void 0;
72
72
  const refreshToken = id ? generateRefreshToken(id) : void 0;
73
- const response = NextResponse.json(accessToken, {
73
+ const response = new NextResponse(accessToken, {
74
74
  status: 200
75
75
  });
76
76
  if (!accessToken) {
@@ -158,7 +158,7 @@ function generateRefreshToken(id) {
158
158
  function getTokenizedResponse(id) {
159
159
  const accessToken = id ? generateAccessToken(id) : void 0;
160
160
  const refreshToken = id ? generateRefreshToken(id) : void 0;
161
- const response = import_server2.NextResponse.json(accessToken, {
161
+ const response = new import_server2.NextResponse(accessToken, {
162
162
  status: 200
163
163
  });
164
164
  if (!accessToken) {
@@ -113,7 +113,7 @@ function generateRefreshToken(id) {
113
113
  function getTokenizedResponse(id) {
114
114
  const accessToken = id ? generateAccessToken(id) : void 0;
115
115
  const refreshToken = id ? generateRefreshToken(id) : void 0;
116
- const response = NextResponse2.json(accessToken, {
116
+ const response = new NextResponse2(accessToken, {
117
117
  status: 200
118
118
  });
119
119
  if (!accessToken) {
@@ -116,31 +116,34 @@ var tokenContext = (token) => {
116
116
  };
117
117
  };
118
118
  function useAuthQuery(query, variables) {
119
- const token = (0, import_client2.useToken)();
120
119
  const [fetch, result] = (0, import_client.useLazyQuery)(query, {
121
120
  fetchPolicy: "no-cache"
122
121
  });
123
122
  const prevVarsRef = (0, import_react.useRef)(null);
124
123
  (0, import_react.useEffect)(() => {
125
124
  const serialized = JSON.stringify(variables);
126
- if (token && variables && prevVarsRef.current !== serialized) {
125
+ if (variables && prevVarsRef.current !== serialized) {
127
126
  prevVarsRef.current = serialized;
128
127
  void fetch({
129
128
  // @ts-expect-error -- to allow dynamic props
130
129
  variables: { input: variables },
131
- context: tokenContext(token)
130
+ context: {
131
+ credentials: `include`
132
+ }
132
133
  });
133
134
  }
134
- }, [fetch, token, variables]);
135
+ }, [fetch, variables]);
135
136
  const reFetch = (0, import_react.useCallback)(
136
137
  (input) => fetch({
137
138
  // @ts-expect-error -- to allow dynamic props
138
139
  variables: { input },
139
- context: tokenContext(token)
140
+ context: {
141
+ credentials: `include`
142
+ }
140
143
  }),
141
- [fetch, token]
144
+ [fetch]
142
145
  );
143
- return [reFetch, { ...result, hasAuth: !!token }];
146
+ return [reFetch, result];
144
147
  }
145
148
  function useAuthMutation(mutation, options) {
146
149
  const token = (0, import_client2.useToken)();
@@ -1,6 +1,5 @@
1
- import * as graphql from 'graphql';
2
1
  import * as _apollo_client from '@apollo/client';
3
- import { InMemoryCacheConfig, OperationVariables, ApolloClient, MutationHookOptions } from '@apollo/client';
2
+ import { InMemoryCacheConfig, OperationVariables, MutationHookOptions, ApolloClient } from '@apollo/client';
4
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
4
  import React__default, { PropsWithChildren } from 'react';
6
5
 
@@ -59,31 +58,7 @@ declare const tokenContext: (token?: string | null) => {
59
58
  *
60
59
  * @category GraphQL
61
60
  */
62
- declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V["input"]): readonly [(input?: V["input"]) => Promise<_apollo_client.QueryResult<T, V>>, {
63
- readonly hasAuth: false;
64
- readonly client: ApolloClient<any>;
65
- readonly observable: _apollo_client.ObservableQuery<T, V>;
66
- readonly data: T | undefined;
67
- readonly previousData?: T | undefined;
68
- readonly error?: _apollo_client.ApolloError;
69
- readonly errors?: ReadonlyArray<graphql.GraphQLFormattedError>;
70
- readonly loading: boolean;
71
- readonly networkStatus: _apollo_client.NetworkStatus;
72
- readonly called: boolean;
73
- readonly startPolling: (pollInterval: number) => void;
74
- readonly stopPolling: () => void;
75
- readonly subscribeToMore: _apollo_client.SubscribeToMoreFunction<T, V>;
76
- readonly updateQuery: (mapFn: _apollo_client.UpdateQueryMapFn<T, V>) => void;
77
- readonly refetch: (variables?: Partial<V> | undefined) => Promise<_apollo_client.ApolloQueryResult<T>>;
78
- readonly reobserve: (newOptions?: Partial<_apollo_client.WatchQueryOptions<V, T>> | undefined, newNetworkStatus?: _apollo_client.NetworkStatus) => Promise<_apollo_client.ApolloQueryResult<T>>;
79
- readonly variables: V | undefined;
80
- readonly fetchMore: <TFetchData = T, TFetchVars extends OperationVariables = V>(fetchMoreOptions: _apollo_client.FetchMoreQueryOptions<TFetchVars, TFetchData> & {
81
- updateQuery?: ((previousQueryResult: _apollo_client.Unmasked<T>, options: {
82
- fetchMoreResult: _apollo_client.Unmasked<TFetchData>;
83
- variables: TFetchVars;
84
- }) => _apollo_client.Unmasked<T>) | undefined;
85
- }) => Promise<_apollo_client.ApolloQueryResult<TFetchData>>;
86
- }];
61
+ declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V["input"]): readonly [(input?: V["input"]) => Promise<_apollo_client.QueryResult<T, V>>, _apollo_client.QueryResult<T, V>];
87
62
  /**
88
63
  * Hook to run a GraphQL mutation with the current user's token. Returns a function you call with the mutation input.
89
64
  *
@@ -1,6 +1,5 @@
1
- import * as graphql from 'graphql';
2
1
  import * as _apollo_client from '@apollo/client';
3
- import { InMemoryCacheConfig, OperationVariables, ApolloClient, MutationHookOptions } from '@apollo/client';
2
+ import { InMemoryCacheConfig, OperationVariables, MutationHookOptions, ApolloClient } from '@apollo/client';
4
3
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
4
  import React__default, { PropsWithChildren } from 'react';
6
5
 
@@ -59,31 +58,7 @@ declare const tokenContext: (token?: string | null) => {
59
58
  *
60
59
  * @category GraphQL
61
60
  */
62
- declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V["input"]): readonly [(input?: V["input"]) => Promise<_apollo_client.QueryResult<T, V>>, {
63
- readonly hasAuth: false;
64
- readonly client: ApolloClient<any>;
65
- readonly observable: _apollo_client.ObservableQuery<T, V>;
66
- readonly data: T | undefined;
67
- readonly previousData?: T | undefined;
68
- readonly error?: _apollo_client.ApolloError;
69
- readonly errors?: ReadonlyArray<graphql.GraphQLFormattedError>;
70
- readonly loading: boolean;
71
- readonly networkStatus: _apollo_client.NetworkStatus;
72
- readonly called: boolean;
73
- readonly startPolling: (pollInterval: number) => void;
74
- readonly stopPolling: () => void;
75
- readonly subscribeToMore: _apollo_client.SubscribeToMoreFunction<T, V>;
76
- readonly updateQuery: (mapFn: _apollo_client.UpdateQueryMapFn<T, V>) => void;
77
- readonly refetch: (variables?: Partial<V> | undefined) => Promise<_apollo_client.ApolloQueryResult<T>>;
78
- readonly reobserve: (newOptions?: Partial<_apollo_client.WatchQueryOptions<V, T>> | undefined, newNetworkStatus?: _apollo_client.NetworkStatus) => Promise<_apollo_client.ApolloQueryResult<T>>;
79
- readonly variables: V | undefined;
80
- readonly fetchMore: <TFetchData = T, TFetchVars extends OperationVariables = V>(fetchMoreOptions: _apollo_client.FetchMoreQueryOptions<TFetchVars, TFetchData> & {
81
- updateQuery?: ((previousQueryResult: _apollo_client.Unmasked<T>, options: {
82
- fetchMoreResult: _apollo_client.Unmasked<TFetchData>;
83
- variables: TFetchVars;
84
- }) => _apollo_client.Unmasked<T>) | undefined;
85
- }) => Promise<_apollo_client.ApolloQueryResult<TFetchData>>;
86
- }];
61
+ declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V["input"]): readonly [(input?: V["input"]) => Promise<_apollo_client.QueryResult<T, V>>, _apollo_client.QueryResult<T, V>];
87
62
  /**
88
63
  * Hook to run a GraphQL mutation with the current user's token. Returns a function you call with the mutation input.
89
64
  *
@@ -91,31 +91,34 @@ var tokenContext = (token) => {
91
91
  };
92
92
  };
93
93
  function useAuthQuery(query, variables) {
94
- const token = useToken();
95
94
  const [fetch, result] = useLazyQuery(query, {
96
95
  fetchPolicy: "no-cache"
97
96
  });
98
97
  const prevVarsRef = useRef(null);
99
98
  useEffect(() => {
100
99
  const serialized = JSON.stringify(variables);
101
- if (token && variables && prevVarsRef.current !== serialized) {
100
+ if (variables && prevVarsRef.current !== serialized) {
102
101
  prevVarsRef.current = serialized;
103
102
  void fetch({
104
103
  // @ts-expect-error -- to allow dynamic props
105
104
  variables: { input: variables },
106
- context: tokenContext(token)
105
+ context: {
106
+ credentials: `include`
107
+ }
107
108
  });
108
109
  }
109
- }, [fetch, token, variables]);
110
+ }, [fetch, variables]);
110
111
  const reFetch = useCallback(
111
112
  (input) => fetch({
112
113
  // @ts-expect-error -- to allow dynamic props
113
114
  variables: { input },
114
- context: tokenContext(token)
115
+ context: {
116
+ credentials: `include`
117
+ }
115
118
  }),
116
- [fetch, token]
119
+ [fetch]
117
120
  );
118
- return [reFetch, { ...result, hasAuth: !!token }];
121
+ return [reFetch, result];
119
122
  }
120
123
  function useAuthMutation(mutation, options) {
121
124
  const token = useToken();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.7.24",
3
+ "version": "1.7.26",
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",