naystack 1.2.12 → 1.2.14

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.
@@ -20,10 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/auth/email/client.ts
21
21
  var client_exports = {};
22
22
  __export(client_exports, {
23
- getEmailAuthUtils: () => getEmailAuthUtils,
24
- useLoginWithEmail: () => useLoginWithEmail,
25
- useLogout: () => useLogout,
26
- useSignUpWithEmail: () => useSignUpWithEmail
23
+ getEmailAuthUtils: () => getEmailAuthUtils
27
24
  });
28
25
  module.exports = __toCommonJS(client_exports);
29
26
  var import_client = require("naystack/graphql/client");
@@ -49,7 +46,6 @@ function useSignUpWithEmail(endpoint) {
49
46
  }
50
47
  function useLoginWithEmail(endpoint) {
51
48
  const setToken = (0, import_client.useSetToken)();
52
- console.warn(setToken, "2");
53
49
  return (0, import_react.useCallback)(
54
50
  async (data) => {
55
51
  const res = await fetch(endpoint, {
@@ -68,8 +64,7 @@ function useLoginWithEmail(endpoint) {
68
64
  );
69
65
  }
70
66
  function useLogout(endpoint) {
71
- const { setToken, token } = (0, import_react.useContext)(import_client.TokenContext);
72
- console.warn(token, setToken, "1");
67
+ const setToken = (0, import_client.useSetToken)();
73
68
  return (0, import_react.useCallback)(
74
69
  async (data) => {
75
70
  setToken(null);
@@ -91,8 +86,5 @@ function getEmailAuthUtils(endpoint) {
91
86
  }
92
87
  // Annotate the CommonJS export names for ESM import in node:
93
88
  0 && (module.exports = {
94
- getEmailAuthUtils,
95
- useLoginWithEmail,
96
- useLogout,
97
- useSignUpWithEmail
89
+ getEmailAuthUtils
98
90
  });
@@ -1,10 +1,7 @@
1
- declare function useSignUpWithEmail(endpoint: string): (data: object) => Promise<string | null>;
2
- declare function useLoginWithEmail(endpoint: string): (data: object) => Promise<string | null>;
3
- declare function useLogout(endpoint: string): (data?: object) => Promise<void>;
4
1
  declare function getEmailAuthUtils(endpoint: string): {
5
2
  useSignUp: () => (data: object) => Promise<string | null>;
6
3
  useLogin: () => (data: object) => Promise<string | null>;
7
4
  useLogout: () => (data?: object) => Promise<void>;
8
5
  };
9
6
 
10
- export { getEmailAuthUtils, useLoginWithEmail, useLogout, useSignUpWithEmail };
7
+ export { getEmailAuthUtils };
@@ -1,10 +1,7 @@
1
- declare function useSignUpWithEmail(endpoint: string): (data: object) => Promise<string | null>;
2
- declare function useLoginWithEmail(endpoint: string): (data: object) => Promise<string | null>;
3
- declare function useLogout(endpoint: string): (data?: object) => Promise<void>;
4
1
  declare function getEmailAuthUtils(endpoint: string): {
5
2
  useSignUp: () => (data: object) => Promise<string | null>;
6
3
  useLogin: () => (data: object) => Promise<string | null>;
7
4
  useLogout: () => (data?: object) => Promise<void>;
8
5
  };
9
6
 
10
- export { getEmailAuthUtils, useLoginWithEmail, useLogout, useSignUpWithEmail };
7
+ export { getEmailAuthUtils };
@@ -1,6 +1,6 @@
1
1
  // src/auth/email/client.ts
2
- import { TokenContext, useSetToken } from "naystack/graphql/client";
3
- import { useCallback, useContext } from "react";
2
+ import { useSetToken } from "naystack/graphql/client";
3
+ import { useCallback } from "react";
4
4
  function useSignUpWithEmail(endpoint) {
5
5
  const setToken = useSetToken();
6
6
  return useCallback(
@@ -22,7 +22,6 @@ function useSignUpWithEmail(endpoint) {
22
22
  }
23
23
  function useLoginWithEmail(endpoint) {
24
24
  const setToken = useSetToken();
25
- console.warn(setToken, "2");
26
25
  return useCallback(
27
26
  async (data) => {
28
27
  const res = await fetch(endpoint, {
@@ -41,8 +40,7 @@ function useLoginWithEmail(endpoint) {
41
40
  );
42
41
  }
43
42
  function useLogout(endpoint) {
44
- const { setToken, token } = useContext(TokenContext);
45
- console.warn(token, setToken, "1");
43
+ const setToken = useSetToken();
46
44
  return useCallback(
47
45
  async (data) => {
48
46
  setToken(null);
@@ -63,8 +61,5 @@ function getEmailAuthUtils(endpoint) {
63
61
  };
64
62
  }
65
63
  export {
66
- getEmailAuthUtils,
67
- useLoginWithEmail,
68
- useLogout,
69
- useSignUpWithEmail
64
+ getEmailAuthUtils
70
65
  };
@@ -21,10 +21,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var server_exports = {};
22
22
  __export(server_exports, {
23
23
  Injector: () => Injector,
24
- getGraphQLQuery: () => getGraphQLQuery
24
+ PreloadQuery: () => PreloadQuery,
25
+ getClient: () => getClient,
26
+ getGraphQLQuery: () => getGraphQLQuery,
27
+ query: () => query
25
28
  });
26
29
  module.exports = __toCommonJS(server_exports);
27
30
  var import_client = require("@apollo/client");
31
+ var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
28
32
  var import_headers = require("next/headers");
29
33
  var import_react = require("react");
30
34
  function Injector({
@@ -42,15 +46,31 @@ async function InjectorSuspensed({
42
46
  const data = await fetch();
43
47
  return /* @__PURE__ */ React.createElement(Component, { loading: false, ...props || {}, data });
44
48
  }
45
- var getGraphQLQuery = ({ uri }) => {
46
- const client = new import_client.ApolloClient({
49
+ var { getClient, query, PreloadQuery } = (0, import_client_integration_nextjs.registerApolloClient)(() => {
50
+ return new import_client.ApolloClient({
47
51
  cache: new import_client.InMemoryCache(),
48
52
  link: new import_client.HttpLink({
49
- uri
53
+ // this needs to be an absolute url, as relative urls cannot be used in SSR
54
+ uri: "http://example.com/api/graphql",
55
+ fetchOptions: {
56
+ // you can pass additional options that should be passed to `fetch` here,
57
+ // e.g. Next.js-related `fetch` options regarding caching and revalidation
58
+ // see https://nextjs.org/docs/app/api-reference/functions/fetch#fetchurl-options
59
+ }
50
60
  })
51
61
  });
62
+ });
63
+ var getGraphQLQuery = ({ uri }) => {
64
+ const { query: query2 } = (0, import_client_integration_nextjs.registerApolloClient)(() => {
65
+ return new import_client.ApolloClient({
66
+ cache: new import_client.InMemoryCache(),
67
+ link: new import_client.HttpLink({
68
+ uri
69
+ })
70
+ });
71
+ });
52
72
  return async (_query, options) => {
53
- const res = await client.query({
73
+ const res = await query2({
54
74
  query: _query,
55
75
  variables: options?.variables,
56
76
  context: {
@@ -72,5 +92,8 @@ var getGraphQLQuery = ({ uri }) => {
72
92
  // Annotate the CommonJS export names for ESM import in node:
73
93
  0 && (module.exports = {
74
94
  Injector,
75
- getGraphQLQuery
95
+ PreloadQuery,
96
+ getClient,
97
+ getGraphQLQuery,
98
+ query
76
99
  });
@@ -1,6 +1,8 @@
1
+ import * as _apollo_client_integration_nextjs from '@apollo/client-integration-nextjs';
2
+ import * as _apollo_client from '@apollo/client';
3
+ import { ApolloClient, OperationVariables } from '@apollo/client';
1
4
  import * as React from 'react';
2
5
  import { FC } from 'react';
3
- import { OperationVariables } from '@apollo/client';
4
6
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
7
 
6
8
  type OmittedProps<Y> = Omit<Omit<Y, "loading">, "data">;
@@ -16,6 +18,9 @@ declare function Injector<T, Y>({ fetch, Component, props, }: {
16
18
  loading: boolean;
17
19
  } & Y>;
18
20
  } & ComponentProps<Y>): React.JSX.Element;
21
+ declare const getClient: () => ApolloClient<_apollo_client.NormalizedCacheObject>;
22
+ declare const query: <T = any, TVariables extends OperationVariables = OperationVariables>(options: _apollo_client.QueryOptions<TVariables, T>) => Promise<_apollo_client.ApolloQueryResult<_apollo_client.MaybeMasked<T>>>;
23
+ declare const PreloadQuery: _apollo_client_integration_nextjs.PreloadQueryComponent;
19
24
  declare const getGraphQLQuery: ({ uri }: {
20
25
  uri: string;
21
26
  }) => <T, V extends OperationVariables>(_query: TypedDocumentNode<T, V>, options?: {
@@ -25,4 +30,4 @@ declare const getGraphQLQuery: ({ uri }: {
25
30
  noCookie?: boolean;
26
31
  }) => Promise<T>;
27
32
 
28
- export { Injector, getGraphQLQuery };
33
+ export { Injector, PreloadQuery, getClient, getGraphQLQuery, query };
@@ -1,6 +1,8 @@
1
+ import * as _apollo_client_integration_nextjs from '@apollo/client-integration-nextjs';
2
+ import * as _apollo_client from '@apollo/client';
3
+ import { ApolloClient, OperationVariables } from '@apollo/client';
1
4
  import * as React from 'react';
2
5
  import { FC } from 'react';
3
- import { OperationVariables } from '@apollo/client';
4
6
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
7
 
6
8
  type OmittedProps<Y> = Omit<Omit<Y, "loading">, "data">;
@@ -16,6 +18,9 @@ declare function Injector<T, Y>({ fetch, Component, props, }: {
16
18
  loading: boolean;
17
19
  } & Y>;
18
20
  } & ComponentProps<Y>): React.JSX.Element;
21
+ declare const getClient: () => ApolloClient<_apollo_client.NormalizedCacheObject>;
22
+ declare const query: <T = any, TVariables extends OperationVariables = OperationVariables>(options: _apollo_client.QueryOptions<TVariables, T>) => Promise<_apollo_client.ApolloQueryResult<_apollo_client.MaybeMasked<T>>>;
23
+ declare const PreloadQuery: _apollo_client_integration_nextjs.PreloadQueryComponent;
19
24
  declare const getGraphQLQuery: ({ uri }: {
20
25
  uri: string;
21
26
  }) => <T, V extends OperationVariables>(_query: TypedDocumentNode<T, V>, options?: {
@@ -25,4 +30,4 @@ declare const getGraphQLQuery: ({ uri }: {
25
30
  noCookie?: boolean;
26
31
  }) => Promise<T>;
27
32
 
28
- export { Injector, getGraphQLQuery };
33
+ export { Injector, PreloadQuery, getClient, getGraphQLQuery, query };
@@ -4,6 +4,7 @@ import {
4
4
  HttpLink,
5
5
  InMemoryCache
6
6
  } from "@apollo/client";
7
+ import { registerApolloClient } from "@apollo/client-integration-nextjs";
7
8
  import { cookies } from "next/headers";
8
9
  import { Suspense } from "react";
9
10
  function Injector({
@@ -21,15 +22,31 @@ async function InjectorSuspensed({
21
22
  const data = await fetch();
22
23
  return /* @__PURE__ */ React.createElement(Component, { loading: false, ...props || {}, data });
23
24
  }
24
- var getGraphQLQuery = ({ uri }) => {
25
- const client = new ApolloClient({
25
+ var { getClient, query, PreloadQuery } = registerApolloClient(() => {
26
+ return new ApolloClient({
26
27
  cache: new InMemoryCache(),
27
28
  link: new HttpLink({
28
- uri
29
+ // this needs to be an absolute url, as relative urls cannot be used in SSR
30
+ uri: "http://example.com/api/graphql",
31
+ fetchOptions: {
32
+ // you can pass additional options that should be passed to `fetch` here,
33
+ // e.g. Next.js-related `fetch` options regarding caching and revalidation
34
+ // see https://nextjs.org/docs/app/api-reference/functions/fetch#fetchurl-options
35
+ }
29
36
  })
30
37
  });
38
+ });
39
+ var getGraphQLQuery = ({ uri }) => {
40
+ const { query: query2 } = registerApolloClient(() => {
41
+ return new ApolloClient({
42
+ cache: new InMemoryCache(),
43
+ link: new HttpLink({
44
+ uri
45
+ })
46
+ });
47
+ });
31
48
  return async (_query, options) => {
32
- const res = await client.query({
49
+ const res = await query2({
33
50
  query: _query,
34
51
  variables: options?.variables,
35
52
  context: {
@@ -50,5 +67,8 @@ var getGraphQLQuery = ({ uri }) => {
50
67
  };
51
68
  export {
52
69
  Injector,
53
- getGraphQLQuery
70
+ PreloadQuery,
71
+ getClient,
72
+ getGraphQLQuery,
73
+ query
54
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.2.12",
3
+ "version": "1.2.14",
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",