dn-react-router-toolkit 0.8.1 → 0.9.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/dist/api/create_api_handler.d.mts +2 -2
- package/dist/api/create_api_handler.d.ts +2 -2
- package/dist/api/create_api_handler.js +55 -52
- package/dist/api/create_api_handler.mjs +61 -59
- package/dist/api/create_handler.d.mts +5 -5
- package/dist/api/create_handler.d.ts +5 -5
- package/dist/api/create_handler.js +41 -44
- package/dist/api/create_handler.mjs +41 -44
- package/dist/api/index.d.mts +4 -3
- package/dist/api/index.d.ts +4 -3
- package/dist/api/index.js +118 -102
- package/dist/api/index.mjs +130 -109
- package/dist/api/item_api_handler.d.mts +4 -3
- package/dist/api/item_api_handler.d.ts +4 -3
- package/dist/api/item_api_handler.js +22 -6
- package/dist/api/item_api_handler.mjs +28 -6
- package/dist/auth/cookie_manager.d.mts +1 -1
- package/dist/auth/cookie_manager.d.ts +1 -1
- package/dist/auth/index.d.mts +2 -2
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +18 -18
- package/dist/auth/index.mjs +18 -18
- package/dist/auth/with_auth.d.mts +2 -2
- package/dist/auth/with_auth.d.ts +2 -2
- package/dist/auth/with_auth.js +18 -18
- package/dist/auth/with_auth.mjs +18 -18
- package/dist/client/editor.d.mts +2 -2
- package/dist/client/editor.d.ts +2 -2
- package/dist/client/editor.js +9 -3
- package/dist/client/editor.mjs +9 -3
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +9 -3
- package/dist/client/index.mjs +9 -3
- package/dist/crud/crud_form.js +22 -4
- package/dist/crud/crud_form.mjs +11 -3
- package/dist/crud/crud_form_provider.js +16 -3
- package/dist/crud/crud_form_provider.mjs +14 -1
- package/dist/crud/index.d.mts +0 -20
- package/dist/crud/index.d.ts +0 -20
- package/dist/crud/index.js +32 -8589
- package/dist/crud/index.mjs +11 -8599
- package/dist/db/backup/index.d.mts +1 -1
- package/dist/db/backup/index.d.ts +1 -1
- package/dist/form/create_form_component.js +21 -2
- package/dist/form/create_form_component.mjs +10 -1
- package/dist/form/form_components.js +21 -2
- package/dist/form/form_components.mjs +10 -1
- package/dist/form/index.js +21 -2
- package/dist/form/index.mjs +10 -1
- package/dist/post/editor_toolbar.js +20 -3
- package/dist/post/editor_toolbar.mjs +9 -2
- package/dist/post/index.js +93 -7711
- package/dist/post/index.mjs +69 -7723
- package/dist/post/post_form_page.js +91 -7711
- package/dist/post/post_form_page.mjs +69 -7725
- package/dist/post/thumbnail_picker.js +21 -2
- package/dist/post/thumbnail_picker.mjs +10 -1
- package/dist/table/buttons.js +11 -14
- package/dist/table/buttons.mjs +10 -13
- package/dist/table/index.d.mts +0 -2
- package/dist/table/index.d.ts +0 -2
- package/dist/table/index.js +24 -95
- package/dist/table/index.mjs +23 -92
- package/dist/table/load_table.d.mts +1 -1
- package/dist/table/load_table.d.ts +1 -1
- package/dist/table/load_table.js +2 -2
- package/dist/table/load_table.mjs +2 -2
- package/dist/table/loader.js +2 -2
- package/dist/table/loader.mjs +2 -2
- package/dist/table/table.d.mts +2 -2
- package/dist/table/table.d.ts +2 -2
- package/dist/table/table.js +14 -25
- package/dist/table/table.mjs +11 -24
- package/dist/table/table_form.js +16 -39
- package/dist/table/table_form.mjs +15 -38
- package/dist/utils/cn.d.mts +3 -0
- package/dist/utils/cn.d.ts +3 -0
- package/dist/utils/cn.js +32 -0
- package/dist/utils/cn.mjs +7 -0
- package/dist/utils/date.d.mts +5 -0
- package/dist/utils/date.d.ts +5 -0
- package/dist/utils/date.js +65 -0
- package/dist/utils/date.mjs +29 -0
- package/dist/utils/index.d.mts +7 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +116 -0
- package/dist/utils/index.mjs +73 -0
- package/dist/utils/korean.d.mts +6 -0
- package/dist/utils/korean.d.ts +6 -0
- package/dist/{crud/generate_pages.js → utils/korean.js} +16 -30
- package/dist/utils/korean.mjs +16 -0
- package/dist/utils/singleton.d.mts +3 -0
- package/dist/utils/singleton.d.ts +3 -0
- package/dist/utils/singleton.js +37 -0
- package/dist/utils/singleton.mjs +12 -0
- package/dist/utils/sleep.d.mts +3 -0
- package/dist/utils/sleep.d.ts +3 -0
- package/dist/{table/item_loader.js → utils/sleep.js} +8 -19
- package/dist/utils/sleep.mjs +7 -0
- package/dist/utils/slug.d.mts +3 -0
- package/dist/utils/slug.d.ts +3 -0
- package/dist/{crud/generate_handlers.js → utils/slug.js} +8 -15
- package/dist/utils/slug.mjs +7 -0
- package/package.json +7 -3
- package/dist/crud/crud_loader.d.mts +0 -26
- package/dist/crud/crud_loader.d.ts +0 -26
- package/dist/crud/crud_loader.js +0 -351
- package/dist/crud/crud_loader.mjs +0 -337
- package/dist/crud/crud_page.d.mts +0 -32
- package/dist/crud/crud_page.d.ts +0 -32
- package/dist/crud/crud_page.js +0 -776
- package/dist/crud/crud_page.mjs +0 -758
- package/dist/crud/generate_handlers.d.mts +0 -16
- package/dist/crud/generate_handlers.d.ts +0 -16
- package/dist/crud/generate_handlers.mjs +0 -14
- package/dist/crud/generate_pages.d.mts +0 -19
- package/dist/crud/generate_pages.d.ts +0 -19
- package/dist/crud/generate_pages.mjs +0 -30
- package/dist/crud/generate_routes.d.mts +0 -5
- package/dist/crud/generate_routes.d.ts +0 -5
- package/dist/crud/generate_routes.js +0 -7639
- package/dist/crud/generate_routes.mjs +0 -7627
- package/dist/table/item_loader.d.mts +0 -14
- package/dist/table/item_loader.d.ts +0 -14
- package/dist/table/item_loader.mjs +0 -18
- package/dist/table/page.d.mts +0 -16
- package/dist/table/page.d.ts +0 -16
- package/dist/table/page.js +0 -375
- package/dist/table/page.mjs +0 -350
package/dist/api/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// src/api/create_handler.ts
|
|
2
|
-
import { NOT_FOUND } from "dn-react-toolkit/http";
|
|
3
2
|
import {
|
|
4
3
|
findAuthHandler,
|
|
5
4
|
loginHandler,
|
|
@@ -11,7 +10,7 @@ import {
|
|
|
11
10
|
signupHandler,
|
|
12
11
|
signUpWithThirdpartyHandler,
|
|
13
12
|
thirdpartyAuthCallbackHandler
|
|
14
|
-
} from "
|
|
13
|
+
} from "gw-auth/server";
|
|
15
14
|
|
|
16
15
|
// src/auth/with_auth.ts
|
|
17
16
|
var toResponse = (result) => {
|
|
@@ -37,31 +36,31 @@ function createWithStrictAuthHandler({ authService }) {
|
|
|
37
36
|
arg.request
|
|
38
37
|
);
|
|
39
38
|
if (accessToken) {
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
|
|
39
|
+
const verifyResult = await authService.accessTokenManager.verify(accessToken);
|
|
40
|
+
if (verifyResult.isOk) {
|
|
41
|
+
const payload = verifyResult.value;
|
|
42
|
+
if (payload) {
|
|
43
|
+
return respond(payload);
|
|
44
|
+
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
const refreshToken = await authService.getRefreshTokenFromCookies(
|
|
46
48
|
arg.request
|
|
47
49
|
);
|
|
48
50
|
if (refreshToken) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
headers.append("Set-Cookie", setCookieHeader);
|
|
56
|
-
const payload = authService.accessTokenManager.decode(newAccessToken);
|
|
57
|
-
return respond(payload, headers);
|
|
58
|
-
} catch (e) {
|
|
59
|
-
console.log(e);
|
|
60
|
-
const setCookieHeader = await authService.getRefreshTokenSetCookie(void 0);
|
|
61
|
-
const headers = new Headers();
|
|
62
|
-
headers.append("Set-Cookie", setCookieHeader);
|
|
63
|
-
return respond(void 0, headers);
|
|
51
|
+
const refreshResult = await authService.refreshAccessToken(refreshToken);
|
|
52
|
+
if (refreshResult.isErr) {
|
|
53
|
+
const setCookieHeader2 = await authService.getRefreshTokenSetCookie(void 0);
|
|
54
|
+
const headers2 = new Headers();
|
|
55
|
+
headers2.append("Set-Cookie", setCookieHeader2);
|
|
56
|
+
return respond(void 0, headers2);
|
|
64
57
|
}
|
|
58
|
+
const newAccessToken = refreshResult.value;
|
|
59
|
+
const setCookieHeader = await authService.getAccessTokenSetCookie(newAccessToken);
|
|
60
|
+
const headers = new Headers();
|
|
61
|
+
headers.append("Set-Cookie", setCookieHeader);
|
|
62
|
+
const payload = authService.accessTokenManager.decode(newAccessToken);
|
|
63
|
+
return respond(payload, headers);
|
|
65
64
|
}
|
|
66
65
|
return respond(void 0);
|
|
67
66
|
};
|
|
@@ -76,12 +75,13 @@ import { createCookie } from "react-router";
|
|
|
76
75
|
import {
|
|
77
76
|
deleteFileHandler,
|
|
78
77
|
uploadFileHandler
|
|
79
|
-
} from "
|
|
78
|
+
} from "gw-file/server";
|
|
79
|
+
import { httpNotFound } from "gw-response";
|
|
80
80
|
var createAPIHandler = ({
|
|
81
81
|
authService,
|
|
82
82
|
fileService,
|
|
83
83
|
passwordRecoveryService,
|
|
84
|
-
|
|
84
|
+
authProviders,
|
|
85
85
|
signupTokenManager
|
|
86
86
|
}) => {
|
|
87
87
|
const handler = async (args) => {
|
|
@@ -96,7 +96,7 @@ var createAPIHandler = ({
|
|
|
96
96
|
switch (method) {
|
|
97
97
|
case "GET": {
|
|
98
98
|
return withAuth(
|
|
99
|
-
(auth) => ({ request: request2 }) => findAuthHandler(auth)(
|
|
99
|
+
(auth) => ({ request: request2 }) => findAuthHandler(auth)()
|
|
100
100
|
);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -116,13 +116,10 @@ var createAPIHandler = ({
|
|
|
116
116
|
const provider = slug[2];
|
|
117
117
|
switch (method) {
|
|
118
118
|
case "POST": {
|
|
119
|
-
return loginWithThirdPartyHandler(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
getThirdPartyAuth
|
|
124
|
-
}
|
|
125
|
-
);
|
|
119
|
+
return loginWithThirdPartyHandler(request, {
|
|
120
|
+
provider,
|
|
121
|
+
authProviders
|
|
122
|
+
});
|
|
126
123
|
}
|
|
127
124
|
}
|
|
128
125
|
}
|
|
@@ -161,14 +158,11 @@ var createAPIHandler = ({
|
|
|
161
158
|
default: {
|
|
162
159
|
switch (method) {
|
|
163
160
|
case "POST": {
|
|
164
|
-
return signUpWithThirdpartyHandler(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
signupTokenManager
|
|
170
|
-
}
|
|
171
|
-
);
|
|
161
|
+
return signUpWithThirdpartyHandler(request, {
|
|
162
|
+
authService,
|
|
163
|
+
fileService,
|
|
164
|
+
signupTokenManager
|
|
165
|
+
});
|
|
172
166
|
}
|
|
173
167
|
}
|
|
174
168
|
}
|
|
@@ -181,7 +175,7 @@ var createAPIHandler = ({
|
|
|
181
175
|
return thirdpartyAuthCallbackHandler(request, {
|
|
182
176
|
provider,
|
|
183
177
|
authService,
|
|
184
|
-
|
|
178
|
+
authProviders
|
|
185
179
|
});
|
|
186
180
|
}
|
|
187
181
|
}
|
|
@@ -204,9 +198,9 @@ var createAPIHandler = ({
|
|
|
204
198
|
switch (method) {
|
|
205
199
|
case "POST": {
|
|
206
200
|
return withAuth(
|
|
207
|
-
(auth) => ({ request: request2 }) => uploadFileHandler({ fileService })(
|
|
208
|
-
auth
|
|
209
|
-
)
|
|
201
|
+
(auth) => ({ request: request2 }) => uploadFileHandler({ fileService })(request2, {
|
|
202
|
+
userId: auth?.userId
|
|
203
|
+
})
|
|
210
204
|
)(args);
|
|
211
205
|
}
|
|
212
206
|
}
|
|
@@ -218,7 +212,7 @@ var createAPIHandler = ({
|
|
|
218
212
|
return withAuth(
|
|
219
213
|
(auth) => () => deleteFileHandler({
|
|
220
214
|
fileRepository: fileService.fileRepository
|
|
221
|
-
})({ fileId })(
|
|
215
|
+
})({ fileId, userId: auth?.userId })()
|
|
222
216
|
);
|
|
223
217
|
}
|
|
224
218
|
}
|
|
@@ -226,7 +220,10 @@ var createAPIHandler = ({
|
|
|
226
220
|
}
|
|
227
221
|
}
|
|
228
222
|
default: {
|
|
229
|
-
return
|
|
223
|
+
return httpNotFound({
|
|
224
|
+
code: "RESOURCE_NOT_FOUND",
|
|
225
|
+
message: "\uB9AC\uC18C\uC2A4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
226
|
+
});
|
|
230
227
|
}
|
|
231
228
|
}
|
|
232
229
|
};
|
|
@@ -234,14 +231,6 @@ var createAPIHandler = ({
|
|
|
234
231
|
};
|
|
235
232
|
|
|
236
233
|
// src/api/create_api_handler.ts
|
|
237
|
-
import {
|
|
238
|
-
BAD_REQUEST,
|
|
239
|
-
CONFLICT,
|
|
240
|
-
CREATED,
|
|
241
|
-
INTERNAL_SERVER_ERROR,
|
|
242
|
-
METHOD_NOT_ALLOWED,
|
|
243
|
-
UNAUTHORIZED
|
|
244
|
-
} from "dn-react-toolkit/http";
|
|
245
234
|
import {
|
|
246
235
|
and
|
|
247
236
|
} from "drizzle-orm";
|
|
@@ -285,6 +274,13 @@ function deserialize(data) {
|
|
|
285
274
|
}
|
|
286
275
|
|
|
287
276
|
// src/api/create_api_handler.ts
|
|
277
|
+
import {
|
|
278
|
+
httpBadRequest,
|
|
279
|
+
httpConflict,
|
|
280
|
+
httpCreated,
|
|
281
|
+
httpMethodNotAllowed,
|
|
282
|
+
httpUnauthorized
|
|
283
|
+
} from "gw-response";
|
|
288
284
|
function apiHandler({
|
|
289
285
|
withAuthAction,
|
|
290
286
|
repository,
|
|
@@ -298,70 +294,73 @@ function apiHandler({
|
|
|
298
294
|
};
|
|
299
295
|
const action = withAuthAction((auth) => async ({ request }) => {
|
|
300
296
|
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
301
|
-
throw
|
|
297
|
+
throw httpUnauthorized({
|
|
298
|
+
code: "UNAUTHORIZED",
|
|
299
|
+
message: "\uC778\uC99D\uC774 \uD544\uC694\uD569\uB2C8\uB2E4."
|
|
300
|
+
});
|
|
302
301
|
}
|
|
303
302
|
switch (request.method) {
|
|
304
303
|
case "POST":
|
|
305
304
|
case "PUT": {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
305
|
+
const serilaizedParams = await request.json();
|
|
306
|
+
const params = deserialize(serilaizedParams);
|
|
307
|
+
if (validators) {
|
|
308
|
+
const paramsForValidation = Object.keys(validators).filter(
|
|
309
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
310
|
+
);
|
|
311
|
+
for (const paramKey of paramsForValidation) {
|
|
312
|
+
const value = params[paramKey];
|
|
313
|
+
const validator = validators[paramKey];
|
|
314
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
315
|
+
throw httpBadRequest({
|
|
316
|
+
code: "BAD_REQUEST",
|
|
317
|
+
message: validator.message ? validator.message(value) : "\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4."
|
|
318
|
+
});
|
|
321
319
|
}
|
|
322
320
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
321
|
+
}
|
|
322
|
+
const itemId = params.id || v4();
|
|
323
|
+
if (!params.id && existingConditions) {
|
|
324
|
+
const paramsForExistenceCheck = Object.keys(
|
|
325
|
+
existingConditions
|
|
326
|
+
).filter(
|
|
327
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
328
|
+
);
|
|
329
|
+
if (paramsForExistenceCheck.length > 0) {
|
|
330
|
+
const where = and(
|
|
331
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
332
|
+
const condition = existingConditions[key];
|
|
333
|
+
if (condition) {
|
|
334
|
+
acc.push(condition(params[key]));
|
|
335
|
+
}
|
|
336
|
+
return acc;
|
|
337
|
+
}, [])
|
|
329
338
|
);
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}, [])
|
|
339
|
-
);
|
|
340
|
-
const existing = await repository.findAll({
|
|
341
|
-
limit: 1,
|
|
342
|
-
where
|
|
339
|
+
const existing = await repository.findAll({
|
|
340
|
+
limit: 1,
|
|
341
|
+
where
|
|
342
|
+
});
|
|
343
|
+
if (existing.length > 0) {
|
|
344
|
+
return httpConflict({
|
|
345
|
+
code: "CONFLICT",
|
|
346
|
+
message: "\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4."
|
|
343
347
|
});
|
|
344
|
-
if (existing.length > 0) {
|
|
345
|
-
throw CONFLICT("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
|
|
346
|
-
}
|
|
347
348
|
}
|
|
348
349
|
}
|
|
349
|
-
const values = {
|
|
350
|
-
id: itemId,
|
|
351
|
-
userId: injectUserId ? auth?.userId : void 0,
|
|
352
|
-
...params
|
|
353
|
-
};
|
|
354
|
-
const item = await repository.save(values);
|
|
355
|
-
return CREATED(item);
|
|
356
|
-
} catch (error) {
|
|
357
|
-
if (error instanceof Error) {
|
|
358
|
-
throw INTERNAL_SERVER_ERROR(error.message);
|
|
359
|
-
}
|
|
360
|
-
throw error;
|
|
361
350
|
}
|
|
351
|
+
const values = {
|
|
352
|
+
id: itemId,
|
|
353
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
354
|
+
...params
|
|
355
|
+
};
|
|
356
|
+
const item = await repository.save(values);
|
|
357
|
+
return httpCreated(item);
|
|
362
358
|
}
|
|
363
359
|
default:
|
|
364
|
-
throw
|
|
360
|
+
throw httpMethodNotAllowed({
|
|
361
|
+
code: "METHOD_NOT_ALLOWED",
|
|
362
|
+
message: "\uD5C8\uC6A9\uB418\uC9C0 \uC54A\uC740 \uBA54\uC11C\uB4DC\uC785\uB2C8\uB2E4."
|
|
363
|
+
});
|
|
365
364
|
}
|
|
366
365
|
});
|
|
367
366
|
return {
|
|
@@ -371,7 +370,14 @@ function apiHandler({
|
|
|
371
370
|
}
|
|
372
371
|
|
|
373
372
|
// src/api/item_api_handler.ts
|
|
374
|
-
import {
|
|
373
|
+
import {
|
|
374
|
+
httpForbidden,
|
|
375
|
+
httpMethodNotAllowed as httpMethodNotAllowed2,
|
|
376
|
+
httpNoContent,
|
|
377
|
+
httpNotFound as httpNotFound2,
|
|
378
|
+
httpUnauthorized as httpUnauthorized2
|
|
379
|
+
} from "gw-response";
|
|
380
|
+
import { ok } from "gw-result";
|
|
375
381
|
function itemApiHandler({
|
|
376
382
|
withAuthAction,
|
|
377
383
|
repository,
|
|
@@ -379,24 +385,39 @@ function itemApiHandler({
|
|
|
379
385
|
roles
|
|
380
386
|
}) {
|
|
381
387
|
const loader = async ({ request }) => {
|
|
382
|
-
return {};
|
|
388
|
+
return ok({});
|
|
383
389
|
};
|
|
384
390
|
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
385
391
|
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
386
|
-
|
|
392
|
+
return httpUnauthorized2({
|
|
393
|
+
code: "UNAUTHORIZED",
|
|
394
|
+
message: "\uC778\uC99D\uC774 \uD544\uC694\uD569\uB2C8\uB2E4."
|
|
395
|
+
});
|
|
387
396
|
}
|
|
388
397
|
const itemId = params.itemId;
|
|
389
398
|
const existing = await repository.find(itemId);
|
|
390
399
|
if (!existing) {
|
|
391
|
-
|
|
400
|
+
return httpNotFound2({
|
|
401
|
+
code: "RESOURCE_NOT_FOUND",
|
|
402
|
+
message: "\uC790\uB8CC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
403
|
+
});
|
|
392
404
|
}
|
|
393
405
|
if (isOwnedBy && !isOwnedBy(existing, auth)) {
|
|
394
|
-
|
|
406
|
+
return httpForbidden({
|
|
407
|
+
code: "FORBIDDEN",
|
|
408
|
+
message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
409
|
+
});
|
|
395
410
|
}
|
|
396
411
|
switch (request.method) {
|
|
397
412
|
case "DELETE": {
|
|
398
413
|
await repository.delete(itemId);
|
|
399
|
-
return
|
|
414
|
+
return httpNoContent();
|
|
415
|
+
}
|
|
416
|
+
default: {
|
|
417
|
+
return httpMethodNotAllowed2({
|
|
418
|
+
code: "METHOD_NOT_ALLOWED",
|
|
419
|
+
message: "\uD5C8\uC6A9\uB418\uC9C0 \uC54A\uC740 \uBA54\uC11C\uB4DC\uC785\uB2C8\uB2E4."
|
|
420
|
+
});
|
|
400
421
|
}
|
|
401
422
|
}
|
|
402
423
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import * as gw_result from 'gw-result';
|
|
1
2
|
import { LoaderFunctionArgs } from 'react-router';
|
|
2
3
|
import { TableRepository } from '../table/repository.mjs';
|
|
3
4
|
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
5
|
import { WithAuthHandler } from '../auth/with_auth.mjs';
|
|
5
|
-
import { AccessTokenPayload } from '
|
|
6
|
+
import { AccessTokenPayload } from 'gw-auth';
|
|
6
7
|
import 'drizzle-orm';
|
|
7
8
|
import 'drizzle-orm/node-postgres';
|
|
8
|
-
import '
|
|
9
|
+
import 'gw-auth/server';
|
|
9
10
|
|
|
10
11
|
type ItemAPIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
11
12
|
withAuthAction: WithAuthHandler<LoaderFunctionArgs>;
|
|
@@ -14,7 +15,7 @@ type ItemAPIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
|
14
15
|
roles?: string[];
|
|
15
16
|
};
|
|
16
17
|
declare function itemApiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, isOwnedBy, roles, }: ItemAPIHandlerOptions<T, TSelect>): {
|
|
17
|
-
loader: ({ request }: LoaderFunctionArgs) => Promise<{}
|
|
18
|
+
loader: ({ request }: LoaderFunctionArgs) => Promise<gw_result.Ok<{}>>;
|
|
18
19
|
action: (arg: LoaderFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
19
20
|
};
|
|
20
21
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import * as gw_result from 'gw-result';
|
|
1
2
|
import { LoaderFunctionArgs } from 'react-router';
|
|
2
3
|
import { TableRepository } from '../table/repository.js';
|
|
3
4
|
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
5
|
import { WithAuthHandler } from '../auth/with_auth.js';
|
|
5
|
-
import { AccessTokenPayload } from '
|
|
6
|
+
import { AccessTokenPayload } from 'gw-auth';
|
|
6
7
|
import 'drizzle-orm';
|
|
7
8
|
import 'drizzle-orm/node-postgres';
|
|
8
|
-
import '
|
|
9
|
+
import 'gw-auth/server';
|
|
9
10
|
|
|
10
11
|
type ItemAPIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
11
12
|
withAuthAction: WithAuthHandler<LoaderFunctionArgs>;
|
|
@@ -14,7 +15,7 @@ type ItemAPIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
|
14
15
|
roles?: string[];
|
|
15
16
|
};
|
|
16
17
|
declare function itemApiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, isOwnedBy, roles, }: ItemAPIHandlerOptions<T, TSelect>): {
|
|
17
|
-
loader: ({ request }: LoaderFunctionArgs) => Promise<{}
|
|
18
|
+
loader: ({ request }: LoaderFunctionArgs) => Promise<gw_result.Ok<{}>>;
|
|
18
19
|
action: (arg: LoaderFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
19
20
|
};
|
|
20
21
|
|
|
@@ -23,7 +23,8 @@ __export(item_api_handler_exports, {
|
|
|
23
23
|
itemApiHandler: () => itemApiHandler
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(item_api_handler_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_gw_response = require("gw-response");
|
|
27
|
+
var import_gw_result = require("gw-result");
|
|
27
28
|
function itemApiHandler({
|
|
28
29
|
withAuthAction,
|
|
29
30
|
repository,
|
|
@@ -31,24 +32,39 @@ function itemApiHandler({
|
|
|
31
32
|
roles
|
|
32
33
|
}) {
|
|
33
34
|
const loader = async ({ request }) => {
|
|
34
|
-
return {};
|
|
35
|
+
return (0, import_gw_result.ok)({});
|
|
35
36
|
};
|
|
36
37
|
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
37
38
|
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
38
|
-
|
|
39
|
+
return (0, import_gw_response.httpUnauthorized)({
|
|
40
|
+
code: "UNAUTHORIZED",
|
|
41
|
+
message: "\uC778\uC99D\uC774 \uD544\uC694\uD569\uB2C8\uB2E4."
|
|
42
|
+
});
|
|
39
43
|
}
|
|
40
44
|
const itemId = params.itemId;
|
|
41
45
|
const existing = await repository.find(itemId);
|
|
42
46
|
if (!existing) {
|
|
43
|
-
|
|
47
|
+
return (0, import_gw_response.httpNotFound)({
|
|
48
|
+
code: "RESOURCE_NOT_FOUND",
|
|
49
|
+
message: "\uC790\uB8CC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
50
|
+
});
|
|
44
51
|
}
|
|
45
52
|
if (isOwnedBy && !isOwnedBy(existing, auth)) {
|
|
46
|
-
|
|
53
|
+
return (0, import_gw_response.httpForbidden)({
|
|
54
|
+
code: "FORBIDDEN",
|
|
55
|
+
message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
56
|
+
});
|
|
47
57
|
}
|
|
48
58
|
switch (request.method) {
|
|
49
59
|
case "DELETE": {
|
|
50
60
|
await repository.delete(itemId);
|
|
51
|
-
return
|
|
61
|
+
return (0, import_gw_response.httpNoContent)();
|
|
62
|
+
}
|
|
63
|
+
default: {
|
|
64
|
+
return (0, import_gw_response.httpMethodNotAllowed)({
|
|
65
|
+
code: "METHOD_NOT_ALLOWED",
|
|
66
|
+
message: "\uD5C8\uC6A9\uB418\uC9C0 \uC54A\uC740 \uBA54\uC11C\uB4DC\uC785\uB2C8\uB2E4."
|
|
67
|
+
});
|
|
52
68
|
}
|
|
53
69
|
}
|
|
54
70
|
});
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
// src/api/item_api_handler.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
httpForbidden,
|
|
4
|
+
httpMethodNotAllowed,
|
|
5
|
+
httpNoContent,
|
|
6
|
+
httpNotFound,
|
|
7
|
+
httpUnauthorized
|
|
8
|
+
} from "gw-response";
|
|
9
|
+
import { ok } from "gw-result";
|
|
3
10
|
function itemApiHandler({
|
|
4
11
|
withAuthAction,
|
|
5
12
|
repository,
|
|
@@ -7,24 +14,39 @@ function itemApiHandler({
|
|
|
7
14
|
roles
|
|
8
15
|
}) {
|
|
9
16
|
const loader = async ({ request }) => {
|
|
10
|
-
return {};
|
|
17
|
+
return ok({});
|
|
11
18
|
};
|
|
12
19
|
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
13
20
|
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
14
|
-
|
|
21
|
+
return httpUnauthorized({
|
|
22
|
+
code: "UNAUTHORIZED",
|
|
23
|
+
message: "\uC778\uC99D\uC774 \uD544\uC694\uD569\uB2C8\uB2E4."
|
|
24
|
+
});
|
|
15
25
|
}
|
|
16
26
|
const itemId = params.itemId;
|
|
17
27
|
const existing = await repository.find(itemId);
|
|
18
28
|
if (!existing) {
|
|
19
|
-
|
|
29
|
+
return httpNotFound({
|
|
30
|
+
code: "RESOURCE_NOT_FOUND",
|
|
31
|
+
message: "\uC790\uB8CC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
32
|
+
});
|
|
20
33
|
}
|
|
21
34
|
if (isOwnedBy && !isOwnedBy(existing, auth)) {
|
|
22
|
-
|
|
35
|
+
return httpForbidden({
|
|
36
|
+
code: "FORBIDDEN",
|
|
37
|
+
message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
38
|
+
});
|
|
23
39
|
}
|
|
24
40
|
switch (request.method) {
|
|
25
41
|
case "DELETE": {
|
|
26
42
|
await repository.delete(itemId);
|
|
27
|
-
return
|
|
43
|
+
return httpNoContent();
|
|
44
|
+
}
|
|
45
|
+
default: {
|
|
46
|
+
return httpMethodNotAllowed({
|
|
47
|
+
code: "METHOD_NOT_ALLOWED",
|
|
48
|
+
message: "\uD5C8\uC6A9\uB418\uC9C0 \uC54A\uC740 \uBA54\uC11C\uB4DC\uC785\uB2C8\uB2E4."
|
|
49
|
+
});
|
|
28
50
|
}
|
|
29
51
|
}
|
|
30
52
|
});
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { WithAuthHandler, createWithStrictAuthHandler } from './with_auth.mjs';
|
|
2
2
|
export { ReactRouterCookieManager } from './cookie_manager.mjs';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
3
|
+
import 'gw-auth';
|
|
4
|
+
import 'gw-auth/server';
|
|
5
5
|
import 'react-router';
|
|
6
6
|
import 'cookie';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { WithAuthHandler, createWithStrictAuthHandler } from './with_auth.js';
|
|
2
2
|
export { ReactRouterCookieManager } from './cookie_manager.js';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
3
|
+
import 'gw-auth';
|
|
4
|
+
import 'gw-auth/server';
|
|
5
5
|
import 'react-router';
|
|
6
6
|
import 'cookie';
|
package/dist/auth/index.js
CHANGED
|
@@ -49,31 +49,31 @@ function createWithStrictAuthHandler({ authService }) {
|
|
|
49
49
|
arg.request
|
|
50
50
|
);
|
|
51
51
|
if (accessToken) {
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
|
|
52
|
+
const verifyResult = await authService.accessTokenManager.verify(accessToken);
|
|
53
|
+
if (verifyResult.isOk) {
|
|
54
|
+
const payload = verifyResult.value;
|
|
55
|
+
if (payload) {
|
|
56
|
+
return respond(payload);
|
|
57
|
+
}
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
const refreshToken = await authService.getRefreshTokenFromCookies(
|
|
58
61
|
arg.request
|
|
59
62
|
);
|
|
60
63
|
if (refreshToken) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
headers.append("Set-Cookie", setCookieHeader);
|
|
68
|
-
const payload = authService.accessTokenManager.decode(newAccessToken);
|
|
69
|
-
return respond(payload, headers);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
console.log(e);
|
|
72
|
-
const setCookieHeader = await authService.getRefreshTokenSetCookie(void 0);
|
|
73
|
-
const headers = new Headers();
|
|
74
|
-
headers.append("Set-Cookie", setCookieHeader);
|
|
75
|
-
return respond(void 0, headers);
|
|
64
|
+
const refreshResult = await authService.refreshAccessToken(refreshToken);
|
|
65
|
+
if (refreshResult.isErr) {
|
|
66
|
+
const setCookieHeader2 = await authService.getRefreshTokenSetCookie(void 0);
|
|
67
|
+
const headers2 = new Headers();
|
|
68
|
+
headers2.append("Set-Cookie", setCookieHeader2);
|
|
69
|
+
return respond(void 0, headers2);
|
|
76
70
|
}
|
|
71
|
+
const newAccessToken = refreshResult.value;
|
|
72
|
+
const setCookieHeader = await authService.getAccessTokenSetCookie(newAccessToken);
|
|
73
|
+
const headers = new Headers();
|
|
74
|
+
headers.append("Set-Cookie", setCookieHeader);
|
|
75
|
+
const payload = authService.accessTokenManager.decode(newAccessToken);
|
|
76
|
+
return respond(payload, headers);
|
|
77
77
|
}
|
|
78
78
|
return respond(void 0);
|
|
79
79
|
};
|