orb-billing 3.2.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/package.json +2 -2
- package/resources/alerts.d.ts +9 -9
- package/resources/alerts.d.ts.map +1 -1
- package/resources/alerts.js.map +1 -1
- package/resources/alerts.mjs.map +1 -1
- package/resources/customers/customers.d.ts +0 -7
- package/resources/customers/customers.d.ts.map +1 -1
- package/resources/customers/customers.js +0 -3
- package/resources/customers/customers.js.map +1 -1
- package/resources/customers/customers.mjs +0 -3
- package/resources/customers/customers.mjs.map +1 -1
- package/resources/customers/index.d.ts +0 -1
- package/resources/customers/index.d.ts.map +1 -1
- package/resources/customers/index.js +1 -3
- package/resources/customers/index.js.map +1 -1
- package/resources/customers/index.mjs +0 -1
- package/resources/customers/index.mjs.map +1 -1
- package/resources/events/backfills.d.ts +42 -0
- package/resources/events/backfills.d.ts.map +1 -1
- package/resources/events/backfills.js +6 -0
- package/resources/events/backfills.js.map +1 -1
- package/resources/events/backfills.mjs +6 -0
- package/resources/events/backfills.mjs.map +1 -1
- package/resources/events/events.d.ts +11 -2
- package/resources/events/events.d.ts.map +1 -1
- package/resources/events/events.js +11 -2
- package/resources/events/events.js.map +1 -1
- package/resources/events/events.mjs +11 -2
- package/resources/events/events.mjs.map +1 -1
- package/resources/plans/plans.d.ts +15 -15
- package/resources/plans/plans.d.ts.map +1 -1
- package/resources/prices/prices.d.ts +108 -18
- package/resources/prices/prices.d.ts.map +1 -1
- package/resources/prices/prices.js.map +1 -1
- package/resources/prices/prices.mjs.map +1 -1
- package/resources/subscriptions.d.ts +20 -30
- package/resources/subscriptions.d.ts.map +1 -1
- package/resources/subscriptions.js.map +1 -1
- package/resources/subscriptions.mjs.map +1 -1
- package/src/resources/alerts.ts +24 -9
- package/src/resources/customers/customers.ts +0 -7
- package/src/resources/customers/index.ts +0 -7
- package/src/resources/events/backfills.ts +48 -0
- package/src/resources/events/events.ts +11 -2
- package/src/resources/plans/plans.ts +15 -15
- package/src/resources/prices/prices.ts +162 -18
- package/src/resources/subscriptions.ts +20 -32
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/resources/customers/usage.d.ts +0 -326
- package/resources/customers/usage.d.ts.map +0 -1
- package/resources/customers/usage.js +0 -227
- package/resources/customers/usage.js.map +0 -1
- package/resources/customers/usage.mjs +0 -223
- package/resources/customers/usage.mjs.map +0 -1
- package/src/resources/customers/usage.ts +0 -372
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Usage = void 0;
|
|
5
|
-
const resource_1 = require("../../resource.js");
|
|
6
|
-
class Usage extends resource_1.APIResource {
|
|
7
|
-
/**
|
|
8
|
-
* This endpoint is used to amend usage within a timeframe for a customer that has
|
|
9
|
-
* an active subscription.
|
|
10
|
-
*
|
|
11
|
-
* This endpoint will mark _all_ existing events within
|
|
12
|
-
* `[timeframe_start, timeframe_end)` as _ignored_ for billing purposes, and Orb
|
|
13
|
-
* will only use the _new_ events passed in the body of this request as the source
|
|
14
|
-
* of truth for that timeframe moving forwards. Note that a given time period can
|
|
15
|
-
* be amended any number of times, so events can be overwritten in subsequent calls
|
|
16
|
-
* to th is endpoint.
|
|
17
|
-
*
|
|
18
|
-
* This is a powerful and audit-safe mechanism to retroactively change usage data
|
|
19
|
-
* in cases where you need to:
|
|
20
|
-
*
|
|
21
|
-
* - decrease historical usage consumption because of degraded service availability
|
|
22
|
-
* in your systems
|
|
23
|
-
* - account for gaps from your usage reporting mechanism
|
|
24
|
-
* - make point-in-time fixes for specific event records, while retaining the
|
|
25
|
-
* original time of usage and associated metadata. This amendment API is designed
|
|
26
|
-
* with two explicit goals:
|
|
27
|
-
*
|
|
28
|
-
* 1. Amendments are **always audit-safe**. The amendment process will still retain
|
|
29
|
-
* original events in the timeframe, though they will be ignored for billing
|
|
30
|
-
* calculations. For auditing a nd data fidelity purposes, Orb never overwrites
|
|
31
|
-
* or permanently deletes ingested usage data.
|
|
32
|
-
* 2. Amendments always preserve data **consistency**. In other words, either an
|
|
33
|
-
* amendment is fully processed by the system (and the new events for the
|
|
34
|
-
* timeframe are honored rather than the existing ones) or the amendment request
|
|
35
|
-
* fails. To maintain this important property, Orb prevents _partial event
|
|
36
|
-
* ingestion_ on this endpoint.
|
|
37
|
-
*
|
|
38
|
-
* ## Response semantics
|
|
39
|
-
*
|
|
40
|
-
* - Either all events are ingested successfully, or all fail to ingest (returning
|
|
41
|
-
* a `4xx` or `5xx` response code).
|
|
42
|
-
* - Any event that fails schema validation will lead to a `4xx` response. In this
|
|
43
|
-
* case, to maintain data consistency, Orb will not ingest any events and will
|
|
44
|
-
* also not deprecate existing events in the time period.
|
|
45
|
-
* - You can assume that the amendment is successful on receipt of a `2xx`
|
|
46
|
-
* response.While a successful response from this endpoint indicates that the new
|
|
47
|
-
* events have been ingested, updating usage totals happens asynchronously and
|
|
48
|
-
* may be delayed by a few minutes.
|
|
49
|
-
*
|
|
50
|
-
* As emphasized above, Orb will never show an inconsistent state (e.g. in invoice
|
|
51
|
-
* previews or dashboards); either it will show the existing state (before the
|
|
52
|
-
* amendment) or the new state (with new events in the requested timeframe).
|
|
53
|
-
*
|
|
54
|
-
* ## Sample request body
|
|
55
|
-
*
|
|
56
|
-
* ```json
|
|
57
|
-
* {
|
|
58
|
-
* "events": [
|
|
59
|
-
* {
|
|
60
|
-
* "event_name": "payment_processed",
|
|
61
|
-
* "timestamp": "2022-03-24T07:15:00Z",
|
|
62
|
-
* "properties": {
|
|
63
|
-
* "amount": 100
|
|
64
|
-
* }
|
|
65
|
-
* },
|
|
66
|
-
* {
|
|
67
|
-
* "event_name": "payment_failed",
|
|
68
|
-
* "timestamp": "2022-03-24T07:15:00Z",
|
|
69
|
-
* "properties": {
|
|
70
|
-
* "amount": 100
|
|
71
|
-
* }
|
|
72
|
-
* }
|
|
73
|
-
* ]
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* ## Request Validation
|
|
78
|
-
*
|
|
79
|
-
* - The `timestamp` of each event reported must fall within the bounds of
|
|
80
|
-
* `timeframe_start` and `timeframe_end`. As with ingestion, all timesta mps must
|
|
81
|
-
* be sent in ISO8601 format with UTC timezone offset.
|
|
82
|
-
* - Orb **does not accept an `idempotency_key`** with each event in this endpoint,
|
|
83
|
-
* since the entirety of the event list must be ingested to ensure consistency.
|
|
84
|
-
* On retryable errors , you should retry the request in its entirety, and assume
|
|
85
|
-
* that the amendment operation has not succeeded until receipt of a `2xx`.
|
|
86
|
-
*
|
|
87
|
-
* - Both `timeframe_start` and `timeframe_end` must be timestamps in the past.
|
|
88
|
-
* Furthermore, Orb will genera lly validate that the `timeframe_start` and
|
|
89
|
-
* `timeframe_end` fall within the customer's _current_ subscription billing pe
|
|
90
|
-
* riod. However, Orb does allow amendments while in the grace period of the
|
|
91
|
-
* previous billing period; in this instance, the timeframe can start before the
|
|
92
|
-
* current period.
|
|
93
|
-
*
|
|
94
|
-
* ## API Limits
|
|
95
|
-
*
|
|
96
|
-
* Note that Orb does not currently enforce a hard rate- limit for API usage or a
|
|
97
|
-
* maximum request payload size. Similar to the event ingestion API, this API is
|
|
98
|
-
* architected for h igh-throughput ingestion. It is also safe to
|
|
99
|
-
* _programmatically_ call this endpoint if your system can automatically dete ct a
|
|
100
|
-
* need for historical amendment.
|
|
101
|
-
*
|
|
102
|
-
* In order to overwrite timeframes with a very large number of events, we suggest
|
|
103
|
-
* using multiple calls with small adjacent (e.g. every hour) timeframes.
|
|
104
|
-
*
|
|
105
|
-
* @deprecated This method will be removed in a future release. Please use the 'events.backfills.create' instead.
|
|
106
|
-
*/
|
|
107
|
-
update(id, params, options) {
|
|
108
|
-
const { timeframe_end, timeframe_start, ...body } = params;
|
|
109
|
-
return this._client.patch(`/customers/${id}/usage`, {
|
|
110
|
-
query: { timeframe_end, timeframe_start },
|
|
111
|
-
body,
|
|
112
|
-
...options,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* This endpoint is used to amend usage within a timeframe for a customer that has
|
|
117
|
-
* an active subscription.
|
|
118
|
-
*
|
|
119
|
-
* This endpoint will mark _all_ existing events within
|
|
120
|
-
* `[timeframe_start, timeframe_end)` as _ignored_ for billing purposes, and Orb
|
|
121
|
-
* will only use the _new_ events passed in the body of this request as the source
|
|
122
|
-
* of truth for that timeframe moving forwards. Note that a given time period can
|
|
123
|
-
* be amended any number of times, so events can be overwritten in subsequent calls
|
|
124
|
-
* to th is endpoint.
|
|
125
|
-
*
|
|
126
|
-
* This is a powerful and audit-safe mechanism to retroactively change usage data
|
|
127
|
-
* in cases where you need to:
|
|
128
|
-
*
|
|
129
|
-
* - decrease historical usage consumption because of degraded service availability
|
|
130
|
-
* in your systems
|
|
131
|
-
* - account for gaps from your usage reporting mechanism
|
|
132
|
-
* - make point-in-time fixes for specific event records, while retaining the
|
|
133
|
-
* original time of usage and associated metadata. This amendment API is designed
|
|
134
|
-
* with two explicit goals:
|
|
135
|
-
*
|
|
136
|
-
* 1. Amendments are **always audit-safe**. The amendment process will still retain
|
|
137
|
-
* original events in the timeframe, though they will be ignored for billing
|
|
138
|
-
* calculations. For auditing a nd data fidelity purposes, Orb never overwrites
|
|
139
|
-
* or permanently deletes ingested usage data.
|
|
140
|
-
* 2. Amendments always preserve data **consistency**. In other words, either an
|
|
141
|
-
* amendment is fully processed by the system (and the new events for the
|
|
142
|
-
* timeframe are honored rather than the existing ones) or the amendment request
|
|
143
|
-
* fails. To maintain this important property, Orb prevents _partial event
|
|
144
|
-
* ingestion_ on this endpoint.
|
|
145
|
-
*
|
|
146
|
-
* ## Response semantics
|
|
147
|
-
*
|
|
148
|
-
* - Either all events are ingested successfully, or all fail to ingest (returning
|
|
149
|
-
* a `4xx` or `5xx` response code).
|
|
150
|
-
* - Any event that fails schema validation will lead to a `4xx` response. In this
|
|
151
|
-
* case, to maintain data consistency, Orb will not ingest any events and will
|
|
152
|
-
* also not deprecate existing events in the time period.
|
|
153
|
-
* - You can assume that the amendment is successful on receipt of a `2xx`
|
|
154
|
-
* response.While a successful response from this endpoint indicates that the new
|
|
155
|
-
* events have been ingested, updating usage totals happens asynchronously and
|
|
156
|
-
* may be delayed by a few minutes.
|
|
157
|
-
*
|
|
158
|
-
* As emphasized above, Orb will never show an inconsistent state (e.g. in invoice
|
|
159
|
-
* previews or dashboards); either it will show the existing state (before the
|
|
160
|
-
* amendment) or the new state (with new events in the requested timeframe).
|
|
161
|
-
*
|
|
162
|
-
* ## Sample request body
|
|
163
|
-
*
|
|
164
|
-
* ```json
|
|
165
|
-
* {
|
|
166
|
-
* "events": [
|
|
167
|
-
* {
|
|
168
|
-
* "event_name": "payment_processed",
|
|
169
|
-
* "timestamp": "2022-03-24T07:15:00Z",
|
|
170
|
-
* "properties": {
|
|
171
|
-
* "amount": 100
|
|
172
|
-
* }
|
|
173
|
-
* },
|
|
174
|
-
* {
|
|
175
|
-
* "event_name": "payment_failed",
|
|
176
|
-
* "timestamp": "2022-03-24T07:15:00Z",
|
|
177
|
-
* "properties": {
|
|
178
|
-
* "amount": 100
|
|
179
|
-
* }
|
|
180
|
-
* }
|
|
181
|
-
* ]
|
|
182
|
-
* }
|
|
183
|
-
* ```
|
|
184
|
-
*
|
|
185
|
-
* ## Request Validation
|
|
186
|
-
*
|
|
187
|
-
* - The `timestamp` of each event reported must fall within the bounds of
|
|
188
|
-
* `timeframe_start` and `timeframe_end`. As with ingestion, all timesta mps must
|
|
189
|
-
* be sent in ISO8601 format with UTC timezone offset.
|
|
190
|
-
* - Orb **does not accept an `idempotency_key`** with each event in this endpoint,
|
|
191
|
-
* since the entirety of the event list must be ingested to ensure consistency.
|
|
192
|
-
* On retryable errors , you should retry the request in its entirety, and assume
|
|
193
|
-
* that the amendment operation has not succeeded until receipt of a `2xx`.
|
|
194
|
-
*
|
|
195
|
-
* - Both `timeframe_start` and `timeframe_end` must be timestamps in the past.
|
|
196
|
-
* Furthermore, Orb will genera lly validate that the `timeframe_start` and
|
|
197
|
-
* `timeframe_end` fall within the customer's _current_ subscription billing pe
|
|
198
|
-
* riod. However, Orb does allow amendments while in the grace period of the
|
|
199
|
-
* previous billing period; in this instance, the timeframe can start before the
|
|
200
|
-
* current period.
|
|
201
|
-
*
|
|
202
|
-
* ## API Limits
|
|
203
|
-
*
|
|
204
|
-
* Note that Orb does not currently enforce a hard rate- limit for API usage or a
|
|
205
|
-
* maximum request payload size. Similar to the event ingestion API, this API is
|
|
206
|
-
* architected for h igh-throughput ingestion. It is also safe to
|
|
207
|
-
* _programmatically_ call this endpoint if your system can automatically dete ct a
|
|
208
|
-
* need for historical amendment.
|
|
209
|
-
*
|
|
210
|
-
* In order to overwrite timeframes with a very large number of events, we suggest
|
|
211
|
-
* using multiple calls with small adjacent (e.g. every hour) timeframes.
|
|
212
|
-
*
|
|
213
|
-
* @deprecated This method will be removed in a future release. Please use the 'events.backfills.create' instead.
|
|
214
|
-
*/
|
|
215
|
-
updateByExternalId(id, params, options) {
|
|
216
|
-
const { timeframe_end, timeframe_start, ...body } = params;
|
|
217
|
-
return this._client.patch(`/customers/external_customer_id/${id}/usage`, {
|
|
218
|
-
query: { timeframe_end, timeframe_start },
|
|
219
|
-
body,
|
|
220
|
-
...options,
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
exports.Usage = Usage;
|
|
225
|
-
(function (Usage) {
|
|
226
|
-
})(Usage = exports.Usage || (exports.Usage = {}));
|
|
227
|
-
//# sourceMappingURL=usage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/resources/customers/usage.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,gDAA6C;AAI7C,MAAa,KAAM,SAAQ,sBAAW;IACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmGG;IACH,MAAM,CACJ,EAAU,EACV,MAAyB,EACzB,OAA6B;QAE7B,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,QAAQ,EAAE;YAClD,KAAK,EAAE,EAAE,aAAa,EAAE,eAAe,EAAE;YACzC,IAAI;YACJ,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmGG;IACH,kBAAkB,CAChB,EAAU,EACV,MAAqC,EACrC,OAA6B;QAE7B,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,QAAQ,EAAE;YACvE,KAAK,EAAE,EAAE,aAAa,EAAE,eAAe,EAAE;YACzC,IAAI;YACJ,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;CACF;AAlOD,sBAkOC;AAsID,WAAiB,KAAK;AAKtB,CAAC,EALgB,KAAK,GAAL,aAAK,KAAL,aAAK,QAKrB"}
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
import { APIResource } from "../../resource.mjs";
|
|
3
|
-
export class Usage extends APIResource {
|
|
4
|
-
/**
|
|
5
|
-
* This endpoint is used to amend usage within a timeframe for a customer that has
|
|
6
|
-
* an active subscription.
|
|
7
|
-
*
|
|
8
|
-
* This endpoint will mark _all_ existing events within
|
|
9
|
-
* `[timeframe_start, timeframe_end)` as _ignored_ for billing purposes, and Orb
|
|
10
|
-
* will only use the _new_ events passed in the body of this request as the source
|
|
11
|
-
* of truth for that timeframe moving forwards. Note that a given time period can
|
|
12
|
-
* be amended any number of times, so events can be overwritten in subsequent calls
|
|
13
|
-
* to th is endpoint.
|
|
14
|
-
*
|
|
15
|
-
* This is a powerful and audit-safe mechanism to retroactively change usage data
|
|
16
|
-
* in cases where you need to:
|
|
17
|
-
*
|
|
18
|
-
* - decrease historical usage consumption because of degraded service availability
|
|
19
|
-
* in your systems
|
|
20
|
-
* - account for gaps from your usage reporting mechanism
|
|
21
|
-
* - make point-in-time fixes for specific event records, while retaining the
|
|
22
|
-
* original time of usage and associated metadata. This amendment API is designed
|
|
23
|
-
* with two explicit goals:
|
|
24
|
-
*
|
|
25
|
-
* 1. Amendments are **always audit-safe**. The amendment process will still retain
|
|
26
|
-
* original events in the timeframe, though they will be ignored for billing
|
|
27
|
-
* calculations. For auditing a nd data fidelity purposes, Orb never overwrites
|
|
28
|
-
* or permanently deletes ingested usage data.
|
|
29
|
-
* 2. Amendments always preserve data **consistency**. In other words, either an
|
|
30
|
-
* amendment is fully processed by the system (and the new events for the
|
|
31
|
-
* timeframe are honored rather than the existing ones) or the amendment request
|
|
32
|
-
* fails. To maintain this important property, Orb prevents _partial event
|
|
33
|
-
* ingestion_ on this endpoint.
|
|
34
|
-
*
|
|
35
|
-
* ## Response semantics
|
|
36
|
-
*
|
|
37
|
-
* - Either all events are ingested successfully, or all fail to ingest (returning
|
|
38
|
-
* a `4xx` or `5xx` response code).
|
|
39
|
-
* - Any event that fails schema validation will lead to a `4xx` response. In this
|
|
40
|
-
* case, to maintain data consistency, Orb will not ingest any events and will
|
|
41
|
-
* also not deprecate existing events in the time period.
|
|
42
|
-
* - You can assume that the amendment is successful on receipt of a `2xx`
|
|
43
|
-
* response.While a successful response from this endpoint indicates that the new
|
|
44
|
-
* events have been ingested, updating usage totals happens asynchronously and
|
|
45
|
-
* may be delayed by a few minutes.
|
|
46
|
-
*
|
|
47
|
-
* As emphasized above, Orb will never show an inconsistent state (e.g. in invoice
|
|
48
|
-
* previews or dashboards); either it will show the existing state (before the
|
|
49
|
-
* amendment) or the new state (with new events in the requested timeframe).
|
|
50
|
-
*
|
|
51
|
-
* ## Sample request body
|
|
52
|
-
*
|
|
53
|
-
* ```json
|
|
54
|
-
* {
|
|
55
|
-
* "events": [
|
|
56
|
-
* {
|
|
57
|
-
* "event_name": "payment_processed",
|
|
58
|
-
* "timestamp": "2022-03-24T07:15:00Z",
|
|
59
|
-
* "properties": {
|
|
60
|
-
* "amount": 100
|
|
61
|
-
* }
|
|
62
|
-
* },
|
|
63
|
-
* {
|
|
64
|
-
* "event_name": "payment_failed",
|
|
65
|
-
* "timestamp": "2022-03-24T07:15:00Z",
|
|
66
|
-
* "properties": {
|
|
67
|
-
* "amount": 100
|
|
68
|
-
* }
|
|
69
|
-
* }
|
|
70
|
-
* ]
|
|
71
|
-
* }
|
|
72
|
-
* ```
|
|
73
|
-
*
|
|
74
|
-
* ## Request Validation
|
|
75
|
-
*
|
|
76
|
-
* - The `timestamp` of each event reported must fall within the bounds of
|
|
77
|
-
* `timeframe_start` and `timeframe_end`. As with ingestion, all timesta mps must
|
|
78
|
-
* be sent in ISO8601 format with UTC timezone offset.
|
|
79
|
-
* - Orb **does not accept an `idempotency_key`** with each event in this endpoint,
|
|
80
|
-
* since the entirety of the event list must be ingested to ensure consistency.
|
|
81
|
-
* On retryable errors , you should retry the request in its entirety, and assume
|
|
82
|
-
* that the amendment operation has not succeeded until receipt of a `2xx`.
|
|
83
|
-
*
|
|
84
|
-
* - Both `timeframe_start` and `timeframe_end` must be timestamps in the past.
|
|
85
|
-
* Furthermore, Orb will genera lly validate that the `timeframe_start` and
|
|
86
|
-
* `timeframe_end` fall within the customer's _current_ subscription billing pe
|
|
87
|
-
* riod. However, Orb does allow amendments while in the grace period of the
|
|
88
|
-
* previous billing period; in this instance, the timeframe can start before the
|
|
89
|
-
* current period.
|
|
90
|
-
*
|
|
91
|
-
* ## API Limits
|
|
92
|
-
*
|
|
93
|
-
* Note that Orb does not currently enforce a hard rate- limit for API usage or a
|
|
94
|
-
* maximum request payload size. Similar to the event ingestion API, this API is
|
|
95
|
-
* architected for h igh-throughput ingestion. It is also safe to
|
|
96
|
-
* _programmatically_ call this endpoint if your system can automatically dete ct a
|
|
97
|
-
* need for historical amendment.
|
|
98
|
-
*
|
|
99
|
-
* In order to overwrite timeframes with a very large number of events, we suggest
|
|
100
|
-
* using multiple calls with small adjacent (e.g. every hour) timeframes.
|
|
101
|
-
*
|
|
102
|
-
* @deprecated This method will be removed in a future release. Please use the 'events.backfills.create' instead.
|
|
103
|
-
*/
|
|
104
|
-
update(id, params, options) {
|
|
105
|
-
const { timeframe_end, timeframe_start, ...body } = params;
|
|
106
|
-
return this._client.patch(`/customers/${id}/usage`, {
|
|
107
|
-
query: { timeframe_end, timeframe_start },
|
|
108
|
-
body,
|
|
109
|
-
...options,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* This endpoint is used to amend usage within a timeframe for a customer that has
|
|
114
|
-
* an active subscription.
|
|
115
|
-
*
|
|
116
|
-
* This endpoint will mark _all_ existing events within
|
|
117
|
-
* `[timeframe_start, timeframe_end)` as _ignored_ for billing purposes, and Orb
|
|
118
|
-
* will only use the _new_ events passed in the body of this request as the source
|
|
119
|
-
* of truth for that timeframe moving forwards. Note that a given time period can
|
|
120
|
-
* be amended any number of times, so events can be overwritten in subsequent calls
|
|
121
|
-
* to th is endpoint.
|
|
122
|
-
*
|
|
123
|
-
* This is a powerful and audit-safe mechanism to retroactively change usage data
|
|
124
|
-
* in cases where you need to:
|
|
125
|
-
*
|
|
126
|
-
* - decrease historical usage consumption because of degraded service availability
|
|
127
|
-
* in your systems
|
|
128
|
-
* - account for gaps from your usage reporting mechanism
|
|
129
|
-
* - make point-in-time fixes for specific event records, while retaining the
|
|
130
|
-
* original time of usage and associated metadata. This amendment API is designed
|
|
131
|
-
* with two explicit goals:
|
|
132
|
-
*
|
|
133
|
-
* 1. Amendments are **always audit-safe**. The amendment process will still retain
|
|
134
|
-
* original events in the timeframe, though they will be ignored for billing
|
|
135
|
-
* calculations. For auditing a nd data fidelity purposes, Orb never overwrites
|
|
136
|
-
* or permanently deletes ingested usage data.
|
|
137
|
-
* 2. Amendments always preserve data **consistency**. In other words, either an
|
|
138
|
-
* amendment is fully processed by the system (and the new events for the
|
|
139
|
-
* timeframe are honored rather than the existing ones) or the amendment request
|
|
140
|
-
* fails. To maintain this important property, Orb prevents _partial event
|
|
141
|
-
* ingestion_ on this endpoint.
|
|
142
|
-
*
|
|
143
|
-
* ## Response semantics
|
|
144
|
-
*
|
|
145
|
-
* - Either all events are ingested successfully, or all fail to ingest (returning
|
|
146
|
-
* a `4xx` or `5xx` response code).
|
|
147
|
-
* - Any event that fails schema validation will lead to a `4xx` response. In this
|
|
148
|
-
* case, to maintain data consistency, Orb will not ingest any events and will
|
|
149
|
-
* also not deprecate existing events in the time period.
|
|
150
|
-
* - You can assume that the amendment is successful on receipt of a `2xx`
|
|
151
|
-
* response.While a successful response from this endpoint indicates that the new
|
|
152
|
-
* events have been ingested, updating usage totals happens asynchronously and
|
|
153
|
-
* may be delayed by a few minutes.
|
|
154
|
-
*
|
|
155
|
-
* As emphasized above, Orb will never show an inconsistent state (e.g. in invoice
|
|
156
|
-
* previews or dashboards); either it will show the existing state (before the
|
|
157
|
-
* amendment) or the new state (with new events in the requested timeframe).
|
|
158
|
-
*
|
|
159
|
-
* ## Sample request body
|
|
160
|
-
*
|
|
161
|
-
* ```json
|
|
162
|
-
* {
|
|
163
|
-
* "events": [
|
|
164
|
-
* {
|
|
165
|
-
* "event_name": "payment_processed",
|
|
166
|
-
* "timestamp": "2022-03-24T07:15:00Z",
|
|
167
|
-
* "properties": {
|
|
168
|
-
* "amount": 100
|
|
169
|
-
* }
|
|
170
|
-
* },
|
|
171
|
-
* {
|
|
172
|
-
* "event_name": "payment_failed",
|
|
173
|
-
* "timestamp": "2022-03-24T07:15:00Z",
|
|
174
|
-
* "properties": {
|
|
175
|
-
* "amount": 100
|
|
176
|
-
* }
|
|
177
|
-
* }
|
|
178
|
-
* ]
|
|
179
|
-
* }
|
|
180
|
-
* ```
|
|
181
|
-
*
|
|
182
|
-
* ## Request Validation
|
|
183
|
-
*
|
|
184
|
-
* - The `timestamp` of each event reported must fall within the bounds of
|
|
185
|
-
* `timeframe_start` and `timeframe_end`. As with ingestion, all timesta mps must
|
|
186
|
-
* be sent in ISO8601 format with UTC timezone offset.
|
|
187
|
-
* - Orb **does not accept an `idempotency_key`** with each event in this endpoint,
|
|
188
|
-
* since the entirety of the event list must be ingested to ensure consistency.
|
|
189
|
-
* On retryable errors , you should retry the request in its entirety, and assume
|
|
190
|
-
* that the amendment operation has not succeeded until receipt of a `2xx`.
|
|
191
|
-
*
|
|
192
|
-
* - Both `timeframe_start` and `timeframe_end` must be timestamps in the past.
|
|
193
|
-
* Furthermore, Orb will genera lly validate that the `timeframe_start` and
|
|
194
|
-
* `timeframe_end` fall within the customer's _current_ subscription billing pe
|
|
195
|
-
* riod. However, Orb does allow amendments while in the grace period of the
|
|
196
|
-
* previous billing period; in this instance, the timeframe can start before the
|
|
197
|
-
* current period.
|
|
198
|
-
*
|
|
199
|
-
* ## API Limits
|
|
200
|
-
*
|
|
201
|
-
* Note that Orb does not currently enforce a hard rate- limit for API usage or a
|
|
202
|
-
* maximum request payload size. Similar to the event ingestion API, this API is
|
|
203
|
-
* architected for h igh-throughput ingestion. It is also safe to
|
|
204
|
-
* _programmatically_ call this endpoint if your system can automatically dete ct a
|
|
205
|
-
* need for historical amendment.
|
|
206
|
-
*
|
|
207
|
-
* In order to overwrite timeframes with a very large number of events, we suggest
|
|
208
|
-
* using multiple calls with small adjacent (e.g. every hour) timeframes.
|
|
209
|
-
*
|
|
210
|
-
* @deprecated This method will be removed in a future release. Please use the 'events.backfills.create' instead.
|
|
211
|
-
*/
|
|
212
|
-
updateByExternalId(id, params, options) {
|
|
213
|
-
const { timeframe_end, timeframe_start, ...body } = params;
|
|
214
|
-
return this._client.patch(`/customers/external_customer_id/${id}/usage`, {
|
|
215
|
-
query: { timeframe_end, timeframe_start },
|
|
216
|
-
body,
|
|
217
|
-
...options,
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
(function (Usage) {
|
|
222
|
-
})(Usage || (Usage = {}));
|
|
223
|
-
//# sourceMappingURL=usage.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usage.mjs","sourceRoot":"","sources":["../../src/resources/customers/usage.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;AAItB,MAAM,OAAO,KAAM,SAAQ,WAAW;IACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmGG;IACH,MAAM,CACJ,EAAU,EACV,MAAyB,EACzB,OAA6B;QAE7B,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,QAAQ,EAAE;YAClD,KAAK,EAAE,EAAE,aAAa,EAAE,eAAe,EAAE;YACzC,IAAI;YACJ,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmGG;IACH,kBAAkB,CAChB,EAAU,EACV,MAAqC,EACrC,OAA6B;QAE7B,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;QAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,QAAQ,EAAE;YACvE,KAAK,EAAE,EAAE,aAAa,EAAE,eAAe,EAAE;YACzC,IAAI;YACJ,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;CACF;AAsID,WAAiB,KAAK;AAKtB,CAAC,EALgB,KAAK,KAAL,KAAK,QAKrB"}
|