naystack 1.2.16 → 1.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/email/client.cjs.js +35 -7
- package/dist/auth/email/client.d.mts +13 -1
- package/dist/auth/email/client.d.ts +13 -1
- package/dist/auth/email/client.esm.js +34 -4
- package/dist/auth/email/index.cjs.js +23 -18
- package/dist/auth/email/index.d.mts +4 -12
- package/dist/auth/email/index.d.ts +4 -12
- package/dist/auth/email/index.esm.js +23 -18
- package/dist/auth/email/routes/delete.cjs.js +45 -1
- package/dist/auth/email/routes/delete.esm.js +45 -1
- package/dist/auth/email/routes/get.cjs.js +6 -2
- package/dist/auth/email/routes/get.d.mts +2 -2
- package/dist/auth/email/routes/get.d.ts +2 -2
- package/dist/auth/email/routes/get.esm.js +6 -2
- package/dist/auth/email/routes/post.cjs.js +3 -1
- package/dist/auth/email/routes/post.esm.js +3 -1
- package/dist/auth/email/routes/put.cjs.js +3 -0
- package/dist/auth/email/routes/put.esm.js +3 -0
- package/dist/auth/email/types.d.mts +5 -3
- package/dist/auth/email/types.d.ts +5 -3
- package/dist/auth/email/utils.cjs.js +8 -8
- package/dist/auth/email/utils.d.mts +3 -5
- package/dist/auth/email/utils.d.ts +3 -5
- package/dist/auth/email/utils.esm.js +7 -7
- package/dist/auth/index.cjs.js +23 -18
- package/dist/auth/index.d.mts +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.esm.js +23 -18
- package/dist/client/hooks.d.mts +2 -2
- package/dist/client/hooks.d.ts +2 -2
- package/dist/file/client.cjs.js +20 -23
- package/dist/file/client.d.mts +4 -10
- package/dist/file/client.d.ts +4 -10
- package/dist/file/client.esm.js +19 -22
- package/dist/file/index.cjs.js +47 -55
- package/dist/file/index.d.mts +0 -1
- package/dist/file/index.d.ts +0 -1
- package/dist/file/index.esm.js +47 -55
- package/dist/file/put.cjs.js +29 -58
- package/dist/file/put.d.mts +2 -1
- package/dist/file/put.d.ts +2 -1
- package/dist/file/put.esm.js +29 -58
- package/dist/file/setup.cjs.js +47 -55
- package/dist/file/setup.d.mts +16 -12
- package/dist/file/setup.d.ts +16 -12
- package/dist/file/setup.esm.js +47 -55
- package/dist/file/utils.cjs.js +29 -27
- package/dist/file/utils.d.mts +9 -6
- package/dist/file/utils.d.ts +9 -6
- package/dist/file/utils.esm.js +24 -22
- package/dist/graphql/client.cjs.js +11 -34
- package/dist/graphql/client.d.mts +3 -9
- package/dist/graphql/client.d.ts +3 -9
- package/dist/graphql/client.esm.js +8 -30
- package/dist/graphql/server.d.mts +2 -2
- package/dist/graphql/server.d.ts +2 -2
- package/dist/graphql/types.d.mts +2 -0
- package/dist/graphql/types.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
1
2
|
import { UserOutput, UserInput, ErrorHandler } from '../types.js';
|
|
2
|
-
import 'next/server';
|
|
3
3
|
|
|
4
4
|
type InitRoutesOptions = {
|
|
5
5
|
getUser: (email: string) => Promise<UserOutput | undefined>;
|
|
@@ -8,8 +8,10 @@ type InitRoutesOptions = {
|
|
|
8
8
|
signingKey: string;
|
|
9
9
|
refreshKey: string;
|
|
10
10
|
turnstileKey?: string;
|
|
11
|
-
onSignUp?: (
|
|
12
|
-
|
|
11
|
+
onSignUp?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
12
|
+
onLogin?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
13
|
+
onRefresh?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
14
|
+
onLogout?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
export type { InitRoutesOptions };
|
|
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/auth/email/utils.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
-
|
|
23
|
+
getContext: () => getContext,
|
|
24
24
|
massageRequest: () => massageRequest,
|
|
25
25
|
verifyCaptcha: () => verifyCaptcha
|
|
26
26
|
});
|
|
@@ -95,30 +95,30 @@ async function verifyCaptcha(token, secret) {
|
|
|
95
95
|
}
|
|
96
96
|
return false;
|
|
97
97
|
}
|
|
98
|
-
var
|
|
98
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
99
99
|
const bearer = req.headers.get("authorization");
|
|
100
100
|
if (!bearer) {
|
|
101
101
|
const refresh = req.cookies.get("refresh")?.value;
|
|
102
102
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
103
|
-
if (userId) return {
|
|
104
|
-
return null;
|
|
103
|
+
if (userId) return { userId, isRefreshID: true };
|
|
104
|
+
return { userId: null };
|
|
105
105
|
}
|
|
106
106
|
const token = bearer.slice(7);
|
|
107
107
|
try {
|
|
108
108
|
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
109
109
|
if (typeof res === "string") {
|
|
110
|
-
return null;
|
|
110
|
+
return { userId: null };
|
|
111
111
|
}
|
|
112
112
|
return {
|
|
113
|
-
|
|
113
|
+
userId: res.id
|
|
114
114
|
};
|
|
115
115
|
} catch {
|
|
116
116
|
}
|
|
117
|
-
return null;
|
|
117
|
+
return { userId: null };
|
|
118
118
|
};
|
|
119
119
|
// Annotate the CommonJS export names for ESM import in node:
|
|
120
120
|
0 && (module.exports = {
|
|
121
|
-
|
|
121
|
+
getContext,
|
|
122
122
|
massageRequest,
|
|
123
123
|
verifyCaptcha
|
|
124
124
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { Context } from '../../graphql/types.mjs';
|
|
2
3
|
import { InitRoutesOptions } from './types.mjs';
|
|
3
4
|
import '../types.mjs';
|
|
4
5
|
|
|
@@ -12,9 +13,6 @@ declare function massageRequest(req: NextRequest, options: InitRoutesOptions): P
|
|
|
12
13
|
};
|
|
13
14
|
}>;
|
|
14
15
|
declare function verifyCaptcha(token: string, secret?: string): Promise<boolean>;
|
|
15
|
-
declare const
|
|
16
|
-
refreshUserID?: number;
|
|
17
|
-
accessUserId?: number;
|
|
18
|
-
} | null;
|
|
16
|
+
declare const getContext: (refreshKey: string, signingKey: string, req: NextRequest) => Context;
|
|
19
17
|
|
|
20
|
-
export {
|
|
18
|
+
export { getContext, massageRequest, verifyCaptcha };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { Context } from '../../graphql/types.js';
|
|
2
3
|
import { InitRoutesOptions } from './types.js';
|
|
3
4
|
import '../types.js';
|
|
4
5
|
|
|
@@ -12,9 +13,6 @@ declare function massageRequest(req: NextRequest, options: InitRoutesOptions): P
|
|
|
12
13
|
};
|
|
13
14
|
}>;
|
|
14
15
|
declare function verifyCaptcha(token: string, secret?: string): Promise<boolean>;
|
|
15
|
-
declare const
|
|
16
|
-
refreshUserID?: number;
|
|
17
|
-
accessUserId?: number;
|
|
18
|
-
} | null;
|
|
16
|
+
declare const getContext: (refreshKey: string, signingKey: string, req: NextRequest) => Context;
|
|
19
17
|
|
|
20
|
-
export {
|
|
18
|
+
export { getContext, massageRequest, verifyCaptcha };
|
|
@@ -69,29 +69,29 @@ async function verifyCaptcha(token, secret) {
|
|
|
69
69
|
}
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
|
-
var
|
|
72
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
73
73
|
const bearer = req.headers.get("authorization");
|
|
74
74
|
if (!bearer) {
|
|
75
75
|
const refresh = req.cookies.get("refresh")?.value;
|
|
76
76
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
77
|
-
if (userId) return {
|
|
78
|
-
return null;
|
|
77
|
+
if (userId) return { userId, isRefreshID: true };
|
|
78
|
+
return { userId: null };
|
|
79
79
|
}
|
|
80
80
|
const token = bearer.slice(7);
|
|
81
81
|
try {
|
|
82
82
|
const res = verify2(token, signingKey);
|
|
83
83
|
if (typeof res === "string") {
|
|
84
|
-
return null;
|
|
84
|
+
return { userId: null };
|
|
85
85
|
}
|
|
86
86
|
return {
|
|
87
|
-
|
|
87
|
+
userId: res.id
|
|
88
88
|
};
|
|
89
89
|
} catch {
|
|
90
90
|
}
|
|
91
|
-
return null;
|
|
91
|
+
return { userId: null };
|
|
92
92
|
};
|
|
93
93
|
export {
|
|
94
|
-
|
|
94
|
+
getContext,
|
|
95
95
|
massageRequest,
|
|
96
96
|
verifyCaptcha
|
|
97
97
|
};
|
package/dist/auth/index.cjs.js
CHANGED
|
@@ -142,42 +142,49 @@ async function verifyCaptcha(token, secret) {
|
|
|
142
142
|
}
|
|
143
143
|
return false;
|
|
144
144
|
}
|
|
145
|
-
var
|
|
145
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
146
146
|
const bearer = req.headers.get("authorization");
|
|
147
147
|
if (!bearer) {
|
|
148
148
|
const refresh = req.cookies.get("refresh")?.value;
|
|
149
149
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
150
|
-
if (userId) return {
|
|
151
|
-
return null;
|
|
150
|
+
if (userId) return { userId, isRefreshID: true };
|
|
151
|
+
return { userId: null };
|
|
152
152
|
}
|
|
153
153
|
const token = bearer.slice(7);
|
|
154
154
|
try {
|
|
155
155
|
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
156
156
|
if (typeof res === "string") {
|
|
157
|
-
return null;
|
|
157
|
+
return { userId: null };
|
|
158
158
|
}
|
|
159
159
|
return {
|
|
160
|
-
|
|
160
|
+
userId: res.id
|
|
161
161
|
};
|
|
162
162
|
} catch {
|
|
163
163
|
}
|
|
164
|
-
return null;
|
|
164
|
+
return { userId: null };
|
|
165
165
|
};
|
|
166
166
|
|
|
167
167
|
// src/auth/email/routes/delete.ts
|
|
168
168
|
var getDeleteRoute = (options) => async (req) => {
|
|
169
|
-
if (options.onLogout)
|
|
169
|
+
if (options.onLogout) {
|
|
170
|
+
const ctx = await getContext(options.refreshKey, options.signingKey, req);
|
|
171
|
+
await options.onLogout?.(ctx.userId, req);
|
|
172
|
+
}
|
|
170
173
|
return getTokenizedResponse(void 0, "");
|
|
171
174
|
};
|
|
172
175
|
|
|
173
176
|
// src/auth/email/routes/get.ts
|
|
174
|
-
var getGetRoute = (options) => (req) => {
|
|
177
|
+
var getGetRoute = (options) => async (req) => {
|
|
175
178
|
const refresh = req.cookies.get("refresh")?.value;
|
|
176
179
|
const userID = getUserIdFromRefreshToken(options.refreshKey, refresh);
|
|
177
|
-
if (userID)
|
|
180
|
+
if (userID) {
|
|
181
|
+
if (options.onRefresh) {
|
|
182
|
+
await options.onRefresh?.(userID, req);
|
|
183
|
+
}
|
|
178
184
|
return getTokenizedResponse(
|
|
179
185
|
generateAccessToken(userID, options.signingKey)
|
|
180
186
|
);
|
|
187
|
+
}
|
|
181
188
|
return getTokenizedResponse();
|
|
182
189
|
};
|
|
183
190
|
|
|
@@ -202,7 +209,9 @@ var getPostRoute = (options) => async (req) => {
|
|
|
202
209
|
password: encryptedPassword
|
|
203
210
|
});
|
|
204
211
|
if (newUser) {
|
|
205
|
-
options.onSignUp
|
|
212
|
+
if (options.onSignUp) {
|
|
213
|
+
await options.onSignUp?.(newUser.id, req);
|
|
214
|
+
}
|
|
206
215
|
return getTokenizedResponse(
|
|
207
216
|
generateAccessToken(newUser.id, options.signingKey),
|
|
208
217
|
generateRefreshToken(newUser.id, options.refreshKey)
|
|
@@ -219,6 +228,9 @@ var getPutRoute = (options) => async (req) => {
|
|
|
219
228
|
if (!user)
|
|
220
229
|
return handleError(400, "A user does not exist", options.onError);
|
|
221
230
|
if (await verifyUser(user, data.password)) {
|
|
231
|
+
if (options.onLogin) {
|
|
232
|
+
await options.onLogin?.(user.id, req);
|
|
233
|
+
}
|
|
222
234
|
return getTokenizedResponse(
|
|
223
235
|
generateAccessToken(user.id, options.signingKey),
|
|
224
236
|
generateRefreshToken(user.id, options.refreshKey)
|
|
@@ -234,14 +246,7 @@ function getEmailAuthRoutes(options) {
|
|
|
234
246
|
POST: getPostRoute(options),
|
|
235
247
|
PUT: getPutRoute(options),
|
|
236
248
|
DELETE: getDeleteRoute(options),
|
|
237
|
-
getContext: (req) =>
|
|
238
|
-
const ids = getUserContext(options.refreshKey, options.signingKey, req);
|
|
239
|
-
if (!ids) return { userId: null };
|
|
240
|
-
if (ids.refreshUserID) {
|
|
241
|
-
return { userId: ids.refreshUserID, isRefreshID: true };
|
|
242
|
-
}
|
|
243
|
-
return { userId: ids.accessUserId };
|
|
244
|
-
}
|
|
249
|
+
getContext: (req) => getContext(options.refreshKey, options.signingKey, req)
|
|
245
250
|
};
|
|
246
251
|
}
|
|
247
252
|
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ export { getEmailAuthRoutes } from './email/index.mjs';
|
|
|
2
2
|
export { initGoogleAuth } from './google/index.mjs';
|
|
3
3
|
export { initInstagramAuth } from './instagram/index.mjs';
|
|
4
4
|
import 'next/server';
|
|
5
|
+
import '../graphql/types.mjs';
|
|
5
6
|
import './email/types.mjs';
|
|
6
7
|
import './types.mjs';
|
|
7
8
|
import 'googleapis';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { getEmailAuthRoutes } from './email/index.js';
|
|
|
2
2
|
export { initGoogleAuth } from './google/index.js';
|
|
3
3
|
export { initInstagramAuth } from './instagram/index.js';
|
|
4
4
|
import 'next/server';
|
|
5
|
+
import '../graphql/types.js';
|
|
5
6
|
import './email/types.js';
|
|
6
7
|
import './types.js';
|
|
7
8
|
import 'googleapis';
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -114,42 +114,49 @@ async function verifyCaptcha(token, secret) {
|
|
|
114
114
|
}
|
|
115
115
|
return false;
|
|
116
116
|
}
|
|
117
|
-
var
|
|
117
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
118
118
|
const bearer = req.headers.get("authorization");
|
|
119
119
|
if (!bearer) {
|
|
120
120
|
const refresh = req.cookies.get("refresh")?.value;
|
|
121
121
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
122
|
-
if (userId) return {
|
|
123
|
-
return null;
|
|
122
|
+
if (userId) return { userId, isRefreshID: true };
|
|
123
|
+
return { userId: null };
|
|
124
124
|
}
|
|
125
125
|
const token = bearer.slice(7);
|
|
126
126
|
try {
|
|
127
127
|
const res = verify2(token, signingKey);
|
|
128
128
|
if (typeof res === "string") {
|
|
129
|
-
return null;
|
|
129
|
+
return { userId: null };
|
|
130
130
|
}
|
|
131
131
|
return {
|
|
132
|
-
|
|
132
|
+
userId: res.id
|
|
133
133
|
};
|
|
134
134
|
} catch {
|
|
135
135
|
}
|
|
136
|
-
return null;
|
|
136
|
+
return { userId: null };
|
|
137
137
|
};
|
|
138
138
|
|
|
139
139
|
// src/auth/email/routes/delete.ts
|
|
140
140
|
var getDeleteRoute = (options) => async (req) => {
|
|
141
|
-
if (options.onLogout)
|
|
141
|
+
if (options.onLogout) {
|
|
142
|
+
const ctx = await getContext(options.refreshKey, options.signingKey, req);
|
|
143
|
+
await options.onLogout?.(ctx.userId, req);
|
|
144
|
+
}
|
|
142
145
|
return getTokenizedResponse(void 0, "");
|
|
143
146
|
};
|
|
144
147
|
|
|
145
148
|
// src/auth/email/routes/get.ts
|
|
146
|
-
var getGetRoute = (options) => (req) => {
|
|
149
|
+
var getGetRoute = (options) => async (req) => {
|
|
147
150
|
const refresh = req.cookies.get("refresh")?.value;
|
|
148
151
|
const userID = getUserIdFromRefreshToken(options.refreshKey, refresh);
|
|
149
|
-
if (userID)
|
|
152
|
+
if (userID) {
|
|
153
|
+
if (options.onRefresh) {
|
|
154
|
+
await options.onRefresh?.(userID, req);
|
|
155
|
+
}
|
|
150
156
|
return getTokenizedResponse(
|
|
151
157
|
generateAccessToken(userID, options.signingKey)
|
|
152
158
|
);
|
|
159
|
+
}
|
|
153
160
|
return getTokenizedResponse();
|
|
154
161
|
};
|
|
155
162
|
|
|
@@ -174,7 +181,9 @@ var getPostRoute = (options) => async (req) => {
|
|
|
174
181
|
password: encryptedPassword
|
|
175
182
|
});
|
|
176
183
|
if (newUser) {
|
|
177
|
-
options.onSignUp
|
|
184
|
+
if (options.onSignUp) {
|
|
185
|
+
await options.onSignUp?.(newUser.id, req);
|
|
186
|
+
}
|
|
178
187
|
return getTokenizedResponse(
|
|
179
188
|
generateAccessToken(newUser.id, options.signingKey),
|
|
180
189
|
generateRefreshToken(newUser.id, options.refreshKey)
|
|
@@ -191,6 +200,9 @@ var getPutRoute = (options) => async (req) => {
|
|
|
191
200
|
if (!user)
|
|
192
201
|
return handleError(400, "A user does not exist", options.onError);
|
|
193
202
|
if (await verifyUser(user, data.password)) {
|
|
203
|
+
if (options.onLogin) {
|
|
204
|
+
await options.onLogin?.(user.id, req);
|
|
205
|
+
}
|
|
194
206
|
return getTokenizedResponse(
|
|
195
207
|
generateAccessToken(user.id, options.signingKey),
|
|
196
208
|
generateRefreshToken(user.id, options.refreshKey)
|
|
@@ -206,14 +218,7 @@ function getEmailAuthRoutes(options) {
|
|
|
206
218
|
POST: getPostRoute(options),
|
|
207
219
|
PUT: getPutRoute(options),
|
|
208
220
|
DELETE: getDeleteRoute(options),
|
|
209
|
-
getContext: (req) =>
|
|
210
|
-
const ids = getUserContext(options.refreshKey, options.signingKey, req);
|
|
211
|
-
if (!ids) return { userId: null };
|
|
212
|
-
if (ids.refreshUserID) {
|
|
213
|
-
return { userId: ids.refreshUserID, isRefreshID: true };
|
|
214
|
-
}
|
|
215
|
-
return { userId: ids.accessUserId };
|
|
216
|
-
}
|
|
221
|
+
getContext: (req) => getContext(options.refreshKey, options.signingKey, req)
|
|
217
222
|
};
|
|
218
223
|
}
|
|
219
224
|
|
package/dist/client/hooks.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
|
|
3
|
-
declare function useVisibility(onVisible?: () => void):
|
|
3
|
+
declare function useVisibility(onVisible?: () => void): react.RefObject<null>;
|
|
4
4
|
declare function useBreakpoint(query: string): boolean | null;
|
|
5
5
|
|
|
6
6
|
export { useBreakpoint, useVisibility };
|
package/dist/client/hooks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
|
|
3
|
-
declare function useVisibility(onVisible?: () => void):
|
|
3
|
+
declare function useVisibility(onVisible?: () => void): react.RefObject<null>;
|
|
4
4
|
declare function useBreakpoint(query: string): boolean | null;
|
|
5
5
|
|
|
6
6
|
export { useBreakpoint, useVisibility };
|
package/dist/file/client.cjs.js
CHANGED
|
@@ -20,32 +20,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/file/client.ts
|
|
21
21
|
var client_exports = {};
|
|
22
22
|
__export(client_exports, {
|
|
23
|
-
|
|
23
|
+
getUseFileUpload: () => getUseFileUpload
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(client_exports);
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}).then(
|
|
45
|
-
async (res) => await res.json() || null
|
|
46
|
-
);
|
|
26
|
+
var import_client = require("naystack/auth/email/client");
|
|
27
|
+
var getUseFileUpload = (route) => () => {
|
|
28
|
+
const token = (0, import_client.useToken)();
|
|
29
|
+
return (file, type, data) => {
|
|
30
|
+
const formData = new FormData();
|
|
31
|
+
formData.append("type", type);
|
|
32
|
+
formData.append("file", file);
|
|
33
|
+
if (data) formData.append("data", JSON.stringify(data));
|
|
34
|
+
return fetch(route, {
|
|
35
|
+
method: "PUT",
|
|
36
|
+
body: formData,
|
|
37
|
+
headers: {
|
|
38
|
+
Authorization: `Bearer ${token}`
|
|
39
|
+
}
|
|
40
|
+
}).then(
|
|
41
|
+
async (res) => await res.json() || null
|
|
42
|
+
);
|
|
43
|
+
};
|
|
47
44
|
};
|
|
48
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49
46
|
0 && (module.exports = {
|
|
50
|
-
|
|
47
|
+
getUseFileUpload
|
|
51
48
|
});
|
package/dist/file/client.d.mts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
|
|
3
|
-
token: string;
|
|
4
|
-
type: string;
|
|
5
|
-
sync?: boolean;
|
|
6
|
-
data?: object;
|
|
7
|
-
}) => Promise<ImageUploadResponseType>;
|
|
8
|
-
interface ImageUploadResponseType {
|
|
1
|
+
declare const getUseFileUpload: (route: string) => () => (file: File | Blob, type: string, data?: object) => Promise<FileUploadResponseType>;
|
|
2
|
+
interface FileUploadResponseType {
|
|
9
3
|
url?: string;
|
|
10
|
-
|
|
4
|
+
onUploadResponse?: object;
|
|
11
5
|
}
|
|
12
6
|
|
|
13
|
-
export {
|
|
7
|
+
export { getUseFileUpload };
|
package/dist/file/client.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
|
|
3
|
-
token: string;
|
|
4
|
-
type: string;
|
|
5
|
-
sync?: boolean;
|
|
6
|
-
data?: object;
|
|
7
|
-
}) => Promise<ImageUploadResponseType>;
|
|
8
|
-
interface ImageUploadResponseType {
|
|
1
|
+
declare const getUseFileUpload: (route: string) => () => (file: File | Blob, type: string, data?: object) => Promise<FileUploadResponseType>;
|
|
2
|
+
interface FileUploadResponseType {
|
|
9
3
|
url?: string;
|
|
10
|
-
|
|
4
|
+
onUploadResponse?: object;
|
|
11
5
|
}
|
|
12
6
|
|
|
13
|
-
export {
|
|
7
|
+
export { getUseFileUpload };
|
package/dist/file/client.esm.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
// src/file/client.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}).then(
|
|
21
|
-
async (res) => await res.json() || null
|
|
22
|
-
);
|
|
2
|
+
import { useToken } from "naystack/auth/email/client";
|
|
3
|
+
var getUseFileUpload = (route) => () => {
|
|
4
|
+
const token = useToken();
|
|
5
|
+
return (file, type, data) => {
|
|
6
|
+
const formData = new FormData();
|
|
7
|
+
formData.append("type", type);
|
|
8
|
+
formData.append("file", file);
|
|
9
|
+
if (data) formData.append("data", JSON.stringify(data));
|
|
10
|
+
return fetch(route, {
|
|
11
|
+
method: "PUT",
|
|
12
|
+
body: formData,
|
|
13
|
+
headers: {
|
|
14
|
+
Authorization: `Bearer ${token}`
|
|
15
|
+
}
|
|
16
|
+
}).then(
|
|
17
|
+
async (res) => await res.json() || null
|
|
18
|
+
);
|
|
19
|
+
};
|
|
23
20
|
};
|
|
24
21
|
export {
|
|
25
|
-
|
|
22
|
+
getUseFileUpload
|
|
26
23
|
};
|