@lssm/lib.metering 1.41.0 → 1.42.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.
- package/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/aggregation/index.d.ts +156 -0
- package/dist/aggregation/index.d.ts.map +1 -0
- package/dist/aggregation/index.js +274 -1
- package/dist/aggregation/index.js.map +1 -0
- package/dist/contracts/index.d.ts +1139 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +1032 -1
- package/dist/contracts/index.js.map +1 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -1
- package/dist/docs/metering.docblock.d.ts +1 -0
- package/dist/docs/metering.docblock.js +22 -2
- package/dist/docs/metering.docblock.js.map +1 -0
- package/dist/entities/index.d.ts +231 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +418 -1
- package/dist/entities/index.js.map +1 -0
- package/dist/events.d.ts +540 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +417 -1
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -1
- package/dist/metering.feature.d.ts +12 -0
- package/dist/metering.feature.d.ts.map +1 -0
- package/dist/metering.feature.js +127 -1
- package/dist/metering.feature.js.map +1 -0
- package/package.json +23 -15
package/dist/contracts/index.js
CHANGED
|
@@ -1 +1,1032 @@
|
|
|
1
|
-
import{ScalarTypeEnum as e,defineSchemaModel as t}from"@lssm/lib.schema";import{defineCommand as n,defineQuery as r}from"@lssm/lib.contracts";const i=[`platform.metering`],a=t({name:`MetricDefinition`,description:`Represents a metric definition`,fields:{id:{type:e.String_unsecure(),isOptional:!1},key:{type:e.String_unsecure(),isOptional:!1},name:{type:e.String_unsecure(),isOptional:!1},description:{type:e.String_unsecure(),isOptional:!0},unit:{type:e.String_unsecure(),isOptional:!1},aggregationType:{type:e.String_unsecure(),isOptional:!1},resetPeriod:{type:e.String_unsecure(),isOptional:!1},category:{type:e.String_unsecure(),isOptional:!0},isActive:{type:e.Boolean(),isOptional:!1},orgId:{type:e.String_unsecure(),isOptional:!0},createdAt:{type:e.DateTime(),isOptional:!1},updatedAt:{type:e.DateTime(),isOptional:!1}}}),o=t({name:`UsageRecord`,description:`Represents a usage record`,fields:{id:{type:e.String_unsecure(),isOptional:!1},metricKey:{type:e.String_unsecure(),isOptional:!1},subjectType:{type:e.String_unsecure(),isOptional:!1},subjectId:{type:e.String_unsecure(),isOptional:!1},quantity:{type:e.Float_unsecure(),isOptional:!1},source:{type:e.String_unsecure(),isOptional:!0},resourceId:{type:e.String_unsecure(),isOptional:!0},resourceType:{type:e.String_unsecure(),isOptional:!0},metadata:{type:e.JSON(),isOptional:!0},timestamp:{type:e.DateTime(),isOptional:!1},createdAt:{type:e.DateTime(),isOptional:!1}}}),s=t({name:`UsageSummary`,description:`Represents aggregated usage`,fields:{id:{type:e.String_unsecure(),isOptional:!1},metricKey:{type:e.String_unsecure(),isOptional:!1},subjectType:{type:e.String_unsecure(),isOptional:!1},subjectId:{type:e.String_unsecure(),isOptional:!1},periodType:{type:e.String_unsecure(),isOptional:!1},periodStart:{type:e.DateTime(),isOptional:!1},periodEnd:{type:e.DateTime(),isOptional:!1},totalQuantity:{type:e.Float_unsecure(),isOptional:!1},recordCount:{type:e.Int_unsecure(),isOptional:!1},minQuantity:{type:e.Float_unsecure(),isOptional:!0},maxQuantity:{type:e.Float_unsecure(),isOptional:!0},avgQuantity:{type:e.Float_unsecure(),isOptional:!0}}}),c=t({name:`UsageThreshold`,description:`Represents a usage threshold`,fields:{id:{type:e.String_unsecure(),isOptional:!1},metricKey:{type:e.String_unsecure(),isOptional:!1},subjectType:{type:e.String_unsecure(),isOptional:!0},subjectId:{type:e.String_unsecure(),isOptional:!0},name:{type:e.String_unsecure(),isOptional:!1},threshold:{type:e.Float_unsecure(),isOptional:!1},warnThreshold:{type:e.Float_unsecure(),isOptional:!0},periodType:{type:e.String_unsecure(),isOptional:!1},action:{type:e.String_unsecure(),isOptional:!1},currentValue:{type:e.Float_unsecure(),isOptional:!1},isActive:{type:e.Boolean(),isOptional:!1},createdAt:{type:e.DateTime(),isOptional:!1}}}),l=t({name:`DefineMetricInput`,description:`Input for defining a metric`,fields:{key:{type:e.String_unsecure(),isOptional:!1},name:{type:e.String_unsecure(),isOptional:!1},description:{type:e.String_unsecure(),isOptional:!0},unit:{type:e.String_unsecure(),isOptional:!1},aggregationType:{type:e.String_unsecure(),isOptional:!0},resetPeriod:{type:e.String_unsecure(),isOptional:!0},category:{type:e.String_unsecure(),isOptional:!0},orgId:{type:e.String_unsecure(),isOptional:!0},metadata:{type:e.JSON(),isOptional:!0}}}),u=t({name:`UpdateMetricInput`,description:`Input for updating a metric`,fields:{metricId:{type:e.String_unsecure(),isOptional:!1},name:{type:e.String_unsecure(),isOptional:!0},description:{type:e.String_unsecure(),isOptional:!0},category:{type:e.String_unsecure(),isOptional:!0},isActive:{type:e.Boolean(),isOptional:!0},metadata:{type:e.JSON(),isOptional:!0}}}),d=t({name:`DeleteMetricInput`,description:`Input for deleting a metric`,fields:{metricId:{type:e.String_unsecure(),isOptional:!1}}}),f=t({name:`GetMetricInput`,description:`Input for getting a metric`,fields:{key:{type:e.String_unsecure(),isOptional:!1},orgId:{type:e.String_unsecure(),isOptional:!0}}}),p=t({name:`ListMetricsInput`,description:`Input for listing metrics`,fields:{orgId:{type:e.String_unsecure(),isOptional:!0},category:{type:e.String_unsecure(),isOptional:!0},isActive:{type:e.Boolean(),isOptional:!0},limit:{type:e.Int_unsecure(),isOptional:!0},offset:{type:e.Int_unsecure(),isOptional:!0}}}),m=t({name:`ListMetricsOutput`,description:`Output for listing metrics`,fields:{metrics:{type:a,isArray:!0,isOptional:!1},total:{type:e.Int_unsecure(),isOptional:!1}}}),h=t({name:`RecordUsageInput`,description:`Input for recording usage`,fields:{metricKey:{type:e.String_unsecure(),isOptional:!1},subjectType:{type:e.String_unsecure(),isOptional:!1},subjectId:{type:e.String_unsecure(),isOptional:!1},quantity:{type:e.Float_unsecure(),isOptional:!1},timestamp:{type:e.DateTime(),isOptional:!0},source:{type:e.String_unsecure(),isOptional:!0},resourceId:{type:e.String_unsecure(),isOptional:!0},resourceType:{type:e.String_unsecure(),isOptional:!0},metadata:{type:e.JSON(),isOptional:!0},idempotencyKey:{type:e.String_unsecure(),isOptional:!0}}}),g=t({name:`RecordBatchUsageInput`,description:`Input for recording batch usage`,fields:{records:{type:h,isArray:!0,isOptional:!1}}}),_=t({name:`RecordBatchUsageOutput`,description:`Output for recording batch usage`,fields:{recordedCount:{type:e.Int_unsecure(),isOptional:!1},skippedCount:{type:e.Int_unsecure(),isOptional:!1},recordIds:{type:e.JSON(),isOptional:!1}}}),v=t({name:`GetUsageInput`,description:`Input for getting usage`,fields:{metricKey:{type:e.String_unsecure(),isOptional:!1},subjectType:{type:e.String_unsecure(),isOptional:!1},subjectId:{type:e.String_unsecure(),isOptional:!1},startDate:{type:e.DateTime(),isOptional:!1},endDate:{type:e.DateTime(),isOptional:!1},limit:{type:e.Int_unsecure(),isOptional:!0},offset:{type:e.Int_unsecure(),isOptional:!0}}}),y=t({name:`GetUsageOutput`,description:`Output for getting usage`,fields:{records:{type:o,isArray:!0,isOptional:!1},total:{type:e.Int_unsecure(),isOptional:!1},totalQuantity:{type:e.Float_unsecure(),isOptional:!1}}}),b=t({name:`GetUsageSummaryInput`,description:`Input for getting usage summary`,fields:{metricKey:{type:e.String_unsecure(),isOptional:!1},subjectType:{type:e.String_unsecure(),isOptional:!1},subjectId:{type:e.String_unsecure(),isOptional:!1},periodType:{type:e.String_unsecure(),isOptional:!1},startDate:{type:e.DateTime(),isOptional:!1},endDate:{type:e.DateTime(),isOptional:!0}}}),x=t({name:`GetUsageSummaryOutput`,description:`Output for getting usage summary`,fields:{summaries:{type:s,isArray:!0,isOptional:!1},total:{type:e.Int_unsecure(),isOptional:!1}}}),S=t({name:`CreateThresholdInput`,description:`Input for creating a threshold`,fields:{metricKey:{type:e.String_unsecure(),isOptional:!1},subjectType:{type:e.String_unsecure(),isOptional:!0},subjectId:{type:e.String_unsecure(),isOptional:!0},name:{type:e.String_unsecure(),isOptional:!1},threshold:{type:e.Float_unsecure(),isOptional:!1},warnThreshold:{type:e.Float_unsecure(),isOptional:!0},periodType:{type:e.String_unsecure(),isOptional:!0},action:{type:e.String_unsecure(),isOptional:!0},notifyEmails:{type:e.JSON(),isOptional:!0},notifyWebhook:{type:e.String_unsecure(),isOptional:!0}}}),C=t({name:`UpdateThresholdInput`,description:`Input for updating a threshold`,fields:{thresholdId:{type:e.String_unsecure(),isOptional:!1},name:{type:e.String_unsecure(),isOptional:!0},threshold:{type:e.Float_unsecure(),isOptional:!0},warnThreshold:{type:e.Float_unsecure(),isOptional:!0},action:{type:e.String_unsecure(),isOptional:!0},notifyEmails:{type:e.JSON(),isOptional:!0},notifyWebhook:{type:e.String_unsecure(),isOptional:!0},isActive:{type:e.Boolean(),isOptional:!0}}}),w=t({name:`DeleteThresholdInput`,description:`Input for deleting a threshold`,fields:{thresholdId:{type:e.String_unsecure(),isOptional:!1}}}),T=t({name:`ListThresholdsInput`,description:`Input for listing thresholds`,fields:{metricKey:{type:e.String_unsecure(),isOptional:!0},subjectType:{type:e.String_unsecure(),isOptional:!0},subjectId:{type:e.String_unsecure(),isOptional:!0},isActive:{type:e.Boolean(),isOptional:!0}}}),E=t({name:`ListThresholdsOutput`,description:`Output for listing thresholds`,fields:{thresholds:{type:c,isArray:!0,isOptional:!1},total:{type:e.Int_unsecure(),isOptional:!1}}}),D=t({name:`SuccessOutput`,description:`Generic success output`,fields:{success:{type:e.Boolean(),isOptional:!1}}}),O=n({meta:{name:`metric.define`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`metric`,`define`],description:`Define a new usage metric.`,goal:`Create a new metric for tracking usage.`,context:`Called when setting up metering.`},io:{input:l,output:a,errors:{METRIC_KEY_EXISTS:{description:`Metric key already exists`,http:409,gqlCode:`METRIC_KEY_EXISTS`,when:`A metric with this key already exists`}}},policy:{auth:`admin`}}),k=n({meta:{name:`metric.update`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`metric`,`update`],description:`Update a metric definition.`,goal:`Modify metric configuration.`,context:`Called when updating metric settings.`},io:{input:u,output:a,errors:{METRIC_NOT_FOUND:{description:`Metric does not exist`,http:404,gqlCode:`METRIC_NOT_FOUND`,when:`Metric ID is invalid`}}},policy:{auth:`admin`}}),A=n({meta:{name:`metric.delete`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`metric`,`delete`],description:`Delete a metric definition.`,goal:`Remove a metric and its data.`,context:`Called when removing a metric.`},io:{input:d,output:D,errors:{METRIC_NOT_FOUND:{description:`Metric does not exist`,http:404,gqlCode:`METRIC_NOT_FOUND`,when:`Metric ID is invalid`}}},policy:{auth:`admin`}}),j=r({meta:{name:`metric.get`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`metric`,`get`],description:`Get a metric by key.`,goal:`Retrieve metric definition.`,context:`Called to inspect metric details.`},io:{input:f,output:a,errors:{METRIC_NOT_FOUND:{description:`Metric does not exist`,http:404,gqlCode:`METRIC_NOT_FOUND`,when:`Metric key is invalid`}}},policy:{auth:`user`}}),M=r({meta:{name:`metric.list`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`metric`,`list`],description:`List all metrics.`,goal:`View configured metrics.`,context:`Called to browse metrics.`},io:{input:p,output:m},policy:{auth:`user`}}),N=n({meta:{name:`usage.record`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`usage`,`record`],description:`Record a usage event.`,goal:`Track usage for billing and monitoring.`,context:`Called when usage occurs.`},io:{input:h,output:o,errors:{METRIC_NOT_FOUND:{description:`Metric does not exist`,http:404,gqlCode:`METRIC_NOT_FOUND`,when:`Metric key is invalid`},DUPLICATE_RECORD:{description:`Record already exists`,http:409,gqlCode:`DUPLICATE_RECORD`,when:`Idempotency key already used`}}},policy:{auth:`admin`}}),P=n({meta:{name:`usage.recordBatch`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`usage`,`batch`],description:`Record multiple usage events.`,goal:`Efficiently track bulk usage.`,context:`Called for batch processing.`},io:{input:g,output:_},policy:{auth:`admin`}}),F=r({meta:{name:`usage.get`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`usage`,`get`],description:`Get usage records for a subject.`,goal:`View detailed usage history.`,context:`Called to analyze usage.`},io:{input:v,output:y},policy:{auth:`user`}}),I=r({meta:{name:`usage.getSummary`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`usage`,`summary`],description:`Get aggregated usage summary.`,goal:`View usage totals for billing.`,context:`Called for billing and reporting.`},io:{input:b,output:x},policy:{auth:`user`}}),L=n({meta:{name:`threshold.create`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`threshold`,`create`],description:`Create a usage threshold.`,goal:`Set up usage limits and alerts.`,context:`Called when configuring limits.`},io:{input:S,output:c,errors:{METRIC_NOT_FOUND:{description:`Metric does not exist`,http:404,gqlCode:`METRIC_NOT_FOUND`,when:`Metric key is invalid`}}},policy:{auth:`admin`}}),R=n({meta:{name:`threshold.update`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`threshold`,`update`],description:`Update a threshold.`,goal:`Modify threshold configuration.`,context:`Called when adjusting limits.`},io:{input:C,output:c,errors:{THRESHOLD_NOT_FOUND:{description:`Threshold does not exist`,http:404,gqlCode:`THRESHOLD_NOT_FOUND`,when:`Threshold ID is invalid`}}},policy:{auth:`admin`}}),z=n({meta:{name:`threshold.delete`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`threshold`,`delete`],description:`Delete a threshold.`,goal:`Remove a usage threshold.`,context:`Called when removing limits.`},io:{input:w,output:D,errors:{THRESHOLD_NOT_FOUND:{description:`Threshold does not exist`,http:404,gqlCode:`THRESHOLD_NOT_FOUND`,when:`Threshold ID is invalid`}}},policy:{auth:`admin`}}),B=r({meta:{name:`threshold.list`,version:1,stability:`stable`,owners:[...i],tags:[`metering`,`threshold`,`list`],description:`List usage thresholds.`,goal:`View configured limits.`,context:`Called to browse thresholds.`},io:{input:T,output:E},policy:{auth:`user`}});export{L as CreateThresholdContract,O as DefineMetricContract,A as DeleteMetricContract,z as DeleteThresholdContract,j as GetMetricContract,F as GetUsageContract,I as GetUsageSummaryContract,M as ListMetricsContract,B as ListThresholdsContract,a as MetricDefinitionModel,P as RecordBatchUsageContract,N as RecordUsageContract,k as UpdateMetricContract,R as UpdateThresholdContract,o as UsageRecordModel,s as UsageSummaryModel,c as UsageThresholdModel};
|
|
1
|
+
import { ScalarTypeEnum, defineSchemaModel } from "@lssm/lib.schema";
|
|
2
|
+
import { defineCommand, defineQuery } from "@lssm/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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|