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.
Files changed (130) hide show
  1. package/dist/api/create_api_handler.d.mts +2 -2
  2. package/dist/api/create_api_handler.d.ts +2 -2
  3. package/dist/api/create_api_handler.js +55 -52
  4. package/dist/api/create_api_handler.mjs +61 -59
  5. package/dist/api/create_handler.d.mts +5 -5
  6. package/dist/api/create_handler.d.ts +5 -5
  7. package/dist/api/create_handler.js +41 -44
  8. package/dist/api/create_handler.mjs +41 -44
  9. package/dist/api/index.d.mts +4 -3
  10. package/dist/api/index.d.ts +4 -3
  11. package/dist/api/index.js +118 -102
  12. package/dist/api/index.mjs +130 -109
  13. package/dist/api/item_api_handler.d.mts +4 -3
  14. package/dist/api/item_api_handler.d.ts +4 -3
  15. package/dist/api/item_api_handler.js +22 -6
  16. package/dist/api/item_api_handler.mjs +28 -6
  17. package/dist/auth/cookie_manager.d.mts +1 -1
  18. package/dist/auth/cookie_manager.d.ts +1 -1
  19. package/dist/auth/index.d.mts +2 -2
  20. package/dist/auth/index.d.ts +2 -2
  21. package/dist/auth/index.js +18 -18
  22. package/dist/auth/index.mjs +18 -18
  23. package/dist/auth/with_auth.d.mts +2 -2
  24. package/dist/auth/with_auth.d.ts +2 -2
  25. package/dist/auth/with_auth.js +18 -18
  26. package/dist/auth/with_auth.mjs +18 -18
  27. package/dist/client/editor.d.mts +2 -2
  28. package/dist/client/editor.d.ts +2 -2
  29. package/dist/client/editor.js +9 -3
  30. package/dist/client/editor.mjs +9 -3
  31. package/dist/client/index.d.mts +2 -2
  32. package/dist/client/index.d.ts +2 -2
  33. package/dist/client/index.js +9 -3
  34. package/dist/client/index.mjs +9 -3
  35. package/dist/crud/crud_form.js +22 -4
  36. package/dist/crud/crud_form.mjs +11 -3
  37. package/dist/crud/crud_form_provider.js +16 -3
  38. package/dist/crud/crud_form_provider.mjs +14 -1
  39. package/dist/crud/index.d.mts +0 -20
  40. package/dist/crud/index.d.ts +0 -20
  41. package/dist/crud/index.js +32 -8589
  42. package/dist/crud/index.mjs +11 -8599
  43. package/dist/db/backup/index.d.mts +1 -1
  44. package/dist/db/backup/index.d.ts +1 -1
  45. package/dist/form/create_form_component.js +21 -2
  46. package/dist/form/create_form_component.mjs +10 -1
  47. package/dist/form/form_components.js +21 -2
  48. package/dist/form/form_components.mjs +10 -1
  49. package/dist/form/index.js +21 -2
  50. package/dist/form/index.mjs +10 -1
  51. package/dist/post/editor_toolbar.js +20 -3
  52. package/dist/post/editor_toolbar.mjs +9 -2
  53. package/dist/post/index.js +93 -7711
  54. package/dist/post/index.mjs +69 -7723
  55. package/dist/post/post_form_page.js +91 -7711
  56. package/dist/post/post_form_page.mjs +69 -7725
  57. package/dist/post/thumbnail_picker.js +21 -2
  58. package/dist/post/thumbnail_picker.mjs +10 -1
  59. package/dist/table/buttons.js +11 -14
  60. package/dist/table/buttons.mjs +10 -13
  61. package/dist/table/index.d.mts +0 -2
  62. package/dist/table/index.d.ts +0 -2
  63. package/dist/table/index.js +24 -95
  64. package/dist/table/index.mjs +23 -92
  65. package/dist/table/load_table.d.mts +1 -1
  66. package/dist/table/load_table.d.ts +1 -1
  67. package/dist/table/load_table.js +2 -2
  68. package/dist/table/load_table.mjs +2 -2
  69. package/dist/table/loader.js +2 -2
  70. package/dist/table/loader.mjs +2 -2
  71. package/dist/table/table.d.mts +2 -2
  72. package/dist/table/table.d.ts +2 -2
  73. package/dist/table/table.js +14 -25
  74. package/dist/table/table.mjs +11 -24
  75. package/dist/table/table_form.js +16 -39
  76. package/dist/table/table_form.mjs +15 -38
  77. package/dist/utils/cn.d.mts +3 -0
  78. package/dist/utils/cn.d.ts +3 -0
  79. package/dist/utils/cn.js +32 -0
  80. package/dist/utils/cn.mjs +7 -0
  81. package/dist/utils/date.d.mts +5 -0
  82. package/dist/utils/date.d.ts +5 -0
  83. package/dist/utils/date.js +65 -0
  84. package/dist/utils/date.mjs +29 -0
  85. package/dist/utils/index.d.mts +7 -0
  86. package/dist/utils/index.d.ts +7 -0
  87. package/dist/utils/index.js +116 -0
  88. package/dist/utils/index.mjs +73 -0
  89. package/dist/utils/korean.d.mts +6 -0
  90. package/dist/utils/korean.d.ts +6 -0
  91. package/dist/{crud/generate_pages.js → utils/korean.js} +16 -30
  92. package/dist/utils/korean.mjs +16 -0
  93. package/dist/utils/singleton.d.mts +3 -0
  94. package/dist/utils/singleton.d.ts +3 -0
  95. package/dist/utils/singleton.js +37 -0
  96. package/dist/utils/singleton.mjs +12 -0
  97. package/dist/utils/sleep.d.mts +3 -0
  98. package/dist/utils/sleep.d.ts +3 -0
  99. package/dist/{table/item_loader.js → utils/sleep.js} +8 -19
  100. package/dist/utils/sleep.mjs +7 -0
  101. package/dist/utils/slug.d.mts +3 -0
  102. package/dist/utils/slug.d.ts +3 -0
  103. package/dist/{crud/generate_handlers.js → utils/slug.js} +8 -15
  104. package/dist/utils/slug.mjs +7 -0
  105. package/package.json +7 -3
  106. package/dist/crud/crud_loader.d.mts +0 -26
  107. package/dist/crud/crud_loader.d.ts +0 -26
  108. package/dist/crud/crud_loader.js +0 -351
  109. package/dist/crud/crud_loader.mjs +0 -337
  110. package/dist/crud/crud_page.d.mts +0 -32
  111. package/dist/crud/crud_page.d.ts +0 -32
  112. package/dist/crud/crud_page.js +0 -776
  113. package/dist/crud/crud_page.mjs +0 -758
  114. package/dist/crud/generate_handlers.d.mts +0 -16
  115. package/dist/crud/generate_handlers.d.ts +0 -16
  116. package/dist/crud/generate_handlers.mjs +0 -14
  117. package/dist/crud/generate_pages.d.mts +0 -19
  118. package/dist/crud/generate_pages.d.ts +0 -19
  119. package/dist/crud/generate_pages.mjs +0 -30
  120. package/dist/crud/generate_routes.d.mts +0 -5
  121. package/dist/crud/generate_routes.d.ts +0 -5
  122. package/dist/crud/generate_routes.js +0 -7639
  123. package/dist/crud/generate_routes.mjs +0 -7627
  124. package/dist/table/item_loader.d.mts +0 -14
  125. package/dist/table/item_loader.d.ts +0 -14
  126. package/dist/table/item_loader.mjs +0 -18
  127. package/dist/table/page.d.mts +0 -16
  128. package/dist/table/page.d.ts +0 -16
  129. package/dist/table/page.js +0 -375
  130. package/dist/table/page.mjs +0 -350
@@ -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 "dn-react-toolkit/auth/server";
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 payload = await authService.accessTokenManager.verify(accessToken);
41
- if (payload) {
42
- return respond(payload);
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
- try {
50
- const newAccessToken = await authService.refreshAccessToken(refreshToken);
51
- const setCookieHeader = await authService.getAccessTokenSetCookie(
52
- newAccessToken
53
- );
54
- const headers = new Headers();
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 "dn-react-toolkit/file/server";
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
- getThirdPartyAuth,
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)(request2)
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
- request,
121
- {
122
- provider,
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
- request,
166
- {
167
- authService,
168
- fileService,
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
- getThirdPartyAuth
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
- )(request2)
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 })(auth)()
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 NOT_FOUND();
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 UNAUTHORIZED();
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
- try {
307
- const serilaizedParams = await request.json();
308
- const params = deserialize(serilaizedParams);
309
- if (validators) {
310
- const paramsForValidation = Object.keys(validators).filter(
311
- (key) => Object.prototype.hasOwnProperty.call(validators, key)
312
- );
313
- for (const paramKey of paramsForValidation) {
314
- const value = params[paramKey];
315
- const validator = validators[paramKey];
316
- if (validator?.validate && !validator.validate(value)) {
317
- throw BAD_REQUEST(
318
- validator.message ? validator.message(value) : void 0
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
- const itemId = params.id || v4();
324
- if (!params.id && existingConditions) {
325
- const paramsForExistenceCheck = Object.keys(
326
- existingConditions
327
- ).filter(
328
- (key) => Object.prototype.hasOwnProperty.call(params, key)
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
- if (paramsForExistenceCheck.length > 0) {
331
- const where = and(
332
- ...paramsForExistenceCheck.reduce((acc, key) => {
333
- const condition = existingConditions[key];
334
- if (condition) {
335
- acc.push(condition(params[key]));
336
- }
337
- return acc;
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 METHOD_NOT_ALLOWED();
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 { FORBIDDEN, NOT_FOUND as NOT_FOUND2, UNAUTHORIZED as UNAUTHORIZED2 } from "dn-react-toolkit/http";
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
- throw UNAUTHORIZED2();
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
- throw NOT_FOUND2();
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
- throw FORBIDDEN();
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 'dn-react-toolkit/auth';
6
+ import { AccessTokenPayload } from 'gw-auth';
6
7
  import 'drizzle-orm';
7
8
  import 'drizzle-orm/node-postgres';
8
- import 'dn-react-toolkit/auth/server';
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 'dn-react-toolkit/auth';
6
+ import { AccessTokenPayload } from 'gw-auth';
6
7
  import 'drizzle-orm';
7
8
  import 'drizzle-orm/node-postgres';
8
- import 'dn-react-toolkit/auth/server';
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 import_http = require("dn-react-toolkit/http");
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
- throw (0, import_http.UNAUTHORIZED)();
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
- throw (0, import_http.NOT_FOUND)();
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
- throw (0, import_http.FORBIDDEN)();
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 { FORBIDDEN, NOT_FOUND, UNAUTHORIZED } from "dn-react-toolkit/http";
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
- throw UNAUTHORIZED();
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
- throw NOT_FOUND();
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
- throw FORBIDDEN();
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
  });
@@ -1,4 +1,4 @@
1
- import { CookieManager } from 'dn-react-toolkit/auth/server';
1
+ import { CookieManager } from 'gw-auth/server';
2
2
  import { SerializeOptions, ParseOptions } from 'cookie';
3
3
 
4
4
  declare class ReactRouterCookieManager implements CookieManager {
@@ -1,4 +1,4 @@
1
- import { CookieManager } from 'dn-react-toolkit/auth/server';
1
+ import { CookieManager } from 'gw-auth/server';
2
2
  import { SerializeOptions, ParseOptions } from 'cookie';
3
3
 
4
4
  declare class ReactRouterCookieManager implements CookieManager {
@@ -1,6 +1,6 @@
1
1
  export { WithAuthHandler, createWithStrictAuthHandler } from './with_auth.mjs';
2
2
  export { ReactRouterCookieManager } from './cookie_manager.mjs';
3
- import 'dn-react-toolkit/auth';
4
- import 'dn-react-toolkit/auth/server';
3
+ import 'gw-auth';
4
+ import 'gw-auth/server';
5
5
  import 'react-router';
6
6
  import 'cookie';
@@ -1,6 +1,6 @@
1
1
  export { WithAuthHandler, createWithStrictAuthHandler } from './with_auth.js';
2
2
  export { ReactRouterCookieManager } from './cookie_manager.js';
3
- import 'dn-react-toolkit/auth';
4
- import 'dn-react-toolkit/auth/server';
3
+ import 'gw-auth';
4
+ import 'gw-auth/server';
5
5
  import 'react-router';
6
6
  import 'cookie';
@@ -49,31 +49,31 @@ function createWithStrictAuthHandler({ authService }) {
49
49
  arg.request
50
50
  );
51
51
  if (accessToken) {
52
- const payload = await authService.accessTokenManager.verify(accessToken);
53
- if (payload) {
54
- return respond(payload);
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
- try {
62
- const newAccessToken = await authService.refreshAccessToken(refreshToken);
63
- const setCookieHeader = await authService.getAccessTokenSetCookie(
64
- newAccessToken
65
- );
66
- const headers = new Headers();
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
  };