business-as-code 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +43 -0
- 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 +61 -0
- package/dist/entities/organization.d.ts.map +1 -0
- package/dist/entities/organization.js +816 -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/finance/account.d.ts +44 -0
- package/dist/finance/account.d.ts.map +1 -0
- package/dist/finance/account.js +6 -0
- package/dist/finance/account.js.map +1 -0
- package/dist/finance/authority.d.ts +78 -0
- package/dist/finance/authority.d.ts.map +1 -0
- package/dist/finance/authority.js +27 -0
- package/dist/finance/authority.js.map +1 -0
- package/dist/finance/card.d.ts +36 -0
- package/dist/finance/card.d.ts.map +1 -0
- package/dist/finance/card.js +6 -0
- package/dist/finance/card.js.map +1 -0
- package/dist/finance/identity.d.ts +30 -0
- package/dist/finance/identity.d.ts.map +1 -0
- package/dist/finance/identity.js +8 -0
- package/dist/finance/identity.js.map +1 -0
- package/dist/finance/index.d.ts +36 -0
- package/dist/finance/index.d.ts.map +1 -0
- package/dist/finance/index.js +22 -0
- package/dist/finance/index.js.map +1 -0
- package/dist/finance/ledger.d.ts +24 -0
- package/dist/finance/ledger.d.ts.map +1 -0
- package/dist/finance/ledger.js +8 -0
- package/dist/finance/ledger.js.map +1 -0
- package/dist/finance/merchant.d.ts +129 -0
- package/dist/finance/merchant.d.ts.map +1 -0
- package/dist/finance/merchant.js +21 -0
- package/dist/finance/merchant.js.map +1 -0
- package/dist/finance/outcome-contract.d.ts +139 -0
- package/dist/finance/outcome-contract.d.ts.map +1 -0
- package/dist/finance/outcome-contract.js +27 -0
- package/dist/finance/outcome-contract.js.map +1 -0
- package/dist/finance/port.d.ts +121 -0
- package/dist/finance/port.d.ts.map +1 -0
- package/dist/finance/port.js +10 -0
- package/dist/finance/port.js.map +1 -0
- package/dist/finance/pricing.d.ts +154 -0
- package/dist/finance/pricing.d.ts.map +1 -0
- package/dist/finance/pricing.js +79 -0
- package/dist/finance/pricing.js.map +1 -0
- package/dist/finance/proof-predicate.d.ts +92 -0
- package/dist/finance/proof-predicate.d.ts.map +1 -0
- package/dist/finance/proof-predicate.js +80 -0
- package/dist/finance/proof-predicate.js.map +1 -0
- package/dist/finance/refund.d.ts +44 -0
- package/dist/finance/refund.d.ts.map +1 -0
- package/dist/finance/refund.js +41 -0
- package/dist/finance/refund.js.map +1 -0
- package/dist/finance/sla.d.ts +25 -0
- package/dist/finance/sla.d.ts.map +1 -0
- package/dist/finance/sla.js +7 -0
- package/dist/finance/sla.js.map +1 -0
- package/dist/finance/types.d.ts +79 -0
- package/dist/finance/types.d.ts.map +1 -0
- package/dist/finance/types.js +8 -0
- package/dist/finance/types.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 +106 -0
- package/dist/goals.d.ts.map +1 -0
- package/dist/goals.js +284 -0
- package/dist/goals.js.map +1 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +144 -0
- package/dist/index.js.map +1 -0
- package/dist/kpis.d.ts +137 -0
- package/dist/kpis.d.ts.map +1 -0
- package/dist/kpis.js +297 -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 +330 -0
- package/dist/metrics.js.map +1 -0
- package/dist/okrs.d.ts +157 -0
- package/dist/okrs.d.ts.map +1 -0
- package/dist/okrs.js +391 -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 +242 -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 +577 -0
- package/dist/queries.js.map +1 -0
- package/dist/roles.d.ts +334 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/roles.js +282 -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 +248 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +8 -4
- package/src/finance/account.ts +48 -0
- package/src/finance/authority.ts +42 -0
- package/src/finance/card.ts +38 -0
- package/src/finance/identity.ts +31 -0
- package/src/finance/index.ts +117 -0
- package/src/finance/ledger.ts +26 -0
- package/src/finance/merchant.ts +127 -0
- package/src/finance/outcome-contract.ts +157 -0
- package/src/finance/port.ts +144 -0
- package/src/finance/pricing.ts +197 -0
- package/src/finance/proof-predicate.ts +106 -0
- package/src/finance/refund.ts +52 -0
- package/src/finance/sla.ts +33 -0
- package/src/finance/types.ts +75 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/vision.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vision statement definition
|
|
3
|
+
*/
|
|
4
|
+
import type { VisionDefinition } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Define a business vision statement with timeframe and success indicators
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const vision = Vision({
|
|
11
|
+
* statement: 'To become the world\'s most trusted widget platform',
|
|
12
|
+
* timeframe: '5 years',
|
|
13
|
+
* successIndicators: [
|
|
14
|
+
* '10M+ active users',
|
|
15
|
+
* 'Present in 50+ countries',
|
|
16
|
+
* 'Industry-leading NPS score',
|
|
17
|
+
* '$1B+ annual revenue',
|
|
18
|
+
* ],
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function Vision(definition: VisionDefinition): VisionDefinition;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a success indicator has been achieved
|
|
25
|
+
*/
|
|
26
|
+
export declare function checkIndicator(vision: VisionDefinition, indicator: string, currentMetrics: Record<string, number | boolean>): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Calculate vision progress based on achieved indicators
|
|
29
|
+
*/
|
|
30
|
+
export declare function calculateProgress(vision: VisionDefinition, currentMetrics: Record<string, number | boolean>): number;
|
|
31
|
+
/**
|
|
32
|
+
* Validate vision definition
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateVision(vision: VisionDefinition): {
|
|
35
|
+
valid: boolean;
|
|
36
|
+
errors: string[];
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=vision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vision.d.ts","sourceRoot":"","sources":["../src/vision.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,UAAU,EAAE,gBAAgB,GAAG,gBAAgB,CAYrE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,gBAAgB,EACxB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAC/C,OAAO,CAKT;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,gBAAgB,EACxB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAC/C,MAAM,CAUR;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,gBAAgB,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAe7F"}
|
package/dist/vision.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vision statement definition
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Define a business vision statement with timeframe and success indicators
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const vision = Vision({
|
|
10
|
+
* statement: 'To become the world\'s most trusted widget platform',
|
|
11
|
+
* timeframe: '5 years',
|
|
12
|
+
* successIndicators: [
|
|
13
|
+
* '10M+ active users',
|
|
14
|
+
* 'Present in 50+ countries',
|
|
15
|
+
* 'Industry-leading NPS score',
|
|
16
|
+
* '$1B+ annual revenue',
|
|
17
|
+
* ],
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function Vision(definition) {
|
|
22
|
+
// Validate required fields
|
|
23
|
+
if (!definition.statement) {
|
|
24
|
+
throw new Error('Vision statement is required');
|
|
25
|
+
}
|
|
26
|
+
// Return validated vision definition
|
|
27
|
+
return {
|
|
28
|
+
...definition,
|
|
29
|
+
successIndicators: definition.successIndicators || [],
|
|
30
|
+
metadata: definition.metadata || {},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if a success indicator has been achieved
|
|
35
|
+
*/
|
|
36
|
+
export function checkIndicator(vision, indicator, currentMetrics) {
|
|
37
|
+
// Simple check - would need more sophisticated parsing in production
|
|
38
|
+
return Object.entries(currentMetrics).some(([key, value]) => {
|
|
39
|
+
return indicator.toLowerCase().includes(key.toLowerCase()) && Boolean(value);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Calculate vision progress based on achieved indicators
|
|
44
|
+
*/
|
|
45
|
+
export function calculateProgress(vision, currentMetrics) {
|
|
46
|
+
if (!vision.successIndicators || vision.successIndicators.length === 0) {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
const achieved = vision.successIndicators.filter(indicator => checkIndicator(vision, indicator, currentMetrics)).length;
|
|
50
|
+
return (achieved / vision.successIndicators.length) * 100;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Validate vision definition
|
|
54
|
+
*/
|
|
55
|
+
export function validateVision(vision) {
|
|
56
|
+
const errors = [];
|
|
57
|
+
if (!vision.statement) {
|
|
58
|
+
errors.push('Vision statement is required');
|
|
59
|
+
}
|
|
60
|
+
if (vision.statement && vision.statement.length < 10) {
|
|
61
|
+
errors.push('Vision statement should be at least 10 characters');
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
valid: errors.length === 0,
|
|
65
|
+
errors,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=vision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vision.js","sourceRoot":"","sources":["../src/vision.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CAAC,UAA4B;IACjD,2BAA2B;IAC3B,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,qCAAqC;IACrC,OAAO;QACL,GAAG,UAAU;QACb,iBAAiB,EAAE,UAAU,CAAC,iBAAiB,IAAI,EAAE;QACrD,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,EAAE;KACpC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAwB,EACxB,SAAiB,EACjB,cAAgD;IAEhD,qEAAqE;IACrE,OAAO,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC1D,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAA;IAC9E,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAAwB,EACxB,cAAgD;IAEhD,IAAI,CAAC,MAAM,CAAC,iBAAiB,IAAI,MAAM,CAAC,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvE,OAAO,CAAC,CAAA;IACV,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAC3D,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,cAAc,CAAC,CAClD,CAAC,MAAM,CAAA;IAER,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG,GAAG,CAAA;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAwB;IACrD,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;IAC7C,CAAC;IAED,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACrD,MAAM,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAA;IAClE,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM;KACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow definition (automation sequences)
|
|
3
|
+
*/
|
|
4
|
+
import type { WorkflowDefinition, WorkflowAction, WorkflowTrigger } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Define an automated workflow with triggers and actions
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const workflow = Workflow({
|
|
11
|
+
* name: 'New Customer Welcome',
|
|
12
|
+
* description: 'Automated welcome sequence for new customers',
|
|
13
|
+
* trigger: {
|
|
14
|
+
* type: 'event',
|
|
15
|
+
* event: 'Customer.created',
|
|
16
|
+
* },
|
|
17
|
+
* actions: [
|
|
18
|
+
* {
|
|
19
|
+
* order: 1,
|
|
20
|
+
* type: 'send',
|
|
21
|
+
* description: 'Send welcome email',
|
|
22
|
+
* params: {
|
|
23
|
+
* template: 'welcome_email',
|
|
24
|
+
* to: '{{customer.email}}',
|
|
25
|
+
* },
|
|
26
|
+
* },
|
|
27
|
+
* {
|
|
28
|
+
* order: 2,
|
|
29
|
+
* type: 'create',
|
|
30
|
+
* description: 'Create onboarding task',
|
|
31
|
+
* params: {
|
|
32
|
+
* type: 'Task',
|
|
33
|
+
* title: 'Onboard {{customer.name}}',
|
|
34
|
+
* assignee: 'customer_success_team',
|
|
35
|
+
* },
|
|
36
|
+
* },
|
|
37
|
+
* {
|
|
38
|
+
* order: 3,
|
|
39
|
+
* type: 'wait',
|
|
40
|
+
* description: 'Wait 24 hours',
|
|
41
|
+
* params: {
|
|
42
|
+
* duration: '24 hours',
|
|
43
|
+
* },
|
|
44
|
+
* },
|
|
45
|
+
* {
|
|
46
|
+
* order: 4,
|
|
47
|
+
* type: 'notify',
|
|
48
|
+
* description: 'Send setup reminder',
|
|
49
|
+
* params: {
|
|
50
|
+
* channel: 'email',
|
|
51
|
+
* message: 'Reminder to complete setup',
|
|
52
|
+
* },
|
|
53
|
+
* condition: 'customer.setupCompleted === false',
|
|
54
|
+
* },
|
|
55
|
+
* ],
|
|
56
|
+
* })
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function Workflow(definition: WorkflowDefinition): WorkflowDefinition;
|
|
60
|
+
/**
|
|
61
|
+
* Get actions in execution order
|
|
62
|
+
*/
|
|
63
|
+
export declare function getActionsInOrder(workflow: WorkflowDefinition): WorkflowAction[];
|
|
64
|
+
/**
|
|
65
|
+
* Get actions by type
|
|
66
|
+
*/
|
|
67
|
+
export declare function getActionsByType(workflow: WorkflowDefinition, type: WorkflowAction['type']): WorkflowAction[];
|
|
68
|
+
/**
|
|
69
|
+
* Get conditional actions
|
|
70
|
+
*/
|
|
71
|
+
export declare function getConditionalActions(workflow: WorkflowDefinition): WorkflowAction[];
|
|
72
|
+
/**
|
|
73
|
+
* Add action to workflow
|
|
74
|
+
*/
|
|
75
|
+
export declare function addAction(workflow: WorkflowDefinition, action: WorkflowAction): WorkflowDefinition;
|
|
76
|
+
/**
|
|
77
|
+
* Remove action from workflow
|
|
78
|
+
*/
|
|
79
|
+
export declare function removeAction(workflow: WorkflowDefinition, order: number): WorkflowDefinition;
|
|
80
|
+
/**
|
|
81
|
+
* Update action in workflow
|
|
82
|
+
*/
|
|
83
|
+
export declare function updateAction(workflow: WorkflowDefinition, order: number, updates: Partial<WorkflowAction>): WorkflowDefinition;
|
|
84
|
+
/**
|
|
85
|
+
* Check if trigger is event-based
|
|
86
|
+
*/
|
|
87
|
+
export declare function isEventTrigger(trigger: WorkflowTrigger): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Check if trigger is schedule-based
|
|
90
|
+
*/
|
|
91
|
+
export declare function isScheduleTrigger(trigger: WorkflowTrigger): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Check if trigger is webhook-based
|
|
94
|
+
*/
|
|
95
|
+
export declare function isWebhookTrigger(trigger: WorkflowTrigger): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Parse wait duration to milliseconds
|
|
98
|
+
*/
|
|
99
|
+
export declare function parseWaitDuration(duration: string): number;
|
|
100
|
+
/**
|
|
101
|
+
* Evaluate condition (simple implementation)
|
|
102
|
+
*/
|
|
103
|
+
export declare function evaluateCondition(condition: string, context: Record<string, unknown>): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Fill template with context values
|
|
106
|
+
*/
|
|
107
|
+
export declare function fillTemplate(template: string, context: Record<string, unknown>): string;
|
|
108
|
+
/**
|
|
109
|
+
* Validate workflow definition
|
|
110
|
+
*/
|
|
111
|
+
export declare function validateWorkflow(workflow: WorkflowDefinition): {
|
|
112
|
+
valid: boolean;
|
|
113
|
+
errors: string[];
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=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OAAO,CAElE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAiC1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAgB9F;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAKvF;AASD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,GAAG;IAC9D,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB,CA2CA"}
|
package/dist/workflow.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow definition (automation sequences)
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Define an automated workflow with triggers and actions
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const workflow = Workflow({
|
|
10
|
+
* name: 'New Customer Welcome',
|
|
11
|
+
* description: 'Automated welcome sequence for new customers',
|
|
12
|
+
* trigger: {
|
|
13
|
+
* type: 'event',
|
|
14
|
+
* event: 'Customer.created',
|
|
15
|
+
* },
|
|
16
|
+
* actions: [
|
|
17
|
+
* {
|
|
18
|
+
* order: 1,
|
|
19
|
+
* type: 'send',
|
|
20
|
+
* description: 'Send welcome email',
|
|
21
|
+
* params: {
|
|
22
|
+
* template: 'welcome_email',
|
|
23
|
+
* to: '{{customer.email}}',
|
|
24
|
+
* },
|
|
25
|
+
* },
|
|
26
|
+
* {
|
|
27
|
+
* order: 2,
|
|
28
|
+
* type: 'create',
|
|
29
|
+
* description: 'Create onboarding task',
|
|
30
|
+
* params: {
|
|
31
|
+
* type: 'Task',
|
|
32
|
+
* title: 'Onboard {{customer.name}}',
|
|
33
|
+
* assignee: 'customer_success_team',
|
|
34
|
+
* },
|
|
35
|
+
* },
|
|
36
|
+
* {
|
|
37
|
+
* order: 3,
|
|
38
|
+
* type: 'wait',
|
|
39
|
+
* description: 'Wait 24 hours',
|
|
40
|
+
* params: {
|
|
41
|
+
* duration: '24 hours',
|
|
42
|
+
* },
|
|
43
|
+
* },
|
|
44
|
+
* {
|
|
45
|
+
* order: 4,
|
|
46
|
+
* type: 'notify',
|
|
47
|
+
* description: 'Send setup reminder',
|
|
48
|
+
* params: {
|
|
49
|
+
* channel: 'email',
|
|
50
|
+
* message: 'Reminder to complete setup',
|
|
51
|
+
* },
|
|
52
|
+
* condition: 'customer.setupCompleted === false',
|
|
53
|
+
* },
|
|
54
|
+
* ],
|
|
55
|
+
* })
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function Workflow(definition) {
|
|
59
|
+
if (!definition.name) {
|
|
60
|
+
throw new Error('Workflow name is required');
|
|
61
|
+
}
|
|
62
|
+
if (!definition.trigger) {
|
|
63
|
+
throw new Error('Workflow trigger is required');
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
...definition,
|
|
67
|
+
actions: definition.actions || [],
|
|
68
|
+
metadata: definition.metadata || {},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get actions in execution order
|
|
73
|
+
*/
|
|
74
|
+
export function getActionsInOrder(workflow) {
|
|
75
|
+
return [...(workflow.actions || [])].sort((a, b) => a.order - b.order);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get actions by type
|
|
79
|
+
*/
|
|
80
|
+
export function getActionsByType(workflow, type) {
|
|
81
|
+
return workflow.actions?.filter((action) => action.type === type) || [];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get conditional actions
|
|
85
|
+
*/
|
|
86
|
+
export function getConditionalActions(workflow) {
|
|
87
|
+
return workflow.actions?.filter((action) => action.condition) || [];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Add action to workflow
|
|
91
|
+
*/
|
|
92
|
+
export function addAction(workflow, action) {
|
|
93
|
+
return {
|
|
94
|
+
...workflow,
|
|
95
|
+
actions: [...(workflow.actions || []), action],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Remove action from workflow
|
|
100
|
+
*/
|
|
101
|
+
export function removeAction(workflow, order) {
|
|
102
|
+
const actions = workflow.actions?.filter((a) => a.order !== order);
|
|
103
|
+
const result = { ...workflow };
|
|
104
|
+
if (actions !== undefined)
|
|
105
|
+
result.actions = actions;
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Update action in workflow
|
|
110
|
+
*/
|
|
111
|
+
export function updateAction(workflow, order, updates) {
|
|
112
|
+
const actions = workflow.actions?.map((action) => action.order === order ? { ...action, ...updates } : action);
|
|
113
|
+
const result = { ...workflow };
|
|
114
|
+
if (actions !== undefined)
|
|
115
|
+
result.actions = actions;
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check if trigger is event-based
|
|
120
|
+
*/
|
|
121
|
+
export function isEventTrigger(trigger) {
|
|
122
|
+
return trigger.type === 'event';
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Check if trigger is schedule-based
|
|
126
|
+
*/
|
|
127
|
+
export function isScheduleTrigger(trigger) {
|
|
128
|
+
return trigger.type === 'schedule';
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check if trigger is webhook-based
|
|
132
|
+
*/
|
|
133
|
+
export function isWebhookTrigger(trigger) {
|
|
134
|
+
return trigger.type === 'webhook';
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Parse wait duration to milliseconds
|
|
138
|
+
*/
|
|
139
|
+
export function parseWaitDuration(duration) {
|
|
140
|
+
const match = duration.match(/(\d+)\s*(ms|millisecond|milliseconds|s|second|seconds|m|minute|minutes|h|hour|hours|d|day|days)/);
|
|
141
|
+
if (!match)
|
|
142
|
+
return 0;
|
|
143
|
+
const value = parseInt(match[1] || '0', 10);
|
|
144
|
+
const unit = match[2];
|
|
145
|
+
switch (unit) {
|
|
146
|
+
case 'ms':
|
|
147
|
+
case 'millisecond':
|
|
148
|
+
case 'milliseconds':
|
|
149
|
+
return value;
|
|
150
|
+
case 's':
|
|
151
|
+
case 'second':
|
|
152
|
+
case 'seconds':
|
|
153
|
+
return value * 1000;
|
|
154
|
+
case 'm':
|
|
155
|
+
case 'minute':
|
|
156
|
+
case 'minutes':
|
|
157
|
+
return value * 60 * 1000;
|
|
158
|
+
case 'h':
|
|
159
|
+
case 'hour':
|
|
160
|
+
case 'hours':
|
|
161
|
+
return value * 60 * 60 * 1000;
|
|
162
|
+
case 'd':
|
|
163
|
+
case 'day':
|
|
164
|
+
case 'days':
|
|
165
|
+
return value * 24 * 60 * 60 * 1000;
|
|
166
|
+
default:
|
|
167
|
+
return 0;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Evaluate condition (simple implementation)
|
|
172
|
+
*/
|
|
173
|
+
export function evaluateCondition(condition, context) {
|
|
174
|
+
// This is a simplified implementation
|
|
175
|
+
// In production, use a proper expression evaluator
|
|
176
|
+
try {
|
|
177
|
+
// Replace variable references with actual values
|
|
178
|
+
let expression = condition;
|
|
179
|
+
for (const [key, value] of Object.entries(context)) {
|
|
180
|
+
const regex = new RegExp(`\\b${key}\\b`, 'g');
|
|
181
|
+
expression = expression.replace(regex, JSON.stringify(value));
|
|
182
|
+
}
|
|
183
|
+
// Evaluate the expression (unsafe in production - use a proper evaluator)
|
|
184
|
+
return Boolean(eval(expression));
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Fill template with context values
|
|
192
|
+
*/
|
|
193
|
+
export function fillTemplate(template, context) {
|
|
194
|
+
return template.replace(/\{\{([^}]+)\}\}/g, (_, path) => {
|
|
195
|
+
const value = getNestedValue(context, path.trim());
|
|
196
|
+
return String(value ?? '');
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get nested value from object by path
|
|
201
|
+
*/
|
|
202
|
+
function getNestedValue(obj, path) {
|
|
203
|
+
return path.split('.').reduce((acc, part) => acc?.[part], obj);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Validate workflow definition
|
|
207
|
+
*/
|
|
208
|
+
export function validateWorkflow(workflow) {
|
|
209
|
+
const errors = [];
|
|
210
|
+
if (!workflow.name) {
|
|
211
|
+
errors.push('Workflow name is required');
|
|
212
|
+
}
|
|
213
|
+
if (!workflow.trigger) {
|
|
214
|
+
errors.push('Workflow trigger is required');
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
if (workflow.trigger.type === 'event' && !workflow.trigger.event) {
|
|
218
|
+
errors.push('Event trigger must specify an event name');
|
|
219
|
+
}
|
|
220
|
+
if (workflow.trigger.type === 'schedule' && !workflow.trigger.schedule) {
|
|
221
|
+
errors.push('Schedule trigger must specify a schedule expression');
|
|
222
|
+
}
|
|
223
|
+
if (workflow.trigger.type === 'webhook' && !workflow.trigger.webhook) {
|
|
224
|
+
errors.push('Webhook trigger must specify a webhook URL');
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (workflow.actions) {
|
|
228
|
+
const orders = new Set();
|
|
229
|
+
for (const action of workflow.actions) {
|
|
230
|
+
if (!action.type) {
|
|
231
|
+
errors.push(`Action at order ${action.order} must have a type`);
|
|
232
|
+
}
|
|
233
|
+
if (orders.has(action.order)) {
|
|
234
|
+
errors.push(`Duplicate action order: ${action.order}`);
|
|
235
|
+
}
|
|
236
|
+
orders.add(action.order);
|
|
237
|
+
// Validate action-specific requirements
|
|
238
|
+
if (action.type === 'wait' && !action.params?.['duration']) {
|
|
239
|
+
errors.push(`Wait action at order ${action.order} must specify duration`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
valid: errors.length === 0,
|
|
245
|
+
errors,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,UAAU,QAAQ,CAAC,UAA8B;IACrD,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,OAAO;QACL,GAAG,UAAU;QACb,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,EAAE;QACjC,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,EAAE;KACpC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAA4B;IAC5D,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAA;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAA4B,EAC5B,IAA4B;IAE5B,OAAO,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI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M,CAAC,IAAI,CAAC,2BAA2B,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;YACxD,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAExB,wCAAwC;YACxC,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,wBAAwB,MAAM,CAAC,KAAK,wBAAwB,CAAC,CAAA;YAC3E,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM;KACP,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "business-as-code",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Primitives for expressing business logic and processes as code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./finance": {
|
|
14
|
+
"import": "./dist/finance/index.js",
|
|
15
|
+
"types": "./dist/finance/index.d.ts"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"scripts": {
|
|
@@ -20,9 +24,9 @@
|
|
|
20
24
|
"clean": "rm -rf dist"
|
|
21
25
|
},
|
|
22
26
|
"dependencies": {
|
|
23
|
-
"ai-database": "2.
|
|
24
|
-
"ai-functions": "2.
|
|
25
|
-
"digital-workers": "2.
|
|
27
|
+
"ai-database": "2.4.0",
|
|
28
|
+
"ai-functions": "2.4.0",
|
|
29
|
+
"digital-workers": "2.4.0",
|
|
26
30
|
"org.ai": "0.0.1"
|
|
27
31
|
},
|
|
28
32
|
"devDependencies": {},
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account — bank/treasury/wallet account abstraction across providers.
|
|
3
|
+
* Stripe Treasury, Mercury, Column, Increase, Privy non-custodial wallet, etc.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Currency, Money } from './types.js'
|
|
7
|
+
|
|
8
|
+
export interface Account {
|
|
9
|
+
$id: string
|
|
10
|
+
$type: 'Account'
|
|
11
|
+
/** Tenant the account belongs to (ThingRef shape). */
|
|
12
|
+
tenantRef?: string
|
|
13
|
+
purpose: string
|
|
14
|
+
currency: Currency
|
|
15
|
+
providerData: {
|
|
16
|
+
provider: string
|
|
17
|
+
externalId: string
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AccountSpec {
|
|
22
|
+
tenantRef?: string
|
|
23
|
+
purpose: string
|
|
24
|
+
currency: Currency
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TransferOpts {
|
|
28
|
+
fromAccountRef: string
|
|
29
|
+
toAccountRef: string
|
|
30
|
+
amount: Money
|
|
31
|
+
/** Idempotency key for at-most-once semantics. */
|
|
32
|
+
idempotencyKey?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface TransferResult {
|
|
36
|
+
$id: string
|
|
37
|
+
$type: 'Transfer'
|
|
38
|
+
fromAccountRef: string
|
|
39
|
+
toAccountRef: string
|
|
40
|
+
amount: Money
|
|
41
|
+
status: 'pending' | 'settled' | 'failed' | 'reversed'
|
|
42
|
+
/** ISO-8601 timestamp. */
|
|
43
|
+
createdAt: string
|
|
44
|
+
providerData: {
|
|
45
|
+
provider: string
|
|
46
|
+
externalId: string
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AuthorityBoundary — typed regulatory marker on a Service.
|
|
3
|
+
* The 12-tag catalog (per startup-builder SERVICES.md) lets a cascade
|
|
4
|
+
* declare the boundary it operates within; routing and HITL gates
|
|
5
|
+
* compose against the boundary.
|
|
6
|
+
*
|
|
7
|
+
* 10 regulated tags + 2 sentinels (none, self-only).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type AuthorityBoundaryRef =
|
|
11
|
+
| 'self-only' // sentinel: agent acts for itself; no externally-binding outputs
|
|
12
|
+
| 'tenant-only' // sentinel: outputs bind only the tenant; no external counterparties
|
|
13
|
+
| 'unlicensed-advisory' // general-knowledge advisory; no professional license claimed
|
|
14
|
+
| 'cpa-attest' // CPA-signed attestation required
|
|
15
|
+
| 'jd-bar-admitted' // attorney admitted to relevant bar
|
|
16
|
+
| 'md-licensed' // physician with current state license
|
|
17
|
+
| 'fiduciary-investment-advice' // RIA / fiduciary-grade investment recommendation
|
|
18
|
+
| 'broker-dealer' // broker-dealer scope (FINRA-registered context)
|
|
19
|
+
| 'insurance-licensed' // licensed insurance producer
|
|
20
|
+
| 'real-estate-licensed' // licensed real-estate broker / agent
|
|
21
|
+
| 'pe-stamp' // PE-stamped engineering output
|
|
22
|
+
| 'kyc-aml-required' // identity + AML screening before action
|
|
23
|
+
| (string & { __brand?: 'AuthorityBoundaryRef' })
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Catalog of canonical AuthorityBoundary tags with policy hints. Consumers
|
|
27
|
+
* reference by id; substrate enforces gating + HITL routing per tag.
|
|
28
|
+
*/
|
|
29
|
+
export const AuthorityBoundaries = {
|
|
30
|
+
'self-only': { regulated: false, requiresHumanSign: false, requiresKYC: false },
|
|
31
|
+
'tenant-only': { regulated: false, requiresHumanSign: false, requiresKYC: false },
|
|
32
|
+
'unlicensed-advisory': { regulated: false, requiresHumanSign: false, requiresKYC: false },
|
|
33
|
+
'cpa-attest': { regulated: true, requiresHumanSign: true, requiresKYC: true },
|
|
34
|
+
'jd-bar-admitted': { regulated: true, requiresHumanSign: true, requiresKYC: true },
|
|
35
|
+
'md-licensed': { regulated: true, requiresHumanSign: true, requiresKYC: true },
|
|
36
|
+
'fiduciary-investment-advice': { regulated: true, requiresHumanSign: true, requiresKYC: true },
|
|
37
|
+
'broker-dealer': { regulated: true, requiresHumanSign: true, requiresKYC: true },
|
|
38
|
+
'insurance-licensed': { regulated: true, requiresHumanSign: true, requiresKYC: true },
|
|
39
|
+
'real-estate-licensed': { regulated: true, requiresHumanSign: true, requiresKYC: true },
|
|
40
|
+
'pe-stamp': { regulated: true, requiresHumanSign: true, requiresKYC: false },
|
|
41
|
+
'kyc-aml-required': { regulated: true, requiresHumanSign: false, requiresKYC: true },
|
|
42
|
+
} as const
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Card — virtual card issued by a finance provider (Stripe Issuing, Brex, Lithic, etc.).
|
|
3
|
+
* Per-Worker / per-Function / per-Task lifecycle.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Money } from './types.js'
|
|
7
|
+
|
|
8
|
+
export interface Card {
|
|
9
|
+
$id: string
|
|
10
|
+
$type: 'Card'
|
|
11
|
+
scope: 'single-use' | 'recurring'
|
|
12
|
+
/** Worker the card is issued to (Person/Agent/Role); ThingRef shape. */
|
|
13
|
+
workerRef?: string
|
|
14
|
+
caps: {
|
|
15
|
+
perTransaction?: Money
|
|
16
|
+
daily?: Money
|
|
17
|
+
total?: Money
|
|
18
|
+
}
|
|
19
|
+
/** Allowed Merchant Category Codes. */
|
|
20
|
+
mccAllowed?: string[]
|
|
21
|
+
/** Velocity controls. */
|
|
22
|
+
velocity?: {
|
|
23
|
+
maxTxPerDay?: number
|
|
24
|
+
}
|
|
25
|
+
state: 'issued' | 'active' | 'locked' | 'disposed'
|
|
26
|
+
providerData: {
|
|
27
|
+
provider: string
|
|
28
|
+
externalId: string
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CardSpec {
|
|
33
|
+
scope: 'single-use' | 'recurring'
|
|
34
|
+
workerRef?: string
|
|
35
|
+
caps: Card['caps']
|
|
36
|
+
mccAllowed?: string[]
|
|
37
|
+
velocity?: Card['velocity']
|
|
38
|
+
}
|