naystack 1.6.1 → 1.7.1
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/README.md +39 -22
- package/dist/auth/email/client.d.mts +17 -0
- package/dist/auth/email/client.d.ts +17 -0
- package/dist/auth/email/index.cjs.js +3 -3
- package/dist/auth/email/index.d.mts +6 -6
- package/dist/auth/email/index.d.ts +6 -6
- package/dist/auth/email/index.esm.js +2 -2
- package/dist/auth/email/routes/delete.d.mts +3 -3
- package/dist/auth/email/routes/delete.d.ts +3 -3
- package/dist/auth/email/routes/get.d.mts +3 -3
- package/dist/auth/email/routes/get.d.ts +3 -3
- package/dist/auth/email/routes/post.d.mts +3 -3
- package/dist/auth/email/routes/post.d.ts +3 -3
- package/dist/auth/email/routes/put.d.mts +3 -3
- package/dist/auth/email/routes/put.d.ts +3 -3
- package/dist/auth/email/token.cjs.js +3 -3
- package/dist/auth/email/token.d.mts +2 -2
- package/dist/auth/email/token.d.ts +2 -2
- package/dist/auth/email/token.esm.js +3 -3
- package/dist/auth/email/types.d.mts +5 -4
- package/dist/auth/email/types.d.ts +5 -4
- package/dist/auth/email/utils.d.mts +3 -3
- package/dist/auth/email/utils.d.ts +3 -3
- package/dist/auth/google/get.d.mts +3 -3
- package/dist/auth/google/get.d.ts +3 -3
- package/dist/auth/google/index.cjs.js +3 -3
- package/dist/auth/google/index.d.mts +7 -7
- package/dist/auth/google/index.d.ts +7 -7
- package/dist/auth/google/index.esm.js +2 -2
- package/dist/auth/index.cjs.js +12 -12
- package/dist/auth/index.d.mts +3 -3
- package/dist/auth/index.d.ts +3 -3
- package/dist/auth/index.esm.js +9 -9
- package/dist/auth/instagram/index.cjs.js +6 -6
- package/dist/auth/instagram/index.d.mts +8 -9
- package/dist/auth/instagram/index.d.ts +8 -9
- package/dist/auth/instagram/index.esm.js +5 -5
- package/dist/auth/instagram/route.cjs.js +3 -3
- package/dist/auth/instagram/route.d.mts +3 -3
- package/dist/auth/instagram/route.d.ts +3 -3
- package/dist/auth/instagram/route.esm.js +3 -3
- package/dist/file/client.d.mts +7 -7
- package/dist/file/client.d.ts +7 -7
- package/dist/graphql/client.d.mts +5 -5
- package/dist/graphql/client.d.ts +5 -5
- package/dist/graphql/index.cjs.js +20 -6
- package/dist/graphql/index.d.mts +2 -2
- package/dist/graphql/index.d.ts +2 -2
- package/dist/graphql/index.esm.js +18 -4
- package/dist/graphql/init.cjs.js +3 -3
- package/dist/graphql/init.d.mts +4 -4
- package/dist/graphql/init.d.ts +4 -4
- package/dist/graphql/init.esm.js +2 -2
- package/dist/graphql/utils.cjs.js +17 -3
- package/dist/graphql/utils.d.mts +16 -16
- package/dist/graphql/utils.d.ts +16 -16
- package/dist/graphql/utils.esm.js +16 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/socials/instagram/webhook.d.mts +2 -2
- package/dist/socials/instagram/webhook.d.ts +2 -2
- package/dist/utils/route.d.mts +20 -0
- package/dist/utils/route.d.ts +20 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { Context } from '../../graphql/types.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { SetupEmailAuthOptions } from './types.mjs';
|
|
4
4
|
import '../types.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -8,11 +8,11 @@ import '../types.mjs';
|
|
|
8
8
|
* if `TURNSTILE_KEY` is set, validates the Cloudflare Turnstile captcha.
|
|
9
9
|
*
|
|
10
10
|
* @param req - The NextRequest (body is read via `req.json()`).
|
|
11
|
-
* @param options - Same `
|
|
11
|
+
* @param options - Same `SetupEmailAuthOptions` passed to `setupEmailAuth`; used for `onError` when validation fails.
|
|
12
12
|
* @returns Promise of either `{ error: NextResponse }` (validation failed) or `{ data: { password, ...rest } }` with the validated payload.
|
|
13
13
|
* @category Auth
|
|
14
14
|
*/
|
|
15
|
-
declare function massageRequest(req: NextRequest, options:
|
|
15
|
+
declare function massageRequest(req: NextRequest, options: SetupEmailAuthOptions): Promise<{
|
|
16
16
|
error?: NextResponse;
|
|
17
17
|
data?: {
|
|
18
18
|
password: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
import { Context } from '../../graphql/types.js';
|
|
3
|
-
import {
|
|
3
|
+
import { SetupEmailAuthOptions } from './types.js';
|
|
4
4
|
import '../types.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -8,11 +8,11 @@ import '../types.js';
|
|
|
8
8
|
* if `TURNSTILE_KEY` is set, validates the Cloudflare Turnstile captcha.
|
|
9
9
|
*
|
|
10
10
|
* @param req - The NextRequest (body is read via `req.json()`).
|
|
11
|
-
* @param options - Same `
|
|
11
|
+
* @param options - Same `SetupEmailAuthOptions` passed to `setupEmailAuth`; used for `onError` when validation fails.
|
|
12
12
|
* @returns Promise of either `{ error: NextResponse }` (validation failed) or `{ data: { password, ...rest } }` with the validated payload.
|
|
13
13
|
* @category Auth
|
|
14
14
|
*/
|
|
15
|
-
declare function massageRequest(req: NextRequest, options:
|
|
15
|
+
declare function massageRequest(req: NextRequest, options: SetupEmailAuthOptions): Promise<{
|
|
16
16
|
error?: NextResponse;
|
|
17
17
|
data?: {
|
|
18
18
|
password: string;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { SetupGoogleAuthOptions } from './index.mjs';
|
|
3
3
|
import 'googleapis';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the GET route handler for Google OAuth (initiate and callback).
|
|
7
|
-
* @param options -
|
|
7
|
+
* @param options - SetupGoogleAuthOptions
|
|
8
8
|
* @returns Async route handler
|
|
9
9
|
*/
|
|
10
|
-
declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, }:
|
|
10
|
+
declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, }: SetupGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
11
11
|
|
|
12
12
|
export { getGoogleGetRoute };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { SetupGoogleAuthOptions } from './index.js';
|
|
3
3
|
import 'googleapis';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the GET route handler for Google OAuth (initiate and callback).
|
|
7
|
-
* @param options -
|
|
7
|
+
* @param options - SetupGoogleAuthOptions
|
|
8
8
|
* @returns Async route handler
|
|
9
9
|
*/
|
|
10
|
-
declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, }:
|
|
10
|
+
declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, }: SetupGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
11
11
|
|
|
12
12
|
export { getGoogleGetRoute };
|
|
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/auth/google/index.ts
|
|
21
21
|
var google_exports = {};
|
|
22
22
|
__export(google_exports, {
|
|
23
|
-
|
|
23
|
+
setupGoogleAuth: () => setupGoogleAuth
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(google_exports);
|
|
26
26
|
|
|
@@ -172,12 +172,12 @@ var getGoogleGetRoute = ({
|
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
// src/auth/google/index.ts
|
|
175
|
-
function
|
|
175
|
+
function setupGoogleAuth(props) {
|
|
176
176
|
return {
|
|
177
177
|
GET: getGoogleGetRoute(props)
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
// Annotate the CommonJS export names for ESM import in node:
|
|
181
181
|
0 && (module.exports = {
|
|
182
|
-
|
|
182
|
+
setupGoogleAuth
|
|
183
183
|
});
|
|
@@ -4,7 +4,7 @@ import { oauth2_v2 } from 'googleapis';
|
|
|
4
4
|
/** Google OAuth userinfo schema (from googleapis). */
|
|
5
5
|
type Schema$Userinfo = oauth2_v2.Schema$Userinfo;
|
|
6
6
|
/**
|
|
7
|
-
* Options for initializing Google OAuth via {@link
|
|
7
|
+
* Options for initializing Google OAuth via {@link setupGoogleAuth}.
|
|
8
8
|
*
|
|
9
9
|
* @property getUserIdFromEmail - Given Google userinfo (email, name, picture, etc.), resolves to your app's user id. Return `null` if the user should not be authenticated.
|
|
10
10
|
* @property redirectURL - Where to redirect after successful Google auth (e.g. `"/dashboard"`).
|
|
@@ -12,7 +12,7 @@ type Schema$Userinfo = oauth2_v2.Schema$Userinfo;
|
|
|
12
12
|
*
|
|
13
13
|
* @category Auth
|
|
14
14
|
*/
|
|
15
|
-
interface
|
|
15
|
+
interface SetupGoogleAuthOptions {
|
|
16
16
|
getUserIdFromEmail: (email: Schema$Userinfo, data?: string) => Promise<number | null>;
|
|
17
17
|
redirectURL: string;
|
|
18
18
|
errorRedirectURL?: string;
|
|
@@ -25,15 +25,15 @@ interface InitGoogleAuthOptions {
|
|
|
25
25
|
*
|
|
26
26
|
* Requires env vars: `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, `NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT`.
|
|
27
27
|
*
|
|
28
|
-
* @param props - Options. See {@link
|
|
28
|
+
* @param props - Options. See {@link SetupGoogleAuthOptions}.
|
|
29
29
|
* @returns Object with `GET` — export as your route's GET handler.
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
32
|
* ```ts
|
|
33
33
|
* // app/api/(auth)/google/route.ts
|
|
34
|
-
* import {
|
|
34
|
+
* import { setupGoogleAuth } from "naystack/auth";
|
|
35
35
|
*
|
|
36
|
-
* export const { GET } =
|
|
36
|
+
* export const { GET } = setupGoogleAuth({
|
|
37
37
|
* getUserIdFromEmail: async (googleUser) => {
|
|
38
38
|
* // Find or create user by Google email
|
|
39
39
|
* const user = await findOrCreateUserByEmail(googleUser.email!);
|
|
@@ -46,8 +46,8 @@ interface InitGoogleAuthOptions {
|
|
|
46
46
|
*
|
|
47
47
|
* @category Auth
|
|
48
48
|
*/
|
|
49
|
-
declare function
|
|
49
|
+
declare function setupGoogleAuth(props: SetupGoogleAuthOptions): {
|
|
50
50
|
GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
export { type
|
|
53
|
+
export { type SetupGoogleAuthOptions, setupGoogleAuth };
|
|
@@ -4,7 +4,7 @@ import { oauth2_v2 } from 'googleapis';
|
|
|
4
4
|
/** Google OAuth userinfo schema (from googleapis). */
|
|
5
5
|
type Schema$Userinfo = oauth2_v2.Schema$Userinfo;
|
|
6
6
|
/**
|
|
7
|
-
* Options for initializing Google OAuth via {@link
|
|
7
|
+
* Options for initializing Google OAuth via {@link setupGoogleAuth}.
|
|
8
8
|
*
|
|
9
9
|
* @property getUserIdFromEmail - Given Google userinfo (email, name, picture, etc.), resolves to your app's user id. Return `null` if the user should not be authenticated.
|
|
10
10
|
* @property redirectURL - Where to redirect after successful Google auth (e.g. `"/dashboard"`).
|
|
@@ -12,7 +12,7 @@ type Schema$Userinfo = oauth2_v2.Schema$Userinfo;
|
|
|
12
12
|
*
|
|
13
13
|
* @category Auth
|
|
14
14
|
*/
|
|
15
|
-
interface
|
|
15
|
+
interface SetupGoogleAuthOptions {
|
|
16
16
|
getUserIdFromEmail: (email: Schema$Userinfo, data?: string) => Promise<number | null>;
|
|
17
17
|
redirectURL: string;
|
|
18
18
|
errorRedirectURL?: string;
|
|
@@ -25,15 +25,15 @@ interface InitGoogleAuthOptions {
|
|
|
25
25
|
*
|
|
26
26
|
* Requires env vars: `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, `NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT`.
|
|
27
27
|
*
|
|
28
|
-
* @param props - Options. See {@link
|
|
28
|
+
* @param props - Options. See {@link SetupGoogleAuthOptions}.
|
|
29
29
|
* @returns Object with `GET` — export as your route's GET handler.
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
32
|
* ```ts
|
|
33
33
|
* // app/api/(auth)/google/route.ts
|
|
34
|
-
* import {
|
|
34
|
+
* import { setupGoogleAuth } from "naystack/auth";
|
|
35
35
|
*
|
|
36
|
-
* export const { GET } =
|
|
36
|
+
* export const { GET } = setupGoogleAuth({
|
|
37
37
|
* getUserIdFromEmail: async (googleUser) => {
|
|
38
38
|
* // Find or create user by Google email
|
|
39
39
|
* const user = await findOrCreateUserByEmail(googleUser.email!);
|
|
@@ -46,8 +46,8 @@ interface InitGoogleAuthOptions {
|
|
|
46
46
|
*
|
|
47
47
|
* @category Auth
|
|
48
48
|
*/
|
|
49
|
-
declare function
|
|
49
|
+
declare function setupGoogleAuth(props: SetupGoogleAuthOptions): {
|
|
50
50
|
GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
export { type
|
|
53
|
+
export { type SetupGoogleAuthOptions, setupGoogleAuth };
|
|
@@ -146,11 +146,11 @@ var getGoogleGetRoute = ({
|
|
|
146
146
|
};
|
|
147
147
|
|
|
148
148
|
// src/auth/google/index.ts
|
|
149
|
-
function
|
|
149
|
+
function setupGoogleAuth(props) {
|
|
150
150
|
return {
|
|
151
151
|
GET: getGoogleGetRoute(props)
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
export {
|
|
155
|
-
|
|
155
|
+
setupGoogleAuth
|
|
156
156
|
};
|
package/dist/auth/index.cjs.js
CHANGED
|
@@ -33,11 +33,11 @@ __export(auth_exports, {
|
|
|
33
33
|
AuthFetch: () => AuthFetch,
|
|
34
34
|
checkAuthStatus: () => checkAuthStatus,
|
|
35
35
|
getContext: () => getContext,
|
|
36
|
-
getEmailAuthRoutes: () => getEmailAuthRoutes,
|
|
37
36
|
getRefreshToken: () => getRefreshToken,
|
|
38
37
|
getRefreshedInstagramAccessToken: () => getRefreshedInstagramAccessToken,
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
setupEmailAuth: () => setupEmailAuth,
|
|
39
|
+
setupGoogleAuth: () => setupGoogleAuth,
|
|
40
|
+
setupInstagramAuth: () => setupInstagramAuth
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(auth_exports);
|
|
43
43
|
|
|
@@ -178,10 +178,10 @@ function getUserIdFromRefreshToken(refreshToken) {
|
|
|
178
178
|
}
|
|
179
179
|
return null;
|
|
180
180
|
}
|
|
181
|
-
function getUserIdFromAccessToken(
|
|
182
|
-
if (
|
|
181
|
+
function getUserIdFromAccessToken(accessToken) {
|
|
182
|
+
if (accessToken)
|
|
183
183
|
try {
|
|
184
|
-
const decoded = (0, import_jsonwebtoken.verify)(
|
|
184
|
+
const decoded = (0, import_jsonwebtoken.verify)(accessToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
185
185
|
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
186
186
|
return decoded.id;
|
|
187
187
|
} catch (e) {
|
|
@@ -418,7 +418,7 @@ function AuthFetch() {
|
|
|
418
418
|
}
|
|
419
419
|
|
|
420
420
|
// src/auth/email/index.ts
|
|
421
|
-
function
|
|
421
|
+
function setupEmailAuth(options) {
|
|
422
422
|
const { allowedOrigins } = options;
|
|
423
423
|
return {
|
|
424
424
|
GET: withCors(getGetRoute(options), allowedOrigins),
|
|
@@ -521,7 +521,7 @@ var getGoogleGetRoute = ({
|
|
|
521
521
|
};
|
|
522
522
|
|
|
523
523
|
// src/auth/google/index.ts
|
|
524
|
-
function
|
|
524
|
+
function setupGoogleAuth(props) {
|
|
525
525
|
return {
|
|
526
526
|
GET: getGoogleGetRoute(props)
|
|
527
527
|
};
|
|
@@ -627,7 +627,7 @@ var getInstagramRoute = ({
|
|
|
627
627
|
};
|
|
628
628
|
|
|
629
629
|
// src/auth/instagram/index.ts
|
|
630
|
-
function
|
|
630
|
+
function setupInstagramAuth(props) {
|
|
631
631
|
return {
|
|
632
632
|
GET: getInstagramRoute(props)
|
|
633
633
|
};
|
|
@@ -644,9 +644,9 @@ async function getRefreshToken() {
|
|
|
644
644
|
AuthFetch,
|
|
645
645
|
checkAuthStatus,
|
|
646
646
|
getContext,
|
|
647
|
-
getEmailAuthRoutes,
|
|
648
647
|
getRefreshToken,
|
|
649
648
|
getRefreshedInstagramAccessToken,
|
|
650
|
-
|
|
651
|
-
|
|
649
|
+
setupEmailAuth,
|
|
650
|
+
setupGoogleAuth,
|
|
651
|
+
setupInstagramAuth
|
|
652
652
|
});
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { setupEmailAuth } from './email/index.mjs';
|
|
2
|
+
export { setupGoogleAuth } from './google/index.mjs';
|
|
3
|
+
export { setupInstagramAuth } from './instagram/index.mjs';
|
|
4
4
|
export { getRefreshToken } from './utils/token.mjs';
|
|
5
5
|
export { default as AuthFetch } from './email/server.mjs';
|
|
6
6
|
export { checkAuthStatus } from './email/token.mjs';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { setupEmailAuth } from './email/index.js';
|
|
2
|
+
export { setupGoogleAuth } from './google/index.js';
|
|
3
|
+
export { setupInstagramAuth } from './instagram/index.js';
|
|
4
4
|
export { getRefreshToken } from './utils/token.js';
|
|
5
5
|
export { default as AuthFetch } from './email/server.js';
|
|
6
6
|
export { checkAuthStatus } from './email/token.js';
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -135,10 +135,10 @@ function getUserIdFromRefreshToken(refreshToken) {
|
|
|
135
135
|
}
|
|
136
136
|
return null;
|
|
137
137
|
}
|
|
138
|
-
function getUserIdFromAccessToken(
|
|
139
|
-
if (
|
|
138
|
+
function getUserIdFromAccessToken(accessToken) {
|
|
139
|
+
if (accessToken)
|
|
140
140
|
try {
|
|
141
|
-
const decoded = verify(
|
|
141
|
+
const decoded = verify(accessToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
142
142
|
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
143
143
|
return decoded.id;
|
|
144
144
|
} catch (e) {
|
|
@@ -379,7 +379,7 @@ function AuthFetch() {
|
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
// src/auth/email/index.ts
|
|
382
|
-
function
|
|
382
|
+
function setupEmailAuth(options) {
|
|
383
383
|
const { allowedOrigins } = options;
|
|
384
384
|
return {
|
|
385
385
|
GET: withCors(getGetRoute(options), allowedOrigins),
|
|
@@ -482,7 +482,7 @@ var getGoogleGetRoute = ({
|
|
|
482
482
|
};
|
|
483
483
|
|
|
484
484
|
// src/auth/google/index.ts
|
|
485
|
-
function
|
|
485
|
+
function setupGoogleAuth(props) {
|
|
486
486
|
return {
|
|
487
487
|
GET: getGoogleGetRoute(props)
|
|
488
488
|
};
|
|
@@ -588,7 +588,7 @@ var getInstagramRoute = ({
|
|
|
588
588
|
};
|
|
589
589
|
|
|
590
590
|
// src/auth/instagram/index.ts
|
|
591
|
-
function
|
|
591
|
+
function setupInstagramAuth(props) {
|
|
592
592
|
return {
|
|
593
593
|
GET: getInstagramRoute(props)
|
|
594
594
|
};
|
|
@@ -604,9 +604,9 @@ export {
|
|
|
604
604
|
AuthFetch,
|
|
605
605
|
checkAuthStatus,
|
|
606
606
|
getContext,
|
|
607
|
-
getEmailAuthRoutes,
|
|
608
607
|
getRefreshToken,
|
|
609
608
|
getRefreshedInstagramAccessToken,
|
|
610
|
-
|
|
611
|
-
|
|
609
|
+
setupEmailAuth,
|
|
610
|
+
setupGoogleAuth,
|
|
611
|
+
setupInstagramAuth
|
|
612
612
|
};
|
|
@@ -21,7 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var instagram_exports = {};
|
|
22
22
|
__export(instagram_exports, {
|
|
23
23
|
getRefreshedInstagramAccessToken: () => getRefreshedInstagramAccessToken,
|
|
24
|
-
|
|
24
|
+
setupInstagramAuth: () => setupInstagramAuth
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(instagram_exports);
|
|
27
27
|
|
|
@@ -86,10 +86,10 @@ function getEnv(key, skipCheck) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// src/auth/email/token.ts
|
|
89
|
-
function getUserIdFromAccessToken(
|
|
90
|
-
if (
|
|
89
|
+
function getUserIdFromAccessToken(accessToken) {
|
|
90
|
+
if (accessToken)
|
|
91
91
|
try {
|
|
92
|
-
const decoded = (0, import_jsonwebtoken.verify)(
|
|
92
|
+
const decoded = (0, import_jsonwebtoken.verify)(accessToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
93
93
|
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
94
94
|
return decoded.id;
|
|
95
95
|
} catch (e) {
|
|
@@ -196,7 +196,7 @@ var getInstagramRoute = ({
|
|
|
196
196
|
};
|
|
197
197
|
|
|
198
198
|
// src/auth/instagram/index.ts
|
|
199
|
-
function
|
|
199
|
+
function setupInstagramAuth(props) {
|
|
200
200
|
return {
|
|
201
201
|
GET: getInstagramRoute(props)
|
|
202
202
|
};
|
|
@@ -204,5 +204,5 @@ function initInstagramAuth(props) {
|
|
|
204
204
|
// Annotate the CommonJS export names for ESM import in node:
|
|
205
205
|
0 && (module.exports = {
|
|
206
206
|
getRefreshedInstagramAccessToken,
|
|
207
|
-
|
|
207
|
+
setupInstagramAuth
|
|
208
208
|
});
|
|
@@ -3,7 +3,7 @@ export { getRefreshedInstagramAccessToken } from './utils.mjs';
|
|
|
3
3
|
import { InstagramUser } from '../../socials/instagram/types.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Options for initializing Instagram OAuth via {@link
|
|
6
|
+
* Options for initializing Instagram OAuth via {@link setupInstagramAuth}.
|
|
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
9
|
* @property redirectURL - Where to redirect after successful Instagram auth.
|
|
@@ -11,7 +11,7 @@ import { InstagramUser } from '../../socials/instagram/types.mjs';
|
|
|
11
11
|
*
|
|
12
12
|
* @category Auth
|
|
13
13
|
*/
|
|
14
|
-
interface
|
|
14
|
+
interface SetupInstagramAuthOptions {
|
|
15
15
|
onUser: (data: InstagramUser, id: number | null, accessToken: string) => Promise<string | void>;
|
|
16
16
|
redirectURL: string;
|
|
17
17
|
errorRedirectURL: string;
|
|
@@ -23,28 +23,27 @@ interface InitInstagramAuthOptions {
|
|
|
23
23
|
*
|
|
24
24
|
* Requires env vars: `INSTAGRAM_CLIENT_ID`, `INSTAGRAM_CLIENT_SECRET`, `NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT`.
|
|
25
25
|
*
|
|
26
|
-
* @param props - Options. See {@link
|
|
26
|
+
* @param props - Options. See {@link SetupInstagramAuthOptions}.
|
|
27
27
|
* @returns Object with `GET` (route handler) and `getRefreshedAccessToken` (refreshes a long-lived token).
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
31
31
|
* // app/api/(auth)/instagram/route.ts
|
|
32
|
-
* import {
|
|
32
|
+
* import { setupInstagramAuth } from "naystack/auth";
|
|
33
33
|
*
|
|
34
|
-
* export const { GET
|
|
34
|
+
* export const { GET } = setupInstagramAuth({
|
|
35
35
|
* onUser: async (igUser, appUserId, accessToken) => {
|
|
36
36
|
* await saveInstagramUser(appUserId, igUser, accessToken);
|
|
37
37
|
* },
|
|
38
|
-
*
|
|
38
|
+
* redirectURL: "/dashboard",
|
|
39
39
|
* errorRedirectURL: "/login",
|
|
40
|
-
* refreshKey: process.env.REFRESH_KEY!,
|
|
41
40
|
* });
|
|
42
41
|
* ```
|
|
43
42
|
*
|
|
44
43
|
* @category Auth
|
|
45
44
|
*/
|
|
46
|
-
declare function
|
|
45
|
+
declare function setupInstagramAuth(props: SetupInstagramAuthOptions): {
|
|
47
46
|
GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
|
|
48
47
|
};
|
|
49
48
|
|
|
50
|
-
export { type
|
|
49
|
+
export { type SetupInstagramAuthOptions, setupInstagramAuth };
|
|
@@ -3,7 +3,7 @@ export { getRefreshedInstagramAccessToken } from './utils.js';
|
|
|
3
3
|
import { InstagramUser } from '../../socials/instagram/types.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Options for initializing Instagram OAuth via {@link
|
|
6
|
+
* Options for initializing Instagram OAuth via {@link setupInstagramAuth}.
|
|
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
9
|
* @property redirectURL - Where to redirect after successful Instagram auth.
|
|
@@ -11,7 +11,7 @@ import { InstagramUser } from '../../socials/instagram/types.js';
|
|
|
11
11
|
*
|
|
12
12
|
* @category Auth
|
|
13
13
|
*/
|
|
14
|
-
interface
|
|
14
|
+
interface SetupInstagramAuthOptions {
|
|
15
15
|
onUser: (data: InstagramUser, id: number | null, accessToken: string) => Promise<string | void>;
|
|
16
16
|
redirectURL: string;
|
|
17
17
|
errorRedirectURL: string;
|
|
@@ -23,28 +23,27 @@ interface InitInstagramAuthOptions {
|
|
|
23
23
|
*
|
|
24
24
|
* Requires env vars: `INSTAGRAM_CLIENT_ID`, `INSTAGRAM_CLIENT_SECRET`, `NEXT_PUBLIC_INSTAGRAM_AUTH_ENDPOINT`.
|
|
25
25
|
*
|
|
26
|
-
* @param props - Options. See {@link
|
|
26
|
+
* @param props - Options. See {@link SetupInstagramAuthOptions}.
|
|
27
27
|
* @returns Object with `GET` (route handler) and `getRefreshedAccessToken` (refreshes a long-lived token).
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
31
31
|
* // app/api/(auth)/instagram/route.ts
|
|
32
|
-
* import {
|
|
32
|
+
* import { setupInstagramAuth } from "naystack/auth";
|
|
33
33
|
*
|
|
34
|
-
* export const { GET
|
|
34
|
+
* export const { GET } = setupInstagramAuth({
|
|
35
35
|
* onUser: async (igUser, appUserId, accessToken) => {
|
|
36
36
|
* await saveInstagramUser(appUserId, igUser, accessToken);
|
|
37
37
|
* },
|
|
38
|
-
*
|
|
38
|
+
* redirectURL: "/dashboard",
|
|
39
39
|
* errorRedirectURL: "/login",
|
|
40
|
-
* refreshKey: process.env.REFRESH_KEY!,
|
|
41
40
|
* });
|
|
42
41
|
* ```
|
|
43
42
|
*
|
|
44
43
|
* @category Auth
|
|
45
44
|
*/
|
|
46
|
-
declare function
|
|
45
|
+
declare function setupInstagramAuth(props: SetupInstagramAuthOptions): {
|
|
47
46
|
GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
|
|
48
47
|
};
|
|
49
48
|
|
|
50
|
-
export { type
|
|
49
|
+
export { type SetupInstagramAuthOptions, setupInstagramAuth };
|
|
@@ -59,10 +59,10 @@ function getEnv(key, skipCheck) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// src/auth/email/token.ts
|
|
62
|
-
function getUserIdFromAccessToken(
|
|
63
|
-
if (
|
|
62
|
+
function getUserIdFromAccessToken(accessToken) {
|
|
63
|
+
if (accessToken)
|
|
64
64
|
try {
|
|
65
|
-
const decoded = verify(
|
|
65
|
+
const decoded = verify(accessToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
66
66
|
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
67
67
|
return decoded.id;
|
|
68
68
|
} catch (e) {
|
|
@@ -169,12 +169,12 @@ var getInstagramRoute = ({
|
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
// src/auth/instagram/index.ts
|
|
172
|
-
function
|
|
172
|
+
function setupInstagramAuth(props) {
|
|
173
173
|
return {
|
|
174
174
|
GET: getInstagramRoute(props)
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
177
|
export {
|
|
178
178
|
getRefreshedInstagramAccessToken,
|
|
179
|
-
|
|
179
|
+
setupInstagramAuth
|
|
180
180
|
};
|
|
@@ -83,10 +83,10 @@ function getEnv(key, skipCheck) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// src/auth/email/token.ts
|
|
86
|
-
function getUserIdFromAccessToken(
|
|
87
|
-
if (
|
|
86
|
+
function getUserIdFromAccessToken(accessToken) {
|
|
87
|
+
if (accessToken)
|
|
88
88
|
try {
|
|
89
|
-
const decoded = (0, import_jsonwebtoken.verify)(
|
|
89
|
+
const decoded = (0, import_jsonwebtoken.verify)(accessToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
90
90
|
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
91
91
|
return decoded.id;
|
|
92
92
|
} catch (e) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { SetupInstagramAuthOptions } from './index.mjs';
|
|
3
3
|
import './utils.mjs';
|
|
4
4
|
import '../../socials/instagram/types.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns the GET route handler for Instagram OAuth callback.
|
|
8
|
-
* @param options -
|
|
8
|
+
* @param options - SetupInstagramAuthOptions (onUser, redirect URLs)
|
|
9
9
|
* @returns Async route handler for the OAuth callback
|
|
10
10
|
*/
|
|
11
|
-
declare const getInstagramRoute: ({ redirectURL, errorRedirectURL, onUser, }:
|
|
11
|
+
declare const getInstagramRoute: ({ redirectURL, errorRedirectURL, onUser, }: SetupInstagramAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
12
12
|
|
|
13
13
|
export { getInstagramRoute };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { SetupInstagramAuthOptions } from './index.js';
|
|
3
3
|
import './utils.js';
|
|
4
4
|
import '../../socials/instagram/types.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns the GET route handler for Instagram OAuth callback.
|
|
8
|
-
* @param options -
|
|
8
|
+
* @param options - SetupInstagramAuthOptions (onUser, redirect URLs)
|
|
9
9
|
* @returns Async route handler for the OAuth callback
|
|
10
10
|
*/
|
|
11
|
-
declare const getInstagramRoute: ({ redirectURL, errorRedirectURL, onUser, }:
|
|
11
|
+
declare const getInstagramRoute: ({ redirectURL, errorRedirectURL, onUser, }: SetupInstagramAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
|
|
12
12
|
|
|
13
13
|
export { getInstagramRoute };
|
|
@@ -59,10 +59,10 @@ function getEnv(key, skipCheck) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// src/auth/email/token.ts
|
|
62
|
-
function getUserIdFromAccessToken(
|
|
63
|
-
if (
|
|
62
|
+
function getUserIdFromAccessToken(accessToken) {
|
|
63
|
+
if (accessToken)
|
|
64
64
|
try {
|
|
65
|
-
const decoded = verify(
|
|
65
|
+
const decoded = verify(accessToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
|
|
66
66
|
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
67
67
|
return decoded.id;
|
|
68
68
|
} catch (e) {
|
package/dist/file/client.d.mts
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
* The endpoint is read from `NEXT_PUBLIC_FILE_ENDPOINT` env var. The file is sent as multipart form data
|
|
6
6
|
* along with a `type` string and optional JSON `data` for metadata.
|
|
7
7
|
*
|
|
8
|
-
* @returns A function `(file, type,
|
|
8
|
+
* @returns A function `(file, type, config?) => Promise<FileUploadResponseType | null>`.
|
|
9
9
|
* - `file` — `File` or `Blob` to upload.
|
|
10
10
|
* - `type` — String category (e.g. `"avatar"`, `"DealDocument"`); sent as form field `type`.
|
|
11
|
-
* - `
|
|
12
|
-
*
|
|
11
|
+
* - `config` — Optional object with:
|
|
12
|
+
* - `data` — JSON-serializable metadata object; sent as form field `data`.
|
|
13
|
+
* - `async` — If `true`, the upload is processed asynchronously on the server.
|
|
14
|
+
* Resolves to the JSON response `{ url, data }` or `null`.
|
|
13
15
|
*
|
|
14
16
|
* @example
|
|
15
17
|
* ```tsx
|
|
@@ -23,9 +25,7 @@
|
|
|
23
25
|
* setUploading(true);
|
|
24
26
|
* try {
|
|
25
27
|
* const result = await uploadFile(file, "DealDocument", {
|
|
26
|
-
* dealId,
|
|
27
|
-
* fileName: file.name,
|
|
28
|
-
* category: "Contract",
|
|
28
|
+
* data: { dealId, fileName: file.name, category: "Contract" },
|
|
29
29
|
* });
|
|
30
30
|
* if (result?.url) {
|
|
31
31
|
* console.log("Uploaded:", result.url);
|
|
@@ -50,7 +50,7 @@ declare const useFileUpload: () => (file: File | Blob, type: string, config?: {
|
|
|
50
50
|
* Shape of the JSON response from the file upload PUT endpoint.
|
|
51
51
|
*
|
|
52
52
|
* @property url - The public S3 URL of the uploaded file.
|
|
53
|
-
* @property
|
|
53
|
+
* @property data - The return value from the `onUpload` callback in `setupFileUpload`.
|
|
54
54
|
*
|
|
55
55
|
* @category File
|
|
56
56
|
*/
|