naystack 1.4.0 → 1.4.2

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.
@@ -1,6 +1,4 @@
1
1
  import React__default, { Dispatch, SetStateAction } from 'react';
2
- import { UserInput } from '../types.mjs';
3
- import 'next/server';
4
2
 
5
3
  declare const TokenContext: React__default.Context<{
6
4
  token: string | null;
@@ -12,8 +10,8 @@ declare const getAuthWrapper: (endpoint: string) => ({ children }: {
12
10
  declare function useToken(): string | null;
13
11
  declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
14
12
  declare function getEmailAuthUtils(endpoint: string): {
15
- useSignUp: () => (data: UserInput) => Promise<string | null>;
16
- useLogin: () => (data: UserInput) => Promise<string | null>;
13
+ useSignUp: () => (data: object) => Promise<string | null>;
14
+ useLogin: () => (data: object) => Promise<string | null>;
17
15
  useLogout: () => (data?: object) => Promise<void>;
18
16
  };
19
17
 
@@ -1,6 +1,4 @@
1
1
  import React__default, { Dispatch, SetStateAction } from 'react';
2
- import { UserInput } from '../types.js';
3
- import 'next/server';
4
2
 
5
3
  declare const TokenContext: React__default.Context<{
6
4
  token: string | null;
@@ -12,8 +10,8 @@ declare const getAuthWrapper: (endpoint: string) => ({ children }: {
12
10
  declare function useToken(): string | null;
13
11
  declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
14
12
  declare function getEmailAuthUtils(endpoint: string): {
15
- useSignUp: () => (data: UserInput) => Promise<string | null>;
16
- useLogin: () => (data: UserInput) => Promise<string | null>;
13
+ useSignUp: () => (data: object) => Promise<string | null>;
14
+ useLogin: () => (data: object) => Promise<string | null>;
17
15
  useLogout: () => (data?: object) => Promise<void>;
18
16
  };
19
17
 
@@ -88,13 +88,15 @@ function handleError(status, message, onError) {
88
88
  // src/auth/email/utils.ts
89
89
  async function massageRequest(req, options) {
90
90
  const data = await req.json();
91
- if (!data.email || !data.password)
91
+ if (!data.password)
92
92
  return {
93
- error: handleError(400, "Missing email or password", options.onError)
93
+ error: handleError(400, "Missing password", options.onError)
94
94
  };
95
95
  if (options.turnstileKey) {
96
96
  if (!data.captchaToken)
97
- return { error: handleError(400, "Missing captcha", options.onError) };
97
+ return {
98
+ error: handleError(400, "Missing captchaToken", options.onError)
99
+ };
98
100
  if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
99
101
  return {
100
102
  error: handleError(400, "Invalid captcha", options.onError)
@@ -62,13 +62,15 @@ function handleError(status, message, onError) {
62
62
  // src/auth/email/utils.ts
63
63
  async function massageRequest(req, options) {
64
64
  const data = await req.json();
65
- if (!data.email || !data.password)
65
+ if (!data.password)
66
66
  return {
67
- error: handleError(400, "Missing email or password", options.onError)
67
+ error: handleError(400, "Missing password", options.onError)
68
68
  };
69
69
  if (options.turnstileKey) {
70
70
  if (!data.captchaToken)
71
- return { error: handleError(400, "Missing captcha", options.onError) };
71
+ return {
72
+ error: handleError(400, "Missing captchaToken", options.onError)
73
+ };
72
74
  if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
73
75
  return {
74
76
  error: handleError(400, "Invalid captcha", options.onError)
@@ -75,13 +75,15 @@ function verifyUser(user, password) {
75
75
  var import_jsonwebtoken2 = require("jsonwebtoken");
76
76
  async function massageRequest(req, options) {
77
77
  const data = await req.json();
78
- if (!data.email || !data.password)
78
+ if (!data.password)
79
79
  return {
80
- error: handleError(400, "Missing email or password", options.onError)
80
+ error: handleError(400, "Missing password", options.onError)
81
81
  };
82
82
  if (options.turnstileKey) {
83
83
  if (!data.captchaToken)
84
- return { error: handleError(400, "Missing captcha", options.onError) };
84
+ return {
85
+ error: handleError(400, "Missing captchaToken", options.onError)
86
+ };
85
87
  if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
86
88
  return {
87
89
  error: handleError(400, "Invalid captcha", options.onError)
@@ -51,13 +51,15 @@ function verifyUser(user, password) {
51
51
  import { verify as verify2 } from "jsonwebtoken";
52
52
  async function massageRequest(req, options) {
53
53
  const data = await req.json();
54
- if (!data.email || !data.password)
54
+ if (!data.password)
55
55
  return {
56
- error: handleError(400, "Missing email or password", options.onError)
56
+ error: handleError(400, "Missing password", options.onError)
57
57
  };
58
58
  if (options.turnstileKey) {
59
59
  if (!data.captchaToken)
60
- return { error: handleError(400, "Missing captcha", options.onError) };
60
+ return {
61
+ error: handleError(400, "Missing captchaToken", options.onError)
62
+ };
61
63
  if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
62
64
  return {
63
65
  error: handleError(400, "Invalid captcha", options.onError)
@@ -74,13 +74,15 @@ function verifyUser(user, password) {
74
74
  var import_jsonwebtoken2 = require("jsonwebtoken");
75
75
  async function massageRequest(req, options) {
76
76
  const data = await req.json();
77
- if (!data.email || !data.password)
77
+ if (!data.password)
78
78
  return {
79
- error: handleError(400, "Missing email or password", options.onError)
79
+ error: handleError(400, "Missing password", options.onError)
80
80
  };
81
81
  if (options.turnstileKey) {
82
82
  if (!data.captchaToken)
83
- return { error: handleError(400, "Missing captcha", options.onError) };
83
+ return {
84
+ error: handleError(400, "Missing captchaToken", options.onError)
85
+ };
84
86
  if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
85
87
  return {
86
88
  error: handleError(400, "Invalid captcha", options.onError)
@@ -48,13 +48,15 @@ function verifyUser(user, password) {
48
48
  import { verify as verify2 } from "jsonwebtoken";
49
49
  async function massageRequest(req, options) {
50
50
  const data = await req.json();
51
- if (!data.email || !data.password)
51
+ if (!data.password)
52
52
  return {
53
- error: handleError(400, "Missing email or password", options.onError)
53
+ error: handleError(400, "Missing password", options.onError)
54
54
  };
55
55
  if (options.turnstileKey) {
56
56
  if (!data.captchaToken)
57
- return { error: handleError(400, "Missing captcha", options.onError) };
57
+ return {
58
+ error: handleError(400, "Missing captchaToken", options.onError)
59
+ };
58
60
  if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
59
61
  return {
60
62
  error: handleError(400, "Invalid captcha", options.onError)
@@ -1,9 +1,9 @@
1
1
  import { NextRequest } from 'next/server';
2
- import { UserInput, UserOutput, ErrorHandler } from '../types.mjs';
2
+ import { UserOutput, ErrorHandler } from '../types.mjs';
3
3
 
4
4
  type InitRoutesOptions = {
5
- getUser: (data: UserInput) => Promise<UserOutput | undefined>;
6
- createUser: (user: UserInput) => Promise<UserOutput | undefined>;
5
+ getUser: (data: any) => Promise<UserOutput | undefined>;
6
+ createUser: (user: any) => Promise<UserOutput | undefined>;
7
7
  onError?: ErrorHandler;
8
8
  keys: AuthKeys;
9
9
  turnstileKey?: string;
@@ -1,9 +1,9 @@
1
1
  import { NextRequest } from 'next/server';
2
- import { UserInput, UserOutput, ErrorHandler } from '../types.js';
2
+ import { UserOutput, ErrorHandler } from '../types.js';
3
3
 
4
4
  type InitRoutesOptions = {
5
- getUser: (data: UserInput) => Promise<UserOutput | undefined>;
6
- createUser: (user: UserInput) => Promise<UserOutput | undefined>;
5
+ getUser: (data: any) => Promise<UserOutput | undefined>;
6
+ createUser: (user: any) => Promise<UserOutput | undefined>;
7
7
  onError?: ErrorHandler;
8
8
  keys: AuthKeys;
9
9
  turnstileKey?: string;
@@ -55,13 +55,15 @@ function handleError(status, message, onError) {
55
55
  // src/auth/email/utils.ts
56
56
  async function massageRequest(req, options) {
57
57
  const data = await req.json();
58
- if (!data.email || !data.password)
58
+ if (!data.password)
59
59
  return {
60
- error: handleError(400, "Missing email or password", options.onError)
60
+ error: handleError(400, "Missing password", options.onError)
61
61
  };
62
62
  if (options.turnstileKey) {
63
63
  if (!data.captchaToken)
64
- return { error: handleError(400, "Missing captcha", options.onError) };
64
+ return {
65
+ error: handleError(400, "Missing captchaToken", options.onError)
66
+ };
65
67
  if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
66
68
  return {
67
69
  error: handleError(400, "Invalid captcha", options.onError)
@@ -6,7 +6,6 @@ import '../types.mjs';
6
6
  declare function massageRequest(req: NextRequest, options: InitRoutesOptions): Promise<{
7
7
  error?: NextResponse;
8
8
  data?: {
9
- email: string;
10
9
  password: string;
11
10
  } & {
12
11
  [key: string]: unknown;
@@ -6,7 +6,6 @@ import '../types.js';
6
6
  declare function massageRequest(req: NextRequest, options: InitRoutesOptions): Promise<{
7
7
  error?: NextResponse;
8
8
  data?: {
9
- email: string;
10
9
  password: string;
11
10
  } & {
12
11
  [key: string]: unknown;
@@ -29,13 +29,15 @@ function handleError(status, message, onError) {
29
29
  // src/auth/email/utils.ts
30
30
  async function massageRequest(req, options) {
31
31
  const data = await req.json();
32
- if (!data.email || !data.password)
32
+ if (!data.password)
33
33
  return {
34
- error: handleError(400, "Missing email or password", options.onError)
34
+ error: handleError(400, "Missing password", options.onError)
35
35
  };
36
36
  if (options.turnstileKey) {
37
37
  if (!data.captchaToken)
38
- return { error: handleError(400, "Missing captcha", options.onError) };
38
+ return {
39
+ error: handleError(400, "Missing captchaToken", options.onError)
40
+ };
39
41
  if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
40
42
  return {
41
43
  error: handleError(400, "Invalid captcha", options.onError)
@@ -102,13 +102,15 @@ function handleError(status, message, onError) {
102
102
  // src/auth/email/utils.ts
103
103
  async function massageRequest(req, options) {
104
104
  const data = await req.json();
105
- if (!data.email || !data.password)
105
+ if (!data.password)
106
106
  return {
107
- error: handleError(400, "Missing email or password", options.onError)
107
+ error: handleError(400, "Missing password", options.onError)
108
108
  };
109
109
  if (options.turnstileKey) {
110
110
  if (!data.captchaToken)
111
- return { error: handleError(400, "Missing captcha", options.onError) };
111
+ return {
112
+ error: handleError(400, "Missing captchaToken", options.onError)
113
+ };
112
114
  if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
113
115
  return {
114
116
  error: handleError(400, "Invalid captcha", options.onError)
@@ -74,13 +74,15 @@ function handleError(status, message, onError) {
74
74
  // src/auth/email/utils.ts
75
75
  async function massageRequest(req, options) {
76
76
  const data = await req.json();
77
- if (!data.email || !data.password)
77
+ if (!data.password)
78
78
  return {
79
- error: handleError(400, "Missing email or password", options.onError)
79
+ error: handleError(400, "Missing password", options.onError)
80
80
  };
81
81
  if (options.turnstileKey) {
82
82
  if (!data.captchaToken)
83
- return { error: handleError(400, "Missing captcha", options.onError) };
83
+ return {
84
+ error: handleError(400, "Missing captchaToken", options.onError)
85
+ };
84
86
  if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
85
87
  return {
86
88
  error: handleError(400, "Invalid captcha", options.onError)
@@ -4,11 +4,6 @@ type ErrorHandler = (error: {
4
4
  status: number;
5
5
  message: string;
6
6
  }) => NextResponse;
7
- type UserInput = {
8
- password: string;
9
- } & {
10
- [key: string]: unknown;
11
- };
12
7
  type UserOutput = {
13
8
  id: number;
14
9
  password: string | null;
@@ -16,4 +11,4 @@ type UserOutput = {
16
11
  [key: string]: unknown;
17
12
  };
18
13
 
19
- export type { ErrorHandler, UserInput, UserOutput };
14
+ export type { ErrorHandler, UserOutput };
@@ -4,11 +4,6 @@ type ErrorHandler = (error: {
4
4
  status: number;
5
5
  message: string;
6
6
  }) => NextResponse;
7
- type UserInput = {
8
- password: string;
9
- } & {
10
- [key: string]: unknown;
11
- };
12
7
  type UserOutput = {
13
8
  id: number;
14
9
  password: string | null;
@@ -16,4 +11,4 @@ type UserOutput = {
16
11
  [key: string]: unknown;
17
12
  };
18
13
 
19
- export type { ErrorHandler, UserInput, UserOutput };
14
+ export type { ErrorHandler, UserOutput };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "A stack built with Next + GraphQL + S3 + Auth",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",