dn-react-router-toolkit 0.8.0 → 0.9.0
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/index.js +13 -4
- package/dist/api/index.mjs +14 -5
- package/dist/api/item_api_handler.d.mts +4 -2
- package/dist/api/item_api_handler.d.ts +4 -2
- package/dist/api/item_api_handler.js +13 -4
- package/dist/api/item_api_handler.mjs +14 -5
- package/dist/crud/index.d.mts +0 -20
- package/dist/crud/index.d.ts +0 -20
- package/dist/crud/index.js +12 -8508
- package/dist/crud/index.mjs +0 -8516
- package/dist/post/index.js +67 -7705
- package/dist/post/index.mjs +54 -7717
- package/dist/post/post_form_page.js +67 -7705
- package/dist/post/post_form_page.mjs +54 -7717
- package/dist/table/index.d.mts +1 -3
- package/dist/table/index.d.ts +1 -3
- package/dist/table/index.js +83 -76
- package/dist/table/index.mjs +84 -74
- package/dist/table/load_table.d.mts +8 -2
- package/dist/table/load_table.d.ts +8 -2
- package/dist/table/load_table.js +23 -3
- package/dist/table/load_table.mjs +24 -3
- package/dist/table/loader.d.mts +3 -0
- package/dist/table/loader.d.ts +3 -0
- package/dist/table/loader.js +23 -3
- package/dist/table/loader.mjs +24 -3
- package/dist/table/repository.d.mts +6 -4
- package/dist/table/repository.d.ts +6 -4
- package/dist/table/repository.js +4 -0
- package/dist/table/repository.mjs +4 -0
- package/dist/table/table.d.mts +5 -2
- package/dist/table/table.d.ts +5 -2
- package/dist/table/table.js +38 -6
- package/dist/table/table.mjs +38 -6
- package/dist/table/table_form.d.mts +2 -2
- package/dist/table/table_form.d.ts +2 -2
- package/dist/table/table_form.js +52 -19
- package/dist/table/table_form.mjs +52 -19
- package/dist/table/use_table.d.mts +3 -3
- package/dist/table/use_table.d.ts +3 -3
- package/dist/table/use_table.js +1 -10
- package/dist/table/use_table.mjs +1 -10
- package/package.json +1 -1
- 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 -322
- package/dist/crud/crud_loader.mjs +0 -307
- 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 -726
- package/dist/crud/crud_page.mjs +0 -708
- package/dist/crud/generate_handlers.d.mts +0 -16
- package/dist/crud/generate_handlers.d.ts +0 -16
- package/dist/crud/generate_handlers.js +0 -39
- 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.js +0 -55
- 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.js +0 -43
- 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 -325
- package/dist/table/page.mjs +0 -300
package/dist/api/index.js
CHANGED
|
@@ -379,18 +379,27 @@ function apiHandler({
|
|
|
379
379
|
var import_http3 = require("dn-react-toolkit/http");
|
|
380
380
|
function itemApiHandler({
|
|
381
381
|
withAuthAction,
|
|
382
|
-
repository
|
|
382
|
+
repository,
|
|
383
|
+
isOwnedBy,
|
|
384
|
+
roles
|
|
383
385
|
}) {
|
|
384
386
|
const loader = async ({ request }) => {
|
|
385
387
|
return {};
|
|
386
388
|
};
|
|
387
389
|
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
388
|
-
if (!auth || auth.role
|
|
389
|
-
|
|
390
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
391
|
+
throw (0, import_http3.UNAUTHORIZED)();
|
|
392
|
+
}
|
|
393
|
+
const itemId = params.itemId;
|
|
394
|
+
const existing = await repository.find(itemId);
|
|
395
|
+
if (!existing) {
|
|
396
|
+
throw (0, import_http3.NOT_FOUND)();
|
|
397
|
+
}
|
|
398
|
+
if (isOwnedBy && !isOwnedBy(existing, auth)) {
|
|
399
|
+
throw (0, import_http3.FORBIDDEN)();
|
|
390
400
|
}
|
|
391
401
|
switch (request.method) {
|
|
392
402
|
case "DELETE": {
|
|
393
|
-
const itemId = params.itemId;
|
|
394
403
|
await repository.delete(itemId);
|
|
395
404
|
return {};
|
|
396
405
|
}
|
package/dist/api/index.mjs
CHANGED
|
@@ -371,21 +371,30 @@ function apiHandler({
|
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
// src/api/item_api_handler.ts
|
|
374
|
-
import { UNAUTHORIZED as UNAUTHORIZED2 } from "dn-react-toolkit/http";
|
|
374
|
+
import { FORBIDDEN, NOT_FOUND as NOT_FOUND2, UNAUTHORIZED as UNAUTHORIZED2 } from "dn-react-toolkit/http";
|
|
375
375
|
function itemApiHandler({
|
|
376
376
|
withAuthAction,
|
|
377
|
-
repository
|
|
377
|
+
repository,
|
|
378
|
+
isOwnedBy,
|
|
379
|
+
roles
|
|
378
380
|
}) {
|
|
379
381
|
const loader = async ({ request }) => {
|
|
380
382
|
return {};
|
|
381
383
|
};
|
|
382
384
|
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
383
|
-
if (!auth || auth.role
|
|
384
|
-
|
|
385
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
386
|
+
throw UNAUTHORIZED2();
|
|
387
|
+
}
|
|
388
|
+
const itemId = params.itemId;
|
|
389
|
+
const existing = await repository.find(itemId);
|
|
390
|
+
if (!existing) {
|
|
391
|
+
throw NOT_FOUND2();
|
|
392
|
+
}
|
|
393
|
+
if (isOwnedBy && !isOwnedBy(existing, auth)) {
|
|
394
|
+
throw FORBIDDEN();
|
|
385
395
|
}
|
|
386
396
|
switch (request.method) {
|
|
387
397
|
case "DELETE": {
|
|
388
|
-
const itemId = params.itemId;
|
|
389
398
|
await repository.delete(itemId);
|
|
390
399
|
return {};
|
|
391
400
|
}
|
|
@@ -2,16 +2,18 @@ import { LoaderFunctionArgs } from 'react-router';
|
|
|
2
2
|
import { TableRepository } from '../table/repository.mjs';
|
|
3
3
|
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
4
|
import { WithAuthHandler } from '../auth/with_auth.mjs';
|
|
5
|
+
import { AccessTokenPayload } from 'dn-react-toolkit/auth';
|
|
5
6
|
import 'drizzle-orm';
|
|
6
7
|
import 'drizzle-orm/node-postgres';
|
|
7
|
-
import 'dn-react-toolkit/auth';
|
|
8
8
|
import 'dn-react-toolkit/auth/server';
|
|
9
9
|
|
|
10
10
|
type ItemAPIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
11
11
|
withAuthAction: WithAuthHandler<LoaderFunctionArgs>;
|
|
12
12
|
repository: TableRepository<T, TSelect>;
|
|
13
|
+
isOwnedBy?: (item: TSelect, auth: AccessTokenPayload | undefined) => boolean;
|
|
14
|
+
roles?: string[];
|
|
13
15
|
};
|
|
14
|
-
declare function itemApiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, }: ItemAPIHandlerOptions<T, TSelect>): {
|
|
16
|
+
declare function itemApiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, isOwnedBy, roles, }: ItemAPIHandlerOptions<T, TSelect>): {
|
|
15
17
|
loader: ({ request }: LoaderFunctionArgs) => Promise<{}>;
|
|
16
18
|
action: (arg: LoaderFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
17
19
|
};
|
|
@@ -2,16 +2,18 @@ import { LoaderFunctionArgs } from 'react-router';
|
|
|
2
2
|
import { TableRepository } from '../table/repository.js';
|
|
3
3
|
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
4
|
import { WithAuthHandler } from '../auth/with_auth.js';
|
|
5
|
+
import { AccessTokenPayload } from 'dn-react-toolkit/auth';
|
|
5
6
|
import 'drizzle-orm';
|
|
6
7
|
import 'drizzle-orm/node-postgres';
|
|
7
|
-
import 'dn-react-toolkit/auth';
|
|
8
8
|
import 'dn-react-toolkit/auth/server';
|
|
9
9
|
|
|
10
10
|
type ItemAPIHandlerOptions<T extends PgTableWithColumns<any>, TSelect> = {
|
|
11
11
|
withAuthAction: WithAuthHandler<LoaderFunctionArgs>;
|
|
12
12
|
repository: TableRepository<T, TSelect>;
|
|
13
|
+
isOwnedBy?: (item: TSelect, auth: AccessTokenPayload | undefined) => boolean;
|
|
14
|
+
roles?: string[];
|
|
13
15
|
};
|
|
14
|
-
declare function itemApiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, }: ItemAPIHandlerOptions<T, TSelect>): {
|
|
16
|
+
declare function itemApiHandler<T extends PgTableWithColumns<any>, TSelect>({ withAuthAction, repository, isOwnedBy, roles, }: ItemAPIHandlerOptions<T, TSelect>): {
|
|
15
17
|
loader: ({ request }: LoaderFunctionArgs) => Promise<{}>;
|
|
16
18
|
action: (arg: LoaderFunctionArgs<any>) => Promise<unknown> | unknown;
|
|
17
19
|
};
|
|
@@ -26,18 +26,27 @@ module.exports = __toCommonJS(item_api_handler_exports);
|
|
|
26
26
|
var import_http = require("dn-react-toolkit/http");
|
|
27
27
|
function itemApiHandler({
|
|
28
28
|
withAuthAction,
|
|
29
|
-
repository
|
|
29
|
+
repository,
|
|
30
|
+
isOwnedBy,
|
|
31
|
+
roles
|
|
30
32
|
}) {
|
|
31
33
|
const loader = async ({ request }) => {
|
|
32
34
|
return {};
|
|
33
35
|
};
|
|
34
36
|
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
35
|
-
if (!auth || auth.role
|
|
36
|
-
|
|
37
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
38
|
+
throw (0, import_http.UNAUTHORIZED)();
|
|
39
|
+
}
|
|
40
|
+
const itemId = params.itemId;
|
|
41
|
+
const existing = await repository.find(itemId);
|
|
42
|
+
if (!existing) {
|
|
43
|
+
throw (0, import_http.NOT_FOUND)();
|
|
44
|
+
}
|
|
45
|
+
if (isOwnedBy && !isOwnedBy(existing, auth)) {
|
|
46
|
+
throw (0, import_http.FORBIDDEN)();
|
|
37
47
|
}
|
|
38
48
|
switch (request.method) {
|
|
39
49
|
case "DELETE": {
|
|
40
|
-
const itemId = params.itemId;
|
|
41
50
|
await repository.delete(itemId);
|
|
42
51
|
return {};
|
|
43
52
|
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
// src/api/item_api_handler.ts
|
|
2
|
-
import { UNAUTHORIZED } from "dn-react-toolkit/http";
|
|
2
|
+
import { FORBIDDEN, NOT_FOUND, UNAUTHORIZED } from "dn-react-toolkit/http";
|
|
3
3
|
function itemApiHandler({
|
|
4
4
|
withAuthAction,
|
|
5
|
-
repository
|
|
5
|
+
repository,
|
|
6
|
+
isOwnedBy,
|
|
7
|
+
roles
|
|
6
8
|
}) {
|
|
7
9
|
const loader = async ({ request }) => {
|
|
8
10
|
return {};
|
|
9
11
|
};
|
|
10
12
|
const action = withAuthAction((auth) => async ({ params, request }) => {
|
|
11
|
-
if (!auth || auth.role
|
|
12
|
-
|
|
13
|
+
if (roles && roles.length > 0 && (!auth || !roles.includes(auth.role))) {
|
|
14
|
+
throw UNAUTHORIZED();
|
|
15
|
+
}
|
|
16
|
+
const itemId = params.itemId;
|
|
17
|
+
const existing = await repository.find(itemId);
|
|
18
|
+
if (!existing) {
|
|
19
|
+
throw NOT_FOUND();
|
|
20
|
+
}
|
|
21
|
+
if (isOwnedBy && !isOwnedBy(existing, auth)) {
|
|
22
|
+
throw FORBIDDEN();
|
|
13
23
|
}
|
|
14
24
|
switch (request.method) {
|
|
15
25
|
case "DELETE": {
|
|
16
|
-
const itemId = params.itemId;
|
|
17
26
|
await repository.delete(itemId);
|
|
18
27
|
return {};
|
|
19
28
|
}
|
package/dist/crud/index.d.mts
CHANGED
|
@@ -1,25 +1,5 @@
|
|
|
1
1
|
export { CrudFormProps, FormColumnValue, FormColumns, FormContext, FormContextProps, useFormContext } from './crud_form_provider.mjs';
|
|
2
|
-
export { CrudHandler, CrudHandlerOptions, crudHandler } from './crud_loader.mjs';
|
|
3
|
-
export { CrudPage, CrudPageOptions, crudPage } from './crud_page.mjs';
|
|
4
|
-
export { generateHandlers } from './generate_handlers.mjs';
|
|
5
|
-
export { generatePages } from './generate_pages.mjs';
|
|
6
|
-
export { generateCrudRoutes } from './generate_routes.mjs';
|
|
7
2
|
export { deserialize, serialize } from './serialize.mjs';
|
|
8
3
|
import 'react/jsx-runtime';
|
|
9
4
|
import 'react';
|
|
10
5
|
import 'react-store-input';
|
|
11
|
-
import 'react-router';
|
|
12
|
-
import '../table/item_loader.mjs';
|
|
13
|
-
import '../table/repository.mjs';
|
|
14
|
-
import 'drizzle-orm';
|
|
15
|
-
import 'drizzle-orm/node-postgres';
|
|
16
|
-
import 'drizzle-orm/pg-core';
|
|
17
|
-
import '../table/load_table.mjs';
|
|
18
|
-
import '../api/create_api_handler.mjs';
|
|
19
|
-
import '../auth/with_auth.mjs';
|
|
20
|
-
import 'dn-react-toolkit/auth';
|
|
21
|
-
import 'dn-react-toolkit/auth/server';
|
|
22
|
-
import '../table/table_form.mjs';
|
|
23
|
-
import '../table/table.mjs';
|
|
24
|
-
import '../table/use_table.mjs';
|
|
25
|
-
import '@react-router/dev/routes';
|
package/dist/crud/index.d.ts
CHANGED
|
@@ -1,25 +1,5 @@
|
|
|
1
1
|
export { CrudFormProps, FormColumnValue, FormColumns, FormContext, FormContextProps, useFormContext } from './crud_form_provider.js';
|
|
2
|
-
export { CrudHandler, CrudHandlerOptions, crudHandler } from './crud_loader.js';
|
|
3
|
-
export { CrudPage, CrudPageOptions, crudPage } from './crud_page.js';
|
|
4
|
-
export { generateHandlers } from './generate_handlers.js';
|
|
5
|
-
export { generatePages } from './generate_pages.js';
|
|
6
|
-
export { generateCrudRoutes } from './generate_routes.js';
|
|
7
2
|
export { deserialize, serialize } from './serialize.js';
|
|
8
3
|
import 'react/jsx-runtime';
|
|
9
4
|
import 'react';
|
|
10
5
|
import 'react-store-input';
|
|
11
|
-
import 'react-router';
|
|
12
|
-
import '../table/item_loader.js';
|
|
13
|
-
import '../table/repository.js';
|
|
14
|
-
import 'drizzle-orm';
|
|
15
|
-
import 'drizzle-orm/node-postgres';
|
|
16
|
-
import 'drizzle-orm/pg-core';
|
|
17
|
-
import '../table/load_table.js';
|
|
18
|
-
import '../api/create_api_handler.js';
|
|
19
|
-
import '../auth/with_auth.js';
|
|
20
|
-
import 'dn-react-toolkit/auth';
|
|
21
|
-
import 'dn-react-toolkit/auth/server';
|
|
22
|
-
import '../table/table_form.js';
|
|
23
|
-
import '../table/table.js';
|
|
24
|
-
import '../table/use_table.js';
|
|
25
|
-
import '@react-router/dev/routes';
|