naystack 1.2.17 → 1.2.20
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/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 +39 -47
- package/dist/file/index.d.mts +0 -1
- package/dist/file/index.d.ts +0 -1
- package/dist/file/index.esm.js +39 -47
- package/dist/file/put.cjs.js +21 -50
- package/dist/file/put.d.mts +2 -1
- package/dist/file/put.d.ts +2 -1
- package/dist/file/put.esm.js +21 -50
- package/dist/file/setup.cjs.js +39 -47
- package/dist/file/setup.d.mts +16 -12
- package/dist/file/setup.d.ts +16 -12
- package/dist/file/setup.esm.js +39 -47
- 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 +14 -39
- package/dist/graphql/client.d.mts +5 -14
- package/dist/graphql/client.d.ts +5 -14
- package/dist/graphql/client.esm.js +11 -35
- package/dist/graphql/init.d.mts +1 -1
- package/dist/graphql/init.d.ts +1 -1
- package/dist/graphql/server.d.mts +2 -2
- package/dist/graphql/server.d.ts +2 -2
- package/package.json +1 -1
package/dist/file/utils.cjs.js
CHANGED
|
@@ -20,18 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/file/utils.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
deleteFile: () => deleteFile,
|
|
24
|
+
getDownloadURL: () => getDownloadURL,
|
|
25
25
|
getS3Client: () => getS3Client,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
getUploadURL: () => getUploadURL,
|
|
27
|
+
uploadBlob: () => uploadBlob,
|
|
28
|
+
uploadFile: () => uploadFile
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(utils_exports);
|
|
31
|
-
var import_node_crypto = require("crypto");
|
|
32
31
|
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
33
32
|
var import_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
|
|
34
|
-
var import_functions = require("@vercel/functions");
|
|
35
33
|
var getS3Client = (options) => new import_client_s3.S3Client({
|
|
36
34
|
region: options.region,
|
|
37
35
|
credentials: {
|
|
@@ -40,30 +38,34 @@ var getS3Client = (options) => new import_client_s3.S3Client({
|
|
|
40
38
|
}
|
|
41
39
|
});
|
|
42
40
|
var getURLPrefix = (options) => `https://${options.bucket}.s3.${options.region}.amazonaws.com/`;
|
|
43
|
-
function
|
|
44
|
-
return
|
|
41
|
+
function getKey(keys) {
|
|
42
|
+
return typeof keys === "string" ? keys : keys.join("/");
|
|
45
43
|
}
|
|
46
|
-
var
|
|
44
|
+
var getUploadURL = (client, Bucket) => (keys) => {
|
|
47
45
|
const command = new import_client_s3.PutObjectCommand({
|
|
48
46
|
Bucket,
|
|
49
|
-
Key:
|
|
50
|
-
ACL:
|
|
47
|
+
Key: getKey(keys),
|
|
48
|
+
ACL: "public-read"
|
|
51
49
|
});
|
|
52
50
|
return (0, import_s3_request_presigner.getSignedUrl)(client, command, { expiresIn: 300 });
|
|
53
51
|
};
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
return `${getURLPrefix(options)}${getHash(keys)}`;
|
|
52
|
+
var getDownloadURL = (options) => (keys) => {
|
|
53
|
+
return `${getURLPrefix(options)}${getKey(keys)}`;
|
|
57
54
|
};
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
var uploadFile = (client, options) => async (keys, {
|
|
56
|
+
url,
|
|
57
|
+
blob
|
|
58
|
+
}) => {
|
|
59
|
+
if (!blob && !url) return null;
|
|
60
|
+
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
61
|
+
if (fileBlob) {
|
|
62
|
+
const key = getKey(keys);
|
|
63
|
+
await uploadBlob(client, options.bucket)(fileBlob, key);
|
|
64
|
+
return getDownloadURL(options)(key);
|
|
63
65
|
}
|
|
64
66
|
return null;
|
|
65
67
|
};
|
|
66
|
-
var
|
|
68
|
+
var deleteFile = (client, options) => async (url) => {
|
|
67
69
|
const key = url.split(getURLPrefix(options))[1];
|
|
68
70
|
if (key) {
|
|
69
71
|
try {
|
|
@@ -80,7 +82,7 @@ var deleteImage = (client, options) => async (url) => {
|
|
|
80
82
|
}
|
|
81
83
|
return false;
|
|
82
84
|
};
|
|
83
|
-
var
|
|
85
|
+
var uploadBlob = (client, Bucket) => async (file, key) => {
|
|
84
86
|
const fileBuffer = await file.arrayBuffer();
|
|
85
87
|
return client.send(
|
|
86
88
|
new import_client_s3.PutObjectCommand({
|
|
@@ -95,10 +97,10 @@ var uploadFile = (client, Bucket) => async (file, key) => {
|
|
|
95
97
|
};
|
|
96
98
|
// Annotate the CommonJS export names for ESM import in node:
|
|
97
99
|
0 && (module.exports = {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
deleteFile,
|
|
101
|
+
getDownloadURL,
|
|
100
102
|
getS3Client,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
getUploadURL,
|
|
104
|
+
uploadBlob,
|
|
105
|
+
uploadFile
|
|
104
106
|
});
|
package/dist/file/utils.d.mts
CHANGED
|
@@ -4,10 +4,13 @@ import { SetupFileUploadOptions } from './setup.mjs';
|
|
|
4
4
|
import 'next/server';
|
|
5
5
|
|
|
6
6
|
declare const getS3Client: (options: SetupFileUploadOptions) => S3Client;
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
9
|
-
declare const
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
declare const getUploadURL: (client: S3Client, Bucket: string) => (keys: string | string[]) => Promise<string>;
|
|
8
|
+
declare const getDownloadURL: (options: SetupFileUploadOptions) => (keys: string | string[]) => string;
|
|
9
|
+
declare const uploadFile: (client: S3Client, options: SetupFileUploadOptions) => (keys: string | string[], { url, blob, }: {
|
|
10
|
+
blob?: Blob;
|
|
11
|
+
url?: string;
|
|
12
|
+
}) => Promise<string | null>;
|
|
13
|
+
declare const deleteFile: (client: S3Client, options: SetupFileUploadOptions) => (url: string) => Promise<boolean>;
|
|
14
|
+
declare const uploadBlob: (client: S3Client, Bucket: string) => (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
|
|
12
15
|
|
|
13
|
-
export {
|
|
16
|
+
export { deleteFile, getDownloadURL, getS3Client, getUploadURL, uploadBlob, uploadFile };
|
package/dist/file/utils.d.ts
CHANGED
|
@@ -4,10 +4,13 @@ import { SetupFileUploadOptions } from './setup.js';
|
|
|
4
4
|
import 'next/server';
|
|
5
5
|
|
|
6
6
|
declare const getS3Client: (options: SetupFileUploadOptions) => S3Client;
|
|
7
|
-
declare const
|
|
8
|
-
declare const
|
|
9
|
-
declare const
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
declare const getUploadURL: (client: S3Client, Bucket: string) => (keys: string | string[]) => Promise<string>;
|
|
8
|
+
declare const getDownloadURL: (options: SetupFileUploadOptions) => (keys: string | string[]) => string;
|
|
9
|
+
declare const uploadFile: (client: S3Client, options: SetupFileUploadOptions) => (keys: string | string[], { url, blob, }: {
|
|
10
|
+
blob?: Blob;
|
|
11
|
+
url?: string;
|
|
12
|
+
}) => Promise<string | null>;
|
|
13
|
+
declare const deleteFile: (client: S3Client, options: SetupFileUploadOptions) => (url: string) => Promise<boolean>;
|
|
14
|
+
declare const uploadBlob: (client: S3Client, Bucket: string) => (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
|
|
12
15
|
|
|
13
|
-
export {
|
|
16
|
+
export { deleteFile, getDownloadURL, getS3Client, getUploadURL, uploadBlob, uploadFile };
|
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,53 +31,31 @@ 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
|
|
47
|
-
|
|
48
|
-
setToken: () => null
|
|
49
|
-
});
|
|
50
|
-
var getApolloWrapper = ({
|
|
51
|
-
graphqlUri,
|
|
52
|
-
cacheConfig,
|
|
53
|
-
authEndpoint
|
|
44
|
+
var getApolloWrapper = (endpoint, {
|
|
45
|
+
cacheConfig
|
|
54
46
|
}) => {
|
|
55
47
|
function makeClient() {
|
|
56
48
|
return new import_client_integration_nextjs.ApolloClient({
|
|
57
49
|
cache: new import_client_integration_nextjs.InMemoryCache(cacheConfig),
|
|
58
50
|
link: new import_client.HttpLink({
|
|
59
|
-
uri:
|
|
51
|
+
uri: endpoint
|
|
60
52
|
})
|
|
61
53
|
});
|
|
62
54
|
}
|
|
63
55
|
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));
|
|
56
|
+
return /* @__PURE__ */ import_react.default.createElement(import_client_integration_nextjs.ApolloNextAppProvider, { makeClient }, children);
|
|
71
57
|
};
|
|
72
58
|
};
|
|
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
59
|
var tokenContext = (token) => {
|
|
82
60
|
if (!token) return void 0;
|
|
83
61
|
return {
|
|
@@ -88,31 +66,31 @@ var tokenContext = (token) => {
|
|
|
88
66
|
};
|
|
89
67
|
};
|
|
90
68
|
function useAuthQuery(query, variables) {
|
|
91
|
-
const token = useToken();
|
|
92
|
-
const [
|
|
69
|
+
const token = (0, import_client2.useToken)();
|
|
70
|
+
const [fetch, result] = (0, import_client.useLazyQuery)(query);
|
|
93
71
|
const [calledVars, setCalledVars] = (0, import_react.useState)();
|
|
94
72
|
(0, import_react.useEffect)(() => {
|
|
95
73
|
if (token && variables && calledVars !== JSON.stringify(variables)) {
|
|
96
74
|
setCalledVars(JSON.stringify(variables));
|
|
97
|
-
void
|
|
75
|
+
void fetch({
|
|
98
76
|
variables,
|
|
99
77
|
context: tokenContext(token),
|
|
100
78
|
fetchPolicy: "no-cache"
|
|
101
79
|
});
|
|
102
80
|
}
|
|
103
|
-
}, [
|
|
81
|
+
}, [fetch, token, variables, calledVars]);
|
|
104
82
|
const reFetch = (0, import_react.useCallback)(
|
|
105
|
-
(v) =>
|
|
83
|
+
(v) => fetch({
|
|
106
84
|
variables: v,
|
|
107
85
|
context: tokenContext(token),
|
|
108
86
|
fetchPolicy: "no-cache"
|
|
109
87
|
}),
|
|
110
|
-
[
|
|
88
|
+
[fetch, token]
|
|
111
89
|
);
|
|
112
90
|
return [reFetch, result];
|
|
113
91
|
}
|
|
114
92
|
function useAuthMutation(mutation, options) {
|
|
115
|
-
const token = useToken();
|
|
93
|
+
const token = (0, import_client2.useToken)();
|
|
116
94
|
const [mutate, result] = (0, import_client.useMutation)(mutation, options);
|
|
117
95
|
const method = (0, import_react.useCallback)(
|
|
118
96
|
(variables) => mutate({
|
|
@@ -125,11 +103,8 @@ function useAuthMutation(mutation, options) {
|
|
|
125
103
|
}
|
|
126
104
|
// Annotate the CommonJS export names for ESM import in node:
|
|
127
105
|
0 && (module.exports = {
|
|
128
|
-
TokenContext,
|
|
129
106
|
getApolloWrapper,
|
|
130
107
|
tokenContext,
|
|
131
108
|
useAuthMutation,
|
|
132
|
-
useAuthQuery
|
|
133
|
-
useSetToken,
|
|
134
|
-
useToken
|
|
109
|
+
useAuthQuery
|
|
135
110
|
});
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import * as _apollo_client from '@apollo/client';
|
|
2
|
-
import { OperationVariables, MutationHookOptions } from '@apollo/client';
|
|
3
|
-
import { InMemoryCacheConfig } from '@apollo/client/cache';
|
|
2
|
+
import { InMemoryCacheConfig, OperationVariables, MutationHookOptions } from '@apollo/client';
|
|
4
3
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
5
|
-
import
|
|
4
|
+
import react__default, { PropsWithChildren } from 'react';
|
|
6
5
|
|
|
7
|
-
declare const
|
|
8
|
-
token: string | null;
|
|
9
|
-
setToken: Dispatch<SetStateAction<string | null>>;
|
|
10
|
-
}>;
|
|
11
|
-
declare const getApolloWrapper: ({ graphqlUri, cacheConfig, authEndpoint, }: {
|
|
12
|
-
graphqlUri: string;
|
|
13
|
-
authEndpoint: string;
|
|
6
|
+
declare const getApolloWrapper: (endpoint: string, { cacheConfig, }: {
|
|
14
7
|
cacheConfig?: InMemoryCacheConfig;
|
|
15
|
-
}) => ({ children }: PropsWithChildren) =>
|
|
16
|
-
declare function useToken(): string | null;
|
|
17
|
-
declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
|
|
8
|
+
}) => ({ children }: PropsWithChildren) => react__default.JSX.Element;
|
|
18
9
|
declare const tokenContext: (token?: string | null) => {
|
|
19
10
|
headers: {
|
|
20
11
|
authorization: string;
|
|
@@ -24,4 +15,4 @@ declare const tokenContext: (token?: string | null) => {
|
|
|
24
15
|
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
16
|
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
17
|
|
|
27
|
-
export {
|
|
18
|
+
export { getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
|
package/dist/graphql/client.d.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import * as _apollo_client from '@apollo/client';
|
|
2
|
-
import { OperationVariables, MutationHookOptions } from '@apollo/client';
|
|
3
|
-
import { InMemoryCacheConfig } from '@apollo/client/cache';
|
|
2
|
+
import { InMemoryCacheConfig, OperationVariables, MutationHookOptions } from '@apollo/client';
|
|
4
3
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
5
|
-
import
|
|
4
|
+
import react__default, { PropsWithChildren } from 'react';
|
|
6
5
|
|
|
7
|
-
declare const
|
|
8
|
-
token: string | null;
|
|
9
|
-
setToken: Dispatch<SetStateAction<string | null>>;
|
|
10
|
-
}>;
|
|
11
|
-
declare const getApolloWrapper: ({ graphqlUri, cacheConfig, authEndpoint, }: {
|
|
12
|
-
graphqlUri: string;
|
|
13
|
-
authEndpoint: string;
|
|
6
|
+
declare const getApolloWrapper: (endpoint: string, { cacheConfig, }: {
|
|
14
7
|
cacheConfig?: InMemoryCacheConfig;
|
|
15
|
-
}) => ({ children }: PropsWithChildren) =>
|
|
16
|
-
declare function useToken(): string | null;
|
|
17
|
-
declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
|
|
8
|
+
}) => ({ children }: PropsWithChildren) => react__default.JSX.Element;
|
|
18
9
|
declare const tokenContext: (token?: string | null) => {
|
|
19
10
|
headers: {
|
|
20
11
|
authorization: string;
|
|
@@ -24,4 +15,4 @@ declare const tokenContext: (token?: string | null) => {
|
|
|
24
15
|
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
16
|
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
17
|
|
|
27
|
-
export {
|
|
18
|
+
export { getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
|
|
@@ -11,48 +11,27 @@ 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
|
|
22
|
-
|
|
23
|
-
setToken: () => null
|
|
24
|
-
});
|
|
25
|
-
var getApolloWrapper = ({
|
|
26
|
-
graphqlUri,
|
|
27
|
-
cacheConfig,
|
|
28
|
-
authEndpoint
|
|
20
|
+
var getApolloWrapper = (endpoint, {
|
|
21
|
+
cacheConfig
|
|
29
22
|
}) => {
|
|
30
23
|
function makeClient() {
|
|
31
24
|
return new ApolloClient({
|
|
32
25
|
cache: new InMemoryCache(cacheConfig),
|
|
33
26
|
link: new HttpLink({
|
|
34
|
-
uri:
|
|
27
|
+
uri: endpoint
|
|
35
28
|
})
|
|
36
29
|
});
|
|
37
30
|
}
|
|
38
31
|
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));
|
|
32
|
+
return /* @__PURE__ */ React.createElement(ApolloNextAppProvider, { makeClient }, children);
|
|
46
33
|
};
|
|
47
34
|
};
|
|
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
35
|
var tokenContext = (token) => {
|
|
57
36
|
if (!token) return void 0;
|
|
58
37
|
return {
|
|
@@ -64,25 +43,25 @@ var tokenContext = (token) => {
|
|
|
64
43
|
};
|
|
65
44
|
function useAuthQuery(query, variables) {
|
|
66
45
|
const token = useToken();
|
|
67
|
-
const [
|
|
46
|
+
const [fetch, result] = useLazyQuery(query);
|
|
68
47
|
const [calledVars, setCalledVars] = useState();
|
|
69
48
|
useEffect(() => {
|
|
70
49
|
if (token && variables && calledVars !== JSON.stringify(variables)) {
|
|
71
50
|
setCalledVars(JSON.stringify(variables));
|
|
72
|
-
void
|
|
51
|
+
void fetch({
|
|
73
52
|
variables,
|
|
74
53
|
context: tokenContext(token),
|
|
75
54
|
fetchPolicy: "no-cache"
|
|
76
55
|
});
|
|
77
56
|
}
|
|
78
|
-
}, [
|
|
57
|
+
}, [fetch, token, variables, calledVars]);
|
|
79
58
|
const reFetch = useCallback(
|
|
80
|
-
(v) =>
|
|
59
|
+
(v) => fetch({
|
|
81
60
|
variables: v,
|
|
82
61
|
context: tokenContext(token),
|
|
83
62
|
fetchPolicy: "no-cache"
|
|
84
63
|
}),
|
|
85
|
-
[
|
|
64
|
+
[fetch, token]
|
|
86
65
|
);
|
|
87
66
|
return [reFetch, result];
|
|
88
67
|
}
|
|
@@ -99,11 +78,8 @@ function useAuthMutation(mutation, options) {
|
|
|
99
78
|
return [method, result];
|
|
100
79
|
}
|
|
101
80
|
export {
|
|
102
|
-
TokenContext,
|
|
103
81
|
getApolloWrapper,
|
|
104
82
|
tokenContext,
|
|
105
83
|
useAuthMutation,
|
|
106
|
-
useAuthQuery
|
|
107
|
-
useSetToken,
|
|
108
|
-
useToken
|
|
84
|
+
useAuthQuery
|
|
109
85
|
};
|
package/dist/graphql/init.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ declare function initGraphQLServer({ authChecker, resolvers, plugins, getContext
|
|
|
6
6
|
authChecker?: AuthChecker<any>;
|
|
7
7
|
resolvers: NonEmptyArray<Function>;
|
|
8
8
|
plugins?: ApolloServerPlugin[];
|
|
9
|
-
getContext?: (req: NextRequest) => Promise<any
|
|
9
|
+
getContext?: (req: NextRequest) => Promise<any> | any;
|
|
10
10
|
}): Promise<{
|
|
11
11
|
GET: (request: NextRequest) => Promise<Response>;
|
|
12
12
|
POST: (request: NextRequest) => Promise<Response>;
|
package/dist/graphql/init.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare function initGraphQLServer({ authChecker, resolvers, plugins, getContext
|
|
|
6
6
|
authChecker?: AuthChecker<any>;
|
|
7
7
|
resolvers: NonEmptyArray<Function>;
|
|
8
8
|
plugins?: ApolloServerPlugin[];
|
|
9
|
-
getContext?: (req: NextRequest) => Promise<any
|
|
9
|
+
getContext?: (req: NextRequest) => Promise<any> | any;
|
|
10
10
|
}): Promise<{
|
|
11
11
|
GET: (request: NextRequest) => Promise<Response>;
|
|
12
12
|
POST: (request: NextRequest) => Promise<Response>;
|
|
@@ -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?: {
|