@contractspec/lib.metering 0.0.0-canary-20260113162409

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1032 @@
1
+ import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
2
+ import { defineCommand, defineQuery } from "@contractspec/lib.contracts";
3
+
4
+ //#region src/contracts/index.ts
5
+ const OWNERS = ["platform.metering"];
6
+ const MetricDefinitionModel = defineSchemaModel({
7
+ name: "MetricDefinition",
8
+ description: "Represents a metric definition",
9
+ fields: {
10
+ id: {
11
+ type: ScalarTypeEnum.String_unsecure(),
12
+ isOptional: false
13
+ },
14
+ key: {
15
+ type: ScalarTypeEnum.String_unsecure(),
16
+ isOptional: false
17
+ },
18
+ name: {
19
+ type: ScalarTypeEnum.String_unsecure(),
20
+ isOptional: false
21
+ },
22
+ description: {
23
+ type: ScalarTypeEnum.String_unsecure(),
24
+ isOptional: true
25
+ },
26
+ unit: {
27
+ type: ScalarTypeEnum.String_unsecure(),
28
+ isOptional: false
29
+ },
30
+ aggregationType: {
31
+ type: ScalarTypeEnum.String_unsecure(),
32
+ isOptional: false
33
+ },
34
+ resetPeriod: {
35
+ type: ScalarTypeEnum.String_unsecure(),
36
+ isOptional: false
37
+ },
38
+ category: {
39
+ type: ScalarTypeEnum.String_unsecure(),
40
+ isOptional: true
41
+ },
42
+ isActive: {
43
+ type: ScalarTypeEnum.Boolean(),
44
+ isOptional: false
45
+ },
46
+ orgId: {
47
+ type: ScalarTypeEnum.String_unsecure(),
48
+ isOptional: true
49
+ },
50
+ createdAt: {
51
+ type: ScalarTypeEnum.DateTime(),
52
+ isOptional: false
53
+ },
54
+ updatedAt: {
55
+ type: ScalarTypeEnum.DateTime(),
56
+ isOptional: false
57
+ }
58
+ }
59
+ });
60
+ const UsageRecordModel = defineSchemaModel({
61
+ name: "UsageRecord",
62
+ description: "Represents a usage record",
63
+ fields: {
64
+ id: {
65
+ type: ScalarTypeEnum.String_unsecure(),
66
+ isOptional: false
67
+ },
68
+ metricKey: {
69
+ type: ScalarTypeEnum.String_unsecure(),
70
+ isOptional: false
71
+ },
72
+ subjectType: {
73
+ type: ScalarTypeEnum.String_unsecure(),
74
+ isOptional: false
75
+ },
76
+ subjectId: {
77
+ type: ScalarTypeEnum.String_unsecure(),
78
+ isOptional: false
79
+ },
80
+ quantity: {
81
+ type: ScalarTypeEnum.Float_unsecure(),
82
+ isOptional: false
83
+ },
84
+ source: {
85
+ type: ScalarTypeEnum.String_unsecure(),
86
+ isOptional: true
87
+ },
88
+ resourceId: {
89
+ type: ScalarTypeEnum.String_unsecure(),
90
+ isOptional: true
91
+ },
92
+ resourceType: {
93
+ type: ScalarTypeEnum.String_unsecure(),
94
+ isOptional: true
95
+ },
96
+ metadata: {
97
+ type: ScalarTypeEnum.JSON(),
98
+ isOptional: true
99
+ },
100
+ timestamp: {
101
+ type: ScalarTypeEnum.DateTime(),
102
+ isOptional: false
103
+ },
104
+ createdAt: {
105
+ type: ScalarTypeEnum.DateTime(),
106
+ isOptional: false
107
+ }
108
+ }
109
+ });
110
+ const UsageSummaryModel = defineSchemaModel({
111
+ name: "UsageSummary",
112
+ description: "Represents aggregated usage",
113
+ fields: {
114
+ id: {
115
+ type: ScalarTypeEnum.String_unsecure(),
116
+ isOptional: false
117
+ },
118
+ metricKey: {
119
+ type: ScalarTypeEnum.String_unsecure(),
120
+ isOptional: false
121
+ },
122
+ subjectType: {
123
+ type: ScalarTypeEnum.String_unsecure(),
124
+ isOptional: false
125
+ },
126
+ subjectId: {
127
+ type: ScalarTypeEnum.String_unsecure(),
128
+ isOptional: false
129
+ },
130
+ periodType: {
131
+ type: ScalarTypeEnum.String_unsecure(),
132
+ isOptional: false
133
+ },
134
+ periodStart: {
135
+ type: ScalarTypeEnum.DateTime(),
136
+ isOptional: false
137
+ },
138
+ periodEnd: {
139
+ type: ScalarTypeEnum.DateTime(),
140
+ isOptional: false
141
+ },
142
+ totalQuantity: {
143
+ type: ScalarTypeEnum.Float_unsecure(),
144
+ isOptional: false
145
+ },
146
+ recordCount: {
147
+ type: ScalarTypeEnum.Int_unsecure(),
148
+ isOptional: false
149
+ },
150
+ minQuantity: {
151
+ type: ScalarTypeEnum.Float_unsecure(),
152
+ isOptional: true
153
+ },
154
+ maxQuantity: {
155
+ type: ScalarTypeEnum.Float_unsecure(),
156
+ isOptional: true
157
+ },
158
+ avgQuantity: {
159
+ type: ScalarTypeEnum.Float_unsecure(),
160
+ isOptional: true
161
+ }
162
+ }
163
+ });
164
+ const UsageThresholdModel = defineSchemaModel({
165
+ name: "UsageThreshold",
166
+ description: "Represents a usage threshold",
167
+ fields: {
168
+ id: {
169
+ type: ScalarTypeEnum.String_unsecure(),
170
+ isOptional: false
171
+ },
172
+ metricKey: {
173
+ type: ScalarTypeEnum.String_unsecure(),
174
+ isOptional: false
175
+ },
176
+ subjectType: {
177
+ type: ScalarTypeEnum.String_unsecure(),
178
+ isOptional: true
179
+ },
180
+ subjectId: {
181
+ type: ScalarTypeEnum.String_unsecure(),
182
+ isOptional: true
183
+ },
184
+ name: {
185
+ type: ScalarTypeEnum.String_unsecure(),
186
+ isOptional: false
187
+ },
188
+ threshold: {
189
+ type: ScalarTypeEnum.Float_unsecure(),
190
+ isOptional: false
191
+ },
192
+ warnThreshold: {
193
+ type: ScalarTypeEnum.Float_unsecure(),
194
+ isOptional: true
195
+ },
196
+ periodType: {
197
+ type: ScalarTypeEnum.String_unsecure(),
198
+ isOptional: false
199
+ },
200
+ action: {
201
+ type: ScalarTypeEnum.String_unsecure(),
202
+ isOptional: false
203
+ },
204
+ currentValue: {
205
+ type: ScalarTypeEnum.Float_unsecure(),
206
+ isOptional: false
207
+ },
208
+ isActive: {
209
+ type: ScalarTypeEnum.Boolean(),
210
+ isOptional: false
211
+ },
212
+ createdAt: {
213
+ type: ScalarTypeEnum.DateTime(),
214
+ isOptional: false
215
+ }
216
+ }
217
+ });
218
+ const DefineMetricInput = defineSchemaModel({
219
+ name: "DefineMetricInput",
220
+ description: "Input for defining a metric",
221
+ fields: {
222
+ key: {
223
+ type: ScalarTypeEnum.String_unsecure(),
224
+ isOptional: false
225
+ },
226
+ name: {
227
+ type: ScalarTypeEnum.String_unsecure(),
228
+ isOptional: false
229
+ },
230
+ description: {
231
+ type: ScalarTypeEnum.String_unsecure(),
232
+ isOptional: true
233
+ },
234
+ unit: {
235
+ type: ScalarTypeEnum.String_unsecure(),
236
+ isOptional: false
237
+ },
238
+ aggregationType: {
239
+ type: ScalarTypeEnum.String_unsecure(),
240
+ isOptional: true
241
+ },
242
+ resetPeriod: {
243
+ type: ScalarTypeEnum.String_unsecure(),
244
+ isOptional: true
245
+ },
246
+ category: {
247
+ type: ScalarTypeEnum.String_unsecure(),
248
+ isOptional: true
249
+ },
250
+ orgId: {
251
+ type: ScalarTypeEnum.String_unsecure(),
252
+ isOptional: true
253
+ },
254
+ metadata: {
255
+ type: ScalarTypeEnum.JSON(),
256
+ isOptional: true
257
+ }
258
+ }
259
+ });
260
+ const UpdateMetricInput = defineSchemaModel({
261
+ name: "UpdateMetricInput",
262
+ description: "Input for updating a metric",
263
+ fields: {
264
+ metricId: {
265
+ type: ScalarTypeEnum.String_unsecure(),
266
+ isOptional: false
267
+ },
268
+ name: {
269
+ type: ScalarTypeEnum.String_unsecure(),
270
+ isOptional: true
271
+ },
272
+ description: {
273
+ type: ScalarTypeEnum.String_unsecure(),
274
+ isOptional: true
275
+ },
276
+ category: {
277
+ type: ScalarTypeEnum.String_unsecure(),
278
+ isOptional: true
279
+ },
280
+ isActive: {
281
+ type: ScalarTypeEnum.Boolean(),
282
+ isOptional: true
283
+ },
284
+ metadata: {
285
+ type: ScalarTypeEnum.JSON(),
286
+ isOptional: true
287
+ }
288
+ }
289
+ });
290
+ const DeleteMetricInput = defineSchemaModel({
291
+ name: "DeleteMetricInput",
292
+ description: "Input for deleting a metric",
293
+ fields: { metricId: {
294
+ type: ScalarTypeEnum.String_unsecure(),
295
+ isOptional: false
296
+ } }
297
+ });
298
+ const GetMetricInput = defineSchemaModel({
299
+ name: "GetMetricInput",
300
+ description: "Input for getting a metric",
301
+ fields: {
302
+ key: {
303
+ type: ScalarTypeEnum.String_unsecure(),
304
+ isOptional: false
305
+ },
306
+ orgId: {
307
+ type: ScalarTypeEnum.String_unsecure(),
308
+ isOptional: true
309
+ }
310
+ }
311
+ });
312
+ const ListMetricsInput = defineSchemaModel({
313
+ name: "ListMetricsInput",
314
+ description: "Input for listing metrics",
315
+ fields: {
316
+ orgId: {
317
+ type: ScalarTypeEnum.String_unsecure(),
318
+ isOptional: true
319
+ },
320
+ category: {
321
+ type: ScalarTypeEnum.String_unsecure(),
322
+ isOptional: true
323
+ },
324
+ isActive: {
325
+ type: ScalarTypeEnum.Boolean(),
326
+ isOptional: true
327
+ },
328
+ limit: {
329
+ type: ScalarTypeEnum.Int_unsecure(),
330
+ isOptional: true
331
+ },
332
+ offset: {
333
+ type: ScalarTypeEnum.Int_unsecure(),
334
+ isOptional: true
335
+ }
336
+ }
337
+ });
338
+ const ListMetricsOutput = defineSchemaModel({
339
+ name: "ListMetricsOutput",
340
+ description: "Output for listing metrics",
341
+ fields: {
342
+ metrics: {
343
+ type: MetricDefinitionModel,
344
+ isArray: true,
345
+ isOptional: false
346
+ },
347
+ total: {
348
+ type: ScalarTypeEnum.Int_unsecure(),
349
+ isOptional: false
350
+ }
351
+ }
352
+ });
353
+ const RecordUsageInput = defineSchemaModel({
354
+ name: "RecordUsageInput",
355
+ description: "Input for recording usage",
356
+ fields: {
357
+ metricKey: {
358
+ type: ScalarTypeEnum.String_unsecure(),
359
+ isOptional: false
360
+ },
361
+ subjectType: {
362
+ type: ScalarTypeEnum.String_unsecure(),
363
+ isOptional: false
364
+ },
365
+ subjectId: {
366
+ type: ScalarTypeEnum.String_unsecure(),
367
+ isOptional: false
368
+ },
369
+ quantity: {
370
+ type: ScalarTypeEnum.Float_unsecure(),
371
+ isOptional: false
372
+ },
373
+ timestamp: {
374
+ type: ScalarTypeEnum.DateTime(),
375
+ isOptional: true
376
+ },
377
+ source: {
378
+ type: ScalarTypeEnum.String_unsecure(),
379
+ isOptional: true
380
+ },
381
+ resourceId: {
382
+ type: ScalarTypeEnum.String_unsecure(),
383
+ isOptional: true
384
+ },
385
+ resourceType: {
386
+ type: ScalarTypeEnum.String_unsecure(),
387
+ isOptional: true
388
+ },
389
+ metadata: {
390
+ type: ScalarTypeEnum.JSON(),
391
+ isOptional: true
392
+ },
393
+ idempotencyKey: {
394
+ type: ScalarTypeEnum.String_unsecure(),
395
+ isOptional: true
396
+ }
397
+ }
398
+ });
399
+ const RecordBatchUsageInput = defineSchemaModel({
400
+ name: "RecordBatchUsageInput",
401
+ description: "Input for recording batch usage",
402
+ fields: { records: {
403
+ type: RecordUsageInput,
404
+ isArray: true,
405
+ isOptional: false
406
+ } }
407
+ });
408
+ const RecordBatchUsageOutput = defineSchemaModel({
409
+ name: "RecordBatchUsageOutput",
410
+ description: "Output for recording batch usage",
411
+ fields: {
412
+ recordedCount: {
413
+ type: ScalarTypeEnum.Int_unsecure(),
414
+ isOptional: false
415
+ },
416
+ skippedCount: {
417
+ type: ScalarTypeEnum.Int_unsecure(),
418
+ isOptional: false
419
+ },
420
+ recordIds: {
421
+ type: ScalarTypeEnum.JSON(),
422
+ isOptional: false
423
+ }
424
+ }
425
+ });
426
+ const GetUsageInput = defineSchemaModel({
427
+ name: "GetUsageInput",
428
+ description: "Input for getting usage",
429
+ fields: {
430
+ metricKey: {
431
+ type: ScalarTypeEnum.String_unsecure(),
432
+ isOptional: false
433
+ },
434
+ subjectType: {
435
+ type: ScalarTypeEnum.String_unsecure(),
436
+ isOptional: false
437
+ },
438
+ subjectId: {
439
+ type: ScalarTypeEnum.String_unsecure(),
440
+ isOptional: false
441
+ },
442
+ startDate: {
443
+ type: ScalarTypeEnum.DateTime(),
444
+ isOptional: false
445
+ },
446
+ endDate: {
447
+ type: ScalarTypeEnum.DateTime(),
448
+ isOptional: false
449
+ },
450
+ limit: {
451
+ type: ScalarTypeEnum.Int_unsecure(),
452
+ isOptional: true
453
+ },
454
+ offset: {
455
+ type: ScalarTypeEnum.Int_unsecure(),
456
+ isOptional: true
457
+ }
458
+ }
459
+ });
460
+ const GetUsageOutput = defineSchemaModel({
461
+ name: "GetUsageOutput",
462
+ description: "Output for getting usage",
463
+ fields: {
464
+ records: {
465
+ type: UsageRecordModel,
466
+ isArray: true,
467
+ isOptional: false
468
+ },
469
+ total: {
470
+ type: ScalarTypeEnum.Int_unsecure(),
471
+ isOptional: false
472
+ },
473
+ totalQuantity: {
474
+ type: ScalarTypeEnum.Float_unsecure(),
475
+ isOptional: false
476
+ }
477
+ }
478
+ });
479
+ const GetUsageSummaryInput = defineSchemaModel({
480
+ name: "GetUsageSummaryInput",
481
+ description: "Input for getting usage summary",
482
+ fields: {
483
+ metricKey: {
484
+ type: ScalarTypeEnum.String_unsecure(),
485
+ isOptional: false
486
+ },
487
+ subjectType: {
488
+ type: ScalarTypeEnum.String_unsecure(),
489
+ isOptional: false
490
+ },
491
+ subjectId: {
492
+ type: ScalarTypeEnum.String_unsecure(),
493
+ isOptional: false
494
+ },
495
+ periodType: {
496
+ type: ScalarTypeEnum.String_unsecure(),
497
+ isOptional: false
498
+ },
499
+ startDate: {
500
+ type: ScalarTypeEnum.DateTime(),
501
+ isOptional: false
502
+ },
503
+ endDate: {
504
+ type: ScalarTypeEnum.DateTime(),
505
+ isOptional: true
506
+ }
507
+ }
508
+ });
509
+ const GetUsageSummaryOutput = defineSchemaModel({
510
+ name: "GetUsageSummaryOutput",
511
+ description: "Output for getting usage summary",
512
+ fields: {
513
+ summaries: {
514
+ type: UsageSummaryModel,
515
+ isArray: true,
516
+ isOptional: false
517
+ },
518
+ total: {
519
+ type: ScalarTypeEnum.Int_unsecure(),
520
+ isOptional: false
521
+ }
522
+ }
523
+ });
524
+ const CreateThresholdInput = defineSchemaModel({
525
+ name: "CreateThresholdInput",
526
+ description: "Input for creating a threshold",
527
+ fields: {
528
+ metricKey: {
529
+ type: ScalarTypeEnum.String_unsecure(),
530
+ isOptional: false
531
+ },
532
+ subjectType: {
533
+ type: ScalarTypeEnum.String_unsecure(),
534
+ isOptional: true
535
+ },
536
+ subjectId: {
537
+ type: ScalarTypeEnum.String_unsecure(),
538
+ isOptional: true
539
+ },
540
+ name: {
541
+ type: ScalarTypeEnum.String_unsecure(),
542
+ isOptional: false
543
+ },
544
+ threshold: {
545
+ type: ScalarTypeEnum.Float_unsecure(),
546
+ isOptional: false
547
+ },
548
+ warnThreshold: {
549
+ type: ScalarTypeEnum.Float_unsecure(),
550
+ isOptional: true
551
+ },
552
+ periodType: {
553
+ type: ScalarTypeEnum.String_unsecure(),
554
+ isOptional: true
555
+ },
556
+ action: {
557
+ type: ScalarTypeEnum.String_unsecure(),
558
+ isOptional: true
559
+ },
560
+ notifyEmails: {
561
+ type: ScalarTypeEnum.JSON(),
562
+ isOptional: true
563
+ },
564
+ notifyWebhook: {
565
+ type: ScalarTypeEnum.String_unsecure(),
566
+ isOptional: true
567
+ }
568
+ }
569
+ });
570
+ const UpdateThresholdInput = defineSchemaModel({
571
+ name: "UpdateThresholdInput",
572
+ description: "Input for updating a threshold",
573
+ fields: {
574
+ thresholdId: {
575
+ type: ScalarTypeEnum.String_unsecure(),
576
+ isOptional: false
577
+ },
578
+ name: {
579
+ type: ScalarTypeEnum.String_unsecure(),
580
+ isOptional: true
581
+ },
582
+ threshold: {
583
+ type: ScalarTypeEnum.Float_unsecure(),
584
+ isOptional: true
585
+ },
586
+ warnThreshold: {
587
+ type: ScalarTypeEnum.Float_unsecure(),
588
+ isOptional: true
589
+ },
590
+ action: {
591
+ type: ScalarTypeEnum.String_unsecure(),
592
+ isOptional: true
593
+ },
594
+ notifyEmails: {
595
+ type: ScalarTypeEnum.JSON(),
596
+ isOptional: true
597
+ },
598
+ notifyWebhook: {
599
+ type: ScalarTypeEnum.String_unsecure(),
600
+ isOptional: true
601
+ },
602
+ isActive: {
603
+ type: ScalarTypeEnum.Boolean(),
604
+ isOptional: true
605
+ }
606
+ }
607
+ });
608
+ const DeleteThresholdInput = defineSchemaModel({
609
+ name: "DeleteThresholdInput",
610
+ description: "Input for deleting a threshold",
611
+ fields: { thresholdId: {
612
+ type: ScalarTypeEnum.String_unsecure(),
613
+ isOptional: false
614
+ } }
615
+ });
616
+ const ListThresholdsInput = defineSchemaModel({
617
+ name: "ListThresholdsInput",
618
+ description: "Input for listing thresholds",
619
+ fields: {
620
+ metricKey: {
621
+ type: ScalarTypeEnum.String_unsecure(),
622
+ isOptional: true
623
+ },
624
+ subjectType: {
625
+ type: ScalarTypeEnum.String_unsecure(),
626
+ isOptional: true
627
+ },
628
+ subjectId: {
629
+ type: ScalarTypeEnum.String_unsecure(),
630
+ isOptional: true
631
+ },
632
+ isActive: {
633
+ type: ScalarTypeEnum.Boolean(),
634
+ isOptional: true
635
+ }
636
+ }
637
+ });
638
+ const ListThresholdsOutput = defineSchemaModel({
639
+ name: "ListThresholdsOutput",
640
+ description: "Output for listing thresholds",
641
+ fields: {
642
+ thresholds: {
643
+ type: UsageThresholdModel,
644
+ isArray: true,
645
+ isOptional: false
646
+ },
647
+ total: {
648
+ type: ScalarTypeEnum.Int_unsecure(),
649
+ isOptional: false
650
+ }
651
+ }
652
+ });
653
+ const SuccessOutput = defineSchemaModel({
654
+ name: "SuccessOutput",
655
+ description: "Generic success output",
656
+ fields: { success: {
657
+ type: ScalarTypeEnum.Boolean(),
658
+ isOptional: false
659
+ } }
660
+ });
661
+ /**
662
+ * Define a metric.
663
+ */
664
+ const DefineMetricContract = defineCommand({
665
+ meta: {
666
+ key: "metric.define",
667
+ version: "1.0.0",
668
+ stability: "stable",
669
+ owners: [...OWNERS],
670
+ tags: [
671
+ "metering",
672
+ "metric",
673
+ "define"
674
+ ],
675
+ description: "Define a new usage metric.",
676
+ goal: "Create a new metric for tracking usage.",
677
+ context: "Called when setting up metering."
678
+ },
679
+ io: {
680
+ input: DefineMetricInput,
681
+ output: MetricDefinitionModel,
682
+ errors: { METRIC_KEY_EXISTS: {
683
+ description: "Metric key already exists",
684
+ http: 409,
685
+ gqlCode: "METRIC_KEY_EXISTS",
686
+ when: "A metric with this key already exists"
687
+ } }
688
+ },
689
+ policy: { auth: "admin" }
690
+ });
691
+ /**
692
+ * Update a metric.
693
+ */
694
+ const UpdateMetricContract = defineCommand({
695
+ meta: {
696
+ key: "metric.update",
697
+ version: "1.0.0",
698
+ stability: "stable",
699
+ owners: [...OWNERS],
700
+ tags: [
701
+ "metering",
702
+ "metric",
703
+ "update"
704
+ ],
705
+ description: "Update a metric definition.",
706
+ goal: "Modify metric configuration.",
707
+ context: "Called when updating metric settings."
708
+ },
709
+ io: {
710
+ input: UpdateMetricInput,
711
+ output: MetricDefinitionModel,
712
+ errors: { METRIC_NOT_FOUND: {
713
+ description: "Metric does not exist",
714
+ http: 404,
715
+ gqlCode: "METRIC_NOT_FOUND",
716
+ when: "Metric ID is invalid"
717
+ } }
718
+ },
719
+ policy: { auth: "admin" }
720
+ });
721
+ /**
722
+ * Delete a metric.
723
+ */
724
+ const DeleteMetricContract = defineCommand({
725
+ meta: {
726
+ key: "metric.delete",
727
+ version: "1.0.0",
728
+ stability: "stable",
729
+ owners: [...OWNERS],
730
+ tags: [
731
+ "metering",
732
+ "metric",
733
+ "delete"
734
+ ],
735
+ description: "Delete a metric definition.",
736
+ goal: "Remove a metric and its data.",
737
+ context: "Called when removing a metric."
738
+ },
739
+ io: {
740
+ input: DeleteMetricInput,
741
+ output: SuccessOutput,
742
+ errors: { METRIC_NOT_FOUND: {
743
+ description: "Metric does not exist",
744
+ http: 404,
745
+ gqlCode: "METRIC_NOT_FOUND",
746
+ when: "Metric ID is invalid"
747
+ } }
748
+ },
749
+ policy: { auth: "admin" }
750
+ });
751
+ /**
752
+ * Get a metric by key.
753
+ */
754
+ const GetMetricContract = defineQuery({
755
+ meta: {
756
+ key: "metric.get",
757
+ version: "1.0.0",
758
+ stability: "stable",
759
+ owners: [...OWNERS],
760
+ tags: [
761
+ "metering",
762
+ "metric",
763
+ "get"
764
+ ],
765
+ description: "Get a metric by key.",
766
+ goal: "Retrieve metric definition.",
767
+ context: "Called to inspect metric details."
768
+ },
769
+ io: {
770
+ input: GetMetricInput,
771
+ output: MetricDefinitionModel,
772
+ errors: { METRIC_NOT_FOUND: {
773
+ description: "Metric does not exist",
774
+ http: 404,
775
+ gqlCode: "METRIC_NOT_FOUND",
776
+ when: "Metric key is invalid"
777
+ } }
778
+ },
779
+ policy: { auth: "user" }
780
+ });
781
+ /**
782
+ * List metrics.
783
+ */
784
+ const ListMetricsContract = defineQuery({
785
+ meta: {
786
+ key: "metric.list",
787
+ version: "1.0.0",
788
+ stability: "stable",
789
+ owners: [...OWNERS],
790
+ tags: [
791
+ "metering",
792
+ "metric",
793
+ "list"
794
+ ],
795
+ description: "List all metrics.",
796
+ goal: "View configured metrics.",
797
+ context: "Called to browse metrics."
798
+ },
799
+ io: {
800
+ input: ListMetricsInput,
801
+ output: ListMetricsOutput
802
+ },
803
+ policy: { auth: "user" }
804
+ });
805
+ /**
806
+ * Record usage.
807
+ */
808
+ const RecordUsageContract = defineCommand({
809
+ meta: {
810
+ key: "usage.record",
811
+ version: "1.0.0",
812
+ stability: "stable",
813
+ owners: [...OWNERS],
814
+ tags: [
815
+ "metering",
816
+ "usage",
817
+ "record"
818
+ ],
819
+ description: "Record a usage event.",
820
+ goal: "Track usage for billing and monitoring.",
821
+ context: "Called when usage occurs."
822
+ },
823
+ io: {
824
+ input: RecordUsageInput,
825
+ output: UsageRecordModel,
826
+ errors: {
827
+ METRIC_NOT_FOUND: {
828
+ description: "Metric does not exist",
829
+ http: 404,
830
+ gqlCode: "METRIC_NOT_FOUND",
831
+ when: "Metric key is invalid"
832
+ },
833
+ DUPLICATE_RECORD: {
834
+ description: "Record already exists",
835
+ http: 409,
836
+ gqlCode: "DUPLICATE_RECORD",
837
+ when: "Idempotency key already used"
838
+ }
839
+ }
840
+ },
841
+ policy: { auth: "admin" }
842
+ });
843
+ /**
844
+ * Record batch usage.
845
+ */
846
+ const RecordBatchUsageContract = defineCommand({
847
+ meta: {
848
+ key: "usage.recordBatch",
849
+ version: "1.0.0",
850
+ stability: "stable",
851
+ owners: [...OWNERS],
852
+ tags: [
853
+ "metering",
854
+ "usage",
855
+ "batch"
856
+ ],
857
+ description: "Record multiple usage events.",
858
+ goal: "Efficiently track bulk usage.",
859
+ context: "Called for batch processing."
860
+ },
861
+ io: {
862
+ input: RecordBatchUsageInput,
863
+ output: RecordBatchUsageOutput
864
+ },
865
+ policy: { auth: "admin" }
866
+ });
867
+ /**
868
+ * Get usage records.
869
+ */
870
+ const GetUsageContract = defineQuery({
871
+ meta: {
872
+ key: "usage.get",
873
+ version: "1.0.0",
874
+ stability: "stable",
875
+ owners: [...OWNERS],
876
+ tags: [
877
+ "metering",
878
+ "usage",
879
+ "get"
880
+ ],
881
+ description: "Get usage records for a subject.",
882
+ goal: "View detailed usage history.",
883
+ context: "Called to analyze usage."
884
+ },
885
+ io: {
886
+ input: GetUsageInput,
887
+ output: GetUsageOutput
888
+ },
889
+ policy: { auth: "user" }
890
+ });
891
+ /**
892
+ * Get usage summary.
893
+ */
894
+ const GetUsageSummaryContract = defineQuery({
895
+ meta: {
896
+ key: "usage.getSummary",
897
+ version: "1.0.0",
898
+ stability: "stable",
899
+ owners: [...OWNERS],
900
+ tags: [
901
+ "metering",
902
+ "usage",
903
+ "summary"
904
+ ],
905
+ description: "Get aggregated usage summary.",
906
+ goal: "View usage totals for billing.",
907
+ context: "Called for billing and reporting."
908
+ },
909
+ io: {
910
+ input: GetUsageSummaryInput,
911
+ output: GetUsageSummaryOutput
912
+ },
913
+ policy: { auth: "user" }
914
+ });
915
+ /**
916
+ * Create a threshold.
917
+ */
918
+ const CreateThresholdContract = defineCommand({
919
+ meta: {
920
+ key: "threshold.create",
921
+ version: "1.0.0",
922
+ stability: "stable",
923
+ owners: [...OWNERS],
924
+ tags: [
925
+ "metering",
926
+ "threshold",
927
+ "create"
928
+ ],
929
+ description: "Create a usage threshold.",
930
+ goal: "Set up usage limits and alerts.",
931
+ context: "Called when configuring limits."
932
+ },
933
+ io: {
934
+ input: CreateThresholdInput,
935
+ output: UsageThresholdModel,
936
+ errors: { METRIC_NOT_FOUND: {
937
+ description: "Metric does not exist",
938
+ http: 404,
939
+ gqlCode: "METRIC_NOT_FOUND",
940
+ when: "Metric key is invalid"
941
+ } }
942
+ },
943
+ policy: { auth: "admin" }
944
+ });
945
+ /**
946
+ * Update a threshold.
947
+ */
948
+ const UpdateThresholdContract = defineCommand({
949
+ meta: {
950
+ key: "threshold.update",
951
+ version: "1.0.0",
952
+ stability: "stable",
953
+ owners: [...OWNERS],
954
+ tags: [
955
+ "metering",
956
+ "threshold",
957
+ "update"
958
+ ],
959
+ description: "Update a threshold.",
960
+ goal: "Modify threshold configuration.",
961
+ context: "Called when adjusting limits."
962
+ },
963
+ io: {
964
+ input: UpdateThresholdInput,
965
+ output: UsageThresholdModel,
966
+ errors: { THRESHOLD_NOT_FOUND: {
967
+ description: "Threshold does not exist",
968
+ http: 404,
969
+ gqlCode: "THRESHOLD_NOT_FOUND",
970
+ when: "Threshold ID is invalid"
971
+ } }
972
+ },
973
+ policy: { auth: "admin" }
974
+ });
975
+ /**
976
+ * Delete a threshold.
977
+ */
978
+ const DeleteThresholdContract = defineCommand({
979
+ meta: {
980
+ key: "threshold.delete",
981
+ version: "1.0.0",
982
+ stability: "stable",
983
+ owners: [...OWNERS],
984
+ tags: [
985
+ "metering",
986
+ "threshold",
987
+ "delete"
988
+ ],
989
+ description: "Delete a threshold.",
990
+ goal: "Remove a usage threshold.",
991
+ context: "Called when removing limits."
992
+ },
993
+ io: {
994
+ input: DeleteThresholdInput,
995
+ output: SuccessOutput,
996
+ errors: { THRESHOLD_NOT_FOUND: {
997
+ description: "Threshold does not exist",
998
+ http: 404,
999
+ gqlCode: "THRESHOLD_NOT_FOUND",
1000
+ when: "Threshold ID is invalid"
1001
+ } }
1002
+ },
1003
+ policy: { auth: "admin" }
1004
+ });
1005
+ /**
1006
+ * List thresholds.
1007
+ */
1008
+ const ListThresholdsContract = defineQuery({
1009
+ meta: {
1010
+ key: "threshold.list",
1011
+ version: "1.0.0",
1012
+ stability: "stable",
1013
+ owners: [...OWNERS],
1014
+ tags: [
1015
+ "metering",
1016
+ "threshold",
1017
+ "list"
1018
+ ],
1019
+ description: "List usage thresholds.",
1020
+ goal: "View configured limits.",
1021
+ context: "Called to browse thresholds."
1022
+ },
1023
+ io: {
1024
+ input: ListThresholdsInput,
1025
+ output: ListThresholdsOutput
1026
+ },
1027
+ policy: { auth: "user" }
1028
+ });
1029
+
1030
+ //#endregion
1031
+ export { CreateThresholdContract, DefineMetricContract, DeleteMetricContract, DeleteThresholdContract, GetMetricContract, GetUsageContract, GetUsageSummaryContract, ListMetricsContract, ListThresholdsContract, MetricDefinitionModel, RecordBatchUsageContract, RecordUsageContract, UpdateMetricContract, UpdateThresholdContract, UsageRecordModel, UsageSummaryModel, UsageThresholdModel };
1032
+ //# sourceMappingURL=index.js.map