business-as-code 0.2.1 → 2.0.2
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +17 -0
- package/IMPLEMENTATION.md +226 -0
- package/README.md +1133 -193
- package/dist/business.d.ts +62 -0
- package/dist/business.d.ts.map +1 -0
- package/dist/business.js +109 -0
- package/dist/business.js.map +1 -0
- package/dist/dollar.d.ts +60 -0
- package/dist/dollar.d.ts.map +1 -0
- package/dist/dollar.js +107 -0
- package/dist/dollar.js.map +1 -0
- package/dist/entities/assets.d.ts +21 -0
- package/dist/entities/assets.d.ts.map +1 -0
- package/dist/entities/assets.js +323 -0
- package/dist/entities/assets.js.map +1 -0
- package/dist/entities/business.d.ts +36 -0
- package/dist/entities/business.d.ts.map +1 -0
- package/dist/entities/business.js +370 -0
- package/dist/entities/business.js.map +1 -0
- package/dist/entities/communication.d.ts +21 -0
- package/dist/entities/communication.d.ts.map +1 -0
- package/dist/entities/communication.js +255 -0
- package/dist/entities/communication.js.map +1 -0
- package/dist/entities/customers.d.ts +58 -0
- package/dist/entities/customers.d.ts.map +1 -0
- package/dist/entities/customers.js +989 -0
- package/dist/entities/customers.js.map +1 -0
- package/dist/entities/financials.d.ts +59 -0
- package/dist/entities/financials.d.ts.map +1 -0
- package/dist/entities/financials.js +932 -0
- package/dist/entities/financials.js.map +1 -0
- package/dist/entities/goals.d.ts +58 -0
- package/dist/entities/goals.d.ts.map +1 -0
- package/dist/entities/goals.js +800 -0
- package/dist/entities/goals.js.map +1 -0
- package/dist/entities/index.d.ts +299 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +198 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/entities/legal.d.ts +21 -0
- package/dist/entities/legal.d.ts.map +1 -0
- package/dist/entities/legal.js +301 -0
- package/dist/entities/legal.js.map +1 -0
- package/dist/entities/market.d.ts +21 -0
- package/dist/entities/market.d.ts.map +1 -0
- package/dist/entities/market.js +301 -0
- package/dist/entities/market.js.map +1 -0
- package/dist/entities/marketing.d.ts +67 -0
- package/dist/entities/marketing.d.ts.map +1 -0
- package/dist/entities/marketing.js +1157 -0
- package/dist/entities/marketing.js.map +1 -0
- package/dist/entities/offerings.d.ts +51 -0
- package/dist/entities/offerings.d.ts.map +1 -0
- package/dist/entities/offerings.js +727 -0
- package/dist/entities/offerings.js.map +1 -0
- package/dist/entities/operations.d.ts +58 -0
- package/dist/entities/operations.d.ts.map +1 -0
- package/dist/entities/operations.js +787 -0
- package/dist/entities/operations.js.map +1 -0
- package/dist/entities/organization.d.ts +57 -0
- package/dist/entities/organization.d.ts.map +1 -0
- package/dist/entities/organization.js +807 -0
- package/dist/entities/organization.js.map +1 -0
- package/dist/entities/partnerships.d.ts +21 -0
- package/dist/entities/partnerships.d.ts.map +1 -0
- package/dist/entities/partnerships.js +300 -0
- package/dist/entities/partnerships.js.map +1 -0
- package/dist/entities/planning.d.ts +87 -0
- package/dist/entities/planning.d.ts.map +1 -0
- package/dist/entities/planning.js +271 -0
- package/dist/entities/planning.js.map +1 -0
- package/dist/entities/projects.d.ts +25 -0
- package/dist/entities/projects.d.ts.map +1 -0
- package/dist/entities/projects.js +349 -0
- package/dist/entities/projects.js.map +1 -0
- package/dist/entities/risk.d.ts +21 -0
- package/dist/entities/risk.d.ts.map +1 -0
- package/dist/entities/risk.js +293 -0
- package/dist/entities/risk.js.map +1 -0
- package/dist/entities/sales.d.ts +72 -0
- package/dist/entities/sales.d.ts.map +1 -0
- package/dist/entities/sales.js +1248 -0
- package/dist/entities/sales.js.map +1 -0
- package/dist/financials.d.ts +130 -0
- package/dist/financials.d.ts.map +1 -0
- package/dist/financials.js +297 -0
- package/dist/financials.js.map +1 -0
- package/dist/goals.d.ts +87 -0
- package/dist/goals.d.ts.map +1 -0
- package/dist/goals.js +215 -0
- package/dist/goals.js.map +1 -0
- package/dist/index.d.ts +97 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +131 -1079
- package/dist/index.js.map +1 -1
- package/dist/kpis.d.ts +118 -0
- package/dist/kpis.d.ts.map +1 -0
- package/dist/kpis.js +232 -0
- package/dist/kpis.js.map +1 -0
- package/dist/metrics.d.ts +448 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +325 -0
- package/dist/metrics.js.map +1 -0
- package/dist/okrs.d.ts +123 -0
- package/dist/okrs.d.ts.map +1 -0
- package/dist/okrs.js +269 -0
- package/dist/okrs.js.map +1 -0
- package/dist/organization.d.ts +585 -0
- package/dist/organization.d.ts.map +1 -0
- package/dist/organization.js +173 -0
- package/dist/organization.js.map +1 -0
- package/dist/process.d.ts +112 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +241 -0
- package/dist/process.js.map +1 -0
- package/dist/product.d.ts +85 -0
- package/dist/product.d.ts.map +1 -0
- package/dist/product.js +145 -0
- package/dist/product.js.map +1 -0
- package/dist/queries.d.ts +304 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +415 -0
- package/dist/queries.js.map +1 -0
- package/dist/roles.d.ts +340 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/roles.js +255 -0
- package/dist/roles.js.map +1 -0
- package/dist/service.d.ts +61 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +140 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +459 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/vision.d.ts +38 -0
- package/dist/vision.d.ts.map +1 -0
- package/dist/vision.js +68 -0
- package/dist/vision.js.map +1 -0
- package/dist/workflow.d.ts +115 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +247 -0
- package/dist/workflow.js.map +1 -0
- package/examples/basic-usage.ts +307 -0
- package/package.json +19 -60
- package/src/business.ts +121 -0
- package/src/dollar.ts +132 -0
- package/src/entities/assets.ts +332 -0
- package/src/entities/business.ts +406 -0
- package/src/entities/communication.ts +264 -0
- package/src/entities/customers.ts +1072 -0
- package/src/entities/financials.ts +1011 -0
- package/src/entities/goals.ts +871 -0
- package/src/entities/index.ts +383 -0
- package/src/entities/legal.ts +310 -0
- package/src/entities/market.ts +310 -0
- package/src/entities/marketing.ts +1249 -0
- package/src/entities/offerings.ts +789 -0
- package/src/entities/operations.ts +861 -0
- package/src/entities/organization.ts +876 -0
- package/src/entities/partnerships.ts +309 -0
- package/src/entities/planning.ts +307 -0
- package/src/entities/projects.ts +360 -0
- package/src/entities/risk.ts +302 -0
- package/src/entities/sales.ts +1352 -0
- package/src/financials.ts +352 -0
- package/src/goals.ts +250 -0
- package/src/index.test.ts +336 -0
- package/src/index.ts +530 -0
- package/src/kpis.ts +275 -0
- package/src/metrics.ts +825 -0
- package/src/okrs.ts +325 -0
- package/src/organization.ts +909 -0
- package/src/process.ts +272 -0
- package/src/product.ts +178 -0
- package/src/queries.ts +767 -0
- package/src/roles.ts +686 -0
- package/src/service.ts +164 -0
- package/src/types.ts +493 -0
- package/src/vision.ts +88 -0
- package/src/workflow.ts +280 -0
- package/tsconfig.json +9 -0
- package/dist/loaders/index.d.ts +0 -174
- package/dist/loaders/index.js +0 -366
- package/dist/loaders/index.js.map +0 -1
- package/dist/schema/index.d.ts +0 -146
- package/dist/schema/index.js +0 -716
- package/dist/schema/index.js.map +0 -1
- package/dist/types-CJ9eGS_C.d.ts +0 -86
package/dist/roles.d.ts
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Business Roles - Bridges digital-workers and ai-database authorization
|
|
3
|
+
*
|
|
4
|
+
* Connects:
|
|
5
|
+
* - WorkerRole (business role: CEO, Engineer, Manager)
|
|
6
|
+
* - Authorization Role (FGA/RBAC: permissions, access control)
|
|
7
|
+
* - Task Assignment (who handles what in workflows/processes)
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Business role type - the function of a worker in the organization
|
|
13
|
+
*/
|
|
14
|
+
export type BusinessRoleType = 'ceo' | 'cto' | 'cfo' | 'coo' | 'cmo' | 'cpo' | 'director' | 'manager' | 'lead' | 'supervisor' | 'engineer' | 'designer' | 'analyst' | 'specialist' | 'coordinator' | 'operator' | 'agent' | 'assistant' | string;
|
|
15
|
+
/**
|
|
16
|
+
* Business Role - extends WorkerRole with authorization and task capabilities
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const engineeringManager: BusinessRole = {
|
|
21
|
+
* id: 'role_eng_manager',
|
|
22
|
+
* name: 'Engineering Manager',
|
|
23
|
+
* type: 'manager',
|
|
24
|
+
* department: 'Engineering',
|
|
25
|
+
* description: 'Leads engineering team and makes technical decisions',
|
|
26
|
+
*
|
|
27
|
+
* // Business responsibilities
|
|
28
|
+
* responsibilities: [
|
|
29
|
+
* 'Lead engineering team',
|
|
30
|
+
* 'Make architecture decisions',
|
|
31
|
+
* 'Conduct code reviews',
|
|
32
|
+
* ],
|
|
33
|
+
*
|
|
34
|
+
* // Authorization permissions (from FGA)
|
|
35
|
+
* permissions: {
|
|
36
|
+
* repository: ['read', 'edit', 'act:merge', 'act:deploy'],
|
|
37
|
+
* project: ['read', 'edit', 'manage'],
|
|
38
|
+
* team: ['read', 'edit'],
|
|
39
|
+
* },
|
|
40
|
+
*
|
|
41
|
+
* // Task capabilities
|
|
42
|
+
* canHandle: ['code-review', 'architecture-decision', 'deployment-approval'],
|
|
43
|
+
* canDelegate: ['code-review', 'testing'],
|
|
44
|
+
* canApprove: ['pull-request', 'deployment', 'budget-under-5k'],
|
|
45
|
+
*
|
|
46
|
+
* // Worker type preference
|
|
47
|
+
* workerType: 'human',
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export interface BusinessRole {
|
|
52
|
+
/** Unique role identifier */
|
|
53
|
+
id: string;
|
|
54
|
+
/** Role display name */
|
|
55
|
+
name: string;
|
|
56
|
+
/** Role type classification */
|
|
57
|
+
type: BusinessRoleType;
|
|
58
|
+
/** Department or team */
|
|
59
|
+
department?: string;
|
|
60
|
+
/** Human-readable description */
|
|
61
|
+
description?: string;
|
|
62
|
+
/** Key responsibilities */
|
|
63
|
+
responsibilities?: string[];
|
|
64
|
+
/** Required skills */
|
|
65
|
+
skills?: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Authorization permissions by resource type
|
|
68
|
+
*
|
|
69
|
+
* Maps resource types to allowed actions:
|
|
70
|
+
* - 'read', 'edit', 'delete', 'manage' (standard)
|
|
71
|
+
* - 'act:*' or 'act:verb' (domain-specific verbs)
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* permissions: {
|
|
76
|
+
* document: ['read', 'edit'],
|
|
77
|
+
* invoice: ['read', 'act:send', 'act:void'],
|
|
78
|
+
* project: ['read', 'edit', 'manage'],
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
permissions?: Record<string, string[]>;
|
|
83
|
+
/** Task types this role can handle */
|
|
84
|
+
canHandle?: string[];
|
|
85
|
+
/** Task types this role can delegate to others */
|
|
86
|
+
canDelegate?: string[];
|
|
87
|
+
/** Request types this role can approve */
|
|
88
|
+
canApprove?: string[];
|
|
89
|
+
/** Escalation path - role to escalate to */
|
|
90
|
+
escalateTo?: string;
|
|
91
|
+
/** Reports to - manager role */
|
|
92
|
+
reportsTo?: string;
|
|
93
|
+
/** Worker type preference: 'ai' | 'human' | 'hybrid' */
|
|
94
|
+
workerType?: 'ai' | 'human' | 'hybrid';
|
|
95
|
+
/** Level in hierarchy (1 = entry, higher = more senior) */
|
|
96
|
+
level?: number;
|
|
97
|
+
/** Compensation band */
|
|
98
|
+
compensationBand?: string;
|
|
99
|
+
/** Additional metadata */
|
|
100
|
+
metadata?: Record<string, unknown>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Task status
|
|
104
|
+
*/
|
|
105
|
+
export type TaskStatus = 'pending' | 'assigned' | 'in_progress' | 'blocked' | 'completed' | 'failed' | 'cancelled';
|
|
106
|
+
/**
|
|
107
|
+
* Task priority
|
|
108
|
+
*/
|
|
109
|
+
export type TaskPriority = 'low' | 'normal' | 'high' | 'urgent' | 'critical';
|
|
110
|
+
/**
|
|
111
|
+
* Task assignment - links a worker to a task
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const assignment: TaskAssignment = {
|
|
116
|
+
* id: 'assign_123',
|
|
117
|
+
* taskId: 'task_review_pr_456',
|
|
118
|
+
* taskType: 'code-review',
|
|
119
|
+
*
|
|
120
|
+
* // Who is assigned
|
|
121
|
+
* assignee: { type: 'worker', id: 'worker_alice' },
|
|
122
|
+
* role: 'role_eng_manager',
|
|
123
|
+
*
|
|
124
|
+
* // From what process/workflow
|
|
125
|
+
* processId: 'process_code_review',
|
|
126
|
+
* stepId: 'step_1_review',
|
|
127
|
+
*
|
|
128
|
+
* // Status and timing
|
|
129
|
+
* status: 'in_progress',
|
|
130
|
+
* priority: 'high',
|
|
131
|
+
* assignedAt: new Date(),
|
|
132
|
+
* dueAt: new Date(Date.now() + 24 * 60 * 60 * 1000),
|
|
133
|
+
*
|
|
134
|
+
* // Context
|
|
135
|
+
* context: {
|
|
136
|
+
* pullRequestId: 'pr_789',
|
|
137
|
+
* repository: 'acme/webapp',
|
|
138
|
+
* },
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export interface TaskAssignment {
|
|
143
|
+
/** Unique assignment ID */
|
|
144
|
+
id: string;
|
|
145
|
+
/** Task identifier */
|
|
146
|
+
taskId: string;
|
|
147
|
+
/** Task type (for routing) */
|
|
148
|
+
taskType: string;
|
|
149
|
+
/** Task description */
|
|
150
|
+
description?: string;
|
|
151
|
+
/** Who is assigned */
|
|
152
|
+
assignee: AssigneeRef;
|
|
153
|
+
/** Required role for this task */
|
|
154
|
+
role?: string;
|
|
155
|
+
/** Source process ID */
|
|
156
|
+
processId?: string;
|
|
157
|
+
/** Source workflow ID */
|
|
158
|
+
workflowId?: string;
|
|
159
|
+
/** Step ID within process/workflow */
|
|
160
|
+
stepId?: string;
|
|
161
|
+
/** Current status */
|
|
162
|
+
status: TaskStatus;
|
|
163
|
+
/** Priority */
|
|
164
|
+
priority?: TaskPriority;
|
|
165
|
+
/** When assigned */
|
|
166
|
+
assignedAt: Date;
|
|
167
|
+
/** Who assigned it */
|
|
168
|
+
assignedBy?: AssigneeRef;
|
|
169
|
+
/** Due date */
|
|
170
|
+
dueAt?: Date;
|
|
171
|
+
/** Started at */
|
|
172
|
+
startedAt?: Date;
|
|
173
|
+
/** Completed at */
|
|
174
|
+
completedAt?: Date;
|
|
175
|
+
/** Task context/data */
|
|
176
|
+
context?: Record<string, unknown>;
|
|
177
|
+
/** Task result */
|
|
178
|
+
result?: unknown;
|
|
179
|
+
/** Notes */
|
|
180
|
+
notes?: string;
|
|
181
|
+
/** Metadata */
|
|
182
|
+
metadata?: Record<string, unknown>;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Reference to an assignee (worker, team, or role)
|
|
186
|
+
*/
|
|
187
|
+
export interface AssigneeRef {
|
|
188
|
+
/** Type of assignee */
|
|
189
|
+
type: 'worker' | 'team' | 'role';
|
|
190
|
+
/** Assignee ID */
|
|
191
|
+
id: string;
|
|
192
|
+
/** Display name */
|
|
193
|
+
name?: string;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Task routing rule - determines who handles what tasks
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* const routingRules: TaskRoutingRule[] = [
|
|
201
|
+
* {
|
|
202
|
+
* taskType: 'code-review',
|
|
203
|
+
* requiredRole: 'engineer',
|
|
204
|
+
* requiredLevel: 2,
|
|
205
|
+
* requiredSkills: ['TypeScript'],
|
|
206
|
+
* preferWorkerType: 'human',
|
|
207
|
+
* },
|
|
208
|
+
* {
|
|
209
|
+
* taskType: 'expense-approval',
|
|
210
|
+
* requiredRole: 'manager',
|
|
211
|
+
* amountThreshold: 1000,
|
|
212
|
+
* escalateAbove: 5000, // Escalate to director above $5k
|
|
213
|
+
* escalateTo: 'director',
|
|
214
|
+
* },
|
|
215
|
+
* {
|
|
216
|
+
* taskType: 'customer-inquiry',
|
|
217
|
+
* requiredRole: 'agent',
|
|
218
|
+
* preferWorkerType: 'ai',
|
|
219
|
+
* fallbackTo: 'human', // Escalate to human if AI can't handle
|
|
220
|
+
* },
|
|
221
|
+
* ]
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
export interface TaskRoutingRule {
|
|
225
|
+
/** Task type this rule applies to */
|
|
226
|
+
taskType: string;
|
|
227
|
+
/** Required role type */
|
|
228
|
+
requiredRole?: BusinessRoleType;
|
|
229
|
+
/** Minimum level required */
|
|
230
|
+
requiredLevel?: number;
|
|
231
|
+
/** Required skills */
|
|
232
|
+
requiredSkills?: string[];
|
|
233
|
+
/** Required permissions */
|
|
234
|
+
requiredPermissions?: string[];
|
|
235
|
+
/** Preferred worker type */
|
|
236
|
+
preferWorkerType?: 'ai' | 'human' | 'hybrid';
|
|
237
|
+
/** Amount threshold (for approval tasks) */
|
|
238
|
+
amountThreshold?: number;
|
|
239
|
+
/** Amount above which to escalate */
|
|
240
|
+
escalateAbove?: number;
|
|
241
|
+
/** Role to escalate to */
|
|
242
|
+
escalateTo?: BusinessRoleType | string;
|
|
243
|
+
/** Fallback worker type if preferred unavailable */
|
|
244
|
+
fallbackTo?: 'ai' | 'human';
|
|
245
|
+
/** Priority for this task type */
|
|
246
|
+
defaultPriority?: TaskPriority;
|
|
247
|
+
/** SLA in minutes */
|
|
248
|
+
slaMinutes?: number;
|
|
249
|
+
/** Additional conditions */
|
|
250
|
+
conditions?: Record<string, unknown>;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Workflow role - defines a role within the context of a workflow
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* const workflowRoles: WorkflowRole[] = [
|
|
258
|
+
* {
|
|
259
|
+
* name: 'Requester',
|
|
260
|
+
* description: 'Person who initiates the request',
|
|
261
|
+
* canInitiate: true,
|
|
262
|
+
* canView: ['all'],
|
|
263
|
+
* },
|
|
264
|
+
* {
|
|
265
|
+
* name: 'Approver',
|
|
266
|
+
* description: 'Person who approves or rejects',
|
|
267
|
+
* tasks: ['review', 'approve', 'reject'],
|
|
268
|
+
* canView: ['details', 'history'],
|
|
269
|
+
* requiredBusinessRole: 'manager',
|
|
270
|
+
* },
|
|
271
|
+
* {
|
|
272
|
+
* name: 'Processor',
|
|
273
|
+
* description: 'Person who processes after approval',
|
|
274
|
+
* tasks: ['process', 'complete'],
|
|
275
|
+
* requiredBusinessRole: 'operator',
|
|
276
|
+
* },
|
|
277
|
+
* ]
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
export interface WorkflowRole {
|
|
281
|
+
/** Role name within workflow */
|
|
282
|
+
name: string;
|
|
283
|
+
/** Description */
|
|
284
|
+
description?: string;
|
|
285
|
+
/** Can initiate this workflow */
|
|
286
|
+
canInitiate?: boolean;
|
|
287
|
+
/** Tasks this role handles */
|
|
288
|
+
tasks?: string[];
|
|
289
|
+
/** What this role can view */
|
|
290
|
+
canView?: string[];
|
|
291
|
+
/** Required business role */
|
|
292
|
+
requiredBusinessRole?: BusinessRoleType | string;
|
|
293
|
+
/** Required permissions */
|
|
294
|
+
requiredPermissions?: string[];
|
|
295
|
+
/** Minimum level */
|
|
296
|
+
minLevel?: number;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Standard business roles with typical permissions
|
|
300
|
+
*/
|
|
301
|
+
export declare const StandardBusinessRoles: Record<string, Partial<BusinessRole>>;
|
|
302
|
+
/**
|
|
303
|
+
* Create a business role from a standard template
|
|
304
|
+
*/
|
|
305
|
+
export declare function createBusinessRole(id: string, template: keyof typeof StandardBusinessRoles, overrides?: Partial<BusinessRole>): BusinessRole;
|
|
306
|
+
/**
|
|
307
|
+
* Check if a role has permission for an action on a resource type
|
|
308
|
+
*/
|
|
309
|
+
export declare function hasPermission(role: BusinessRole, resourceType: string, action: string): boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Check if a role can handle a task type
|
|
312
|
+
*/
|
|
313
|
+
export declare function canHandleTask(role: BusinessRole, taskType: string): boolean;
|
|
314
|
+
/**
|
|
315
|
+
* Check if a role can approve a request type
|
|
316
|
+
*/
|
|
317
|
+
export declare function canApproveRequest(role: BusinessRole, requestType: string): boolean;
|
|
318
|
+
/**
|
|
319
|
+
* Check if a role can delegate a task type
|
|
320
|
+
*/
|
|
321
|
+
export declare function canDelegateTask(role: BusinessRole, taskType: string): boolean;
|
|
322
|
+
/**
|
|
323
|
+
* Find the best role for a task based on routing rules
|
|
324
|
+
*/
|
|
325
|
+
export declare function findRoleForTask(taskType: string, rules: TaskRoutingRule[], context?: {
|
|
326
|
+
amount?: number;
|
|
327
|
+
skills?: string[];
|
|
328
|
+
}): TaskRoutingRule | undefined;
|
|
329
|
+
/**
|
|
330
|
+
* Create a task assignment
|
|
331
|
+
*/
|
|
332
|
+
export declare function createTaskAssignment(taskId: string, taskType: string, assignee: AssigneeRef, options?: Partial<Omit<TaskAssignment, 'id' | 'taskId' | 'taskType' | 'assignee' | 'status' | 'assignedAt'>>): TaskAssignment;
|
|
333
|
+
/**
|
|
334
|
+
* Transition task assignment status
|
|
335
|
+
*/
|
|
336
|
+
export declare function transitionTaskStatus(assignment: TaskAssignment, newStatus: TaskStatus, options?: {
|
|
337
|
+
result?: unknown;
|
|
338
|
+
notes?: string;
|
|
339
|
+
}): TaskAssignment;
|
|
340
|
+
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../src/roles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAM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,EAAE,MAAM,GAAG,OAAO,CAG7E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,eAAe,EAAE,EACxB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAC/C,eAAe,GAAG,SAAS,CAoB7B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,YAAY,CAAC,CAAC,GAC3G,cAAc,CAWhB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7C,cAAc,CAWhB"}
|
package/dist/roles.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Business Roles - Bridges digital-workers and ai-database authorization
|
|
3
|
+
*
|
|
4
|
+
* Connects:
|
|
5
|
+
* - WorkerRole (business role: CEO, Engineer, Manager)
|
|
6
|
+
* - Authorization Role (FGA/RBAC: permissions, access control)
|
|
7
|
+
* - Task Assignment (who handles what in workflows/processes)
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// Standard Business Roles
|
|
13
|
+
// =============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* Standard business roles with typical permissions
|
|
16
|
+
*/
|
|
17
|
+
export const StandardBusinessRoles = {
|
|
18
|
+
// Executive
|
|
19
|
+
ceo: {
|
|
20
|
+
type: 'ceo',
|
|
21
|
+
name: 'Chief Executive Officer',
|
|
22
|
+
level: 10,
|
|
23
|
+
permissions: { '*': ['manage'] },
|
|
24
|
+
canApprove: ['*'],
|
|
25
|
+
workerType: 'human',
|
|
26
|
+
},
|
|
27
|
+
cto: {
|
|
28
|
+
type: 'cto',
|
|
29
|
+
name: 'Chief Technology Officer',
|
|
30
|
+
level: 10,
|
|
31
|
+
department: 'Technology',
|
|
32
|
+
permissions: {
|
|
33
|
+
technology: ['manage'],
|
|
34
|
+
repository: ['manage'],
|
|
35
|
+
infrastructure: ['manage'],
|
|
36
|
+
},
|
|
37
|
+
canApprove: ['technical-decision', 'architecture', 'technology-budget'],
|
|
38
|
+
workerType: 'human',
|
|
39
|
+
},
|
|
40
|
+
cfo: {
|
|
41
|
+
type: 'cfo',
|
|
42
|
+
name: 'Chief Financial Officer',
|
|
43
|
+
level: 10,
|
|
44
|
+
department: 'Finance',
|
|
45
|
+
permissions: {
|
|
46
|
+
finance: ['manage'],
|
|
47
|
+
budget: ['manage'],
|
|
48
|
+
expense: ['manage'],
|
|
49
|
+
},
|
|
50
|
+
canApprove: ['expense', 'budget', 'financial-decision'],
|
|
51
|
+
workerType: 'human',
|
|
52
|
+
},
|
|
53
|
+
// Management
|
|
54
|
+
director: {
|
|
55
|
+
type: 'director',
|
|
56
|
+
level: 8,
|
|
57
|
+
permissions: {
|
|
58
|
+
team: ['manage'],
|
|
59
|
+
project: ['manage'],
|
|
60
|
+
budget: ['read', 'edit'],
|
|
61
|
+
},
|
|
62
|
+
canApprove: ['hiring', 'budget-under-50k', 'project'],
|
|
63
|
+
workerType: 'human',
|
|
64
|
+
},
|
|
65
|
+
manager: {
|
|
66
|
+
type: 'manager',
|
|
67
|
+
level: 6,
|
|
68
|
+
permissions: {
|
|
69
|
+
team: ['read', 'edit'],
|
|
70
|
+
project: ['read', 'edit', 'manage'],
|
|
71
|
+
},
|
|
72
|
+
canApprove: ['expense-under-5k', 'time-off', 'code-review'],
|
|
73
|
+
workerType: 'human',
|
|
74
|
+
},
|
|
75
|
+
lead: {
|
|
76
|
+
type: 'lead',
|
|
77
|
+
level: 5,
|
|
78
|
+
permissions: {
|
|
79
|
+
team: ['read'],
|
|
80
|
+
project: ['read', 'edit'],
|
|
81
|
+
repository: ['read', 'edit', 'act:merge'],
|
|
82
|
+
},
|
|
83
|
+
canDelegate: ['code-review', 'testing'],
|
|
84
|
+
workerType: 'hybrid',
|
|
85
|
+
},
|
|
86
|
+
// Individual Contributors
|
|
87
|
+
engineer: {
|
|
88
|
+
type: 'engineer',
|
|
89
|
+
level: 3,
|
|
90
|
+
department: 'Engineering',
|
|
91
|
+
permissions: {
|
|
92
|
+
repository: ['read', 'edit'],
|
|
93
|
+
project: ['read'],
|
|
94
|
+
},
|
|
95
|
+
canHandle: ['coding', 'code-review', 'bug-fix', 'testing'],
|
|
96
|
+
workerType: 'hybrid',
|
|
97
|
+
},
|
|
98
|
+
analyst: {
|
|
99
|
+
type: 'analyst',
|
|
100
|
+
level: 3,
|
|
101
|
+
permissions: {
|
|
102
|
+
data: ['read'],
|
|
103
|
+
report: ['read', 'edit'],
|
|
104
|
+
},
|
|
105
|
+
canHandle: ['data-analysis', 'reporting', 'research'],
|
|
106
|
+
workerType: 'hybrid',
|
|
107
|
+
},
|
|
108
|
+
// Operations
|
|
109
|
+
agent: {
|
|
110
|
+
type: 'agent',
|
|
111
|
+
level: 2,
|
|
112
|
+
permissions: {
|
|
113
|
+
ticket: ['read', 'edit', 'act:respond', 'act:escalate'],
|
|
114
|
+
customer: ['read'],
|
|
115
|
+
},
|
|
116
|
+
canHandle: ['customer-inquiry', 'support-ticket', 'basic-troubleshooting'],
|
|
117
|
+
workerType: 'ai', // AI-first
|
|
118
|
+
},
|
|
119
|
+
assistant: {
|
|
120
|
+
type: 'assistant',
|
|
121
|
+
level: 1,
|
|
122
|
+
permissions: {
|
|
123
|
+
calendar: ['read', 'edit'],
|
|
124
|
+
email: ['read', 'act:draft'],
|
|
125
|
+
task: ['read', 'edit'],
|
|
126
|
+
},
|
|
127
|
+
canHandle: ['scheduling', 'email-draft', 'task-management', 'research'],
|
|
128
|
+
workerType: 'ai', // AI-first
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
// =============================================================================
|
|
132
|
+
// Helper Functions
|
|
133
|
+
// =============================================================================
|
|
134
|
+
/**
|
|
135
|
+
* Create a business role from a standard template
|
|
136
|
+
*/
|
|
137
|
+
export function createBusinessRole(id, template, overrides) {
|
|
138
|
+
const standard = StandardBusinessRoles[template];
|
|
139
|
+
if (!standard) {
|
|
140
|
+
throw new Error(`Unknown role template: ${template}`);
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
id,
|
|
144
|
+
name: standard.name || template,
|
|
145
|
+
type: standard.type || template,
|
|
146
|
+
...standard,
|
|
147
|
+
...overrides,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check if a role has permission for an action on a resource type
|
|
152
|
+
*/
|
|
153
|
+
export function hasPermission(role, resourceType, action) {
|
|
154
|
+
if (!role.permissions)
|
|
155
|
+
return false;
|
|
156
|
+
// Check wildcard permissions
|
|
157
|
+
const wildcardPerms = role.permissions['*'];
|
|
158
|
+
if (wildcardPerms) {
|
|
159
|
+
if (wildcardPerms.includes('manage') || wildcardPerms.includes('*'))
|
|
160
|
+
return true;
|
|
161
|
+
if (wildcardPerms.includes(action))
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
// Check resource-specific permissions
|
|
165
|
+
const resourcePerms = role.permissions[resourceType];
|
|
166
|
+
if (!resourcePerms)
|
|
167
|
+
return false;
|
|
168
|
+
// Check for exact match
|
|
169
|
+
if (resourcePerms.includes(action))
|
|
170
|
+
return true;
|
|
171
|
+
// Check for 'manage' which includes all actions
|
|
172
|
+
if (resourcePerms.includes('manage') || resourcePerms.includes('*'))
|
|
173
|
+
return true;
|
|
174
|
+
// Check for act:* pattern
|
|
175
|
+
if (action.startsWith('act:')) {
|
|
176
|
+
if (resourcePerms.includes('act:*'))
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Check if a role can handle a task type
|
|
183
|
+
*/
|
|
184
|
+
export function canHandleTask(role, taskType) {
|
|
185
|
+
if (!role.canHandle)
|
|
186
|
+
return false;
|
|
187
|
+
return role.canHandle.includes(taskType) || role.canHandle.includes('*');
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Check if a role can approve a request type
|
|
191
|
+
*/
|
|
192
|
+
export function canApproveRequest(role, requestType) {
|
|
193
|
+
if (!role.canApprove)
|
|
194
|
+
return false;
|
|
195
|
+
return role.canApprove.includes(requestType) || role.canApprove.includes('*');
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Check if a role can delegate a task type
|
|
199
|
+
*/
|
|
200
|
+
export function canDelegateTask(role, taskType) {
|
|
201
|
+
if (!role.canDelegate)
|
|
202
|
+
return false;
|
|
203
|
+
return role.canDelegate.includes(taskType) || role.canDelegate.includes('*');
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Find the best role for a task based on routing rules
|
|
207
|
+
*/
|
|
208
|
+
export function findRoleForTask(taskType, rules, context) {
|
|
209
|
+
const matchingRules = rules.filter(rule => rule.taskType === taskType);
|
|
210
|
+
if (matchingRules.length === 0)
|
|
211
|
+
return undefined;
|
|
212
|
+
// If there's an amount and escalation rules, check those
|
|
213
|
+
if (context?.amount) {
|
|
214
|
+
for (const rule of matchingRules) {
|
|
215
|
+
if (rule.escalateAbove && context.amount > rule.escalateAbove) {
|
|
216
|
+
// Find the escalated rule
|
|
217
|
+
const escalatedRule = rules.find(r => r.taskType === taskType && r.requiredRole === rule.escalateTo);
|
|
218
|
+
if (escalatedRule)
|
|
219
|
+
return escalatedRule;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Return the first matching rule
|
|
224
|
+
return matchingRules[0];
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Create a task assignment
|
|
228
|
+
*/
|
|
229
|
+
export function createTaskAssignment(taskId, taskType, assignee, options) {
|
|
230
|
+
return {
|
|
231
|
+
id: `assign_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`,
|
|
232
|
+
taskId,
|
|
233
|
+
taskType,
|
|
234
|
+
assignee,
|
|
235
|
+
status: 'assigned',
|
|
236
|
+
assignedAt: new Date(),
|
|
237
|
+
priority: 'normal',
|
|
238
|
+
...options,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Transition task assignment status
|
|
243
|
+
*/
|
|
244
|
+
export function transitionTaskStatus(assignment, newStatus, options) {
|
|
245
|
+
const now = new Date();
|
|
246
|
+
return {
|
|
247
|
+
...assignment,
|
|
248
|
+
status: newStatus,
|
|
249
|
+
...(newStatus === 'in_progress' && !assignment.startedAt ? { startedAt: now } : {}),
|
|
250
|
+
...(newStatus === 'completed' || newStatus === 'failed' ? { completedAt: now } : {}),
|
|
251
|
+
...(options?.result ? { result: options.result } : {}),
|
|
252
|
+
...(options?.notes ? { notes: options.notes } : {}),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=roles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../src/roles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA8YH,gFAAgF;AAChF,0BAA0B;AAC1B,gFAAgF;AAEhF;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAA0C;IAC1E,YAAY;IACZ,GAAG,EAAE;QACH,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,yBAAyB;QAC/B,KAAK,EAAE,EAAE;QACT,WAAW,EAAE,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE;QAChC,UAAU,EAAE,CAAC,GAAG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C,CAAC,EAAE;QACpE,MAAM;QACN,QAAQ;QACR,QAAQ;QACR,MAAM,EAAE,UAAU;QAClB,UAAU,EAAE,IAAI,IAAI,EAAE;QACtB,QAAQ,EAAE,QAAQ;QAClB,GAAG,OAAO;KACX,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAA0B,EAC1B,SAAqB,EACrB,OAA8C;IAE9C,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IAEtB,OAAO;QACL,GAAG,UAAU;QACb,MAAM,EAAE,SAAS;QACjB,GAAG,CAAC,SAAS,KAAK,aAAa,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnF,GAAG,CAAC,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpF,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service definition and management
|
|
3
|
+
*/
|
|
4
|
+
import type { ServiceDefinition } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Define a service with pricing, SLA, and delivery information
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const service = Service({
|
|
11
|
+
* name: 'Widget Consulting',
|
|
12
|
+
* description: 'Expert widget implementation and optimization',
|
|
13
|
+
* category: 'Consulting',
|
|
14
|
+
* targetSegment: 'Enterprise',
|
|
15
|
+
* valueProposition: 'Get expert help implementing widgets in 2 weeks',
|
|
16
|
+
* pricingModel: 'fixed',
|
|
17
|
+
* price: 5000,
|
|
18
|
+
* currency: 'USD',
|
|
19
|
+
* deliveryTime: '2 weeks',
|
|
20
|
+
* sla: {
|
|
21
|
+
* uptime: 99.9,
|
|
22
|
+
* responseTime: '< 24 hours',
|
|
23
|
+
* supportHours: 'Business hours (9-5 EST)',
|
|
24
|
+
* penalties: '10% refund per day of delay',
|
|
25
|
+
* },
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function Service(definition: ServiceDefinition): ServiceDefinition;
|
|
30
|
+
/**
|
|
31
|
+
* Calculate service price based on hours (for hourly pricing)
|
|
32
|
+
*/
|
|
33
|
+
export declare function calculateHourlyPrice(service: ServiceDefinition, hours: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* Calculate monthly retainer equivalent
|
|
36
|
+
*/
|
|
37
|
+
export declare function calculateMonthlyRetainer(service: ServiceDefinition, hoursPerMonth: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Check if service meets SLA uptime requirement
|
|
40
|
+
*/
|
|
41
|
+
export declare function checkSLAUptime(service: ServiceDefinition, actualUptime: number): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Parse delivery time to days
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseDeliveryTimeToDays(deliveryTime?: string): number;
|
|
46
|
+
/**
|
|
47
|
+
* Estimate service completion date
|
|
48
|
+
*/
|
|
49
|
+
export declare function estimateCompletionDate(service: ServiceDefinition, startDate?: Date): Date;
|
|
50
|
+
/**
|
|
51
|
+
* Calculate service value (for value-based pricing)
|
|
52
|
+
*/
|
|
53
|
+
export declare function calculateValueBasedPrice(service: ServiceDefinition, customerValue: number, valueSharePercentage: number): number;
|
|
54
|
+
/**
|
|
55
|
+
* Validate service definition
|
|
56
|
+
*/
|
|
57
|
+
export declare function validateService(service: ServiceDefinition): {
|
|
58
|
+
valid: boolean;
|
|
59
|
+
errors: string[];
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,OAAO,CAAC,UAAU,EAAE,iBAAiB,GAAG,iBAAiB,CAWxE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKtF;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAKlG;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAGxF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CA4BrE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,iBAAiB,EAAE,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAMzF;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,iBAAiB,EAC1B,aAAa,EAAE,MAAM,EACrB,oBAAoB,EAAE,MAAM,GAC3B,MAAM,CAUR;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CA0BhG"}
|