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.
Files changed (190) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +17 -0
  3. package/IMPLEMENTATION.md +226 -0
  4. package/README.md +1133 -193
  5. package/dist/business.d.ts +62 -0
  6. package/dist/business.d.ts.map +1 -0
  7. package/dist/business.js +109 -0
  8. package/dist/business.js.map +1 -0
  9. package/dist/dollar.d.ts +60 -0
  10. package/dist/dollar.d.ts.map +1 -0
  11. package/dist/dollar.js +107 -0
  12. package/dist/dollar.js.map +1 -0
  13. package/dist/entities/assets.d.ts +21 -0
  14. package/dist/entities/assets.d.ts.map +1 -0
  15. package/dist/entities/assets.js +323 -0
  16. package/dist/entities/assets.js.map +1 -0
  17. package/dist/entities/business.d.ts +36 -0
  18. package/dist/entities/business.d.ts.map +1 -0
  19. package/dist/entities/business.js +370 -0
  20. package/dist/entities/business.js.map +1 -0
  21. package/dist/entities/communication.d.ts +21 -0
  22. package/dist/entities/communication.d.ts.map +1 -0
  23. package/dist/entities/communication.js +255 -0
  24. package/dist/entities/communication.js.map +1 -0
  25. package/dist/entities/customers.d.ts +58 -0
  26. package/dist/entities/customers.d.ts.map +1 -0
  27. package/dist/entities/customers.js +989 -0
  28. package/dist/entities/customers.js.map +1 -0
  29. package/dist/entities/financials.d.ts +59 -0
  30. package/dist/entities/financials.d.ts.map +1 -0
  31. package/dist/entities/financials.js +932 -0
  32. package/dist/entities/financials.js.map +1 -0
  33. package/dist/entities/goals.d.ts +58 -0
  34. package/dist/entities/goals.d.ts.map +1 -0
  35. package/dist/entities/goals.js +800 -0
  36. package/dist/entities/goals.js.map +1 -0
  37. package/dist/entities/index.d.ts +299 -0
  38. package/dist/entities/index.d.ts.map +1 -0
  39. package/dist/entities/index.js +198 -0
  40. package/dist/entities/index.js.map +1 -0
  41. package/dist/entities/legal.d.ts +21 -0
  42. package/dist/entities/legal.d.ts.map +1 -0
  43. package/dist/entities/legal.js +301 -0
  44. package/dist/entities/legal.js.map +1 -0
  45. package/dist/entities/market.d.ts +21 -0
  46. package/dist/entities/market.d.ts.map +1 -0
  47. package/dist/entities/market.js +301 -0
  48. package/dist/entities/market.js.map +1 -0
  49. package/dist/entities/marketing.d.ts +67 -0
  50. package/dist/entities/marketing.d.ts.map +1 -0
  51. package/dist/entities/marketing.js +1157 -0
  52. package/dist/entities/marketing.js.map +1 -0
  53. package/dist/entities/offerings.d.ts +51 -0
  54. package/dist/entities/offerings.d.ts.map +1 -0
  55. package/dist/entities/offerings.js +727 -0
  56. package/dist/entities/offerings.js.map +1 -0
  57. package/dist/entities/operations.d.ts +58 -0
  58. package/dist/entities/operations.d.ts.map +1 -0
  59. package/dist/entities/operations.js +787 -0
  60. package/dist/entities/operations.js.map +1 -0
  61. package/dist/entities/organization.d.ts +57 -0
  62. package/dist/entities/organization.d.ts.map +1 -0
  63. package/dist/entities/organization.js +807 -0
  64. package/dist/entities/organization.js.map +1 -0
  65. package/dist/entities/partnerships.d.ts +21 -0
  66. package/dist/entities/partnerships.d.ts.map +1 -0
  67. package/dist/entities/partnerships.js +300 -0
  68. package/dist/entities/partnerships.js.map +1 -0
  69. package/dist/entities/planning.d.ts +87 -0
  70. package/dist/entities/planning.d.ts.map +1 -0
  71. package/dist/entities/planning.js +271 -0
  72. package/dist/entities/planning.js.map +1 -0
  73. package/dist/entities/projects.d.ts +25 -0
  74. package/dist/entities/projects.d.ts.map +1 -0
  75. package/dist/entities/projects.js +349 -0
  76. package/dist/entities/projects.js.map +1 -0
  77. package/dist/entities/risk.d.ts +21 -0
  78. package/dist/entities/risk.d.ts.map +1 -0
  79. package/dist/entities/risk.js +293 -0
  80. package/dist/entities/risk.js.map +1 -0
  81. package/dist/entities/sales.d.ts +72 -0
  82. package/dist/entities/sales.d.ts.map +1 -0
  83. package/dist/entities/sales.js +1248 -0
  84. package/dist/entities/sales.js.map +1 -0
  85. package/dist/financials.d.ts +130 -0
  86. package/dist/financials.d.ts.map +1 -0
  87. package/dist/financials.js +297 -0
  88. package/dist/financials.js.map +1 -0
  89. package/dist/goals.d.ts +87 -0
  90. package/dist/goals.d.ts.map +1 -0
  91. package/dist/goals.js +215 -0
  92. package/dist/goals.js.map +1 -0
  93. package/dist/index.d.ts +97 -4
  94. package/dist/index.d.ts.map +1 -0
  95. package/dist/index.js +131 -1079
  96. package/dist/index.js.map +1 -1
  97. package/dist/kpis.d.ts +118 -0
  98. package/dist/kpis.d.ts.map +1 -0
  99. package/dist/kpis.js +232 -0
  100. package/dist/kpis.js.map +1 -0
  101. package/dist/metrics.d.ts +448 -0
  102. package/dist/metrics.d.ts.map +1 -0
  103. package/dist/metrics.js +325 -0
  104. package/dist/metrics.js.map +1 -0
  105. package/dist/okrs.d.ts +123 -0
  106. package/dist/okrs.d.ts.map +1 -0
  107. package/dist/okrs.js +269 -0
  108. package/dist/okrs.js.map +1 -0
  109. package/dist/organization.d.ts +585 -0
  110. package/dist/organization.d.ts.map +1 -0
  111. package/dist/organization.js +173 -0
  112. package/dist/organization.js.map +1 -0
  113. package/dist/process.d.ts +112 -0
  114. package/dist/process.d.ts.map +1 -0
  115. package/dist/process.js +241 -0
  116. package/dist/process.js.map +1 -0
  117. package/dist/product.d.ts +85 -0
  118. package/dist/product.d.ts.map +1 -0
  119. package/dist/product.js +145 -0
  120. package/dist/product.js.map +1 -0
  121. package/dist/queries.d.ts +304 -0
  122. package/dist/queries.d.ts.map +1 -0
  123. package/dist/queries.js +415 -0
  124. package/dist/queries.js.map +1 -0
  125. package/dist/roles.d.ts +340 -0
  126. package/dist/roles.d.ts.map +1 -0
  127. package/dist/roles.js +255 -0
  128. package/dist/roles.js.map +1 -0
  129. package/dist/service.d.ts +61 -0
  130. package/dist/service.d.ts.map +1 -0
  131. package/dist/service.js +140 -0
  132. package/dist/service.js.map +1 -0
  133. package/dist/types.d.ts +459 -0
  134. package/dist/types.d.ts.map +1 -0
  135. package/dist/types.js +5 -0
  136. package/dist/types.js.map +1 -0
  137. package/dist/vision.d.ts +38 -0
  138. package/dist/vision.d.ts.map +1 -0
  139. package/dist/vision.js +68 -0
  140. package/dist/vision.js.map +1 -0
  141. package/dist/workflow.d.ts +115 -0
  142. package/dist/workflow.d.ts.map +1 -0
  143. package/dist/workflow.js +247 -0
  144. package/dist/workflow.js.map +1 -0
  145. package/examples/basic-usage.ts +307 -0
  146. package/package.json +19 -60
  147. package/src/business.ts +121 -0
  148. package/src/dollar.ts +132 -0
  149. package/src/entities/assets.ts +332 -0
  150. package/src/entities/business.ts +406 -0
  151. package/src/entities/communication.ts +264 -0
  152. package/src/entities/customers.ts +1072 -0
  153. package/src/entities/financials.ts +1011 -0
  154. package/src/entities/goals.ts +871 -0
  155. package/src/entities/index.ts +383 -0
  156. package/src/entities/legal.ts +310 -0
  157. package/src/entities/market.ts +310 -0
  158. package/src/entities/marketing.ts +1249 -0
  159. package/src/entities/offerings.ts +789 -0
  160. package/src/entities/operations.ts +861 -0
  161. package/src/entities/organization.ts +876 -0
  162. package/src/entities/partnerships.ts +309 -0
  163. package/src/entities/planning.ts +307 -0
  164. package/src/entities/projects.ts +360 -0
  165. package/src/entities/risk.ts +302 -0
  166. package/src/entities/sales.ts +1352 -0
  167. package/src/financials.ts +352 -0
  168. package/src/goals.ts +250 -0
  169. package/src/index.test.ts +336 -0
  170. package/src/index.ts +530 -0
  171. package/src/kpis.ts +275 -0
  172. package/src/metrics.ts +825 -0
  173. package/src/okrs.ts +325 -0
  174. package/src/organization.ts +909 -0
  175. package/src/process.ts +272 -0
  176. package/src/product.ts +178 -0
  177. package/src/queries.ts +767 -0
  178. package/src/roles.ts +686 -0
  179. package/src/service.ts +164 -0
  180. package/src/types.ts +493 -0
  181. package/src/vision.ts +88 -0
  182. package/src/workflow.ts +280 -0
  183. package/tsconfig.json +9 -0
  184. package/dist/loaders/index.d.ts +0 -174
  185. package/dist/loaders/index.js +0 -366
  186. package/dist/loaders/index.js.map +0 -1
  187. package/dist/schema/index.d.ts +0 -146
  188. package/dist/schema/index.js +0 -716
  189. package/dist/schema/index.js.map +0 -1
  190. package/dist/types-CJ9eGS_C.d.ts +0 -86
@@ -0,0 +1,585 @@
1
+ /**
2
+ * Organization Structure - Flows to FGA/RBAC
3
+ *
4
+ * Defines the complete organizational hierarchy:
5
+ *
6
+ * Organization
7
+ * └── Department
8
+ * └── Team
9
+ * └── Position (Role + Worker)
10
+ * └── Permissions (FGA/RBAC)
11
+ *
12
+ * This structure enables:
13
+ * - Hierarchical permission inheritance
14
+ * - Role-based task assignment
15
+ * - Approval chains based on org structure
16
+ * - Resource access control based on department/team
17
+ *
18
+ * @packageDocumentation
19
+ */
20
+ import type { BusinessRole, TaskRoutingRule, WorkflowRole } from './roles.js';
21
+ /**
22
+ * Organization - top-level business entity
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const acme: Organization = {
27
+ * id: 'org_acme',
28
+ * name: 'Acme Corp',
29
+ * domain: 'acme.com',
30
+ * industry: 'technology',
31
+ *
32
+ * // Hierarchy
33
+ * departments: [engineering, sales, support],
34
+ *
35
+ * // Global settings
36
+ * settings: {
37
+ * defaultCurrency: 'USD',
38
+ * timezone: 'America/Los_Angeles',
39
+ * workWeek: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'],
40
+ * },
41
+ *
42
+ * // Resource hierarchy for FGA
43
+ * resourceHierarchy: {
44
+ * organization: { children: ['department', 'project', 'repository'] },
45
+ * department: { parent: 'organization', children: ['team'] },
46
+ * team: { parent: 'department', children: ['position'] },
47
+ * },
48
+ * }
49
+ * ```
50
+ */
51
+ export interface Organization {
52
+ /** Unique identifier */
53
+ id: string;
54
+ /** Organization name */
55
+ name: string;
56
+ /** Primary domain */
57
+ domain?: string;
58
+ /** Legal name (if different) */
59
+ legalName?: string;
60
+ /** Industry/sector */
61
+ industry?: string;
62
+ /** Mission statement */
63
+ mission?: string;
64
+ /** Core values */
65
+ values?: string[];
66
+ /** Founded date */
67
+ foundedAt?: Date;
68
+ /** Headquarters location */
69
+ headquarters?: Address;
70
+ /** Organization settings */
71
+ settings?: OrganizationSettings;
72
+ /** Departments */
73
+ departments?: Department[];
74
+ /** Standalone teams (not in departments) */
75
+ teams?: Team[];
76
+ /** Organization-wide roles */
77
+ roles?: BusinessRole[];
78
+ /** Resource hierarchy for FGA */
79
+ resourceHierarchy?: ResourceHierarchy;
80
+ /** Global approval chains */
81
+ approvalChains?: ApprovalChain[];
82
+ /** Task routing rules */
83
+ routingRules?: TaskRoutingRule[];
84
+ /** Metadata */
85
+ metadata?: Record<string, unknown>;
86
+ }
87
+ /**
88
+ * Organization settings
89
+ */
90
+ export interface OrganizationSettings {
91
+ /** Default currency */
92
+ defaultCurrency?: string;
93
+ /** Default timezone */
94
+ timezone?: string;
95
+ /** Work week days */
96
+ workWeek?: string[];
97
+ /** Business hours */
98
+ businessHours?: {
99
+ start: string;
100
+ end: string;
101
+ timezone?: string;
102
+ };
103
+ /** Fiscal year start month (1-12) */
104
+ fiscalYearStart?: number;
105
+ /** Default language */
106
+ language?: string;
107
+ /** Date format */
108
+ dateFormat?: string;
109
+ }
110
+ /**
111
+ * Address
112
+ */
113
+ export interface Address {
114
+ street?: string;
115
+ city?: string;
116
+ state?: string;
117
+ postalCode?: string;
118
+ country?: string;
119
+ }
120
+ /**
121
+ * Department - major organizational division
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * const engineering: Department = {
126
+ * id: 'dept_eng',
127
+ * name: 'Engineering',
128
+ * code: 'ENG',
129
+ *
130
+ * // Leadership
131
+ * head: { roleId: 'role_cto', positionId: 'pos_cto_jane' },
132
+ *
133
+ * // Teams
134
+ * teams: [platformTeam, productTeam, infraTeam],
135
+ *
136
+ * // Budget
137
+ * budget: {
138
+ * annual: 5000000,
139
+ * currency: 'USD',
140
+ * categories: {
141
+ * salaries: 3500000,
142
+ * tools: 200000,
143
+ * infrastructure: 800000,
144
+ * training: 100000,
145
+ * },
146
+ * },
147
+ *
148
+ * // FGA: Department-level permissions
149
+ * defaultPermissions: {
150
+ * repository: ['read'],
151
+ * project: ['read'],
152
+ * },
153
+ * }
154
+ * ```
155
+ */
156
+ export interface Department {
157
+ /** Unique identifier */
158
+ id: string;
159
+ /** Department name */
160
+ name: string;
161
+ /** Short code (e.g., 'ENG', 'SALES') */
162
+ code?: string;
163
+ /** Description */
164
+ description?: string;
165
+ /** Department head position */
166
+ head?: PositionRef;
167
+ /** Parent department (for sub-departments) */
168
+ parentId?: string;
169
+ /** Teams within department */
170
+ teams?: Team[];
171
+ /** Department budget */
172
+ budget?: Budget;
173
+ /** Cost center code */
174
+ costCenter?: string;
175
+ /** Department goals */
176
+ goals?: string[];
177
+ /** Default permissions for department members */
178
+ defaultPermissions?: Record<string, string[]>;
179
+ /** Department-specific roles */
180
+ roles?: BusinessRole[];
181
+ /** Department-specific routing rules */
182
+ routingRules?: TaskRoutingRule[];
183
+ /** Metadata */
184
+ metadata?: Record<string, unknown>;
185
+ }
186
+ /**
187
+ * Team - working group within a department
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * const platformTeam: Team = {
192
+ * id: 'team_platform',
193
+ * name: 'Platform Team',
194
+ * departmentId: 'dept_eng',
195
+ *
196
+ * // Leadership
197
+ * lead: { roleId: 'role_lead', positionId: 'pos_lead_bob' },
198
+ *
199
+ * // Members
200
+ * positions: [
201
+ * { id: 'pos_1', roleId: 'role_engineer', workerId: 'worker_alice' },
202
+ * { id: 'pos_2', roleId: 'role_engineer', workerId: 'worker_charlie' },
203
+ * { id: 'pos_3', roleId: 'role_engineer', workerId: null }, // Open position
204
+ * ],
205
+ *
206
+ * // Team resources (for FGA scoping)
207
+ * resources: {
208
+ * repositories: ['platform-core', 'platform-api'],
209
+ * projects: ['platform-v2'],
210
+ * },
211
+ *
212
+ * // Team-level permissions (inherited by members)
213
+ * defaultPermissions: {
214
+ * repository: ['read', 'edit', 'act:merge'],
215
+ * project: ['read', 'edit'],
216
+ * },
217
+ * }
218
+ * ```
219
+ */
220
+ export interface Team {
221
+ /** Unique identifier */
222
+ id: string;
223
+ /** Team name */
224
+ name: string;
225
+ /** Parent department */
226
+ departmentId?: string;
227
+ /** Description */
228
+ description?: string;
229
+ /** Team lead position */
230
+ lead?: PositionRef;
231
+ /** Team positions */
232
+ positions?: Position[];
233
+ /** Team objectives */
234
+ objectives?: string[];
235
+ /** Team resources (for FGA scoping) */
236
+ resources?: TeamResources;
237
+ /** Team budget (if separate from department) */
238
+ budget?: Budget;
239
+ /** Default permissions for team members */
240
+ defaultPermissions?: Record<string, string[]>;
241
+ /** Workflow roles for this team */
242
+ workflowRoles?: WorkflowRole[];
243
+ /** Communication channels */
244
+ channels?: TeamChannels;
245
+ /** Metadata */
246
+ metadata?: Record<string, unknown>;
247
+ }
248
+ /**
249
+ * Team resources - scopes FGA permissions
250
+ */
251
+ export interface TeamResources {
252
+ /** Owned repositories */
253
+ repositories?: string[];
254
+ /** Owned projects */
255
+ projects?: string[];
256
+ /** Owned products */
257
+ products?: string[];
258
+ /** Custom resource types */
259
+ [resourceType: string]: string[] | undefined;
260
+ }
261
+ /**
262
+ * Team communication channels
263
+ */
264
+ export interface TeamChannels {
265
+ slack?: string;
266
+ teams?: string;
267
+ email?: string;
268
+ discord?: string;
269
+ }
270
+ /**
271
+ * Position - a role filled by a worker
272
+ *
273
+ * The position is the link between:
274
+ * - Business Role (responsibilities, permissions)
275
+ * - Worker (human or AI agent)
276
+ * - Location in org hierarchy (team → department → org)
277
+ *
278
+ * @example
279
+ * ```ts
280
+ * const seniorEngineerPosition: Position = {
281
+ * id: 'pos_se_123',
282
+ * title: 'Senior Software Engineer',
283
+ *
284
+ * // Role defines what this position can do
285
+ * roleId: 'role_senior_engineer',
286
+ *
287
+ * // Worker currently filling this position
288
+ * workerId: 'worker_alice',
289
+ * workerType: 'human',
290
+ *
291
+ * // Hierarchy
292
+ * teamId: 'team_platform',
293
+ * reportsTo: 'pos_lead_bob',
294
+ *
295
+ * // Position-specific permissions (added to role permissions)
296
+ * additionalPermissions: {
297
+ * 'repository:platform-core': ['manage'],
298
+ * },
299
+ *
300
+ * // Employment details
301
+ * startDate: new Date('2023-01-15'),
302
+ * status: 'active',
303
+ * }
304
+ * ```
305
+ */
306
+ export interface Position {
307
+ /** Unique identifier */
308
+ id: string;
309
+ /** Position title */
310
+ title: string;
311
+ /** Business role this position requires */
312
+ roleId: string;
313
+ /** Worker filling this position (null = open position) */
314
+ workerId?: string | null;
315
+ /** Type of worker (human, agent, or either) */
316
+ workerType?: 'human' | 'agent' | 'any';
317
+ /** Team this position belongs to */
318
+ teamId?: string;
319
+ /** Position this reports to */
320
+ reportsTo?: string;
321
+ /** Direct reports (position IDs) */
322
+ directReports?: string[];
323
+ /** Position-specific additional permissions */
324
+ additionalPermissions?: Record<string, string[]>;
325
+ /** Start date */
326
+ startDate?: Date;
327
+ /** End date (for contractors/temporary) */
328
+ endDate?: Date;
329
+ /** Position status */
330
+ status?: 'active' | 'open' | 'on-leave' | 'terminated';
331
+ /** Full-time equivalent (1.0 = full-time) */
332
+ fte?: number;
333
+ /** Location */
334
+ location?: string;
335
+ /** Remote/hybrid/onsite */
336
+ workModel?: 'remote' | 'hybrid' | 'onsite';
337
+ /** Compensation */
338
+ compensation?: Compensation;
339
+ /** Metadata */
340
+ metadata?: Record<string, unknown>;
341
+ }
342
+ /**
343
+ * Position reference
344
+ */
345
+ export interface PositionRef {
346
+ positionId?: string;
347
+ roleId?: string;
348
+ workerId?: string;
349
+ }
350
+ /**
351
+ * Compensation details
352
+ */
353
+ export interface Compensation {
354
+ /** Base salary */
355
+ baseSalary?: number;
356
+ /** Currency */
357
+ currency?: string;
358
+ /** Pay frequency */
359
+ frequency?: 'hourly' | 'weekly' | 'biweekly' | 'monthly' | 'annual';
360
+ /** Bonus target percentage */
361
+ bonusTarget?: number;
362
+ /** Equity grants */
363
+ equity?: {
364
+ type: 'options' | 'rsu' | 'shares';
365
+ amount: number;
366
+ vestingSchedule?: string;
367
+ };
368
+ /** Band/level */
369
+ band?: string;
370
+ }
371
+ /**
372
+ * Budget allocation
373
+ */
374
+ export interface Budget {
375
+ /** Total annual budget */
376
+ annual?: number;
377
+ /** Currency */
378
+ currency?: string;
379
+ /** Budget period */
380
+ period?: string;
381
+ /** Budget categories */
382
+ categories?: Record<string, number>;
383
+ /** Spent to date */
384
+ spent?: number;
385
+ /** Remaining */
386
+ remaining?: number;
387
+ }
388
+ /**
389
+ * Resource hierarchy definition for FGA
390
+ *
391
+ * Defines how resources relate to each other for permission inheritance.
392
+ *
393
+ * @example
394
+ * ```ts
395
+ * const hierarchy: ResourceHierarchy = {
396
+ * // Organization is root
397
+ * organization: {
398
+ * children: ['department', 'project', 'repository'],
399
+ * },
400
+ *
401
+ * // Department inherits from org
402
+ * department: {
403
+ * parent: 'organization',
404
+ * children: ['team'],
405
+ * },
406
+ *
407
+ * // Team inherits from department
408
+ * team: {
409
+ * parent: 'department',
410
+ * children: ['position'],
411
+ * },
412
+ *
413
+ * // Project can be org-level or team-level
414
+ * project: {
415
+ * parent: 'organization',
416
+ * alternateParents: ['team'],
417
+ * children: ['document', 'task'],
418
+ * },
419
+ *
420
+ * // Repository can be org-level or team-level
421
+ * repository: {
422
+ * parent: 'organization',
423
+ * alternateParents: ['team'],
424
+ * },
425
+ * }
426
+ * ```
427
+ */
428
+ export interface ResourceHierarchy {
429
+ [resourceType: string]: ResourceHierarchyNode;
430
+ }
431
+ /**
432
+ * Node in resource hierarchy
433
+ */
434
+ export interface ResourceHierarchyNode {
435
+ /** Primary parent resource type */
436
+ parent?: string;
437
+ /** Alternative parent types */
438
+ alternateParents?: string[];
439
+ /** Child resource types */
440
+ children?: string[];
441
+ /** Whether permissions cascade down */
442
+ inheritPermissions?: boolean;
443
+ /** Maximum depth (for nested resources) */
444
+ maxDepth?: number;
445
+ }
446
+ /**
447
+ * Approval chain - defines who approves what
448
+ *
449
+ * @example
450
+ * ```ts
451
+ * const expenseApprovalChain: ApprovalChain = {
452
+ * id: 'chain_expense',
453
+ * name: 'Expense Approval',
454
+ * type: 'expense',
455
+ *
456
+ * levels: [
457
+ * {
458
+ * threshold: 1000,
459
+ * approvers: [{ type: 'direct-manager' }],
460
+ * },
461
+ * {
462
+ * threshold: 5000,
463
+ * approvers: [
464
+ * { type: 'direct-manager' },
465
+ * { type: 'role', roleId: 'director' },
466
+ * ],
467
+ * },
468
+ * {
469
+ * threshold: 25000,
470
+ * approvers: [
471
+ * { type: 'direct-manager' },
472
+ * { type: 'role', roleId: 'vp' },
473
+ * { type: 'role', roleId: 'cfo' },
474
+ * ],
475
+ * },
476
+ * ],
477
+ *
478
+ * // Escalation settings
479
+ * escalation: {
480
+ * afterHours: 24,
481
+ * escalateTo: 'skip-level-manager',
482
+ * },
483
+ * }
484
+ * ```
485
+ */
486
+ export interface ApprovalChain {
487
+ /** Chain identifier */
488
+ id: string;
489
+ /** Chain name */
490
+ name: string;
491
+ /** What type of requests this chain handles */
492
+ type: string;
493
+ /** Approval levels */
494
+ levels: ApprovalLevel[];
495
+ /** Escalation rules */
496
+ escalation?: EscalationRule;
497
+ /** Active/inactive */
498
+ active?: boolean;
499
+ /** Metadata */
500
+ metadata?: Record<string, unknown>;
501
+ }
502
+ /**
503
+ * Approval level within a chain
504
+ */
505
+ export interface ApprovalLevel {
506
+ /** Threshold amount (requests above this need this level) */
507
+ threshold?: number;
508
+ /** Approvers at this level */
509
+ approvers: ApproverSpec[];
510
+ /** How many approvers needed */
511
+ requiredApprovals?: number;
512
+ /** Whether approvals at this level are sequential or parallel */
513
+ approvalMode?: 'sequential' | 'parallel' | 'any';
514
+ /** SLA for this level (hours) */
515
+ slaHours?: number;
516
+ }
517
+ /**
518
+ * Approver specification
519
+ */
520
+ export interface ApproverSpec {
521
+ /** Approver type */
522
+ type: 'direct-manager' | 'skip-level-manager' | 'role' | 'position' | 'worker' | 'team';
523
+ /** Role ID (if type is 'role') */
524
+ roleId?: string;
525
+ /** Position ID (if type is 'position') */
526
+ positionId?: string;
527
+ /** Worker ID (if type is 'worker') */
528
+ workerId?: string;
529
+ /** Team ID (if type is 'team') */
530
+ teamId?: string;
531
+ }
532
+ /**
533
+ * Escalation rule
534
+ */
535
+ export interface EscalationRule {
536
+ /** Hours before escalation */
537
+ afterHours: number;
538
+ /** Who to escalate to */
539
+ escalateTo: 'skip-level-manager' | 'department-head' | 'role' | 'position';
540
+ /** Role ID if escalating to role */
541
+ roleId?: string;
542
+ /** Position ID if escalating to position */
543
+ positionId?: string;
544
+ /** Maximum escalations */
545
+ maxEscalations?: number;
546
+ }
547
+ /**
548
+ * Resolved permissions for a worker
549
+ *
550
+ * Combines:
551
+ * - Organization-level defaults
552
+ * - Department-level permissions
553
+ * - Team-level permissions
554
+ * - Role permissions
555
+ * - Position-specific permissions
556
+ */
557
+ export interface ResolvedPermissions {
558
+ /** Worker ID */
559
+ workerId: string;
560
+ /** Position ID */
561
+ positionId: string;
562
+ /** Effective permissions by resource type */
563
+ permissions: Record<string, string[]>;
564
+ /** Resource-specific permissions */
565
+ resourcePermissions: Record<string, Record<string, string[]>>;
566
+ /** Approval capabilities */
567
+ canApprove: string[];
568
+ /** Task handling capabilities */
569
+ canHandle: string[];
570
+ /** Inheritance chain (for debugging) */
571
+ inheritanceChain: string[];
572
+ }
573
+ /**
574
+ * Resolve permissions for a position in the org hierarchy
575
+ */
576
+ export declare function resolvePermissions(org: Organization, positionId: string): ResolvedPermissions | null;
577
+ /**
578
+ * Get approval chain for a request
579
+ */
580
+ export declare function getApprovalChainForRequest(org: Organization, requestType: string, amount?: number): ApproverSpec[];
581
+ /**
582
+ * Find manager for a position (follows reportsTo chain)
583
+ */
584
+ export declare function findManager(org: Organization, positionId: string): Position | null;
585
+ //# sourceMappingURL=organization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organization.d.ts","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,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