@iveri/contracts 0.95.0 → 0.97.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/README.md CHANGED
@@ -219,6 +219,19 @@ What a company running a taxi service reads in its own panel: `TaxiRideStatus`,
219
219
  - **A day's totals are the rides requested on it**, so `completed` can never exceed `requested`, and the panel names the
220
220
  time zone the days were cut in.
221
221
 
222
+ ### `api/delivery/` → `@iveri/contracts/delivery`
223
+
224
+ What a company running a delivery service reads in its own panel, shaped like Taxi's: `DeliveryJobStatus`, the live
225
+ board (`DeliveryBoard`, `DeliveryBoardJob`), each courier's work since a moment (`DeliveryCourierActivityList`), its
226
+ senders (`DeliverySendersPage`), its fee settings (`DeliveryFeeSettings`, `UpdateDeliveryFeeSettingsRequest`) and its
227
+ daily totals (`DeliveryDailyReport`).
228
+
229
+ - **A job the company asked for itself has no sender** (`senderUserId: null`), as a shop shipping its own orders does;
230
+ it is on the board and in the totals, and in nobody's row of the senders list.
231
+ - **Proof is a yes or no and the recipient's name.** The photograph is private evidence and is never in these shapes.
232
+ - **`expired` folds quote-expired into no courier found, and `failed` stays apart**, because a refused request is a
233
+ fault on Iveri's side rather than the company's.
234
+
222
235
  ### Why the wire shapes moved here
223
236
 
224
237
  `conduit-admin-web` hand-transcribed all of it, carefully and with comments. It still drifted:
@@ -17,6 +17,12 @@ export interface ChatAppWebhook {
17
17
  url: string;
18
18
  events: ChatWebhookEvent[];
19
19
  isActive: boolean;
20
+ /**
21
+ * Until when the secret the last rotation replaced still signs beside the new one, or null when only one does.
22
+ * Every delivery meanwhile carries a `v1` for each, so a server still checking the old secret keeps accepting them.
23
+ * Ended early by `POST …/end-secret-overlap`.
24
+ */
25
+ previousSecretExpiresAt: Nullable<IsoDateTime>;
20
26
  createdAt: IsoDateTime;
21
27
  updatedAt: IsoDateTime;
22
28
  }
@@ -35,7 +41,8 @@ export interface UpdateChatAppWebhookRequest {
35
41
  }
36
42
  /**
37
43
  * `POST /apps/:appId/webhooks` and `POST …/rotate-secret`. The only answers that hold the signing secret: Baasi does
38
- * not keep it, and after a rotation the old one stops signing at once.
44
+ * not keep it. After a rotation the old secret keeps signing beside the new one until `previousSecretExpiresAt` (a day,
45
+ * unless the deployment says otherwise), so the server can be moved over without refusing a delivery.
39
46
  */
40
47
  export interface CreatedChatAppWebhook extends ChatAppWebhook {
41
48
  /** `bwh_` and 32 random bytes in base64url. The HMAC key for `Baasi-Signature`. */
@@ -61,7 +68,8 @@ export interface ChatAppWebhookDelivery {
61
68
  export type ChatAppWebhookDeliveriesPage = CursorPage<ChatAppWebhookDelivery>;
62
69
  /**
63
70
  * The body every webhook carries, signed with `Baasi-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of
64
- * "<t>.<body>">`. Users are named by the app's own ids for them. `id` is stable across retries, so a server that has
71
+ * "<t>.<body>">`, with a second `v1=` for the replaced secret while a rotation overlaps: accept the request when any
72
+ * `v1` matches. Users are named by the app's own ids for them. `id` is stable across retries, so a server that has
65
73
  * seen it may answer 200 and do nothing.
66
74
  */
67
75
  export interface ChatWebhookPayload<TType extends ChatWebhookEvent = ChatWebhookEvent, TData = unknown> {
@@ -70,6 +70,15 @@ export interface Connection {
70
70
  * usable: the client id and secret are typed in, the token is only ever granted.
71
71
  */
72
72
  connectedAt: Nullable<IsoDateTime>;
73
+ /**
74
+ * Until when the signing secret this connection's last rotation replaced still signs beside the
75
+ * new one, or null when only one secret signs.
76
+ *
77
+ * Only an `hmac-signature` connection ever has one, and only after an update that replaced its
78
+ * `secret` with {@link UpdateConnectionBody.previousSigningSecretValidForSeconds}. Null once that
79
+ * moment has passed, so a reader never has to compare it with the clock.
80
+ */
81
+ previousSigningSecretExpiresAt: Nullable<IsoDateTime>;
73
82
  /** Stops *new* dispatches being accepted. Does not cancel ones already queued. */
74
83
  isActive: boolean;
75
84
  createdAt: IsoDateTime;
@@ -129,6 +138,21 @@ export interface UpdateConnectionBody {
129
138
  credentials?: Nullable<Record<string, string>>;
130
139
  variables?: Nullable<Record<string, string>>;
131
140
  isActive?: boolean;
141
+ /**
142
+ * Keeps the `secret` this update replaces signing beside the new one for this many seconds,
143
+ * 1 to `MAX_SIGNING_SECRET_OVERLAP_SECONDS`. **`hmac-signature` connections only**, and
144
+ * only with a `credentials` object that changes the `secret`; anything else is refused.
145
+ *
146
+ * Omitted, the replaced secret stops signing at once, as it always has. A receiver still
147
+ * checking the old secret then refuses every request until it is updated, and those requests
148
+ * dead-letter on the 4xx. With an overlap, every request carries a `v1` for each secret, so a
149
+ * receiver holding either accepts it.
150
+ *
151
+ * **At most two secrets sign at once.** Rotating again during an overlap keeps the secret this
152
+ * update replaces and drops the older one. Ending an overlap early is
153
+ * `DELETE /api/v1/connections/:id/previous-signing-secret`.
154
+ */
155
+ previousSigningSecretValidForSeconds?: number;
132
156
  }
133
157
  /**
134
158
  * `POST /api/v1/connections/:id/verify`.
@@ -13,6 +13,10 @@ export declare enum ConnectorSignatureFormat {
13
13
  * header on commas, recompute over the timestamp, a dot and the body exactly as received,
14
14
  * compare in constant time, and refuse a timestamp older than a few minutes. A request with no
15
15
  * body is signed over `<t>.` alone.
16
+ *
17
+ * While a replaced secret is still within its overlap the header carries one `v1=` per live
18
+ * secret, the newest first (`t=…,v1=<new>,v1=<old>`), which is how Stripe signs during a roll:
19
+ * a receiver accepts the request when any `v1` matches the secret it holds.
16
20
  */
17
21
  STRIPE_V1 = "stripe-v1"
18
22
  }
@@ -14,6 +14,10 @@ export var ConnectorSignatureFormat;
14
14
  * header on commas, recompute over the timestamp, a dot and the body exactly as received,
15
15
  * compare in constant time, and refuse a timestamp older than a few minutes. A request with no
16
16
  * body is signed over `<t>.` alone.
17
+ *
18
+ * While a replaced secret is still within its overlap the header carries one `v1=` per live
19
+ * secret, the newest first (`t=…,v1=<new>,v1=<old>`), which is how Stripe signs during a roll:
20
+ * a receiver accepts the request when any `v1` matches the secret it holds.
17
21
  */
18
22
  ConnectorSignatureFormat["STRIPE_V1"] = "stripe-v1";
19
23
  })(ConnectorSignatureFormat || (ConnectorSignatureFormat = {}));
@@ -31,6 +31,13 @@ export declare const CONNECTOR_CREDENTIAL_PRIVATE_KEY_ID = "privateKeyId";
31
31
  * that could rename it could only name it wrongly.
32
32
  */
33
33
  export declare const CONNECTOR_CREDENTIAL_SECRET = "secret";
34
+ /**
35
+ * The longest a replaced signing secret may keep signing beside its successor: seven days.
36
+ *
37
+ * Long enough for a receiver deployed weekly to pick up the new secret, short enough that a secret
38
+ * somebody replaced because it leaked stops being accepted within a week of their saying so.
39
+ */
40
+ export declare const MAX_SIGNING_SECRET_OVERLAP_SECONDS = 604800;
34
41
  /**
35
42
  * How a request is signed. `HMAC_SIGNATURE` only.
36
43
  *
@@ -26,3 +26,10 @@ export const CONNECTOR_CREDENTIAL_PRIVATE_KEY_ID = 'privateKeyId';
26
26
  * that could rename it could only name it wrongly.
27
27
  */
28
28
  export const CONNECTOR_CREDENTIAL_SECRET = 'secret';
29
+ /**
30
+ * The longest a replaced signing secret may keep signing beside its successor: seven days.
31
+ *
32
+ * Long enough for a receiver deployed weekly to pick up the new secret, short enough that a secret
33
+ * somebody replaced because it leaked stops being accepted within a week of their saying so.
34
+ */
35
+ export const MAX_SIGNING_SECRET_OVERLAP_SECONDS = 604_800;
@@ -0,0 +1,128 @@
1
+ import type { IsoDateTime } from '../../type/iso-date-time.type.js';
2
+ import type { Nullable } from '../../type/nil.type.js';
3
+ import type { Paginated } from '../../type/paginated.type.js';
4
+ import type { UUID } from '../../type/uuid.type.js';
5
+ import type { DeliveryJobStatus } from './delivery-job-status.enum.js';
6
+ /** A stop as the sender gave it. There is no address search, so it is coordinates only. */
7
+ export interface DeliveryPoint {
8
+ latitude: number;
9
+ longitude: number;
10
+ }
11
+ /**
12
+ * One job as the company running the delivery service sees it on its board.
13
+ *
14
+ * The company sees its own customers' stops; Iveri's backoffice never does. A stop is null once the job's location is
15
+ * past the retention window, which differs from never having one. People are identifiers: the panel names them from
16
+ * identity's public profile.
17
+ */
18
+ export interface DeliveryBoardJob {
19
+ id: UUID;
20
+ status: DeliveryJobStatus;
21
+ /** Null when the company asked for the delivery itself, as a shop shipping its own orders does. */
22
+ senderUserId: Nullable<UUID>;
23
+ /** The Mobility worker carrying it, once a courier accepted. */
24
+ courierWorkerId: Nullable<UUID>;
25
+ /** The courier as a person; briefly null after acceptance while Delivery resolves the worker. */
26
+ courierUserId: Nullable<UUID>;
27
+ pickup: Nullable<DeliveryPoint>;
28
+ dropoff: Nullable<DeliveryPoint>;
29
+ /** A straight-line floor, never a final charge. */
30
+ quotedFeeMinor: number;
31
+ quotedFeeCurrency: string;
32
+ quotedDistanceMeters: number;
33
+ createdAt: IsoDateTime;
34
+ assignedAt: Nullable<IsoDateTime>;
35
+ pickedUpAt: Nullable<IsoDateTime>;
36
+ inTransitAt: Nullable<IsoDateTime>;
37
+ deliveredAt: Nullable<IsoDateTime>;
38
+ cancelledAt: Nullable<IsoDateTime>;
39
+ /** Whether the courier left proof. The photograph itself is private evidence and is never on the board. */
40
+ hasProof: boolean;
41
+ /** The name the courier entered for whoever took the parcel; null without proof or past its retention window. */
42
+ recipientName: Nullable<string>;
43
+ }
44
+ /**
45
+ * `GET /company/board?since=`: what is happening now, and what finished since `since` (the start of the company's
46
+ * day, which only the panel knows). Each list is capped and newest first.
47
+ */
48
+ export interface DeliveryBoard {
49
+ since: IsoDateTime;
50
+ /** Looking for a courier, assigned, picked up or in transit. Waiting quotes are not work yet. */
51
+ active: DeliveryBoardJob[];
52
+ /** Delivered, cancelled, expired, quote-expired or failed since `since`. */
53
+ finished: DeliveryBoardJob[];
54
+ }
55
+ /** One courier's work since a moment, keyed by their Mobility worker. Couriers with no jobs are absent. */
56
+ export interface DeliveryCourierActivity {
57
+ workerId: UUID;
58
+ deliveredJobs: number;
59
+ lastDeliveredAt: Nullable<IsoDateTime>;
60
+ /** The job they are carrying now, if any. */
61
+ activeJobId: Nullable<UUID>;
62
+ activeJobStatus: Nullable<DeliveryJobStatus>;
63
+ }
64
+ /** `GET /company/couriers/activity?since=`. */
65
+ export interface DeliveryCourierActivityList {
66
+ since: IsoDateTime;
67
+ couriers: DeliveryCourierActivity[];
68
+ }
69
+ /**
70
+ * Somebody who has asked this company to carry something. Named by the panel from identity. Jobs the company asked
71
+ * for itself have no sender and are not anybody's here.
72
+ */
73
+ export interface DeliverySenderSummary {
74
+ userId: UUID;
75
+ /** Every job they asked for, including quotes they never accepted. */
76
+ jobs: number;
77
+ deliveredJobs: number;
78
+ lastJobAt: IsoDateTime;
79
+ }
80
+ /** `GET /company/senders`, most recent sender first. */
81
+ export type DeliverySendersPage = Paginated<DeliverySenderSummary>;
82
+ /**
83
+ * What a quote costs: `base + round(metres × perKilometre / 1000)`, in minor units of `currency`. The distance is a
84
+ * straight line, so the quote stays a floor whatever these are set to.
85
+ */
86
+ export interface DeliveryFeeSettings {
87
+ currency: string;
88
+ baseFeeMinor: number;
89
+ perKilometreMinor: number;
90
+ /** True while the company has never set its own prices and the service's defaults apply. */
91
+ isDefault: boolean;
92
+ updatedAt: Nullable<IsoDateTime>;
93
+ }
94
+ /** `PUT /company/fee-settings`. Applies to quotes made afterwards; a quote already given keeps its price. */
95
+ export interface UpdateDeliveryFeeSettingsRequest {
96
+ currency: string;
97
+ baseFeeMinor: number;
98
+ perKilometreMinor: number;
99
+ }
100
+ /** Quoted fees of a day's delivered jobs in one currency. Quoted, not earned: nothing settles a fee yet. */
101
+ export interface DeliveryQuotedFeeTotal {
102
+ currency: string;
103
+ quotedFeeMinor: number;
104
+ }
105
+ /**
106
+ * One day of the jobs requested on it, in the report's time zone: how many were asked for, and how those ended. A job
107
+ * requested late and delivered after midnight counts on the day it was asked for.
108
+ */
109
+ export interface DeliveryDailyTotals {
110
+ /** `YYYY-MM-DD`. */
111
+ date: string;
112
+ requested: number;
113
+ delivered: number;
114
+ cancelled: number;
115
+ /** No courier was found, or the sender let the quote run out. */
116
+ expired: number;
117
+ /** Mobility refused the request: a fault on Iveri's side rather than the company's. */
118
+ failed: number;
119
+ /** Sum of the quoted fees of that day's delivered jobs, per currency. */
120
+ deliveredQuotedFees: DeliveryQuotedFeeTotal[];
121
+ }
122
+ /** `GET /company/reports/daily?days=&timeZone=`: oldest day first, every day present, zeroes included. */
123
+ export interface DeliveryDailyReport {
124
+ timeZone: string;
125
+ from: string;
126
+ to: string;
127
+ days: DeliveryDailyTotals[];
128
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Where a delivery job stands. `delivery-api` owns the lifecycle; this is its wire vocabulary, so a company's panel and
3
+ * Iveri's backoffice can label a job without restating it.
4
+ */
5
+ export declare enum DeliveryJobStatus {
6
+ /** Priced and waiting for the sender to accept it. */
7
+ QUOTED = "quoted",
8
+ /** Confirmed, and looking for a courier. */
9
+ DISPATCHING = "dispatching",
10
+ /** A courier accepted and is on the way to the pickup. */
11
+ COURIER_ASSIGNED = "courier-assigned",
12
+ /** The courier has the parcel. */
13
+ PICKED_UP = "picked-up",
14
+ /** The parcel is on its way to the drop-off. */
15
+ IN_TRANSIT = "in-transit",
16
+ /** Handed over, with the recipient's name and a photograph as proof. */
17
+ DELIVERED = "delivered",
18
+ /** The sender never accepted the quote before it ran out. */
19
+ QUOTE_EXPIRED = "quote-expired",
20
+ /** Mobility found no courier. */
21
+ EXPIRED = "expired",
22
+ /** Mobility refused the request outright; the job never reached a courier. */
23
+ FAILED = "failed",
24
+ CANCELLED = "cancelled"
25
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Where a delivery job stands. `delivery-api` owns the lifecycle; this is its wire vocabulary, so a company's panel and
3
+ * Iveri's backoffice can label a job without restating it.
4
+ */
5
+ export var DeliveryJobStatus;
6
+ (function (DeliveryJobStatus) {
7
+ /** Priced and waiting for the sender to accept it. */
8
+ DeliveryJobStatus["QUOTED"] = "quoted";
9
+ /** Confirmed, and looking for a courier. */
10
+ DeliveryJobStatus["DISPATCHING"] = "dispatching";
11
+ /** A courier accepted and is on the way to the pickup. */
12
+ DeliveryJobStatus["COURIER_ASSIGNED"] = "courier-assigned";
13
+ /** The courier has the parcel. */
14
+ DeliveryJobStatus["PICKED_UP"] = "picked-up";
15
+ /** The parcel is on its way to the drop-off. */
16
+ DeliveryJobStatus["IN_TRANSIT"] = "in-transit";
17
+ /** Handed over, with the recipient's name and a photograph as proof. */
18
+ DeliveryJobStatus["DELIVERED"] = "delivered";
19
+ /** The sender never accepted the quote before it ran out. */
20
+ DeliveryJobStatus["QUOTE_EXPIRED"] = "quote-expired";
21
+ /** Mobility found no courier. */
22
+ DeliveryJobStatus["EXPIRED"] = "expired";
23
+ /** Mobility refused the request outright; the job never reached a courier. */
24
+ DeliveryJobStatus["FAILED"] = "failed";
25
+ DeliveryJobStatus["CANCELLED"] = "cancelled";
26
+ })(DeliveryJobStatus || (DeliveryJobStatus = {}));
@@ -0,0 +1,2 @@
1
+ export * from './delivery-admin.type.js';
2
+ export * from './delivery-job-status.enum.js';
@@ -0,0 +1,2 @@
1
+ export * from './delivery-admin.type.js';
2
+ export * from './delivery-job-status.enum.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iveri/contracts",
3
- "version": "0.95.0",
3
+ "version": "0.97.0",
4
4
  "description": "Wire contracts shared by every Iveri backend and frontend. Zero runtime dependencies.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -84,6 +84,10 @@
84
84
  "types": "./dist/api/taxi/index.d.ts",
85
85
  "default": "./dist/api/taxi/index.js"
86
86
  },
87
+ "./delivery": {
88
+ "types": "./dist/api/delivery/index.d.ts",
89
+ "default": "./dist/api/delivery/index.js"
90
+ },
87
91
  "./billing": {
88
92
  "types": "./dist/api/billing/index.d.ts",
89
93
  "default": "./dist/api/billing/index.js"