@tmlmobilidade/go-types-permissions 20260828.1636.54
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/allow-all.d.ts +4 -0
- package/dist/allow-all.js +5 -0
- package/dist/catalog.d.ts +199 -0
- package/dist/catalog.js +349 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/permissions.d.ts +397 -0
- package/dist/permissions.js +47 -0
- package/dist/registry.d.ts +192 -0
- package/dist/registry.js +47 -0
- package/dist/resources-registy.d.ts +16 -0
- package/dist/resources-registy.js +32 -0
- package/dist/scopes/agencies/actions.d.ts +3 -0
- package/dist/scopes/agencies/actions.js +11 -0
- package/dist/scopes/agencies/permission.d.ts +12 -0
- package/dist/scopes/agencies/permission.js +9 -0
- package/dist/scopes/agencies/registry.d.ts +12 -0
- package/dist/scopes/agencies/registry.js +9 -0
- package/dist/scopes/agencies/scope.d.ts +3 -0
- package/dist/scopes/agencies/scope.js +4 -0
- package/dist/scopes/alerts/actions.d.ts +3 -0
- package/dist/scopes/alerts/actions.js +14 -0
- package/dist/scopes/alerts/permission.d.ts +30 -0
- package/dist/scopes/alerts/permission.js +11 -0
- package/dist/scopes/alerts/registry.d.ts +12 -0
- package/dist/scopes/alerts/registry.js +9 -0
- package/dist/scopes/alerts/resources.d.ts +12 -0
- package/dist/scopes/alerts/resources.js +7 -0
- package/dist/scopes/alerts/scope.d.ts +3 -0
- package/dist/scopes/alerts/scope.js +4 -0
- package/dist/scopes/annotations/actions.d.ts +3 -0
- package/dist/scopes/annotations/actions.js +11 -0
- package/dist/scopes/annotations/permission.d.ts +25 -0
- package/dist/scopes/annotations/permission.js +11 -0
- package/dist/scopes/annotations/registry.d.ts +12 -0
- package/dist/scopes/annotations/registry.js +9 -0
- package/dist/scopes/annotations/resources.d.ts +9 -0
- package/dist/scopes/annotations/resources.js +6 -0
- package/dist/scopes/annotations/scope.d.ts +3 -0
- package/dist/scopes/annotations/scope.js +4 -0
- package/dist/scopes/events/actions.d.ts +3 -0
- package/dist/scopes/events/actions.js +11 -0
- package/dist/scopes/events/permission.d.ts +25 -0
- package/dist/scopes/events/permission.js +11 -0
- package/dist/scopes/events/registry.d.ts +12 -0
- package/dist/scopes/events/registry.js +9 -0
- package/dist/scopes/events/resources.d.ts +9 -0
- package/dist/scopes/events/resources.js +6 -0
- package/dist/scopes/events/scope.d.ts +3 -0
- package/dist/scopes/events/scope.js +4 -0
- package/dist/scopes/fares/actions.d.ts +3 -0
- package/dist/scopes/fares/actions.js +11 -0
- package/dist/scopes/fares/permission.d.ts +25 -0
- package/dist/scopes/fares/permission.js +11 -0
- package/dist/scopes/fares/registry.d.ts +12 -0
- package/dist/scopes/fares/registry.js +9 -0
- package/dist/scopes/fares/resources.d.ts +9 -0
- package/dist/scopes/fares/resources.js +6 -0
- package/dist/scopes/fares/scope.d.ts +3 -0
- package/dist/scopes/fares/scope.js +4 -0
- package/dist/scopes/gtfs-validations/actions.d.ts +3 -0
- package/dist/scopes/gtfs-validations/actions.js +11 -0
- package/dist/scopes/gtfs-validations/permission.d.ts +25 -0
- package/dist/scopes/gtfs-validations/permission.js +11 -0
- package/dist/scopes/gtfs-validations/registry.d.ts +12 -0
- package/dist/scopes/gtfs-validations/registry.js +9 -0
- package/dist/scopes/gtfs-validations/resources.d.ts +9 -0
- package/dist/scopes/gtfs-validations/resources.js +6 -0
- package/dist/scopes/gtfs-validations/scope.d.ts +3 -0
- package/dist/scopes/gtfs-validations/scope.js +4 -0
- package/dist/scopes/holidays/actions.d.ts +3 -0
- package/dist/scopes/holidays/actions.js +11 -0
- package/dist/scopes/holidays/permission.d.ts +25 -0
- package/dist/scopes/holidays/permission.js +11 -0
- package/dist/scopes/holidays/registry.d.ts +12 -0
- package/dist/scopes/holidays/registry.js +9 -0
- package/dist/scopes/holidays/resources.d.ts +9 -0
- package/dist/scopes/holidays/resources.js +6 -0
- package/dist/scopes/holidays/scope.d.ts +3 -0
- package/dist/scopes/holidays/scope.js +4 -0
- package/dist/scopes/home/actions.d.ts +3 -0
- package/dist/scopes/home/actions.js +8 -0
- package/dist/scopes/home/permission.d.ts +12 -0
- package/dist/scopes/home/permission.js +9 -0
- package/dist/scopes/home/registry.d.ts +12 -0
- package/dist/scopes/home/registry.js +9 -0
- package/dist/scopes/home/scope.d.ts +3 -0
- package/dist/scopes/home/scope.js +4 -0
- package/dist/scopes/lines/actions.d.ts +3 -0
- package/dist/scopes/lines/actions.js +11 -0
- package/dist/scopes/lines/permission.d.ts +25 -0
- package/dist/scopes/lines/permission.js +11 -0
- package/dist/scopes/lines/registry.d.ts +12 -0
- package/dist/scopes/lines/registry.js +9 -0
- package/dist/scopes/lines/resources.d.ts +9 -0
- package/dist/scopes/lines/resources.js +6 -0
- package/dist/scopes/lines/scope.d.ts +3 -0
- package/dist/scopes/lines/scope.js +4 -0
- package/dist/scopes/organizations/actions.d.ts +3 -0
- package/dist/scopes/organizations/actions.js +11 -0
- package/dist/scopes/organizations/permission.d.ts +12 -0
- package/dist/scopes/organizations/permission.js +9 -0
- package/dist/scopes/organizations/registry.d.ts +12 -0
- package/dist/scopes/organizations/registry.js +9 -0
- package/dist/scopes/organizations/scope.d.ts +3 -0
- package/dist/scopes/organizations/scope.js +4 -0
- package/dist/scopes/performance/actions.d.ts +3 -0
- package/dist/scopes/performance/actions.js +7 -0
- package/dist/scopes/performance/permission.d.ts +12 -0
- package/dist/scopes/performance/permission.js +9 -0
- package/dist/scopes/performance/registry.d.ts +12 -0
- package/dist/scopes/performance/registry.js +9 -0
- package/dist/scopes/performance/scope.d.ts +3 -0
- package/dist/scopes/performance/scope.js +4 -0
- package/dist/scopes/plans/actions.d.ts +3 -0
- package/dist/scopes/plans/actions.js +22 -0
- package/dist/scopes/plans/permission.d.ts +25 -0
- package/dist/scopes/plans/permission.js +11 -0
- package/dist/scopes/plans/registry.d.ts +12 -0
- package/dist/scopes/plans/registry.js +9 -0
- package/dist/scopes/plans/resources.d.ts +9 -0
- package/dist/scopes/plans/resources.js +6 -0
- package/dist/scopes/plans/scope.d.ts +3 -0
- package/dist/scopes/plans/scope.js +4 -0
- package/dist/scopes/rides/actions.d.ts +3 -0
- package/dist/scopes/rides/actions.js +19 -0
- package/dist/scopes/rides/permission.d.ts +25 -0
- package/dist/scopes/rides/permission.js +11 -0
- package/dist/scopes/rides/registry.d.ts +12 -0
- package/dist/scopes/rides/registry.js +9 -0
- package/dist/scopes/rides/resources.d.ts +9 -0
- package/dist/scopes/rides/resources.js +6 -0
- package/dist/scopes/rides/scope.d.ts +3 -0
- package/dist/scopes/rides/scope.js +4 -0
- package/dist/scopes/roles/actions.d.ts +3 -0
- package/dist/scopes/roles/actions.js +11 -0
- package/dist/scopes/roles/permission.d.ts +12 -0
- package/dist/scopes/roles/permission.js +9 -0
- package/dist/scopes/roles/registry.d.ts +12 -0
- package/dist/scopes/roles/registry.js +9 -0
- package/dist/scopes/roles/scope.d.ts +3 -0
- package/dist/scopes/roles/scope.js +4 -0
- package/dist/scopes/sams/actions.d.ts +3 -0
- package/dist/scopes/sams/actions.js +8 -0
- package/dist/scopes/sams/permission.d.ts +25 -0
- package/dist/scopes/sams/permission.js +11 -0
- package/dist/scopes/sams/registry.d.ts +12 -0
- package/dist/scopes/sams/registry.js +9 -0
- package/dist/scopes/sams/resources.d.ts +9 -0
- package/dist/scopes/sams/resources.js +6 -0
- package/dist/scopes/sams/scope.d.ts +3 -0
- package/dist/scopes/sams/scope.js +4 -0
- package/dist/scopes/stops/actions.d.ts +3 -0
- package/dist/scopes/stops/actions.js +14 -0
- package/dist/scopes/stops/permission.d.ts +30 -0
- package/dist/scopes/stops/permission.js +11 -0
- package/dist/scopes/stops/registry.d.ts +12 -0
- package/dist/scopes/stops/registry.js +9 -0
- package/dist/scopes/stops/resources.d.ts +12 -0
- package/dist/scopes/stops/resources.js +7 -0
- package/dist/scopes/stops/scope.d.ts +3 -0
- package/dist/scopes/stops/scope.js +4 -0
- package/dist/scopes/typologies/actions.d.ts +3 -0
- package/dist/scopes/typologies/actions.js +11 -0
- package/dist/scopes/typologies/permission.d.ts +25 -0
- package/dist/scopes/typologies/permission.js +11 -0
- package/dist/scopes/typologies/registry.d.ts +12 -0
- package/dist/scopes/typologies/registry.js +9 -0
- package/dist/scopes/typologies/resources.d.ts +9 -0
- package/dist/scopes/typologies/resources.js +6 -0
- package/dist/scopes/typologies/scope.d.ts +3 -0
- package/dist/scopes/typologies/scope.js +4 -0
- package/dist/scopes/users/actions.d.ts +3 -0
- package/dist/scopes/users/actions.js +11 -0
- package/dist/scopes/users/permission.d.ts +12 -0
- package/dist/scopes/users/permission.js +9 -0
- package/dist/scopes/users/registry.d.ts +12 -0
- package/dist/scopes/users/registry.js +9 -0
- package/dist/scopes/users/scope.d.ts +3 -0
- package/dist/scopes/users/scope.js +4 -0
- package/dist/scopes/vehicles/actions.d.ts +3 -0
- package/dist/scopes/vehicles/actions.js +11 -0
- package/dist/scopes/vehicles/permission.d.ts +25 -0
- package/dist/scopes/vehicles/permission.js +11 -0
- package/dist/scopes/vehicles/registry.d.ts +12 -0
- package/dist/scopes/vehicles/registry.js +9 -0
- package/dist/scopes/vehicles/resources.d.ts +9 -0
- package/dist/scopes/vehicles/resources.js +6 -0
- package/dist/scopes/vehicles/scope.d.ts +3 -0
- package/dist/scopes/vehicles/scope.js +4 -0
- package/dist/scopes/year-periods/actions.d.ts +3 -0
- package/dist/scopes/year-periods/actions.js +11 -0
- package/dist/scopes/year-periods/permission.d.ts +25 -0
- package/dist/scopes/year-periods/permission.js +11 -0
- package/dist/scopes/year-periods/registry.d.ts +12 -0
- package/dist/scopes/year-periods/registry.js +9 -0
- package/dist/scopes/year-periods/resources.d.ts +9 -0
- package/dist/scopes/year-periods/resources.js +6 -0
- package/dist/scopes/year-periods/scope.d.ts +3 -0
- package/dist/scopes/year-periods/scope.js +4 -0
- package/dist/scopes/zones/actions.d.ts +3 -0
- package/dist/scopes/zones/actions.js +11 -0
- package/dist/scopes/zones/permission.d.ts +25 -0
- package/dist/scopes/zones/permission.js +11 -0
- package/dist/scopes/zones/registry.d.ts +12 -0
- package/dist/scopes/zones/registry.js +9 -0
- package/dist/scopes/zones/resources.d.ts +9 -0
- package/dist/scopes/zones/resources.js +6 -0
- package/dist/scopes/zones/scope.d.ts +3 -0
- package/dist/scopes/zones/scope.js +4 -0
- package/dist/utils/has-permission-resource.d.ts +29 -0
- package/dist/utils/has-permission-resource.js +41 -0
- package/dist/utils/has-permission.d.ts +8 -0
- package/dist/utils/has-permission.js +20 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/package.json +48 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const UsersPermissionSchema: z.ZodObject<{
|
|
3
|
+
action: z.ZodEnum<["create", "delete", "read", "lock", "update"]>;
|
|
4
|
+
scope: z.ZodLiteral<"users">;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
action: "create" | "delete" | "read" | "lock" | "update";
|
|
7
|
+
scope: "users";
|
|
8
|
+
}, {
|
|
9
|
+
action: "create" | "delete" | "read" | "lock" | "update";
|
|
10
|
+
scope: "users";
|
|
11
|
+
}>;
|
|
12
|
+
export type UsersPermission = z.infer<typeof UsersPermissionSchema>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { UsersPermissionActionsSchema } from './actions.js';
|
|
4
|
+
import { UsersPermissionScopeSchema } from './scope.js';
|
|
5
|
+
/* * */
|
|
6
|
+
export const UsersPermissionSchema = z.object({
|
|
7
|
+
action: UsersPermissionActionsSchema,
|
|
8
|
+
scope: UsersPermissionScopeSchema,
|
|
9
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const UsersPermissionRegistrySchema: z.ZodObject<{
|
|
3
|
+
actions: z.ZodArray<z.ZodEnum<["create", "delete", "read", "lock", "update"]>, "many">;
|
|
4
|
+
scope: z.ZodLiteral<"users">;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
scope: "users";
|
|
7
|
+
actions: ("create" | "delete" | "read" | "lock" | "update")[];
|
|
8
|
+
}, {
|
|
9
|
+
scope: "users";
|
|
10
|
+
actions: ("create" | "delete" | "read" | "lock" | "update")[];
|
|
11
|
+
}>;
|
|
12
|
+
export type UsersPermissionRegistry = z.infer<typeof UsersPermissionRegistrySchema>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { UsersPermissionActionsSchema } from './actions.js';
|
|
4
|
+
import { UsersPermissionScopeSchema } from './scope.js';
|
|
5
|
+
/* * */
|
|
6
|
+
export const UsersPermissionRegistrySchema = z.object({
|
|
7
|
+
actions: z.array(UsersPermissionActionsSchema),
|
|
8
|
+
scope: UsersPermissionScopeSchema,
|
|
9
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const VehiclesPermissionSchema: z.ZodObject<{
|
|
3
|
+
action: z.ZodEnum<["create", "delete", "read", "lock", "update"]>;
|
|
4
|
+
resources: z.ZodDefault<z.ZodObject<{
|
|
5
|
+
agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
agency_ids: string[];
|
|
8
|
+
}, {
|
|
9
|
+
agency_ids?: string[] | undefined;
|
|
10
|
+
}>>;
|
|
11
|
+
scope: z.ZodLiteral<"vehicles">;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
action: "create" | "delete" | "read" | "lock" | "update";
|
|
14
|
+
scope: "vehicles";
|
|
15
|
+
resources: {
|
|
16
|
+
agency_ids: string[];
|
|
17
|
+
};
|
|
18
|
+
}, {
|
|
19
|
+
action: "create" | "delete" | "read" | "lock" | "update";
|
|
20
|
+
scope: "vehicles";
|
|
21
|
+
resources?: {
|
|
22
|
+
agency_ids?: string[] | undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
export type VehiclesPermission = z.infer<typeof VehiclesPermissionSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { VehiclesPermissionActionsSchema } from './actions.js';
|
|
4
|
+
import { VehiclesPermissionResourcesSchema } from './resources.js';
|
|
5
|
+
import { VehiclesPermissionScopeSchema } from './scope.js';
|
|
6
|
+
/* * */
|
|
7
|
+
export const VehiclesPermissionSchema = z.object({
|
|
8
|
+
action: VehiclesPermissionActionsSchema,
|
|
9
|
+
resources: VehiclesPermissionResourcesSchema.default({}),
|
|
10
|
+
scope: VehiclesPermissionScopeSchema,
|
|
11
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const VehiclesPermissionRegistrySchema: z.ZodObject<{
|
|
3
|
+
actions: z.ZodArray<z.ZodEnum<["create", "delete", "read", "lock", "update"]>, "many">;
|
|
4
|
+
scope: z.ZodLiteral<"vehicles">;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
scope: "vehicles";
|
|
7
|
+
actions: ("create" | "delete" | "read" | "lock" | "update")[];
|
|
8
|
+
}, {
|
|
9
|
+
scope: "vehicles";
|
|
10
|
+
actions: ("create" | "delete" | "read" | "lock" | "update")[];
|
|
11
|
+
}>;
|
|
12
|
+
export type VehiclesPermissionRegistry = z.infer<typeof VehiclesPermissionRegistrySchema>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { VehiclesPermissionActionsSchema } from './actions.js';
|
|
4
|
+
import { VehiclesPermissionScopeSchema } from './scope.js';
|
|
5
|
+
/* * */
|
|
6
|
+
export const VehiclesPermissionRegistrySchema = z.object({
|
|
7
|
+
actions: z.array(VehiclesPermissionActionsSchema),
|
|
8
|
+
scope: VehiclesPermissionScopeSchema,
|
|
9
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const VehiclesPermissionResourcesSchema: z.ZodObject<{
|
|
3
|
+
agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
4
|
+
}, "strip", z.ZodTypeAny, {
|
|
5
|
+
agency_ids: string[];
|
|
6
|
+
}, {
|
|
7
|
+
agency_ids?: string[] | undefined;
|
|
8
|
+
}>;
|
|
9
|
+
export type VehiclesPermissionResources = z.infer<typeof VehiclesPermissionResourcesSchema>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const YearPeriodsPermissionSchema: z.ZodObject<{
|
|
3
|
+
action: z.ZodEnum<["create", "delete", "read", "lock", "update"]>;
|
|
4
|
+
resources: z.ZodDefault<z.ZodObject<{
|
|
5
|
+
agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
agency_ids: string[];
|
|
8
|
+
}, {
|
|
9
|
+
agency_ids?: string[] | undefined;
|
|
10
|
+
}>>;
|
|
11
|
+
scope: z.ZodLiteral<"year_periods">;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
action: "create" | "delete" | "read" | "lock" | "update";
|
|
14
|
+
scope: "year_periods";
|
|
15
|
+
resources: {
|
|
16
|
+
agency_ids: string[];
|
|
17
|
+
};
|
|
18
|
+
}, {
|
|
19
|
+
action: "create" | "delete" | "read" | "lock" | "update";
|
|
20
|
+
scope: "year_periods";
|
|
21
|
+
resources?: {
|
|
22
|
+
agency_ids?: string[] | undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
export type YearPeriodsPermission = z.infer<typeof YearPeriodsPermissionSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { YearPeriodsPermissionActionsSchema } from './actions.js';
|
|
4
|
+
import { YearPeriodsPermissionResourcesSchema } from './resources.js';
|
|
5
|
+
import { YearPeriodsPermissionScopeSchema } from './scope.js';
|
|
6
|
+
/* * */
|
|
7
|
+
export const YearPeriodsPermissionSchema = z.object({
|
|
8
|
+
action: YearPeriodsPermissionActionsSchema,
|
|
9
|
+
resources: YearPeriodsPermissionResourcesSchema.default({}),
|
|
10
|
+
scope: YearPeriodsPermissionScopeSchema,
|
|
11
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const YearPeriodsPermissionRegistrySchema: z.ZodObject<{
|
|
3
|
+
actions: z.ZodArray<z.ZodEnum<["create", "delete", "read", "lock", "update"]>, "many">;
|
|
4
|
+
scope: z.ZodLiteral<"year_periods">;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
scope: "year_periods";
|
|
7
|
+
actions: ("create" | "delete" | "read" | "lock" | "update")[];
|
|
8
|
+
}, {
|
|
9
|
+
scope: "year_periods";
|
|
10
|
+
actions: ("create" | "delete" | "read" | "lock" | "update")[];
|
|
11
|
+
}>;
|
|
12
|
+
export type YearPeriodsPermissionRegistry = z.infer<typeof YearPeriodsPermissionRegistrySchema>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { YearPeriodsPermissionActionsSchema } from './actions.js';
|
|
4
|
+
import { YearPeriodsPermissionScopeSchema } from './scope.js';
|
|
5
|
+
/* * */
|
|
6
|
+
export const YearPeriodsPermissionRegistrySchema = z.object({
|
|
7
|
+
actions: z.array(YearPeriodsPermissionActionsSchema),
|
|
8
|
+
scope: YearPeriodsPermissionScopeSchema,
|
|
9
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const YearPeriodsPermissionResourcesSchema: z.ZodObject<{
|
|
3
|
+
agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
4
|
+
}, "strip", z.ZodTypeAny, {
|
|
5
|
+
agency_ids: string[];
|
|
6
|
+
}, {
|
|
7
|
+
agency_ids?: string[] | undefined;
|
|
8
|
+
}>;
|
|
9
|
+
export type YearPeriodsPermissionResources = z.infer<typeof YearPeriodsPermissionResourcesSchema>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ZonesPermissionSchema: z.ZodObject<{
|
|
3
|
+
action: z.ZodEnum<["create", "delete", "lock", "nav", "update"]>;
|
|
4
|
+
resources: z.ZodDefault<z.ZodObject<{
|
|
5
|
+
agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
agency_ids: string[];
|
|
8
|
+
}, {
|
|
9
|
+
agency_ids?: string[] | undefined;
|
|
10
|
+
}>>;
|
|
11
|
+
scope: z.ZodLiteral<"zones">;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
action: "create" | "delete" | "lock" | "update" | "nav";
|
|
14
|
+
scope: "zones";
|
|
15
|
+
resources: {
|
|
16
|
+
agency_ids: string[];
|
|
17
|
+
};
|
|
18
|
+
}, {
|
|
19
|
+
action: "create" | "delete" | "lock" | "update" | "nav";
|
|
20
|
+
scope: "zones";
|
|
21
|
+
resources?: {
|
|
22
|
+
agency_ids?: string[] | undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
export type ZonesPermission = z.infer<typeof ZonesPermissionSchema>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ZonesPermissionActionsSchema } from './actions.js';
|
|
4
|
+
import { ZonesPermissionResourcesSchema } from './resources.js';
|
|
5
|
+
import { ZonesPermissionScopeSchema } from './scope.js';
|
|
6
|
+
/* * */
|
|
7
|
+
export const ZonesPermissionSchema = z.object({
|
|
8
|
+
action: ZonesPermissionActionsSchema,
|
|
9
|
+
resources: ZonesPermissionResourcesSchema.default({}),
|
|
10
|
+
scope: ZonesPermissionScopeSchema,
|
|
11
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ZonesPermissionRegistrySchema: z.ZodObject<{
|
|
3
|
+
actions: z.ZodArray<z.ZodEnum<["create", "delete", "lock", "nav", "update"]>, "many">;
|
|
4
|
+
scope: z.ZodLiteral<"zones">;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
scope: "zones";
|
|
7
|
+
actions: ("create" | "delete" | "lock" | "update" | "nav")[];
|
|
8
|
+
}, {
|
|
9
|
+
scope: "zones";
|
|
10
|
+
actions: ("create" | "delete" | "lock" | "update" | "nav")[];
|
|
11
|
+
}>;
|
|
12
|
+
export type ZonesPermissionRegistry = z.infer<typeof ZonesPermissionRegistrySchema>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ZonesPermissionActionsSchema } from './actions.js';
|
|
4
|
+
import { ZonesPermissionScopeSchema } from './scope.js';
|
|
5
|
+
/* * */
|
|
6
|
+
export const ZonesPermissionRegistrySchema = z.object({
|
|
7
|
+
actions: z.array(ZonesPermissionActionsSchema),
|
|
8
|
+
scope: ZonesPermissionScopeSchema,
|
|
9
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ZonesPermissionResourcesSchema: z.ZodObject<{
|
|
3
|
+
agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
4
|
+
}, "strip", z.ZodTypeAny, {
|
|
5
|
+
agency_ids: string[];
|
|
6
|
+
}, {
|
|
7
|
+
agency_ids?: string[] | undefined;
|
|
8
|
+
}>;
|
|
9
|
+
export type ZonesPermissionResources = z.infer<typeof ZonesPermissionResourcesSchema>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PermissionsResources } from '../resources-registy.js';
|
|
2
|
+
import { type Permission } from '../permissions.js';
|
|
3
|
+
interface HasPermissionResourceRequirements {
|
|
4
|
+
/**
|
|
5
|
+
* The required permission to check.
|
|
6
|
+
*/
|
|
7
|
+
requiredPermission: Omit<Permission, 'resources'>;
|
|
8
|
+
/**
|
|
9
|
+
* The required value to check.
|
|
10
|
+
*/
|
|
11
|
+
requiredValue: string;
|
|
12
|
+
/**
|
|
13
|
+
* The key of the resource.
|
|
14
|
+
*/
|
|
15
|
+
resourceKey: keyof PermissionsResources;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if a permission exists in a list of permissions, with additional check for a given resource value.
|
|
19
|
+
* If a `value` exists in a `resource` of a User `permissions` object that
|
|
20
|
+
* matches the given `action` and `scope`. For example, if you want to check if
|
|
21
|
+
* a user has access to a specific `agency_id`, you set `value=43` and `resource_key='agency_ids'`.
|
|
22
|
+
* If the provided `permissions` object contains the value `43` inside the `scope='plans'`,
|
|
23
|
+
* `action='create'` and `resource_key='agency_ids'` the function will return true.
|
|
24
|
+
* @param userPermissions The list of permissions (from a user or request).
|
|
25
|
+
* @param requirements The requirements to check for.
|
|
26
|
+
* @returns True if the permission is found, false otherwise.
|
|
27
|
+
*/
|
|
28
|
+
export declare function hasPermissionResource(userPermissions: Permission[], { requiredPermission, requiredValue, resourceKey }: HasPermissionResourceRequirements): boolean;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { AllowAllFlagValue } from '../allow-all.js';
|
|
3
|
+
/**
|
|
4
|
+
* Check if a permission exists in a list of permissions, with additional check for a given resource value.
|
|
5
|
+
* If a `value` exists in a `resource` of a User `permissions` object that
|
|
6
|
+
* matches the given `action` and `scope`. For example, if you want to check if
|
|
7
|
+
* a user has access to a specific `agency_id`, you set `value=43` and `resource_key='agency_ids'`.
|
|
8
|
+
* If the provided `permissions` object contains the value `43` inside the `scope='plans'`,
|
|
9
|
+
* `action='create'` and `resource_key='agency_ids'` the function will return true.
|
|
10
|
+
* @param userPermissions The list of permissions (from a user or request).
|
|
11
|
+
* @param requirements The requirements to check for.
|
|
12
|
+
* @returns True if the permission is found, false otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export function hasPermissionResource(userPermissions, { requiredPermission, requiredValue, resourceKey }) {
|
|
15
|
+
//
|
|
16
|
+
//
|
|
17
|
+
// Return false if no permissions
|
|
18
|
+
if (!userPermissions?.length)
|
|
19
|
+
return false;
|
|
20
|
+
if (!resourceKey || !requiredValue)
|
|
21
|
+
return false;
|
|
22
|
+
//
|
|
23
|
+
// Find the permission with the given action and scope
|
|
24
|
+
const foundUserPermission = userPermissions.find(p => p.action === requiredPermission.action && p.scope === requiredPermission.scope);
|
|
25
|
+
if (!foundUserPermission)
|
|
26
|
+
return false;
|
|
27
|
+
//
|
|
28
|
+
// Exit if the found user permission does not have the resources property
|
|
29
|
+
// or if the resources property is empty
|
|
30
|
+
if (!('resources' in foundUserPermission))
|
|
31
|
+
return false;
|
|
32
|
+
const resourceValues = foundUserPermission.resources[resourceKey];
|
|
33
|
+
if (!resourceValues?.length)
|
|
34
|
+
return false;
|
|
35
|
+
//
|
|
36
|
+
// Check if the found user permission can access all values
|
|
37
|
+
// or has the required value
|
|
38
|
+
if (resourceValues.includes(AllowAllFlagValue))
|
|
39
|
+
return true;
|
|
40
|
+
return resourceValues.includes(requiredValue);
|
|
41
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Permission } from '../permissions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if a list of permission entries has the requested scope/action pair.
|
|
4
|
+
* @param userPermissions The list of permission entries to check against.
|
|
5
|
+
* @param requiredPermission The required permission to check.
|
|
6
|
+
* @returns True if the permission is found, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare function hasPermission(userPermissions: Permission[], requiredPermission: Omit<Permission, 'resources'>): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
/**
|
|
3
|
+
* Check if a list of permission entries has the requested scope/action pair.
|
|
4
|
+
* @param userPermissions The list of permission entries to check against.
|
|
5
|
+
* @param requiredPermission The required permission to check.
|
|
6
|
+
* @returns True if the permission is found, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export function hasPermission(userPermissions, requiredPermission) {
|
|
9
|
+
//
|
|
10
|
+
//
|
|
11
|
+
// Return false if no permissions
|
|
12
|
+
if (!userPermissions)
|
|
13
|
+
return false;
|
|
14
|
+
//
|
|
15
|
+
// Find the permission with the given action and scope
|
|
16
|
+
const foundPermission = userPermissions.find(p => p.action === requiredPermission.action && p.scope === requiredPermission.scope);
|
|
17
|
+
if (!foundPermission)
|
|
18
|
+
return false;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tmlmobilidade/go-types-permissions",
|
|
3
|
+
"version": "20260828.1636.54",
|
|
4
|
+
"author": {
|
|
5
|
+
"email": "iso@tmlmobilidade.pt",
|
|
6
|
+
"name": "TML-ISO"
|
|
7
|
+
},
|
|
8
|
+
"license": "AGPL-3.0-or-later",
|
|
9
|
+
"homepage": "https://go.tmlmobilidade.pt",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/tmlmobilidade/go/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/tmlmobilidade/go.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"public transit",
|
|
19
|
+
"tml",
|
|
20
|
+
"transportes metropolitanos de lisboa",
|
|
21
|
+
"go"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc && resolve-tspaths",
|
|
34
|
+
"lint": "eslint ./src/ && tsc --noEmit",
|
|
35
|
+
"lint:fix": "eslint ./src/ --fix",
|
|
36
|
+
"watch": "tsc-watch --onSuccess 'resolve-tspaths'"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"zod": "3.25.76"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@tmlmobilidade/go-utils-tsconfig": "*",
|
|
43
|
+
"@types/node": "26.1.2",
|
|
44
|
+
"resolve-tspaths": "0.8.23",
|
|
45
|
+
"tsc-watch": "7.2.1",
|
|
46
|
+
"typescript": "6.0.3"
|
|
47
|
+
}
|
|
48
|
+
}
|