naystack 1.5.26 → 1.5.28
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/auth/email/client.cjs.js +23 -6
- package/dist/auth/email/client.d.mts +7 -6
- package/dist/auth/email/client.d.ts +7 -6
- package/dist/auth/email/client.esm.js +23 -6
- package/dist/auth/email/index.cjs.js +3 -1
- package/dist/auth/email/index.esm.js +3 -1
- package/dist/auth/email/routes/get.cjs.js +3 -1
- package/dist/auth/email/routes/get.esm.js +3 -1
- package/dist/auth/index.cjs.js +3 -1
- package/dist/auth/index.esm.js +3 -1
- package/dist/graphql/client.cjs.js +9 -10
- package/dist/graphql/client.d.mts +0 -32
- package/dist/graphql/client.d.ts +0 -32
- package/dist/graphql/client.esm.js +12 -14
- package/dist/graphql/next.cjs.js +108 -0
- package/dist/graphql/next.d.mts +8 -0
- package/dist/graphql/next.d.ts +8 -0
- package/dist/graphql/next.esm.js +78 -0
- package/package.json +6 -1
|
@@ -44,6 +44,9 @@ __export(client_exports, {
|
|
|
44
44
|
module.exports = __toCommonJS(client_exports);
|
|
45
45
|
var import_react = __toESM(require("react"));
|
|
46
46
|
|
|
47
|
+
// src/auth/constants.ts
|
|
48
|
+
var REFRESH_COOKIE_NAME = "refresh";
|
|
49
|
+
|
|
47
50
|
// src/env.ts
|
|
48
51
|
var getEnvValue = (key) => {
|
|
49
52
|
switch (key) {
|
|
@@ -95,19 +98,33 @@ function getEnv(key, skipCheck) {
|
|
|
95
98
|
|
|
96
99
|
// src/auth/email/client.tsx
|
|
97
100
|
var TokenContext = (0, import_react.createContext)({
|
|
98
|
-
token:
|
|
101
|
+
token: void 0,
|
|
99
102
|
setToken: () => null
|
|
100
103
|
});
|
|
101
|
-
var AuthWrapper = ({
|
|
102
|
-
|
|
104
|
+
var AuthWrapper = ({
|
|
105
|
+
children,
|
|
106
|
+
onTokenUpdate
|
|
107
|
+
}) => {
|
|
108
|
+
const [token, setToken] = (0, import_react.useState)();
|
|
109
|
+
(0, import_react.useEffect)(() => {
|
|
110
|
+
if (onTokenUpdate && token !== void 0) {
|
|
111
|
+
onTokenUpdate(token);
|
|
112
|
+
}
|
|
113
|
+
}, [token]);
|
|
103
114
|
return /* @__PURE__ */ import_react.default.createElement(TokenContext.Provider, { value: { token, setToken } }, children);
|
|
104
115
|
};
|
|
105
|
-
function useAuthFetch() {
|
|
116
|
+
function useAuthFetch(getRefreshToken) {
|
|
106
117
|
const setToken = useSetToken();
|
|
107
|
-
|
|
118
|
+
const fetchToken = async () => {
|
|
108
119
|
fetch(getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */), {
|
|
109
|
-
credentials: "include"
|
|
120
|
+
credentials: "include",
|
|
121
|
+
body: getRefreshToken ? JSON.stringify({
|
|
122
|
+
[REFRESH_COOKIE_NAME]: await getRefreshToken()
|
|
123
|
+
}) : void 0
|
|
110
124
|
}).then((res) => res.json()).then((data) => setToken(data.accessToken));
|
|
125
|
+
};
|
|
126
|
+
(0, import_react.useEffect)(() => {
|
|
127
|
+
fetchToken();
|
|
111
128
|
}, []);
|
|
112
129
|
}
|
|
113
130
|
function AuthApply({ data }) {
|
|
@@ -5,8 +5,8 @@ import React__default, { Dispatch, SetStateAction } from 'react';
|
|
|
5
5
|
* @category Auth
|
|
6
6
|
*/
|
|
7
7
|
declare const TokenContext: React__default.Context<{
|
|
8
|
-
token: string | null;
|
|
9
|
-
setToken: Dispatch<SetStateAction<string | null>>;
|
|
8
|
+
token: string | null | undefined;
|
|
9
|
+
setToken: Dispatch<SetStateAction<string | null | undefined>>;
|
|
10
10
|
}>;
|
|
11
11
|
/**
|
|
12
12
|
* Provider that fetches the current access token from your auth endpoint and exposes it via TokenContext.
|
|
@@ -39,10 +39,11 @@ declare const TokenContext: React__default.Context<{
|
|
|
39
39
|
*
|
|
40
40
|
* @category Auth
|
|
41
41
|
*/
|
|
42
|
-
declare const AuthWrapper: ({ children }: {
|
|
42
|
+
declare const AuthWrapper: ({ children, onTokenUpdate, }: {
|
|
43
43
|
children: React__default.ReactNode;
|
|
44
|
+
onTokenUpdate?: (token: string | null) => void;
|
|
44
45
|
}) => React__default.JSX.Element;
|
|
45
|
-
declare function useAuthFetch(): void;
|
|
46
|
+
declare function useAuthFetch(getRefreshToken?: () => Promise<string>): void;
|
|
46
47
|
declare function AuthApply({ data }: {
|
|
47
48
|
data?: string | null;
|
|
48
49
|
}): null;
|
|
@@ -73,7 +74,7 @@ declare function AuthApply({ data }: {
|
|
|
73
74
|
*
|
|
74
75
|
* @category Auth
|
|
75
76
|
*/
|
|
76
|
-
declare function useToken(): string | null;
|
|
77
|
+
declare function useToken(): string | null | undefined;
|
|
77
78
|
/**
|
|
78
79
|
* Returns the setter for the access token in TokenContext. Use to update token after login/signup or clear it on logout.
|
|
79
80
|
* Must be used inside `AuthWrapper`. Typically you won't need this directly — use `useLogin`, `useSignUp`, and `useLogout` instead.
|
|
@@ -82,7 +83,7 @@ declare function useToken(): string | null;
|
|
|
82
83
|
*
|
|
83
84
|
* @category Auth
|
|
84
85
|
*/
|
|
85
|
-
declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
|
|
86
|
+
declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null | undefined>>;
|
|
86
87
|
/**
|
|
87
88
|
* Returns a sign-up function that POSTs to the auth endpoint with credentials. On success, the response's
|
|
88
89
|
* `accessToken` is stored and the token context updates automatically.
|
|
@@ -5,8 +5,8 @@ import React__default, { Dispatch, SetStateAction } from 'react';
|
|
|
5
5
|
* @category Auth
|
|
6
6
|
*/
|
|
7
7
|
declare const TokenContext: React__default.Context<{
|
|
8
|
-
token: string | null;
|
|
9
|
-
setToken: Dispatch<SetStateAction<string | null>>;
|
|
8
|
+
token: string | null | undefined;
|
|
9
|
+
setToken: Dispatch<SetStateAction<string | null | undefined>>;
|
|
10
10
|
}>;
|
|
11
11
|
/**
|
|
12
12
|
* Provider that fetches the current access token from your auth endpoint and exposes it via TokenContext.
|
|
@@ -39,10 +39,11 @@ declare const TokenContext: React__default.Context<{
|
|
|
39
39
|
*
|
|
40
40
|
* @category Auth
|
|
41
41
|
*/
|
|
42
|
-
declare const AuthWrapper: ({ children }: {
|
|
42
|
+
declare const AuthWrapper: ({ children, onTokenUpdate, }: {
|
|
43
43
|
children: React__default.ReactNode;
|
|
44
|
+
onTokenUpdate?: (token: string | null) => void;
|
|
44
45
|
}) => React__default.JSX.Element;
|
|
45
|
-
declare function useAuthFetch(): void;
|
|
46
|
+
declare function useAuthFetch(getRefreshToken?: () => Promise<string>): void;
|
|
46
47
|
declare function AuthApply({ data }: {
|
|
47
48
|
data?: string | null;
|
|
48
49
|
}): null;
|
|
@@ -73,7 +74,7 @@ declare function AuthApply({ data }: {
|
|
|
73
74
|
*
|
|
74
75
|
* @category Auth
|
|
75
76
|
*/
|
|
76
|
-
declare function useToken(): string | null;
|
|
77
|
+
declare function useToken(): string | null | undefined;
|
|
77
78
|
/**
|
|
78
79
|
* Returns the setter for the access token in TokenContext. Use to update token after login/signup or clear it on logout.
|
|
79
80
|
* Must be used inside `AuthWrapper`. Typically you won't need this directly — use `useLogin`, `useSignUp`, and `useLogout` instead.
|
|
@@ -82,7 +83,7 @@ declare function useToken(): string | null;
|
|
|
82
83
|
*
|
|
83
84
|
* @category Auth
|
|
84
85
|
*/
|
|
85
|
-
declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
|
|
86
|
+
declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null | undefined>>;
|
|
86
87
|
/**
|
|
87
88
|
* Returns a sign-up function that POSTs to the auth endpoint with credentials. On success, the response's
|
|
88
89
|
* `accessToken` is stored and the token context updates automatically.
|
|
@@ -9,6 +9,9 @@ import React, {
|
|
|
9
9
|
useState
|
|
10
10
|
} from "react";
|
|
11
11
|
|
|
12
|
+
// src/auth/constants.ts
|
|
13
|
+
var REFRESH_COOKIE_NAME = "refresh";
|
|
14
|
+
|
|
12
15
|
// src/env.ts
|
|
13
16
|
var getEnvValue = (key) => {
|
|
14
17
|
switch (key) {
|
|
@@ -60,19 +63,33 @@ function getEnv(key, skipCheck) {
|
|
|
60
63
|
|
|
61
64
|
// src/auth/email/client.tsx
|
|
62
65
|
var TokenContext = createContext({
|
|
63
|
-
token:
|
|
66
|
+
token: void 0,
|
|
64
67
|
setToken: () => null
|
|
65
68
|
});
|
|
66
|
-
var AuthWrapper = ({
|
|
67
|
-
|
|
69
|
+
var AuthWrapper = ({
|
|
70
|
+
children,
|
|
71
|
+
onTokenUpdate
|
|
72
|
+
}) => {
|
|
73
|
+
const [token, setToken] = useState();
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (onTokenUpdate && token !== void 0) {
|
|
76
|
+
onTokenUpdate(token);
|
|
77
|
+
}
|
|
78
|
+
}, [token]);
|
|
68
79
|
return /* @__PURE__ */ React.createElement(TokenContext.Provider, { value: { token, setToken } }, children);
|
|
69
80
|
};
|
|
70
|
-
function useAuthFetch() {
|
|
81
|
+
function useAuthFetch(getRefreshToken) {
|
|
71
82
|
const setToken = useSetToken();
|
|
72
|
-
|
|
83
|
+
const fetchToken = async () => {
|
|
73
84
|
fetch(getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */), {
|
|
74
|
-
credentials: "include"
|
|
85
|
+
credentials: "include",
|
|
86
|
+
body: getRefreshToken ? JSON.stringify({
|
|
87
|
+
[REFRESH_COOKIE_NAME]: await getRefreshToken()
|
|
88
|
+
}) : void 0
|
|
75
89
|
}).then((res) => res.json()).then((data) => setToken(data.accessToken));
|
|
90
|
+
};
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
fetchToken();
|
|
76
93
|
}, []);
|
|
77
94
|
}
|
|
78
95
|
function AuthApply({ data }) {
|
|
@@ -243,7 +243,9 @@ var getDeleteRoute = (options) => async (req) => {
|
|
|
243
243
|
// src/auth/email/routes/get.ts
|
|
244
244
|
var getGetRoute = (options) => async (req) => {
|
|
245
245
|
const refresh = req.cookies.get(REFRESH_COOKIE_NAME)?.value;
|
|
246
|
-
const
|
|
246
|
+
const requestBody = refresh ? null : await req.json();
|
|
247
|
+
const bodyRefresh = requestBody?.[REFRESH_COOKIE_NAME];
|
|
248
|
+
const userID = getUserIdFromRefreshToken(refresh || bodyRefresh);
|
|
247
249
|
if (userID) {
|
|
248
250
|
if (options.onRefresh) {
|
|
249
251
|
const body = await req.json();
|
|
@@ -206,7 +206,9 @@ var getDeleteRoute = (options) => async (req) => {
|
|
|
206
206
|
// src/auth/email/routes/get.ts
|
|
207
207
|
var getGetRoute = (options) => async (req) => {
|
|
208
208
|
const refresh = req.cookies.get(REFRESH_COOKIE_NAME)?.value;
|
|
209
|
-
const
|
|
209
|
+
const requestBody = refresh ? null : await req.json();
|
|
210
|
+
const bodyRefresh = requestBody?.[REFRESH_COOKIE_NAME];
|
|
211
|
+
const userID = getUserIdFromRefreshToken(refresh || bodyRefresh);
|
|
210
212
|
if (userID) {
|
|
211
213
|
if (options.onRefresh) {
|
|
212
214
|
const body = await req.json();
|
|
@@ -124,7 +124,9 @@ function getUserIdFromRefreshToken(refreshToken) {
|
|
|
124
124
|
// src/auth/email/routes/get.ts
|
|
125
125
|
var getGetRoute = (options) => async (req) => {
|
|
126
126
|
const refresh = req.cookies.get(REFRESH_COOKIE_NAME)?.value;
|
|
127
|
-
const
|
|
127
|
+
const requestBody = refresh ? null : await req.json();
|
|
128
|
+
const bodyRefresh = requestBody?.[REFRESH_COOKIE_NAME];
|
|
129
|
+
const userID = getUserIdFromRefreshToken(refresh || bodyRefresh);
|
|
128
130
|
if (userID) {
|
|
129
131
|
if (options.onRefresh) {
|
|
130
132
|
const body = await req.json();
|
|
@@ -98,7 +98,9 @@ function getUserIdFromRefreshToken(refreshToken) {
|
|
|
98
98
|
// src/auth/email/routes/get.ts
|
|
99
99
|
var getGetRoute = (options) => async (req) => {
|
|
100
100
|
const refresh = req.cookies.get(REFRESH_COOKIE_NAME)?.value;
|
|
101
|
-
const
|
|
101
|
+
const requestBody = refresh ? null : await req.json();
|
|
102
|
+
const bodyRefresh = requestBody?.[REFRESH_COOKIE_NAME];
|
|
103
|
+
const userID = getUserIdFromRefreshToken(refresh || bodyRefresh);
|
|
102
104
|
if (userID) {
|
|
103
105
|
if (options.onRefresh) {
|
|
104
106
|
const body = await req.json();
|
package/dist/auth/index.cjs.js
CHANGED
|
@@ -261,7 +261,9 @@ var getDeleteRoute = (options) => async (req) => {
|
|
|
261
261
|
// src/auth/email/routes/get.ts
|
|
262
262
|
var getGetRoute = (options) => async (req) => {
|
|
263
263
|
const refresh = req.cookies.get(REFRESH_COOKIE_NAME)?.value;
|
|
264
|
-
const
|
|
264
|
+
const requestBody = refresh ? null : await req.json();
|
|
265
|
+
const bodyRefresh = requestBody?.[REFRESH_COOKIE_NAME];
|
|
266
|
+
const userID = getUserIdFromRefreshToken(refresh || bodyRefresh);
|
|
265
267
|
if (userID) {
|
|
266
268
|
if (options.onRefresh) {
|
|
267
269
|
const body = await req.json();
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -218,7 +218,9 @@ var getDeleteRoute = (options) => async (req) => {
|
|
|
218
218
|
// src/auth/email/routes/get.ts
|
|
219
219
|
var getGetRoute = (options) => async (req) => {
|
|
220
220
|
const refresh = req.cookies.get(REFRESH_COOKIE_NAME)?.value;
|
|
221
|
-
const
|
|
221
|
+
const requestBody = refresh ? null : await req.json();
|
|
222
|
+
const bodyRefresh = requestBody?.[REFRESH_COOKIE_NAME];
|
|
223
|
+
const userID = getUserIdFromRefreshToken(refresh || bodyRefresh);
|
|
222
224
|
if (userID) {
|
|
223
225
|
if (options.onRefresh) {
|
|
224
226
|
const body = await req.json();
|
|
@@ -38,7 +38,6 @@ __export(client_exports, {
|
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(client_exports);
|
|
40
40
|
var import_client = require("@apollo/client");
|
|
41
|
-
var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
|
|
42
41
|
var import_client2 = require("naystack/auth/email/client");
|
|
43
42
|
var import_react = __toESM(require("react"));
|
|
44
43
|
|
|
@@ -92,19 +91,19 @@ function getEnv(key, skipCheck) {
|
|
|
92
91
|
}
|
|
93
92
|
|
|
94
93
|
// src/graphql/client.tsx
|
|
94
|
+
function makeClient(cacheConfig) {
|
|
95
|
+
return new import_client.ApolloClient({
|
|
96
|
+
cache: new import_client.InMemoryCache(cacheConfig),
|
|
97
|
+
link: new import_client.HttpLink({
|
|
98
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
}
|
|
95
102
|
var ApolloWrapper = ({
|
|
96
103
|
children,
|
|
97
104
|
cacheConfig
|
|
98
105
|
}) => {
|
|
99
|
-
|
|
100
|
-
return new import_client_integration_nextjs.ApolloClient({
|
|
101
|
-
cache: new import_client_integration_nextjs.InMemoryCache(cacheConfig),
|
|
102
|
-
link: new import_client.HttpLink({
|
|
103
|
-
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
104
|
-
})
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
return /* @__PURE__ */ import_react.default.createElement(import_client_integration_nextjs.ApolloNextAppProvider, { makeClient }, children);
|
|
106
|
+
return /* @__PURE__ */ import_react.default.createElement(import_client.ApolloProvider, { client: makeClient(cacheConfig) }, children);
|
|
108
107
|
};
|
|
109
108
|
var tokenContext = (token) => {
|
|
110
109
|
if (!token) return void 0;
|
|
@@ -3,38 +3,6 @@ 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
|
-
/**
|
|
7
|
-
* Apollo Client provider for Next.js. Wrap your app (or a subtree) so client components can run GraphQL queries and mutations.
|
|
8
|
-
* The GraphQL endpoint is read from `NEXT_PUBLIC_GRAPHQL_ENDPOINT` env var.
|
|
9
|
-
*
|
|
10
|
-
* Must be placed **inside** `AuthWrapper` (since `useAuthQuery` / `useAuthMutation` depend on the auth token).
|
|
11
|
-
*
|
|
12
|
-
* @param props - Component props.
|
|
13
|
-
* @param props.children - React children (your app or page content).
|
|
14
|
-
* @param props.cacheConfig - Optional `InMemoryCache` config (e.g. `typePolicies`, `addTypename`). Passed to Apollo's `InMemoryCache`.
|
|
15
|
-
* @returns Provider component that supplies Apollo Client to the tree.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* // app/layout.tsx
|
|
20
|
-
* import { AuthWrapper } from "naystack/auth/email/client";
|
|
21
|
-
* import { ApolloWrapper } from "naystack/graphql/client";
|
|
22
|
-
*
|
|
23
|
-
* export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
24
|
-
* return (
|
|
25
|
-
* <html lang="en">
|
|
26
|
-
* <body>
|
|
27
|
-
* <AuthWrapper>
|
|
28
|
-
* <ApolloWrapper>{children}</ApolloWrapper>
|
|
29
|
-
* </AuthWrapper>
|
|
30
|
-
* </body>
|
|
31
|
-
* </html>
|
|
32
|
-
* );
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @category GraphQL
|
|
37
|
-
*/
|
|
38
6
|
declare const ApolloWrapper: ({ children, cacheConfig, }: PropsWithChildren<{
|
|
39
7
|
cacheConfig?: InMemoryCacheConfig;
|
|
40
8
|
}>) => React__default.JSX.Element;
|
package/dist/graphql/client.d.ts
CHANGED
|
@@ -3,38 +3,6 @@ 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
|
-
/**
|
|
7
|
-
* Apollo Client provider for Next.js. Wrap your app (or a subtree) so client components can run GraphQL queries and mutations.
|
|
8
|
-
* The GraphQL endpoint is read from `NEXT_PUBLIC_GRAPHQL_ENDPOINT` env var.
|
|
9
|
-
*
|
|
10
|
-
* Must be placed **inside** `AuthWrapper` (since `useAuthQuery` / `useAuthMutation` depend on the auth token).
|
|
11
|
-
*
|
|
12
|
-
* @param props - Component props.
|
|
13
|
-
* @param props.children - React children (your app or page content).
|
|
14
|
-
* @param props.cacheConfig - Optional `InMemoryCache` config (e.g. `typePolicies`, `addTypename`). Passed to Apollo's `InMemoryCache`.
|
|
15
|
-
* @returns Provider component that supplies Apollo Client to the tree.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* // app/layout.tsx
|
|
20
|
-
* import { AuthWrapper } from "naystack/auth/email/client";
|
|
21
|
-
* import { ApolloWrapper } from "naystack/graphql/client";
|
|
22
|
-
*
|
|
23
|
-
* export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
24
|
-
* return (
|
|
25
|
-
* <html lang="en">
|
|
26
|
-
* <body>
|
|
27
|
-
* <AuthWrapper>
|
|
28
|
-
* <ApolloWrapper>{children}</ApolloWrapper>
|
|
29
|
-
* </AuthWrapper>
|
|
30
|
-
* </body>
|
|
31
|
-
* </html>
|
|
32
|
-
* );
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @category GraphQL
|
|
37
|
-
*/
|
|
38
6
|
declare const ApolloWrapper: ({ children, cacheConfig, }: PropsWithChildren<{
|
|
39
7
|
cacheConfig?: InMemoryCacheConfig;
|
|
40
8
|
}>) => React__default.JSX.Element;
|
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
// src/graphql/client.tsx
|
|
4
4
|
import {
|
|
5
|
+
ApolloClient,
|
|
6
|
+
ApolloProvider,
|
|
5
7
|
HttpLink,
|
|
8
|
+
InMemoryCache,
|
|
6
9
|
useLazyQuery,
|
|
7
10
|
useMutation
|
|
8
11
|
} from "@apollo/client";
|
|
9
|
-
import {
|
|
10
|
-
ApolloClient,
|
|
11
|
-
ApolloNextAppProvider,
|
|
12
|
-
InMemoryCache
|
|
13
|
-
} from "@apollo/client-integration-nextjs";
|
|
14
12
|
import { useToken } from "naystack/auth/email/client";
|
|
15
13
|
import React, {
|
|
16
14
|
useCallback,
|
|
@@ -68,19 +66,19 @@ function getEnv(key, skipCheck) {
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
// src/graphql/client.tsx
|
|
69
|
+
function makeClient(cacheConfig) {
|
|
70
|
+
return new ApolloClient({
|
|
71
|
+
cache: new InMemoryCache(cacheConfig),
|
|
72
|
+
link: new HttpLink({
|
|
73
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
}
|
|
71
77
|
var ApolloWrapper = ({
|
|
72
78
|
children,
|
|
73
79
|
cacheConfig
|
|
74
80
|
}) => {
|
|
75
|
-
|
|
76
|
-
return new ApolloClient({
|
|
77
|
-
cache: new InMemoryCache(cacheConfig),
|
|
78
|
-
link: new HttpLink({
|
|
79
|
-
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
80
|
-
})
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return /* @__PURE__ */ React.createElement(ApolloNextAppProvider, { makeClient }, children);
|
|
81
|
+
return /* @__PURE__ */ React.createElement(ApolloProvider, { client: makeClient(cacheConfig) }, children);
|
|
84
82
|
};
|
|
85
83
|
var tokenContext = (token) => {
|
|
86
84
|
if (!token) return void 0;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/graphql/next.tsx
|
|
32
|
+
var next_exports = {};
|
|
33
|
+
__export(next_exports, {
|
|
34
|
+
ApolloWrapper: () => ApolloWrapper
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(next_exports);
|
|
37
|
+
var import_client = require("@apollo/client");
|
|
38
|
+
var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
|
|
39
|
+
var import_react = __toESM(require("react"));
|
|
40
|
+
|
|
41
|
+
// src/env.ts
|
|
42
|
+
var getEnvValue = (key) => {
|
|
43
|
+
switch (key) {
|
|
44
|
+
case "NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */:
|
|
45
|
+
return process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT || process.env.EXPO_PUBLIC_GRAPHQL_ENDPOINT;
|
|
46
|
+
case "NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */:
|
|
47
|
+
return process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT || process.env.EXPO_PUBLIC_EMAIL_AUTH_ENDPOINT;
|
|
48
|
+
case "NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT" /* NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT */:
|
|
49
|
+
return process.env.NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT || process.env.EXPO_PUBLIC_GOOGLE_AUTH_ENDPOINT;
|
|
50
|
+
case "NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT" /* NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT */:
|
|
51
|
+
return process.env.NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT || process.env.EXPO_PUBLIC_INSTAGRAM_AUTH_ENDPOINT;
|
|
52
|
+
case "NEXT_PUBLIC_FILE_ENDPOINT" /* NEXT_PUBLIC_FILE_ENDPOINT */:
|
|
53
|
+
return process.env.NEXT_PUBLIC_FILE_ENDPOINT || process.env.EXPO_PUBLIC_FILE_ENDPOINT;
|
|
54
|
+
case "NEXT_PUBLIC_BASE_URL" /* NEXT_PUBLIC_BASE_URL */:
|
|
55
|
+
return process.env.NEXT_PUBLIC_BASE_URL || process.env.EXPO_PUBLIC_BASE_URL;
|
|
56
|
+
case "REFRESH_KEY" /* REFRESH_KEY */:
|
|
57
|
+
return process.env.REFRESH_KEY;
|
|
58
|
+
case "SIGNING_KEY" /* SIGNING_KEY */:
|
|
59
|
+
return process.env.SIGNING_KEY;
|
|
60
|
+
case "INSTAGRAM_CLIENT_SECRET" /* INSTAGRAM_CLIENT_SECRET */:
|
|
61
|
+
return process.env.INSTAGRAM_CLIENT_SECRET;
|
|
62
|
+
case "INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */:
|
|
63
|
+
return process.env.INSTAGRAM_CLIENT_ID;
|
|
64
|
+
case "GOOGLE_CLIENT_SECRET" /* GOOGLE_CLIENT_SECRET */:
|
|
65
|
+
return process.env.GOOGLE_CLIENT_SECRET;
|
|
66
|
+
case "GOOGLE_CLIENT_ID" /* GOOGLE_CLIENT_ID */:
|
|
67
|
+
return process.env.GOOGLE_CLIENT_ID;
|
|
68
|
+
case "TURNSTILE_KEY" /* TURNSTILE_KEY */:
|
|
69
|
+
return process.env.TURNSTILE_KEY;
|
|
70
|
+
case "AWS_ACCESS_KEY_ID" /* AWS_ACCESS_KEY_ID */:
|
|
71
|
+
return process.env.AWS_ACCESS_KEY_ID;
|
|
72
|
+
case "AWS_ACCESS_KEY_SECRET" /* AWS_ACCESS_KEY_SECRET */:
|
|
73
|
+
return process.env.AWS_ACCESS_KEY_SECRET;
|
|
74
|
+
case "AWS_REGION" /* AWS_REGION */:
|
|
75
|
+
return process.env.AWS_REGION;
|
|
76
|
+
case "AWS_BUCKET" /* AWS_BUCKET */:
|
|
77
|
+
return process.env.AWS_BUCKET;
|
|
78
|
+
case "NODE_ENV" /* NODE_ENV */:
|
|
79
|
+
return process.env.NODE_ENV;
|
|
80
|
+
default:
|
|
81
|
+
return process.env[key];
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
function getEnv(key, skipCheck) {
|
|
85
|
+
const value = getEnvValue(key);
|
|
86
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/graphql/next.tsx
|
|
91
|
+
function makeClient(cacheConfig) {
|
|
92
|
+
return new import_client_integration_nextjs.ApolloClient({
|
|
93
|
+
cache: new import_client_integration_nextjs.InMemoryCache(cacheConfig),
|
|
94
|
+
link: new import_client.HttpLink({
|
|
95
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
var ApolloWrapper = ({
|
|
100
|
+
children,
|
|
101
|
+
cacheConfig
|
|
102
|
+
}) => {
|
|
103
|
+
return /* @__PURE__ */ import_react.default.createElement(import_client_integration_nextjs.ApolloNextAppProvider, { makeClient: () => makeClient(cacheConfig) }, children);
|
|
104
|
+
};
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
ApolloWrapper
|
|
108
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InMemoryCacheConfig } from '@apollo/client';
|
|
2
|
+
import React__default, { PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
declare const ApolloWrapper: ({ children, cacheConfig, }: PropsWithChildren<{
|
|
5
|
+
cacheConfig?: InMemoryCacheConfig;
|
|
6
|
+
}>) => React__default.JSX.Element;
|
|
7
|
+
|
|
8
|
+
export { ApolloWrapper };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InMemoryCacheConfig } from '@apollo/client';
|
|
2
|
+
import React__default, { PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
declare const ApolloWrapper: ({ children, cacheConfig, }: PropsWithChildren<{
|
|
5
|
+
cacheConfig?: InMemoryCacheConfig;
|
|
6
|
+
}>) => React__default.JSX.Element;
|
|
7
|
+
|
|
8
|
+
export { ApolloWrapper };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/graphql/next.tsx
|
|
4
|
+
import { HttpLink } from "@apollo/client";
|
|
5
|
+
import {
|
|
6
|
+
ApolloClient,
|
|
7
|
+
ApolloNextAppProvider,
|
|
8
|
+
InMemoryCache
|
|
9
|
+
} from "@apollo/client-integration-nextjs";
|
|
10
|
+
import React from "react";
|
|
11
|
+
|
|
12
|
+
// src/env.ts
|
|
13
|
+
var getEnvValue = (key) => {
|
|
14
|
+
switch (key) {
|
|
15
|
+
case "NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */:
|
|
16
|
+
return process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT || process.env.EXPO_PUBLIC_GRAPHQL_ENDPOINT;
|
|
17
|
+
case "NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */:
|
|
18
|
+
return process.env.NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT || process.env.EXPO_PUBLIC_EMAIL_AUTH_ENDPOINT;
|
|
19
|
+
case "NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT" /* NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT */:
|
|
20
|
+
return process.env.NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT || process.env.EXPO_PUBLIC_GOOGLE_AUTH_ENDPOINT;
|
|
21
|
+
case "NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT" /* NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT */:
|
|
22
|
+
return process.env.NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT || process.env.EXPO_PUBLIC_INSTAGRAM_AUTH_ENDPOINT;
|
|
23
|
+
case "NEXT_PUBLIC_FILE_ENDPOINT" /* NEXT_PUBLIC_FILE_ENDPOINT */:
|
|
24
|
+
return process.env.NEXT_PUBLIC_FILE_ENDPOINT || process.env.EXPO_PUBLIC_FILE_ENDPOINT;
|
|
25
|
+
case "NEXT_PUBLIC_BASE_URL" /* NEXT_PUBLIC_BASE_URL */:
|
|
26
|
+
return process.env.NEXT_PUBLIC_BASE_URL || process.env.EXPO_PUBLIC_BASE_URL;
|
|
27
|
+
case "REFRESH_KEY" /* REFRESH_KEY */:
|
|
28
|
+
return process.env.REFRESH_KEY;
|
|
29
|
+
case "SIGNING_KEY" /* SIGNING_KEY */:
|
|
30
|
+
return process.env.SIGNING_KEY;
|
|
31
|
+
case "INSTAGRAM_CLIENT_SECRET" /* INSTAGRAM_CLIENT_SECRET */:
|
|
32
|
+
return process.env.INSTAGRAM_CLIENT_SECRET;
|
|
33
|
+
case "INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */:
|
|
34
|
+
return process.env.INSTAGRAM_CLIENT_ID;
|
|
35
|
+
case "GOOGLE_CLIENT_SECRET" /* GOOGLE_CLIENT_SECRET */:
|
|
36
|
+
return process.env.GOOGLE_CLIENT_SECRET;
|
|
37
|
+
case "GOOGLE_CLIENT_ID" /* GOOGLE_CLIENT_ID */:
|
|
38
|
+
return process.env.GOOGLE_CLIENT_ID;
|
|
39
|
+
case "TURNSTILE_KEY" /* TURNSTILE_KEY */:
|
|
40
|
+
return process.env.TURNSTILE_KEY;
|
|
41
|
+
case "AWS_ACCESS_KEY_ID" /* AWS_ACCESS_KEY_ID */:
|
|
42
|
+
return process.env.AWS_ACCESS_KEY_ID;
|
|
43
|
+
case "AWS_ACCESS_KEY_SECRET" /* AWS_ACCESS_KEY_SECRET */:
|
|
44
|
+
return process.env.AWS_ACCESS_KEY_SECRET;
|
|
45
|
+
case "AWS_REGION" /* AWS_REGION */:
|
|
46
|
+
return process.env.AWS_REGION;
|
|
47
|
+
case "AWS_BUCKET" /* AWS_BUCKET */:
|
|
48
|
+
return process.env.AWS_BUCKET;
|
|
49
|
+
case "NODE_ENV" /* NODE_ENV */:
|
|
50
|
+
return process.env.NODE_ENV;
|
|
51
|
+
default:
|
|
52
|
+
return process.env[key];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
function getEnv(key, skipCheck) {
|
|
56
|
+
const value = getEnvValue(key);
|
|
57
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/graphql/next.tsx
|
|
62
|
+
function makeClient(cacheConfig) {
|
|
63
|
+
return new ApolloClient({
|
|
64
|
+
cache: new InMemoryCache(cacheConfig),
|
|
65
|
+
link: new HttpLink({
|
|
66
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
var ApolloWrapper = ({
|
|
71
|
+
children,
|
|
72
|
+
cacheConfig
|
|
73
|
+
}) => {
|
|
74
|
+
return /* @__PURE__ */ React.createElement(ApolloNextAppProvider, { makeClient: () => makeClient(cacheConfig) }, children);
|
|
75
|
+
};
|
|
76
|
+
export {
|
|
77
|
+
ApolloWrapper
|
|
78
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "naystack",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.28",
|
|
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",
|
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
"import": "./dist/graphql/client.esm.js",
|
|
34
34
|
"require": "./dist/graphql/client.cjs.js"
|
|
35
35
|
},
|
|
36
|
+
"./graphql/next": {
|
|
37
|
+
"types": "./dist/graphql/next.d.ts",
|
|
38
|
+
"import": "./dist/graphql/next.esm.js",
|
|
39
|
+
"require": "./dist/graphql/next.cjs.js"
|
|
40
|
+
},
|
|
36
41
|
"./auth/email/client": {
|
|
37
42
|
"types": "./dist/auth/email/client.d.ts",
|
|
38
43
|
"import": "./dist/auth/email/client.esm.js",
|