naystack 1.1.13-beta.2 → 1.1.13-beta.4
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/index.d.mts +0 -1
- package/dist/auth/index.d.ts +0 -1
- package/dist/auth/instagram/{client-utils.cjs.js → client.cjs.js} +7 -8
- package/dist/auth/instagram/client.d.mts +3 -0
- package/dist/auth/instagram/client.d.ts +3 -0
- package/dist/auth/instagram/client.esm.js +5 -0
- package/dist/auth/instagram/index.cjs.js +0 -5
- 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 +0 -4
- package/dist/auth/instagram/route.d.mts +0 -1
- package/dist/auth/instagram/route.d.ts +0 -1
- package/dist/client/hooks.cjs.js +0 -1
- package/dist/client/hooks.esm.js +0 -2
- package/dist/client/index.cjs.js +31 -0
- package/dist/client/index.d.mts +2 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.esm.js +29 -0
- package/dist/file/client.cjs.js +51 -0
- package/dist/file/client.d.mts +13 -0
- package/dist/file/client.d.ts +13 -0
- package/dist/file/client.esm.js +26 -0
- package/dist/file/index.cjs.js +195 -0
- package/dist/file/index.d.mts +3 -0
- package/dist/file/index.d.ts +3 -0
- package/dist/file/index.esm.js +172 -0
- package/dist/file/put.cjs.js +157 -0
- package/dist/file/put.d.mts +11 -0
- package/dist/file/put.d.ts +11 -0
- package/dist/file/put.esm.js +136 -0
- package/dist/file/setup.cjs.js +195 -0
- package/dist/file/setup.d.mts +34 -0
- package/dist/file/setup.d.ts +34 -0
- package/dist/file/setup.esm.js +172 -0
- package/dist/file/utils.cjs.js +104 -0
- package/dist/file/utils.d.mts +13 -0
- package/dist/file/utils.d.ts +13 -0
- package/dist/file/utils.esm.js +78 -0
- package/package.json +8 -1
- package/dist/auth/instagram/client-utils.d.mts +0 -3
- package/dist/auth/instagram/client-utils.d.ts +0 -3
- package/dist/auth/instagram/client-utils.esm.js +0 -7
package/dist/auth/index.d.mts
CHANGED
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
"use client";
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -18,14 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
17
|
};
|
|
19
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
19
|
|
|
21
|
-
// src/auth/instagram/client
|
|
22
|
-
var
|
|
23
|
-
__export(
|
|
24
|
-
|
|
20
|
+
// src/auth/instagram/client.ts
|
|
21
|
+
var client_exports = {};
|
|
22
|
+
__export(client_exports, {
|
|
23
|
+
getInstagramAuthorizationURLSetup: () => getInstagramAuthorizationURLSetup
|
|
25
24
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
27
|
-
var
|
|
25
|
+
module.exports = __toCommonJS(client_exports);
|
|
26
|
+
var getInstagramAuthorizationURLSetup = (clientId, redirectURL) => (token) => `https://www.instagram.com/oauth/authorize?client_id=${clientId}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${redirectURL}`;
|
|
28
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
28
|
0 && (module.exports = {
|
|
30
|
-
|
|
29
|
+
getInstagramAuthorizationURLSetup
|
|
31
30
|
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// src/auth/instagram/client.ts
|
|
2
|
+
var getInstagramAuthorizationURLSetup = (clientId, redirectURL) => (token) => `https://www.instagram.com/oauth/authorize?client_id=${clientId}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${redirectURL}`;
|
|
3
|
+
export {
|
|
4
|
+
getInstagramAuthorizationURLSetup
|
|
5
|
+
};
|
|
@@ -20,7 +20,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/auth/instagram/index.ts
|
|
21
21
|
var instagram_exports = {};
|
|
22
22
|
__export(instagram_exports, {
|
|
23
|
-
getInstagramAuthorizationURL: () => getInstagramAuthorizationURL,
|
|
24
23
|
initInstagramAuth: () => initInstagramAuth
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(instagram_exports);
|
|
@@ -144,9 +143,6 @@ var getInstagramRoute = ({
|
|
|
144
143
|
};
|
|
145
144
|
};
|
|
146
145
|
|
|
147
|
-
// src/auth/instagram/client-utils.ts
|
|
148
|
-
var getInstagramAuthorizationURL = (clientId, authRoute) => (token) => `https://www.instagram.com/oauth/authorize?client_id=${clientId}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${authRoute}`;
|
|
149
|
-
|
|
150
146
|
// src/auth/instagram/index.ts
|
|
151
147
|
function initInstagramAuth(props) {
|
|
152
148
|
return {
|
|
@@ -156,6 +152,5 @@ function initInstagramAuth(props) {
|
|
|
156
152
|
}
|
|
157
153
|
// Annotate the CommonJS export names for ESM import in node:
|
|
158
154
|
0 && (module.exports = {
|
|
159
|
-
getInstagramAuthorizationURL,
|
|
160
155
|
initInstagramAuth
|
|
161
156
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
2
|
import { getRefreshedAccessToken } from './utils.mjs';
|
|
3
3
|
import { InstagramUser } from '../../socials/instagram/types.mjs';
|
|
4
|
-
export { getInstagramAuthorizationURL } from './client-utils.mjs';
|
|
5
4
|
|
|
6
5
|
interface InitInstagramAuthOptions {
|
|
7
6
|
onUser: (data: InstagramUser, id: number | null, accessToken: string) => Promise<string | void>;
|
|
@@ -12,7 +11,6 @@ interface InitInstagramAuthOptions {
|
|
|
12
11
|
clientSecret: string;
|
|
13
12
|
refreshKey: string;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
declare function initInstagramAuth(props: InitInstagramAuthOptions): {
|
|
17
15
|
GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
|
|
18
16
|
getRefreshedAccessToken: typeof getRefreshedAccessToken;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
2
|
import { getRefreshedAccessToken } from './utils.js';
|
|
3
3
|
import { InstagramUser } from '../../socials/instagram/types.js';
|
|
4
|
-
export { getInstagramAuthorizationURL } from './client-utils.js';
|
|
5
4
|
|
|
6
5
|
interface InitInstagramAuthOptions {
|
|
7
6
|
onUser: (data: InstagramUser, id: number | null, accessToken: string) => Promise<string | void>;
|
|
@@ -12,7 +11,6 @@ interface InitInstagramAuthOptions {
|
|
|
12
11
|
clientSecret: string;
|
|
13
12
|
refreshKey: string;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
declare function initInstagramAuth(props: InitInstagramAuthOptions): {
|
|
17
15
|
GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
|
|
18
16
|
getRefreshedAccessToken: typeof getRefreshedAccessToken;
|
|
@@ -117,9 +117,6 @@ var getInstagramRoute = ({
|
|
|
117
117
|
};
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
// src/auth/instagram/client-utils.ts
|
|
121
|
-
var getInstagramAuthorizationURL = (clientId, authRoute) => (token) => `https://www.instagram.com/oauth/authorize?client_id=${clientId}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${authRoute}`;
|
|
122
|
-
|
|
123
120
|
// src/auth/instagram/index.ts
|
|
124
121
|
function initInstagramAuth(props) {
|
|
125
122
|
return {
|
|
@@ -128,6 +125,5 @@ function initInstagramAuth(props) {
|
|
|
128
125
|
};
|
|
129
126
|
}
|
|
130
127
|
export {
|
|
131
|
-
getInstagramAuthorizationURL,
|
|
132
128
|
initInstagramAuth
|
|
133
129
|
};
|
|
@@ -2,7 +2,6 @@ import { NextRequest, NextResponse } from 'next/server';
|
|
|
2
2
|
import { InitInstagramAuthOptions } from './index.mjs';
|
|
3
3
|
import './utils.mjs';
|
|
4
4
|
import '../../socials/instagram/types.mjs';
|
|
5
|
-
import './client-utils.mjs';
|
|
6
5
|
|
|
7
6
|
declare const getInstagramRoute: ({ successRedirectURL, errorRedirectURL, onUser, authRoute, clientSecret, clientId, }: InitInstagramAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
8
7
|
|
|
@@ -2,7 +2,6 @@ import { NextRequest, NextResponse } from 'next/server';
|
|
|
2
2
|
import { InitInstagramAuthOptions } from './index.js';
|
|
3
3
|
import './utils.js';
|
|
4
4
|
import '../../socials/instagram/types.js';
|
|
5
|
-
import './client-utils.js';
|
|
6
5
|
|
|
7
6
|
declare const getInstagramRoute: ({ successRedirectURL, errorRedirectURL, onUser, authRoute, clientSecret, clientId, }: InitInstagramAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
8
7
|
|
package/dist/client/hooks.cjs.js
CHANGED
package/dist/client/hooks.esm.js
CHANGED
package/dist/client/index.cjs.js
CHANGED
|
@@ -20,12 +20,41 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/client/index.ts
|
|
21
21
|
var client_exports = {};
|
|
22
22
|
__export(client_exports, {
|
|
23
|
+
getHandleImageUpload: () => getHandleImageUpload,
|
|
24
|
+
getInstagramAuthorizationURLSetup: () => getInstagramAuthorizationURLSetup,
|
|
23
25
|
setupSEO: () => setupSEO,
|
|
24
26
|
useBreakpoint: () => useBreakpoint,
|
|
25
27
|
useVisibility: () => useVisibility
|
|
26
28
|
});
|
|
27
29
|
module.exports = __toCommonJS(client_exports);
|
|
28
30
|
|
|
31
|
+
// src/auth/instagram/client.ts
|
|
32
|
+
var getInstagramAuthorizationURLSetup = (clientId, redirectURL) => (token) => `https://www.instagram.com/oauth/authorize?client_id=${clientId}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${redirectURL}`;
|
|
33
|
+
|
|
34
|
+
// src/file/client.ts
|
|
35
|
+
var getHandleImageUpload = (route) => ({
|
|
36
|
+
file,
|
|
37
|
+
type,
|
|
38
|
+
token,
|
|
39
|
+
data,
|
|
40
|
+
sync
|
|
41
|
+
}) => {
|
|
42
|
+
const formData = new FormData();
|
|
43
|
+
formData.append("type", type);
|
|
44
|
+
if (file) formData.append("file", file);
|
|
45
|
+
if (sync) formData.append("sync", sync.toString());
|
|
46
|
+
if (data) formData.append("data", JSON.stringify(data));
|
|
47
|
+
return fetch(route, {
|
|
48
|
+
method: "PUT",
|
|
49
|
+
body: formData,
|
|
50
|
+
headers: {
|
|
51
|
+
Authorization: `Bearer ${token}`
|
|
52
|
+
}
|
|
53
|
+
}).then(
|
|
54
|
+
async (res) => await res.json() || null
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
29
58
|
// src/client/hooks.ts
|
|
30
59
|
var import_react = require("react");
|
|
31
60
|
function useVisibility(onVisible) {
|
|
@@ -96,6 +125,8 @@ var setupSEO = (SEO) => (title, description, image) => ({
|
|
|
96
125
|
});
|
|
97
126
|
// Annotate the CommonJS export names for ESM import in node:
|
|
98
127
|
0 && (module.exports = {
|
|
128
|
+
getHandleImageUpload,
|
|
129
|
+
getInstagramAuthorizationURLSetup,
|
|
99
130
|
setupSEO,
|
|
100
131
|
useBreakpoint,
|
|
101
132
|
useVisibility
|
package/dist/client/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { getInstagramAuthorizationURLSetup } from '../auth/instagram/client.mjs';
|
|
2
|
+
export { ImageUploadResponseType, getHandleImageUpload } from '../file/client.mjs';
|
|
1
3
|
export { useBreakpoint, useVisibility } from './hooks.mjs';
|
|
2
4
|
export { setupSEO } from './seo.mjs';
|
|
3
5
|
import 'react';
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { getInstagramAuthorizationURLSetup } from '../auth/instagram/client.js';
|
|
2
|
+
export { ImageUploadResponseType, getHandleImageUpload } from '../file/client.js';
|
|
1
3
|
export { useBreakpoint, useVisibility } from './hooks.js';
|
|
2
4
|
export { setupSEO } from './seo.js';
|
|
3
5
|
import 'react';
|
package/dist/client/index.esm.js
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
// src/auth/instagram/client.ts
|
|
2
|
+
var getInstagramAuthorizationURLSetup = (clientId, redirectURL) => (token) => `https://www.instagram.com/oauth/authorize?client_id=${clientId}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${redirectURL}`;
|
|
3
|
+
|
|
4
|
+
// src/file/client.ts
|
|
5
|
+
var getHandleImageUpload = (route) => ({
|
|
6
|
+
file,
|
|
7
|
+
type,
|
|
8
|
+
token,
|
|
9
|
+
data,
|
|
10
|
+
sync
|
|
11
|
+
}) => {
|
|
12
|
+
const formData = new FormData();
|
|
13
|
+
formData.append("type", type);
|
|
14
|
+
if (file) formData.append("file", file);
|
|
15
|
+
if (sync) formData.append("sync", sync.toString());
|
|
16
|
+
if (data) formData.append("data", JSON.stringify(data));
|
|
17
|
+
return fetch(route, {
|
|
18
|
+
method: "PUT",
|
|
19
|
+
body: formData,
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${token}`
|
|
22
|
+
}
|
|
23
|
+
}).then(
|
|
24
|
+
async (res) => await res.json() || null
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
1
28
|
// src/client/hooks.ts
|
|
2
29
|
import { useEffect, useRef, useState } from "react";
|
|
3
30
|
function useVisibility(onVisible) {
|
|
@@ -67,6 +94,8 @@ var setupSEO = (SEO) => (title, description, image) => ({
|
|
|
67
94
|
publisher: SEO.siteName
|
|
68
95
|
});
|
|
69
96
|
export {
|
|
97
|
+
getHandleImageUpload,
|
|
98
|
+
getInstagramAuthorizationURLSetup,
|
|
70
99
|
setupSEO,
|
|
71
100
|
useBreakpoint,
|
|
72
101
|
useVisibility
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/file/client.ts
|
|
21
|
+
var client_exports = {};
|
|
22
|
+
__export(client_exports, {
|
|
23
|
+
getHandleImageUpload: () => getHandleImageUpload
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(client_exports);
|
|
26
|
+
var getHandleImageUpload = (route) => ({
|
|
27
|
+
file,
|
|
28
|
+
type,
|
|
29
|
+
token,
|
|
30
|
+
data,
|
|
31
|
+
sync
|
|
32
|
+
}) => {
|
|
33
|
+
const formData = new FormData();
|
|
34
|
+
formData.append("type", type);
|
|
35
|
+
if (file) formData.append("file", file);
|
|
36
|
+
if (sync) formData.append("sync", sync.toString());
|
|
37
|
+
if (data) formData.append("data", JSON.stringify(data));
|
|
38
|
+
return fetch(route, {
|
|
39
|
+
method: "PUT",
|
|
40
|
+
body: formData,
|
|
41
|
+
headers: {
|
|
42
|
+
Authorization: `Bearer ${token}`
|
|
43
|
+
}
|
|
44
|
+
}).then(
|
|
45
|
+
async (res) => await res.json() || null
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
getHandleImageUpload
|
|
51
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const getHandleImageUpload: (route: string) => ({ file, type, token, data, sync, }: {
|
|
2
|
+
file?: File | Blob;
|
|
3
|
+
token: string;
|
|
4
|
+
type: string;
|
|
5
|
+
sync?: boolean;
|
|
6
|
+
data?: object;
|
|
7
|
+
}) => Promise<ImageUploadResponseType>;
|
|
8
|
+
interface ImageUploadResponseType {
|
|
9
|
+
url?: string;
|
|
10
|
+
response?: object;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { type ImageUploadResponseType, getHandleImageUpload };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const getHandleImageUpload: (route: string) => ({ file, type, token, data, sync, }: {
|
|
2
|
+
file?: File | Blob;
|
|
3
|
+
token: string;
|
|
4
|
+
type: string;
|
|
5
|
+
sync?: boolean;
|
|
6
|
+
data?: object;
|
|
7
|
+
}) => Promise<ImageUploadResponseType>;
|
|
8
|
+
interface ImageUploadResponseType {
|
|
9
|
+
url?: string;
|
|
10
|
+
response?: object;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { type ImageUploadResponseType, getHandleImageUpload };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/file/client.ts
|
|
2
|
+
var getHandleImageUpload = (route) => ({
|
|
3
|
+
file,
|
|
4
|
+
type,
|
|
5
|
+
token,
|
|
6
|
+
data,
|
|
7
|
+
sync
|
|
8
|
+
}) => {
|
|
9
|
+
const formData = new FormData();
|
|
10
|
+
formData.append("type", type);
|
|
11
|
+
if (file) formData.append("file", file);
|
|
12
|
+
if (sync) formData.append("sync", sync.toString());
|
|
13
|
+
if (data) formData.append("data", JSON.stringify(data));
|
|
14
|
+
return fetch(route, {
|
|
15
|
+
method: "PUT",
|
|
16
|
+
body: formData,
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: `Bearer ${token}`
|
|
19
|
+
}
|
|
20
|
+
}).then(
|
|
21
|
+
async (res) => await res.json() || null
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
getHandleImageUpload
|
|
26
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/file/index.ts
|
|
21
|
+
var file_exports = {};
|
|
22
|
+
__export(file_exports, {
|
|
23
|
+
setupFileUpload: () => setupFileUpload
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(file_exports);
|
|
26
|
+
|
|
27
|
+
// src/file/put.ts
|
|
28
|
+
var import_functions2 = require("@vercel/functions");
|
|
29
|
+
var import_server3 = require("next/server");
|
|
30
|
+
var import_uuid = require("uuid");
|
|
31
|
+
|
|
32
|
+
// src/auth/email/utils.ts
|
|
33
|
+
var import_jsonwebtoken2 = require("jsonwebtoken");
|
|
34
|
+
|
|
35
|
+
// src/auth/email/token.ts
|
|
36
|
+
var import_bcryptjs = require("bcryptjs");
|
|
37
|
+
var import_jsonwebtoken = require("jsonwebtoken");
|
|
38
|
+
var import_server = require("next/server");
|
|
39
|
+
function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
40
|
+
if (refreshToken)
|
|
41
|
+
try {
|
|
42
|
+
const decoded = (0, import_jsonwebtoken.verify)(refreshToken, refreshKey);
|
|
43
|
+
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
44
|
+
return decoded.id;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (!(e instanceof import_jsonwebtoken.JsonWebTokenError)) console.error(e, "errors");
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/auth/utils/errors.ts
|
|
53
|
+
var import_server2 = require("next/server");
|
|
54
|
+
|
|
55
|
+
// src/auth/email/utils.ts
|
|
56
|
+
var getUserContext = (refreshKey, signingKey, req) => {
|
|
57
|
+
const bearer = req.headers.get("authorization");
|
|
58
|
+
if (!bearer) {
|
|
59
|
+
const refresh = req.cookies.get("refresh")?.value;
|
|
60
|
+
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
61
|
+
if (userId) return { refreshUserID: userId };
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const token = bearer.slice(7);
|
|
65
|
+
try {
|
|
66
|
+
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
67
|
+
if (typeof res === "string") {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
accessUserId: res.id
|
|
72
|
+
};
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/file/utils.ts
|
|
79
|
+
var import_node_crypto = require("crypto");
|
|
80
|
+
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
81
|
+
var import_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
|
|
82
|
+
var import_functions = require("@vercel/functions");
|
|
83
|
+
var getS3Client = (options) => new import_client_s3.S3Client({
|
|
84
|
+
region: options.region,
|
|
85
|
+
credentials: {
|
|
86
|
+
accessKeyId: options.awsKey,
|
|
87
|
+
secretAccessKey: options.awsSecret
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
var getURLPrefix = (options) => `https://${options.bucket}.s3.${options.region}.amazonaws.com/`;
|
|
91
|
+
function getHash(keys) {
|
|
92
|
+
return (0, import_node_crypto.createHash)("sha256").update(keys.join("/")).digest("hex");
|
|
93
|
+
}
|
|
94
|
+
var getUploadFileURL = (client, Bucket) => (keys, isPublic) => {
|
|
95
|
+
const command = new import_client_s3.PutObjectCommand({
|
|
96
|
+
Bucket,
|
|
97
|
+
Key: getHash(keys),
|
|
98
|
+
ACL: isPublic ? "public-read" : void 0
|
|
99
|
+
});
|
|
100
|
+
return (0, import_s3_request_presigner.getSignedUrl)(client, command, { expiresIn: 300 });
|
|
101
|
+
};
|
|
102
|
+
var getFileURL = (options) => (keys) => {
|
|
103
|
+
if (typeof keys === "string") return `${getURLPrefix(options)}${keys}`;
|
|
104
|
+
return `${getURLPrefix(options)}${getHash(keys)}`;
|
|
105
|
+
};
|
|
106
|
+
var uploadImage = (client, options) => async (url, key, blob) => {
|
|
107
|
+
const photoBlob = blob || await fetch(url).then((file) => file.blob());
|
|
108
|
+
if (photoBlob) {
|
|
109
|
+
(0, import_functions.waitUntil)(uploadFile(client, options.bucket)(photoBlob, getHash(key)));
|
|
110
|
+
return getFileURL(options)(key);
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
};
|
|
114
|
+
var deleteImage = (client, options) => async (url) => {
|
|
115
|
+
const key = url.split(getURLPrefix(options))[1];
|
|
116
|
+
if (key) {
|
|
117
|
+
try {
|
|
118
|
+
await client.send(
|
|
119
|
+
new import_client_s3.DeleteObjectCommand({
|
|
120
|
+
Bucket: options.bucket,
|
|
121
|
+
Key: key
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
return true;
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.error("ERROR", url, e);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
};
|
|
131
|
+
var uploadFile = (client, Bucket) => async (file, key) => {
|
|
132
|
+
const fileBuffer = await file.arrayBuffer();
|
|
133
|
+
return client.send(
|
|
134
|
+
new import_client_s3.PutObjectCommand({
|
|
135
|
+
Bucket,
|
|
136
|
+
Key: key,
|
|
137
|
+
ACL: "public-read",
|
|
138
|
+
Body: Buffer.from(fileBuffer),
|
|
139
|
+
ContentType: file.type,
|
|
140
|
+
ContentLength: file.size
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/file/put.ts
|
|
146
|
+
var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
147
|
+
const ctx = getUserContext(options.refreshKey, options.signingKey, req);
|
|
148
|
+
if (!ctx?.accessUserId)
|
|
149
|
+
return import_server3.NextResponse.json({ error: "unauthorized" }, { status: 401 });
|
|
150
|
+
const formData = await req.formData();
|
|
151
|
+
const type = formData.get("type");
|
|
152
|
+
const sync = Boolean(formData.get("sync"));
|
|
153
|
+
const file = formData.get("file");
|
|
154
|
+
const data = formData.get("data");
|
|
155
|
+
const imageKey = (0, import_uuid.v4)();
|
|
156
|
+
const url = file ? getFileURL(options)(imageKey) : null;
|
|
157
|
+
const handleKeyProcessing = async () => {
|
|
158
|
+
if (file) await uploadFile(client, options.bucket)(file, imageKey);
|
|
159
|
+
if (!type || !ctx.accessUserId) return;
|
|
160
|
+
const { deleteURL, response } = await options.processFile({
|
|
161
|
+
url,
|
|
162
|
+
type,
|
|
163
|
+
userId: ctx.accessUserId,
|
|
164
|
+
data: typeof data === "string" ? JSON.parse(data) : void 0
|
|
165
|
+
});
|
|
166
|
+
if (deleteURL) await deleteImage(client, options)(deleteURL);
|
|
167
|
+
return response;
|
|
168
|
+
};
|
|
169
|
+
if (!sync) {
|
|
170
|
+
(0, import_functions2.waitUntil)(handleKeyProcessing());
|
|
171
|
+
return import_server3.NextResponse.json({ url });
|
|
172
|
+
} else {
|
|
173
|
+
return import_server3.NextResponse.json({
|
|
174
|
+
url,
|
|
175
|
+
response: await handleKeyProcessing()
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// src/file/setup.ts
|
|
181
|
+
function setupFileUpload(options) {
|
|
182
|
+
const client = getS3Client(options);
|
|
183
|
+
return {
|
|
184
|
+
PUT: getFileUploadPutRoute(options, client),
|
|
185
|
+
getUploadFileURL: getUploadFileURL(client, options.bucket),
|
|
186
|
+
uploadImage: uploadImage(client, options),
|
|
187
|
+
deleteImage: deleteImage(client, options),
|
|
188
|
+
getFileURL: getFileURL(options),
|
|
189
|
+
uploadFile: uploadFile(client, options.bucket)
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
193
|
+
0 && (module.exports = {
|
|
194
|
+
setupFileUpload
|
|
195
|
+
});
|