services-as-software 0.1.0 → 2.0.1

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 (78) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +235 -225
  4. package/dist/client.d.ts +25 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +103 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/endpoint.d.ts +102 -0
  9. package/dist/endpoint.d.ts.map +1 -0
  10. package/dist/endpoint.js +96 -0
  11. package/dist/endpoint.js.map +1 -0
  12. package/dist/entities/billing.d.ts +60 -0
  13. package/dist/entities/billing.d.ts.map +1 -0
  14. package/dist/entities/billing.js +954 -0
  15. package/dist/entities/billing.js.map +1 -0
  16. package/dist/entities/customers.d.ts +45 -0
  17. package/dist/entities/customers.d.ts.map +1 -0
  18. package/dist/entities/customers.js +679 -0
  19. package/dist/entities/customers.js.map +1 -0
  20. package/dist/entities/delivery.d.ts +59 -0
  21. package/dist/entities/delivery.d.ts.map +1 -0
  22. package/dist/entities/delivery.js +890 -0
  23. package/dist/entities/delivery.js.map +1 -0
  24. package/dist/entities/index.d.ts +114 -0
  25. package/dist/entities/index.d.ts.map +1 -0
  26. package/dist/entities/index.js +89 -0
  27. package/dist/entities/index.js.map +1 -0
  28. package/dist/entities/operations.d.ts +59 -0
  29. package/dist/entities/operations.d.ts.map +1 -0
  30. package/dist/entities/operations.js +1010 -0
  31. package/dist/entities/operations.js.map +1 -0
  32. package/dist/entities/orchestration.d.ts +52 -0
  33. package/dist/entities/orchestration.d.ts.map +1 -0
  34. package/dist/entities/orchestration.js +883 -0
  35. package/dist/entities/orchestration.js.map +1 -0
  36. package/dist/entities/services.d.ts +50 -0
  37. package/dist/entities/services.d.ts.map +1 -0
  38. package/dist/entities/services.js +805 -0
  39. package/dist/entities/services.js.map +1 -0
  40. package/dist/helpers.d.ts +362 -0
  41. package/dist/helpers.d.ts.map +1 -0
  42. package/dist/helpers.js +400 -0
  43. package/dist/helpers.js.map +1 -0
  44. package/dist/index.d.ts +17 -215
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +18 -172
  47. package/dist/index.js.map +1 -0
  48. package/dist/provider.d.ts +85 -0
  49. package/dist/provider.d.ts.map +1 -0
  50. package/dist/provider.js +158 -0
  51. package/dist/provider.js.map +1 -0
  52. package/dist/service.d.ts +43 -0
  53. package/dist/service.d.ts.map +1 -0
  54. package/dist/service.js +206 -0
  55. package/dist/service.js.map +1 -0
  56. package/dist/types.d.ts +469 -0
  57. package/dist/types.d.ts.map +1 -0
  58. package/dist/types.js +5 -0
  59. package/dist/types.js.map +1 -0
  60. package/examples/client-usage.ts +82 -0
  61. package/examples/translation-service.ts +227 -0
  62. package/package.json +24 -38
  63. package/src/client.ts +132 -0
  64. package/src/endpoint.ts +144 -0
  65. package/src/entities/billing.ts +1037 -0
  66. package/src/entities/customers.ts +740 -0
  67. package/src/entities/delivery.ts +974 -0
  68. package/src/entities/index.ts +157 -0
  69. package/src/entities/operations.ts +1099 -0
  70. package/src/entities/orchestration.ts +956 -0
  71. package/src/entities/services.ts +872 -0
  72. package/src/helpers.ts +474 -0
  73. package/src/index.ts +97 -0
  74. package/src/provider.ts +183 -0
  75. package/src/service.test.ts +195 -0
  76. package/src/service.ts +266 -0
  77. package/src/types.ts +543 -0
  78. package/tsconfig.json +9 -0
@@ -0,0 +1,400 @@
1
+ /**
2
+ * Helper functions for common service operations
3
+ */
4
+ /**
5
+ * Ask a question (helper for creating ask endpoints)
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const askEndpoint = Endpoint({
10
+ * name: 'ask',
11
+ * handler: ask(async (question, context) => {
12
+ * // Your Q&A logic here
13
+ * return `Answer to: ${question}`
14
+ * }),
15
+ * })
16
+ * ```
17
+ */
18
+ export function ask(handler) {
19
+ return async (input, serviceContext) => {
20
+ return handler(input.question, input.context, serviceContext);
21
+ };
22
+ }
23
+ /**
24
+ * Deliver results (helper for creating deliver endpoints)
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const deliverEndpoint = Endpoint({
29
+ * name: 'deliver',
30
+ * handler: deliver(async (orderId, results) => {
31
+ * // Delivery logic here
32
+ * console.log(`Delivering order ${orderId}`)
33
+ * }),
34
+ * })
35
+ * ```
36
+ */
37
+ export function deliver(handler) {
38
+ return async (input, context) => {
39
+ return handler(input.orderId, input.results, context);
40
+ };
41
+ }
42
+ /**
43
+ * Execute a task (helper for creating do endpoints)
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const doEndpoint = Endpoint({
48
+ * name: 'do',
49
+ * handler: do(async (action, input) => {
50
+ * switch (action) {
51
+ * case 'process':
52
+ * return { status: 'processed' }
53
+ * default:
54
+ * throw new Error(`Unknown action: ${action}`)
55
+ * }
56
+ * }),
57
+ * })
58
+ * ```
59
+ */
60
+ export function do_(handler) {
61
+ return async (input, context) => {
62
+ return handler(input.action, input.input, context);
63
+ };
64
+ }
65
+ /**
66
+ * Generate content (helper for creating generate endpoints)
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const generateEndpoint = Endpoint({
71
+ * name: 'generate',
72
+ * handler: generate(async (prompt, options) => {
73
+ * // Generation logic here
74
+ * return { text: `Generated from: ${prompt}` }
75
+ * }),
76
+ * })
77
+ * ```
78
+ */
79
+ export function generate(handler) {
80
+ return async (input, context) => {
81
+ return handler(input.prompt, input.options, context);
82
+ };
83
+ }
84
+ /**
85
+ * Type checking/validation (helper for creating is endpoints)
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const isEndpoint = Endpoint({
90
+ * name: 'is',
91
+ * handler: is(async (value, type) => {
92
+ * // Validation logic here
93
+ * return typeof value === type
94
+ * }),
95
+ * })
96
+ * ```
97
+ */
98
+ export function is(handler) {
99
+ return async (input, context) => {
100
+ return handler(input.value, input.type, context);
101
+ };
102
+ }
103
+ /**
104
+ * Send notification (helper for creating notify endpoints)
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const notifyEndpoint = Endpoint({
109
+ * name: 'notify',
110
+ * handler: notify(async (notification) => {
111
+ * // Send notification via email, Slack, etc.
112
+ * console.log(`Sending notification: ${notification.subject}`)
113
+ * }),
114
+ * })
115
+ * ```
116
+ */
117
+ export function notify(handler) {
118
+ return async (input, context) => {
119
+ return handler(input, context);
120
+ };
121
+ }
122
+ /**
123
+ * Event handler (helper for creating event handlers)
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * service.on('order.created', on(async (order) => {
128
+ * console.log(`New order: ${order.id}`)
129
+ * }))
130
+ * ```
131
+ */
132
+ export function on(handler) {
133
+ return handler;
134
+ }
135
+ /**
136
+ * Place an order (helper for creating order endpoints)
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * const orderEndpoint = Endpoint({
141
+ * name: 'order',
142
+ * handler: order(async (product, quantity, context) => {
143
+ * const orderId = generateOrderId()
144
+ * return {
145
+ * id: orderId,
146
+ * customerId: context?.customerId || 'unknown',
147
+ * product,
148
+ * quantity,
149
+ * total: calculateTotal(product, quantity),
150
+ * currency: 'USD',
151
+ * status: 'pending',
152
+ * createdAt: new Date(),
153
+ * updatedAt: new Date(),
154
+ * }
155
+ * }),
156
+ * })
157
+ * ```
158
+ */
159
+ export function order(handler) {
160
+ return async (input, context) => {
161
+ return handler(input.product, input.quantity, context);
162
+ };
163
+ }
164
+ /**
165
+ * Queue processor (helper for queue handlers)
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * service.queue('process-orders', queue(async (job) => {
170
+ * console.log(`Processing job: ${job.id}`)
171
+ * }))
172
+ * ```
173
+ */
174
+ export function queue(handler) {
175
+ return handler;
176
+ }
177
+ /**
178
+ * Request a quote (helper for creating quote endpoints)
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * const quoteEndpoint = Endpoint({
183
+ * name: 'quote',
184
+ * handler: quote(async (product, quantity, context) => {
185
+ * const price = calculatePrice(product, quantity)
186
+ * return {
187
+ * id: generateQuoteId(),
188
+ * customerId: context?.customerId || 'unknown',
189
+ * product,
190
+ * quantity,
191
+ * price,
192
+ * currency: 'USD',
193
+ * expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30 days
194
+ * }
195
+ * }),
196
+ * })
197
+ * ```
198
+ */
199
+ export function quote(handler) {
200
+ return async (input, context) => {
201
+ return handler(input.product, input.quantity, context);
202
+ };
203
+ }
204
+ /**
205
+ * Subscribe to a plan (helper for creating subscribe endpoints)
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * const subscribeEndpoint = Endpoint({
210
+ * name: 'subscribe',
211
+ * handler: subscribe(async (planId, context) => {
212
+ * const plan = findPlan(planId)
213
+ * return {
214
+ * id: generateSubscriptionId(),
215
+ * customerId: context?.customerId || 'unknown',
216
+ * planId,
217
+ * status: 'active',
218
+ * currentPeriodStart: new Date(),
219
+ * currentPeriodEnd: getNextBillingDate(plan.pricing.interval),
220
+ * }
221
+ * }),
222
+ * })
223
+ * ```
224
+ */
225
+ export function subscribe(handler) {
226
+ return async (input, context) => {
227
+ return handler(input.planId, context);
228
+ };
229
+ }
230
+ /**
231
+ * Scheduled task (helper for every/scheduled tasks)
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * service.every('0 0 * * *', every(async () => {
236
+ * console.log('Running daily task')
237
+ * }))
238
+ * ```
239
+ */
240
+ export function every(handler) {
241
+ return handler;
242
+ }
243
+ /**
244
+ * Get entitlements (helper for creating entitlements endpoints)
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * const entitlementsEndpoint = Endpoint({
249
+ * name: 'entitlements',
250
+ * handler: entitlements(async (context) => {
251
+ * return context?.entitlements || []
252
+ * }),
253
+ * })
254
+ * ```
255
+ */
256
+ export function entitlements(handler) {
257
+ return async (_input, context) => {
258
+ return handler(context);
259
+ };
260
+ }
261
+ /**
262
+ * Get KPIs (helper for creating KPI endpoints)
263
+ *
264
+ * @example
265
+ * ```ts
266
+ * const kpisEndpoint = Endpoint({
267
+ * name: 'kpis',
268
+ * handler: kpis(async () => {
269
+ * return {
270
+ * 'revenue': 10000,
271
+ * 'customers': 150,
272
+ * 'satisfaction': 4.5,
273
+ * }
274
+ * }),
275
+ * })
276
+ * ```
277
+ */
278
+ export function kpis(handler) {
279
+ return async (_input, context) => {
280
+ return handler(context);
281
+ };
282
+ }
283
+ /**
284
+ * Get OKRs (helper for creating OKR endpoints)
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * const okrsEndpoint = Endpoint({
289
+ * name: 'okrs',
290
+ * handler: okrs(async () => {
291
+ * return [{
292
+ * id: 'okr-1',
293
+ * objective: 'Improve customer satisfaction',
294
+ * keyResults: [
295
+ * {
296
+ * description: 'Increase NPS score',
297
+ * measure: async () => 8.5,
298
+ * target: 9.0,
299
+ * unit: 'score',
300
+ * },
301
+ * ],
302
+ * }]
303
+ * }),
304
+ * })
305
+ * ```
306
+ */
307
+ export function okrs(handler) {
308
+ return async (_input, context) => {
309
+ return handler(context);
310
+ };
311
+ }
312
+ /**
313
+ * Create a subscription plan
314
+ *
315
+ * @example
316
+ * ```ts
317
+ * const plan = Plan({
318
+ * id: 'pro',
319
+ * name: 'Pro Plan',
320
+ * description: 'For professional users',
321
+ * pricing: {
322
+ * model: 'subscription',
323
+ * basePrice: 49.99,
324
+ * currency: 'USD',
325
+ * interval: 'monthly',
326
+ * },
327
+ * entitlements: ['api-access', 'advanced-features'],
328
+ * features: ['Unlimited API calls', '24/7 support', 'Custom integrations'],
329
+ * limits: {
330
+ * 'api-calls': 100000,
331
+ * 'storage': 1000000000, // 1GB in bytes
332
+ * },
333
+ * })
334
+ * ```
335
+ */
336
+ export function Plan(plan) {
337
+ return plan;
338
+ }
339
+ /**
340
+ * Create a KPI definition
341
+ *
342
+ * @example
343
+ * ```ts
344
+ * const kpi = KPI({
345
+ * id: 'monthly-revenue',
346
+ * name: 'Monthly Revenue',
347
+ * description: 'Total revenue for the current month',
348
+ * calculate: async () => {
349
+ * return await getMonthlyRevenue()
350
+ * },
351
+ * target: 100000,
352
+ * unit: 'USD',
353
+ * })
354
+ * ```
355
+ */
356
+ export function KPI(kpi) {
357
+ return kpi;
358
+ }
359
+ /**
360
+ * Create an OKR definition
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * const okr = OKR({
365
+ * id: 'q1-2024',
366
+ * objective: 'Grow user base by 50%',
367
+ * keyResults: [
368
+ * {
369
+ * description: 'Acquire 5000 new users',
370
+ * measure: async () => await getNewUserCount(),
371
+ * target: 5000,
372
+ * unit: 'users',
373
+ * },
374
+ * ],
375
+ * period: 'Q1 2024',
376
+ * owner: 'Growth Team',
377
+ * })
378
+ * ```
379
+ */
380
+ export function OKR(okr) {
381
+ return okr;
382
+ }
383
+ /**
384
+ * Create an entitlement definition
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * const entitlement = Entitlement({
389
+ * id: 'api-access',
390
+ * name: 'API Access',
391
+ * description: 'Access to the service API',
392
+ * resource: 'api',
393
+ * actions: ['read', 'write'],
394
+ * })
395
+ * ```
396
+ */
397
+ export function Entitlement(entitlement) {
398
+ return entitlement;
399
+ }
400
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,GAAG,CACjB,OAAkG;IAElG,OAAO,KAAK,EACV,KAA8C,EAC9C,cAA+B,EACd,EAAE;QACnB,OAAO,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,cAAc,CAAC,CAAA;IAC/D,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO,CACrB,OAAuF;IAEvF,OAAO,KAAK,EACV,KAA4C,EAC5C,OAAwB,EACT,EAAE;QACjB,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACvD,CAAC,CAAA;AACH,C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AAC,OAAO,CAAC,CAAA;IACzB,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,IAAI,CAAC,IAAsB;IACzC,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,GAAG,CAAC,GAAkB;IACpC,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,GAAG,CAAC,GAAkB;IACpC,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,WAAkC;IAC5D,OAAO,WAAW,CAAA;AACpB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,216 +1,18 @@
1
- import { Objective as Objective$1, KeyResult as KeyResult$1 } from 'business-as-code';
2
-
3
1
  /**
4
- * Pricing model types for services
5
- */
6
- type PricingModel = 'cost-based' | 'margin-based' | 'activity-based' | 'outcome-based';
7
- /**
8
- * Cost-based pricing configuration
9
- */
10
- interface CostBasedPricing {
11
- model: 'cost-based';
12
- costBase: number;
13
- fixedCosts?: number;
14
- variableCosts?: number;
15
- }
16
- /**
17
- * Margin-based pricing configuration
18
- */
19
- interface MarginBasedPricing {
20
- model: 'margin-based';
21
- costBase: number;
22
- marginPercentage: number;
23
- }
24
- /**
25
- * Activity-based pricing configuration
26
- */
27
- interface ActivityBasedPricing {
28
- model: 'activity-based';
29
- activities: {
30
- name: string;
31
- description?: string;
32
- rate: number;
33
- }[];
34
- }
35
- /**
36
- * Outcome-based pricing configuration
37
- */
38
- interface OutcomeBasedPricing {
39
- model: 'outcome-based';
40
- outcomes: {
41
- metric: string;
42
- description?: string;
43
- targetValue: number;
44
- price: number;
45
- unit?: string;
46
- }[];
47
- }
48
- /**
49
- * Union type for all pricing configurations
50
- */
51
- type ServicePricing = CostBasedPricing | MarginBasedPricing | ActivityBasedPricing | OutcomeBasedPricing;
52
- /**
53
- * Implementation types for services
54
- */
55
- type ImplementationType = 'function' | 'workflow' | 'agent';
56
- /**
57
- * Implementation details for a service
58
- */
59
- interface ImplementationDetails {
60
- type: ImplementationType;
61
- id: string;
62
- version?: string;
63
- configuration?: Record<string, any>;
64
- }
65
- /**
66
- * Service definition with business model aspects
67
- */
68
- interface ServiceDefinition {
69
- /**
70
- * Service name
71
- */
72
- name: string;
73
- /**
74
- * Service description
75
- */
76
- description?: string;
77
- /**
78
- * Service objective
79
- */
80
- objective: Objective$1;
81
- /**
82
- * Key results for measuring service success
83
- */
84
- keyResults: KeyResult$1[];
85
- /**
86
- * Service pricing model
87
- */
88
- pricing: ServicePricing;
89
- /**
90
- * Implementation details
91
- */
92
- implementation: ImplementationDetails;
93
- /**
94
- * Additional metadata
95
- */
96
- metadata?: Record<string, any>;
97
- }
98
- /**
99
- * Registered service with additional properties
100
- */
101
- interface RegisteredService extends ServiceDefinition {
102
- /**
103
- * Unique service identifier
104
- */
105
- id: string;
106
- /**
107
- * Service status
108
- */
109
- status: 'active' | 'inactive' | 'degraded';
110
- /**
111
- * Service endpoint URL
112
- */
113
- endpoint: string;
114
- /**
115
- * Creation timestamp
116
- */
117
- createdAt: string;
118
- /**
119
- * Last update timestamp
120
- */
121
- updatedAt: string;
122
- }
123
-
124
- interface Objective {
125
- description: string;
126
- keyResults: string[] | KeyResult[];
127
- }
128
- interface KeyResult {
129
- description: string;
130
- target?: number;
131
- currentValue?: number;
132
- unit?: string;
133
- dueDate?: Date;
134
- }
135
-
136
- /**
137
- * Calculate price for cost-based pricing model
138
- * @param pricing Cost-based pricing configuration
139
- * @param quantity Number of units
140
- * @returns Calculated price
141
- */
142
- declare function calculateCostBasedPrice(pricing: CostBasedPricing, quantity?: number): number;
143
- /**
144
- * Calculate price for margin-based pricing model
145
- * @param pricing Margin-based pricing configuration
146
- * @param quantity Number of units
147
- * @returns Calculated price
148
- */
149
- declare function calculateMarginBasedPrice(pricing: MarginBasedPricing, quantity?: number): number;
150
- /**
151
- * Calculate price for activity-based pricing model
152
- * @param pricing Activity-based pricing configuration
153
- * @param activities Record of activity names and their quantities
154
- * @returns Calculated price
155
- */
156
- declare function calculateActivityBasedPrice(pricing: ActivityBasedPricing, activities: Record<string, number>): number;
157
- /**
158
- * Calculate price for outcome-based pricing model
159
- * @param pricing Outcome-based pricing configuration
160
- * @param outcomes Record of metric names and their achieved values
161
- * @returns Calculated price
162
- */
163
- declare function calculateOutcomeBasedPrice(pricing: OutcomeBasedPricing, outcomes: Record<string, number>): number;
164
- /**
165
- * Calculate price based on the pricing model
166
- * @param pricing Service pricing configuration
167
- * @param params Additional parameters for price calculation
168
- * @returns Calculated price
169
- */
170
- declare function calculatePrice(pricing: ServicePricing, params?: {
171
- quantity?: number;
172
- activities?: Record<string, number>;
173
- outcomes?: Record<string, number>;
174
- }): number;
175
-
176
- /**
177
- * Create a service with objectives, key results, and pricing models
178
- * @param definition Service definition
179
- * @returns Service object with additional methods
180
- */
181
- declare function Service(definition: ServiceDefinition): {
182
- /**
183
- * Calculate the price for this service
184
- * @param params Parameters for price calculation
185
- * @returns Calculated price
186
- */
187
- calculatePrice(params?: Parameters<typeof calculatePrice>[1]): number;
188
- /**
189
- * Register the service with the service registry
190
- * @param options Optional configuration for service registration
191
- * @returns Promise resolving to the registered service
192
- */
193
- register(options?: {
194
- apiKey?: string;
195
- baseUrl?: string;
196
- }): Promise<RegisteredService>;
197
- /**
198
- * Track progress towards key results
199
- * @param results Record of key result updates
200
- */
201
- trackProgress(results: Record<string, number>): void;
202
- /**
203
- * Check if all key results have been achieved
204
- * @returns Whether all key results have been achieved
205
- */
206
- isObjectiveAchieved(): boolean;
207
- name: string;
208
- description?: string;
209
- objective: Objective;
210
- keyResults: KeyResult[];
211
- pricing: ServicePricing;
212
- implementation: ImplementationDetails;
213
- metadata?: Record<string, any>;
214
- };
215
-
216
- export { type ActivityBasedPricing, type CostBasedPricing, type ImplementationDetails, type ImplementationType, type MarginBasedPricing, type OutcomeBasedPricing, type PricingModel, type RegisteredService, Service, type ServiceDefinition, type ServicePricing, calculateActivityBasedPrice, calculateCostBasedPrice, calculateMarginBasedPrice, calculateOutcomeBasedPrice, calculatePrice };
2
+ * services-as-software - Primitives for building AI-powered services that operate as software
3
+ *
4
+ * Services are a superset of digital-workers with a payment/business overlay,
5
+ * capable of crossing company/business boundaries.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export * from './entities/index.js';
10
+ export { Service } from './service.js';
11
+ export { Endpoint, GET, POST, PUT, DELETE, PATCH } from './endpoint.js';
12
+ export { Client } from './client.js';
13
+ export { Provider, providers } from './provider.js';
14
+ export { ask, deliver, do_ as do, generate, is, notify, on, order, queue, quote, subscribe, every, entitlements, kpis, okrs, Plan, KPI, OKR, Entitlement, } from './helpers.js';
15
+ export type { Service as ServiceType, ServiceDefinition, ServiceClient, ServiceContext, ServiceStatus, EndpointDefinition, PricingModel, PricingConfig, PricingTier, BillingInterval, Currency, Order, OrderStatus, Quote, Subscription, SubscriptionStatus, SubscriptionPlan, Notification, EventHandler, ScheduledTask, EntitlementDefinition, KPIDefinition, OKRDefinition, KeyResult, UsageTracker, UsageEvent, Usage, ClientConfig, Provider as ProviderType, JSONSchema, } from './types.js';
16
+ export type { EndpointConfig } from './endpoint.js';
17
+ export type { ProviderConfig } from './provider.js';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,qBAAqB,CAAA;AAGnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAGnD,OAAO,EACL,GAAG,EACH,OAAO,EACP,GAAG,IAAI,EAAE,EACT,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,GAAG,EACH,WAAW,GACZ,MAAM,cAAc,CAAA;AAGrB,YAAY,EAEV,OAAO,IAAI,WAAW,EACtB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,aAAa,EAGb,kBAAkB,EAGlB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,eAAe,EACf,QAAQ,EAGR,KAAK,EACL,WAAW,EACX,KAAK,EACL,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAGhB,YAAY,EAGZ,YAAY,EACZ,aAAa,EAGb,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,SAAS,EAGT,YAAY,EACZ,UAAU,EACV,KAAK,EAGL,YAAY,EACZ,QAAQ,IAAI,YAAY,EAGxB,UAAU,GACX,MAAM,YAAY,CAAA;AAGnB,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA"}