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.
- package/dist/auth/email/client.cjs.js +35 -7
- package/dist/auth/email/client.d.mts +13 -1
- package/dist/auth/email/client.d.ts +13 -1
- package/dist/auth/email/client.esm.js +34 -4
- package/dist/auth/email/index.cjs.js +23 -18
- package/dist/auth/email/index.d.mts +4 -12
- package/dist/auth/email/index.d.ts +4 -12
- package/dist/auth/email/index.esm.js +23 -18
- package/dist/auth/email/routes/delete.cjs.js +45 -1
- package/dist/auth/email/routes/delete.esm.js +45 -1
- package/dist/auth/email/routes/get.cjs.js +6 -2
- package/dist/auth/email/routes/get.d.mts +2 -2
- package/dist/auth/email/routes/get.d.ts +2 -2
- package/dist/auth/email/routes/get.esm.js +6 -2
- package/dist/auth/email/routes/post.cjs.js +3 -1
- package/dist/auth/email/routes/post.esm.js +3 -1
- package/dist/auth/email/routes/put.cjs.js +3 -0
- package/dist/auth/email/routes/put.esm.js +3 -0
- package/dist/auth/email/types.d.mts +5 -3
- package/dist/auth/email/types.d.ts +5 -3
- package/dist/auth/email/utils.cjs.js +8 -8
- package/dist/auth/email/utils.d.mts +3 -5
- package/dist/auth/email/utils.d.ts +3 -5
- package/dist/auth/email/utils.esm.js +7 -7
- package/dist/auth/index.cjs.js +23 -18
- package/dist/auth/index.d.mts +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.esm.js +23 -18
- package/dist/client/hooks.d.mts +2 -2
- package/dist/client/hooks.d.ts +2 -2
- package/dist/file/client.cjs.js +20 -23
- package/dist/file/client.d.mts +4 -10
- package/dist/file/client.d.ts +4 -10
- package/dist/file/client.esm.js +19 -22
- package/dist/file/index.cjs.js +47 -55
- package/dist/file/index.d.mts +0 -1
- package/dist/file/index.d.ts +0 -1
- package/dist/file/index.esm.js +47 -55
- package/dist/file/put.cjs.js +29 -58
- package/dist/file/put.d.mts +2 -1
- package/dist/file/put.d.ts +2 -1
- package/dist/file/put.esm.js +29 -58
- package/dist/file/setup.cjs.js +47 -55
- package/dist/file/setup.d.mts +16 -12
- package/dist/file/setup.d.ts +16 -12
- package/dist/file/setup.esm.js +47 -55
- package/dist/file/utils.cjs.js +29 -27
- package/dist/file/utils.d.mts +9 -6
- package/dist/file/utils.d.ts +9 -6
- package/dist/file/utils.esm.js +24 -22
- package/dist/graphql/client.cjs.js +11 -34
- package/dist/graphql/client.d.mts +3 -9
- package/dist/graphql/client.d.ts +3 -9
- package/dist/graphql/client.esm.js +8 -30
- package/dist/graphql/server.d.mts +2 -2
- package/dist/graphql/server.d.ts +2 -2
- package/dist/graphql/types.d.mts +2 -0
- package/dist/graphql/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/file/utils.esm.js
CHANGED
|
@@ -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
|
|
19
|
-
return
|
|
16
|
+
function getKey(keys) {
|
|
17
|
+
return typeof keys === "string" ? keys : keys.join("/");
|
|
20
18
|
}
|
|
21
|
-
var
|
|
19
|
+
var getUploadURL = (client, Bucket) => (keys) => {
|
|
22
20
|
const command = new PutObjectCommand({
|
|
23
21
|
Bucket,
|
|
24
|
-
Key:
|
|
25
|
-
ACL:
|
|
22
|
+
Key: getKey(keys),
|
|
23
|
+
ACL: "public-read"
|
|
26
24
|
});
|
|
27
25
|
return getSignedUrl(client, command, { expiresIn: 300 });
|
|
28
26
|
};
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
return `${getURLPrefix(options)}${getHash(keys)}`;
|
|
27
|
+
var getDownloadURL = (options) => (keys) => {
|
|
28
|
+
return `${getURLPrefix(options)}${getKey(keys)}`;
|
|
32
29
|
};
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
73
|
-
|
|
74
|
+
deleteFile,
|
|
75
|
+
getDownloadURL,
|
|
74
76
|
getS3Client,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
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 [
|
|
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
|
|
77
|
+
void fetch({
|
|
98
78
|
variables,
|
|
99
79
|
context: tokenContext(token),
|
|
100
80
|
fetchPolicy: "no-cache"
|
|
101
81
|
});
|
|
102
82
|
}
|
|
103
|
-
}, [
|
|
83
|
+
}, [fetch, token, variables, calledVars]);
|
|
104
84
|
const reFetch = (0, import_react.useCallback)(
|
|
105
|
-
(v) =>
|
|
85
|
+
(v) => fetch({
|
|
106
86
|
variables: v,
|
|
107
87
|
context: tokenContext(token),
|
|
108
88
|
fetchPolicy: "no-cache"
|
|
109
89
|
}),
|
|
110
|
-
[
|
|
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
|
|
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) =>
|
|
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 {
|
|
21
|
+
export { getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
|
package/dist/graphql/client.d.ts
CHANGED
|
@@ -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
|
|
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) =>
|
|
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 {
|
|
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
|
-
|
|
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 [
|
|
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
|
|
53
|
+
void fetch({
|
|
73
54
|
variables,
|
|
74
55
|
context: tokenContext(token),
|
|
75
56
|
fetchPolicy: "no-cache"
|
|
76
57
|
});
|
|
77
58
|
}
|
|
78
|
-
}, [
|
|
59
|
+
}, [fetch, token, variables, calledVars]);
|
|
79
60
|
const reFetch = useCallback(
|
|
80
|
-
(v) =>
|
|
61
|
+
(v) => fetch({
|
|
81
62
|
variables: v,
|
|
82
63
|
context: tokenContext(token),
|
|
83
64
|
fetchPolicy: "no-cache"
|
|
84
65
|
}),
|
|
85
|
-
[
|
|
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
|
|
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>):
|
|
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?: {
|
package/dist/graphql/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
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>):
|
|
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?: {
|
package/dist/graphql/types.d.mts
CHANGED
package/dist/graphql/types.d.ts
CHANGED