naystack 1.7.5 → 1.7.6

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.
@@ -112,14 +112,17 @@ var AuthWrapper = ({
112
112
  skipInitialFetch
113
113
  }) => {
114
114
  const [token, setToken] = (0, import_react.useState)();
115
- useAuthFetch({ getRefreshToken, skip: skipInitialFetch });
116
115
  (0, import_react.useEffect)(() => {
117
116
  if (onTokenUpdate && token !== void 0) {
118
117
  onTokenUpdate(token);
119
118
  }
120
119
  }, [token]);
121
- return /* @__PURE__ */ import_react.default.createElement(TokenContext.Provider, { value: { token, setToken } }, children);
120
+ return /* @__PURE__ */ import_react.default.createElement(TokenContext.Provider, { value: { token, setToken } }, !skipInitialFetch && /* @__PURE__ */ import_react.default.createElement(AuthChildComponent, { getRefreshToken }), children);
122
121
  };
122
+ function AuthChildComponent({ getRefreshToken }) {
123
+ useAuthFetch({ getRefreshToken });
124
+ return null;
125
+ }
123
126
  function useAuthFetch({ getRefreshToken, skip }) {
124
127
  const setToken = useSetToken();
125
128
  const fetchToken = async () => {
@@ -74,14 +74,17 @@ var AuthWrapper = ({
74
74
  skipInitialFetch
75
75
  }) => {
76
76
  const [token, setToken] = useState();
77
- useAuthFetch({ getRefreshToken, skip: skipInitialFetch });
78
77
  useEffect(() => {
79
78
  if (onTokenUpdate && token !== void 0) {
80
79
  onTokenUpdate(token);
81
80
  }
82
81
  }, [token]);
83
- return /* @__PURE__ */ React.createElement(TokenContext.Provider, { value: { token, setToken } }, children);
82
+ return /* @__PURE__ */ React.createElement(TokenContext.Provider, { value: { token, setToken } }, !skipInitialFetch && /* @__PURE__ */ React.createElement(AuthChildComponent, { getRefreshToken }), children);
84
83
  };
84
+ function AuthChildComponent({ getRefreshToken }) {
85
+ useAuthFetch({ getRefreshToken });
86
+ return null;
87
+ }
85
88
  function useAuthFetch({ getRefreshToken, skip }) {
86
89
  const setToken = useSetToken();
87
90
  const fetchToken = async () => {
@@ -109,14 +109,17 @@ var AuthWrapper = ({
109
109
  skipInitialFetch
110
110
  }) => {
111
111
  const [token, setToken] = (0, import_react.useState)();
112
- useAuthFetch({ getRefreshToken, skip: skipInitialFetch });
113
112
  (0, import_react.useEffect)(() => {
114
113
  if (onTokenUpdate && token !== void 0) {
115
114
  onTokenUpdate(token);
116
115
  }
117
116
  }, [token]);
118
- return /* @__PURE__ */ import_react.default.createElement(TokenContext.Provider, { value: { token, setToken } }, children);
117
+ return /* @__PURE__ */ import_react.default.createElement(TokenContext.Provider, { value: { token, setToken } }, !skipInitialFetch && /* @__PURE__ */ import_react.default.createElement(AuthChildComponent, { getRefreshToken }), children);
119
118
  };
119
+ function AuthChildComponent({ getRefreshToken }) {
120
+ useAuthFetch({ getRefreshToken });
121
+ return null;
122
+ }
120
123
  function useAuthFetch({ getRefreshToken, skip }) {
121
124
  const setToken = useSetToken();
122
125
  const fetchToken = async () => {
@@ -74,14 +74,17 @@ var AuthWrapper = ({
74
74
  skipInitialFetch
75
75
  }) => {
76
76
  const [token, setToken] = useState();
77
- useAuthFetch({ getRefreshToken, skip: skipInitialFetch });
78
77
  useEffect(() => {
79
78
  if (onTokenUpdate && token !== void 0) {
80
79
  onTokenUpdate(token);
81
80
  }
82
81
  }, [token]);
83
- return /* @__PURE__ */ React.createElement(TokenContext.Provider, { value: { token, setToken } }, children);
82
+ return /* @__PURE__ */ React.createElement(TokenContext.Provider, { value: { token, setToken } }, !skipInitialFetch && /* @__PURE__ */ React.createElement(AuthChildComponent, { getRefreshToken }), children);
84
83
  };
84
+ function AuthChildComponent({ getRefreshToken }) {
85
+ useAuthFetch({ getRefreshToken });
86
+ return null;
87
+ }
85
88
  function useAuthFetch({ getRefreshToken, skip }) {
86
89
  const setToken = useSetToken();
87
90
  const fetchToken = async () => {
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var auth_exports = {};
32
32
  __export(auth_exports, {
33
33
  AuthFetch: () => AuthFetch,
34
+ AuthWrapper: () => AuthWrapper,
34
35
  checkAuthStatus: () => checkAuthStatus,
35
36
  getContext: () => getContext,
36
37
  getRefreshToken: () => getRefreshToken,
@@ -416,6 +417,9 @@ function AuthFetch() {
416
417
  }
417
418
  );
418
419
  }
420
+ function AuthWrapper({ children, getRefreshToken: getRefreshToken2, onTokenUpdate, skipInitialFetch }) {
421
+ return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, /* @__PURE__ */ import_react3.default.createElement(import_client2.AuthWrapper, { skipInitialFetch: true, getRefreshToken: getRefreshToken2, onTokenUpdate }, !skipInitialFetch && /* @__PURE__ */ import_react3.default.createElement(AuthFetch, null), children));
422
+ }
419
423
 
420
424
  // src/auth/email/index.ts
421
425
  function setupEmailAuth(options) {
@@ -642,6 +646,7 @@ async function getRefreshToken() {
642
646
  // Annotate the CommonJS export names for ESM import in node:
643
647
  0 && (module.exports = {
644
648
  AuthFetch,
649
+ AuthWrapper,
645
650
  checkAuthStatus,
646
651
  getContext,
647
652
  getRefreshToken,
@@ -1,8 +1,8 @@
1
1
  export { setupEmailAuth } from './email/index.mjs';
2
- export { setupGoogleAuth } from './google/index.mjs';
3
- export { setupInstagramAuth } from './instagram/index.mjs';
2
+ export { SetupGoogleAuthOptions, setupGoogleAuth } from './google/index.mjs';
3
+ export { SetupInstagramAuthOptions, setupInstagramAuth } from './instagram/index.mjs';
4
4
  export { getRefreshToken } from './utils/token.mjs';
5
- export { AuthFetch } from './email/next.mjs';
5
+ export { AuthFetch, AuthWrapper } from './email/next.mjs';
6
6
  export { checkAuthStatus } from './email/token.mjs';
7
7
  export { getContext } from './email/utils.mjs';
8
8
  export { getRefreshedInstagramAccessToken } from './instagram/utils.mjs';
@@ -1,8 +1,8 @@
1
1
  export { setupEmailAuth } from './email/index.js';
2
- export { setupGoogleAuth } from './google/index.js';
3
- export { setupInstagramAuth } from './instagram/index.js';
2
+ export { SetupGoogleAuthOptions, setupGoogleAuth } from './google/index.js';
3
+ export { SetupInstagramAuthOptions, setupInstagramAuth } from './instagram/index.js';
4
4
  export { getRefreshToken } from './utils/token.js';
5
- export { AuthFetch } from './email/next.js';
5
+ export { AuthFetch, AuthWrapper } from './email/next.js';
6
6
  export { checkAuthStatus } from './email/token.js';
7
7
  export { getContext } from './email/utils.js';
8
8
  export { getRefreshedInstagramAccessToken } from './instagram/utils.js';
@@ -377,6 +377,9 @@ function AuthFetch() {
377
377
  }
378
378
  );
379
379
  }
380
+ function AuthWrapper({ children, getRefreshToken: getRefreshToken2, onTokenUpdate, skipInitialFetch }) {
381
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(AuthWrapperClient, { skipInitialFetch: true, getRefreshToken: getRefreshToken2, onTokenUpdate }, !skipInitialFetch && /* @__PURE__ */ React2.createElement(AuthFetch, null), children));
382
+ }
380
383
 
381
384
  // src/auth/email/index.ts
382
385
  function setupEmailAuth(options) {
@@ -602,6 +605,7 @@ async function getRefreshToken() {
602
605
  }
603
606
  export {
604
607
  AuthFetch,
608
+ AuthWrapper,
605
609
  checkAuthStatus,
606
610
  getContext,
607
611
  getRefreshToken,
@@ -31,15 +31,16 @@ 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
- ApolloWrapper: () => ApolloWrapper,
34
+ ApolloWrapperClient: () => ApolloWrapperClient,
35
+ ApolloWrapperNext: () => ApolloWrapper,
35
36
  tokenContext: () => tokenContext,
36
37
  useAuthMutation: () => useAuthMutation,
37
38
  useAuthQuery: () => useAuthQuery
38
39
  });
39
40
  module.exports = __toCommonJS(client_exports);
40
- var import_client = require("@apollo/client");
41
- var import_client2 = require("naystack/auth/client");
42
- var import_react = __toESM(require("react"));
41
+ var import_client2 = require("@apollo/client");
42
+ var import_client3 = require("naystack/auth/client");
43
+ var import_react2 = __toESM(require("react"));
43
44
 
44
45
  // src/env.ts
45
46
  var EXTRA_ENV = globalThis.__NAYSTACK_ENV__ || (globalThis.__NAYSTACK_ENV__ = {});
@@ -91,10 +92,13 @@ function getEnv(key, skipCheck) {
91
92
  return value;
92
93
  }
93
94
 
94
- // src/graphql/client.tsx
95
+ // src/graphql/next.tsx
96
+ var import_client = require("@apollo/client");
97
+ var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
98
+ var import_react = __toESM(require("react"));
95
99
  function makeClient(cacheConfig) {
96
- return new import_client.ApolloClient({
97
- cache: new import_client.InMemoryCache(cacheConfig),
100
+ return new import_client_integration_nextjs.ApolloClient({
101
+ cache: new import_client_integration_nextjs.InMemoryCache(cacheConfig),
98
102
  link: new import_client.HttpLink({
99
103
  uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
100
104
  })
@@ -104,7 +108,23 @@ var ApolloWrapper = ({
104
108
  children,
105
109
  cacheConfig
106
110
  }) => {
107
- return /* @__PURE__ */ import_react.default.createElement(import_client.ApolloProvider, { client: makeClient(cacheConfig) }, children);
111
+ return /* @__PURE__ */ import_react.default.createElement(import_client_integration_nextjs.ApolloNextAppProvider, { makeClient: () => makeClient(cacheConfig) }, children);
112
+ };
113
+
114
+ // src/graphql/client.tsx
115
+ function makeClient2(cacheConfig) {
116
+ return new import_client2.ApolloClient({
117
+ cache: new import_client2.InMemoryCache(cacheConfig),
118
+ link: new import_client2.HttpLink({
119
+ uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
120
+ })
121
+ });
122
+ }
123
+ var ApolloWrapperClient = ({
124
+ children,
125
+ cacheConfig
126
+ }) => {
127
+ return /* @__PURE__ */ import_react2.default.createElement(import_client2.ApolloProvider, { client: makeClient2(cacheConfig) }, children);
108
128
  };
109
129
  var tokenContext = (token) => {
110
130
  if (!token) return void 0;
@@ -116,12 +136,12 @@ var tokenContext = (token) => {
116
136
  };
117
137
  };
118
138
  function useAuthQuery(query, variables) {
119
- const token = (0, import_client2.useToken)();
120
- const [fetch, result] = (0, import_client.useLazyQuery)(query, {
139
+ const token = (0, import_client3.useToken)();
140
+ const [fetch, result] = (0, import_client2.useLazyQuery)(query, {
121
141
  fetchPolicy: "no-cache"
122
142
  });
123
- const prevVarsRef = (0, import_react.useRef)(null);
124
- (0, import_react.useEffect)(() => {
143
+ const prevVarsRef = (0, import_react2.useRef)(null);
144
+ (0, import_react2.useEffect)(() => {
125
145
  const serialized = JSON.stringify(variables);
126
146
  if (token && variables && prevVarsRef.current !== serialized) {
127
147
  prevVarsRef.current = serialized;
@@ -132,7 +152,7 @@ function useAuthQuery(query, variables) {
132
152
  });
133
153
  }
134
154
  }, [fetch, token, variables]);
135
- const reFetch = (0, import_react.useCallback)(
155
+ const reFetch = (0, import_react2.useCallback)(
136
156
  (input) => fetch({
137
157
  // @ts-expect-error -- to allow dynamic props
138
158
  variables: { input },
@@ -143,9 +163,9 @@ function useAuthQuery(query, variables) {
143
163
  return [reFetch, { ...result, hasAuth: !!token }];
144
164
  }
145
165
  function useAuthMutation(mutation, options) {
146
- const token = (0, import_client2.useToken)();
147
- const [mutate, result] = (0, import_client.useMutation)(mutation, options);
148
- const method = (0, import_react.useCallback)(
166
+ const token = (0, import_client3.useToken)();
167
+ const [mutate, result] = (0, import_client2.useMutation)(mutation, options);
168
+ const method = (0, import_react2.useCallback)(
149
169
  (input) => mutate({
150
170
  // @ts-expect-error -- to allow dynamic props
151
171
  variables: { input },
@@ -157,7 +177,8 @@ function useAuthMutation(mutation, options) {
157
177
  }
158
178
  // Annotate the CommonJS export names for ESM import in node:
159
179
  0 && (module.exports = {
160
- ApolloWrapper,
180
+ ApolloWrapperClient,
181
+ ApolloWrapperNext,
161
182
  tokenContext,
162
183
  useAuthMutation,
163
184
  useAuthQuery
@@ -3,8 +3,9 @@ import * as _apollo_client from '@apollo/client';
3
3
  import { InMemoryCacheConfig, OperationVariables, ApolloClient, MutationHookOptions } from '@apollo/client';
4
4
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
5
  import React__default, { PropsWithChildren } from 'react';
6
+ export { ApolloWrapper as ApolloWrapperNext } from './next.mjs';
6
7
 
7
- declare const ApolloWrapper: ({ children, cacheConfig, }: PropsWithChildren<{
8
+ declare const ApolloWrapperClient: ({ children, cacheConfig, }: PropsWithChildren<{
8
9
  cacheConfig?: InMemoryCacheConfig;
9
10
  }>) => React__default.JSX.Element;
10
11
  /**
@@ -129,4 +130,4 @@ declare function useAuthMutation<T, V extends OperationVariables>(mutation: Type
129
130
  readonly reset: () => void;
130
131
  }];
131
132
 
132
- export { ApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
133
+ export { ApolloWrapperClient, tokenContext, useAuthMutation, useAuthQuery };
@@ -3,8 +3,9 @@ import * as _apollo_client from '@apollo/client';
3
3
  import { InMemoryCacheConfig, OperationVariables, ApolloClient, MutationHookOptions } from '@apollo/client';
4
4
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
5
  import React__default, { PropsWithChildren } from 'react';
6
+ export { ApolloWrapper as ApolloWrapperNext } from './next.js';
6
7
 
7
- declare const ApolloWrapper: ({ children, cacheConfig, }: PropsWithChildren<{
8
+ declare const ApolloWrapperClient: ({ children, cacheConfig, }: PropsWithChildren<{
8
9
  cacheConfig?: InMemoryCacheConfig;
9
10
  }>) => React__default.JSX.Element;
10
11
  /**
@@ -129,4 +130,4 @@ declare function useAuthMutation<T, V extends OperationVariables>(mutation: Type
129
130
  readonly reset: () => void;
130
131
  }];
131
132
 
132
- export { ApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
133
+ export { ApolloWrapperClient, tokenContext, useAuthMutation, useAuthQuery };
@@ -2,15 +2,15 @@
2
2
 
3
3
  // src/graphql/client.tsx
4
4
  import {
5
- ApolloClient,
5
+ ApolloClient as ApolloClient2,
6
6
  ApolloProvider,
7
- HttpLink,
8
- InMemoryCache,
7
+ HttpLink as HttpLink2,
8
+ InMemoryCache as InMemoryCache2,
9
9
  useLazyQuery,
10
10
  useMutation
11
11
  } from "@apollo/client";
12
12
  import { useToken } from "naystack/auth/client";
13
- import React, {
13
+ import React2, {
14
14
  useCallback,
15
15
  useEffect,
16
16
  useRef
@@ -66,7 +66,14 @@ function getEnv(key, skipCheck) {
66
66
  return value;
67
67
  }
68
68
 
69
- // src/graphql/client.tsx
69
+ // src/graphql/next.tsx
70
+ import { HttpLink } from "@apollo/client";
71
+ import {
72
+ ApolloClient,
73
+ ApolloNextAppProvider,
74
+ InMemoryCache
75
+ } from "@apollo/client-integration-nextjs";
76
+ import React from "react";
70
77
  function makeClient(cacheConfig) {
71
78
  return new ApolloClient({
72
79
  cache: new InMemoryCache(cacheConfig),
@@ -79,7 +86,23 @@ var ApolloWrapper = ({
79
86
  children,
80
87
  cacheConfig
81
88
  }) => {
82
- return /* @__PURE__ */ React.createElement(ApolloProvider, { client: makeClient(cacheConfig) }, children);
89
+ return /* @__PURE__ */ React.createElement(ApolloNextAppProvider, { makeClient: () => makeClient(cacheConfig) }, children);
90
+ };
91
+
92
+ // src/graphql/client.tsx
93
+ function makeClient2(cacheConfig) {
94
+ return new ApolloClient2({
95
+ cache: new InMemoryCache2(cacheConfig),
96
+ link: new HttpLink2({
97
+ uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
98
+ })
99
+ });
100
+ }
101
+ var ApolloWrapperClient = ({
102
+ children,
103
+ cacheConfig
104
+ }) => {
105
+ return /* @__PURE__ */ React2.createElement(ApolloProvider, { client: makeClient2(cacheConfig) }, children);
83
106
  };
84
107
  var tokenContext = (token) => {
85
108
  if (!token) return void 0;
@@ -131,7 +154,8 @@ function useAuthMutation(mutation, options) {
131
154
  return [method, { ...result, hasAuth: !!token }];
132
155
  }
133
156
  export {
134
- ApolloWrapper,
157
+ ApolloWrapperClient,
158
+ ApolloWrapper as ApolloWrapperNext,
135
159
  tokenContext,
136
160
  useAuthMutation,
137
161
  useAuthQuery
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
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,11 +33,6 @@
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
- },
41
36
  "./file": {
42
37
  "types": "./dist/file/index.d.ts",
43
38
  "import": "./dist/file/index.esm.js",