@qcobro/common 1.12.4 → 1.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/billing/evaluate.d.ts +36 -0
- package/dist/billing/evaluate.d.ts.map +1 -0
- package/dist/billing/evaluate.js +136 -0
- package/dist/billing/evaluate.js.map +1 -0
- package/dist/billing/index.d.ts +7 -0
- package/dist/billing/index.d.ts.map +1 -0
- package/dist/billing/index.js +7 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/billing/ledger.d.ts +70 -0
- package/dist/billing/ledger.d.ts.map +1 -0
- package/dist/billing/ledger.js +59 -0
- package/dist/billing/ledger.js.map +1 -0
- package/dist/billing/money.d.ts +26 -0
- package/dist/billing/money.d.ts.map +1 -0
- package/dist/billing/money.js +58 -0
- package/dist/billing/money.js.map +1 -0
- package/dist/billing/pricing.d.ts +58 -0
- package/dist/billing/pricing.d.ts.map +1 -0
- package/dist/billing/pricing.js +68 -0
- package/dist/billing/pricing.js.map +1 -0
- package/dist/billing/proration.d.ts +8 -0
- package/dist/billing/proration.d.ts.map +1 -0
- package/dist/billing/proration.js +17 -0
- package/dist/billing/proration.js.map +1 -0
- package/dist/billing/rates.d.ts +108 -0
- package/dist/billing/rates.d.ts.map +1 -0
- package/dist/billing/rates.js +56 -0
- package/dist/billing/rates.js.map +1 -0
- package/dist/bin/engineEval.d.ts +67 -0
- package/dist/bin/engineEval.d.ts.map +1 -0
- package/dist/bin/engineEval.js +290 -0
- package/dist/bin/engineEval.js.map +1 -0
- package/dist/config.d.ts +141 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +70 -2
- package/dist/config.js.map +1 -1
- package/dist/evaluation/evaluate.d.ts +4 -0
- package/dist/evaluation/evaluate.d.ts.map +1 -0
- package/dist/evaluation/evaluate.js +504 -0
- package/dist/evaluation/evaluate.js.map +1 -0
- package/dist/evaluation/index.d.ts +3 -0
- package/dist/evaluation/index.d.ts.map +1 -0
- package/dist/evaluation/index.js +3 -0
- package/dist/evaluation/index.js.map +1 -0
- package/dist/evaluation/scorecard.d.ts +84 -0
- package/dist/evaluation/scorecard.d.ts.map +1 -0
- package/dist/evaluation/scorecard.js +29 -0
- package/dist/evaluation/scorecard.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/schemas/billing.d.ts +74 -0
- package/dist/schemas/billing.d.ts.map +1 -0
- package/dist/schemas/billing.js +68 -0
- package/dist/schemas/billing.js.map +1 -0
- package/dist/schemas/engineEvents.d.ts +407 -0
- package/dist/schemas/engineEvents.d.ts.map +1 -0
- package/dist/schemas/engineEvents.js +179 -0
- package/dist/schemas/engineEvents.js.map +1 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +2 -0
- package/dist/schemas/index.js.map +1 -1
- package/dist/types/billing.d.ts +134 -0
- package/dist/types/billing.d.ts.map +1 -0
- package/dist/types/billing.js +8 -0
- package/dist/types/billing.js.map +1 -0
- package/dist/types/engine.d.ts +13 -2
- package/dist/types/engine.d.ts.map +1 -1
- package/dist/types/engine.js +12 -1
- package/dist/types/engine.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/pacing.d.ts +17 -0
- package/dist/utils/pacing.d.ts.map +1 -0
- package/dist/utils/pacing.js +18 -0
- package/dist/utils/pacing.js.map +1 -0
- package/dist/utils/time.d.ts +16 -0
- package/dist/utils/time.d.ts.map +1 -1
- package/dist/utils/time.js +17 -0
- package/dist/utils/time.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { dispatchChannelSchema } from "./dispatch.js";
|
|
3
|
+
/**
|
|
4
|
+
* Engine flight-recorder events. The engine (and the inbound provider webhooks)
|
|
5
|
+
* emit these as an append-only stream; the pure evaluator in `../evaluation/`
|
|
6
|
+
* replays a stream to prove a run stayed within parameters. Events are
|
|
7
|
+
* self-contained: `campaign.evaluated` snapshots the config in force that tick,
|
|
8
|
+
* so evaluating never requires reading live campaign rows.
|
|
9
|
+
*
|
|
10
|
+
* Correlation spine: `tickId` + `seq` order events within a tick;
|
|
11
|
+
* `workspaceRef`/`campaignId`/`portfolioAccountId`/`providerRef` tie them to the
|
|
12
|
+
* domain. Only tick lifecycle events are deployment-level (one engine loop ticks
|
|
13
|
+
* across all workspaces) — everything else carries `workspaceRef`.
|
|
14
|
+
*
|
|
15
|
+
* Privacy: recipient identifiers are masked (see `maskRecipient`); rendered
|
|
16
|
+
* bodies, scripts, and transcripts never enter the stream (they live on the
|
|
17
|
+
* gestión).
|
|
18
|
+
*/
|
|
19
|
+
export const engineEventKindSchema = z.enum([
|
|
20
|
+
"tick.started",
|
|
21
|
+
"tick.completed",
|
|
22
|
+
"campaign.evaluated",
|
|
23
|
+
"account.decided",
|
|
24
|
+
"attempt.reserved",
|
|
25
|
+
"dispatch.requested",
|
|
26
|
+
"dispatch.succeeded",
|
|
27
|
+
"dispatch.failed",
|
|
28
|
+
"provider.event"
|
|
29
|
+
]);
|
|
30
|
+
/** Fields every event carries; the correlation spine. */
|
|
31
|
+
const eventBase = z.object({
|
|
32
|
+
/** Unique event id (uuid or `<tickId>#<seq>`); violations reference these. */
|
|
33
|
+
id: z.string().min(1),
|
|
34
|
+
/** Event instant (engine clock for tick events, receipt time for provider events), ISO. */
|
|
35
|
+
at: z.string().min(1),
|
|
36
|
+
/** The tick this event belongs to; absent on provider events (they arrive between ticks). */
|
|
37
|
+
tickId: z.string().optional(),
|
|
38
|
+
/** Monotonic order within the tick. */
|
|
39
|
+
seq: z.number().int().nonnegative().optional()
|
|
40
|
+
});
|
|
41
|
+
/** Spine fields for events owned by a workspace (all non-tick events). */
|
|
42
|
+
const workspaceScoped = eventBase.extend({
|
|
43
|
+
workspaceRef: z.string().min(1)
|
|
44
|
+
});
|
|
45
|
+
/** Per-channel numbers keyed by engine channel. */
|
|
46
|
+
const perChannel = (value) => z.partialRecord(dispatchChannelSchema, value);
|
|
47
|
+
/** Snapshot of the campaign parameters in force during a tick (self-contained stream). */
|
|
48
|
+
export const campaignSnapshotSchema = z.object({
|
|
49
|
+
status: z.string(),
|
|
50
|
+
/** Local calendar bounds as ISO instants (the engine's stored campaign dates). */
|
|
51
|
+
startDate: z.string(),
|
|
52
|
+
endDate: z.string().nullable(),
|
|
53
|
+
/** ISO weekdays (1 = Monday … 7 = Sunday). */
|
|
54
|
+
daysOfWeek: z.array(z.number().int().min(1).max(7)),
|
|
55
|
+
/** Local wall-clock bounds, `HH:MM` 24h. */
|
|
56
|
+
startTime: z.string(),
|
|
57
|
+
endTime: z.string(),
|
|
58
|
+
maxAttemptsPerAccount: z.number().int().nonnegative(),
|
|
59
|
+
maxAttemptsPerDay: z.number().int().nonnegative(),
|
|
60
|
+
/** IANA timezone of the campaign's workspace (drives window + daily-cap math). */
|
|
61
|
+
timezone: z.string(),
|
|
62
|
+
channel: dispatchChannelSchema.nullable()
|
|
63
|
+
});
|
|
64
|
+
const tickStartedSchema = eventBase.extend({
|
|
65
|
+
kind: z.literal("tick.started"),
|
|
66
|
+
/** Tokens granted per channel this tick (perTickCapacity of the per-minute rates). */
|
|
67
|
+
budgets: perChannel(z.number().int().nonnegative()),
|
|
68
|
+
/** The deployment-wide per-tick dispatch cap, when configured. */
|
|
69
|
+
perTickMax: z.number().int().nonnegative().optional()
|
|
70
|
+
});
|
|
71
|
+
const tickCompletedSchema = eventBase.extend({
|
|
72
|
+
kind: z.literal("tick.completed"),
|
|
73
|
+
durationMs: z.number().nonnegative(),
|
|
74
|
+
/** Total dispatches across all workspaces this tick. */
|
|
75
|
+
dispatched: z.number().int().nonnegative(),
|
|
76
|
+
/** Whether the deployment-wide per-tick cap was hit (skews budget-utilization checks). */
|
|
77
|
+
perTickMaxReached: z.boolean(),
|
|
78
|
+
/**
|
|
79
|
+
* Tokens consumed vs granted per bucket (`dispatched` = consumed — a failed
|
|
80
|
+
* dispatch still spends its token). The voice channels share one bucket whose
|
|
81
|
+
* consumption is reported on VOICE_AI.
|
|
82
|
+
*/
|
|
83
|
+
channelUsage: perChannel(z.object({ dispatched: z.number().int().nonnegative(), budget: z.number().int().nonnegative() }))
|
|
84
|
+
});
|
|
85
|
+
const campaignEvaluatedSchema = workspaceScoped.extend({
|
|
86
|
+
kind: z.literal("campaign.evaluated"),
|
|
87
|
+
campaignId: z.string().min(1),
|
|
88
|
+
/** Display name at evaluation time — scorecards read it so consumers never join back. */
|
|
89
|
+
campaignName: z.string().optional(),
|
|
90
|
+
inWindow: z.boolean(),
|
|
91
|
+
skipReason: z.string().optional(),
|
|
92
|
+
/** Set when the engine auto-completed the campaign this tick. */
|
|
93
|
+
completed: z.boolean().optional(),
|
|
94
|
+
/** Candidates loaded for the campaign (0 when skipped before loading). */
|
|
95
|
+
candidateCount: z.number().int().nonnegative(),
|
|
96
|
+
snapshot: campaignSnapshotSchema
|
|
97
|
+
});
|
|
98
|
+
const accountDecidedSchema = workspaceScoped.extend({
|
|
99
|
+
kind: z.literal("account.decided"),
|
|
100
|
+
campaignId: z.string().min(1),
|
|
101
|
+
portfolioAccountId: z.string().min(1),
|
|
102
|
+
/** An `AccountDecision` (`dispatched`, `budget_exhausted`, suppression reasons, …). */
|
|
103
|
+
decision: z.string().min(1),
|
|
104
|
+
providerRef: z.string().optional()
|
|
105
|
+
});
|
|
106
|
+
const attemptReservedSchema = workspaceScoped.extend({
|
|
107
|
+
kind: z.literal("attempt.reserved"),
|
|
108
|
+
campaignId: z.string().min(1),
|
|
109
|
+
portfolioAccountId: z.string().min(1)
|
|
110
|
+
});
|
|
111
|
+
const dispatchRequestedSchema = workspaceScoped.extend({
|
|
112
|
+
kind: z.literal("dispatch.requested"),
|
|
113
|
+
campaignId: z.string().min(1),
|
|
114
|
+
portfolioAccountId: z.string().min(1),
|
|
115
|
+
channel: dispatchChannelSchema,
|
|
116
|
+
/** Masked recipient (see `maskRecipient`) — never the full identifier. */
|
|
117
|
+
toMasked: z.string()
|
|
118
|
+
});
|
|
119
|
+
const dispatchSucceededSchema = workspaceScoped.extend({
|
|
120
|
+
kind: z.literal("dispatch.succeeded"),
|
|
121
|
+
campaignId: z.string().min(1),
|
|
122
|
+
portfolioAccountId: z.string().min(1),
|
|
123
|
+
channel: dispatchChannelSchema,
|
|
124
|
+
providerRef: z.string().min(1),
|
|
125
|
+
latencyMs: z.number().nonnegative(),
|
|
126
|
+
toMasked: z.string()
|
|
127
|
+
});
|
|
128
|
+
const dispatchFailedSchema = workspaceScoped.extend({
|
|
129
|
+
kind: z.literal("dispatch.failed"),
|
|
130
|
+
campaignId: z.string().min(1),
|
|
131
|
+
portfolioAccountId: z.string().min(1),
|
|
132
|
+
channel: dispatchChannelSchema,
|
|
133
|
+
latencyMs: z.number().nonnegative(),
|
|
134
|
+
/** Coarse classification (the error's constructor name or "Error"). */
|
|
135
|
+
errorClass: z.string(),
|
|
136
|
+
errorMessage: z.string(),
|
|
137
|
+
toMasked: z.string()
|
|
138
|
+
});
|
|
139
|
+
const providerEventSchema = eventBase.extend({
|
|
140
|
+
kind: z.literal("provider.event"),
|
|
141
|
+
/** Owning workspace, resolved from the matched gestión; absent when unmatched. */
|
|
142
|
+
workspaceRef: z.string().optional(),
|
|
143
|
+
/** Which inbound surface received it. */
|
|
144
|
+
source: z.enum(["voice-events", "contact-logs", "meta-whatsapp", "email-inbound"]),
|
|
145
|
+
providerRef: z.string().optional(),
|
|
146
|
+
/** Provider-side timestamp when the payload carries one (receipt time is `at`). */
|
|
147
|
+
providerAt: z.string().optional(),
|
|
148
|
+
/** Whether the ref matched a known gestión. */
|
|
149
|
+
matched: z.boolean(),
|
|
150
|
+
campaignId: z.string().optional(),
|
|
151
|
+
portfolioAccountId: z.string().optional(),
|
|
152
|
+
/** Compact, content-free summary (event type, status, duration — never transcripts). */
|
|
153
|
+
summary: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional()
|
|
154
|
+
});
|
|
155
|
+
export const engineEventSchema = z.discriminatedUnion("kind", [
|
|
156
|
+
tickStartedSchema,
|
|
157
|
+
tickCompletedSchema,
|
|
158
|
+
campaignEvaluatedSchema,
|
|
159
|
+
accountDecidedSchema,
|
|
160
|
+
attemptReservedSchema,
|
|
161
|
+
dispatchRequestedSchema,
|
|
162
|
+
dispatchSucceededSchema,
|
|
163
|
+
dispatchFailedSchema,
|
|
164
|
+
providerEventSchema
|
|
165
|
+
]);
|
|
166
|
+
/**
|
|
167
|
+
* Mask a recipient identifier for the event stream. Phones keep the last 4
|
|
168
|
+
* characters; emails keep the first character of the local part and the domain.
|
|
169
|
+
*/
|
|
170
|
+
export function maskRecipient(to) {
|
|
171
|
+
const at = to.indexOf("@");
|
|
172
|
+
if (at > 0) {
|
|
173
|
+
return `${to[0]}***@${to.slice(at + 1)}`;
|
|
174
|
+
}
|
|
175
|
+
if (to.length <= 4)
|
|
176
|
+
return "*".repeat(to.length);
|
|
177
|
+
return `${"*".repeat(to.length - 4)}${to.slice(-4)}`;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=engineEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engineEvents.js","sourceRoot":"","sources":["../../src/schemas/engineEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,CAAC;IAC1C,cAAc;IACd,gBAAgB;IAChB,oBAAoB;IACpB,iBAAiB;IACjB,kBAAk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B,qBAAqB;IACrB,uBAAuB;IACvB,uBAAuB;IACvB,oBAAoB;IACpB,mBAAmB;CACpB,CAAC,CAAC;AA6BH;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,EAAU;IACtC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QACX,OAAO,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IAC3C,CAAC;IACD,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC;QAAE,OAAO,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvD,CAAC"}
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC"}
|
package/dist/schemas/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client interfaces the billing service functions depend on — the Prisma subset
|
|
3
|
+
* they use, so tests inject stubs with no live database. Monetary columns are
|
|
4
|
+
* BigInt in the database; these interfaces surface them as `bigint` and the
|
|
5
|
+
* functions convert to safe-integer micro-unit `number`s at the boundary.
|
|
6
|
+
*/
|
|
7
|
+
/** Prisma's BillingMeter enum values (DB spelling of the common meter keys). */
|
|
8
|
+
export type DbBillingMeter = "SMS" | "EMAIL" | "WHATSAPP_MESSAGE" | "VOICE_PRERECORDED" | "VOICE_AI" | "WHATSAPP_VOICE_PRERECORDED" | "WHATSAPP_VOICE_AI";
|
|
9
|
+
export type DbLedgerEntryKind = "GRANT" | "USAGE_DEBIT" | "VOID" | "ADJUSTMENT";
|
|
10
|
+
export interface WorkspaceBillingRecord {
|
|
11
|
+
workspaceRef: string;
|
|
12
|
+
billingAccountId: string;
|
|
13
|
+
planKey: string;
|
|
14
|
+
/** Enterprise overrides: a Partial of the shared rates schema (validated on read). */
|
|
15
|
+
rateOverrides: unknown;
|
|
16
|
+
stripeSubscriptionItemId: string | null;
|
|
17
|
+
cycleStart: Date | null;
|
|
18
|
+
cycleEnd: Date | null;
|
|
19
|
+
}
|
|
20
|
+
export interface UsageRecordRow {
|
|
21
|
+
id: string;
|
|
22
|
+
workspaceRef: string;
|
|
23
|
+
meter: DbBillingMeter;
|
|
24
|
+
quantity: number;
|
|
25
|
+
unitPriceMicro: bigint;
|
|
26
|
+
amountMicro: bigint;
|
|
27
|
+
increments: string | null;
|
|
28
|
+
settledAt: Date | null;
|
|
29
|
+
campaignId: string | null;
|
|
30
|
+
portfolioAccountId: string | null;
|
|
31
|
+
providerRef: string | null;
|
|
32
|
+
at: Date;
|
|
33
|
+
}
|
|
34
|
+
export interface LedgerEntryRow {
|
|
35
|
+
id: string;
|
|
36
|
+
workspaceRef: string;
|
|
37
|
+
kind: DbLedgerEntryKind;
|
|
38
|
+
amountMicro: bigint;
|
|
39
|
+
at: Date;
|
|
40
|
+
usageRecordId: string | null;
|
|
41
|
+
stripeInvoiceId: string | null;
|
|
42
|
+
}
|
|
43
|
+
/** The Prisma subset the billing functions reach through the tRPC/engine context. */
|
|
44
|
+
export interface BillingAccountRecord {
|
|
45
|
+
id: string;
|
|
46
|
+
createdFromUserRef: string;
|
|
47
|
+
stripeCustomerId: string;
|
|
48
|
+
stripeSubscriptionId: string | null;
|
|
49
|
+
collectionMethod: string;
|
|
50
|
+
paymentFailed: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface BillingClient {
|
|
53
|
+
workspaceBilling: {
|
|
54
|
+
findUnique(args: {
|
|
55
|
+
where: {
|
|
56
|
+
workspaceRef: string;
|
|
57
|
+
};
|
|
58
|
+
}): Promise<WorkspaceBillingRecord | null>;
|
|
59
|
+
create(args: {
|
|
60
|
+
data: Record<string, unknown>;
|
|
61
|
+
}): Promise<WorkspaceBillingRecord>;
|
|
62
|
+
update(args: {
|
|
63
|
+
where: {
|
|
64
|
+
workspaceRef: string;
|
|
65
|
+
};
|
|
66
|
+
data: Record<string, unknown>;
|
|
67
|
+
}): Promise<WorkspaceBillingRecord>;
|
|
68
|
+
};
|
|
69
|
+
billingAccount: {
|
|
70
|
+
findUnique(args: {
|
|
71
|
+
where: {
|
|
72
|
+
id: string;
|
|
73
|
+
};
|
|
74
|
+
}): Promise<BillingAccountRecord | null>;
|
|
75
|
+
findFirst(args: {
|
|
76
|
+
where: {
|
|
77
|
+
stripeCustomerId?: string;
|
|
78
|
+
createdFromUserRef?: string;
|
|
79
|
+
};
|
|
80
|
+
}): Promise<BillingAccountRecord | null>;
|
|
81
|
+
create(args: {
|
|
82
|
+
data: Record<string, unknown>;
|
|
83
|
+
}): Promise<BillingAccountRecord>;
|
|
84
|
+
update(args: {
|
|
85
|
+
where: {
|
|
86
|
+
id: string;
|
|
87
|
+
};
|
|
88
|
+
data: Record<string, unknown>;
|
|
89
|
+
}): Promise<BillingAccountRecord>;
|
|
90
|
+
updateMany(args: {
|
|
91
|
+
where: {
|
|
92
|
+
stripeCustomerId: string;
|
|
93
|
+
};
|
|
94
|
+
data: Record<string, unknown>;
|
|
95
|
+
}): Promise<{
|
|
96
|
+
count: number;
|
|
97
|
+
}>;
|
|
98
|
+
};
|
|
99
|
+
usageRecord: {
|
|
100
|
+
create(args: {
|
|
101
|
+
data: Record<string, unknown>;
|
|
102
|
+
}): Promise<UsageRecordRow>;
|
|
103
|
+
findUnique(args: {
|
|
104
|
+
where: {
|
|
105
|
+
providerRef: string;
|
|
106
|
+
};
|
|
107
|
+
}): Promise<UsageRecordRow | null>;
|
|
108
|
+
update(args: {
|
|
109
|
+
where: {
|
|
110
|
+
id: string;
|
|
111
|
+
};
|
|
112
|
+
data: Record<string, unknown>;
|
|
113
|
+
}): Promise<UsageRecordRow>;
|
|
114
|
+
};
|
|
115
|
+
ledgerEntry: {
|
|
116
|
+
create(args: {
|
|
117
|
+
data: Record<string, unknown>;
|
|
118
|
+
}): Promise<LedgerEntryRow>;
|
|
119
|
+
aggregate(args: {
|
|
120
|
+
where: {
|
|
121
|
+
workspaceRef: string;
|
|
122
|
+
};
|
|
123
|
+
_sum: {
|
|
124
|
+
amountMicro: true;
|
|
125
|
+
};
|
|
126
|
+
}): Promise<{
|
|
127
|
+
_sum: {
|
|
128
|
+
amountMicro: bigint | null;
|
|
129
|
+
};
|
|
130
|
+
}>;
|
|
131
|
+
};
|
|
132
|
+
$transaction<T>(fn: (tx: BillingClient) => Promise<T>): Promise<T>;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=billing.d.ts.map
|
|
@@ -0,0 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CAAC,CAAC;QACzE,SAAS,CAAC,IAAI,EAAE;YACd,KAAK,EAAE;gBAAE,YAAY,EAAE,MAAM,CAAA;aAAE,CAAC;YAChC,IAAI,EAAE;gBAAE,WAAW,EAAE,IAAI,CAAA;aAAE,CAAC;SAC7B,GAAG,OAAO,CAAC;YAAE,IAAI,EAAE;gBAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;aAAE,CAAA;SAAE,CAAC,CAAC;KACvD,CAAC;IAEF,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACpE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client interfaces the billing service functions depend on — the Prisma subset
|
|
3
|
+
* they use, so tests inject stubs with no live database. Monetary columns are
|
|
4
|
+
* BigInt in the database; these interfaces surface them as `bigint` and the
|
|
5
|
+
* functions convert to safe-integer micro-unit `number`s at the boundary.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/types/billing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/dist/types/engine.d.ts
CHANGED
|
@@ -12,10 +12,16 @@ export interface Clock {
|
|
|
12
12
|
}
|
|
13
13
|
/** Channels the engine can dispatch (the subset `dispatchOutreach` supports). */
|
|
14
14
|
export type EngineChannel = "VOICE_AI" | "VOICE_PRERECORDED" | "SMS" | "EMAIL" | "WHATSAPP";
|
|
15
|
+
/**
|
|
16
|
+
* Which billing meter a dispatch on each channel consumes — THE single mapping
|
|
17
|
+
* (used by the engine tick, manual outreach, and any future dispatch surface,
|
|
18
|
+
* so the same traffic can never be metered differently on different paths).
|
|
19
|
+
*/
|
|
20
|
+
export declare const BILLING_METER_OF_CHANNEL: Record<EngineChannel, import("../billing/rates.js").BillingMeter>;
|
|
15
21
|
/** Why a campaign was not dispatched at all this tick. */
|
|
16
|
-
export type CampaignSkipReason = "not_active" | "out_of_window" | "channel_not_configured" | "channel_not_supported" | "empty_number_pool" | "voice_not_synced";
|
|
22
|
+
export type CampaignSkipReason = "not_active" | "out_of_window" | "channel_not_configured" | "channel_not_supported" | "empty_number_pool" | "voice_not_synced" | "credits_exhausted" | "payment_failed";
|
|
17
23
|
/** The outcome of considering a single account during a tick. */
|
|
18
|
-
export type AccountDecision = "dispatched" | "dispatch_failed" | "no_phone" | "no_email" | "intent_suppressed" | "account_suppressed" | "promise_suppressed" | "lifetime_cap" | "daily_cap" | "budget_exhausted";
|
|
24
|
+
export type AccountDecision = "dispatched" | "dispatch_failed" | "no_phone" | "no_email" | "intent_suppressed" | "account_suppressed" | "promise_suppressed" | "lifetime_cap" | "daily_cap" | "budget_exhausted" | "credits_exhausted";
|
|
19
25
|
/** Per-account line in the tick report. */
|
|
20
26
|
export interface AccountDecisionEntry {
|
|
21
27
|
portfolioAccountId: string;
|
|
@@ -46,5 +52,10 @@ export interface TickReport {
|
|
|
46
52
|
at: string;
|
|
47
53
|
campaigns: CampaignTickReport[];
|
|
48
54
|
channelUsage: Partial<Record<EngineChannel, ChannelUsage>>;
|
|
55
|
+
/**
|
|
56
|
+
* Flight-recorder events collected during the tick (engine-events capability).
|
|
57
|
+
* The runner flushes them to the configured sink, best-effort, after the tick.
|
|
58
|
+
*/
|
|
59
|
+
events?: import("../schemas/engineEvents.js").EngineEvent[];
|
|
49
60
|
}
|
|
50
61
|
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/types/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oFAAoF;AACpF,MAAM,WAAW,KAAK;IACpB,GAAG,IAAI,IAAI,CAAC;CACb;AAED,iFAAiF;AACjF,MA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IACzE,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,SAAS,EAAE,oBAAoB,EAAE,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,iDAAiD;AACjD,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,oFAAoF;AACpF,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC;IAC3D;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,4BAA4B,EAAE,WAAW,EAAE,CAAC;CAC7D"}
|
package/dist/types/engine.js
CHANGED
|
@@ -6,5 +6,16 @@
|
|
|
6
6
|
* The channel-dispatch ports (`OutboundCallClient`, `SmsClient`, `NumberSelector`)
|
|
7
7
|
* are reused from `./dispatch.js` — channel emulators implement those interfaces.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Which billing meter a dispatch on each channel consumes — THE single mapping
|
|
11
|
+
* (used by the engine tick, manual outreach, and any future dispatch surface,
|
|
12
|
+
* so the same traffic can never be metered differently on different paths).
|
|
13
|
+
*/
|
|
14
|
+
export const BILLING_METER_OF_CHANNEL = {
|
|
15
|
+
VOICE_AI: "voiceAi",
|
|
16
|
+
VOICE_PRERECORDED: "voicePrerecorded",
|
|
17
|
+
SMS: "sms",
|
|
18
|
+
EMAIL: "email",
|
|
19
|
+
WHATSAPP: "whatsappMessage"
|
|
20
|
+
};
|
|
10
21
|
//# sourceMappingURL=engine.js.map
|
package/dist/types/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/types/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/types/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAGjC;IACF,QAAQ,EAAE,SAAS;IACnB,iBAAiB,EAAE,kBAAkB;IACrC,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,iBAAiB;CAC5B,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
package/dist/types/index.js
CHANGED
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { withErrorHandlingAndValidation } from "./withErrorHandlingAndValidation.js";
|
|
2
2
|
export { renderTemplate, extractTemplateTokens, buildOutreachContext, pickRandomNumber } from "./outreach.js";
|
|
3
|
-
export { localParts, localDateString, isSameLocalDay, localWeekdayISO, localTimeHHMM } from "./time.js";
|
|
3
|
+
export { localParts, localDateString, isSameLocalDay, localWeekdayISO, localTimeHHMM, isWithinScheduleWindow, type ScheduleWindow } from "./time.js";
|
|
4
|
+
export { bucketOf, perTickCapacity, type PacingBucket } from "./pacing.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,aAAa,EACb,sBAAsB,EACtB,KAAK,cAAc,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { withErrorHandlingAndValidation } from "./withErrorHandlingAndValidation.js";
|
|
2
2
|
export { renderTemplate, extractTemplateTokens, buildOutreachContext, pickRandomNumber } from "./outreach.js";
|
|
3
|
-
export { localParts, localDateString, isSameLocalDay, localWeekdayISO, localTimeHHMM } from "./time.js";
|
|
3
|
+
export { localParts, localDateString, isSameLocalDay, localWeekdayISO, localTimeHHMM, isWithinScheduleWindow } from "./time.js";
|
|
4
|
+
export { bucketOf, perTickCapacity } from "./pacing.js";
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,aAAa,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,aAAa,EACb,sBAAsB,EAEvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAqB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EngineChannel } from "../types/engine.js";
|
|
2
|
+
/**
|
|
3
|
+
* The engine's pacing buckets. Rate limits are per bucket, not per channel:
|
|
4
|
+
* both voice channels share one bucket (one caller-ID pool, one concurrency
|
|
5
|
+
* budget). This mapping is THE single encoding of that fact — the engine picks
|
|
6
|
+
* buckets with it and the evaluator groups usage with it, so a future bucket
|
|
7
|
+
* split only changes this function.
|
|
8
|
+
*/
|
|
9
|
+
export type PacingBucket = "voice" | "sms" | "email" | "whatsApp";
|
|
10
|
+
export declare function bucketOf(channel: EngineChannel): PacingBucket;
|
|
11
|
+
/**
|
|
12
|
+
* Tokens a bucket may spend in a single tick, from its per-minute rate. Shared
|
|
13
|
+
* by the engine's token buckets and the evaluator's SAF-5 cap check so the two
|
|
14
|
+
* can never drift.
|
|
15
|
+
*/
|
|
16
|
+
export declare function perTickCapacity(ratePerMinute: number, tickSeconds: number): number;
|
|
17
|
+
//# sourceMappingURL=pacing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pacing.d.ts","sourceRoot":"","sources":["../../src/utils/pacing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,UAAU,CAAC;AAElE,wBAAgB,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CAK7D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAElF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function bucketOf(channel) {
|
|
2
|
+
if (channel === "VOICE_AI" || channel === "VOICE_PRERECORDED")
|
|
3
|
+
return "voice";
|
|
4
|
+
if (channel === "SMS")
|
|
5
|
+
return "sms";
|
|
6
|
+
if (channel === "EMAIL")
|
|
7
|
+
return "email";
|
|
8
|
+
return "whatsApp";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Tokens a bucket may spend in a single tick, from its per-minute rate. Shared
|
|
12
|
+
* by the engine's token buckets and the evaluator's SAF-5 cap check so the two
|
|
13
|
+
* can never drift.
|
|
14
|
+
*/
|
|
15
|
+
export function perTickCapacity(ratePerMinute, tickSeconds) {
|
|
16
|
+
return Math.floor((Math.max(0, ratePerMinute) * Math.max(1, tickSeconds)) / 60);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=pacing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pacing.js","sourceRoot":"","sources":["../../src/utils/pacing.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,QAAQ,CAAC,OAAsB;IAC7C,IAAI,OAAO,KAAK,UAAU,IAAI,OAAO,KAAK,mBAAmB;QAAE,OAAO,OAAO,CAAC;IAC9E,IAAI,OAAO,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACpC,IAAI,OAAO,KAAK,OAAO;QAAE,OAAO,OAAO,CAAC;IACxC,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,aAAqB,EAAE,WAAmB;IACxE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,aAAa,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;AAClF,CAAC"}
|
package/dist/utils/time.d.ts
CHANGED
|
@@ -21,5 +21,21 @@ export declare function isSameLocalDay(a: Date, b: Date, timeZone: string): bool
|
|
|
21
21
|
export declare function localWeekdayISO(date: Date, timeZone: string): number;
|
|
22
22
|
/** Local `HH:MM` (24h) for an instant in the timezone. */
|
|
23
23
|
export declare function localTimeHHMM(date: Date, timeZone: string): string;
|
|
24
|
+
/** The schedule fields a contact window comprises (a campaign row or an event snapshot). */
|
|
25
|
+
export interface ScheduleWindow {
|
|
26
|
+
startDate: Date;
|
|
27
|
+
endDate: Date | null;
|
|
28
|
+
/** ISO weekdays (1 = Monday … 7 = Sunday). */
|
|
29
|
+
daysOfWeek: number[];
|
|
30
|
+
/** Local wall-clock bounds, `HH:MM` 24h. Windows do not span midnight. */
|
|
31
|
+
startTime: string;
|
|
32
|
+
endTime: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether `at` falls inside the schedule window, evaluated in `timeZone`. The
|
|
36
|
+
* single window rule shared by the engine's dispatch gate and the evaluator's
|
|
37
|
+
* SAF-1 check, so the judge can never disagree with the engine about a window.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isWithinScheduleWindow(w: ScheduleWindow, at: Date, timeZone: string): boolean;
|
|
24
40
|
export {};
|
|
25
41
|
//# sourceMappingURL=time.d.ts.map
|
package/dist/utils/time.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/utils/time.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,UAAU,UAAU;IAClB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;CACd;AAYD,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAmBnE;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE1E;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,0DAA0D;AAC1D,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAElE"}
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/utils/time.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,UAAU,UAAU;IAClB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;CACd;AAYD,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAmBnE;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE1E;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,0DAA0D;AAC1D,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,4FAA4F;AAC5F,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,GAAG,IAAI,CAAC;IACrB,8CAA8C;IAC9C,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAO7F"}
|
package/dist/utils/time.js
CHANGED
|
@@ -49,4 +49,21 @@ export function localWeekdayISO(date, timeZone) {
|
|
|
49
49
|
export function localTimeHHMM(date, timeZone) {
|
|
50
50
|
return localParts(date, timeZone).time;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether `at` falls inside the schedule window, evaluated in `timeZone`. The
|
|
54
|
+
* single window rule shared by the engine's dispatch gate and the evaluator's
|
|
55
|
+
* SAF-1 check, so the judge can never disagree with the engine about a window.
|
|
56
|
+
*/
|
|
57
|
+
export function isWithinScheduleWindow(w, at, timeZone) {
|
|
58
|
+
const { date, weekday, time } = localParts(at, timeZone);
|
|
59
|
+
if (date < localDateString(w.startDate, timeZone))
|
|
60
|
+
return false;
|
|
61
|
+
if (w.endDate && date > localDateString(w.endDate, timeZone))
|
|
62
|
+
return false;
|
|
63
|
+
if (!w.daysOfWeek.includes(weekday))
|
|
64
|
+
return false;
|
|
65
|
+
if (time < w.startTime || time > w.endTime)
|
|
66
|
+
return false;
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
52
69
|
//# sourceMappingURL=time.js.map
|
package/dist/utils/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/utils/time.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,MAAM,cAAc,GAA2B;IAC7C,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;CACP,CAAC;AAEF,sFAAsF;AACtF,MAAM,UAAU,UAAU,CAAC,IAAU,EAAE,QAAgB;IACrD,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;QAC3C,QAAQ;QACR,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxF,kFAAkF;IAClF,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;IACrD,OAAO;QACL,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,KAAK,IAAI,KAAK,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C5C,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,aAAa,CAAC,IAAU,EAAE,QAAgB;IACxD,OAAO,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC;AACzC,CAAC;AAaD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,CAAiB,EAAE,EAAQ,EAAE,QAAgB;IAClF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IACzD,IAAI,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IAChE,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3E,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,IAAI,GAAG,CAAC,CAAC,SAAS,IAAI,IAAI,GAAG,CAAC,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IACzD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qcobro/common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"exports": {
|
|
12
12
|
".": "./dist/index.js"
|
|
13
13
|
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"engine-eval": "./dist/bin/engineEval.js"
|
|
16
|
+
},
|
|
14
17
|
"scripts": {
|
|
15
18
|
"build": "tsc -b --force",
|
|
16
19
|
"clean": "rm -rf dist *.tsbuildinfo",
|