dn-react-router-toolkit 0.7.5 → 0.7.7
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 -1
- package/dist/api/create_api_handler.d.ts +2 -1
- package/dist/api/create_api_handler.js +5 -4
- package/dist/api/create_api_handler.mjs +8 -8
- package/dist/api/index.d.mts +7 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +163 -2
- package/dist/api/index.mjs +169 -1
- package/dist/crud/crud_loader.js +5 -4
- package/dist/crud/crud_loader.mjs +10 -10
- package/dist/crud/index.js +5 -4
- package/dist/crud/index.mjs +10 -10
- package/dist/post/index.mjs +4 -5
- package/dist/post/post_form_page.mjs +4 -5
- package/package.json +1 -1
|
@@ -19,8 +19,9 @@ type APIHandlerOptions<T extends Table, TSelect> = {
|
|
|
19
19
|
[K in keyof InferInsertModel<T>]?: (value: InferInsertModel<T>[K]) => SQLWrapper;
|
|
20
20
|
};
|
|
21
21
|
injectUserId?: boolean;
|
|
22
|
+
roles?: string[];
|
|
22
23
|
};
|
|
23
|
-
declare function apiHandler<T extends Table, TSelect>({ withAuthAction, repository, validators, existingConditions, injectUserId, }: APIHandlerOptions<T, TSelect>): {
|
|
24
|
+
declare function apiHandler<T extends Table, TSelect>({ withAuthAction, repository, validators, existingConditions, injectUserId, roles, }: APIHandlerOptions<T, TSelect>): {
|
|
24
25
|
loader: ({ request }: LoaderFunctionArgs) => Promise<{}>;
|
|
25
26
|
action: (arg: ActionFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
26
27
|
};
|
|
@@ -19,8 +19,9 @@ type APIHandlerOptions<T extends Table, TSelect> = {
|
|
|
19
19
|
[K in keyof InferInsertModel<T>]?: (value: InferInsertModel<T>[K]) => SQLWrapper;
|
|
20
20
|
};
|
|
21
21
|
injectUserId?: boolean;
|
|
22
|
+
roles?: string[];
|
|
22
23
|
};
|
|
23
|
-
declare function apiHandler<T extends Table, TSelect>({ withAuthAction, repository, validators, existingConditions, injectUserId, }: APIHandlerOptions<T, TSelect>): {
|
|
24
|
+
declare function apiHandler<T extends Table, TSelect>({ withAuthAction, repository, validators, existingConditions, injectUserId, roles, }: APIHandlerOptions<T, TSelect>): {
|
|
24
25
|
loader: ({ request }: LoaderFunctionArgs) => Promise<{}>;
|
|
25
26
|
action: (arg: ActionFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
26
27
|
};
|
|
@@ -71,14 +71,15 @@ function apiHandler({
|
|
|
71
71
|
repository,
|
|
72
72
|
validators,
|
|
73
73
|
existingConditions,
|
|
74
|
-
injectUserId
|
|
74
|
+
injectUserId,
|
|
75
|
+
roles
|
|
75
76
|
}) {
|
|
76
77
|
const loader = async ({ request }) => {
|
|
77
78
|
return {};
|
|
78
79
|
};
|
|
79
80
|
const action = withAuthAction((auth) => async ({ request }) => {
|
|
80
|
-
if (!auth || auth.role
|
|
81
|
-
|
|
81
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
82
|
+
throw (0, import_http.UNAUTHORIZED)();
|
|
82
83
|
}
|
|
83
84
|
switch (request.method) {
|
|
84
85
|
case "POST":
|
|
@@ -128,7 +129,7 @@ function apiHandler({
|
|
|
128
129
|
}
|
|
129
130
|
const values = {
|
|
130
131
|
id: itemId,
|
|
131
|
-
userId: injectUserId ? auth
|
|
132
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
132
133
|
...params
|
|
133
134
|
};
|
|
134
135
|
const item = await repository.save(values);
|
|
@@ -4,14 +4,13 @@ import {
|
|
|
4
4
|
CONFLICT,
|
|
5
5
|
CREATED,
|
|
6
6
|
INTERNAL_SERVER_ERROR,
|
|
7
|
-
METHOD_NOT_ALLOWED
|
|
7
|
+
METHOD_NOT_ALLOWED,
|
|
8
|
+
UNAUTHORIZED
|
|
8
9
|
} from "dn-react-toolkit/http";
|
|
9
10
|
import {
|
|
10
11
|
and
|
|
11
12
|
} from "drizzle-orm";
|
|
12
|
-
import
|
|
13
|
-
redirect
|
|
14
|
-
} from "react-router";
|
|
13
|
+
import "react-router";
|
|
15
14
|
import { v4 } from "uuid";
|
|
16
15
|
|
|
17
16
|
// src/crud/serialize.ts
|
|
@@ -57,14 +56,15 @@ function apiHandler({
|
|
|
57
56
|
repository,
|
|
58
57
|
validators,
|
|
59
58
|
existingConditions,
|
|
60
|
-
injectUserId
|
|
59
|
+
injectUserId,
|
|
60
|
+
roles
|
|
61
61
|
}) {
|
|
62
62
|
const loader = async ({ request }) => {
|
|
63
63
|
return {};
|
|
64
64
|
};
|
|
65
65
|
const action = withAuthAction((auth) => async ({ request }) => {
|
|
66
|
-
if (!auth || auth.role
|
|
67
|
-
|
|
66
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
67
|
+
throw UNAUTHORIZED();
|
|
68
68
|
}
|
|
69
69
|
switch (request.method) {
|
|
70
70
|
case "POST":
|
|
@@ -114,7 +114,7 @@ function apiHandler({
|
|
|
114
114
|
}
|
|
115
115
|
const values = {
|
|
116
116
|
id: itemId,
|
|
117
|
-
userId: injectUserId ? auth
|
|
117
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
118
118
|
...params
|
|
119
119
|
};
|
|
120
120
|
const item = await repository.save(values);
|
package/dist/api/index.d.mts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export { createAPIHandler } from './create_handler.mjs';
|
|
2
|
+
export { APIHandlerOptions, apiHandler } from './create_api_handler.mjs';
|
|
3
|
+
export { ItemAPIHandlerOptions, itemApiHandler } from './item_api_handler.mjs';
|
|
2
4
|
import 'react-router';
|
|
3
5
|
import 'dn-react-toolkit/auth/server';
|
|
4
6
|
import 'dn-react-toolkit/file/server';
|
|
7
|
+
import 'drizzle-orm';
|
|
8
|
+
import '../table/repository.mjs';
|
|
9
|
+
import 'drizzle-orm/pg-core';
|
|
10
|
+
import '../auth/with_auth.mjs';
|
|
11
|
+
import 'dn-react-toolkit/auth';
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export { createAPIHandler } from './create_handler.js';
|
|
2
|
+
export { APIHandlerOptions, apiHandler } from './create_api_handler.js';
|
|
3
|
+
export { ItemAPIHandlerOptions, itemApiHandler } from './item_api_handler.js';
|
|
2
4
|
import 'react-router';
|
|
3
5
|
import 'dn-react-toolkit/auth/server';
|
|
4
6
|
import 'dn-react-toolkit/file/server';
|
|
7
|
+
import 'drizzle-orm';
|
|
8
|
+
import '../table/repository.js';
|
|
9
|
+
import 'drizzle-orm/pg-core';
|
|
10
|
+
import '../auth/with_auth.js';
|
|
11
|
+
import 'dn-react-toolkit/auth';
|
package/dist/api/index.js
CHANGED
|
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/api/index.ts
|
|
21
21
|
var api_exports = {};
|
|
22
22
|
__export(api_exports, {
|
|
23
|
-
|
|
23
|
+
apiHandler: () => apiHandler,
|
|
24
|
+
createAPIHandler: () => createAPIHandler,
|
|
25
|
+
itemApiHandler: () => itemApiHandler
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(api_exports);
|
|
26
28
|
|
|
@@ -237,7 +239,166 @@ var createAPIHandler = ({
|
|
|
237
239
|
};
|
|
238
240
|
return handler;
|
|
239
241
|
};
|
|
242
|
+
|
|
243
|
+
// src/api/create_api_handler.ts
|
|
244
|
+
var import_http2 = require("dn-react-toolkit/http");
|
|
245
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
246
|
+
var import_react_router2 = require("react-router");
|
|
247
|
+
var import_uuid2 = require("uuid");
|
|
248
|
+
|
|
249
|
+
// src/crud/serialize.ts
|
|
250
|
+
function deserialize(data) {
|
|
251
|
+
if (data === void 0) {
|
|
252
|
+
return void 0;
|
|
253
|
+
}
|
|
254
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
255
|
+
const { type, value } = data;
|
|
256
|
+
switch (type) {
|
|
257
|
+
case "null":
|
|
258
|
+
return null;
|
|
259
|
+
case "string":
|
|
260
|
+
return value;
|
|
261
|
+
case "number":
|
|
262
|
+
return value;
|
|
263
|
+
case "boolean":
|
|
264
|
+
return value;
|
|
265
|
+
case "date":
|
|
266
|
+
return new Date(value);
|
|
267
|
+
case "array":
|
|
268
|
+
return value.map((item) => deserialize(item));
|
|
269
|
+
case "object":
|
|
270
|
+
return Object.entries(value).reduce(
|
|
271
|
+
(acc, [key, value2]) => {
|
|
272
|
+
return {
|
|
273
|
+
...acc,
|
|
274
|
+
[key]: deserialize(value2)
|
|
275
|
+
};
|
|
276
|
+
},
|
|
277
|
+
{}
|
|
278
|
+
);
|
|
279
|
+
default:
|
|
280
|
+
return void 0;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return void 0;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/api/create_api_handler.ts
|
|
287
|
+
function apiHandler({
|
|
288
|
+
withAuthAction,
|
|
289
|
+
repository,
|
|
290
|
+
validators,
|
|
291
|
+
existingConditions,
|
|
292
|
+
injectUserId,
|
|
293
|
+
roles
|
|
294
|
+
}) {
|
|
295
|
+
const loader = async ({ request }) => {
|
|
296
|
+
return {};
|
|
297
|
+
};
|
|
298
|
+
const action = withAuthAction((auth) => async ({ request }) => {
|
|
299
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
300
|
+
throw (0, import_http2.UNAUTHORIZED)();
|
|
301
|
+
}
|
|
302
|
+
switch (request.method) {
|
|
303
|
+
case "POST":
|
|
304
|
+
case "PUT": {
|
|
305
|
+
try {
|
|
306
|
+
const serilaizedParams = await request.json();
|
|
307
|
+
const params = deserialize(serilaizedParams);
|
|
308
|
+
if (validators) {
|
|
309
|
+
const paramsForValidation = Object.keys(validators).filter(
|
|
310
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
311
|
+
);
|
|
312
|
+
for (const paramKey of paramsForValidation) {
|
|
313
|
+
const value = params[paramKey];
|
|
314
|
+
const validator = validators[paramKey];
|
|
315
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
316
|
+
throw (0, import_http2.BAD_REQUEST)(
|
|
317
|
+
validator.message ? validator.message(value) : void 0
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const itemId = params.id || (0, import_uuid2.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 = (0, import_drizzle_orm.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
|
+
}, [])
|
|
338
|
+
);
|
|
339
|
+
const existing = await repository.findAll({
|
|
340
|
+
limit: 1,
|
|
341
|
+
where
|
|
342
|
+
});
|
|
343
|
+
if (existing.length > 0) {
|
|
344
|
+
throw (0, import_http2.CONFLICT)("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const values = {
|
|
349
|
+
id: itemId,
|
|
350
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
351
|
+
...params
|
|
352
|
+
};
|
|
353
|
+
const item = await repository.save(values);
|
|
354
|
+
return (0, import_http2.CREATED)(item);
|
|
355
|
+
} catch (error) {
|
|
356
|
+
if (error instanceof Error) {
|
|
357
|
+
throw (0, import_http2.INTERNAL_SERVER_ERROR)(error.message);
|
|
358
|
+
}
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
default:
|
|
363
|
+
throw (0, import_http2.METHOD_NOT_ALLOWED)();
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
return {
|
|
367
|
+
loader,
|
|
368
|
+
action
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/api/item_api_handler.ts
|
|
373
|
+
var import_http3 = require("dn-react-toolkit/http");
|
|
374
|
+
var import_react_router3 = require("react-router");
|
|
375
|
+
function itemApiHandler({
|
|
376
|
+
withAuthAction,
|
|
377
|
+
repository
|
|
378
|
+
}) {
|
|
379
|
+
const loader = async ({ request }) => {
|
|
380
|
+
return {};
|
|
381
|
+
};
|
|
382
|
+
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
383
|
+
if (!auth || auth.role !== "admin") {
|
|
384
|
+
return (0, import_http3.UNAUTHORIZED)();
|
|
385
|
+
}
|
|
386
|
+
switch (request.method) {
|
|
387
|
+
case "DELETE": {
|
|
388
|
+
const itemId = params.itemId;
|
|
389
|
+
await repository.delete(itemId);
|
|
390
|
+
return {};
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
return {
|
|
395
|
+
loader,
|
|
396
|
+
action
|
|
397
|
+
};
|
|
398
|
+
}
|
|
240
399
|
// Annotate the CommonJS export names for ESM import in node:
|
|
241
400
|
0 && (module.exports = {
|
|
242
|
-
|
|
401
|
+
apiHandler,
|
|
402
|
+
createAPIHandler,
|
|
403
|
+
itemApiHandler
|
|
243
404
|
});
|
package/dist/api/index.mjs
CHANGED
|
@@ -225,6 +225,174 @@ var createAPIHandler = ({
|
|
|
225
225
|
};
|
|
226
226
|
return handler;
|
|
227
227
|
};
|
|
228
|
+
|
|
229
|
+
// src/api/create_api_handler.ts
|
|
230
|
+
import {
|
|
231
|
+
BAD_REQUEST,
|
|
232
|
+
CONFLICT,
|
|
233
|
+
CREATED,
|
|
234
|
+
INTERNAL_SERVER_ERROR,
|
|
235
|
+
METHOD_NOT_ALLOWED,
|
|
236
|
+
UNAUTHORIZED
|
|
237
|
+
} from "dn-react-toolkit/http";
|
|
238
|
+
import {
|
|
239
|
+
and
|
|
240
|
+
} from "drizzle-orm";
|
|
241
|
+
import "react-router";
|
|
242
|
+
import { v4 as v42 } from "uuid";
|
|
243
|
+
|
|
244
|
+
// src/crud/serialize.ts
|
|
245
|
+
function deserialize(data) {
|
|
246
|
+
if (data === void 0) {
|
|
247
|
+
return void 0;
|
|
248
|
+
}
|
|
249
|
+
if (typeof data === "object" && data !== null && "type" in data && "value" in data) {
|
|
250
|
+
const { type, value } = data;
|
|
251
|
+
switch (type) {
|
|
252
|
+
case "null":
|
|
253
|
+
return null;
|
|
254
|
+
case "string":
|
|
255
|
+
return value;
|
|
256
|
+
case "number":
|
|
257
|
+
return value;
|
|
258
|
+
case "boolean":
|
|
259
|
+
return value;
|
|
260
|
+
case "date":
|
|
261
|
+
return new Date(value);
|
|
262
|
+
case "array":
|
|
263
|
+
return value.map((item) => deserialize(item));
|
|
264
|
+
case "object":
|
|
265
|
+
return Object.entries(value).reduce(
|
|
266
|
+
(acc, [key, value2]) => {
|
|
267
|
+
return {
|
|
268
|
+
...acc,
|
|
269
|
+
[key]: deserialize(value2)
|
|
270
|
+
};
|
|
271
|
+
},
|
|
272
|
+
{}
|
|
273
|
+
);
|
|
274
|
+
default:
|
|
275
|
+
return void 0;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return void 0;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/api/create_api_handler.ts
|
|
282
|
+
function apiHandler({
|
|
283
|
+
withAuthAction,
|
|
284
|
+
repository,
|
|
285
|
+
validators,
|
|
286
|
+
existingConditions,
|
|
287
|
+
injectUserId,
|
|
288
|
+
roles
|
|
289
|
+
}) {
|
|
290
|
+
const loader = async ({ request }) => {
|
|
291
|
+
return {};
|
|
292
|
+
};
|
|
293
|
+
const action = withAuthAction((auth) => async ({ request }) => {
|
|
294
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
295
|
+
throw UNAUTHORIZED();
|
|
296
|
+
}
|
|
297
|
+
switch (request.method) {
|
|
298
|
+
case "POST":
|
|
299
|
+
case "PUT": {
|
|
300
|
+
try {
|
|
301
|
+
const serilaizedParams = await request.json();
|
|
302
|
+
const params = deserialize(serilaizedParams);
|
|
303
|
+
if (validators) {
|
|
304
|
+
const paramsForValidation = Object.keys(validators).filter(
|
|
305
|
+
(key) => Object.prototype.hasOwnProperty.call(validators, key)
|
|
306
|
+
);
|
|
307
|
+
for (const paramKey of paramsForValidation) {
|
|
308
|
+
const value = params[paramKey];
|
|
309
|
+
const validator = validators[paramKey];
|
|
310
|
+
if (validator?.validate && !validator.validate(value)) {
|
|
311
|
+
throw BAD_REQUEST(
|
|
312
|
+
validator.message ? validator.message(value) : void 0
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const itemId = params.id || v42();
|
|
318
|
+
if (!params.id && existingConditions) {
|
|
319
|
+
const paramsForExistenceCheck = Object.keys(
|
|
320
|
+
existingConditions
|
|
321
|
+
).filter(
|
|
322
|
+
(key) => Object.prototype.hasOwnProperty.call(params, key)
|
|
323
|
+
);
|
|
324
|
+
if (paramsForExistenceCheck.length > 0) {
|
|
325
|
+
const where = and(
|
|
326
|
+
...paramsForExistenceCheck.reduce((acc, key) => {
|
|
327
|
+
const condition = existingConditions[key];
|
|
328
|
+
if (condition) {
|
|
329
|
+
acc.push(condition(params[key]));
|
|
330
|
+
}
|
|
331
|
+
return acc;
|
|
332
|
+
}, [])
|
|
333
|
+
);
|
|
334
|
+
const existing = await repository.findAll({
|
|
335
|
+
limit: 1,
|
|
336
|
+
where
|
|
337
|
+
});
|
|
338
|
+
if (existing.length > 0) {
|
|
339
|
+
throw CONFLICT("\uC790\uB8CC\uAC00 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const values = {
|
|
344
|
+
id: itemId,
|
|
345
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
346
|
+
...params
|
|
347
|
+
};
|
|
348
|
+
const item = await repository.save(values);
|
|
349
|
+
return CREATED(item);
|
|
350
|
+
} catch (error) {
|
|
351
|
+
if (error instanceof Error) {
|
|
352
|
+
throw INTERNAL_SERVER_ERROR(error.message);
|
|
353
|
+
}
|
|
354
|
+
throw error;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
default:
|
|
358
|
+
throw METHOD_NOT_ALLOWED();
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
return {
|
|
362
|
+
loader,
|
|
363
|
+
action
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/api/item_api_handler.ts
|
|
368
|
+
import { UNAUTHORIZED as UNAUTHORIZED2 } from "dn-react-toolkit/http";
|
|
369
|
+
import "react-router";
|
|
370
|
+
function itemApiHandler({
|
|
371
|
+
withAuthAction,
|
|
372
|
+
repository
|
|
373
|
+
}) {
|
|
374
|
+
const loader = async ({ request }) => {
|
|
375
|
+
return {};
|
|
376
|
+
};
|
|
377
|
+
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
378
|
+
if (!auth || auth.role !== "admin") {
|
|
379
|
+
return UNAUTHORIZED2();
|
|
380
|
+
}
|
|
381
|
+
switch (request.method) {
|
|
382
|
+
case "DELETE": {
|
|
383
|
+
const itemId = params.itemId;
|
|
384
|
+
await repository.delete(itemId);
|
|
385
|
+
return {};
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
return {
|
|
390
|
+
loader,
|
|
391
|
+
action
|
|
392
|
+
};
|
|
393
|
+
}
|
|
228
394
|
export {
|
|
229
|
-
|
|
395
|
+
apiHandler,
|
|
396
|
+
createAPIHandler,
|
|
397
|
+
itemApiHandler
|
|
230
398
|
};
|
package/dist/crud/crud_loader.js
CHANGED
|
@@ -132,14 +132,15 @@ function apiHandler({
|
|
|
132
132
|
repository,
|
|
133
133
|
validators,
|
|
134
134
|
existingConditions,
|
|
135
|
-
injectUserId
|
|
135
|
+
injectUserId,
|
|
136
|
+
roles
|
|
136
137
|
}) {
|
|
137
138
|
const loader = async ({ request }) => {
|
|
138
139
|
return {};
|
|
139
140
|
};
|
|
140
141
|
const action = withAuthAction((auth) => async ({ request }) => {
|
|
141
|
-
if (!auth || auth.role
|
|
142
|
-
|
|
142
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
143
|
+
throw (0, import_http.UNAUTHORIZED)();
|
|
143
144
|
}
|
|
144
145
|
switch (request.method) {
|
|
145
146
|
case "POST":
|
|
@@ -189,7 +190,7 @@ function apiHandler({
|
|
|
189
190
|
}
|
|
190
191
|
const values = {
|
|
191
192
|
id: itemId,
|
|
192
|
-
userId: injectUserId ? auth
|
|
193
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
193
194
|
...params
|
|
194
195
|
};
|
|
195
196
|
const item = await repository.save(values);
|
|
@@ -66,14 +66,13 @@ import {
|
|
|
66
66
|
CONFLICT,
|
|
67
67
|
CREATED,
|
|
68
68
|
INTERNAL_SERVER_ERROR,
|
|
69
|
-
METHOD_NOT_ALLOWED
|
|
69
|
+
METHOD_NOT_ALLOWED,
|
|
70
|
+
UNAUTHORIZED
|
|
70
71
|
} from "dn-react-toolkit/http";
|
|
71
72
|
import {
|
|
72
73
|
and as and2
|
|
73
74
|
} from "drizzle-orm";
|
|
74
|
-
import
|
|
75
|
-
redirect
|
|
76
|
-
} from "react-router";
|
|
75
|
+
import "react-router";
|
|
77
76
|
import { v4 } from "uuid";
|
|
78
77
|
|
|
79
78
|
// src/crud/serialize.ts
|
|
@@ -119,14 +118,15 @@ function apiHandler({
|
|
|
119
118
|
repository,
|
|
120
119
|
validators,
|
|
121
120
|
existingConditions,
|
|
122
|
-
injectUserId
|
|
121
|
+
injectUserId,
|
|
122
|
+
roles
|
|
123
123
|
}) {
|
|
124
124
|
const loader = async ({ request }) => {
|
|
125
125
|
return {};
|
|
126
126
|
};
|
|
127
127
|
const action = withAuthAction((auth) => async ({ request }) => {
|
|
128
|
-
if (!auth || auth.role
|
|
129
|
-
|
|
128
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
129
|
+
throw UNAUTHORIZED();
|
|
130
130
|
}
|
|
131
131
|
switch (request.method) {
|
|
132
132
|
case "POST":
|
|
@@ -176,7 +176,7 @@ function apiHandler({
|
|
|
176
176
|
}
|
|
177
177
|
const values = {
|
|
178
178
|
id: itemId,
|
|
179
|
-
userId: injectUserId ? auth
|
|
179
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
180
180
|
...params
|
|
181
181
|
};
|
|
182
182
|
const item = await repository.save(values);
|
|
@@ -199,7 +199,7 @@ function apiHandler({
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
// src/api/item_api_handler.ts
|
|
202
|
-
import { UNAUTHORIZED } from "dn-react-toolkit/http";
|
|
202
|
+
import { UNAUTHORIZED as UNAUTHORIZED2 } from "dn-react-toolkit/http";
|
|
203
203
|
import "react-router";
|
|
204
204
|
function itemApiHandler({
|
|
205
205
|
withAuthAction,
|
|
@@ -210,7 +210,7 @@ function itemApiHandler({
|
|
|
210
210
|
};
|
|
211
211
|
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
212
212
|
if (!auth || auth.role !== "admin") {
|
|
213
|
-
return
|
|
213
|
+
return UNAUTHORIZED2();
|
|
214
214
|
}
|
|
215
215
|
switch (request.method) {
|
|
216
216
|
case "DELETE": {
|
package/dist/crud/index.js
CHANGED
|
@@ -8038,14 +8038,15 @@ function apiHandler({
|
|
|
8038
8038
|
repository,
|
|
8039
8039
|
validators,
|
|
8040
8040
|
existingConditions,
|
|
8041
|
-
injectUserId
|
|
8041
|
+
injectUserId,
|
|
8042
|
+
roles
|
|
8042
8043
|
}) {
|
|
8043
8044
|
const loader = async ({ request }) => {
|
|
8044
8045
|
return {};
|
|
8045
8046
|
};
|
|
8046
8047
|
const action = withAuthAction((auth) => async ({ request }) => {
|
|
8047
|
-
if (!auth || auth.role
|
|
8048
|
-
|
|
8048
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
8049
|
+
throw (0, import_http.UNAUTHORIZED)();
|
|
8049
8050
|
}
|
|
8050
8051
|
switch (request.method) {
|
|
8051
8052
|
case "POST":
|
|
@@ -8095,7 +8096,7 @@ function apiHandler({
|
|
|
8095
8096
|
}
|
|
8096
8097
|
const values = {
|
|
8097
8098
|
id: itemId,
|
|
8098
|
-
userId: injectUserId ? auth
|
|
8099
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
8099
8100
|
...params
|
|
8100
8101
|
};
|
|
8101
8102
|
const item = await repository.save(values);
|
package/dist/crud/index.mjs
CHANGED
|
@@ -8018,28 +8018,28 @@ import {
|
|
|
8018
8018
|
CONFLICT,
|
|
8019
8019
|
CREATED,
|
|
8020
8020
|
INTERNAL_SERVER_ERROR,
|
|
8021
|
-
METHOD_NOT_ALLOWED
|
|
8021
|
+
METHOD_NOT_ALLOWED,
|
|
8022
|
+
UNAUTHORIZED
|
|
8022
8023
|
} from "dn-react-toolkit/http";
|
|
8023
8024
|
import {
|
|
8024
8025
|
and as and2
|
|
8025
8026
|
} from "drizzle-orm";
|
|
8026
|
-
import
|
|
8027
|
-
redirect
|
|
8028
|
-
} from "react-router";
|
|
8027
|
+
import "react-router";
|
|
8029
8028
|
import { v4 } from "uuid";
|
|
8030
8029
|
function apiHandler({
|
|
8031
8030
|
withAuthAction,
|
|
8032
8031
|
repository,
|
|
8033
8032
|
validators,
|
|
8034
8033
|
existingConditions,
|
|
8035
|
-
injectUserId
|
|
8034
|
+
injectUserId,
|
|
8035
|
+
roles
|
|
8036
8036
|
}) {
|
|
8037
8037
|
const loader = async ({ request }) => {
|
|
8038
8038
|
return {};
|
|
8039
8039
|
};
|
|
8040
8040
|
const action = withAuthAction((auth) => async ({ request }) => {
|
|
8041
|
-
if (!auth || auth.role
|
|
8042
|
-
|
|
8041
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
8042
|
+
throw UNAUTHORIZED();
|
|
8043
8043
|
}
|
|
8044
8044
|
switch (request.method) {
|
|
8045
8045
|
case "POST":
|
|
@@ -8089,7 +8089,7 @@ function apiHandler({
|
|
|
8089
8089
|
}
|
|
8090
8090
|
const values = {
|
|
8091
8091
|
id: itemId,
|
|
8092
|
-
userId: injectUserId ? auth
|
|
8092
|
+
userId: injectUserId ? auth?.userId : void 0,
|
|
8093
8093
|
...params
|
|
8094
8094
|
};
|
|
8095
8095
|
const item = await repository.save(values);
|
|
@@ -8112,7 +8112,7 @@ function apiHandler({
|
|
|
8112
8112
|
}
|
|
8113
8113
|
|
|
8114
8114
|
// src/api/item_api_handler.ts
|
|
8115
|
-
import { UNAUTHORIZED } from "dn-react-toolkit/http";
|
|
8115
|
+
import { UNAUTHORIZED as UNAUTHORIZED2 } from "dn-react-toolkit/http";
|
|
8116
8116
|
import "react-router";
|
|
8117
8117
|
function itemApiHandler({
|
|
8118
8118
|
withAuthAction,
|
|
@@ -8123,7 +8123,7 @@ function itemApiHandler({
|
|
|
8123
8123
|
};
|
|
8124
8124
|
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
8125
8125
|
if (!auth || auth.role !== "admin") {
|
|
8126
|
-
return
|
|
8126
|
+
return UNAUTHORIZED2();
|
|
8127
8127
|
}
|
|
8128
8128
|
switch (request.method) {
|
|
8129
8129
|
case "DELETE": {
|
package/dist/post/index.mjs
CHANGED
|
@@ -8083,18 +8083,17 @@ import {
|
|
|
8083
8083
|
CONFLICT,
|
|
8084
8084
|
CREATED,
|
|
8085
8085
|
INTERNAL_SERVER_ERROR,
|
|
8086
|
-
METHOD_NOT_ALLOWED
|
|
8086
|
+
METHOD_NOT_ALLOWED,
|
|
8087
|
+
UNAUTHORIZED
|
|
8087
8088
|
} from "dn-react-toolkit/http";
|
|
8088
8089
|
import {
|
|
8089
8090
|
and as and2
|
|
8090
8091
|
} from "drizzle-orm";
|
|
8091
|
-
import
|
|
8092
|
-
redirect
|
|
8093
|
-
} from "react-router";
|
|
8092
|
+
import "react-router";
|
|
8094
8093
|
import { v4 } from "uuid";
|
|
8095
8094
|
|
|
8096
8095
|
// src/api/item_api_handler.ts
|
|
8097
|
-
import { UNAUTHORIZED } from "dn-react-toolkit/http";
|
|
8096
|
+
import { UNAUTHORIZED as UNAUTHORIZED2 } from "dn-react-toolkit/http";
|
|
8098
8097
|
import "react-router";
|
|
8099
8098
|
|
|
8100
8099
|
// src/crud/crud_page.tsx
|
|
@@ -8085,18 +8085,17 @@ import {
|
|
|
8085
8085
|
CONFLICT,
|
|
8086
8086
|
CREATED,
|
|
8087
8087
|
INTERNAL_SERVER_ERROR,
|
|
8088
|
-
METHOD_NOT_ALLOWED
|
|
8088
|
+
METHOD_NOT_ALLOWED,
|
|
8089
|
+
UNAUTHORIZED
|
|
8089
8090
|
} from "dn-react-toolkit/http";
|
|
8090
8091
|
import {
|
|
8091
8092
|
and as and2
|
|
8092
8093
|
} from "drizzle-orm";
|
|
8093
|
-
import
|
|
8094
|
-
redirect
|
|
8095
|
-
} from "react-router";
|
|
8094
|
+
import "react-router";
|
|
8096
8095
|
import { v4 } from "uuid";
|
|
8097
8096
|
|
|
8098
8097
|
// src/api/item_api_handler.ts
|
|
8099
|
-
import { UNAUTHORIZED } from "dn-react-toolkit/http";
|
|
8098
|
+
import { UNAUTHORIZED as UNAUTHORIZED2 } from "dn-react-toolkit/http";
|
|
8100
8099
|
import "react-router";
|
|
8101
8100
|
|
|
8102
8101
|
// src/crud/crud_page.tsx
|