naystack 1.4.16 → 1.4.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 +27 -12
- package/dist/auth/email/client.esm.js +27 -12
- package/dist/auth/email/index.cjs.js +32 -15
- package/dist/auth/email/index.esm.js +32 -15
- package/dist/auth/email/routes/delete.cjs.js +14 -4
- package/dist/auth/email/routes/delete.esm.js +14 -4
- package/dist/auth/email/routes/get.cjs.js +12 -2
- package/dist/auth/email/routes/get.esm.js +12 -2
- package/dist/auth/email/routes/post.cjs.js +17 -6
- package/dist/auth/email/routes/post.esm.js +17 -6
- package/dist/auth/email/routes/put.cjs.js +12 -4
- package/dist/auth/email/routes/put.esm.js +12 -4
- package/dist/auth/email/token.cjs.js +9 -2
- package/dist/auth/email/token.esm.js +9 -2
- package/dist/auth/email/types.d.mts +1 -7
- package/dist/auth/email/types.d.ts +1 -7
- package/dist/auth/email/utils.cjs.js +16 -5
- package/dist/auth/email/utils.d.mts +2 -2
- package/dist/auth/email/utils.d.ts +2 -2
- package/dist/auth/email/utils.esm.js +16 -5
- package/dist/auth/google/get.cjs.js +15 -7
- package/dist/auth/google/get.d.mts +1 -3
- package/dist/auth/google/get.d.ts +1 -3
- package/dist/auth/google/get.esm.js +15 -7
- package/dist/auth/google/index.cjs.js +15 -7
- package/dist/auth/google/index.d.mts +0 -5
- package/dist/auth/google/index.d.ts +0 -5
- package/dist/auth/google/index.esm.js +15 -7
- package/dist/auth/index.cjs.js +47 -31
- package/dist/auth/index.esm.js +47 -31
- package/dist/auth/instagram/client.cjs.js +12 -1
- package/dist/auth/instagram/client.d.mts +1 -1
- package/dist/auth/instagram/client.d.ts +1 -1
- package/dist/auth/instagram/client.esm.js +10 -1
- package/dist/auth/instagram/index.cjs.js +16 -9
- package/dist/auth/instagram/index.d.mts +0 -2
- package/dist/auth/instagram/index.d.ts +0 -2
- package/dist/auth/instagram/index.esm.js +16 -9
- package/dist/auth/instagram/route.cjs.js +16 -9
- package/dist/auth/instagram/route.d.mts +1 -1
- package/dist/auth/instagram/route.d.ts +1 -1
- package/dist/auth/instagram/route.esm.js +16 -9
- package/dist/auth/instagram/utils.cjs.js +10 -1
- package/dist/auth/instagram/utils.esm.js +8 -1
- package/dist/client/index.cjs.js +8 -1
- package/dist/client/index.esm.js +8 -1
- package/dist/client/seo.cjs.js +10 -1
- package/dist/client/seo.esm.js +8 -1
- package/dist/env.cjs.js +57 -0
- package/dist/env.d.mts +23 -0
- package/dist/env.d.ts +23 -0
- package/dist/env.esm.js +31 -0
- package/dist/file/client.cjs.js +10 -1
- package/dist/file/client.esm.js +10 -1
- package/dist/file/index.cjs.js +40 -28
- package/dist/file/index.d.mts +0 -2
- package/dist/file/index.d.ts +0 -2
- package/dist/file/index.esm.js +40 -28
- package/dist/file/put.cjs.js +23 -11
- package/dist/file/put.d.mts +0 -2
- package/dist/file/put.d.ts +0 -2
- package/dist/file/put.esm.js +23 -11
- package/dist/file/setup.cjs.js +40 -28
- package/dist/file/setup.d.mts +0 -7
- package/dist/file/setup.d.ts +0 -7
- package/dist/file/setup.esm.js +40 -28
- package/dist/file/utils.cjs.js +28 -17
- package/dist/file/utils.d.mts +6 -10
- package/dist/file/utils.d.ts +6 -10
- package/dist/file/utils.esm.js +28 -17
- package/dist/graphql/client.cjs.js +15 -3
- package/dist/graphql/client.d.mts +1 -1
- package/dist/graphql/client.d.ts +1 -1
- package/dist/graphql/client.esm.js +15 -3
- package/dist/graphql/index.cjs.js +65 -3
- package/dist/graphql/index.d.mts +1 -0
- package/dist/graphql/index.d.ts +1 -0
- package/dist/graphql/index.esm.js +65 -3
- package/dist/graphql/init.cjs.js +11 -2
- package/dist/graphql/init.esm.js +11 -2
- package/dist/graphql/server.cjs.js +10 -1
- package/dist/graphql/server.esm.js +10 -1
- package/dist/graphql/utils.cjs.js +54 -1
- package/dist/graphql/utils.d.mts +10 -3
- package/dist/graphql/utils.d.ts +10 -3
- package/dist/graphql/utils.esm.js +54 -1
- package/package.json +1 -1
package/dist/file/setup.esm.js
CHANGED
|
@@ -12,6 +12,13 @@ import { cookies } from "next/headers";
|
|
|
12
12
|
import { redirect } from "next/navigation";
|
|
13
13
|
import { NextResponse } from "next/server";
|
|
14
14
|
|
|
15
|
+
// src/env.ts
|
|
16
|
+
function getEnv(key, skipCheck) {
|
|
17
|
+
const value = process.env[key];
|
|
18
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
// src/auth/constants.ts
|
|
16
23
|
var REFRESH_COOKIE_NAME = "refresh";
|
|
17
24
|
|
|
@@ -33,17 +40,20 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
33
40
|
import { NextResponse as NextResponse2 } from "next/server";
|
|
34
41
|
|
|
35
42
|
// src/auth/email/utils.ts
|
|
36
|
-
var getContext = (
|
|
43
|
+
var getContext = (req) => {
|
|
37
44
|
const bearer = req.headers.get("authorization");
|
|
38
45
|
if (!bearer) {
|
|
39
46
|
const refresh = req.cookies.get(REFRESH_COOKIE_NAME)?.value;
|
|
40
|
-
const userId = getUserIdFromRefreshToken(
|
|
47
|
+
const userId = getUserIdFromRefreshToken(
|
|
48
|
+
getEnv("REFRESH_KEY" /* REFRESH_KEY */),
|
|
49
|
+
refresh
|
|
50
|
+
);
|
|
41
51
|
if (userId) return { userId, isRefreshID: true };
|
|
42
52
|
return { userId: null };
|
|
43
53
|
}
|
|
44
54
|
const token = bearer.slice(7);
|
|
45
55
|
try {
|
|
46
|
-
const res = verify2(token,
|
|
56
|
+
const res = verify2(token, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
47
57
|
if (typeof res === "string") {
|
|
48
58
|
return { userId: null };
|
|
49
59
|
}
|
|
@@ -62,29 +72,31 @@ import {
|
|
|
62
72
|
S3Client
|
|
63
73
|
} from "@aws-sdk/client-s3";
|
|
64
74
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
65
|
-
var getS3Client = (
|
|
66
|
-
region:
|
|
75
|
+
var getS3Client = () => new S3Client({
|
|
76
|
+
region: getEnv("AWS_REGION" /* AWS_REGION */),
|
|
67
77
|
credentials: {
|
|
68
|
-
accessKeyId:
|
|
69
|
-
secretAccessKey:
|
|
78
|
+
accessKeyId: getEnv("AWS_ACCESS_KEY_ID" /* AWS_ACCESS_KEY_ID */),
|
|
79
|
+
secretAccessKey: getEnv("AWS_ACCESS_KEY_SECRET" /* AWS_ACCESS_KEY_SECRET */)
|
|
70
80
|
}
|
|
71
81
|
});
|
|
72
|
-
var
|
|
82
|
+
var URL_PREFIX = `https://${getEnv("AWS_BUCKET" /* AWS_BUCKET */)}.s3.${getEnv(
|
|
83
|
+
"AWS_REGION" /* AWS_REGION */
|
|
84
|
+
)}.amazonaws.com/`;
|
|
73
85
|
function getKey(keys) {
|
|
74
86
|
return typeof keys === "string" ? keys : keys.join("/");
|
|
75
87
|
}
|
|
76
|
-
var getUploadURL = (client
|
|
88
|
+
var getUploadURL = (client) => (keys) => {
|
|
77
89
|
const command = new PutObjectCommand({
|
|
78
|
-
Bucket,
|
|
90
|
+
Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
|
|
79
91
|
Key: getKey(keys),
|
|
80
92
|
ACL: "public-read"
|
|
81
93
|
});
|
|
82
94
|
return getSignedUrl(client, command, { expiresIn: 300 });
|
|
83
95
|
};
|
|
84
|
-
var getDownloadURL = (
|
|
85
|
-
return `${
|
|
96
|
+
var getDownloadURL = (keys) => {
|
|
97
|
+
return `${URL_PREFIX}${getKey(keys)}`;
|
|
86
98
|
};
|
|
87
|
-
var uploadFile = (client
|
|
99
|
+
var uploadFile = (client) => async (keys, {
|
|
88
100
|
url,
|
|
89
101
|
blob
|
|
90
102
|
}) => {
|
|
@@ -92,18 +104,18 @@ var uploadFile = (client, options) => async (keys, {
|
|
|
92
104
|
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
93
105
|
if (fileBlob) {
|
|
94
106
|
const key = getKey(keys);
|
|
95
|
-
await uploadBlob(client
|
|
96
|
-
return getDownloadURL(
|
|
107
|
+
await uploadBlob(client)(fileBlob, key);
|
|
108
|
+
return getDownloadURL(key);
|
|
97
109
|
}
|
|
98
110
|
return null;
|
|
99
111
|
};
|
|
100
|
-
var deleteFile = (client
|
|
101
|
-
const key = url.split(
|
|
112
|
+
var deleteFile = (client) => async (url) => {
|
|
113
|
+
const key = url.split(URL_PREFIX)[1];
|
|
102
114
|
if (key) {
|
|
103
115
|
try {
|
|
104
116
|
await client.send(
|
|
105
117
|
new DeleteObjectCommand({
|
|
106
|
-
Bucket:
|
|
118
|
+
Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
|
|
107
119
|
Key: key
|
|
108
120
|
})
|
|
109
121
|
);
|
|
@@ -114,11 +126,11 @@ var deleteFile = (client, options) => async (url) => {
|
|
|
114
126
|
}
|
|
115
127
|
return false;
|
|
116
128
|
};
|
|
117
|
-
var uploadBlob = (client
|
|
129
|
+
var uploadBlob = (client) => async (file, key) => {
|
|
118
130
|
const fileBuffer = await file.arrayBuffer();
|
|
119
131
|
return client.send(
|
|
120
132
|
new PutObjectCommand({
|
|
121
|
-
Bucket,
|
|
133
|
+
Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
|
|
122
134
|
Key: key,
|
|
123
135
|
ACL: "public-read",
|
|
124
136
|
Body: Buffer.from(fileBuffer),
|
|
@@ -130,7 +142,7 @@ var uploadBlob = (client, Bucket) => async (file, key) => {
|
|
|
130
142
|
|
|
131
143
|
// src/file/put.ts
|
|
132
144
|
var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
133
|
-
const ctx = getContext(
|
|
145
|
+
const ctx = getContext(req);
|
|
134
146
|
if (!ctx?.userId || ctx.isRefreshID)
|
|
135
147
|
return NextResponse3.json({ error: "unauthorized" }, { status: 401 });
|
|
136
148
|
const formData = await req.formData();
|
|
@@ -143,8 +155,8 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
143
155
|
data: typeof data === "string" ? JSON.parse(data) : void 0
|
|
144
156
|
};
|
|
145
157
|
const fileKey = options.getKey ? await options.getKey(inputData) : v4();
|
|
146
|
-
const url = getDownloadURL(
|
|
147
|
-
await uploadBlob(client
|
|
158
|
+
const url = getDownloadURL(fileKey);
|
|
159
|
+
await uploadBlob(client)(file, fileKey);
|
|
148
160
|
const onUploadResponse = await options.onUpload({
|
|
149
161
|
...inputData,
|
|
150
162
|
url
|
|
@@ -157,13 +169,13 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
157
169
|
|
|
158
170
|
// src/file/setup.ts
|
|
159
171
|
function setupFileUpload(options) {
|
|
160
|
-
const client = getS3Client(
|
|
172
|
+
const client = getS3Client();
|
|
161
173
|
return {
|
|
162
174
|
PUT: getFileUploadPutRoute(options, client),
|
|
163
|
-
uploadFile: uploadFile(client
|
|
164
|
-
deleteFile: deleteFile(client
|
|
165
|
-
getUploadURL: getUploadURL(client
|
|
166
|
-
getDownloadURL
|
|
175
|
+
uploadFile: uploadFile(client),
|
|
176
|
+
deleteFile: deleteFile(client),
|
|
177
|
+
getUploadURL: getUploadURL(client),
|
|
178
|
+
getDownloadURL
|
|
167
179
|
};
|
|
168
180
|
}
|
|
169
181
|
export {
|
package/dist/file/utils.cjs.js
CHANGED
|
@@ -30,29 +30,40 @@ __export(utils_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(utils_exports);
|
|
31
31
|
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
32
32
|
var import_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
|
|
34
|
+
// src/env.ts
|
|
35
|
+
function getEnv(key, skipCheck) {
|
|
36
|
+
const value = process.env[key];
|
|
37
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/file/utils.ts
|
|
42
|
+
var getS3Client = () => new import_client_s3.S3Client({
|
|
43
|
+
region: getEnv("AWS_REGION" /* AWS_REGION */),
|
|
35
44
|
credentials: {
|
|
36
|
-
accessKeyId:
|
|
37
|
-
secretAccessKey:
|
|
45
|
+
accessKeyId: getEnv("AWS_ACCESS_KEY_ID" /* AWS_ACCESS_KEY_ID */),
|
|
46
|
+
secretAccessKey: getEnv("AWS_ACCESS_KEY_SECRET" /* AWS_ACCESS_KEY_SECRET */)
|
|
38
47
|
}
|
|
39
48
|
});
|
|
40
|
-
var
|
|
49
|
+
var URL_PREFIX = `https://${getEnv("AWS_BUCKET" /* AWS_BUCKET */)}.s3.${getEnv(
|
|
50
|
+
"AWS_REGION" /* AWS_REGION */
|
|
51
|
+
)}.amazonaws.com/`;
|
|
41
52
|
function getKey(keys) {
|
|
42
53
|
return typeof keys === "string" ? keys : keys.join("/");
|
|
43
54
|
}
|
|
44
|
-
var getUploadURL = (client
|
|
55
|
+
var getUploadURL = (client) => (keys) => {
|
|
45
56
|
const command = new import_client_s3.PutObjectCommand({
|
|
46
|
-
Bucket,
|
|
57
|
+
Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
|
|
47
58
|
Key: getKey(keys),
|
|
48
59
|
ACL: "public-read"
|
|
49
60
|
});
|
|
50
61
|
return (0, import_s3_request_presigner.getSignedUrl)(client, command, { expiresIn: 300 });
|
|
51
62
|
};
|
|
52
|
-
var getDownloadURL = (
|
|
53
|
-
return `${
|
|
63
|
+
var getDownloadURL = (keys) => {
|
|
64
|
+
return `${URL_PREFIX}${getKey(keys)}`;
|
|
54
65
|
};
|
|
55
|
-
var uploadFile = (client
|
|
66
|
+
var uploadFile = (client) => async (keys, {
|
|
56
67
|
url,
|
|
57
68
|
blob
|
|
58
69
|
}) => {
|
|
@@ -60,18 +71,18 @@ var uploadFile = (client, options) => async (keys, {
|
|
|
60
71
|
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
61
72
|
if (fileBlob) {
|
|
62
73
|
const key = getKey(keys);
|
|
63
|
-
await uploadBlob(client
|
|
64
|
-
return getDownloadURL(
|
|
74
|
+
await uploadBlob(client)(fileBlob, key);
|
|
75
|
+
return getDownloadURL(key);
|
|
65
76
|
}
|
|
66
77
|
return null;
|
|
67
78
|
};
|
|
68
|
-
var deleteFile = (client
|
|
69
|
-
const key = url.split(
|
|
79
|
+
var deleteFile = (client) => async (url) => {
|
|
80
|
+
const key = url.split(URL_PREFIX)[1];
|
|
70
81
|
if (key) {
|
|
71
82
|
try {
|
|
72
83
|
await client.send(
|
|
73
84
|
new import_client_s3.DeleteObjectCommand({
|
|
74
|
-
Bucket:
|
|
85
|
+
Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
|
|
75
86
|
Key: key
|
|
76
87
|
})
|
|
77
88
|
);
|
|
@@ -82,11 +93,11 @@ var deleteFile = (client, options) => async (url) => {
|
|
|
82
93
|
}
|
|
83
94
|
return false;
|
|
84
95
|
};
|
|
85
|
-
var uploadBlob = (client
|
|
96
|
+
var uploadBlob = (client) => async (file, key) => {
|
|
86
97
|
const fileBuffer = await file.arrayBuffer();
|
|
87
98
|
return client.send(
|
|
88
99
|
new import_client_s3.PutObjectCommand({
|
|
89
|
-
Bucket,
|
|
100
|
+
Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
|
|
90
101
|
Key: key,
|
|
91
102
|
ACL: "public-read",
|
|
92
103
|
Body: Buffer.from(fileBuffer),
|
package/dist/file/utils.d.mts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import * as _aws_sdk_client_s3 from '@aws-sdk/client-s3';
|
|
2
2
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
3
|
-
import { SetupFileUploadOptions } from './setup.mjs';
|
|
4
|
-
import 'next/server';
|
|
5
|
-
import '../auth/email/types.mjs';
|
|
6
|
-
import '../auth/types.mjs';
|
|
7
3
|
|
|
8
|
-
declare const getS3Client: (
|
|
9
|
-
declare const getUploadURL: (client: S3Client
|
|
10
|
-
declare const getDownloadURL: (
|
|
11
|
-
declare const uploadFile: (client: S3Client
|
|
4
|
+
declare const getS3Client: () => S3Client;
|
|
5
|
+
declare const getUploadURL: (client: S3Client) => (keys: string | string[]) => Promise<string>;
|
|
6
|
+
declare const getDownloadURL: (keys: string | string[]) => string;
|
|
7
|
+
declare const uploadFile: (client: S3Client) => (keys: string | string[], { url, blob, }: {
|
|
12
8
|
blob?: Blob;
|
|
13
9
|
url?: string;
|
|
14
10
|
}) => Promise<string | null>;
|
|
15
|
-
declare const deleteFile: (client: S3Client
|
|
16
|
-
declare const uploadBlob: (client: S3Client
|
|
11
|
+
declare const deleteFile: (client: S3Client) => (url: string) => Promise<boolean>;
|
|
12
|
+
declare const uploadBlob: (client: S3Client) => (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
|
|
17
13
|
|
|
18
14
|
export { deleteFile, getDownloadURL, getS3Client, getUploadURL, uploadBlob, uploadFile };
|
package/dist/file/utils.d.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import * as _aws_sdk_client_s3 from '@aws-sdk/client-s3';
|
|
2
2
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
3
|
-
import { SetupFileUploadOptions } from './setup.js';
|
|
4
|
-
import 'next/server';
|
|
5
|
-
import '../auth/email/types.js';
|
|
6
|
-
import '../auth/types.js';
|
|
7
3
|
|
|
8
|
-
declare const getS3Client: (
|
|
9
|
-
declare const getUploadURL: (client: S3Client
|
|
10
|
-
declare const getDownloadURL: (
|
|
11
|
-
declare const uploadFile: (client: S3Client
|
|
4
|
+
declare const getS3Client: () => S3Client;
|
|
5
|
+
declare const getUploadURL: (client: S3Client) => (keys: string | string[]) => Promise<string>;
|
|
6
|
+
declare const getDownloadURL: (keys: string | string[]) => string;
|
|
7
|
+
declare const uploadFile: (client: S3Client) => (keys: string | string[], { url, blob, }: {
|
|
12
8
|
blob?: Blob;
|
|
13
9
|
url?: string;
|
|
14
10
|
}) => Promise<string | null>;
|
|
15
|
-
declare const deleteFile: (client: S3Client
|
|
16
|
-
declare const uploadBlob: (client: S3Client
|
|
11
|
+
declare const deleteFile: (client: S3Client) => (url: string) => Promise<boolean>;
|
|
12
|
+
declare const uploadBlob: (client: S3Client) => (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
|
|
17
13
|
|
|
18
14
|
export { deleteFile, getDownloadURL, getS3Client, getUploadURL, uploadBlob, uploadFile };
|
package/dist/file/utils.esm.js
CHANGED
|
@@ -5,29 +5,40 @@ import {
|
|
|
5
5
|
S3Client
|
|
6
6
|
} from "@aws-sdk/client-s3";
|
|
7
7
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
// src/env.ts
|
|
10
|
+
function getEnv(key, skipCheck) {
|
|
11
|
+
const value = process.env[key];
|
|
12
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/file/utils.ts
|
|
17
|
+
var getS3Client = () => new S3Client({
|
|
18
|
+
region: getEnv("AWS_REGION" /* AWS_REGION */),
|
|
10
19
|
credentials: {
|
|
11
|
-
accessKeyId:
|
|
12
|
-
secretAccessKey:
|
|
20
|
+
accessKeyId: getEnv("AWS_ACCESS_KEY_ID" /* AWS_ACCESS_KEY_ID */),
|
|
21
|
+
secretAccessKey: getEnv("AWS_ACCESS_KEY_SECRET" /* AWS_ACCESS_KEY_SECRET */)
|
|
13
22
|
}
|
|
14
23
|
});
|
|
15
|
-
var
|
|
24
|
+
var URL_PREFIX = `https://${getEnv("AWS_BUCKET" /* AWS_BUCKET */)}.s3.${getEnv(
|
|
25
|
+
"AWS_REGION" /* AWS_REGION */
|
|
26
|
+
)}.amazonaws.com/`;
|
|
16
27
|
function getKey(keys) {
|
|
17
28
|
return typeof keys === "string" ? keys : keys.join("/");
|
|
18
29
|
}
|
|
19
|
-
var getUploadURL = (client
|
|
30
|
+
var getUploadURL = (client) => (keys) => {
|
|
20
31
|
const command = new PutObjectCommand({
|
|
21
|
-
Bucket,
|
|
32
|
+
Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
|
|
22
33
|
Key: getKey(keys),
|
|
23
34
|
ACL: "public-read"
|
|
24
35
|
});
|
|
25
36
|
return getSignedUrl(client, command, { expiresIn: 300 });
|
|
26
37
|
};
|
|
27
|
-
var getDownloadURL = (
|
|
28
|
-
return `${
|
|
38
|
+
var getDownloadURL = (keys) => {
|
|
39
|
+
return `${URL_PREFIX}${getKey(keys)}`;
|
|
29
40
|
};
|
|
30
|
-
var uploadFile = (client
|
|
41
|
+
var uploadFile = (client) => async (keys, {
|
|
31
42
|
url,
|
|
32
43
|
blob
|
|
33
44
|
}) => {
|
|
@@ -35,18 +46,18 @@ var uploadFile = (client, options) => async (keys, {
|
|
|
35
46
|
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
36
47
|
if (fileBlob) {
|
|
37
48
|
const key = getKey(keys);
|
|
38
|
-
await uploadBlob(client
|
|
39
|
-
return getDownloadURL(
|
|
49
|
+
await uploadBlob(client)(fileBlob, key);
|
|
50
|
+
return getDownloadURL(key);
|
|
40
51
|
}
|
|
41
52
|
return null;
|
|
42
53
|
};
|
|
43
|
-
var deleteFile = (client
|
|
44
|
-
const key = url.split(
|
|
54
|
+
var deleteFile = (client) => async (url) => {
|
|
55
|
+
const key = url.split(URL_PREFIX)[1];
|
|
45
56
|
if (key) {
|
|
46
57
|
try {
|
|
47
58
|
await client.send(
|
|
48
59
|
new DeleteObjectCommand({
|
|
49
|
-
Bucket:
|
|
60
|
+
Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
|
|
50
61
|
Key: key
|
|
51
62
|
})
|
|
52
63
|
);
|
|
@@ -57,11 +68,11 @@ var deleteFile = (client, options) => async (url) => {
|
|
|
57
68
|
}
|
|
58
69
|
return false;
|
|
59
70
|
};
|
|
60
|
-
var uploadBlob = (client
|
|
71
|
+
var uploadBlob = (client) => async (file, key) => {
|
|
61
72
|
const fileBuffer = await file.arrayBuffer();
|
|
62
73
|
return client.send(
|
|
63
74
|
new PutObjectCommand({
|
|
64
|
-
Bucket,
|
|
75
|
+
Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
|
|
65
76
|
Key: key,
|
|
66
77
|
ACL: "public-read",
|
|
67
78
|
Body: Buffer.from(fileBuffer),
|
|
@@ -41,12 +41,24 @@ var import_client = require("@apollo/client");
|
|
|
41
41
|
var import_client_integration_nextjs = require("@apollo/client-integration-nextjs");
|
|
42
42
|
var import_client2 = require("naystack/auth/email/client");
|
|
43
43
|
var import_react = __toESM(require("react"));
|
|
44
|
-
|
|
44
|
+
|
|
45
|
+
// src/env.ts
|
|
46
|
+
function getEnv(key, skipCheck) {
|
|
47
|
+
const value = process.env[key];
|
|
48
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/graphql/client.tsx
|
|
53
|
+
var ApolloWrapper = ({
|
|
54
|
+
children,
|
|
55
|
+
cacheConfig
|
|
56
|
+
}) => {
|
|
45
57
|
function makeClient() {
|
|
46
58
|
return new import_client_integration_nextjs.ApolloClient({
|
|
47
59
|
cache: new import_client_integration_nextjs.InMemoryCache(cacheConfig),
|
|
48
60
|
link: new import_client.HttpLink({
|
|
49
|
-
uri:
|
|
61
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
50
62
|
})
|
|
51
63
|
});
|
|
52
64
|
}
|
|
@@ -90,7 +102,7 @@ function useAuthMutation(mutation, options) {
|
|
|
90
102
|
const [mutate, result] = (0, import_client.useMutation)(mutation, options);
|
|
91
103
|
const method = (0, import_react.useCallback)(
|
|
92
104
|
(input) => mutate({
|
|
93
|
-
// @ts-
|
|
105
|
+
// @ts-expect-error -- to allow dynamic props
|
|
94
106
|
variables: { input },
|
|
95
107
|
context: tokenContext(token)
|
|
96
108
|
}),
|
|
@@ -3,7 +3,7 @@ import { InMemoryCacheConfig, OperationVariables, MutationHookOptions } from '@a
|
|
|
3
3
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
4
|
import React__default, { PropsWithChildren } from 'react';
|
|
5
5
|
|
|
6
|
-
declare const ApolloWrapper: ({ children, cacheConfig }: PropsWithChildren<{
|
|
6
|
+
declare const ApolloWrapper: ({ children, cacheConfig, }: PropsWithChildren<{
|
|
7
7
|
cacheConfig?: InMemoryCacheConfig;
|
|
8
8
|
}>) => React__default.JSX.Element;
|
|
9
9
|
declare const tokenContext: (token?: string | null) => {
|
package/dist/graphql/client.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { InMemoryCacheConfig, OperationVariables, MutationHookOptions } from '@a
|
|
|
3
3
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
4
4
|
import React__default, { PropsWithChildren } from 'react';
|
|
5
5
|
|
|
6
|
-
declare const ApolloWrapper: ({ children, cacheConfig }: PropsWithChildren<{
|
|
6
|
+
declare const ApolloWrapper: ({ children, cacheConfig, }: PropsWithChildren<{
|
|
7
7
|
cacheConfig?: InMemoryCacheConfig;
|
|
8
8
|
}>) => React__default.JSX.Element;
|
|
9
9
|
declare const tokenContext: (token?: string | null) => {
|
|
@@ -17,12 +17,24 @@ import React, {
|
|
|
17
17
|
useEffect,
|
|
18
18
|
useState
|
|
19
19
|
} from "react";
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
// src/env.ts
|
|
22
|
+
function getEnv(key, skipCheck) {
|
|
23
|
+
const value = process.env[key];
|
|
24
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/graphql/client.tsx
|
|
29
|
+
var ApolloWrapper = ({
|
|
30
|
+
children,
|
|
31
|
+
cacheConfig
|
|
32
|
+
}) => {
|
|
21
33
|
function makeClient() {
|
|
22
34
|
return new ApolloClient({
|
|
23
35
|
cache: new InMemoryCache(cacheConfig),
|
|
24
36
|
link: new HttpLink({
|
|
25
|
-
uri:
|
|
37
|
+
uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
|
|
26
38
|
})
|
|
27
39
|
});
|
|
28
40
|
}
|
|
@@ -66,7 +78,7 @@ function useAuthMutation(mutation, options) {
|
|
|
66
78
|
const [mutate, result] = useMutation(mutation, options);
|
|
67
79
|
const method = useCallback(
|
|
68
80
|
(input) => mutate({
|
|
69
|
-
// @ts-
|
|
81
|
+
// @ts-expect-error -- to allow dynamic props
|
|
70
82
|
variables: { input },
|
|
71
83
|
context: tokenContext(token)
|
|
72
84
|
}),
|
|
@@ -575,6 +575,15 @@ var import_server = require("@apollo/server");
|
|
|
575
575
|
var import_default = require("@apollo/server/plugin/landingPage/default");
|
|
576
576
|
var import_next = require("@as-integrations/next");
|
|
577
577
|
var import_type_graphql = require("type-graphql");
|
|
578
|
+
|
|
579
|
+
// src/env.ts
|
|
580
|
+
function getEnv(key, skipCheck) {
|
|
581
|
+
const value = process.env[key];
|
|
582
|
+
if (!skipCheck && !value) throw new Error(`${key} is not defined`);
|
|
583
|
+
return value;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/graphql/init.ts
|
|
578
587
|
async function initGraphQLServer({
|
|
579
588
|
authChecker,
|
|
580
589
|
resolvers,
|
|
@@ -590,7 +599,7 @@ async function initGraphQLServer({
|
|
|
590
599
|
typeDefs,
|
|
591
600
|
resolvers: builtResolvers,
|
|
592
601
|
plugins: [
|
|
593
|
-
|
|
602
|
+
getEnv("NODE_ENV" /* NODE_ENV */, true) === "production" ? (0, import_default.ApolloServerPluginLandingPageProductionDefault)() : (0, import_default.ApolloServerPluginLandingPageLocalDefault)(),
|
|
594
603
|
{
|
|
595
604
|
async requestDidStart({ request, contextValue }) {
|
|
596
605
|
if (contextValue.isRefreshID && !request.query?.startsWith("query"))
|
|
@@ -599,7 +608,7 @@ async function initGraphQLServer({
|
|
|
599
608
|
},
|
|
600
609
|
...plugins || []
|
|
601
610
|
],
|
|
602
|
-
introspection:
|
|
611
|
+
introspection: getEnv("NODE_ENV" /* NODE_ENV */, true) !== "production",
|
|
603
612
|
status400ForVariableCoercionErrors: true
|
|
604
613
|
});
|
|
605
614
|
const handler = (0, import_next.startServerAndCreateNextHandler)(server, {
|
|
@@ -612,9 +621,62 @@ async function initGraphQLServer({
|
|
|
612
621
|
}
|
|
613
622
|
|
|
614
623
|
// src/graphql/utils.ts
|
|
624
|
+
var import_cache = require("next/cache");
|
|
625
|
+
var import_headers2 = require("next/headers");
|
|
615
626
|
var import_type_graphql2 = require("type-graphql");
|
|
627
|
+
|
|
628
|
+
// src/auth/constants.ts
|
|
629
|
+
var REFRESH_COOKIE_NAME = "refresh";
|
|
630
|
+
|
|
631
|
+
// src/auth/email/token.ts
|
|
632
|
+
var import_bcryptjs = require("bcryptjs");
|
|
633
|
+
var import_jsonwebtoken = require("jsonwebtoken");
|
|
634
|
+
var import_headers = require("next/headers");
|
|
635
|
+
var import_navigation = require("next/navigation");
|
|
636
|
+
var import_server2 = require("next/server");
|
|
637
|
+
function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
638
|
+
if (refreshToken)
|
|
639
|
+
try {
|
|
640
|
+
const decoded = (0, import_jsonwebtoken.verify)(refreshToken, refreshKey);
|
|
641
|
+
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
642
|
+
return decoded.id;
|
|
643
|
+
} catch (e) {
|
|
644
|
+
if (!(e instanceof import_jsonwebtoken.JsonWebTokenError)) console.error(e, "errors");
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// src/graphql/utils.ts
|
|
616
651
|
function query(fn, options) {
|
|
617
|
-
return { ...options, fn };
|
|
652
|
+
return { ...options, fn, call: getCaller(fn, options) };
|
|
653
|
+
}
|
|
654
|
+
var getUserId = async () => {
|
|
655
|
+
const Cookie = await (0, import_headers2.cookies)();
|
|
656
|
+
const refresh = Cookie.get(REFRESH_COOKIE_NAME)?.value;
|
|
657
|
+
return refresh ? getUserIdFromRefreshToken(refresh) : null;
|
|
658
|
+
};
|
|
659
|
+
function getCaller(fn, options) {
|
|
660
|
+
return async (data, config) => {
|
|
661
|
+
if (config?.revalidate) {
|
|
662
|
+
const cachedFn = (data2, config2) => {
|
|
663
|
+
"use cache";
|
|
664
|
+
if (config2?.revalidate) (0, import_cache.cacheLife)(config2.revalidate);
|
|
665
|
+
if (config2?.tags) (0, import_cache.cacheTag)(...config2.tags);
|
|
666
|
+
const ctx2 = {
|
|
667
|
+
userId: null,
|
|
668
|
+
isRefreshID: true
|
|
669
|
+
};
|
|
670
|
+
return fn(ctx2, data2);
|
|
671
|
+
};
|
|
672
|
+
return cachedFn(data, config);
|
|
673
|
+
}
|
|
674
|
+
const ctx = {
|
|
675
|
+
userId: options.authorized ? await getUserId() : null,
|
|
676
|
+
isRefreshID: true
|
|
677
|
+
};
|
|
678
|
+
return fn(ctx, data);
|
|
679
|
+
};
|
|
618
680
|
}
|
|
619
681
|
function field(fn, options) {
|
|
620
682
|
return { ...options, fn };
|
package/dist/graphql/index.d.mts
CHANGED
package/dist/graphql/index.d.ts
CHANGED