naystack 1.2.16 → 1.2.19

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.
Files changed (59) hide show
  1. package/dist/auth/email/client.cjs.js +35 -7
  2. package/dist/auth/email/client.d.mts +13 -1
  3. package/dist/auth/email/client.d.ts +13 -1
  4. package/dist/auth/email/client.esm.js +34 -4
  5. package/dist/auth/email/index.cjs.js +23 -18
  6. package/dist/auth/email/index.d.mts +4 -12
  7. package/dist/auth/email/index.d.ts +4 -12
  8. package/dist/auth/email/index.esm.js +23 -18
  9. package/dist/auth/email/routes/delete.cjs.js +45 -1
  10. package/dist/auth/email/routes/delete.esm.js +45 -1
  11. package/dist/auth/email/routes/get.cjs.js +6 -2
  12. package/dist/auth/email/routes/get.d.mts +2 -2
  13. package/dist/auth/email/routes/get.d.ts +2 -2
  14. package/dist/auth/email/routes/get.esm.js +6 -2
  15. package/dist/auth/email/routes/post.cjs.js +3 -1
  16. package/dist/auth/email/routes/post.esm.js +3 -1
  17. package/dist/auth/email/routes/put.cjs.js +3 -0
  18. package/dist/auth/email/routes/put.esm.js +3 -0
  19. package/dist/auth/email/types.d.mts +5 -3
  20. package/dist/auth/email/types.d.ts +5 -3
  21. package/dist/auth/email/utils.cjs.js +8 -8
  22. package/dist/auth/email/utils.d.mts +3 -5
  23. package/dist/auth/email/utils.d.ts +3 -5
  24. package/dist/auth/email/utils.esm.js +7 -7
  25. package/dist/auth/index.cjs.js +23 -18
  26. package/dist/auth/index.d.mts +1 -0
  27. package/dist/auth/index.d.ts +1 -0
  28. package/dist/auth/index.esm.js +23 -18
  29. package/dist/client/hooks.d.mts +2 -2
  30. package/dist/client/hooks.d.ts +2 -2
  31. package/dist/file/client.cjs.js +20 -23
  32. package/dist/file/client.d.mts +4 -10
  33. package/dist/file/client.d.ts +4 -10
  34. package/dist/file/client.esm.js +19 -22
  35. package/dist/file/index.cjs.js +47 -55
  36. package/dist/file/index.d.mts +0 -1
  37. package/dist/file/index.d.ts +0 -1
  38. package/dist/file/index.esm.js +47 -55
  39. package/dist/file/put.cjs.js +29 -58
  40. package/dist/file/put.d.mts +2 -1
  41. package/dist/file/put.d.ts +2 -1
  42. package/dist/file/put.esm.js +29 -58
  43. package/dist/file/setup.cjs.js +47 -55
  44. package/dist/file/setup.d.mts +16 -12
  45. package/dist/file/setup.d.ts +16 -12
  46. package/dist/file/setup.esm.js +47 -55
  47. package/dist/file/utils.cjs.js +29 -27
  48. package/dist/file/utils.d.mts +9 -6
  49. package/dist/file/utils.d.ts +9 -6
  50. package/dist/file/utils.esm.js +24 -22
  51. package/dist/graphql/client.cjs.js +11 -34
  52. package/dist/graphql/client.d.mts +3 -9
  53. package/dist/graphql/client.d.ts +3 -9
  54. package/dist/graphql/client.esm.js +8 -30
  55. package/dist/graphql/server.d.mts +2 -2
  56. package/dist/graphql/server.d.ts +2 -2
  57. package/dist/graphql/types.d.mts +2 -0
  58. package/dist/graphql/types.d.ts +2 -0
  59. package/package.json +1 -1
@@ -1,12 +1,10 @@
1
1
  // src/file/utils.ts
2
- import { createHash } from "crypto";
3
2
  import {
4
3
  DeleteObjectCommand,
5
4
  PutObjectCommand,
6
5
  S3Client
7
6
  } from "@aws-sdk/client-s3";
8
7
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
9
- import { waitUntil } from "@vercel/functions";
10
8
  var getS3Client = (options) => new S3Client({
11
9
  region: options.region,
12
10
  credentials: {
@@ -15,30 +13,34 @@ var getS3Client = (options) => new S3Client({
15
13
  }
16
14
  });
17
15
  var getURLPrefix = (options) => `https://${options.bucket}.s3.${options.region}.amazonaws.com/`;
18
- function getHash(keys) {
19
- return createHash("sha256").update(keys.join("/")).digest("hex");
16
+ function getKey(keys) {
17
+ return typeof keys === "string" ? keys : keys.join("/");
20
18
  }
21
- var getUploadFileURL = (client, Bucket) => (keys, isPublic) => {
19
+ var getUploadURL = (client, Bucket) => (keys) => {
22
20
  const command = new PutObjectCommand({
23
21
  Bucket,
24
- Key: getHash(keys),
25
- ACL: isPublic ? "public-read" : void 0
22
+ Key: getKey(keys),
23
+ ACL: "public-read"
26
24
  });
27
25
  return getSignedUrl(client, command, { expiresIn: 300 });
28
26
  };
29
- var getFileURL = (options) => (keys) => {
30
- if (typeof keys === "string") return `${getURLPrefix(options)}${keys}`;
31
- return `${getURLPrefix(options)}${getHash(keys)}`;
27
+ var getDownloadURL = (options) => (keys) => {
28
+ return `${getURLPrefix(options)}${getKey(keys)}`;
32
29
  };
33
- var uploadImage = (client, options) => async (url, key, blob) => {
34
- const photoBlob = blob || await fetch(url).then((file) => file.blob());
35
- if (photoBlob) {
36
- waitUntil(uploadFile(client, options.bucket)(photoBlob, getHash(key)));
37
- return getFileURL(options)(key);
30
+ var uploadFile = (client, options) => async (keys, {
31
+ url,
32
+ blob
33
+ }) => {
34
+ if (!blob && !url) return null;
35
+ const fileBlob = blob || await fetch(url).then((file) => file.blob());
36
+ if (fileBlob) {
37
+ const key = getKey(keys);
38
+ await uploadBlob(client, options.bucket)(fileBlob, key);
39
+ return getDownloadURL(options)(key);
38
40
  }
39
41
  return null;
40
42
  };
41
- var deleteImage = (client, options) => async (url) => {
43
+ var deleteFile = (client, options) => async (url) => {
42
44
  const key = url.split(getURLPrefix(options))[1];
43
45
  if (key) {
44
46
  try {
@@ -55,7 +57,7 @@ var deleteImage = (client, options) => async (url) => {
55
57
  }
56
58
  return false;
57
59
  };
58
- var uploadFile = (client, Bucket) => async (file, key) => {
60
+ var uploadBlob = (client, Bucket) => async (file, key) => {
59
61
  const fileBuffer = await file.arrayBuffer();
60
62
  return client.send(
61
63
  new PutObjectCommand({
@@ -69,10 +71,10 @@ var uploadFile = (client, Bucket) => async (file, key) => {
69
71
  );
70
72
  };
71
73
  export {
72
- deleteImage,
73
- getFileURL,
74
+ deleteFile,
75
+ getDownloadURL,
74
76
  getS3Client,
75
- getUploadFileURL,
76
- uploadFile,
77
- uploadImage
77
+ getUploadURL,
78
+ uploadBlob,
79
+ uploadFile
78
80
  };
@@ -31,22 +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
- TokenContext: () => TokenContext,
35
34
  getApolloWrapper: () => getApolloWrapper,
36
35
  tokenContext: () => tokenContext,
37
36
  useAuthMutation: () => useAuthMutation,
38
- useAuthQuery: () => useAuthQuery,
39
- useSetToken: () => useSetToken,
40
- useToken: () => useToken
37
+ useAuthQuery: () => useAuthQuery
41
38
  });
42
39
  module.exports = __toCommonJS(client_exports);
43
40
  var import_client = require("@apollo/client");
44
41
  var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
42
+ var import_client2 = require("naystack/auth/email/client");
45
43
  var import_react = __toESM(require("react"));
46
- var TokenContext = (0, import_react.createContext)({
47
- token: null,
48
- setToken: () => null
49
- });
50
44
  var getApolloWrapper = ({
51
45
  graphqlUri,
52
46
  cacheConfig,
@@ -61,23 +55,9 @@ var getApolloWrapper = ({
61
55
  });
62
56
  }
63
57
  return ({ children }) => {
64
- const [token, setToken] = (0, import_react.useState)(null);
65
- (0, import_react.useEffect)(() => {
66
- fetch(authEndpoint, {
67
- credentials: "include"
68
- }).then((res) => res.json()).then((data) => setToken(data.accessToken));
69
- }, []);
70
- return /* @__PURE__ */ import_react.default.createElement(import_client_integration_nextjs.ApolloNextAppProvider, { makeClient }, /* @__PURE__ */ import_react.default.createElement(TokenContext.Provider, { value: { token, setToken } }, children));
58
+ return /* @__PURE__ */ import_react.default.createElement(import_client_integration_nextjs.ApolloNextAppProvider, { makeClient }, children);
71
59
  };
72
60
  };
73
- function useToken() {
74
- const { token } = (0, import_react.useContext)(TokenContext);
75
- return token;
76
- }
77
- function useSetToken() {
78
- const { setToken } = (0, import_react.useContext)(TokenContext);
79
- return setToken;
80
- }
81
61
  var tokenContext = (token) => {
82
62
  if (!token) return void 0;
83
63
  return {
@@ -88,31 +68,31 @@ var tokenContext = (token) => {
88
68
  };
89
69
  };
90
70
  function useAuthQuery(query, variables) {
91
- const token = useToken();
92
- const [fetch2, result] = (0, import_client.useLazyQuery)(query);
71
+ const token = (0, import_client2.useToken)();
72
+ const [fetch, result] = (0, import_client.useLazyQuery)(query);
93
73
  const [calledVars, setCalledVars] = (0, import_react.useState)();
94
74
  (0, import_react.useEffect)(() => {
95
75
  if (token && variables && calledVars !== JSON.stringify(variables)) {
96
76
  setCalledVars(JSON.stringify(variables));
97
- void fetch2({
77
+ void fetch({
98
78
  variables,
99
79
  context: tokenContext(token),
100
80
  fetchPolicy: "no-cache"
101
81
  });
102
82
  }
103
- }, [fetch2, token, variables, calledVars]);
83
+ }, [fetch, token, variables, calledVars]);
104
84
  const reFetch = (0, import_react.useCallback)(
105
- (v) => fetch2({
85
+ (v) => fetch({
106
86
  variables: v,
107
87
  context: tokenContext(token),
108
88
  fetchPolicy: "no-cache"
109
89
  }),
110
- [fetch2, token]
90
+ [fetch, token]
111
91
  );
112
92
  return [reFetch, result];
113
93
  }
114
94
  function useAuthMutation(mutation, options) {
115
- const token = useToken();
95
+ const token = (0, import_client2.useToken)();
116
96
  const [mutate, result] = (0, import_client.useMutation)(mutation, options);
117
97
  const method = (0, import_react.useCallback)(
118
98
  (variables) => mutate({
@@ -125,11 +105,8 @@ function useAuthMutation(mutation, options) {
125
105
  }
126
106
  // Annotate the CommonJS export names for ESM import in node:
127
107
  0 && (module.exports = {
128
- TokenContext,
129
108
  getApolloWrapper,
130
109
  tokenContext,
131
110
  useAuthMutation,
132
- useAuthQuery,
133
- useSetToken,
134
- useToken
111
+ useAuthQuery
135
112
  });
@@ -2,19 +2,13 @@ import * as _apollo_client from '@apollo/client';
2
2
  import { OperationVariables, MutationHookOptions } from '@apollo/client';
3
3
  import { InMemoryCacheConfig } from '@apollo/client/cache';
4
4
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
- import React__default, { Dispatch, SetStateAction, PropsWithChildren } from 'react';
5
+ import react__default, { PropsWithChildren } from 'react';
6
6
 
7
- declare const TokenContext: React__default.Context<{
8
- token: string | null;
9
- setToken: Dispatch<SetStateAction<string | null>>;
10
- }>;
11
7
  declare const getApolloWrapper: ({ graphqlUri, cacheConfig, authEndpoint, }: {
12
8
  graphqlUri: string;
13
9
  authEndpoint: string;
14
10
  cacheConfig?: InMemoryCacheConfig;
15
- }) => ({ children }: PropsWithChildren) => React__default.JSX.Element;
16
- declare function useToken(): string | null;
17
- declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
11
+ }) => ({ children }: PropsWithChildren) => react__default.JSX.Element;
18
12
  declare const tokenContext: (token?: string | null) => {
19
13
  headers: {
20
14
  authorization: string;
@@ -24,4 +18,4 @@ declare const tokenContext: (token?: string | null) => {
24
18
  declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V): readonly [(v?: V) => Promise<_apollo_client.QueryResult<T, V>>, _apollo_client.QueryResult<T, V>];
25
19
  declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(variables?: V) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
26
20
 
27
- export { TokenContext, getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery, useSetToken, useToken };
21
+ export { getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
@@ -2,19 +2,13 @@ import * as _apollo_client from '@apollo/client';
2
2
  import { OperationVariables, MutationHookOptions } from '@apollo/client';
3
3
  import { InMemoryCacheConfig } from '@apollo/client/cache';
4
4
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
- import React__default, { Dispatch, SetStateAction, PropsWithChildren } from 'react';
5
+ import react__default, { PropsWithChildren } from 'react';
6
6
 
7
- declare const TokenContext: React__default.Context<{
8
- token: string | null;
9
- setToken: Dispatch<SetStateAction<string | null>>;
10
- }>;
11
7
  declare const getApolloWrapper: ({ graphqlUri, cacheConfig, authEndpoint, }: {
12
8
  graphqlUri: string;
13
9
  authEndpoint: string;
14
10
  cacheConfig?: InMemoryCacheConfig;
15
- }) => ({ children }: PropsWithChildren) => React__default.JSX.Element;
16
- declare function useToken(): string | null;
17
- declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
11
+ }) => ({ children }: PropsWithChildren) => react__default.JSX.Element;
18
12
  declare const tokenContext: (token?: string | null) => {
19
13
  headers: {
20
14
  authorization: string;
@@ -24,4 +18,4 @@ declare const tokenContext: (token?: string | null) => {
24
18
  declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V): readonly [(v?: V) => Promise<_apollo_client.QueryResult<T, V>>, _apollo_client.QueryResult<T, V>];
25
19
  declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(variables?: V) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
26
20
 
27
- export { TokenContext, getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery, useSetToken, useToken };
21
+ export { getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
@@ -11,17 +11,12 @@ import {
11
11
  ApolloNextAppProvider,
12
12
  InMemoryCache
13
13
  } from "@apollo/client-integration-nextjs";
14
+ import { useToken } from "naystack/auth/email/client";
14
15
  import React, {
15
- createContext,
16
16
  useCallback,
17
- useContext,
18
17
  useEffect,
19
18
  useState
20
19
  } from "react";
21
- var TokenContext = createContext({
22
- token: null,
23
- setToken: () => null
24
- });
25
20
  var getApolloWrapper = ({
26
21
  graphqlUri,
27
22
  cacheConfig,
@@ -36,23 +31,9 @@ var getApolloWrapper = ({
36
31
  });
37
32
  }
38
33
  return ({ children }) => {
39
- const [token, setToken] = useState(null);
40
- useEffect(() => {
41
- fetch(authEndpoint, {
42
- credentials: "include"
43
- }).then((res) => res.json()).then((data) => setToken(data.accessToken));
44
- }, []);
45
- return /* @__PURE__ */ React.createElement(ApolloNextAppProvider, { makeClient }, /* @__PURE__ */ React.createElement(TokenContext.Provider, { value: { token, setToken } }, children));
34
+ return /* @__PURE__ */ React.createElement(ApolloNextAppProvider, { makeClient }, children);
46
35
  };
47
36
  };
48
- function useToken() {
49
- const { token } = useContext(TokenContext);
50
- return token;
51
- }
52
- function useSetToken() {
53
- const { setToken } = useContext(TokenContext);
54
- return setToken;
55
- }
56
37
  var tokenContext = (token) => {
57
38
  if (!token) return void 0;
58
39
  return {
@@ -64,25 +45,25 @@ var tokenContext = (token) => {
64
45
  };
65
46
  function useAuthQuery(query, variables) {
66
47
  const token = useToken();
67
- const [fetch2, result] = useLazyQuery(query);
48
+ const [fetch, result] = useLazyQuery(query);
68
49
  const [calledVars, setCalledVars] = useState();
69
50
  useEffect(() => {
70
51
  if (token && variables && calledVars !== JSON.stringify(variables)) {
71
52
  setCalledVars(JSON.stringify(variables));
72
- void fetch2({
53
+ void fetch({
73
54
  variables,
74
55
  context: tokenContext(token),
75
56
  fetchPolicy: "no-cache"
76
57
  });
77
58
  }
78
- }, [fetch2, token, variables, calledVars]);
59
+ }, [fetch, token, variables, calledVars]);
79
60
  const reFetch = useCallback(
80
- (v) => fetch2({
61
+ (v) => fetch({
81
62
  variables: v,
82
63
  context: tokenContext(token),
83
64
  fetchPolicy: "no-cache"
84
65
  }),
85
- [fetch2, token]
66
+ [fetch, token]
86
67
  );
87
68
  return [reFetch, result];
88
69
  }
@@ -99,11 +80,8 @@ function useAuthMutation(mutation, options) {
99
80
  return [method, result];
100
81
  }
101
82
  export {
102
- TokenContext,
103
83
  getApolloWrapper,
104
84
  tokenContext,
105
85
  useAuthMutation,
106
- useAuthQuery,
107
- useSetToken,
108
- useToken
86
+ useAuthQuery
109
87
  };
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import * as react from 'react';
2
2
  import { FC } from 'react';
3
3
  import { OperationVariables } from '@apollo/client';
4
4
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
@@ -15,7 +15,7 @@ declare function Injector<T, Y>({ fetch, Component, props, }: {
15
15
  data?: T;
16
16
  loading: boolean;
17
17
  } & Y>;
18
- } & ComponentProps<Y>): React.JSX.Element;
18
+ } & ComponentProps<Y>): react.JSX.Element;
19
19
  declare const getGraphQLQuery: ({ uri }: {
20
20
  uri: string;
21
21
  }) => <T, V extends OperationVariables>(_query: TypedDocumentNode<T, V>, options?: {
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import * as react from 'react';
2
2
  import { FC } from 'react';
3
3
  import { OperationVariables } from '@apollo/client';
4
4
  import { TypedDocumentNode } from '@graphql-typed-document-node/core';
@@ -15,7 +15,7 @@ declare function Injector<T, Y>({ fetch, Component, props, }: {
15
15
  data?: T;
16
16
  loading: boolean;
17
17
  } & Y>;
18
- } & ComponentProps<Y>): React.JSX.Element;
18
+ } & ComponentProps<Y>): react.JSX.Element;
19
19
  declare const getGraphQLQuery: ({ uri }: {
20
20
  uri: string;
21
21
  }) => <T, V extends OperationVariables>(_query: TypedDocumentNode<T, V>, options?: {
@@ -1,8 +1,10 @@
1
1
  interface Context {
2
2
  userId: number | null;
3
+ isRefreshID?: boolean;
3
4
  }
4
5
  interface AuthorizedContext {
5
6
  userId: number;
7
+ isRefreshID?: boolean;
6
8
  }
7
9
 
8
10
  export type { AuthorizedContext, Context };
@@ -1,8 +1,10 @@
1
1
  interface Context {
2
2
  userId: number | null;
3
+ isRefreshID?: boolean;
3
4
  }
4
5
  interface AuthorizedContext {
5
6
  userId: number;
7
+ isRefreshID?: boolean;
6
8
  }
7
9
 
8
10
  export type { AuthorizedContext, Context };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.2.16",
3
+ "version": "1.2.19",
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",