dn-react-router-toolkit 0.9.1 → 0.9.3
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_handler.d.mts → default_api_handler.d.mts} +3 -3
- package/dist/api/{create_handler.d.ts → default_api_handler.d.ts} +3 -3
- package/dist/api/{create_handler.js → default_api_handler.js} +8 -8
- package/dist/api/{create_handler.mjs → default_api_handler.mjs} +4 -4
- package/dist/api/index.d.mts +5 -5
- package/dist/api/index.d.ts +5 -5
- package/dist/api/index.js +186 -116
- package/dist/api/index.mjs +192 -126
- package/dist/api/put_resource_handler.d.mts +25 -0
- package/dist/api/put_resource_handler.d.ts +25 -0
- package/dist/api/put_resource_handler.js +214 -0
- package/dist/api/put_resource_handler.mjs +194 -0
- package/dist/api/resource_handler.d.mts +26 -0
- package/dist/api/resource_handler.d.ts +26 -0
- package/dist/api/resource_handler.js +280 -0
- package/dist/api/resource_handler.mjs +265 -0
- package/package.json +5 -5
- package/dist/api/create_api_handler.d.mts +0 -30
- package/dist/api/create_api_handler.d.ts +0 -30
- package/dist/api/create_api_handler.js +0 -158
- package/dist/api/create_api_handler.mjs +0 -141
- package/dist/api/item_api_handler.d.mts +0 -22
- package/dist/api/item_api_handler.d.ts +0 -22
- package/dist/api/item_api_handler.js +0 -79
- package/dist/api/item_api_handler.mjs +0 -60
|
@@ -2,12 +2,12 @@ import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
|
|
|
2
2
|
import { AuthService, PasswordRecoveryService, AuthProvider, JWTManager, ThirdpartyAuthPayload } from 'gw-auth/server';
|
|
3
3
|
import { FileService } from 'gw-file/server';
|
|
4
4
|
|
|
5
|
-
declare const
|
|
5
|
+
declare const defaultAPIHandler: <TFile>({ authService, fileService, passwordRecoveryService, authProviders, signupTokenManager, }: {
|
|
6
6
|
authService: AuthService<TFile>;
|
|
7
7
|
fileService: FileService<TFile>;
|
|
8
8
|
passwordRecoveryService: PasswordRecoveryService;
|
|
9
9
|
authProviders: AuthProvider[];
|
|
10
10
|
signupTokenManager: JWTManager<ThirdpartyAuthPayload>;
|
|
11
|
-
}) => (args: LoaderFunctionArgs | ActionFunctionArgs) => Promise<
|
|
11
|
+
}) => (args: LoaderFunctionArgs | ActionFunctionArgs) => Promise<(({ request }: LoaderFunctionArgs<any> | ActionFunctionArgs<any>) => Promise<Response>) | Response>;
|
|
12
12
|
|
|
13
|
-
export {
|
|
13
|
+
export { defaultAPIHandler };
|
|
@@ -2,12 +2,12 @@ import { LoaderFunctionArgs, ActionFunctionArgs } from 'react-router';
|
|
|
2
2
|
import { AuthService, PasswordRecoveryService, AuthProvider, JWTManager, ThirdpartyAuthPayload } from 'gw-auth/server';
|
|
3
3
|
import { FileService } from 'gw-file/server';
|
|
4
4
|
|
|
5
|
-
declare const
|
|
5
|
+
declare const defaultAPIHandler: <TFile>({ authService, fileService, passwordRecoveryService, authProviders, signupTokenManager, }: {
|
|
6
6
|
authService: AuthService<TFile>;
|
|
7
7
|
fileService: FileService<TFile>;
|
|
8
8
|
passwordRecoveryService: PasswordRecoveryService;
|
|
9
9
|
authProviders: AuthProvider[];
|
|
10
10
|
signupTokenManager: JWTManager<ThirdpartyAuthPayload>;
|
|
11
|
-
}) => (args: LoaderFunctionArgs | ActionFunctionArgs) => Promise<
|
|
11
|
+
}) => (args: LoaderFunctionArgs | ActionFunctionArgs) => Promise<(({ request }: LoaderFunctionArgs<any> | ActionFunctionArgs<any>) => Promise<Response>) | Response>;
|
|
12
12
|
|
|
13
|
-
export {
|
|
13
|
+
export { defaultAPIHandler };
|
|
@@ -17,12 +17,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/api/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
|
|
20
|
+
// src/api/default_api_handler.ts
|
|
21
|
+
var default_api_handler_exports = {};
|
|
22
|
+
__export(default_api_handler_exports, {
|
|
23
|
+
defaultAPIHandler: () => defaultAPIHandler
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(default_api_handler_exports);
|
|
26
26
|
var import_server = require("gw-auth/server");
|
|
27
27
|
|
|
28
28
|
// src/auth/with_auth.ts
|
|
@@ -84,10 +84,10 @@ function createWithStrictAuthHandler({ authService }) {
|
|
|
84
84
|
// src/auth/cookie_manager.ts
|
|
85
85
|
var import_react_router = require("react-router");
|
|
86
86
|
|
|
87
|
-
// src/api/
|
|
87
|
+
// src/api/default_api_handler.ts
|
|
88
88
|
var import_server2 = require("gw-file/server");
|
|
89
89
|
var import_gw_response = require("gw-response");
|
|
90
|
-
var
|
|
90
|
+
var defaultAPIHandler = ({
|
|
91
91
|
authService,
|
|
92
92
|
fileService,
|
|
93
93
|
passwordRecoveryService,
|
|
@@ -241,5 +241,5 @@ var createAPIHandler = ({
|
|
|
241
241
|
};
|
|
242
242
|
// Annotate the CommonJS export names for ESM import in node:
|
|
243
243
|
0 && (module.exports = {
|
|
244
|
-
|
|
244
|
+
defaultAPIHandler
|
|
245
245
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/api/
|
|
1
|
+
// src/api/default_api_handler.ts
|
|
2
2
|
import {
|
|
3
3
|
findAuthHandler,
|
|
4
4
|
loginHandler,
|
|
@@ -71,13 +71,13 @@ function createWithStrictAuthHandler({ authService }) {
|
|
|
71
71
|
// src/auth/cookie_manager.ts
|
|
72
72
|
import { createCookie } from "react-router";
|
|
73
73
|
|
|
74
|
-
// src/api/
|
|
74
|
+
// src/api/default_api_handler.ts
|
|
75
75
|
import {
|
|
76
76
|
deleteFileHandler,
|
|
77
77
|
uploadFileHandler
|
|
78
78
|
} from "gw-file/server";
|
|
79
79
|
import { httpNotFound } from "gw-response";
|
|
80
|
-
var
|
|
80
|
+
var defaultAPIHandler = ({
|
|
81
81
|
authService,
|
|
82
82
|
fileService,
|
|
83
83
|
passwordRecoveryService,
|
|
@@ -230,5 +230,5 @@ var createAPIHandler = ({
|
|
|
230
230
|
return handler;
|
|
231
231
|
};
|
|
232
232
|
export {
|
|
233
|
-
|
|
233
|
+
defaultAPIHandler
|
|
234
234
|
};
|
package/dist/api/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { APIHandlerOptions,
|
|
3
|
-
export {
|
|
1
|
+
export { defaultAPIHandler } from './default_api_handler.mjs';
|
|
2
|
+
export { APIHandlerOptions, resourceHandler } from './resource_handler.mjs';
|
|
3
|
+
export { PutResourceExistingConditions, PutResourceHandlerOptions, PutResourceValidators, putResourceHandler } from './put_resource_handler.mjs';
|
|
4
4
|
import 'react-router';
|
|
5
5
|
import 'gw-auth/server';
|
|
6
6
|
import 'gw-file/server';
|
|
7
|
-
import '
|
|
7
|
+
import 'gw-result';
|
|
8
8
|
import '../table/repository.mjs';
|
|
9
|
+
import 'drizzle-orm';
|
|
9
10
|
import 'drizzle-orm/node-postgres';
|
|
10
11
|
import 'drizzle-orm/pg-core';
|
|
11
12
|
import '../auth/with_auth.mjs';
|
|
12
13
|
import 'gw-auth';
|
|
13
|
-
import 'gw-result';
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { APIHandlerOptions,
|
|
3
|
-
export {
|
|
1
|
+
export { defaultAPIHandler } from './default_api_handler.js';
|
|
2
|
+
export { APIHandlerOptions, resourceHandler } from './resource_handler.js';
|
|
3
|
+
export { PutResourceExistingConditions, PutResourceHandlerOptions, PutResourceValidators, putResourceHandler } from './put_resource_handler.js';
|
|
4
4
|
import 'react-router';
|
|
5
5
|
import 'gw-auth/server';
|
|
6
6
|
import 'gw-file/server';
|
|
7
|
-
import '
|
|
7
|
+
import 'gw-result';
|
|
8
8
|
import '../table/repository.js';
|
|
9
|
+
import 'drizzle-orm';
|
|
9
10
|
import 'drizzle-orm/node-postgres';
|
|
10
11
|
import 'drizzle-orm/pg-core';
|
|
11
12
|
import '../auth/with_auth.js';
|
|
12
13
|
import 'gw-auth';
|
|
13
|
-
import 'gw-result';
|
package/dist/api/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,18 +17,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/api/index.ts
|
|
21
31
|
var api_exports = {};
|
|
22
32
|
__export(api_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
defaultAPIHandler: () => defaultAPIHandler,
|
|
34
|
+
putResourceHandler: () => putResourceHandler,
|
|
35
|
+
resourceHandler: () => resourceHandler
|
|
26
36
|
});
|
|
27
37
|
module.exports = __toCommonJS(api_exports);
|
|
28
38
|
|
|
29
|
-
// src/api/
|
|
39
|
+
// src/api/default_api_handler.ts
|
|
30
40
|
var import_server = require("gw-auth/server");
|
|
31
41
|
|
|
32
42
|
// src/auth/with_auth.ts
|
|
@@ -88,10 +98,10 @@ function createWithStrictAuthHandler({ authService }) {
|
|
|
88
98
|
// src/auth/cookie_manager.ts
|
|
89
99
|
var import_react_router = require("react-router");
|
|
90
100
|
|
|
91
|
-
// src/api/
|
|
101
|
+
// src/api/default_api_handler.ts
|
|
92
102
|
var import_server2 = require("gw-file/server");
|
|
93
103
|
var import_gw_response = require("gw-response");
|
|
94
|
-
var
|
|
104
|
+
var defaultAPIHandler = ({
|
|
95
105
|
authService,
|
|
96
106
|
fileService,
|
|
97
107
|
passwordRecoveryService,
|
|
@@ -244,9 +254,17 @@ var createAPIHandler = ({
|
|
|
244
254
|
return handler;
|
|
245
255
|
};
|
|
246
256
|
|
|
247
|
-
// src/api/
|
|
248
|
-
var
|
|
249
|
-
var
|
|
257
|
+
// src/api/resource_handler.ts
|
|
258
|
+
var import_gw_response3 = require("gw-response");
|
|
259
|
+
var import_gw_result = require("gw-result");
|
|
260
|
+
|
|
261
|
+
// src/api/put_resource_handler.ts
|
|
262
|
+
var import_gw_response2 = require("gw-response");
|
|
263
|
+
|
|
264
|
+
// src/crud/crud_form_provider.tsx
|
|
265
|
+
var import_react_router2 = require("react-router");
|
|
266
|
+
var import_react_store_input = require("react-store-input");
|
|
267
|
+
var import_react = require("react");
|
|
250
268
|
|
|
251
269
|
// src/crud/serialize.ts
|
|
252
270
|
function deserialize(data) {
|
|
@@ -285,139 +303,191 @@ function deserialize(data) {
|
|
|
285
303
|
return void 0;
|
|
286
304
|
}
|
|
287
305
|
|
|
288
|
-
// src/
|
|
289
|
-
var
|
|
290
|
-
|
|
291
|
-
|
|
306
|
+
// src/crud/crud_form_provider.tsx
|
|
307
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
308
|
+
var FormContext = (0, import_react.createContext)({});
|
|
309
|
+
|
|
310
|
+
// src/form/create_form_component.tsx
|
|
311
|
+
var import_react2 = require("react");
|
|
312
|
+
|
|
313
|
+
// src/utils/cn.ts
|
|
314
|
+
function cn(...classes) {
|
|
315
|
+
return classes.filter(Boolean).join(" ").trim();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/utils/date.ts
|
|
319
|
+
var import_moment_timezone = __toESM(require("moment-timezone"));
|
|
320
|
+
|
|
321
|
+
// src/form/create_form_component.tsx
|
|
322
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
323
|
+
function createComponent(tag, options) {
|
|
324
|
+
return function FormComponent({ className, ...props }) {
|
|
325
|
+
const Tag = tag;
|
|
326
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Tag, { ...props, className: cn(options.className, className) });
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/form/form_components.tsx
|
|
331
|
+
var FormEntry = createComponent("div", {
|
|
332
|
+
className: "flex-1"
|
|
333
|
+
});
|
|
334
|
+
var FormRow = createComponent("div", {
|
|
335
|
+
className: "flex-1 flex gap-4 mb-6"
|
|
336
|
+
});
|
|
337
|
+
var FormLabel = createComponent("label", {
|
|
338
|
+
className: "flex-1 font-semibold mb-2.5 block"
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// src/crud/crud_form.tsx
|
|
342
|
+
var import_react_store_input3 = require("react-store-input");
|
|
343
|
+
|
|
344
|
+
// src/client/env_loader.tsx
|
|
345
|
+
var import_react_router3 = require("react-router");
|
|
346
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
347
|
+
|
|
348
|
+
// src/client/file_input.tsx
|
|
349
|
+
var import_react3 = require("react");
|
|
350
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
351
|
+
|
|
352
|
+
// src/client/use_user_agent.tsx
|
|
353
|
+
var import_react_router4 = require("react-router");
|
|
354
|
+
|
|
355
|
+
// src/client/store_text_editor.tsx
|
|
356
|
+
var import_dn_react_text_editor = require("dn-react-text-editor");
|
|
357
|
+
var import_react_store_input2 = require("react-store-input");
|
|
358
|
+
var import_react4 = require("react");
|
|
359
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
360
|
+
|
|
361
|
+
// src/client/editor.tsx
|
|
362
|
+
var import_client = require("gw-file/client");
|
|
363
|
+
|
|
364
|
+
// src/crud/crud_form.tsx
|
|
365
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
366
|
+
|
|
367
|
+
// src/api/put_resource_handler.ts
|
|
368
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
369
|
+
var import_uuid = require("uuid");
|
|
370
|
+
function putResourceHandler({
|
|
292
371
|
repository,
|
|
293
372
|
validators,
|
|
294
373
|
existingConditions,
|
|
295
374
|
injectUserId,
|
|
296
|
-
|
|
375
|
+
isOwnedBy
|
|
297
376
|
}) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
377
|
+
return async (auth, request) => {
|
|
378
|
+
const serilaizedParams = await request.json();
|
|
379
|
+
const params = deserialize(serilaizedParams) || {};
|
|
380
|
+
const itemId = params.id || (0, import_uuid.v4)();
|
|
381
|
+
if (params.id) {
|
|
382
|
+
const existing = await repository.find(itemId);
|
|
383
|
+
if (!existing) {
|
|
384
|
+
return (0, import_gw_response2.httpNotFound)();
|
|
385
|
+
}
|
|
386
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
387
|
+
return (0, import_gw_response2.httpForbidden)();
|
|
388
|
+
}
|
|
307
389
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
)
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (validator?.validate && !validator.validate(value)) {
|
|
321
|
-
throw (0, import_gw_response2.httpBadRequest)({
|
|
322
|
-
code: "BAD_REQUEST",
|
|
323
|
-
message: validator.message ? validator.message(value) : "\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4."
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
}
|
|
390
|
+
if (validators) {
|
|
391
|
+
const paramsForValidation = Object.keys(validators).filter(
|
|
392
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
393
|
+
);
|
|
394
|
+
for (const paramKey of paramsForValidation) {
|
|
395
|
+
const value = params[paramKey];
|
|
396
|
+
const validator = validators[paramKey];
|
|
397
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
398
|
+
return (0, import_gw_response2.httpBadRequest)({
|
|
399
|
+
code: "BAD_REQUEST",
|
|
400
|
+
message: validator.message ? validator.message(value) : "\uC798\uBABB\uB41C \uC694\uCCAD\uC785\uB2C8\uB2E4."
|
|
401
|
+
});
|
|
327
402
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
acc.push(condition(params[key]));
|
|
341
|
-
}
|
|
342
|
-
return acc;
|
|
343
|
-
}, [])
|
|
344
|
-
);
|
|
345
|
-
const existing = await repository.findAll({
|
|
346
|
-
limit: 1,
|
|
347
|
-
where
|
|
348
|
-
});
|
|
349
|
-
if (existing.length > 0) {
|
|
350
|
-
return (0, import_gw_response2.httpConflict)({
|
|
351
|
-
code: "CONFLICT",
|
|
352
|
-
message: "\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4."
|
|
353
|
-
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (!params.id && existingConditions) {
|
|
406
|
+
const paramsForExistenceCheck = Object.keys(existingConditions).filter(
|
|
407
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
408
|
+
);
|
|
409
|
+
if (paramsForExistenceCheck.length > 0) {
|
|
410
|
+
const where = (0, import_drizzle_orm.and)(
|
|
411
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
412
|
+
const condition = existingConditions[key];
|
|
413
|
+
if (condition) {
|
|
414
|
+
acc.push(condition(params[key]));
|
|
354
415
|
}
|
|
355
|
-
|
|
416
|
+
return acc;
|
|
417
|
+
}, [])
|
|
418
|
+
);
|
|
419
|
+
const existing = await repository.findAll({
|
|
420
|
+
limit: 1,
|
|
421
|
+
where
|
|
422
|
+
});
|
|
423
|
+
if (existing.length > 0) {
|
|
424
|
+
return (0, import_gw_response2.httpConflict)();
|
|
356
425
|
}
|
|
357
|
-
const values = {
|
|
358
|
-
id: itemId,
|
|
359
|
-
userId: injectUserId ? auth?.userId : void 0,
|
|
360
|
-
...params
|
|
361
|
-
};
|
|
362
|
-
const item = await repository.save(values);
|
|
363
|
-
return (0, import_gw_response2.httpCreated)(item);
|
|
364
426
|
}
|
|
365
|
-
default:
|
|
366
|
-
throw (0, import_gw_response2.httpMethodNotAllowed)({
|
|
367
|
-
code: "METHOD_NOT_ALLOWED",
|
|
368
|
-
message: "\uD5C8\uC6A9\uB418\uC9C0 \uC54A\uC740 \uBA54\uC11C\uB4DC\uC785\uB2C8\uB2E4."
|
|
369
|
-
});
|
|
370
427
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
428
|
+
const values = {
|
|
429
|
+
id: itemId,
|
|
430
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
431
|
+
...params
|
|
432
|
+
};
|
|
433
|
+
const item = await repository.save(values);
|
|
434
|
+
return (0, import_gw_response2.httpCreated)(item);
|
|
375
435
|
};
|
|
376
436
|
}
|
|
377
437
|
|
|
378
|
-
// src/api/
|
|
379
|
-
|
|
380
|
-
var import_gw_result = require("gw-result");
|
|
381
|
-
function itemApiHandler({
|
|
438
|
+
// src/api/resource_handler.ts
|
|
439
|
+
function resourceHandler({
|
|
382
440
|
withAuthAction,
|
|
383
441
|
repository,
|
|
384
|
-
|
|
385
|
-
|
|
442
|
+
validators,
|
|
443
|
+
existingConditions,
|
|
444
|
+
injectUserId,
|
|
445
|
+
roles,
|
|
446
|
+
isOwnedBy
|
|
386
447
|
}) {
|
|
387
448
|
const loader = async ({ request }) => {
|
|
388
449
|
return (0, import_gw_result.ok)({});
|
|
389
450
|
};
|
|
390
|
-
const action = withAuthAction((auth) => async ({
|
|
451
|
+
const action = withAuthAction((auth) => async ({ request, params }) => {
|
|
391
452
|
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
392
|
-
return (0, import_gw_response3.httpUnauthorized)({
|
|
393
|
-
code: "UNAUTHORIZED",
|
|
394
|
-
message: "\uC778\uC99D\uC774 \uD544\uC694\uD569\uB2C8\uB2E4."
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
const itemId = params.itemId;
|
|
398
|
-
const existing = await repository.find(itemId);
|
|
399
|
-
if (!existing) {
|
|
400
|
-
return (0, import_gw_response3.httpNotFound)({
|
|
401
|
-
code: "RESOURCE_NOT_FOUND",
|
|
402
|
-
message: "\uC790\uB8CC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
if (isOwnedBy && !isOwnedBy(existing, auth)) {
|
|
406
453
|
return (0, import_gw_response3.httpForbidden)({
|
|
407
454
|
code: "FORBIDDEN",
|
|
408
455
|
message: "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
409
456
|
});
|
|
410
457
|
}
|
|
458
|
+
const itemId = params.itemId;
|
|
459
|
+
if (itemId) {
|
|
460
|
+
const existing = await repository.find(itemId);
|
|
461
|
+
if (!existing) {
|
|
462
|
+
return (0, import_gw_response3.httpNotFound)();
|
|
463
|
+
}
|
|
464
|
+
if (isOwnedBy && (!auth || !isOwnedBy(auth, existing))) {
|
|
465
|
+
return (0, import_gw_response3.httpForbidden)();
|
|
466
|
+
}
|
|
467
|
+
switch (request.method) {
|
|
468
|
+
case "DELETE": {
|
|
469
|
+
await repository.delete(itemId);
|
|
470
|
+
return (0, import_gw_response3.httpNoContent)();
|
|
471
|
+
}
|
|
472
|
+
default: {
|
|
473
|
+
return (0, import_gw_response3.httpMethodNotAllowed)();
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
411
477
|
switch (request.method) {
|
|
412
|
-
case "
|
|
413
|
-
|
|
414
|
-
|
|
478
|
+
case "POST":
|
|
479
|
+
case "PUT": {
|
|
480
|
+
const handler = putResourceHandler({
|
|
481
|
+
repository,
|
|
482
|
+
validators,
|
|
483
|
+
existingConditions,
|
|
484
|
+
injectUserId,
|
|
485
|
+
isOwnedBy
|
|
486
|
+
});
|
|
487
|
+
return handler(auth, request);
|
|
415
488
|
}
|
|
416
489
|
default: {
|
|
417
|
-
return (0, import_gw_response3.httpMethodNotAllowed)(
|
|
418
|
-
code: "METHOD_NOT_ALLOWED",
|
|
419
|
-
message: "\uD5C8\uC6A9\uB418\uC9C0 \uC54A\uC740 \uBA54\uC11C\uB4DC\uC785\uB2C8\uB2E4."
|
|
420
|
-
});
|
|
490
|
+
return (0, import_gw_response3.httpMethodNotAllowed)();
|
|
421
491
|
}
|
|
422
492
|
}
|
|
423
493
|
});
|
|
@@ -428,7 +498,7 @@ function itemApiHandler({
|
|
|
428
498
|
}
|
|
429
499
|
// Annotate the CommonJS export names for ESM import in node:
|
|
430
500
|
0 && (module.exports = {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
501
|
+
defaultAPIHandler,
|
|
502
|
+
putResourceHandler,
|
|
503
|
+
resourceHandler
|
|
434
504
|
});
|