naystack 1.8.4 → 1.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/client.cjs.js +10 -43
- package/dist/auth/client.d.mts +1 -1
- package/dist/auth/client.d.ts +1 -1
- package/dist/auth/client.esm.js +14 -38
- package/dist/auth/email/client.cjs.js +10 -43
- package/dist/auth/email/client.d.mts +2 -2
- package/dist/auth/email/client.d.ts +2 -2
- package/dist/auth/email/client.esm.js +14 -38
- package/dist/auth/email/index.d.mts +1 -1
- package/dist/auth/email/index.d.ts +1 -1
- package/dist/auth/email/next.d.mts +1 -1
- package/dist/auth/email/next.d.ts +1 -1
- package/dist/auth/index.d.mts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/graphql/client.cjs.js +8 -36
- package/dist/graphql/client.esm.js +6 -34
- package/dist/graphql/links.cjs.js +3 -31
- package/dist/graphql/links.esm.js +1 -29
- package/dist/graphql/next.cjs.js +3 -31
- package/dist/graphql/next.esm.js +1 -29
- package/package.json +6 -1
package/dist/auth/client.cjs.js
CHANGED
|
@@ -34,9 +34,9 @@ __export(client_exports, {
|
|
|
34
34
|
AuthApply: () => AuthApply,
|
|
35
35
|
AuthWrapper: () => AuthWrapper,
|
|
36
36
|
TokenContext: () => TokenContext,
|
|
37
|
-
getAccessToken: () => getAccessToken,
|
|
38
|
-
refreshAccessToken: () => refreshAccessToken,
|
|
39
|
-
setAccessToken: () => setAccessToken,
|
|
37
|
+
getAccessToken: () => import_token_store2.getAccessToken,
|
|
38
|
+
refreshAccessToken: () => import_token_store2.refreshAccessToken,
|
|
39
|
+
setAccessToken: () => import_token_store2.setAccessToken,
|
|
40
40
|
useAuthFetch: () => useAuthFetch,
|
|
41
41
|
useLogin: () => useLogin,
|
|
42
42
|
useLogout: () => useLogout,
|
|
@@ -47,6 +47,7 @@ __export(client_exports, {
|
|
|
47
47
|
module.exports = __toCommonJS(client_exports);
|
|
48
48
|
|
|
49
49
|
// src/auth/email/client.tsx
|
|
50
|
+
var import_token_store = require("naystack/auth/token-store");
|
|
50
51
|
var import_react = __toESM(require("react"));
|
|
51
52
|
|
|
52
53
|
// src/env.ts
|
|
@@ -99,42 +100,8 @@ function getEnv(key, skipCheck) {
|
|
|
99
100
|
return value;
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
// src/auth/token-store.ts
|
|
103
|
-
var currentToken;
|
|
104
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
105
|
-
var inFlightRefresh = null;
|
|
106
|
-
function getAccessToken() {
|
|
107
|
-
return currentToken;
|
|
108
|
-
}
|
|
109
|
-
function setAccessToken(token) {
|
|
110
|
-
if (token === currentToken) return;
|
|
111
|
-
currentToken = token;
|
|
112
|
-
listeners.forEach((listener) => listener(token));
|
|
113
|
-
}
|
|
114
|
-
function subscribeToAccessToken(listener) {
|
|
115
|
-
listeners.add(listener);
|
|
116
|
-
return () => {
|
|
117
|
-
listeners.delete(listener);
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function refreshAccessToken() {
|
|
121
|
-
if (inFlightRefresh) return inFlightRefresh;
|
|
122
|
-
inFlightRefresh = (async () => {
|
|
123
|
-
const res = await fetch(
|
|
124
|
-
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
125
|
-
{ credentials: "include" }
|
|
126
|
-
);
|
|
127
|
-
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
128
|
-
const token = await res.text() || null;
|
|
129
|
-
setAccessToken(token);
|
|
130
|
-
return token;
|
|
131
|
-
})().finally(() => {
|
|
132
|
-
inFlightRefresh = null;
|
|
133
|
-
});
|
|
134
|
-
return inFlightRefresh;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
103
|
// src/auth/email/client.tsx
|
|
104
|
+
var import_token_store2 = require("naystack/auth/token-store");
|
|
138
105
|
var TokenContext = (0, import_react.createContext)({
|
|
139
106
|
token: void 0,
|
|
140
107
|
setToken: () => null
|
|
@@ -144,12 +111,12 @@ var AuthWrapper = ({
|
|
|
144
111
|
skipInitialFetch
|
|
145
112
|
}) => {
|
|
146
113
|
const [token, setTokenState] = (0, import_react.useState)(
|
|
147
|
-
getAccessToken
|
|
114
|
+
import_token_store.getAccessToken
|
|
148
115
|
);
|
|
149
|
-
(0, import_react.useEffect)(() => subscribeToAccessToken(setTokenState), []);
|
|
116
|
+
(0, import_react.useEffect)(() => (0, import_token_store.subscribeToAccessToken)(setTokenState), []);
|
|
150
117
|
const setToken = (0, import_react.useCallback)((action) => {
|
|
151
|
-
setAccessToken(
|
|
152
|
-
typeof action === "function" ? action(getAccessToken()) : action
|
|
118
|
+
(0, import_token_store.setAccessToken)(
|
|
119
|
+
typeof action === "function" ? action((0, import_token_store.getAccessToken)()) : action
|
|
153
120
|
);
|
|
154
121
|
}, []);
|
|
155
122
|
return /* @__PURE__ */ import_react.default.createElement(TokenContext.Provider, { value: { token, setToken } }, !skipInitialFetch && /* @__PURE__ */ import_react.default.createElement(AuthChildComponent, null), children);
|
|
@@ -161,7 +128,7 @@ function AuthChildComponent() {
|
|
|
161
128
|
function useAuthFetch({ skip } = {}) {
|
|
162
129
|
(0, import_react.useEffect)(() => {
|
|
163
130
|
if (skip) return;
|
|
164
|
-
void refreshAccessToken().catch(() => null);
|
|
131
|
+
void (0, import_token_store.refreshAccessToken)().catch(() => null);
|
|
165
132
|
}, []);
|
|
166
133
|
}
|
|
167
134
|
function AuthApply({ data }) {
|
package/dist/auth/client.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { AuthApply, AuthWrapper, AuthWrapperProps, TokenContext, useAuthFetch, useLogin, useLogout, useSetToken, useSignUp, useToken } from './email/client.mjs';
|
|
2
|
-
export { getAccessToken, refreshAccessToken, setAccessToken } from '
|
|
2
|
+
export { getAccessToken, refreshAccessToken, setAccessToken } from 'naystack/auth/token-store';
|
|
3
3
|
import 'react';
|
package/dist/auth/client.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { AuthApply, AuthWrapper, AuthWrapperProps, TokenContext, useAuthFetch, useLogin, useLogout, useSetToken, useSignUp, useToken } from './email/client.js';
|
|
2
|
-
export { getAccessToken, refreshAccessToken, setAccessToken } from '
|
|
2
|
+
export { getAccessToken, refreshAccessToken, setAccessToken } from 'naystack/auth/token-store';
|
|
3
3
|
import 'react';
|
package/dist/auth/client.esm.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/auth/email/client.tsx
|
|
4
|
+
import {
|
|
5
|
+
getAccessToken,
|
|
6
|
+
refreshAccessToken,
|
|
7
|
+
setAccessToken,
|
|
8
|
+
subscribeToAccessToken
|
|
9
|
+
} from "naystack/auth/token-store";
|
|
4
10
|
import React, {
|
|
5
11
|
createContext,
|
|
6
12
|
useCallback,
|
|
@@ -59,42 +65,12 @@ function getEnv(key, skipCheck) {
|
|
|
59
65
|
return value;
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
// src/auth/token-store.ts
|
|
63
|
-
var currentToken;
|
|
64
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
65
|
-
var inFlightRefresh = null;
|
|
66
|
-
function getAccessToken() {
|
|
67
|
-
return currentToken;
|
|
68
|
-
}
|
|
69
|
-
function setAccessToken(token) {
|
|
70
|
-
if (token === currentToken) return;
|
|
71
|
-
currentToken = token;
|
|
72
|
-
listeners.forEach((listener) => listener(token));
|
|
73
|
-
}
|
|
74
|
-
function subscribeToAccessToken(listener) {
|
|
75
|
-
listeners.add(listener);
|
|
76
|
-
return () => {
|
|
77
|
-
listeners.delete(listener);
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function refreshAccessToken() {
|
|
81
|
-
if (inFlightRefresh) return inFlightRefresh;
|
|
82
|
-
inFlightRefresh = (async () => {
|
|
83
|
-
const res = await fetch(
|
|
84
|
-
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
85
|
-
{ credentials: "include" }
|
|
86
|
-
);
|
|
87
|
-
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
88
|
-
const token = await res.text() || null;
|
|
89
|
-
setAccessToken(token);
|
|
90
|
-
return token;
|
|
91
|
-
})().finally(() => {
|
|
92
|
-
inFlightRefresh = null;
|
|
93
|
-
});
|
|
94
|
-
return inFlightRefresh;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
68
|
// src/auth/email/client.tsx
|
|
69
|
+
import {
|
|
70
|
+
getAccessToken as getAccessToken2,
|
|
71
|
+
refreshAccessToken as refreshAccessToken2,
|
|
72
|
+
setAccessToken as setAccessToken2
|
|
73
|
+
} from "naystack/auth/token-store";
|
|
98
74
|
var TokenContext = createContext({
|
|
99
75
|
token: void 0,
|
|
100
76
|
setToken: () => null
|
|
@@ -203,9 +179,9 @@ export {
|
|
|
203
179
|
AuthApply,
|
|
204
180
|
AuthWrapper,
|
|
205
181
|
TokenContext,
|
|
206
|
-
getAccessToken,
|
|
207
|
-
refreshAccessToken,
|
|
208
|
-
setAccessToken,
|
|
182
|
+
getAccessToken2 as getAccessToken,
|
|
183
|
+
refreshAccessToken2 as refreshAccessToken,
|
|
184
|
+
setAccessToken2 as setAccessToken,
|
|
209
185
|
useAuthFetch,
|
|
210
186
|
useLogin,
|
|
211
187
|
useLogout,
|
|
@@ -34,9 +34,9 @@ __export(client_exports, {
|
|
|
34
34
|
AuthApply: () => AuthApply,
|
|
35
35
|
AuthWrapper: () => AuthWrapper,
|
|
36
36
|
TokenContext: () => TokenContext,
|
|
37
|
-
getAccessToken: () => getAccessToken,
|
|
38
|
-
refreshAccessToken: () => refreshAccessToken,
|
|
39
|
-
setAccessToken: () => setAccessToken,
|
|
37
|
+
getAccessToken: () => import_token_store2.getAccessToken,
|
|
38
|
+
refreshAccessToken: () => import_token_store2.refreshAccessToken,
|
|
39
|
+
setAccessToken: () => import_token_store2.setAccessToken,
|
|
40
40
|
useAuthFetch: () => useAuthFetch,
|
|
41
41
|
useLogin: () => useLogin,
|
|
42
42
|
useLogout: () => useLogout,
|
|
@@ -45,6 +45,7 @@ __export(client_exports, {
|
|
|
45
45
|
useToken: () => useToken
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(client_exports);
|
|
48
|
+
var import_token_store = require("naystack/auth/token-store");
|
|
48
49
|
var import_react = __toESM(require("react"));
|
|
49
50
|
|
|
50
51
|
// src/env.ts
|
|
@@ -97,42 +98,8 @@ function getEnv(key, skipCheck) {
|
|
|
97
98
|
return value;
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
// src/auth/token-store.ts
|
|
101
|
-
var currentToken;
|
|
102
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
103
|
-
var inFlightRefresh = null;
|
|
104
|
-
function getAccessToken() {
|
|
105
|
-
return currentToken;
|
|
106
|
-
}
|
|
107
|
-
function setAccessToken(token) {
|
|
108
|
-
if (token === currentToken) return;
|
|
109
|
-
currentToken = token;
|
|
110
|
-
listeners.forEach((listener) => listener(token));
|
|
111
|
-
}
|
|
112
|
-
function subscribeToAccessToken(listener) {
|
|
113
|
-
listeners.add(listener);
|
|
114
|
-
return () => {
|
|
115
|
-
listeners.delete(listener);
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function refreshAccessToken() {
|
|
119
|
-
if (inFlightRefresh) return inFlightRefresh;
|
|
120
|
-
inFlightRefresh = (async () => {
|
|
121
|
-
const res = await fetch(
|
|
122
|
-
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
123
|
-
{ credentials: "include" }
|
|
124
|
-
);
|
|
125
|
-
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
126
|
-
const token = await res.text() || null;
|
|
127
|
-
setAccessToken(token);
|
|
128
|
-
return token;
|
|
129
|
-
})().finally(() => {
|
|
130
|
-
inFlightRefresh = null;
|
|
131
|
-
});
|
|
132
|
-
return inFlightRefresh;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
101
|
// src/auth/email/client.tsx
|
|
102
|
+
var import_token_store2 = require("naystack/auth/token-store");
|
|
136
103
|
var TokenContext = (0, import_react.createContext)({
|
|
137
104
|
token: void 0,
|
|
138
105
|
setToken: () => null
|
|
@@ -142,12 +109,12 @@ var AuthWrapper = ({
|
|
|
142
109
|
skipInitialFetch
|
|
143
110
|
}) => {
|
|
144
111
|
const [token, setTokenState] = (0, import_react.useState)(
|
|
145
|
-
getAccessToken
|
|
112
|
+
import_token_store.getAccessToken
|
|
146
113
|
);
|
|
147
|
-
(0, import_react.useEffect)(() => subscribeToAccessToken(setTokenState), []);
|
|
114
|
+
(0, import_react.useEffect)(() => (0, import_token_store.subscribeToAccessToken)(setTokenState), []);
|
|
148
115
|
const setToken = (0, import_react.useCallback)((action) => {
|
|
149
|
-
setAccessToken(
|
|
150
|
-
typeof action === "function" ? action(getAccessToken()) : action
|
|
116
|
+
(0, import_token_store.setAccessToken)(
|
|
117
|
+
typeof action === "function" ? action((0, import_token_store.getAccessToken)()) : action
|
|
151
118
|
);
|
|
152
119
|
}, []);
|
|
153
120
|
return /* @__PURE__ */ import_react.default.createElement(TokenContext.Provider, { value: { token, setToken } }, !skipInitialFetch && /* @__PURE__ */ import_react.default.createElement(AuthChildComponent, null), children);
|
|
@@ -159,7 +126,7 @@ function AuthChildComponent() {
|
|
|
159
126
|
function useAuthFetch({ skip } = {}) {
|
|
160
127
|
(0, import_react.useEffect)(() => {
|
|
161
128
|
if (skip) return;
|
|
162
|
-
void refreshAccessToken().catch(() => null);
|
|
129
|
+
void (0, import_token_store.refreshAccessToken)().catch(() => null);
|
|
163
130
|
}, []);
|
|
164
131
|
}
|
|
165
132
|
function AuthApply({ data }) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React__default, { Dispatch, SetStateAction, PropsWithChildren } from 'react';
|
|
2
|
-
export { getAccessToken, refreshAccessToken, setAccessToken } from '
|
|
2
|
+
export { getAccessToken, refreshAccessToken, setAccessToken } from 'naystack/auth/token-store';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* React context holding the current access token and setter; used by useToken/useSetToken and auth hooks.
|
|
@@ -45,7 +45,7 @@ type AuthWrapperProps = PropsWithChildren<{
|
|
|
45
45
|
*
|
|
46
46
|
* @category Auth
|
|
47
47
|
*/
|
|
48
|
-
declare const AuthWrapper: ({ children, skipInitialFetch }: AuthWrapperProps) => React__default.JSX.Element;
|
|
48
|
+
declare const AuthWrapper: ({ children, skipInitialFetch, }: AuthWrapperProps) => React__default.JSX.Element;
|
|
49
49
|
/**
|
|
50
50
|
* Fetches the access token on mount by calling the auth endpoint. Stores the result in TokenContext.
|
|
51
51
|
* Used internally by auth setup; prefer `AuthWrapper` for typical usage.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React__default, { Dispatch, SetStateAction, PropsWithChildren } from 'react';
|
|
2
|
-
export { getAccessToken, refreshAccessToken, setAccessToken } from '
|
|
2
|
+
export { getAccessToken, refreshAccessToken, setAccessToken } from 'naystack/auth/token-store';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* React context holding the current access token and setter; used by useToken/useSetToken and auth hooks.
|
|
@@ -45,7 +45,7 @@ type AuthWrapperProps = PropsWithChildren<{
|
|
|
45
45
|
*
|
|
46
46
|
* @category Auth
|
|
47
47
|
*/
|
|
48
|
-
declare const AuthWrapper: ({ children, skipInitialFetch }: AuthWrapperProps) => React__default.JSX.Element;
|
|
48
|
+
declare const AuthWrapper: ({ children, skipInitialFetch, }: AuthWrapperProps) => React__default.JSX.Element;
|
|
49
49
|
/**
|
|
50
50
|
* Fetches the access token on mount by calling the auth endpoint. Stores the result in TokenContext.
|
|
51
51
|
* Used internally by auth setup; prefer `AuthWrapper` for typical usage.
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/auth/email/client.tsx
|
|
4
|
+
import {
|
|
5
|
+
getAccessToken,
|
|
6
|
+
refreshAccessToken,
|
|
7
|
+
setAccessToken,
|
|
8
|
+
subscribeToAccessToken
|
|
9
|
+
} from "naystack/auth/token-store";
|
|
4
10
|
import React, {
|
|
5
11
|
createContext,
|
|
6
12
|
useCallback,
|
|
@@ -59,42 +65,12 @@ function getEnv(key, skipCheck) {
|
|
|
59
65
|
return value;
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
// src/auth/token-store.ts
|
|
63
|
-
var currentToken;
|
|
64
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
65
|
-
var inFlightRefresh = null;
|
|
66
|
-
function getAccessToken() {
|
|
67
|
-
return currentToken;
|
|
68
|
-
}
|
|
69
|
-
function setAccessToken(token) {
|
|
70
|
-
if (token === currentToken) return;
|
|
71
|
-
currentToken = token;
|
|
72
|
-
listeners.forEach((listener) => listener(token));
|
|
73
|
-
}
|
|
74
|
-
function subscribeToAccessToken(listener) {
|
|
75
|
-
listeners.add(listener);
|
|
76
|
-
return () => {
|
|
77
|
-
listeners.delete(listener);
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function refreshAccessToken() {
|
|
81
|
-
if (inFlightRefresh) return inFlightRefresh;
|
|
82
|
-
inFlightRefresh = (async () => {
|
|
83
|
-
const res = await fetch(
|
|
84
|
-
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
85
|
-
{ credentials: "include" }
|
|
86
|
-
);
|
|
87
|
-
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
88
|
-
const token = await res.text() || null;
|
|
89
|
-
setAccessToken(token);
|
|
90
|
-
return token;
|
|
91
|
-
})().finally(() => {
|
|
92
|
-
inFlightRefresh = null;
|
|
93
|
-
});
|
|
94
|
-
return inFlightRefresh;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
68
|
// src/auth/email/client.tsx
|
|
69
|
+
import {
|
|
70
|
+
getAccessToken as getAccessToken2,
|
|
71
|
+
refreshAccessToken as refreshAccessToken2,
|
|
72
|
+
setAccessToken as setAccessToken2
|
|
73
|
+
} from "naystack/auth/token-store";
|
|
98
74
|
var TokenContext = createContext({
|
|
99
75
|
token: void 0,
|
|
100
76
|
setToken: () => null
|
|
@@ -203,9 +179,9 @@ export {
|
|
|
203
179
|
AuthApply,
|
|
204
180
|
AuthWrapper,
|
|
205
181
|
TokenContext,
|
|
206
|
-
getAccessToken,
|
|
207
|
-
refreshAccessToken,
|
|
208
|
-
setAccessToken,
|
|
182
|
+
getAccessToken2 as getAccessToken,
|
|
183
|
+
refreshAccessToken2 as refreshAccessToken,
|
|
184
|
+
setAccessToken2 as setAccessToken,
|
|
209
185
|
useAuthFetch,
|
|
210
186
|
useLogin,
|
|
211
187
|
useLogout,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
import { AuthWrapperProps } from './client.mjs';
|
|
3
|
-
import '
|
|
3
|
+
import 'naystack/auth/token-store';
|
|
4
4
|
|
|
5
5
|
declare function AuthFetch(): React__default.JSX.Element;
|
|
6
6
|
declare function AuthWrapper({ children, skipInitialFetch }: AuthWrapperProps): React__default.JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
2
|
import { AuthWrapperProps } from './client.js';
|
|
3
|
-
import '
|
|
3
|
+
import 'naystack/auth/token-store';
|
|
4
4
|
|
|
5
5
|
declare function AuthFetch(): React__default.JSX.Element;
|
|
6
6
|
declare function AuthWrapper({ children, skipInitialFetch }: AuthWrapperProps): React__default.JSX.Element;
|
package/dist/auth/index.d.mts
CHANGED
package/dist/auth/index.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ function ClearStoreOnLogout() {
|
|
|
64
64
|
var import_client3 = require("@apollo/client");
|
|
65
65
|
var import_context = require("@apollo/client/link/context");
|
|
66
66
|
var import_error = require("@apollo/client/link/error");
|
|
67
|
+
var import_token_store = require("naystack/auth/token-store");
|
|
67
68
|
|
|
68
69
|
// src/env.ts
|
|
69
70
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
@@ -115,42 +116,13 @@ function getEnv(key, skipCheck) {
|
|
|
115
116
|
return value;
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
// src/auth/token-store.ts
|
|
119
|
-
var currentToken;
|
|
120
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
121
|
-
var inFlightRefresh = null;
|
|
122
|
-
function getAccessToken() {
|
|
123
|
-
return currentToken;
|
|
124
|
-
}
|
|
125
|
-
function setAccessToken(token) {
|
|
126
|
-
if (token === currentToken) return;
|
|
127
|
-
currentToken = token;
|
|
128
|
-
listeners.forEach((listener) => listener(token));
|
|
129
|
-
}
|
|
130
|
-
function refreshAccessToken() {
|
|
131
|
-
if (inFlightRefresh) return inFlightRefresh;
|
|
132
|
-
inFlightRefresh = (async () => {
|
|
133
|
-
const res = await fetch(
|
|
134
|
-
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
135
|
-
{ credentials: "include" }
|
|
136
|
-
);
|
|
137
|
-
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
138
|
-
const token = await res.text() || null;
|
|
139
|
-
setAccessToken(token);
|
|
140
|
-
return token;
|
|
141
|
-
})().finally(() => {
|
|
142
|
-
inFlightRefresh = null;
|
|
143
|
-
});
|
|
144
|
-
return inFlightRefresh;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
119
|
// src/graphql/links.ts
|
|
148
120
|
var RETRY_CONTEXT_KEY = "__naystackRetried";
|
|
149
121
|
function isExpiredTokenError(error) {
|
|
150
122
|
return error.extensions?.code === "UNAUTHENTICATED";
|
|
151
123
|
}
|
|
152
124
|
var authLink = (0, import_context.setContext)((_, previousContext) => {
|
|
153
|
-
const token = getAccessToken();
|
|
125
|
+
const token = (0, import_token_store.getAccessToken)();
|
|
154
126
|
if (!token || previousContext.credentials === "include")
|
|
155
127
|
return previousContext;
|
|
156
128
|
return {
|
|
@@ -168,7 +140,7 @@ var refreshLink = (0, import_error.onError)(({ graphQLErrors, operation, forward
|
|
|
168
140
|
return (0, import_client3.fromPromise)(
|
|
169
141
|
// A failed refresh still replays once: the retry reproduces the original
|
|
170
142
|
// error for the caller instead of surfacing the refresh's error in its place.
|
|
171
|
-
refreshAccessToken().catch(() => null)
|
|
143
|
+
(0, import_token_store.refreshAccessToken)().catch(() => null)
|
|
172
144
|
).flatMap(() => {
|
|
173
145
|
operation.setContext((previousContext) => ({
|
|
174
146
|
...previousContext,
|
|
@@ -212,7 +184,7 @@ var tokenContext = (token) => {
|
|
|
212
184
|
};
|
|
213
185
|
};
|
|
214
186
|
function useAuthQuery(query, variables, options) {
|
|
215
|
-
const [
|
|
187
|
+
const [fetch, result] = (0, import_client4.useLazyQuery)(query, {
|
|
216
188
|
fetchPolicy: "no-cache",
|
|
217
189
|
...options
|
|
218
190
|
});
|
|
@@ -221,7 +193,7 @@ function useAuthQuery(query, variables, options) {
|
|
|
221
193
|
const serialized = JSON.stringify(variables);
|
|
222
194
|
if (variables && prevVarsRef.current !== serialized) {
|
|
223
195
|
prevVarsRef.current = serialized;
|
|
224
|
-
void
|
|
196
|
+
void fetch({
|
|
225
197
|
// @ts-expect-error -- to allow dynamic props
|
|
226
198
|
variables: { input: variables },
|
|
227
199
|
context: {
|
|
@@ -229,16 +201,16 @@ function useAuthQuery(query, variables, options) {
|
|
|
229
201
|
}
|
|
230
202
|
});
|
|
231
203
|
}
|
|
232
|
-
}, [
|
|
204
|
+
}, [fetch, variables]);
|
|
233
205
|
const reFetch = (0, import_react2.useCallback)(
|
|
234
|
-
(input) =>
|
|
206
|
+
(input) => fetch({
|
|
235
207
|
// @ts-expect-error -- to allow dynamic props
|
|
236
208
|
variables: { input },
|
|
237
209
|
context: {
|
|
238
210
|
credentials: `include`
|
|
239
211
|
}
|
|
240
212
|
}),
|
|
241
|
-
[
|
|
213
|
+
[fetch]
|
|
242
214
|
);
|
|
243
215
|
return [reFetch, result];
|
|
244
216
|
}
|
|
@@ -38,6 +38,7 @@ function ClearStoreOnLogout() {
|
|
|
38
38
|
import { ApolloLink, fromPromise, HttpLink } from "@apollo/client";
|
|
39
39
|
import { setContext } from "@apollo/client/link/context";
|
|
40
40
|
import { onError } from "@apollo/client/link/error";
|
|
41
|
+
import { getAccessToken, refreshAccessToken } from "naystack/auth/token-store";
|
|
41
42
|
|
|
42
43
|
// src/env.ts
|
|
43
44
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
@@ -89,35 +90,6 @@ function getEnv(key, skipCheck) {
|
|
|
89
90
|
return value;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
// src/auth/token-store.ts
|
|
93
|
-
var currentToken;
|
|
94
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
95
|
-
var inFlightRefresh = null;
|
|
96
|
-
function getAccessToken() {
|
|
97
|
-
return currentToken;
|
|
98
|
-
}
|
|
99
|
-
function setAccessToken(token) {
|
|
100
|
-
if (token === currentToken) return;
|
|
101
|
-
currentToken = token;
|
|
102
|
-
listeners.forEach((listener) => listener(token));
|
|
103
|
-
}
|
|
104
|
-
function refreshAccessToken() {
|
|
105
|
-
if (inFlightRefresh) return inFlightRefresh;
|
|
106
|
-
inFlightRefresh = (async () => {
|
|
107
|
-
const res = await fetch(
|
|
108
|
-
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
109
|
-
{ credentials: "include" }
|
|
110
|
-
);
|
|
111
|
-
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
112
|
-
const token = await res.text() || null;
|
|
113
|
-
setAccessToken(token);
|
|
114
|
-
return token;
|
|
115
|
-
})().finally(() => {
|
|
116
|
-
inFlightRefresh = null;
|
|
117
|
-
});
|
|
118
|
-
return inFlightRefresh;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
93
|
// src/graphql/links.ts
|
|
122
94
|
var RETRY_CONTEXT_KEY = "__naystackRetried";
|
|
123
95
|
function isExpiredTokenError(error) {
|
|
@@ -186,7 +158,7 @@ var tokenContext = (token) => {
|
|
|
186
158
|
};
|
|
187
159
|
};
|
|
188
160
|
function useAuthQuery(query, variables, options) {
|
|
189
|
-
const [
|
|
161
|
+
const [fetch, result] = useLazyQuery(query, {
|
|
190
162
|
fetchPolicy: "no-cache",
|
|
191
163
|
...options
|
|
192
164
|
});
|
|
@@ -195,7 +167,7 @@ function useAuthQuery(query, variables, options) {
|
|
|
195
167
|
const serialized = JSON.stringify(variables);
|
|
196
168
|
if (variables && prevVarsRef.current !== serialized) {
|
|
197
169
|
prevVarsRef.current = serialized;
|
|
198
|
-
void
|
|
170
|
+
void fetch({
|
|
199
171
|
// @ts-expect-error -- to allow dynamic props
|
|
200
172
|
variables: { input: variables },
|
|
201
173
|
context: {
|
|
@@ -203,16 +175,16 @@ function useAuthQuery(query, variables, options) {
|
|
|
203
175
|
}
|
|
204
176
|
});
|
|
205
177
|
}
|
|
206
|
-
}, [
|
|
178
|
+
}, [fetch, variables]);
|
|
207
179
|
const reFetch = useCallback(
|
|
208
|
-
(input) =>
|
|
180
|
+
(input) => fetch({
|
|
209
181
|
// @ts-expect-error -- to allow dynamic props
|
|
210
182
|
variables: { input },
|
|
211
183
|
context: {
|
|
212
184
|
credentials: `include`
|
|
213
185
|
}
|
|
214
186
|
}),
|
|
215
|
-
[
|
|
187
|
+
[fetch]
|
|
216
188
|
);
|
|
217
189
|
return [reFetch, result];
|
|
218
190
|
}
|
|
@@ -26,6 +26,7 @@ module.exports = __toCommonJS(links_exports);
|
|
|
26
26
|
var import_client = require("@apollo/client");
|
|
27
27
|
var import_context = require("@apollo/client/link/context");
|
|
28
28
|
var import_error = require("@apollo/client/link/error");
|
|
29
|
+
var import_token_store = require("naystack/auth/token-store");
|
|
29
30
|
|
|
30
31
|
// src/env.ts
|
|
31
32
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
@@ -77,42 +78,13 @@ function getEnv(key, skipCheck) {
|
|
|
77
78
|
return value;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
// src/auth/token-store.ts
|
|
81
|
-
var currentToken;
|
|
82
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
83
|
-
var inFlightRefresh = null;
|
|
84
|
-
function getAccessToken() {
|
|
85
|
-
return currentToken;
|
|
86
|
-
}
|
|
87
|
-
function setAccessToken(token) {
|
|
88
|
-
if (token === currentToken) return;
|
|
89
|
-
currentToken = token;
|
|
90
|
-
listeners.forEach((listener) => listener(token));
|
|
91
|
-
}
|
|
92
|
-
function refreshAccessToken() {
|
|
93
|
-
if (inFlightRefresh) return inFlightRefresh;
|
|
94
|
-
inFlightRefresh = (async () => {
|
|
95
|
-
const res = await fetch(
|
|
96
|
-
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
97
|
-
{ credentials: "include" }
|
|
98
|
-
);
|
|
99
|
-
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
100
|
-
const token = await res.text() || null;
|
|
101
|
-
setAccessToken(token);
|
|
102
|
-
return token;
|
|
103
|
-
})().finally(() => {
|
|
104
|
-
inFlightRefresh = null;
|
|
105
|
-
});
|
|
106
|
-
return inFlightRefresh;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
81
|
// src/graphql/links.ts
|
|
110
82
|
var RETRY_CONTEXT_KEY = "__naystackRetried";
|
|
111
83
|
function isExpiredTokenError(error) {
|
|
112
84
|
return error.extensions?.code === "UNAUTHENTICATED";
|
|
113
85
|
}
|
|
114
86
|
var authLink = (0, import_context.setContext)((_, previousContext) => {
|
|
115
|
-
const token = getAccessToken();
|
|
87
|
+
const token = (0, import_token_store.getAccessToken)();
|
|
116
88
|
if (!token || previousContext.credentials === "include")
|
|
117
89
|
return previousContext;
|
|
118
90
|
return {
|
|
@@ -130,7 +102,7 @@ var refreshLink = (0, import_error.onError)(({ graphQLErrors, operation, forward
|
|
|
130
102
|
return (0, import_client.fromPromise)(
|
|
131
103
|
// A failed refresh still replays once: the retry reproduces the original
|
|
132
104
|
// error for the caller instead of surfacing the refresh's error in its place.
|
|
133
|
-
refreshAccessToken().catch(() => null)
|
|
105
|
+
(0, import_token_store.refreshAccessToken)().catch(() => null)
|
|
134
106
|
).flatMap(() => {
|
|
135
107
|
operation.setContext((previousContext) => ({
|
|
136
108
|
...previousContext,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { ApolloLink, fromPromise, HttpLink } from "@apollo/client";
|
|
3
3
|
import { setContext } from "@apollo/client/link/context";
|
|
4
4
|
import { onError } from "@apollo/client/link/error";
|
|
5
|
+
import { getAccessToken, refreshAccessToken } from "naystack/auth/token-store";
|
|
5
6
|
|
|
6
7
|
// src/env.ts
|
|
7
8
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
@@ -53,35 +54,6 @@ function getEnv(key, skipCheck) {
|
|
|
53
54
|
return value;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
// src/auth/token-store.ts
|
|
57
|
-
var currentToken;
|
|
58
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
59
|
-
var inFlightRefresh = null;
|
|
60
|
-
function getAccessToken() {
|
|
61
|
-
return currentToken;
|
|
62
|
-
}
|
|
63
|
-
function setAccessToken(token) {
|
|
64
|
-
if (token === currentToken) return;
|
|
65
|
-
currentToken = token;
|
|
66
|
-
listeners.forEach((listener) => listener(token));
|
|
67
|
-
}
|
|
68
|
-
function refreshAccessToken() {
|
|
69
|
-
if (inFlightRefresh) return inFlightRefresh;
|
|
70
|
-
inFlightRefresh = (async () => {
|
|
71
|
-
const res = await fetch(
|
|
72
|
-
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
73
|
-
{ credentials: "include" }
|
|
74
|
-
);
|
|
75
|
-
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
76
|
-
const token = await res.text() || null;
|
|
77
|
-
setAccessToken(token);
|
|
78
|
-
return token;
|
|
79
|
-
})().finally(() => {
|
|
80
|
-
inFlightRefresh = null;
|
|
81
|
-
});
|
|
82
|
-
return inFlightRefresh;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
57
|
// src/graphql/links.ts
|
|
86
58
|
var RETRY_CONTEXT_KEY = "__naystackRetried";
|
|
87
59
|
function isExpiredTokenError(error) {
|
package/dist/graphql/next.cjs.js
CHANGED
|
@@ -60,6 +60,7 @@ function ClearStoreOnLogout() {
|
|
|
60
60
|
var import_client3 = require("@apollo/client");
|
|
61
61
|
var import_context = require("@apollo/client/link/context");
|
|
62
62
|
var import_error = require("@apollo/client/link/error");
|
|
63
|
+
var import_token_store = require("naystack/auth/token-store");
|
|
63
64
|
|
|
64
65
|
// src/env.ts
|
|
65
66
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
@@ -111,42 +112,13 @@ function getEnv(key, skipCheck) {
|
|
|
111
112
|
return value;
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
// src/auth/token-store.ts
|
|
115
|
-
var currentToken;
|
|
116
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
117
|
-
var inFlightRefresh = null;
|
|
118
|
-
function getAccessToken() {
|
|
119
|
-
return currentToken;
|
|
120
|
-
}
|
|
121
|
-
function setAccessToken(token) {
|
|
122
|
-
if (token === currentToken) return;
|
|
123
|
-
currentToken = token;
|
|
124
|
-
listeners.forEach((listener) => listener(token));
|
|
125
|
-
}
|
|
126
|
-
function refreshAccessToken() {
|
|
127
|
-
if (inFlightRefresh) return inFlightRefresh;
|
|
128
|
-
inFlightRefresh = (async () => {
|
|
129
|
-
const res = await fetch(
|
|
130
|
-
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
131
|
-
{ credentials: "include" }
|
|
132
|
-
);
|
|
133
|
-
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
134
|
-
const token = await res.text() || null;
|
|
135
|
-
setAccessToken(token);
|
|
136
|
-
return token;
|
|
137
|
-
})().finally(() => {
|
|
138
|
-
inFlightRefresh = null;
|
|
139
|
-
});
|
|
140
|
-
return inFlightRefresh;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
115
|
// src/graphql/links.ts
|
|
144
116
|
var RETRY_CONTEXT_KEY = "__naystackRetried";
|
|
145
117
|
function isExpiredTokenError(error) {
|
|
146
118
|
return error.extensions?.code === "UNAUTHENTICATED";
|
|
147
119
|
}
|
|
148
120
|
var authLink = (0, import_context.setContext)((_, previousContext) => {
|
|
149
|
-
const token = getAccessToken();
|
|
121
|
+
const token = (0, import_token_store.getAccessToken)();
|
|
150
122
|
if (!token || previousContext.credentials === "include")
|
|
151
123
|
return previousContext;
|
|
152
124
|
return {
|
|
@@ -164,7 +136,7 @@ var refreshLink = (0, import_error.onError)(({ graphQLErrors, operation, forward
|
|
|
164
136
|
return (0, import_client3.fromPromise)(
|
|
165
137
|
// A failed refresh still replays once: the retry reproduces the original
|
|
166
138
|
// error for the caller instead of surfacing the refresh's error in its place.
|
|
167
|
-
refreshAccessToken().catch(() => null)
|
|
139
|
+
(0, import_token_store.refreshAccessToken)().catch(() => null)
|
|
168
140
|
).flatMap(() => {
|
|
169
141
|
operation.setContext((previousContext) => ({
|
|
170
142
|
...previousContext,
|
package/dist/graphql/next.esm.js
CHANGED
|
@@ -31,6 +31,7 @@ function ClearStoreOnLogout() {
|
|
|
31
31
|
import { ApolloLink, fromPromise, HttpLink } from "@apollo/client";
|
|
32
32
|
import { setContext } from "@apollo/client/link/context";
|
|
33
33
|
import { onError } from "@apollo/client/link/error";
|
|
34
|
+
import { getAccessToken, refreshAccessToken } from "naystack/auth/token-store";
|
|
34
35
|
|
|
35
36
|
// src/env.ts
|
|
36
37
|
var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
|
|
@@ -82,35 +83,6 @@ function getEnv(key, skipCheck) {
|
|
|
82
83
|
return value;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
// src/auth/token-store.ts
|
|
86
|
-
var currentToken;
|
|
87
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
88
|
-
var inFlightRefresh = null;
|
|
89
|
-
function getAccessToken() {
|
|
90
|
-
return currentToken;
|
|
91
|
-
}
|
|
92
|
-
function setAccessToken(token) {
|
|
93
|
-
if (token === currentToken) return;
|
|
94
|
-
currentToken = token;
|
|
95
|
-
listeners.forEach((listener) => listener(token));
|
|
96
|
-
}
|
|
97
|
-
function refreshAccessToken() {
|
|
98
|
-
if (inFlightRefresh) return inFlightRefresh;
|
|
99
|
-
inFlightRefresh = (async () => {
|
|
100
|
-
const res = await fetch(
|
|
101
|
-
getEnv("NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT" /* NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT */),
|
|
102
|
-
{ credentials: "include" }
|
|
103
|
-
);
|
|
104
|
-
if (!res.ok) throw new Error(`Token refresh failed: ${res.status}`);
|
|
105
|
-
const token = await res.text() || null;
|
|
106
|
-
setAccessToken(token);
|
|
107
|
-
return token;
|
|
108
|
-
})().finally(() => {
|
|
109
|
-
inFlightRefresh = null;
|
|
110
|
-
});
|
|
111
|
-
return inFlightRefresh;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
86
|
// src/graphql/links.ts
|
|
115
87
|
var RETRY_CONTEXT_KEY = "__naystackRetried";
|
|
116
88
|
function isExpiredTokenError(error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "naystack",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.5",
|
|
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",
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"import": "./dist/auth/client.esm.js",
|
|
24
24
|
"require": "./dist/auth/client.cjs.js"
|
|
25
25
|
},
|
|
26
|
+
"./auth/token-store": {
|
|
27
|
+
"types": "./dist/auth/token-store.d.ts",
|
|
28
|
+
"import": "./dist/auth/token-store.esm.js",
|
|
29
|
+
"require": "./dist/auth/token-store.cjs.js"
|
|
30
|
+
},
|
|
26
31
|
"./graphql": {
|
|
27
32
|
"types": "./dist/graphql/index.d.ts",
|
|
28
33
|
"import": "./dist/graphql/index.esm.js",
|