@m5kdev/commons 0.23.0 → 0.25.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.
@@ -0,0 +1,85 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let zod = require("zod");
3
+ const DEFAULT_AUTH_ROLES = {
4
+ user: {
5
+ roles: ["user", "admin"],
6
+ managerRoles: ["admin"],
7
+ assignableRoles: ["user", "admin"],
8
+ defaultRole: "user"
9
+ },
10
+ organization: {
11
+ roles: [
12
+ "member",
13
+ "admin",
14
+ "owner"
15
+ ],
16
+ managerRoles: ["admin", "owner"],
17
+ assignableRoles: [
18
+ "member",
19
+ "admin",
20
+ "owner"
21
+ ],
22
+ defaultRole: "member"
23
+ },
24
+ team: {
25
+ roles: ["owner"],
26
+ managerRoles: ["owner"],
27
+ assignableRoles: ["owner"],
28
+ defaultRole: "owner"
29
+ }
30
+ };
31
+ function pickSubset(values, allowed, fallback) {
32
+ const allowedSet = new Set(allowed);
33
+ const picked = values.filter((value) => allowedSet.has(value));
34
+ if (picked.length > 0) return picked;
35
+ const fallbackPicked = fallback.filter((value) => allowedSet.has(value));
36
+ if (fallbackPicked.length > 0) return fallbackPicked;
37
+ return allowed.length > 0 ? [allowed[0]] : [];
38
+ }
39
+ function normalizeRoleScopeConfig(scope, defaults) {
40
+ const roles = scope.roles.length > 0 ? scope.roles : defaults.roles;
41
+ const roleSet = new Set(roles);
42
+ const defaultRole = scope.defaultRole && roleSet.has(scope.defaultRole) ? scope.defaultRole : defaults.defaultRole && roleSet.has(defaults.defaultRole) ? defaults.defaultRole : roles[0];
43
+ return {
44
+ roles,
45
+ managerRoles: pickSubset(scope.managerRoles ?? defaults.managerRoles, roles, defaults.managerRoles),
46
+ assignableRoles: pickSubset(scope.assignableRoles ?? roles, roles, roles),
47
+ defaultRole
48
+ };
49
+ }
50
+ function normalizeAuthRolesConfig(config) {
51
+ if (!config) return DEFAULT_AUTH_ROLES;
52
+ return {
53
+ user: normalizeRoleScopeConfig(config.user, DEFAULT_AUTH_ROLES.user),
54
+ organization: normalizeRoleScopeConfig(config.organization, DEFAULT_AUTH_ROLES.organization),
55
+ team: normalizeRoleScopeConfig(config.team, DEFAULT_AUTH_ROLES.team)
56
+ };
57
+ }
58
+ function defineAuthRoles(config) {
59
+ return normalizeAuthRolesConfig(config);
60
+ }
61
+ function getRoleKeys(config, scope) {
62
+ return config[scope].roles;
63
+ }
64
+ function isAllowedRole(config, scope, role) {
65
+ return getRoleKeys(config, scope).includes(role);
66
+ }
67
+ function createRoleValueSchema(scope) {
68
+ const allowed = [...scope.roles];
69
+ if (allowed.length === 0) return zod.z.string();
70
+ return zod.z.enum(allowed);
71
+ }
72
+ function getAppRoleTranslationKey(scope, role) {
73
+ return `${scope}.role.${role}`;
74
+ }
75
+ //#endregion
76
+ exports.DEFAULT_AUTH_ROLES = DEFAULT_AUTH_ROLES;
77
+ exports.createRoleValueSchema = createRoleValueSchema;
78
+ exports.defineAuthRoles = defineAuthRoles;
79
+ exports.getAppRoleTranslationKey = getAppRoleTranslationKey;
80
+ exports.getRoleKeys = getRoleKeys;
81
+ exports.isAllowedRole = isAllowedRole;
82
+ exports.normalizeAuthRolesConfig = normalizeAuthRolesConfig;
83
+ exports.normalizeRoleScopeConfig = normalizeRoleScopeConfig;
84
+
85
+ //# sourceMappingURL=auth.roles.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.roles.cjs","names":["z"],"sources":["../../../../src/modules/auth/auth.roles.ts"],"sourcesContent":["import { z } from \"zod\";\r\n\r\nexport type AuthRoleScope = \"user\" | \"organization\" | \"team\";\r\n\r\nexport interface AuthRoleScopeConfig {\r\n roles: readonly string[];\r\n managerRoles?: readonly string[];\r\n assignableRoles?: readonly string[];\r\n defaultRole?: string;\r\n}\r\n\r\nexport interface AuthRolesConfig {\r\n user: AuthRoleScopeConfig;\r\n organization: AuthRoleScopeConfig;\r\n team: AuthRoleScopeConfig;\r\n}\r\n\r\nexport interface NormalizedAuthRoleScopeConfig {\r\n roles: readonly string[];\r\n managerRoles: readonly string[];\r\n assignableRoles: readonly string[];\r\n defaultRole: string;\r\n}\r\n\r\nexport interface NormalizedAuthRolesConfig {\r\n user: NormalizedAuthRoleScopeConfig;\r\n organization: NormalizedAuthRoleScopeConfig;\r\n team: NormalizedAuthRoleScopeConfig;\r\n}\r\n\r\nconst DEFAULT_USER_SCOPE: NormalizedAuthRoleScopeConfig = {\r\n roles: [\"user\", \"admin\"],\r\n managerRoles: [\"admin\"],\r\n assignableRoles: [\"user\", \"admin\"],\r\n defaultRole: \"user\",\r\n};\r\n\r\nconst DEFAULT_ORGANIZATION_SCOPE: NormalizedAuthRoleScopeConfig = {\r\n roles: [\"member\", \"admin\", \"owner\"],\r\n managerRoles: [\"admin\", \"owner\"],\r\n assignableRoles: [\"member\", \"admin\", \"owner\"],\r\n defaultRole: \"member\",\r\n};\r\n\r\nconst DEFAULT_TEAM_SCOPE: NormalizedAuthRoleScopeConfig = {\r\n roles: [\"owner\"],\r\n managerRoles: [\"owner\"],\r\n assignableRoles: [\"owner\"],\r\n defaultRole: \"owner\",\r\n};\r\n\r\nexport const DEFAULT_AUTH_ROLES: NormalizedAuthRolesConfig = {\r\n user: DEFAULT_USER_SCOPE,\r\n organization: DEFAULT_ORGANIZATION_SCOPE,\r\n team: DEFAULT_TEAM_SCOPE,\r\n};\r\n\r\nfunction pickSubset(\r\n values: readonly string[],\r\n allowed: readonly string[],\r\n fallback: readonly string[]\r\n): readonly string[] {\r\n const allowedSet = new Set(allowed);\r\n const picked = values.filter((value) => allowedSet.has(value));\r\n if (picked.length > 0) {\r\n return picked;\r\n }\r\n\r\n const fallbackPicked = fallback.filter((value) => allowedSet.has(value));\r\n if (fallbackPicked.length > 0) {\r\n return fallbackPicked;\r\n }\r\n\r\n return allowed.length > 0 ? [allowed[0]] : [];\r\n}\r\n\r\nexport function normalizeRoleScopeConfig(\r\n scope: AuthRoleScopeConfig,\r\n defaults: NormalizedAuthRoleScopeConfig\r\n): NormalizedAuthRoleScopeConfig {\r\n const roles = scope.roles.length > 0 ? scope.roles : defaults.roles;\r\n const roleSet = new Set(roles);\r\n\r\n const defaultRole =\r\n scope.defaultRole && roleSet.has(scope.defaultRole)\r\n ? scope.defaultRole\r\n : defaults.defaultRole && roleSet.has(defaults.defaultRole)\r\n ? defaults.defaultRole\r\n : roles[0];\r\n\r\n const managerRoles = pickSubset(\r\n scope.managerRoles ?? defaults.managerRoles,\r\n roles,\r\n defaults.managerRoles\r\n );\r\n\r\n const assignableRoles = pickSubset(\r\n scope.assignableRoles ?? roles,\r\n roles,\r\n roles\r\n );\r\n\r\n return {\r\n roles,\r\n managerRoles,\r\n assignableRoles,\r\n defaultRole,\r\n };\r\n}\r\n\r\nexport function normalizeAuthRolesConfig(\r\n config?: AuthRolesConfig | null\r\n): NormalizedAuthRolesConfig {\r\n if (!config) {\r\n return DEFAULT_AUTH_ROLES;\r\n }\r\n\r\n return {\r\n user: normalizeRoleScopeConfig(config.user, DEFAULT_AUTH_ROLES.user),\r\n organization: normalizeRoleScopeConfig(config.organization, DEFAULT_AUTH_ROLES.organization),\r\n team: normalizeRoleScopeConfig(config.team, DEFAULT_AUTH_ROLES.team),\r\n };\r\n}\r\n\r\nexport function defineAuthRoles(config: AuthRolesConfig): NormalizedAuthRolesConfig {\r\n return normalizeAuthRolesConfig(config);\r\n}\r\n\r\nexport function getRoleKeys(\r\n config: NormalizedAuthRolesConfig,\r\n scope: AuthRoleScope\r\n): readonly string[] {\r\n return config[scope].roles;\r\n}\r\n\r\nexport function isAllowedRole(\r\n config: NormalizedAuthRolesConfig,\r\n scope: AuthRoleScope,\r\n role: string\r\n): boolean {\r\n return getRoleKeys(config, scope).includes(role);\r\n}\r\n\r\nexport function createRoleValueSchema(scope: NormalizedAuthRoleScopeConfig) {\r\n const allowed = [...scope.roles];\r\n if (allowed.length === 0) {\r\n return z.string();\r\n }\r\n return z.enum(allowed as [string, ...string[]]);\r\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C;EACD;;AAGH,SAAgB,yBACd,QAC2B;AAC3B,KAAI,CAAC,OACH,QAAO;AAGT,QAAO;EACL,MAAM,yBAAyB,OAAO,MAAM,mBAAmB,KAAK;EACpE,cAAc,yBAAyB,OAAO,cAAc,mBAAmB,aAAa;EAC5F,MAAM,yBAAyB,OAAO,MAAM,mBAAmB,KAAK;EACrE;;AAGH,SAAgB,gBAAgB,QAAoD;AAClF,QAAO,yBAAyB,OAAO;;AAGzC,SAAgB,YACd,QACA,OACmB;AACnB,QAAO,OAAO,OAAO;;AAGvB,SAAgB,cACd,QACA,OACA,MACS;AACT,QAAO,YAAY,QAAQ,MAAM,CAAC,SAAS,KAAK;;AAGlD,SAAgB,sBAAsB,OAAsC;CAC1E,MAAM,UAAU,CAAC,GAAG,MAAM,MAAM;AAChC,KAAI,QAAQ,WAAW,EACrB,QAAOA,IAAAA,EAAE,QAAQ;AAEnB,QAAOA,IAAAA,EAAE,KAAK,QAAiC;;AAGjD,SAAgB,yBAAyB,OAAsB,MAAsB;AACnF,QAAO,GAAG,MAAM,QAAQ"}
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/modules/auth/auth.roles.d.ts
4
+ type AuthRoleScope = "user" | "organization" | "team";
5
+ interface AuthRoleScopeConfig {
6
+ roles: readonly string[];
7
+ managerRoles?: readonly string[];
8
+ assignableRoles?: readonly string[];
9
+ defaultRole?: string;
10
+ }
11
+ interface AuthRolesConfig {
12
+ user: AuthRoleScopeConfig;
13
+ organization: AuthRoleScopeConfig;
14
+ team: AuthRoleScopeConfig;
15
+ }
16
+ interface NormalizedAuthRoleScopeConfig {
17
+ roles: readonly string[];
18
+ managerRoles: readonly string[];
19
+ assignableRoles: readonly string[];
20
+ defaultRole: string;
21
+ }
22
+ interface NormalizedAuthRolesConfig {
23
+ user: NormalizedAuthRoleScopeConfig;
24
+ organization: NormalizedAuthRoleScopeConfig;
25
+ team: NormalizedAuthRoleScopeConfig;
26
+ }
27
+ declare const DEFAULT_AUTH_ROLES: NormalizedAuthRolesConfig;
28
+ declare function normalizeRoleScopeConfig(scope: AuthRoleScopeConfig, defaults: NormalizedAuthRoleScopeConfig): NormalizedAuthRoleScopeConfig;
29
+ declare function normalizeAuthRolesConfig(config?: AuthRolesConfig | null): NormalizedAuthRolesConfig;
30
+ declare function defineAuthRoles(config: AuthRolesConfig): NormalizedAuthRolesConfig;
31
+ declare function getRoleKeys(config: NormalizedAuthRolesConfig, scope: AuthRoleScope): readonly string[];
32
+ declare function isAllowedRole(config: NormalizedAuthRolesConfig, scope: AuthRoleScope, role: string): boolean;
33
+ declare function createRoleValueSchema(scope: NormalizedAuthRoleScopeConfig): z.ZodString | z.ZodEnum<{
34
+ [x: string]: string;
35
+ }>;
36
+ declare function getAppRoleTranslationKey(scope: AuthRoleScope, role: string): string;
37
+ //#endregion
38
+ export { AuthRoleScope, AuthRoleScopeConfig, AuthRolesConfig, DEFAULT_AUTH_ROLES, NormalizedAuthRoleScopeConfig, NormalizedAuthRolesConfig, createRoleValueSchema, defineAuthRoles, getAppRoleTranslationKey, getRoleKeys, isAllowedRole, normalizeAuthRolesConfig, normalizeRoleScopeConfig };
39
+ //# sourceMappingURL=auth.roles.d.cts.map
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/modules/auth/auth.roles.d.ts
4
+ type AuthRoleScope = "user" | "organization" | "team";
5
+ interface AuthRoleScopeConfig {
6
+ roles: readonly string[];
7
+ managerRoles?: readonly string[];
8
+ assignableRoles?: readonly string[];
9
+ defaultRole?: string;
10
+ }
11
+ interface AuthRolesConfig {
12
+ user: AuthRoleScopeConfig;
13
+ organization: AuthRoleScopeConfig;
14
+ team: AuthRoleScopeConfig;
15
+ }
16
+ interface NormalizedAuthRoleScopeConfig {
17
+ roles: readonly string[];
18
+ managerRoles: readonly string[];
19
+ assignableRoles: readonly string[];
20
+ defaultRole: string;
21
+ }
22
+ interface NormalizedAuthRolesConfig {
23
+ user: NormalizedAuthRoleScopeConfig;
24
+ organization: NormalizedAuthRoleScopeConfig;
25
+ team: NormalizedAuthRoleScopeConfig;
26
+ }
27
+ declare const DEFAULT_AUTH_ROLES: NormalizedAuthRolesConfig;
28
+ declare function normalizeRoleScopeConfig(scope: AuthRoleScopeConfig, defaults: NormalizedAuthRoleScopeConfig): NormalizedAuthRoleScopeConfig;
29
+ declare function normalizeAuthRolesConfig(config?: AuthRolesConfig | null): NormalizedAuthRolesConfig;
30
+ declare function defineAuthRoles(config: AuthRolesConfig): NormalizedAuthRolesConfig;
31
+ declare function getRoleKeys(config: NormalizedAuthRolesConfig, scope: AuthRoleScope): readonly string[];
32
+ declare function isAllowedRole(config: NormalizedAuthRolesConfig, scope: AuthRoleScope, role: string): boolean;
33
+ declare function createRoleValueSchema(scope: NormalizedAuthRoleScopeConfig): z.ZodString | z.ZodEnum<{
34
+ [x: string]: string;
35
+ }>;
36
+ declare function getAppRoleTranslationKey(scope: AuthRoleScope, role: string): string;
37
+ //#endregion
38
+ export { AuthRoleScope, AuthRoleScopeConfig, AuthRolesConfig, DEFAULT_AUTH_ROLES, NormalizedAuthRoleScopeConfig, NormalizedAuthRolesConfig, createRoleValueSchema, defineAuthRoles, getAppRoleTranslationKey, getRoleKeys, isAllowedRole, normalizeAuthRolesConfig, normalizeRoleScopeConfig };
39
+ //# sourceMappingURL=auth.roles.d.mts.map
@@ -0,0 +1,77 @@
1
+ import { z } from "zod";
2
+ const DEFAULT_AUTH_ROLES = {
3
+ user: {
4
+ roles: ["user", "admin"],
5
+ managerRoles: ["admin"],
6
+ assignableRoles: ["user", "admin"],
7
+ defaultRole: "user"
8
+ },
9
+ organization: {
10
+ roles: [
11
+ "member",
12
+ "admin",
13
+ "owner"
14
+ ],
15
+ managerRoles: ["admin", "owner"],
16
+ assignableRoles: [
17
+ "member",
18
+ "admin",
19
+ "owner"
20
+ ],
21
+ defaultRole: "member"
22
+ },
23
+ team: {
24
+ roles: ["owner"],
25
+ managerRoles: ["owner"],
26
+ assignableRoles: ["owner"],
27
+ defaultRole: "owner"
28
+ }
29
+ };
30
+ function pickSubset(values, allowed, fallback) {
31
+ const allowedSet = new Set(allowed);
32
+ const picked = values.filter((value) => allowedSet.has(value));
33
+ if (picked.length > 0) return picked;
34
+ const fallbackPicked = fallback.filter((value) => allowedSet.has(value));
35
+ if (fallbackPicked.length > 0) return fallbackPicked;
36
+ return allowed.length > 0 ? [allowed[0]] : [];
37
+ }
38
+ function normalizeRoleScopeConfig(scope, defaults) {
39
+ const roles = scope.roles.length > 0 ? scope.roles : defaults.roles;
40
+ const roleSet = new Set(roles);
41
+ const defaultRole = scope.defaultRole && roleSet.has(scope.defaultRole) ? scope.defaultRole : defaults.defaultRole && roleSet.has(defaults.defaultRole) ? defaults.defaultRole : roles[0];
42
+ return {
43
+ roles,
44
+ managerRoles: pickSubset(scope.managerRoles ?? defaults.managerRoles, roles, defaults.managerRoles),
45
+ assignableRoles: pickSubset(scope.assignableRoles ?? roles, roles, roles),
46
+ defaultRole
47
+ };
48
+ }
49
+ function normalizeAuthRolesConfig(config) {
50
+ if (!config) return DEFAULT_AUTH_ROLES;
51
+ return {
52
+ user: normalizeRoleScopeConfig(config.user, DEFAULT_AUTH_ROLES.user),
53
+ organization: normalizeRoleScopeConfig(config.organization, DEFAULT_AUTH_ROLES.organization),
54
+ team: normalizeRoleScopeConfig(config.team, DEFAULT_AUTH_ROLES.team)
55
+ };
56
+ }
57
+ function defineAuthRoles(config) {
58
+ return normalizeAuthRolesConfig(config);
59
+ }
60
+ function getRoleKeys(config, scope) {
61
+ return config[scope].roles;
62
+ }
63
+ function isAllowedRole(config, scope, role) {
64
+ return getRoleKeys(config, scope).includes(role);
65
+ }
66
+ function createRoleValueSchema(scope) {
67
+ const allowed = [...scope.roles];
68
+ if (allowed.length === 0) return z.string();
69
+ return z.enum(allowed);
70
+ }
71
+ function getAppRoleTranslationKey(scope, role) {
72
+ return `${scope}.role.${role}`;
73
+ }
74
+ //#endregion
75
+ export { DEFAULT_AUTH_ROLES, createRoleValueSchema, defineAuthRoles, getAppRoleTranslationKey, getRoleKeys, isAllowedRole, normalizeAuthRolesConfig, normalizeRoleScopeConfig };
76
+
77
+ //# sourceMappingURL=auth.roles.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.roles.mjs","names":[],"sources":["../../../../src/modules/auth/auth.roles.ts"],"sourcesContent":["import { z } from \"zod\";\r\n\r\nexport type AuthRoleScope = \"user\" | \"organization\" | \"team\";\r\n\r\nexport interface AuthRoleScopeConfig {\r\n roles: readonly string[];\r\n managerRoles?: readonly string[];\r\n assignableRoles?: readonly string[];\r\n defaultRole?: string;\r\n}\r\n\r\nexport interface AuthRolesConfig {\r\n user: AuthRoleScopeConfig;\r\n organization: AuthRoleScopeConfig;\r\n team: AuthRoleScopeConfig;\r\n}\r\n\r\nexport interface NormalizedAuthRoleScopeConfig {\r\n roles: readonly string[];\r\n managerRoles: readonly string[];\r\n assignableRoles: readonly string[];\r\n defaultRole: string;\r\n}\r\n\r\nexport interface NormalizedAuthRolesConfig {\r\n user: NormalizedAuthRoleScopeConfig;\r\n organization: NormalizedAuthRoleScopeConfig;\r\n team: NormalizedAuthRoleScopeConfig;\r\n}\r\n\r\nconst DEFAULT_USER_SCOPE: NormalizedAuthRoleScopeConfig = {\r\n roles: [\"user\", \"admin\"],\r\n managerRoles: [\"admin\"],\r\n assignableRoles: [\"user\", \"admin\"],\r\n defaultRole: \"user\",\r\n};\r\n\r\nconst DEFAULT_ORGANIZATION_SCOPE: NormalizedAuthRoleScopeConfig = {\r\n roles: [\"member\", \"admin\", \"owner\"],\r\n managerRoles: [\"admin\", \"owner\"],\r\n assignableRoles: [\"member\", \"admin\", \"owner\"],\r\n defaultRole: \"member\",\r\n};\r\n\r\nconst DEFAULT_TEAM_SCOPE: NormalizedAuthRoleScopeConfig = {\r\n roles: [\"owner\"],\r\n managerRoles: [\"owner\"],\r\n assignableRoles: [\"owner\"],\r\n defaultRole: \"owner\",\r\n};\r\n\r\nexport const DEFAULT_AUTH_ROLES: NormalizedAuthRolesConfig = {\r\n user: DEFAULT_USER_SCOPE,\r\n organization: DEFAULT_ORGANIZATION_SCOPE,\r\n team: DEFAULT_TEAM_SCOPE,\r\n};\r\n\r\nfunction pickSubset(\r\n values: readonly string[],\r\n allowed: readonly string[],\r\n fallback: readonly string[]\r\n): readonly string[] {\r\n const allowedSet = new Set(allowed);\r\n const picked = values.filter((value) => allowedSet.has(value));\r\n if (picked.length > 0) {\r\n return picked;\r\n }\r\n\r\n const fallbackPicked = fallback.filter((value) => allowedSet.has(value));\r\n if (fallbackPicked.length > 0) {\r\n return fallbackPicked;\r\n }\r\n\r\n return allowed.length > 0 ? [allowed[0]] : [];\r\n}\r\n\r\nexport function normalizeRoleScopeConfig(\r\n scope: AuthRoleScopeConfig,\r\n defaults: NormalizedAuthRoleScopeConfig\r\n): NormalizedAuthRoleScopeConfig {\r\n const roles = scope.roles.length > 0 ? scope.roles : defaults.roles;\r\n const roleSet = new Set(roles);\r\n\r\n const defaultRole =\r\n scope.defaultRole && roleSet.has(scope.defaultRole)\r\n ? scope.defaultRole\r\n : defaults.defaultRole && roleSet.has(defaults.defaultRole)\r\n ? defaults.defaultRole\r\n : roles[0];\r\n\r\n const managerRoles = pickSubset(\r\n scope.managerRoles ?? defaults.managerRoles,\r\n roles,\r\n defaults.managerRoles\r\n );\r\n\r\n const assignableRoles = pickSubset(\r\n scope.assignableRoles ?? roles,\r\n roles,\r\n roles\r\n );\r\n\r\n return {\r\n roles,\r\n managerRoles,\r\n assignableRoles,\r\n defaultRole,\r\n };\r\n}\r\n\r\nexport function normalizeAuthRolesConfig(\r\n config?: AuthRolesConfig | null\r\n): NormalizedAuthRolesConfig {\r\n if (!config) {\r\n return DEFAULT_AUTH_ROLES;\r\n }\r\n\r\n return {\r\n user: normalizeRoleScopeConfig(config.user, DEFAULT_AUTH_ROLES.user),\r\n organization: normalizeRoleScopeConfig(config.organization, DEFAULT_AUTH_ROLES.organization),\r\n team: normalizeRoleScopeConfig(config.team, DEFAULT_AUTH_ROLES.team),\r\n };\r\n}\r\n\r\nexport function defineAuthRoles(config: AuthRolesConfig): NormalizedAuthRolesConfig {\r\n return normalizeAuthRolesConfig(config);\r\n}\r\n\r\nexport function getRoleKeys(\r\n config: NormalizedAuthRolesConfig,\r\n scope: AuthRoleScope\r\n): readonly string[] {\r\n return config[scope].roles;\r\n}\r\n\r\nexport function isAllowedRole(\r\n config: NormalizedAuthRolesConfig,\r\n scope: AuthRoleScope,\r\n role: string\r\n): boolean {\r\n return getRoleKeys(config, scope).includes(role);\r\n}\r\n\r\nexport function createRoleValueSchema(scope: NormalizedAuthRoleScopeConfig) {\r\n const allowed = [...scope.roles];\r\n if (allowed.length === 0) {\r\n return z.string();\r\n }\r\n return z.enum(allowed as [string, ...string[]]);\r\n}\r\n\r\nexport function getAppRoleTranslationKey(scope: AuthRoleScope, role: string): string {\r\n return `${scope}.role.${role}`;\r\n}\r\n"],"mappings":";AAmDA,MAAa,qBAAgD;CAC3D,MAtBwD;EACxD,OAAO,CAAC,QAAQ,QAAQ;EACxB,cAAc,CAAC,QAAQ;EACvB,iBAAiB,CAAC,QAAQ,QAAQ;EAClC,aAAa;EACd;CAkBC,cAhBgE;EAChE,OAAO;GAAC;GAAU;GAAS;GAAQ;EACnC,cAAc,CAAC,SAAS,QAAQ;EAChC,iBAAiB;GAAC;GAAU;GAAS;GAAQ;EAC7C,aAAa;EACd;CAYC,MAVwD;EACxD,OAAO,CAAC,QAAQ;EAChB,cAAc,CAAC,QAAQ;EACvB,iBAAiB,CAAC,QAAQ;EAC1B,aAAa;EACd;CAMA;AAED,SAAS,WACP,QACA,SACA,UACmB;CACnB,MAAM,aAAa,IAAI,IAAI,QAAQ;CACnC,MAAM,SAAS,OAAO,QAAQ,UAAU,WAAW,IAAI,MAAM,CAAC;AAC9D,KAAI,OAAO,SAAS,EAClB,QAAO;CAGT,MAAM,iBAAiB,SAAS,QAAQ,UAAU,WAAW,IAAI,MAAM,CAAC;AACxE,KA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endStatusSchema: z.ZodEnum<{
15
- failed: "failed";
16
15
  pending: "pending";
17
16
  sent: "sent";
17
+ failed: "failed";
18
18
  }>;
19
19
  /** Web Push `PushSubscriptionJSON` subset we persist and accept from clients. */
20
20
  declare const pushSubscriptionJsonSchema: z.ZodObject<{
@@ -100,9 +100,9 @@ declare const notificationSendLogSelectSchema: z.ZodObject<{
100
100
  body: z.ZodString;
101
101
  data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
102
102
  status: z.ZodEnum<{
103
- failed: "failed";
104
103
  pending: "pending";
105
104
  sent: "sent";
105
+ failed: "failed";
106
106
  }>;
107
107
  error: z.ZodNullable<z.ZodString>;
108
108
  jobId: z.ZodNullable<z.ZodString>;
@@ -127,9 +127,9 @@ declare const notificationListSendLogsOutputSchema: z.ZodArray<z.ZodObject<{
127
127
  body: z.ZodString;
128
128
  data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
129
129
  status: z.ZodEnum<{
130
- failed: "failed";
131
130
  pending: "pending";
132
131
  sent: "sent";
132
+ failed: "failed";
133
133
  }>;
134
134
  error: z.ZodNullable<z.ZodString>;
135
135
  jobId: z.ZodNullable<z.ZodString>;
@@ -12,9 +12,9 @@ declare const notificationProviderSchema: z.ZodEnum<{
12
12
  fcm: "fcm";
13
13
  }>;
14
14
  declare const notificationSendStatusSchema: z.ZodEnum<{
15
- failed: "failed";
16
15
  pending: "pending";
17
16
  sent: "sent";
17
+ failed: "failed";
18
18
  }>;
19
19
  /** Web Push `PushSubscriptionJSON` subset we persist and accept from clients. */
20
20
  declare const pushSubscriptionJsonSchema: z.ZodObject<{
@@ -100,9 +100,9 @@ declare const notificationSendLogSelectSchema: z.ZodObject<{
100
100
  body: z.ZodString;
101
101
  data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
102
102
  status: z.ZodEnum<{
103
- failed: "failed";
104
103
  pending: "pending";
105
104
  sent: "sent";
105
+ failed: "failed";
106
106
  }>;
107
107
  error: z.ZodNullable<z.ZodString>;
108
108
  jobId: z.ZodNullable<z.ZodString>;
@@ -127,9 +127,9 @@ declare const notificationListSendLogsOutputSchema: z.ZodArray<z.ZodObject<{
127
127
  body: z.ZodString;
128
128
  data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
129
129
  status: z.ZodEnum<{
130
- failed: "failed";
131
130
  pending: "pending";
132
131
  sent: "sent";
132
+ failed: "failed";
133
133
  }>;
134
134
  error: z.ZodNullable<z.ZodString>;
135
135
  jobId: z.ZodNullable<z.ZodString>;
@@ -12,10 +12,10 @@ declare const filterSchema: z.ZodObject<{
12
12
  jsonArray: "jsonArray";
13
13
  }>;
14
14
  method: z.ZodEnum<{
15
- starts_with: "starts_with";
16
- ends_with: "ends_with";
17
15
  contains: "contains";
18
16
  equals: "equals";
17
+ starts_with: "starts_with";
18
+ ends_with: "ends_with";
19
19
  greater_than: "greater_than";
20
20
  less_than: "less_than";
21
21
  on: "on";
@@ -44,10 +44,10 @@ declare const filtersSchema: z.ZodArray<z.ZodObject<{
44
44
  jsonArray: "jsonArray";
45
45
  }>;
46
46
  method: z.ZodEnum<{
47
- starts_with: "starts_with";
48
- ends_with: "ends_with";
49
47
  contains: "contains";
50
48
  equals: "equals";
49
+ starts_with: "starts_with";
50
+ ends_with: "ends_with";
51
51
  greater_than: "greater_than";
52
52
  less_than: "less_than";
53
53
  on: "on";
@@ -84,10 +84,10 @@ declare const querySchema: z.ZodObject<{
84
84
  jsonArray: "jsonArray";
85
85
  }>;
86
86
  method: z.ZodEnum<{
87
- starts_with: "starts_with";
88
- ends_with: "ends_with";
89
87
  contains: "contains";
90
88
  equals: "equals";
89
+ starts_with: "starts_with";
90
+ ends_with: "ends_with";
91
91
  greater_than: "greater_than";
92
92
  less_than: "less_than";
93
93
  on: "on";
@@ -12,10 +12,10 @@ declare const filterSchema: z.ZodObject<{
12
12
  jsonArray: "jsonArray";
13
13
  }>;
14
14
  method: z.ZodEnum<{
15
- starts_with: "starts_with";
16
- ends_with: "ends_with";
17
15
  contains: "contains";
18
16
  equals: "equals";
17
+ starts_with: "starts_with";
18
+ ends_with: "ends_with";
19
19
  greater_than: "greater_than";
20
20
  less_than: "less_than";
21
21
  on: "on";
@@ -44,10 +44,10 @@ declare const filtersSchema: z.ZodArray<z.ZodObject<{
44
44
  jsonArray: "jsonArray";
45
45
  }>;
46
46
  method: z.ZodEnum<{
47
- starts_with: "starts_with";
48
- ends_with: "ends_with";
49
47
  contains: "contains";
50
48
  equals: "equals";
49
+ starts_with: "starts_with";
50
+ ends_with: "ends_with";
51
51
  greater_than: "greater_than";
52
52
  less_than: "less_than";
53
53
  on: "on";
@@ -84,10 +84,10 @@ declare const querySchema: z.ZodObject<{
84
84
  jsonArray: "jsonArray";
85
85
  }>;
86
86
  method: z.ZodEnum<{
87
- starts_with: "starts_with";
88
- ends_with: "ends_with";
89
87
  contains: "contains";
90
88
  equals: "equals";
89
+ starts_with: "starts_with";
90
+ ends_with: "ends_with";
91
91
  greater_than: "greater_than";
92
92
  less_than: "less_than";
93
93
  on: "on";
@@ -42,10 +42,10 @@ declare const tagListInputSchema: z.ZodObject<{
42
42
  jsonArray: "jsonArray";
43
43
  }>;
44
44
  method: z.ZodEnum<{
45
- starts_with: "starts_with";
46
- ends_with: "ends_with";
47
45
  contains: "contains";
48
46
  equals: "equals";
47
+ starts_with: "starts_with";
48
+ ends_with: "ends_with";
49
49
  greater_than: "greater_than";
50
50
  less_than: "less_than";
51
51
  on: "on";
@@ -42,10 +42,10 @@ declare const tagListInputSchema: z.ZodObject<{
42
42
  jsonArray: "jsonArray";
43
43
  }>;
44
44
  method: z.ZodEnum<{
45
- starts_with: "starts_with";
46
- ends_with: "ends_with";
47
45
  contains: "contains";
48
46
  equals: "equals";
47
+ starts_with: "starts_with";
48
+ ends_with: "ends_with";
49
49
  greater_than: "greater_than";
50
50
  less_than: "less_than";
51
51
  on: "on";
@@ -11,10 +11,10 @@ declare const workflowSelectSchema: z.ZodObject<{
11
11
  input: z.ZodUnknown;
12
12
  output: z.ZodUnknown;
13
13
  status: z.ZodEnum<{
14
+ failed: "failed";
14
15
  queued: "queued";
15
16
  running: "running";
16
17
  completed: "completed";
17
- failed: "failed";
18
18
  }>;
19
19
  error: z.ZodNullable<z.ZodString>;
20
20
  retries: z.ZodNumber;
@@ -28,10 +28,10 @@ declare const workflowReadInputSchema: z.ZodObject<{
28
28
  }, z.core.$strip>;
29
29
  declare const workflowListInputSchema: z.ZodObject<{
30
30
  status: z.ZodOptional<z.ZodArray<z.ZodEnum<{
31
+ failed: "failed";
31
32
  queued: "queued";
32
33
  running: "running";
33
34
  completed: "completed";
34
- failed: "failed";
35
35
  }>>>;
36
36
  jobName: z.ZodOptional<z.ZodString>;
37
37
  }, z.core.$strip>;
@@ -51,10 +51,10 @@ declare const workflowReadOutputSchema: z.ZodObject<{
51
51
  input: z.ZodUnknown;
52
52
  output: z.ZodUnknown;
53
53
  status: z.ZodEnum<{
54
+ failed: "failed";
54
55
  queued: "queued";
55
56
  running: "running";
56
57
  completed: "completed";
57
- failed: "failed";
58
58
  }>;
59
59
  error: z.ZodNullable<z.ZodString>;
60
60
  retries: z.ZodNumber;
@@ -73,10 +73,10 @@ declare const workflowListOutputSchema: z.ZodArray<z.ZodObject<{
73
73
  input: z.ZodUnknown;
74
74
  output: z.ZodUnknown;
75
75
  status: z.ZodEnum<{
76
+ failed: "failed";
76
77
  queued: "queued";
77
78
  running: "running";
78
79
  completed: "completed";
79
- failed: "failed";
80
80
  }>;
81
81
  error: z.ZodNullable<z.ZodString>;
82
82
  retries: z.ZodNumber;
@@ -11,10 +11,10 @@ declare const workflowSelectSchema: z.ZodObject<{
11
11
  input: z.ZodUnknown;
12
12
  output: z.ZodUnknown;
13
13
  status: z.ZodEnum<{
14
+ failed: "failed";
14
15
  queued: "queued";
15
16
  running: "running";
16
17
  completed: "completed";
17
- failed: "failed";
18
18
  }>;
19
19
  error: z.ZodNullable<z.ZodString>;
20
20
  retries: z.ZodNumber;
@@ -28,10 +28,10 @@ declare const workflowReadInputSchema: z.ZodObject<{
28
28
  }, z.core.$strip>;
29
29
  declare const workflowListInputSchema: z.ZodObject<{
30
30
  status: z.ZodOptional<z.ZodArray<z.ZodEnum<{
31
+ failed: "failed";
31
32
  queued: "queued";
32
33
  running: "running";
33
34
  completed: "completed";
34
- failed: "failed";
35
35
  }>>>;
36
36
  jobName: z.ZodOptional<z.ZodString>;
37
37
  }, z.core.$strip>;
@@ -51,10 +51,10 @@ declare const workflowReadOutputSchema: z.ZodObject<{
51
51
  input: z.ZodUnknown;
52
52
  output: z.ZodUnknown;
53
53
  status: z.ZodEnum<{
54
+ failed: "failed";
54
55
  queued: "queued";
55
56
  running: "running";
56
57
  completed: "completed";
57
- failed: "failed";
58
58
  }>;
59
59
  error: z.ZodNullable<z.ZodString>;
60
60
  retries: z.ZodNumber;
@@ -73,10 +73,10 @@ declare const workflowListOutputSchema: z.ZodArray<z.ZodObject<{
73
73
  input: z.ZodUnknown;
74
74
  output: z.ZodUnknown;
75
75
  status: z.ZodEnum<{
76
+ failed: "failed";
76
77
  queued: "queued";
77
78
  running: "running";
78
79
  completed: "completed";
79
- failed: "failed";
80
80
  }>;
81
81
  error: z.ZodNullable<z.ZodString>;
82
82
  retries: z.ZodNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m5kdev/commons",
3
- "version": "0.23.0",
3
+ "version": "0.25.0",
4
4
  "license": "GPL-3.0-only",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,7 @@
18
18
  "devDependencies": {
19
19
  "tsdown": "0.21.7",
20
20
  "typescript": "6.0.3",
21
- "@m5kdev/config": "0.23.0"
21
+ "@m5kdev/config": "0.25.0"
22
22
  },
23
23
  "exports": {
24
24
  "./utils/*": {