naystack 1.5.11 → 1.5.13
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.cjs.js +6 -5
- package/dist/auth/index.d.mts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.esm.js +5 -5
- package/dist/auth/instagram/client.cjs.js +4 -4
- package/dist/auth/instagram/client.d.mts +11 -9
- package/dist/auth/instagram/client.d.ts +11 -9
- package/dist/auth/instagram/client.esm.js +3 -3
- package/dist/auth/instagram/index.cjs.js +6 -5
- package/dist/auth/instagram/index.d.mts +3 -6
- package/dist/auth/instagram/index.d.ts +3 -6
- package/dist/auth/instagram/index.esm.js +5 -5
- package/dist/auth/instagram/route.cjs.js +2 -2
- 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 +2 -2
- package/dist/auth/instagram/utils.cjs.js +3 -3
- package/dist/auth/instagram/utils.d.mts +2 -2
- package/dist/auth/instagram/utils.d.ts +2 -2
- package/dist/auth/instagram/utils.esm.js +2 -2
- package/dist/file/index.cjs.js +30 -16
- package/dist/file/index.d.mts +2 -0
- package/dist/file/index.d.ts +2 -0
- package/dist/file/index.esm.js +25 -15
- package/dist/file/put.cjs.js +18 -3
- package/dist/file/put.d.mts +1 -3
- package/dist/file/put.d.ts +1 -3
- package/dist/file/put.esm.js +18 -3
- package/dist/file/setup.cjs.js +13 -48
- package/dist/file/setup.d.mts +0 -7
- package/dist/file/setup.d.ts +0 -7
- package/dist/file/setup.esm.js +13 -48
- package/dist/file/utils.cjs.js +14 -8
- package/dist/file/utils.d.mts +22 -26
- package/dist/file/utils.d.ts +22 -26
- package/dist/file/utils.esm.js +14 -7
- package/package.json +1 -1
package/dist/auth/index.cjs.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(auth_exports, {
|
|
|
24
24
|
getContext: () => getContext,
|
|
25
25
|
getEmailAuthRoutes: () => getEmailAuthRoutes,
|
|
26
26
|
getRefreshToken: () => getRefreshToken,
|
|
27
|
+
getRefreshedInstagramAccessToken: () => getRefreshedInstagramAccessToken,
|
|
27
28
|
initGoogleAuth: () => initGoogleAuth,
|
|
28
29
|
initInstagramAuth: () => initInstagramAuth
|
|
29
30
|
});
|
|
@@ -411,7 +412,7 @@ function initGoogleAuth(props) {
|
|
|
411
412
|
var import_server5 = require("next/server");
|
|
412
413
|
|
|
413
414
|
// src/auth/instagram/utils.ts
|
|
414
|
-
async function
|
|
415
|
+
async function getRefreshedInstagramAccessToken(token) {
|
|
415
416
|
const request = await fetch(
|
|
416
417
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
417
418
|
);
|
|
@@ -474,7 +475,7 @@ var import_server4 = require("next/server");
|
|
|
474
475
|
|
|
475
476
|
// src/auth/instagram/route.ts
|
|
476
477
|
var getInstagramRoute = ({
|
|
477
|
-
|
|
478
|
+
redirectURL,
|
|
478
479
|
errorRedirectURL,
|
|
479
480
|
onUser
|
|
480
481
|
}) => {
|
|
@@ -502,15 +503,14 @@ var getInstagramRoute = ({
|
|
|
502
503
|
instagramData.accessToken
|
|
503
504
|
);
|
|
504
505
|
if (errorMessage) return handleError2(errorMessage);
|
|
505
|
-
return import_server5.NextResponse.redirect(
|
|
506
|
+
return import_server5.NextResponse.redirect(redirectURL);
|
|
506
507
|
};
|
|
507
508
|
};
|
|
508
509
|
|
|
509
510
|
// src/auth/instagram/index.ts
|
|
510
511
|
function initInstagramAuth(props) {
|
|
511
512
|
return {
|
|
512
|
-
GET: getInstagramRoute(props)
|
|
513
|
-
getRefreshedAccessToken
|
|
513
|
+
GET: getInstagramRoute(props)
|
|
514
514
|
};
|
|
515
515
|
}
|
|
516
516
|
|
|
@@ -526,6 +526,7 @@ async function getRefreshToken() {
|
|
|
526
526
|
getContext,
|
|
527
527
|
getEmailAuthRoutes,
|
|
528
528
|
getRefreshToken,
|
|
529
|
+
getRefreshedInstagramAccessToken,
|
|
529
530
|
initGoogleAuth,
|
|
530
531
|
initInstagramAuth
|
|
531
532
|
});
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -4,10 +4,10 @@ export { initInstagramAuth } from './instagram/index.mjs';
|
|
|
4
4
|
export { getRefreshToken } from './utils/token.mjs';
|
|
5
5
|
export { checkAuthStatus } from './email/token.mjs';
|
|
6
6
|
export { getContext } from './email/utils.mjs';
|
|
7
|
+
export { getRefreshedInstagramAccessToken } from './instagram/utils.mjs';
|
|
7
8
|
import 'next/server';
|
|
8
9
|
import './email/types.mjs';
|
|
9
10
|
import './types.mjs';
|
|
10
11
|
import 'googleapis';
|
|
11
|
-
import './instagram/utils.mjs';
|
|
12
12
|
import '../socials/instagram/types.mjs';
|
|
13
13
|
import '../graphql/types.mjs';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ export { initInstagramAuth } from './instagram/index.js';
|
|
|
4
4
|
export { getRefreshToken } from './utils/token.js';
|
|
5
5
|
export { checkAuthStatus } from './email/token.js';
|
|
6
6
|
export { getContext } from './email/utils.js';
|
|
7
|
+
export { getRefreshedInstagramAccessToken } from './instagram/utils.js';
|
|
7
8
|
import 'next/server';
|
|
8
9
|
import './email/types.js';
|
|
9
10
|
import './types.js';
|
|
10
11
|
import 'googleapis';
|
|
11
|
-
import './instagram/utils.js';
|
|
12
12
|
import '../socials/instagram/types.js';
|
|
13
13
|
import '../graphql/types.js';
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -380,7 +380,7 @@ function initGoogleAuth(props) {
|
|
|
380
380
|
import { NextResponse as NextResponse5 } from "next/server";
|
|
381
381
|
|
|
382
382
|
// src/auth/instagram/utils.ts
|
|
383
|
-
async function
|
|
383
|
+
async function getRefreshedInstagramAccessToken(token) {
|
|
384
384
|
const request = await fetch(
|
|
385
385
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
386
386
|
);
|
|
@@ -443,7 +443,7 @@ import { NextResponse as NextResponse4 } from "next/server";
|
|
|
443
443
|
|
|
444
444
|
// src/auth/instagram/route.ts
|
|
445
445
|
var getInstagramRoute = ({
|
|
446
|
-
|
|
446
|
+
redirectURL,
|
|
447
447
|
errorRedirectURL,
|
|
448
448
|
onUser
|
|
449
449
|
}) => {
|
|
@@ -471,15 +471,14 @@ var getInstagramRoute = ({
|
|
|
471
471
|
instagramData.accessToken
|
|
472
472
|
);
|
|
473
473
|
if (errorMessage) return handleError2(errorMessage);
|
|
474
|
-
return NextResponse5.redirect(
|
|
474
|
+
return NextResponse5.redirect(redirectURL);
|
|
475
475
|
};
|
|
476
476
|
};
|
|
477
477
|
|
|
478
478
|
// src/auth/instagram/index.ts
|
|
479
479
|
function initInstagramAuth(props) {
|
|
480
480
|
return {
|
|
481
|
-
GET: getInstagramRoute(props)
|
|
482
|
-
getRefreshedAccessToken
|
|
481
|
+
GET: getInstagramRoute(props)
|
|
483
482
|
};
|
|
484
483
|
}
|
|
485
484
|
|
|
@@ -494,6 +493,7 @@ export {
|
|
|
494
493
|
getContext,
|
|
495
494
|
getEmailAuthRoutes,
|
|
496
495
|
getRefreshToken,
|
|
496
|
+
getRefreshedInstagramAccessToken,
|
|
497
497
|
initGoogleAuth,
|
|
498
498
|
initInstagramAuth
|
|
499
499
|
};
|
|
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/auth/instagram/client.ts
|
|
21
21
|
var client_exports = {};
|
|
22
22
|
__export(client_exports, {
|
|
23
|
-
|
|
23
|
+
getInstagramAuthorizationURL: () => getInstagramAuthorizationURL
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(client_exports);
|
|
26
26
|
|
|
@@ -74,10 +74,10 @@ function getEnv(key, skipCheck) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// src/auth/instagram/client.ts
|
|
77
|
-
var
|
|
77
|
+
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize?client_id=${getEnv(
|
|
78
78
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
79
|
-
)}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${
|
|
79
|
+
)}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${getEnv("NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT" /* NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT */)}`;
|
|
80
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
81
|
0 && (module.exports = {
|
|
82
|
-
|
|
82
|
+
getInstagramAuthorizationURL
|
|
83
83
|
});
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* The state token is
|
|
2
|
+
* Builds the Instagram OAuth authorization URL for the given state token.
|
|
3
|
+
* The state token is passed back by Instagram after authorization and is used to link
|
|
4
|
+
* the Instagram account to the logged-in user.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* Reads `INSTAGRAM_CLIENT_ID` and `NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT` from the environment.
|
|
7
|
+
*
|
|
8
|
+
* @param token - The state token to embed in the authorization URL (typically the user's session or access token).
|
|
9
|
+
* @returns The full Instagram OAuth authorization URL.
|
|
7
10
|
*
|
|
8
11
|
* @example
|
|
9
12
|
* ```ts
|
|
10
|
-
* import {
|
|
13
|
+
* import { getInstagramAuthorizationURL } from "naystack/auth/instagram/client";
|
|
11
14
|
*
|
|
12
|
-
* const
|
|
13
|
-
* const url = getAuthURL(userAccessToken);
|
|
15
|
+
* const url = getInstagramAuthorizationURL(userAccessToken);
|
|
14
16
|
* // => "https://www.instagram.com/oauth/authorize?client_id=...&state=...&redirect_uri=..."
|
|
15
17
|
* window.location.href = url;
|
|
16
18
|
* ```
|
|
17
19
|
*
|
|
18
20
|
* @category Auth
|
|
19
21
|
*/
|
|
20
|
-
declare const
|
|
22
|
+
declare const getInstagramAuthorizationURL: (token: string) => string;
|
|
21
23
|
|
|
22
|
-
export {
|
|
24
|
+
export { getInstagramAuthorizationURL };
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* The state token is
|
|
2
|
+
* Builds the Instagram OAuth authorization URL for the given state token.
|
|
3
|
+
* The state token is passed back by Instagram after authorization and is used to link
|
|
4
|
+
* the Instagram account to the logged-in user.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* Reads `INSTAGRAM_CLIENT_ID` and `NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT` from the environment.
|
|
7
|
+
*
|
|
8
|
+
* @param token - The state token to embed in the authorization URL (typically the user's session or access token).
|
|
9
|
+
* @returns The full Instagram OAuth authorization URL.
|
|
7
10
|
*
|
|
8
11
|
* @example
|
|
9
12
|
* ```ts
|
|
10
|
-
* import {
|
|
13
|
+
* import { getInstagramAuthorizationURL } from "naystack/auth/instagram/client";
|
|
11
14
|
*
|
|
12
|
-
* const
|
|
13
|
-
* const url = getAuthURL(userAccessToken);
|
|
15
|
+
* const url = getInstagramAuthorizationURL(userAccessToken);
|
|
14
16
|
* // => "https://www.instagram.com/oauth/authorize?client_id=...&state=...&redirect_uri=..."
|
|
15
17
|
* window.location.href = url;
|
|
16
18
|
* ```
|
|
17
19
|
*
|
|
18
20
|
* @category Auth
|
|
19
21
|
*/
|
|
20
|
-
declare const
|
|
22
|
+
declare const getInstagramAuthorizationURL: (token: string) => string;
|
|
21
23
|
|
|
22
|
-
export {
|
|
24
|
+
export { getInstagramAuthorizationURL };
|
|
@@ -48,9 +48,9 @@ function getEnv(key, skipCheck) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// src/auth/instagram/client.ts
|
|
51
|
-
var
|
|
51
|
+
var getInstagramAuthorizationURL = (token) => `https://www.instagram.com/oauth/authorize?client_id=${getEnv(
|
|
52
52
|
"INSTAGRAM_CLIENT_ID" /* INSTAGRAM_CLIENT_ID */
|
|
53
|
-
)}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${
|
|
53
|
+
)}&response_type=code&enable_fb_login=0&force_authentication=1&scope=instagram_business_basic&state=${token}&redirect_uri=${getEnv("NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT" /* NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT */)}`;
|
|
54
54
|
export {
|
|
55
|
-
|
|
55
|
+
getInstagramAuthorizationURL
|
|
56
56
|
};
|
|
@@ -20,6 +20,7 @@ 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
|
+
getRefreshedInstagramAccessToken: () => getRefreshedInstagramAccessToken,
|
|
23
24
|
initInstagramAuth: () => initInstagramAuth
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(instagram_exports);
|
|
@@ -98,7 +99,7 @@ function getUserIdFromAccessToken(refreshToken) {
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
// src/auth/instagram/utils.ts
|
|
101
|
-
async function
|
|
102
|
+
async function getRefreshedInstagramAccessToken(token) {
|
|
102
103
|
const request = await fetch(
|
|
103
104
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
104
105
|
);
|
|
@@ -161,7 +162,7 @@ var import_server2 = require("next/server");
|
|
|
161
162
|
|
|
162
163
|
// src/auth/instagram/route.ts
|
|
163
164
|
var getInstagramRoute = ({
|
|
164
|
-
|
|
165
|
+
redirectURL,
|
|
165
166
|
errorRedirectURL,
|
|
166
167
|
onUser
|
|
167
168
|
}) => {
|
|
@@ -189,18 +190,18 @@ var getInstagramRoute = ({
|
|
|
189
190
|
instagramData.accessToken
|
|
190
191
|
);
|
|
191
192
|
if (errorMessage) return handleError(errorMessage);
|
|
192
|
-
return import_server3.NextResponse.redirect(
|
|
193
|
+
return import_server3.NextResponse.redirect(redirectURL);
|
|
193
194
|
};
|
|
194
195
|
};
|
|
195
196
|
|
|
196
197
|
// src/auth/instagram/index.ts
|
|
197
198
|
function initInstagramAuth(props) {
|
|
198
199
|
return {
|
|
199
|
-
GET: getInstagramRoute(props)
|
|
200
|
-
getRefreshedAccessToken
|
|
200
|
+
GET: getInstagramRoute(props)
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
203
|
// Annotate the CommonJS export names for ESM import in node:
|
|
204
204
|
0 && (module.exports = {
|
|
205
|
+
getRefreshedInstagramAccessToken,
|
|
205
206
|
initInstagramAuth
|
|
206
207
|
});
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
|
-
|
|
2
|
+
export { getRefreshedInstagramAccessToken } from './utils.mjs';
|
|
3
3
|
import { InstagramUser } from '../../socials/instagram/types.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Options for initializing Instagram OAuth via {@link initInstagramAuth}.
|
|
7
7
|
*
|
|
8
8
|
* @property onUser - Called with `(instagramUser, appUserId, accessToken)` after successful OAuth. Return a string to show as error (redirects to `errorRedirectURL`); return `void` on success.
|
|
9
|
-
* @property
|
|
9
|
+
* @property redirectURL - Where to redirect after successful Instagram auth.
|
|
10
10
|
* @property errorRedirectURL - Where to redirect on error (with `?error=` query param).
|
|
11
|
-
* @property refreshKey - Your app secret (e.g. `REFRESH_KEY` env var) used in the flow.
|
|
12
11
|
*
|
|
13
12
|
* @category Auth
|
|
14
13
|
*/
|
|
15
14
|
interface InitInstagramAuthOptions {
|
|
16
15
|
onUser: (data: InstagramUser, id: number | null, accessToken: string) => Promise<string | void>;
|
|
17
|
-
|
|
16
|
+
redirectURL: string;
|
|
18
17
|
errorRedirectURL: string;
|
|
19
|
-
refreshKey: string;
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
22
20
|
* Initializes Instagram OAuth. Returns a GET handler for the OAuth callback and a helper to refresh long-lived tokens.
|
|
@@ -47,7 +45,6 @@ interface InitInstagramAuthOptions {
|
|
|
47
45
|
*/
|
|
48
46
|
declare function initInstagramAuth(props: InitInstagramAuthOptions): {
|
|
49
47
|
GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
|
|
50
|
-
getRefreshedAccessToken: typeof getRefreshedAccessToken;
|
|
51
48
|
};
|
|
52
49
|
|
|
53
50
|
export { type InitInstagramAuthOptions, initInstagramAuth };
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
|
-
|
|
2
|
+
export { getRefreshedInstagramAccessToken } from './utils.js';
|
|
3
3
|
import { InstagramUser } from '../../socials/instagram/types.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Options for initializing Instagram OAuth via {@link initInstagramAuth}.
|
|
7
7
|
*
|
|
8
8
|
* @property onUser - Called with `(instagramUser, appUserId, accessToken)` after successful OAuth. Return a string to show as error (redirects to `errorRedirectURL`); return `void` on success.
|
|
9
|
-
* @property
|
|
9
|
+
* @property redirectURL - Where to redirect after successful Instagram auth.
|
|
10
10
|
* @property errorRedirectURL - Where to redirect on error (with `?error=` query param).
|
|
11
|
-
* @property refreshKey - Your app secret (e.g. `REFRESH_KEY` env var) used in the flow.
|
|
12
11
|
*
|
|
13
12
|
* @category Auth
|
|
14
13
|
*/
|
|
15
14
|
interface InitInstagramAuthOptions {
|
|
16
15
|
onUser: (data: InstagramUser, id: number | null, accessToken: string) => Promise<string | void>;
|
|
17
|
-
|
|
16
|
+
redirectURL: string;
|
|
18
17
|
errorRedirectURL: string;
|
|
19
|
-
refreshKey: string;
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
22
20
|
* Initializes Instagram OAuth. Returns a GET handler for the OAuth callback and a helper to refresh long-lived tokens.
|
|
@@ -47,7 +45,6 @@ interface InitInstagramAuthOptions {
|
|
|
47
45
|
*/
|
|
48
46
|
declare function initInstagramAuth(props: InitInstagramAuthOptions): {
|
|
49
47
|
GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
|
|
50
|
-
getRefreshedAccessToken: typeof getRefreshedAccessToken;
|
|
51
48
|
};
|
|
52
49
|
|
|
53
50
|
export { type InitInstagramAuthOptions, initInstagramAuth };
|
|
@@ -72,7 +72,7 @@ function getUserIdFromAccessToken(refreshToken) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// src/auth/instagram/utils.ts
|
|
75
|
-
async function
|
|
75
|
+
async function getRefreshedInstagramAccessToken(token) {
|
|
76
76
|
const request = await fetch(
|
|
77
77
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
78
78
|
);
|
|
@@ -135,7 +135,7 @@ import { NextResponse as NextResponse2 } from "next/server";
|
|
|
135
135
|
|
|
136
136
|
// src/auth/instagram/route.ts
|
|
137
137
|
var getInstagramRoute = ({
|
|
138
|
-
|
|
138
|
+
redirectURL,
|
|
139
139
|
errorRedirectURL,
|
|
140
140
|
onUser
|
|
141
141
|
}) => {
|
|
@@ -163,17 +163,17 @@ var getInstagramRoute = ({
|
|
|
163
163
|
instagramData.accessToken
|
|
164
164
|
);
|
|
165
165
|
if (errorMessage) return handleError(errorMessage);
|
|
166
|
-
return NextResponse3.redirect(
|
|
166
|
+
return NextResponse3.redirect(redirectURL);
|
|
167
167
|
};
|
|
168
168
|
};
|
|
169
169
|
|
|
170
170
|
// src/auth/instagram/index.ts
|
|
171
171
|
function initInstagramAuth(props) {
|
|
172
172
|
return {
|
|
173
|
-
GET: getInstagramRoute(props)
|
|
174
|
-
getRefreshedAccessToken
|
|
173
|
+
GET: getInstagramRoute(props)
|
|
175
174
|
};
|
|
176
175
|
}
|
|
177
176
|
export {
|
|
177
|
+
getRefreshedInstagramAccessToken,
|
|
178
178
|
initInstagramAuth
|
|
179
179
|
};
|
|
@@ -152,7 +152,7 @@ var import_server2 = require("next/server");
|
|
|
152
152
|
|
|
153
153
|
// src/auth/instagram/route.ts
|
|
154
154
|
var getInstagramRoute = ({
|
|
155
|
-
|
|
155
|
+
redirectURL,
|
|
156
156
|
errorRedirectURL,
|
|
157
157
|
onUser
|
|
158
158
|
}) => {
|
|
@@ -180,7 +180,7 @@ var getInstagramRoute = ({
|
|
|
180
180
|
instagramData.accessToken
|
|
181
181
|
);
|
|
182
182
|
if (errorMessage) return handleError(errorMessage);
|
|
183
|
-
return import_server3.NextResponse.redirect(
|
|
183
|
+
return import_server3.NextResponse.redirect(redirectURL);
|
|
184
184
|
};
|
|
185
185
|
};
|
|
186
186
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -8,6 +8,6 @@ import '../../socials/instagram/types.mjs';
|
|
|
8
8
|
* @param options - InitInstagramAuthOptions (onUser, redirect URLs)
|
|
9
9
|
* @returns Async route handler for the OAuth callback
|
|
10
10
|
*/
|
|
11
|
-
declare const getInstagramRoute: ({
|
|
11
|
+
declare const getInstagramRoute: ({ redirectURL, errorRedirectURL, onUser, }: InitInstagramAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
12
12
|
|
|
13
13
|
export { getInstagramRoute };
|
|
@@ -8,6 +8,6 @@ import '../../socials/instagram/types.js';
|
|
|
8
8
|
* @param options - InitInstagramAuthOptions (onUser, redirect URLs)
|
|
9
9
|
* @returns Async route handler for the OAuth callback
|
|
10
10
|
*/
|
|
11
|
-
declare const getInstagramRoute: ({
|
|
11
|
+
declare const getInstagramRoute: ({ redirectURL, errorRedirectURL, onUser, }: InitInstagramAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
12
12
|
|
|
13
13
|
export { getInstagramRoute };
|
|
@@ -128,7 +128,7 @@ import { NextResponse as NextResponse2 } from "next/server";
|
|
|
128
128
|
|
|
129
129
|
// src/auth/instagram/route.ts
|
|
130
130
|
var getInstagramRoute = ({
|
|
131
|
-
|
|
131
|
+
redirectURL,
|
|
132
132
|
errorRedirectURL,
|
|
133
133
|
onUser
|
|
134
134
|
}) => {
|
|
@@ -156,7 +156,7 @@ var getInstagramRoute = ({
|
|
|
156
156
|
instagramData.accessToken
|
|
157
157
|
);
|
|
158
158
|
if (errorMessage) return handleError(errorMessage);
|
|
159
|
-
return NextResponse3.redirect(
|
|
159
|
+
return NextResponse3.redirect(redirectURL);
|
|
160
160
|
};
|
|
161
161
|
};
|
|
162
162
|
export {
|
|
@@ -21,7 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
23
|
getLongLivedToken: () => getLongLivedToken,
|
|
24
|
-
|
|
24
|
+
getRefreshedInstagramAccessToken: () => getRefreshedInstagramAccessToken
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(utils_exports);
|
|
27
27
|
|
|
@@ -75,7 +75,7 @@ function getEnv(key, skipCheck) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
// src/auth/instagram/utils.ts
|
|
78
|
-
async function
|
|
78
|
+
async function getRefreshedInstagramAccessToken(token) {
|
|
79
79
|
const request = await fetch(
|
|
80
80
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
81
81
|
);
|
|
@@ -113,5 +113,5 @@ async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
|
113
113
|
// Annotate the CommonJS export names for ESM import in node:
|
|
114
114
|
0 && (module.exports = {
|
|
115
115
|
getLongLivedToken,
|
|
116
|
-
|
|
116
|
+
getRefreshedInstagramAccessToken
|
|
117
117
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @param token - Current long-lived access token
|
|
4
4
|
* @returns New access token or undefined
|
|
5
5
|
*/
|
|
6
|
-
declare function
|
|
6
|
+
declare function getRefreshedInstagramAccessToken(token: string): Promise<string | undefined>;
|
|
7
7
|
/**
|
|
8
8
|
* Exchanges an OAuth code for a long-lived Instagram access token.
|
|
9
9
|
* @param code - OAuth authorization code from redirect
|
|
@@ -17,4 +17,4 @@ declare function getLongLivedToken(code: string, redirectURL: string, clientId:
|
|
|
17
17
|
userId: string;
|
|
18
18
|
} | undefined>;
|
|
19
19
|
|
|
20
|
-
export { getLongLivedToken,
|
|
20
|
+
export { getLongLivedToken, getRefreshedInstagramAccessToken };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @param token - Current long-lived access token
|
|
4
4
|
* @returns New access token or undefined
|
|
5
5
|
*/
|
|
6
|
-
declare function
|
|
6
|
+
declare function getRefreshedInstagramAccessToken(token: string): Promise<string | undefined>;
|
|
7
7
|
/**
|
|
8
8
|
* Exchanges an OAuth code for a long-lived Instagram access token.
|
|
9
9
|
* @param code - OAuth authorization code from redirect
|
|
@@ -17,4 +17,4 @@ declare function getLongLivedToken(code: string, redirectURL: string, clientId:
|
|
|
17
17
|
userId: string;
|
|
18
18
|
} | undefined>;
|
|
19
19
|
|
|
20
|
-
export { getLongLivedToken,
|
|
20
|
+
export { getLongLivedToken, getRefreshedInstagramAccessToken };
|
|
@@ -48,7 +48,7 @@ function getEnv(key, skipCheck) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// src/auth/instagram/utils.ts
|
|
51
|
-
async function
|
|
51
|
+
async function getRefreshedInstagramAccessToken(token) {
|
|
52
52
|
const request = await fetch(
|
|
53
53
|
`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${token}`
|
|
54
54
|
);
|
|
@@ -85,5 +85,5 @@ async function getLongLivedToken(code, redirectURL, clientId, clientSecret) {
|
|
|
85
85
|
}
|
|
86
86
|
export {
|
|
87
87
|
getLongLivedToken,
|
|
88
|
-
|
|
88
|
+
getRefreshedInstagramAccessToken
|
|
89
89
|
};
|
package/dist/file/index.cjs.js
CHANGED
|
@@ -20,11 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/file/index.ts
|
|
21
21
|
var file_exports = {};
|
|
22
22
|
__export(file_exports, {
|
|
23
|
-
|
|
23
|
+
deleteFile: () => deleteFile,
|
|
24
|
+
getDownloadURL: () => getDownloadURL,
|
|
25
|
+
getUploadURL: () => getUploadURL,
|
|
26
|
+
setupFileUpload: () => setupFileUpload,
|
|
27
|
+
uploadFile: () => uploadFile
|
|
24
28
|
});
|
|
25
29
|
module.exports = __toCommonJS(file_exports);
|
|
26
30
|
|
|
27
31
|
// src/file/put.ts
|
|
32
|
+
var import_functions = require("@vercel/functions");
|
|
28
33
|
var import_server3 = require("next/server");
|
|
29
34
|
var import_uuid = require("uuid");
|
|
30
35
|
|
|
@@ -133,7 +138,7 @@ var getContext = (req) => {
|
|
|
133
138
|
// src/file/utils.ts
|
|
134
139
|
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
135
140
|
var import_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
|
|
136
|
-
var
|
|
141
|
+
var client = new import_client_s3.S3Client({
|
|
137
142
|
region: getEnv("AWS_REGION" /* AWS_REGION */),
|
|
138
143
|
credentials: {
|
|
139
144
|
accessKeyId: getEnv("AWS_ACCESS_KEY_ID" /* AWS_ACCESS_KEY_ID */),
|
|
@@ -146,7 +151,8 @@ var URL_PREFIX = `https://${getEnv("AWS_BUCKET" /* AWS_BUCKET */)}.s3.${getEnv(
|
|
|
146
151
|
function getKey(keys) {
|
|
147
152
|
return typeof keys === "string" ? keys : keys.join("/");
|
|
148
153
|
}
|
|
149
|
-
var getUploadURL = (
|
|
154
|
+
var getUploadURL = (keys) => {
|
|
155
|
+
if (!checkClient(client)) return;
|
|
150
156
|
const command = new import_client_s3.PutObjectCommand({
|
|
151
157
|
Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
|
|
152
158
|
Key: getKey(keys),
|
|
@@ -157,21 +163,23 @@ var getUploadURL = (client) => (keys) => {
|
|
|
157
163
|
var getDownloadURL = (keys) => {
|
|
158
164
|
return `${URL_PREFIX}${getKey(keys)}`;
|
|
159
165
|
};
|
|
160
|
-
var uploadFile =
|
|
166
|
+
var uploadFile = async (keys, {
|
|
161
167
|
url,
|
|
162
168
|
blob
|
|
163
169
|
}) => {
|
|
170
|
+
if (!checkClient(client)) return;
|
|
164
171
|
if (!blob && !url) return null;
|
|
165
172
|
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
166
173
|
if (fileBlob) {
|
|
167
174
|
const key = getKey(keys);
|
|
168
|
-
await uploadBlob(
|
|
175
|
+
await uploadBlob(fileBlob, key);
|
|
169
176
|
return getDownloadURL(key);
|
|
170
177
|
}
|
|
171
178
|
return null;
|
|
172
179
|
};
|
|
173
|
-
var deleteFile =
|
|
180
|
+
var deleteFile = async (url) => {
|
|
174
181
|
const key = url.split(URL_PREFIX)[1];
|
|
182
|
+
if (!checkClient(client)) return;
|
|
175
183
|
if (key) {
|
|
176
184
|
try {
|
|
177
185
|
await client.send(
|
|
@@ -187,7 +195,12 @@ var deleteFile = (client) => async (url) => {
|
|
|
187
195
|
}
|
|
188
196
|
return false;
|
|
189
197
|
};
|
|
190
|
-
|
|
198
|
+
function checkClient(client2) {
|
|
199
|
+
if (!client2) throw new Error("Client does not exist");
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
var uploadBlob = async (file, key) => {
|
|
203
|
+
if (!checkClient(client)) return;
|
|
191
204
|
const fileBuffer = await file.arrayBuffer();
|
|
192
205
|
return client.send(
|
|
193
206
|
new import_client_s3.PutObjectCommand({
|
|
@@ -202,7 +215,7 @@ var uploadBlob = (client) => async (file, key) => {
|
|
|
202
215
|
};
|
|
203
216
|
|
|
204
217
|
// src/file/put.ts
|
|
205
|
-
var getFileUploadPutRoute = (options
|
|
218
|
+
var getFileUploadPutRoute = (options) => async (req) => {
|
|
206
219
|
const ctx = getContext(req);
|
|
207
220
|
if (!ctx?.userId || ctx.isRefreshID)
|
|
208
221
|
return import_server3.NextResponse.json({ error: "unauthorized" }, { status: 401 });
|
|
@@ -210,6 +223,7 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
210
223
|
const file = formData.get("file");
|
|
211
224
|
if (!file) return import_server3.NextResponse.json({ error: "no file" }, { status: 400 });
|
|
212
225
|
const data = formData.get("data");
|
|
226
|
+
const async = formData.get("async");
|
|
213
227
|
const inputData = {
|
|
214
228
|
type: formData.get("type") + "",
|
|
215
229
|
userId: ctx.userId,
|
|
@@ -217,7 +231,8 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
217
231
|
};
|
|
218
232
|
const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
|
|
219
233
|
const url = getDownloadURL(fileKey);
|
|
220
|
-
|
|
234
|
+
if (async) (0, import_functions.waitUntil)(uploadBlob(file, fileKey));
|
|
235
|
+
else await uploadBlob(file, fileKey);
|
|
221
236
|
const onUploadResponse = await options.onUpload({
|
|
222
237
|
...inputData,
|
|
223
238
|
url
|
|
@@ -230,16 +245,15 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
230
245
|
|
|
231
246
|
// src/file/setup.ts
|
|
232
247
|
function setupFileUpload(options) {
|
|
233
|
-
const client = getS3Client();
|
|
234
248
|
return {
|
|
235
|
-
PUT: getFileUploadPutRoute(options
|
|
236
|
-
uploadFile: uploadFile(client),
|
|
237
|
-
deleteFile: deleteFile(client),
|
|
238
|
-
getUploadURL: getUploadURL(client),
|
|
239
|
-
getDownloadURL
|
|
249
|
+
PUT: getFileUploadPutRoute(options)
|
|
240
250
|
};
|
|
241
251
|
}
|
|
242
252
|
// Annotate the CommonJS export names for ESM import in node:
|
|
243
253
|
0 && (module.exports = {
|
|
244
|
-
|
|
254
|
+
deleteFile,
|
|
255
|
+
getDownloadURL,
|
|
256
|
+
getUploadURL,
|
|
257
|
+
setupFileUpload,
|
|
258
|
+
uploadFile
|
|
245
259
|
});
|
package/dist/file/index.d.mts
CHANGED
package/dist/file/index.d.ts
CHANGED