@onereach/billing-shared 31.13.1-beta.13318.0 → 31.14.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/dist/cjs/index.js +0 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/usage-cost-collection.js +15 -0
- package/dist/cjs/types/usage-cost-collection.js.map +1 -0
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/usage-cost-collection.js +12 -0
- package/dist/esm/types/usage-cost-collection.js.map +1 -0
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/usage-cost-collection.d.ts +42 -0
- package/dist/types/types/usage-cost-collection.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/types/index.ts +1 -0
- package/src/types/usage-cost-collection.ts +30 -0
- package/dist/cjs/billing-boundaries/index.js +0 -49
- package/dist/cjs/billing-boundaries/index.js.map +0 -1
- package/dist/cjs/billing-boundaries/types.js +0 -3
- package/dist/cjs/billing-boundaries/types.js.map +0 -1
- package/dist/cjs/usage-granularity/constants.js +0 -7
- package/dist/cjs/usage-granularity/constants.js.map +0 -1
- package/dist/cjs/usage-granularity/index.js +0 -23
- package/dist/cjs/usage-granularity/index.js.map +0 -1
- package/dist/cjs/usage-granularity/metric-policy.js +0 -45
- package/dist/cjs/usage-granularity/metric-policy.js.map +0 -1
- package/dist/cjs/usage-granularity/reporting.types.js +0 -3
- package/dist/cjs/usage-granularity/reporting.types.js.map +0 -1
- package/dist/cjs/usage-granularity/source-event-policy.js +0 -48
- package/dist/cjs/usage-granularity/source-event-policy.js.map +0 -1
- package/dist/cjs/usage-granularity/types.js +0 -3
- package/dist/cjs/usage-granularity/types.js.map +0 -1
- package/dist/cjs/usage-granularity/usage-granularity.js +0 -67
- package/dist/cjs/usage-granularity/usage-granularity.js.map +0 -1
- package/dist/esm/billing-boundaries/index.js +0 -42
- package/dist/esm/billing-boundaries/index.js.map +0 -1
- package/dist/esm/billing-boundaries/types.js +0 -2
- package/dist/esm/billing-boundaries/types.js.map +0 -1
- package/dist/esm/usage-granularity/constants.js +0 -4
- package/dist/esm/usage-granularity/constants.js.map +0 -1
- package/dist/esm/usage-granularity/index.js +0 -7
- package/dist/esm/usage-granularity/index.js.map +0 -1
- package/dist/esm/usage-granularity/metric-policy.js +0 -40
- package/dist/esm/usage-granularity/metric-policy.js.map +0 -1
- package/dist/esm/usage-granularity/reporting.types.js +0 -2
- package/dist/esm/usage-granularity/reporting.types.js.map +0 -1
- package/dist/esm/usage-granularity/source-event-policy.js +0 -43
- package/dist/esm/usage-granularity/source-event-policy.js.map +0 -1
- package/dist/esm/usage-granularity/types.js +0 -2
- package/dist/esm/usage-granularity/types.js.map +0 -1
- package/dist/esm/usage-granularity/usage-granularity.js +0 -60
- package/dist/esm/usage-granularity/usage-granularity.js.map +0 -1
- package/dist/types/billing-boundaries/index.d.ts +0 -6
- package/dist/types/billing-boundaries/index.d.ts.map +0 -1
- package/dist/types/billing-boundaries/types.d.ts +0 -9
- package/dist/types/billing-boundaries/types.d.ts.map +0 -1
- package/dist/types/usage-granularity/constants.d.ts +0 -4
- package/dist/types/usage-granularity/constants.d.ts.map +0 -1
- package/dist/types/usage-granularity/index.d.ts +0 -7
- package/dist/types/usage-granularity/index.d.ts.map +0 -1
- package/dist/types/usage-granularity/metric-policy.d.ts +0 -4
- package/dist/types/usage-granularity/metric-policy.d.ts.map +0 -1
- package/dist/types/usage-granularity/reporting.types.d.ts +0 -14
- package/dist/types/usage-granularity/reporting.types.d.ts.map +0 -1
- package/dist/types/usage-granularity/source-event-policy.d.ts +0 -7
- package/dist/types/usage-granularity/source-event-policy.d.ts.map +0 -1
- package/dist/types/usage-granularity/types.d.ts +0 -8
- package/dist/types/usage-granularity/types.d.ts.map +0 -1
- package/dist/types/usage-granularity/usage-granularity.d.ts +0 -7
- package/dist/types/usage-granularity/usage-granularity.d.ts.map +0 -1
- package/src/billing-boundaries/index.ts +0 -52
- package/src/billing-boundaries/types.ts +0 -9
- package/src/usage-granularity/constants.ts +0 -5
- package/src/usage-granularity/index.ts +0 -6
- package/src/usage-granularity/metric-policy.ts +0 -41
- package/src/usage-granularity/reporting.types.ts +0 -15
- package/src/usage-granularity/source-event-policy.ts +0 -45
- package/src/usage-granularity/types.ts +0 -9
- package/src/usage-granularity/usage-granularity.ts +0 -72
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { CategoryNamespace } from '../enums/category-namespace';
|
|
2
|
-
import { DataSourceProvider } from '../enums/customer-usage';
|
|
3
|
-
const COARSE_EVENTS = {
|
|
4
|
-
[DataSourceProvider.AZURE]: [
|
|
5
|
-
CategoryNamespace.PROCESSING_FLOW,
|
|
6
|
-
CategoryNamespace.PROCESSING_VOICE,
|
|
7
|
-
CategoryNamespace.EXECUTABLE_GENERAL,
|
|
8
|
-
CategoryNamespace.EXECUTABLE_PORT_IN_IDENTIFIER,
|
|
9
|
-
CategoryNamespace.LOOKUP,
|
|
10
|
-
CategoryNamespace.TELEPHONY_VOICE,
|
|
11
|
-
CategoryNamespace.MESSAGING_TEXT,
|
|
12
|
-
CategoryNamespace.CONVERSATIONS_WAP,
|
|
13
|
-
CategoryNamespace.CARRIER_FEE,
|
|
14
|
-
CategoryNamespace.USER,
|
|
15
|
-
CategoryNamespace.IDENTIFIER,
|
|
16
|
-
CategoryNamespace.STORAGE_GENERAL,
|
|
17
|
-
CategoryNamespace.STORAGE_WEAVIATE,
|
|
18
|
-
],
|
|
19
|
-
[DataSourceProvider.DRUID]: [
|
|
20
|
-
CategoryNamespace.EXECUTABLE_LLM,
|
|
21
|
-
CategoryNamespace.EXECUTABLE_GENERAL,
|
|
22
|
-
CategoryNamespace.STORAGE_WEAVIATE,
|
|
23
|
-
CategoryNamespace.LOOKUP,
|
|
24
|
-
CategoryNamespace.TELEPHONY_VOICE,
|
|
25
|
-
CategoryNamespace.PROCESSING_VOICE,
|
|
26
|
-
CategoryNamespace.CARRIER_FEE,
|
|
27
|
-
CategoryNamespace.MESSAGING_TEXT,
|
|
28
|
-
],
|
|
29
|
-
};
|
|
30
|
-
export function supportsCoarseUsageCollection(provider, eventType) {
|
|
31
|
-
if (provider !== DataSourceProvider.AZURE && provider !== DataSourceProvider.DRUID)
|
|
32
|
-
return false;
|
|
33
|
-
return COARSE_EVENTS[provider].includes(eventType);
|
|
34
|
-
}
|
|
35
|
-
export function assertUsageCollectionMetric(provider, eventType, hours) {
|
|
36
|
-
if (hours > 1 && !supportsCoarseUsageCollection(provider, eventType)) {
|
|
37
|
-
throw new Error(`Coarse collection is not verified for ${provider}/${eventType}; use 1h granularity`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=metric-policy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metric-policy.js","sourceRoot":"","sources":["../../../src/usage-granularity/metric-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,aAAa,GAA8F;IAC/G,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;QAC1B,iBAAiB,CAAC,eAAe;QACjC,iBAAiB,CAAC,gBAAgB;QAClC,iBAAiB,CAAC,kBAAkB;QACpC,iBAAiB,CAAC,6BAA6B;QAC/C,iBAAiB,CAAC,MAAM;QACxB,iBAAiB,CAAC,eAAe;QACjC,iBAAiB,CAAC,cAAc;QAChC,iBAAiB,CAAC,iBAAiB;QACnC,iBAAiB,CAAC,WAAW;QAC7B,iBAAiB,CAAC,IAAI;QACtB,iBAAiB,CAAC,UAAU;QAC5B,iBAAiB,CAAC,eAAe;QACjC,iBAAiB,CAAC,gBAAgB;KACnC;IACD,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;QAC1B,iBAAiB,CAAC,cAAc;QAChC,iBAAiB,CAAC,kBAAkB;QACpC,iBAAiB,CAAC,gBAAgB;QAClC,iBAAiB,CAAC,MAAM;QACxB,iBAAiB,CAAC,eAAe;QACjC,iBAAiB,CAAC,gBAAgB;QAClC,iBAAiB,CAAC,WAAW;QAC7B,iBAAiB,CAAC,cAAc;KACjC;CACF,CAAC;AAEF,MAAM,UAAU,6BAA6B,CAAC,QAAgB,EAAE,SAA4B;IAC1F,IAAI,QAAQ,KAAK,kBAAkB,CAAC,KAAK,IAAI,QAAQ,KAAK,kBAAkB,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACjG,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,QAAgB,EAAE,SAA4B,EAAE,KAAa;IACvG,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,6BAA6B,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,IAAI,SAAS,sBAAsB,CAAC,CAAC;IACxG,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reporting.types.js","sourceRoot":"","sources":["../../../src/usage-granularity/reporting.types.ts"],"names":[],"mappings":""}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { CategoryNamespace } from '../enums/category-namespace';
|
|
2
|
-
import { DataSourceProvider } from '../enums/customer-usage';
|
|
3
|
-
export const DB_EVENT_TYPE_MAP = {
|
|
4
|
-
[DataSourceProvider.AZURE]: [
|
|
5
|
-
CategoryNamespace.PROCESSING_FLOW,
|
|
6
|
-
CategoryNamespace.PROCESSING_VOICE,
|
|
7
|
-
CategoryNamespace.EXECUTABLE_GENERAL,
|
|
8
|
-
CategoryNamespace.EXECUTABLE_PORT_IN_IDENTIFIER,
|
|
9
|
-
CategoryNamespace.LOOKUP,
|
|
10
|
-
CategoryNamespace.TELEPHONY_VOICE,
|
|
11
|
-
CategoryNamespace.MESSAGING_TEXT,
|
|
12
|
-
CategoryNamespace.CONVERSATIONS_WAP,
|
|
13
|
-
CategoryNamespace.CARRIER_FEE,
|
|
14
|
-
CategoryNamespace.STORAGE_GENERAL,
|
|
15
|
-
CategoryNamespace.STORAGE_WEAVIATE,
|
|
16
|
-
CategoryNamespace.IDENTIFIER,
|
|
17
|
-
CategoryNamespace.USER,
|
|
18
|
-
CategoryNamespace.PRODUCT,
|
|
19
|
-
],
|
|
20
|
-
[DataSourceProvider.DRUID]: [
|
|
21
|
-
CategoryNamespace.EXECUTABLE_LLM,
|
|
22
|
-
CategoryNamespace.EXECUTABLE_GENERAL,
|
|
23
|
-
CategoryNamespace.STORAGE_WEAVIATE,
|
|
24
|
-
CategoryNamespace.LOOKUP,
|
|
25
|
-
CategoryNamespace.TELEPHONY_VOICE,
|
|
26
|
-
CategoryNamespace.PROCESSING_VOICE,
|
|
27
|
-
CategoryNamespace.CARRIER_FEE,
|
|
28
|
-
CategoryNamespace.MESSAGING_TEXT,
|
|
29
|
-
CategoryNamespace.PRODUCT,
|
|
30
|
-
],
|
|
31
|
-
};
|
|
32
|
-
const CATEGORY_NAMESPACES = new Set(Object.values(CategoryNamespace));
|
|
33
|
-
export function getDruidEventTypes(metadata) {
|
|
34
|
-
if (!Array.isArray(metadata === null || metadata === void 0 ? void 0 : metadata.tables))
|
|
35
|
-
return [];
|
|
36
|
-
const eventTypes = metadata.tables.flatMap(table => {
|
|
37
|
-
if (typeof table !== 'object' || table === null || !('eventTypes' in table))
|
|
38
|
-
return [];
|
|
39
|
-
return Array.isArray(table.eventTypes) ? table.eventTypes : [];
|
|
40
|
-
});
|
|
41
|
-
return Array.from(new Set(eventTypes.filter((eventType) => (typeof eventType === 'string' && CATEGORY_NAMESPACES.has(eventType)))));
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=source-event-policy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"source-event-policy.js","sourceRoot":"","sources":["../../../src/usage-granularity/source-event-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;QAC1B,iBAAiB,CAAC,eAAe;QACjC,iBAAiB,CAAC,gBAAgB;QAClC,iBAAiB,CAAC,kBAAkB;QACpC,iBAAiB,CAAC,6BAA6B;QAC/C,iBAAiB,CAAC,MAAM;QACxB,iBAAiB,CAAC,eAAe;QACjC,iBAAiB,CAAC,cAAc;QAChC,iBAAiB,CAAC,iBAAiB;QACnC,iBAAiB,CAAC,WAAW;QAC7B,iBAAiB,CAAC,eAAe;QACjC,iBAAiB,CAAC,gBAAgB;QAClC,iBAAiB,CAAC,UAAU;QAC5B,iBAAiB,CAAC,IAAI;QACtB,iBAAiB,CAAC,OAAO;KAC1B;IACD,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;QAC1B,iBAAiB,CAAC,cAAc;QAChC,iBAAiB,CAAC,kBAAkB;QACpC,iBAAiB,CAAC,gBAAgB;QAClC,iBAAiB,CAAC,MAAM;QACxB,iBAAiB,CAAC,eAAe;QACjC,iBAAiB,CAAC,gBAAgB;QAClC,iBAAiB,CAAC,WAAW;QAC7B,iBAAiB,CAAC,cAAc;QAChC,iBAAiB,CAAC,OAAO;KAC1B;CACF,CAAC;AAEF,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAE9E,MAAM,UAAU,kBAAkB,CAAC,QAAkC;IACnE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,CAAC;QAAE,OAAO,EAAE,CAAC;IAChD,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,YAAY,IAAI,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACvF,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAkC,EAAE,CAAC,CACzF,OAAO,SAAS,KAAK,QAAQ,IAAI,mBAAmB,CAAC,GAAG,CAAC,SAAS,CAAC,CACpE,CAAC,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/usage-granularity/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { USAGE_GRANULARITY_HOURS, USAGE_HOUR_MS } from './constants';
|
|
2
|
-
export function isUsageGranularityHours(value) {
|
|
3
|
-
return typeof value === 'number' && USAGE_GRANULARITY_HOURS.some(hours => hours === value);
|
|
4
|
-
}
|
|
5
|
-
export function getCompatibleUsageGranularity(hours) {
|
|
6
|
-
const compatible = USAGE_GRANULARITY_HOURS.find(candidate => hours.every(value => candidate % value === 0));
|
|
7
|
-
if (compatible === undefined)
|
|
8
|
-
throw new Error('No compatible usage granularity');
|
|
9
|
-
return compatible;
|
|
10
|
-
}
|
|
11
|
-
export function getUsageSlotStart(date, hours) {
|
|
12
|
-
const time = date.getTime();
|
|
13
|
-
if (!Number.isFinite(time) || !isUsageGranularityHours(hours)) {
|
|
14
|
-
throw new Error('Invalid usage slot date or granularity');
|
|
15
|
-
}
|
|
16
|
-
const duration = hours * USAGE_HOUR_MS;
|
|
17
|
-
return new Date(Math.floor(time / duration) * duration);
|
|
18
|
-
}
|
|
19
|
-
export function resolveUsageGranularity(state, now) {
|
|
20
|
-
if (!Number.isFinite(now.getTime()))
|
|
21
|
-
throw new Error('Invalid usage granularity date');
|
|
22
|
-
if (state.pendingGranularityHours !== null &&
|
|
23
|
-
state.granularityEffectiveAt !== null &&
|
|
24
|
-
new Date(state.granularityEffectiveAt).getTime() <= now.getTime()) {
|
|
25
|
-
return {
|
|
26
|
-
granularityHours: state.pendingGranularityHours,
|
|
27
|
-
pendingGranularityHours: null,
|
|
28
|
-
granularityEffectiveAt: null,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
granularityHours: state.granularityHours,
|
|
33
|
-
pendingGranularityHours: state.pendingGranularityHours,
|
|
34
|
-
granularityEffectiveAt: state.granularityEffectiveAt,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
export function scheduleUsageGranularity(state, requested, now) {
|
|
38
|
-
const current = resolveUsageGranularity(state, now);
|
|
39
|
-
if (requested === undefined)
|
|
40
|
-
return current;
|
|
41
|
-
if (!isUsageGranularityHours(requested))
|
|
42
|
-
throw new Error('Invalid usage granularity');
|
|
43
|
-
if (requested === current.granularityHours) {
|
|
44
|
-
return {
|
|
45
|
-
granularityHours: requested,
|
|
46
|
-
pendingGranularityHours: null,
|
|
47
|
-
granularityEffectiveAt: null,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (requested === current.pendingGranularityHours)
|
|
51
|
-
return current;
|
|
52
|
-
const sharedHours = getCompatibleUsageGranularity([current.granularityHours, requested]);
|
|
53
|
-
const boundary = getUsageSlotStart(now, sharedHours);
|
|
54
|
-
return {
|
|
55
|
-
granularityHours: current.granularityHours,
|
|
56
|
-
pendingGranularityHours: requested,
|
|
57
|
-
granularityEffectiveAt: new Date(boundary.getTime() + sharedHours * USAGE_HOUR_MS),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=usage-granularity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usage-granularity.js","sourceRoot":"","sources":["../../../src/usage-granularity/usage-granularity.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { BillingDateIssue, BillingDateValidationOptions } from './types';
|
|
2
|
-
export declare function isUtcMidnight(value: unknown): value is Date;
|
|
3
|
-
export declare function isUtcInclusiveDateEnd(value: unknown): value is Date;
|
|
4
|
-
export declare function toExclusiveUtcDateEnd(value: Date): Date;
|
|
5
|
-
export declare function getUtcBillingDateIssues(startDate: unknown, endDate: unknown, options?: BillingDateValidationOptions): BillingDateIssue[];
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/billing-boundaries/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAI9E,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAE3D;AAGD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAKnE;AAGD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,CAKvD;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,4BAAiC,GACzC,gBAAgB,EAAE,CAuBpB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/billing-boundaries/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,4BAA4B;IAC3C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/usage-granularity/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,qCAAsC,CAAC;AAE3E,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAEjD,eAAO,MAAM,aAAa,UAAU,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/usage-granularity/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { CategoryNamespace } from '../enums/category-namespace';
|
|
2
|
-
export declare function supportsCoarseUsageCollection(provider: string, eventType: CategoryNamespace): boolean;
|
|
3
|
-
export declare function assertUsageCollectionMetric(provider: string, eventType: CategoryNamespace, hours: number): void;
|
|
4
|
-
//# sourceMappingURL=metric-policy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metric-policy.d.ts","sourceRoot":"","sources":["../../../src/usage-granularity/metric-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AA+BhE,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAGrG;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAI/G"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { UsageGranularityHours } from './types';
|
|
2
|
-
export type UsageResolutionAdjustment = 'granularityExpanded' | 'rangeExpanded' | 'unknownCoverage' | 'providerOverlapExcluded';
|
|
3
|
-
export interface UsageResolutionMetadata {
|
|
4
|
-
requestedGranularityHours: UsageGranularityHours;
|
|
5
|
-
effectiveGranularityHours: UsageGranularityHours;
|
|
6
|
-
requestedDateFrom: string;
|
|
7
|
-
requestedDateTo: string;
|
|
8
|
-
effectiveDateFrom: string;
|
|
9
|
-
effectiveDateTo: string;
|
|
10
|
-
adjustments: UsageResolutionAdjustment[];
|
|
11
|
-
coverageStatus: 'known' | 'partial' | 'unknown';
|
|
12
|
-
coverageVersion: string;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=reporting.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reporting.types.d.ts","sourceRoot":"","sources":["../../../src/usage-granularity/reporting.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,GAAG,eAAe,GAAG,iBAAiB,GAAG,yBAAyB,CAAC;AAEhI,MAAM,WAAW,uBAAuB;IACtC,yBAAyB,EAAE,qBAAqB,CAAC;IACjD,yBAAyB,EAAE,qBAAqB,CAAC;IACjD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,yBAAyB,EAAE,CAAC;IACzC,cAAc,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;IAChD,eAAe,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CategoryNamespace } from '../enums/category-namespace';
|
|
2
|
-
export declare const DB_EVENT_TYPE_MAP: {
|
|
3
|
-
azure: CategoryNamespace[];
|
|
4
|
-
druid: CategoryNamespace[];
|
|
5
|
-
};
|
|
6
|
-
export declare function getDruidEventTypes(metadata?: Record<string, unknown>): CategoryNamespace[];
|
|
7
|
-
//# sourceMappingURL=source-event-policy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"source-event-policy.d.ts","sourceRoot":"","sources":["../../../src/usage-granularity/source-event-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE,eAAO,MAAM,iBAAiB;;;CA4B7B,CAAC;AAIF,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,iBAAiB,EAAE,CAS1F"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { USAGE_GRANULARITY_HOURS } from './constants';
|
|
2
|
-
export type UsageGranularityHours = typeof USAGE_GRANULARITY_HOURS[number];
|
|
3
|
-
export type UsageGranularityState = {
|
|
4
|
-
granularityHours: UsageGranularityHours;
|
|
5
|
-
pendingGranularityHours: UsageGranularityHours | null;
|
|
6
|
-
granularityEffectiveAt: Date | null;
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/usage-granularity/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,MAAM,MAAM,qBAAqB,GAAG,OAAO,uBAAuB,CAAC,MAAM,CAAC,CAAC;AAE3E,MAAM,MAAM,qBAAqB,GAAG;IAClC,gBAAgB,EAAE,qBAAqB,CAAC;IACxC,uBAAuB,EAAE,qBAAqB,GAAG,IAAI,CAAC;IACtD,sBAAsB,EAAE,IAAI,GAAG,IAAI,CAAC;CACrC,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { UsageGranularityHours, UsageGranularityState } from './types';
|
|
2
|
-
export declare function isUsageGranularityHours(value: unknown): value is UsageGranularityHours;
|
|
3
|
-
export declare function getCompatibleUsageGranularity(hours: readonly UsageGranularityHours[]): UsageGranularityHours;
|
|
4
|
-
export declare function getUsageSlotStart(date: Date, hours: UsageGranularityHours): Date;
|
|
5
|
-
export declare function resolveUsageGranularity(state: UsageGranularityState, now: Date): UsageGranularityState;
|
|
6
|
-
export declare function scheduleUsageGranularity(state: UsageGranularityState, requested: UsageGranularityHours | undefined, now: Date): UsageGranularityState;
|
|
7
|
-
//# sourceMappingURL=usage-granularity.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usage-granularity.d.ts","sourceRoot":"","sources":["../../../src/usage-granularity/usage-granularity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE5E,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB,CAEtF;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,SAAS,qBAAqB,EAAE,GACtC,qBAAqB,CAIvB;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,qBAAqB,GAAG,IAAI,CAOhF;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,qBAAqB,EAC5B,GAAG,EAAE,IAAI,GACR,qBAAqB,CAkBvB;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,qBAAqB,EAC5B,SAAS,EAAE,qBAAqB,GAAG,SAAS,EAC5C,GAAG,EAAE,IAAI,GACR,qBAAqB,CAoBvB"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { BillingDateIssue, BillingDateValidationOptions } from './types';
|
|
2
|
-
|
|
3
|
-
const UTC_DAY_MS = 24 * 60 * 60 * 1000;
|
|
4
|
-
|
|
5
|
-
export function isUtcMidnight(value: unknown): value is Date {
|
|
6
|
-
return value instanceof Date && Number.isFinite(value.getTime()) && value.getTime() % UTC_DAY_MS === 0;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** Inclusive calendar ends accept the API's date-only and UTC end-of-day conventions. */
|
|
10
|
-
export function isUtcInclusiveDateEnd(value: unknown): value is Date {
|
|
11
|
-
if (!(value instanceof Date) || !Number.isFinite(value.getTime())) return false;
|
|
12
|
-
const time = value.getTime();
|
|
13
|
-
return (isUtcMidnight(value) || (time + 1) % UTC_DAY_MS === 0)
|
|
14
|
-
&& Number.isFinite(new Date(Math.floor(time / UTC_DAY_MS) * UTC_DAY_MS + UTC_DAY_MS).getTime());
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Convert an inclusive UTC calendar end to the next midnight, without changing stored dates. */
|
|
18
|
-
export function toExclusiveUtcDateEnd(value: Date): Date {
|
|
19
|
-
if (!isUtcInclusiveDateEnd(value)) {
|
|
20
|
-
throw new RangeError('Billing end date must be a UTC calendar date or UTC end of day');
|
|
21
|
-
}
|
|
22
|
-
return new Date(Math.floor(value.getTime() / UTC_DAY_MS) * UTC_DAY_MS + UTC_DAY_MS);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function getUtcBillingDateIssues(
|
|
26
|
-
startDate: unknown,
|
|
27
|
-
endDate: unknown,
|
|
28
|
-
options: BillingDateValidationOptions = {},
|
|
29
|
-
): BillingDateIssue[] {
|
|
30
|
-
const issues: BillingDateIssue[] = [];
|
|
31
|
-
const prefix = options.pathPrefix ? `${options.pathPrefix}.` : '';
|
|
32
|
-
if (!isUtcMidnight(startDate)) {
|
|
33
|
-
issues.push({
|
|
34
|
-
path: `${prefix}startDate`,
|
|
35
|
-
constraints: { utcMidnight: 'Start date must be a valid date at midnight UTC' },
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
const openEnd = options.allowOpenEnd && (endDate === null || endDate === undefined);
|
|
39
|
-
if (!openEnd && !isUtcInclusiveDateEnd(endDate)) {
|
|
40
|
-
issues.push({
|
|
41
|
-
path: `${prefix}endDate`,
|
|
42
|
-
constraints: { utcCalendarEnd: 'End date must be a valid UTC calendar date at midnight or 23:59:59.999 UTC (inclusive)' },
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
if (isUtcMidnight(startDate) && isUtcInclusiveDateEnd(endDate) && toExclusiveUtcDateEnd(endDate) <= startDate) {
|
|
46
|
-
issues.push({
|
|
47
|
-
path: `${prefix}endDate`,
|
|
48
|
-
constraints: { minDate: 'End date must not be before the start date' },
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return issues;
|
|
52
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { CategoryNamespace } from '../enums/category-namespace';
|
|
2
|
-
import { DataSourceProvider } from '../enums/customer-usage';
|
|
3
|
-
|
|
4
|
-
const COARSE_EVENTS: Record<DataSourceProvider.AZURE | DataSourceProvider.DRUID, readonly CategoryNamespace[]> = {
|
|
5
|
-
[DataSourceProvider.AZURE]: [
|
|
6
|
-
CategoryNamespace.PROCESSING_FLOW,
|
|
7
|
-
CategoryNamespace.PROCESSING_VOICE,
|
|
8
|
-
CategoryNamespace.EXECUTABLE_GENERAL,
|
|
9
|
-
CategoryNamespace.EXECUTABLE_PORT_IN_IDENTIFIER,
|
|
10
|
-
CategoryNamespace.LOOKUP,
|
|
11
|
-
CategoryNamespace.TELEPHONY_VOICE,
|
|
12
|
-
CategoryNamespace.MESSAGING_TEXT,
|
|
13
|
-
CategoryNamespace.CONVERSATIONS_WAP,
|
|
14
|
-
CategoryNamespace.CARRIER_FEE,
|
|
15
|
-
CategoryNamespace.USER,
|
|
16
|
-
CategoryNamespace.IDENTIFIER,
|
|
17
|
-
CategoryNamespace.STORAGE_GENERAL,
|
|
18
|
-
CategoryNamespace.STORAGE_WEAVIATE,
|
|
19
|
-
],
|
|
20
|
-
[DataSourceProvider.DRUID]: [
|
|
21
|
-
CategoryNamespace.EXECUTABLE_LLM,
|
|
22
|
-
CategoryNamespace.EXECUTABLE_GENERAL,
|
|
23
|
-
CategoryNamespace.STORAGE_WEAVIATE,
|
|
24
|
-
CategoryNamespace.LOOKUP,
|
|
25
|
-
CategoryNamespace.TELEPHONY_VOICE,
|
|
26
|
-
CategoryNamespace.PROCESSING_VOICE,
|
|
27
|
-
CategoryNamespace.CARRIER_FEE,
|
|
28
|
-
CategoryNamespace.MESSAGING_TEXT,
|
|
29
|
-
],
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export function supportsCoarseUsageCollection(provider: string, eventType: CategoryNamespace): boolean {
|
|
33
|
-
if (provider !== DataSourceProvider.AZURE && provider !== DataSourceProvider.DRUID) return false;
|
|
34
|
-
return COARSE_EVENTS[provider].includes(eventType);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function assertUsageCollectionMetric(provider: string, eventType: CategoryNamespace, hours: number): void {
|
|
38
|
-
if (hours > 1 && !supportsCoarseUsageCollection(provider, eventType)) {
|
|
39
|
-
throw new Error(`Coarse collection is not verified for ${provider}/${eventType}; use 1h granularity`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { UsageGranularityHours } from './types';
|
|
2
|
-
|
|
3
|
-
export type UsageResolutionAdjustment = 'granularityExpanded' | 'rangeExpanded' | 'unknownCoverage' | 'providerOverlapExcluded';
|
|
4
|
-
|
|
5
|
-
export interface UsageResolutionMetadata {
|
|
6
|
-
requestedGranularityHours: UsageGranularityHours;
|
|
7
|
-
effectiveGranularityHours: UsageGranularityHours;
|
|
8
|
-
requestedDateFrom: string;
|
|
9
|
-
requestedDateTo: string;
|
|
10
|
-
effectiveDateFrom: string;
|
|
11
|
-
effectiveDateTo: string;
|
|
12
|
-
adjustments: UsageResolutionAdjustment[];
|
|
13
|
-
coverageStatus: 'known' | 'partial' | 'unknown';
|
|
14
|
-
coverageVersion: string;
|
|
15
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { CategoryNamespace } from '../enums/category-namespace';
|
|
2
|
-
import { DataSourceProvider } from '../enums/customer-usage';
|
|
3
|
-
|
|
4
|
-
export const DB_EVENT_TYPE_MAP = {
|
|
5
|
-
[DataSourceProvider.AZURE]: [
|
|
6
|
-
CategoryNamespace.PROCESSING_FLOW,
|
|
7
|
-
CategoryNamespace.PROCESSING_VOICE,
|
|
8
|
-
CategoryNamespace.EXECUTABLE_GENERAL,
|
|
9
|
-
CategoryNamespace.EXECUTABLE_PORT_IN_IDENTIFIER,
|
|
10
|
-
CategoryNamespace.LOOKUP,
|
|
11
|
-
CategoryNamespace.TELEPHONY_VOICE,
|
|
12
|
-
CategoryNamespace.MESSAGING_TEXT,
|
|
13
|
-
CategoryNamespace.CONVERSATIONS_WAP,
|
|
14
|
-
CategoryNamespace.CARRIER_FEE,
|
|
15
|
-
CategoryNamespace.STORAGE_GENERAL,
|
|
16
|
-
CategoryNamespace.STORAGE_WEAVIATE,
|
|
17
|
-
CategoryNamespace.IDENTIFIER,
|
|
18
|
-
CategoryNamespace.USER,
|
|
19
|
-
CategoryNamespace.PRODUCT,
|
|
20
|
-
],
|
|
21
|
-
[DataSourceProvider.DRUID]: [
|
|
22
|
-
CategoryNamespace.EXECUTABLE_LLM,
|
|
23
|
-
CategoryNamespace.EXECUTABLE_GENERAL,
|
|
24
|
-
CategoryNamespace.STORAGE_WEAVIATE,
|
|
25
|
-
CategoryNamespace.LOOKUP,
|
|
26
|
-
CategoryNamespace.TELEPHONY_VOICE,
|
|
27
|
-
CategoryNamespace.PROCESSING_VOICE,
|
|
28
|
-
CategoryNamespace.CARRIER_FEE,
|
|
29
|
-
CategoryNamespace.MESSAGING_TEXT,
|
|
30
|
-
CategoryNamespace.PRODUCT,
|
|
31
|
-
],
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const CATEGORY_NAMESPACES = new Set<string>(Object.values(CategoryNamespace));
|
|
35
|
-
|
|
36
|
-
export function getDruidEventTypes(metadata?: Record<string, unknown>): CategoryNamespace[] {
|
|
37
|
-
if (!Array.isArray(metadata?.tables)) return [];
|
|
38
|
-
const eventTypes = metadata.tables.flatMap(table => {
|
|
39
|
-
if (typeof table !== 'object' || table === null || !('eventTypes' in table)) return [];
|
|
40
|
-
return Array.isArray(table.eventTypes) ? table.eventTypes : [];
|
|
41
|
-
});
|
|
42
|
-
return Array.from(new Set(eventTypes.filter((eventType): eventType is CategoryNamespace => (
|
|
43
|
-
typeof eventType === 'string' && CATEGORY_NAMESPACES.has(eventType)
|
|
44
|
-
))));
|
|
45
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { USAGE_GRANULARITY_HOURS } from './constants';
|
|
2
|
-
|
|
3
|
-
export type UsageGranularityHours = typeof USAGE_GRANULARITY_HOURS[number];
|
|
4
|
-
|
|
5
|
-
export type UsageGranularityState = {
|
|
6
|
-
granularityHours: UsageGranularityHours;
|
|
7
|
-
pendingGranularityHours: UsageGranularityHours | null;
|
|
8
|
-
granularityEffectiveAt: Date | null;
|
|
9
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { USAGE_GRANULARITY_HOURS, USAGE_HOUR_MS } from './constants';
|
|
2
|
-
import type { UsageGranularityHours, UsageGranularityState } from './types';
|
|
3
|
-
|
|
4
|
-
export function isUsageGranularityHours(value: unknown): value is UsageGranularityHours {
|
|
5
|
-
return typeof value === 'number' && USAGE_GRANULARITY_HOURS.some(hours => hours === value);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function getCompatibleUsageGranularity(
|
|
9
|
-
hours: readonly UsageGranularityHours[],
|
|
10
|
-
): UsageGranularityHours {
|
|
11
|
-
const compatible = USAGE_GRANULARITY_HOURS.find(candidate => hours.every(value => candidate % value === 0));
|
|
12
|
-
if (compatible === undefined) throw new Error('No compatible usage granularity');
|
|
13
|
-
return compatible;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function getUsageSlotStart(date: Date, hours: UsageGranularityHours): Date {
|
|
17
|
-
const time = date.getTime();
|
|
18
|
-
if (!Number.isFinite(time) || !isUsageGranularityHours(hours)) {
|
|
19
|
-
throw new Error('Invalid usage slot date or granularity');
|
|
20
|
-
}
|
|
21
|
-
const duration = hours * USAGE_HOUR_MS;
|
|
22
|
-
return new Date(Math.floor(time / duration) * duration);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function resolveUsageGranularity(
|
|
26
|
-
state: UsageGranularityState,
|
|
27
|
-
now: Date,
|
|
28
|
-
): UsageGranularityState {
|
|
29
|
-
if (!Number.isFinite(now.getTime())) throw new Error('Invalid usage granularity date');
|
|
30
|
-
if (
|
|
31
|
-
state.pendingGranularityHours !== null &&
|
|
32
|
-
state.granularityEffectiveAt !== null &&
|
|
33
|
-
new Date(state.granularityEffectiveAt).getTime() <= now.getTime()
|
|
34
|
-
) {
|
|
35
|
-
return {
|
|
36
|
-
granularityHours: state.pendingGranularityHours,
|
|
37
|
-
pendingGranularityHours: null,
|
|
38
|
-
granularityEffectiveAt: null,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
granularityHours: state.granularityHours,
|
|
43
|
-
pendingGranularityHours: state.pendingGranularityHours,
|
|
44
|
-
granularityEffectiveAt: state.granularityEffectiveAt,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function scheduleUsageGranularity(
|
|
49
|
-
state: UsageGranularityState,
|
|
50
|
-
requested: UsageGranularityHours | undefined,
|
|
51
|
-
now: Date,
|
|
52
|
-
): UsageGranularityState {
|
|
53
|
-
const current = resolveUsageGranularity(state, now);
|
|
54
|
-
if (requested === undefined) return current;
|
|
55
|
-
if (!isUsageGranularityHours(requested)) throw new Error('Invalid usage granularity');
|
|
56
|
-
if (requested === current.granularityHours) {
|
|
57
|
-
return {
|
|
58
|
-
granularityHours: requested,
|
|
59
|
-
pendingGranularityHours: null,
|
|
60
|
-
granularityEffectiveAt: null,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
if (requested === current.pendingGranularityHours) return current;
|
|
64
|
-
|
|
65
|
-
const sharedHours = getCompatibleUsageGranularity([current.granularityHours, requested]);
|
|
66
|
-
const boundary = getUsageSlotStart(now, sharedHours);
|
|
67
|
-
return {
|
|
68
|
-
granularityHours: current.granularityHours,
|
|
69
|
-
pendingGranularityHours: requested,
|
|
70
|
-
granularityEffectiveAt: new Date(boundary.getTime() + sharedHours * USAGE_HOUR_MS),
|
|
71
|
-
};
|
|
72
|
-
}
|