@agentforge-io/sdk-server 4.89.0 → 4.91.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/types.d.ts CHANGED
@@ -2426,6 +2426,11 @@ export interface CaseType {
2426
2426
  tools?: string[];
2427
2427
  /** Business states after `accepted`, in order. */
2428
2428
  states?: CaseBusinessState[];
2429
+ /**
2430
+ * PDK-SERVICE-CHANGES S3 — a booking or a rental can be changed by the customer (`cases.receiptRequestChange`) until this many
2431
+ * hours before it starts. Absent: 24. 0 = until it starts. A whole number 0–720.
2432
+ */
2433
+ changeWindowHours?: number;
2429
2434
  /** false: the case completes when the customer confirms (nothing for the business to act on). Default true. */
2430
2435
  needsBusiness?: boolean;
2431
2436
  /** Minutes without a customer message before an unfinished case is abandoned. Default 120. */
@@ -2556,6 +2561,15 @@ export interface CaseView {
2556
2561
  } | null;
2557
2562
  /** PDK-SERVICE-CHANGES — the prices the business set for lines of this request, by receipt line `key`, with their history; null/absent: none. */
2558
2563
  linePrices?: CaseLinePrices | null;
2564
+ /** PDK-SERVICE-CHANGES S3 — the customer may ask a change now (`cases.receiptRequestChange`); `changeReason` says why not. Absent on an older platform. */
2565
+ changeAllowed?: boolean;
2566
+ changeReason?: CaseChangeReason;
2567
+ /** Which form the change needs: products (`items`), a `service`, a `booking`'s time, a `rental`'s range, or `mixed` (products and services). */
2568
+ changeKind?: CaseChangeKind;
2569
+ /** A booking or a rental: the last instant a change can still be asked (ISO). */
2570
+ changeUntil?: string;
2571
+ /** The change asked and waiting for the business (`cases.answerChange`); null/absent: none. */
2572
+ pendingChange?: CasePendingChange | null;
2559
2573
  /** PDK-OFF-CATALOG — the order's «comodín» lines (products asked for by name that are not in the catalog) and what is left to confirm; null/absent: none. */
2560
2574
  offCatalog?: CaseOffCatalogView | null;
2561
2575
  /** What the customer asked after the business took the case (change, cancel), until the business moves it. */
@@ -2568,6 +2582,12 @@ export interface CaseView {
2568
2582
  payment: CasePayment | null;
2569
2583
  /** AGF-PDK-DISPATCH-PROPOSAL — the latest proposed changes and their answer (absent on an older platform). */
2570
2584
  proposal?: CaseProposal | null;
2585
+ /**
2586
+ * PDK-RENTAL-DEAL R1 — a rental QUOTE request (`createDirectRental({ quote: true })`): where it is, every version the business sent
2587
+ * (newest last; snapshot, validity, answer, comment) and the agreed one. Null: not a quote (absent on an older platform). The lines still
2588
+ * waiting for a price are `cases.receipt(token).quote.pendingLines` (the receipt's lines carry the keys to price).
2589
+ */
2590
+ quote?: CaseQuote | null;
2571
2591
  /** AGF-AGENDA — who of the business attends it: your member reference (set with `cases.assign`). */
2572
2592
  assigneeRef: string | null;
2573
2593
  /** AGF-AGENDA — the time a booking holds, and how it reads («lunes, 9 de noviembre, 10:00–10:45»). */
@@ -2664,7 +2684,9 @@ export interface CreateOffCatalogLineInput {
2664
2684
  */
2665
2685
  export type CasePaymentStatus = 'unpaid' | 'awaiting_payment' | 'pending_confirmation' | 'paid' | 'rejected' | 'refunded' | 'partially_refunded' | 'reversed' | 'voided'
2666
2686
  /** PDK-STORE-CREDIT — «Fiado»: left on the customer's account (`cases.setOnAccount`). Neither to collect nor payable by chat. Absent on an older platform. */
2667
- | 'on_account';
2687
+ | 'on_account'
2688
+ /** PDK-RENTAL-DEAL R7 — some money came in, not all (an anticipo, a partial saldo). Only a case with payment entries reaches it. Absent on an older platform. */
2689
+ | 'partially_paid';
2668
2690
  /** The account the customer chose, as it was then (a later edit never rewrites a sale). */
2669
2691
  export interface CasePaymentAccount {
2670
2692
  id: string;
@@ -2710,18 +2732,45 @@ export interface CasePayment {
2710
2732
  chosenAt?: 'checkout' | 'chat' | 'receipt';
2711
2733
  /** The order ended undone after the customer reported (or the business confirmed) the payment: check it and refund. */
2712
2734
  refundDue?: boolean;
2735
+ /**
2736
+ * PDK-SERVICE-CHANGES S3 — an accepted change request moved the total AFTER the payment was reported or made: what the customer still
2737
+ * owes (positive) or the business owes back (negative), in cents, summed over every such change. Settling the payment (any business move) clears it.
2738
+ */
2739
+ differenceCents?: number;
2713
2740
  /**
2714
2741
  * PDK-STORE-CREDIT — `paid` because the customer account's abonos covered the order's fiado (money counted abono by
2715
2742
  * abono, never on the order). Absent otherwise and on an older platform; cleared when it goes back on account.
2716
2743
  */
2717
2744
  settledBy?: 'account';
2745
+ /** The plan frozen with the agreement: anticipo %, its amount, the deadline, the cancellation policy. */
2746
+ plan?: CasePaymentPlan;
2747
+ /** The case's money lives in its payment entries (`cases.payments`); the fields below are their projection. */
2748
+ ledger?: true;
2749
+ /** Confirmed money in − confirmed refunds. */
2750
+ paidCents?: number;
2751
+ /** Confirmed money in (refunds not subtracted). */
2752
+ grossPaidCents?: number;
2753
+ /** `max(total − paid, 0)` against the live receipt total (absent while the total is unknown). */
2754
+ balanceCents?: number;
2755
+ /** What the customer pays next: the anticipo still owed while it gates the case, else the balance. */
2756
+ dueNowCents?: number;
2757
+ /** Reported entries still waiting for the business. */
2758
+ pendingCents?: number;
2759
+ /** The anticipo still owed (0 when paid, waived or none). */
2760
+ anticipoDueCents?: number;
2761
+ /** `deposit_due`: a required anticipo is not in, so the case cannot be confirmed / dispatched (400 `deposit_due`). */
2762
+ gate?: 'deposit_due' | null;
2763
+ /** What has to go back: after the retention on a case that closed undone, or what was over-paid on a live one. */
2764
+ refundDueCents?: number;
2765
+ /** The money consequence frozen when the case closed undone (penalty tier, retained, to refund). */
2766
+ cancellation?: CaseCancellation;
2718
2767
  history: Array<{
2719
2768
  status: CasePaymentStatus;
2720
2769
  by: 'assistant' | 'customer' | 'business' | 'system';
2721
2770
  at: string;
2722
2771
  note?: string;
2723
2772
  amountCents?: number;
2724
- settledBy?: 'account';
2773
+ settledBy?: 'account' | 'ledger';
2725
2774
  }>;
2726
2775
  }
2727
2776
  /** The payment as a receipt's public link shows it (no proof image, only that one was sent). */
@@ -2751,6 +2800,39 @@ export interface CaseReceiptPayment {
2751
2800
  changeCents?: number | null;
2752
2801
  /** The order ended undone after the customer reported or paid: the business gives the money back. */
2753
2802
  refundDue?: boolean;
2803
+ /** PDK-SERVICE-CHANGES S3 — what is still owed (+) or given back (−) after an accepted change moved the total; null/absent: nothing. */
2804
+ differenceCents?: number | null;
2805
+ /** `expiredAt` (R7-POLISH-2): the anticipo deadline passed with nothing paid and the platform cancelled the case (ISO); null otherwise; absent on an older platform. */
2806
+ plan?: {
2807
+ totalCents: number;
2808
+ anticipoPercent: number;
2809
+ anticipoCents: number;
2810
+ required: boolean;
2811
+ waived: boolean;
2812
+ dueAt: string | null;
2813
+ expiredAt?: string | null;
2814
+ cancelPolicyText: string;
2815
+ };
2816
+ paidCents?: number;
2817
+ balanceCents?: number | null;
2818
+ /** What «Cómo pagar» asks for now: the anticipo while it is owed, then the balance. */
2819
+ dueNowCents?: number | null;
2820
+ /** A reported transfer the business has not confirmed yet («En revisión»). */
2821
+ pendingCents?: number;
2822
+ anticipoDueCents?: number;
2823
+ gate?: 'deposit_due' | null;
2824
+ refundDueCents?: number;
2825
+ /** The money consequence once the case closed undone (null: none). `tier` is the applied `CancelPolicyTier` (or null). */
2826
+ cancellation?: {
2827
+ policyApplied: boolean;
2828
+ by: string;
2829
+ tier: CancelPolicyTier | null;
2830
+ retainedCents: number;
2831
+ refundCents: number;
2832
+ at: string;
2833
+ } | null;
2834
+ /** The customer's payments (no owner data, no proof URL, no actor, no App reference). */
2835
+ entries?: PublicCasePaymentEntry[];
2754
2836
  }
2755
2837
  /** AGF-CASE-RECEIPT — one product line, with the price it had when the receipt was issued. */
2756
2838
  export interface CaseReceiptLine {
@@ -2783,12 +2865,28 @@ export interface CaseReceiptLine {
2783
2865
  weigh?: string;
2784
2866
  /** The business typed its real weight: `qty` is that, not an estimate. */
2785
2867
  weighed?: boolean;
2786
- /** AGF-MENU-OPTIONS M2 — the options chosen; `unitCents` already includes them. */
2868
+ /**
2869
+ * AGF-MENU-OPTIONS M2 — the options chosen; `unitCents` already includes them.
2870
+ * `optionId`: the catalog option's id. `priceMode` (PDK-RENTAL-DEAL R1, rentals): `quote` = «a cotizar» (`deltaCents` is 0, not counted),
2871
+ * `per_trip` = `deltaCents` is charged once per unit, not × the periods.
2872
+ */
2787
2873
  options?: Array<{
2788
2874
  group: string;
2789
2875
  name: string;
2790
2876
  deltaCents: number;
2877
+ optionId?: string;
2878
+ priceMode?: RentalOptionMode;
2791
2879
  }>;
2880
+ /** PDK-RENTAL-DEAL R1 — names of the options that wait for a quote: the line is `priceKind: 'from'` («desde `unitCents`») until the business prices it. */
2881
+ quoteOptions?: string[];
2882
+ /** PDK-RENTAL-DEAL R1 — of `unitCents` (one unit over the whole range), the part charged once per unit (per-trip options): not × `periods.count`. */
2883
+ tripCents?: number;
2884
+ /** PDK-RENTAL-DEAL R1 — a line the business added in a quote (transporte, depósito…), not asked for by the customer (`offCatalog`, already priced). */
2885
+ extra?: true;
2886
+ /** PDK-RENTAL-DEAL R1 — the line of a `per_booking` option (a transport): charged once for the whole case, qty 1, key `booking#<option>`; the business may re-price it in a quote. */
2887
+ perBooking?: true;
2888
+ /** PDK-RENTAL-DEAL R1 — an extra line charged once (a trip), not × the rental's periods. */
2889
+ perTrip?: true;
2792
2890
  /** PDK-BUG-006 — the line is to go (packed for takeaway). Present only when `true`; absent means
2793
2891
  * eaten here, and also on receipts issued before this flag or by an older platform. */
2794
2892
  takeaway?: true;
@@ -2851,8 +2949,8 @@ export interface CaseLinePriceHistoryEntry {
2851
2949
  by: CaseLinePriceActor;
2852
2950
  at: string;
2853
2951
  note?: string;
2854
- /** `applied` (default) or `rejected`. */
2855
- outcome?: 'applied' | 'rejected';
2952
+ /** `applied` (default), `rejected`, or `removed` (an accepted change request took the line off the request: its price is unset, this history stays). */
2953
+ outcome?: 'applied' | 'rejected' | 'removed';
2856
2954
  answer?: 'notify' | 'accepted';
2857
2955
  }
2858
2956
  /** PDK-SERVICE-CHANGES — one line's price override with its history (oldest first). */
@@ -2867,6 +2965,71 @@ export interface CaseLinePriceEntry {
2867
2965
  }
2868
2966
  /** PDK-SERVICE-CHANGES — `CaseView.linePrices`: the line prices by receipt line `key`. */
2869
2967
  export type CaseLinePrices = Record<string, CaseLinePriceEntry>;
2968
+ /** PDK-SERVICE-CHANGES S3 — which form a change needs, from the request's time (booking, rental) or the kinds of its lines. */
2969
+ export type CaseChangeKind = 'items' | 'service' | 'booking' | 'rental' | 'mixed';
2970
+ /**
2971
+ * PDK-SERVICE-CHANGES S3 — why the customer cannot ask a change now (`CaseView.changeReason`, and the `code` of the 409 on
2972
+ * `cases.receiptRequestChange`): `case_closed`; `case_not_sent` (still being put together: edit it); `change_window_closed`
2973
+ * (the rule of its kind: products — confirmed; quote — the customer accepted a price; service — in progress; booking/rental —
2974
+ * fewer than `changeWindowHours`, default 24, before it starts); `change_pending` (the business has a change waiting).
2975
+ */
2976
+ export type CaseChangeReason = 'case_closed' | 'case_not_sent' | 'change_window_closed' | 'change_pending';
2977
+ /** One line of a change request: the FULL new line set replaces the case's catalog lines (units for a rental). */
2978
+ export interface CaseChangeLine {
2979
+ productId: string;
2980
+ /** In the product's unit; or `amountCents` for a product sold by value. */
2981
+ quantity?: number;
2982
+ amountCents?: number;
2983
+ options?: unknown[];
2984
+ takeaway?: boolean;
2985
+ }
2986
+ /**
2987
+ * PDK-SERVICE-CHANGES S3 — what `cases.receiptRequestChange` / `cases.requestChange` send. At least one of `lines`, `data`,
2988
+ * `destination`, `slot` or `rental`. Nothing is held or charged until the business accepts.
2989
+ */
2990
+ export interface CaseChangeInput {
2991
+ /** Why / what for (≤ 500 characters), shown to the business. */
2992
+ note?: string;
2993
+ /** The FULL new set of products/services (units for a rental). Not for a booking (change its `slot`). */
2994
+ lines?: CaseChangeLine[];
2995
+ /** Field answers to change, by the case type's field keys (`null` clears one). */
2996
+ data?: Record<string, unknown>;
2997
+ /** The new address/delivery (`null`: no delivery any more). Its `quote` goes on the receipt's total, as on a direct order. */
2998
+ destination?: CaseDestination | null;
2999
+ /** A booking's new time (you already checked it is free: the platform keeps what was booked, you own availability). */
3000
+ slot?: {
3001
+ startsAt: string;
3002
+ endsAt: string;
3003
+ timezone?: string;
3004
+ resourceId?: string | null;
3005
+ resourceName?: string;
3006
+ };
3007
+ /** A rental's new range (you already hold it); `lines[].periodRateCents` needs an App sk_ key, as on `updateRental`. */
3008
+ rental?: {
3009
+ startsAt: string;
3010
+ endsAt: string;
3011
+ timezone?: string;
3012
+ periods?: {
3013
+ unit?: RentalPeriodUnit;
3014
+ count?: number;
3015
+ };
3016
+ lines?: Array<{
3017
+ productId: string;
3018
+ periodRateCents: number;
3019
+ }>;
3020
+ };
3021
+ }
3022
+ /** PDK-SERVICE-CHANGES S3 — the change waiting for the business (`CaseView.pendingChange`, `CaseReceipt.pendingChange`). */
3023
+ export interface CasePendingChange extends CaseChangeInput {
3024
+ id: string;
3025
+ /** Who asked: the customer (receipt) or the App on their behalf. */
3026
+ by: 'customer' | 'business';
3027
+ at: string;
3028
+ status: 'pending';
3029
+ /** What the receipt would add up to if it were accepted now (line prices, rental rates and delivery included); null: a line still has no price. */
3030
+ previewTotalCents?: number | null;
3031
+ previewCurrency?: string | null;
3032
+ }
2870
3033
  /** PDK-SERVICE-CHANGES — what `cases.setLinePrice` sends. */
2871
3034
  export interface SetCaseLinePriceInput {
2872
3035
  /** The receipt line's `key` (a line of the order: product, service, booking or rental; not a free `off#n` line). */
@@ -2935,7 +3098,10 @@ export interface CaseProposalChange {
2935
3098
  */
2936
3099
  export interface CaseProposal {
2937
3100
  id: string;
2938
- /** `redone`: the customer chose «Rehacer pedido» (the order went back to being edited). */
3101
+ /**
3102
+ * `redone`: the customer chose «Rehacer pedido» (the order went back to being edited). A rental quote's proposal (`quote`) ends `accepted`,
3103
+ * or `withdrawn` for every other end (rejected, changes requested, expired, taken back): which one is `CaseView.quote.versions[n].status`.
3104
+ */
2939
3105
  status: 'pending' | 'accepted' | 'withdrawn' | 'redone';
2940
3106
  sentAt: string;
2941
3107
  answeredAt?: string;
@@ -2951,6 +3117,14 @@ export interface CaseProposal {
2951
3117
  offCatalog?: true;
2952
3118
  /** PDK-SERVICE-CHANGES — a quote of line prices (`cases.setLinePrice`, `answer: 'required'`): the customer must accept or reject (`requiresAnswer` is true, never auto-accepted); each accepted price becomes the line's price and the receipt is re-issued; a rejected one leaves the line as it was. */
2953
3119
  linePrice?: true;
3120
+ /**
3121
+ * PDK-RENTAL-DEAL R1 — a rental QUOTE version waiting for the customer (`cases.sendQuote`). It is NOT answered with `answerProposal` /
3122
+ * `receiptAnswerProposal` (400 `use_quote_answer`) but with `receiptAnswerQuote` / `answerQuote`. `changes` lists the lines priced in it.
3123
+ */
3124
+ quote?: {
3125
+ version: number;
3126
+ validUntil: string;
3127
+ };
2954
3128
  /** PDK-OFF-CATALOG — the customer MUST answer (a line is out or swapped, or its amount is over what they said × 1.2); payment waits for it. */
2955
3129
  requiresAnswer?: boolean;
2956
3130
  /**
@@ -3042,6 +3216,21 @@ export interface CaseReceipt {
3042
3216
  } | null;
3043
3217
  /** AGF-PDK-DISPATCH-PROPOSAL — the business's latest proposed changes and their answer (absent on an older platform). */
3044
3218
  proposal?: CaseProposal | null;
3219
+ /**
3220
+ * PDK-RENTAL-DEAL R1 — a rental QUOTE request: its status, the version in force and the history (sent / accepted / rejected /
3221
+ * changes_requested / superseded / expired, each with validity, total, comments), the lines still «a cotizar» and what the customer may do
3222
+ * now (`actions`). Answer with `cases.receiptAnswerQuote`. Null / absent: not a quote (or an older platform).
3223
+ */
3224
+ quote?: CaseReceiptQuote | null;
3225
+ /** PDK-SERVICE-CHANGES S3 — the customer may ask a change now (`cases.receiptRequestChange`); `changeReason` says why not. Absent on an older platform. */
3226
+ changeAllowed?: boolean;
3227
+ changeReason?: CaseChangeReason;
3228
+ /** Which form the change needs: `items` (the cart), `service`, `booking` (time), `rental` (range) or `mixed`. */
3229
+ changeKind?: CaseChangeKind;
3230
+ /** A booking or a rental: the last instant a change can still be asked (ISO). */
3231
+ changeUntil?: string;
3232
+ /** The change asked and waiting for the business; null/absent: none. */
3233
+ pendingChange?: CasePendingChange | null;
3045
3234
  business: {
3046
3235
  name: string;
3047
3236
  description: string | null;
@@ -3549,7 +3738,14 @@ export interface CaseRental {
3549
3738
  };
3550
3739
  /** The rate of ONE period of ONE unit per product id when your App priced the lines (`periodRateCents`); absent: the catalog price. */
3551
3740
  periodRates?: Record<string, number>;
3741
+ /**
3742
+ * PDK-RENTAL-DEAL R1 — options charged apart from the periods, by the option's id or its lower-cased accent-free name (what you sent in
3743
+ * `lines[].optionPricing`): `quote` = «a cotizar», `per_trip` = charged once per unit, `per_booking` = once for the whole case. Absent: every option is charged per period.
3744
+ */
3745
+ optionModes?: Record<string, RentalOptionMode>;
3552
3746
  }
3747
+ /** PDK-RENTAL-DEAL R1 — how a rental option is charged when it is not «per period and unit». */
3748
+ export type RentalOptionMode = 'quote' | 'per_trip' | 'per_booking';
3553
3749
  /**
3554
3750
  * `POST /api/v1/cases/direct-rental` — an order of items rented over a time range. The body of `CreateDirectOrderInput`
3555
3751
  * (customer, lines, fields, destination, origin, payment, type, idempotencyKey…) plus `rental`. Without the options
@@ -3559,7 +3755,7 @@ export interface CaseRental {
3559
3755
  * price of ONE period (with the chosen `options`) × units × `rental.periods.count`. Never send totals; an App that owns a rate
3560
3756
  * table sends only the rate of one period per line (`lines[].periodRateCents`, R2d).
3561
3757
  */
3562
- export interface CreateDirectRentalInput extends Omit<CreateDirectOrderInput, 'lines' | 'reopens' | 'allowOffCatalog' | 'maxOffCatalogLines' | 'offCatalogLines'> {
3758
+ export interface CreateDirectRentalInput extends Omit<CreateDirectOrderInput, 'lines' | 'reopens'> {
3563
3759
  lines: Array<{
3564
3760
  productId: string;
3565
3761
  /** Units of the item (2 backhoes). */
@@ -3574,7 +3770,33 @@ export interface CreateDirectRentalInput extends Omit<CreateDirectOrderInput, 'l
3574
3770
  * The same product on two lines must use the same rate. Send the SAME unit as `rental.periods.unit`.
3575
3771
  */
3576
3772
  periodRateCents?: number;
3773
+ /**
3774
+ * PDK-RENTAL-DEAL R1 — options of THIS line that are not charged «per period and unit» (only for an App: an sk_ key bound to an App, 403
3775
+ * without it). `option` names an option the line chose (`options[].options`, by id or name); `mode`: `per_trip` = its price delta is charged
3776
+ * ONCE per unit, not × `rental.periods.count`; `per_booking` = ONCE for the whole case (a transport: not × units nor periods; it becomes its own
3777
+ * receipt line, `perBooking: true`, qty 1, even when several lines chose it); `quote` = it has no price: the line shows «desde» (without it) and waits
3778
+ * for the business's quote. A `quote` option makes the booking a quote request: it needs `quote: true` (400 `quote_required` otherwise).
3779
+ * An option the line did not choose, or one named twice with two modes, is a 400.
3780
+ */
3781
+ optionPricing?: Array<{
3782
+ option: string;
3783
+ mode: RentalOptionMode;
3784
+ }>;
3577
3785
  }>;
3786
+ /**
3787
+ * PDK-RENTAL-DEAL R1 — this is a QUOTE REQUEST, not a booking: the case stays `submitted` with `receipt.pricePending` (never instant, nothing
3788
+ * is paid), and the business answers with `cases.sendQuote`. Required when anything is pending a price: a line with a `quote` option, or
3789
+ * `offCatalogLines` (free-text extras the customer asks for: title + qty, with `allowOffCatalog: true`) — 400 `quote_required` otherwise;
3790
+ * `confirmation: 'instant'` with it is a 400 `quote_not_instant`. A rental with nothing pending behaves as before.
3791
+ */
3792
+ quote?: boolean;
3793
+ /**
3794
+ * PDK-RENTAL-DEAL R7 — partial payments: the anticipo (a % of the agreed total, rounded UP to 1 000 COP), its deadline and the cancellation
3795
+ * policy. Frozen on the case when it is agreed (on a quote request, when the customer accepts a version: send the plan with the quote request
3796
+ * as the default, or with `sendQuote` per version). 0 % and no enabled policy = no plan (the legacy single payment). 400 `invalid_payment_plan` /
3797
+ * `invalid_cancel_policy`. With a required anticipo, `confirmation: 'instant'` waits in `accepted` and confirms itself when the anticipo is in.
3798
+ */
3799
+ paymentPlan?: CasePaymentPlanInput;
3578
3800
  rental: {
3579
3801
  /** ISO instants with their offset (Z or ±hh:mm); at most 366 days apart. */
3580
3802
  startsAt: string;
@@ -3591,6 +3813,348 @@ export interface CreateDirectRentalInput extends Omit<CreateDirectOrderInput, 'l
3591
3813
  /** `review` (default): the business accepts it (`submitted`); `instant`: `confirmed` as it is made (your ledger guarantees the units). */
3592
3814
  confirmation?: 'review' | 'instant';
3593
3815
  }
3816
+ /** One tier of a cancellation policy: with a notice of at least `minHoursBefore` hours before the rental starts, retain `percent` % or `fixedCents`. */
3817
+ export interface CancelPolicyTier {
3818
+ /** Whole hours, 0 or more. Tiers are sorted highest first, strictly descending, and the LAST one is 0 (short notice, after the start, no-shows). */
3819
+ minHoursBefore: number;
3820
+ mode: 'percent' | 'fixed';
3821
+ /** `mode: 'percent'`: whole number 0–100 (rounded up to the peso). */
3822
+ percent?: number;
3823
+ /** `mode: 'fixed'`: positive whole cents. */
3824
+ fixedCents?: number;
3825
+ }
3826
+ /** The cancellation policy: 1–4 tiers when `enabled` (none needed when disabled). The retention is capped at what was paid. */
3827
+ export interface CancelPolicy {
3828
+ enabled: boolean;
3829
+ /** What a percent tier is a percent of: the agreed `total` (default) or the `anticipo`. */
3830
+ basis?: 'total' | 'anticipo';
3831
+ tiers: CancelPolicyTier[];
3832
+ }
3833
+ /** What a host App sends with a direct rental / a quote version: `paymentPlan`. */
3834
+ export interface CasePaymentPlanInput {
3835
+ /** Whole number 0–100. 0 with no enabled policy = no plan. */
3836
+ anticipoPercent: number;
3837
+ /** Hours from acceptance to the anticipo deadline, whole 1–168 (default 48). */
3838
+ anticipoDueHours?: number;
3839
+ /** ISO instant: the deadline is never after it (the platform also caps it at the rental start − 1 h). */
3840
+ notLaterThan?: string;
3841
+ cancelPolicy?: CancelPolicy;
3842
+ }
3843
+ /** The plan frozen on the case when the agreement is made (`CaseView.payment.plan`). */
3844
+ export interface CasePaymentPlan {
3845
+ totalCents: number;
3846
+ anticipoPercent: number;
3847
+ anticipoCents: number;
3848
+ /** Gates confirmation / dispatch (true when the anticipo is > 0). */
3849
+ required: boolean;
3850
+ waived?: {
3851
+ at: string;
3852
+ by: string;
3853
+ note: string;
3854
+ };
3855
+ dueHours: number;
3856
+ notLaterThan?: string;
3857
+ /** The anticipo deadline, set when the case is accepted. */
3858
+ dueAt?: string;
3859
+ acceptedAt?: string;
3860
+ /** The deadline was pushed (`cases.extendAnticipo`, or a late report was rejected). */
3861
+ extendedAt?: string;
3862
+ rejectExtended?: true;
3863
+ /** The expiry sweep claimed it: the case is being cancelled and no money is taken any more (409 `deposit_expired`). */
3864
+ expiredAt?: string;
3865
+ overdueNotifiedAt?: string;
3866
+ cancelPolicy?: CancelPolicy;
3867
+ frozenFrom: 'quote' | 'booking';
3868
+ quoteVersion?: number;
3869
+ /** An instant rental held in `accepted` until the anticipo is in: it confirms itself then. */
3870
+ autoConfirm?: true;
3871
+ frozenAt: string;
3872
+ }
3873
+ export type CasePaymentEntryKind = 'anticipo' | 'saldo' | 'other' | 'refund';
3874
+ export type CasePaymentEntryStatus = 'confirmed' | 'pending' | 'rejected';
3875
+ export type CasePaymentEntrySource = 'owner' | 'driver' | 'online' | 'customer';
3876
+ /** One row of a case's append-only payment ledger (`cases.payments`), as the business reads it. */
3877
+ export interface CasePaymentEntry {
3878
+ id: string;
3879
+ /** Position in the ledger, from 1. */
3880
+ seq: number;
3881
+ kind: CasePaymentEntryKind;
3882
+ /** Positive cents (a refund too: `kind: 'refund'` says the direction). */
3883
+ amountCents: number;
3884
+ status: CasePaymentEntryStatus;
3885
+ source: CasePaymentEntrySource;
3886
+ method: string | null;
3887
+ account: CasePaymentAccount | null;
3888
+ reference: string | null;
3889
+ proofUrl: string | null;
3890
+ note: string | null;
3891
+ /** `<caseCode>-P<seq>`: what the customer reads and the PDF prints. */
3892
+ receiptNo: string;
3893
+ actor: string | null;
3894
+ externalRef: Record<string, unknown> | null;
3895
+ /** A refund / reversal points at the entry it undoes. */
3896
+ reversesId: string | null;
3897
+ occurredAt: string;
3898
+ /** When it counted as money (confirmed). Null while pending / when rejected. */
3899
+ countedAt: string | null;
3900
+ resolvedAt: string | null;
3901
+ resolutionNote: string | null;
3902
+ }
3903
+ /** What the customer sees of an entry (`CaseReceipt.payment.entries`). */
3904
+ export interface PublicCasePaymentEntry {
3905
+ kind: CasePaymentEntryKind;
3906
+ amountCents: number;
3907
+ status: CasePaymentEntryStatus;
3908
+ methodName: string | null;
3909
+ receiptNo: string;
3910
+ occurredAt: string;
3911
+ countedAt: string | null;
3912
+ }
3913
+ export type CancelBy = 'customer' | 'business' | 'system';
3914
+ /** The money consequence of cancelling (`cases.cancellationPreview`). */
3915
+ export interface CancellationOutcome {
3916
+ by: CancelBy;
3917
+ /** The policy applies only when the CUSTOMER cancels (the business and the system cancel without a penalty by default). */
3918
+ policyApplied: boolean;
3919
+ /** Hours between the cancel and the rental start (negative after it); null without a start. */
3920
+ noticeHours: number | null;
3921
+ tier: CancelPolicyTier | null;
3922
+ /** Index into `plan.cancelPolicy.tiers` (absent on the customer's public preview). */
3923
+ tierIndex?: number | null;
3924
+ basis: 'total' | 'anticipo' | null;
3925
+ computedPenaltyCents: number;
3926
+ paidCents: number;
3927
+ retainedCents: number;
3928
+ refundCents: number;
3929
+ /** True when the case already closed undone: these are its frozen figures. */
3930
+ frozen: boolean;
3931
+ currency: string | null;
3932
+ }
3933
+ /** `CaseView.payment.cancellation`: the outcome frozen when the case closed undone. */
3934
+ export interface CaseCancellation extends Omit<CancellationOutcome, 'frozen' | 'currency' | 'tierIndex'> {
3935
+ tierIndex: number | null;
3936
+ at: string;
3937
+ /** The retention the team settled on when it differs from the suggestion (recorded with a reason on the refund entry). */
3938
+ agreedRetainedCents?: number;
3939
+ }
3940
+ /** `POST :id/payments` — money that came in. A confirmed entry. */
3941
+ export interface RecordCasePaymentInput {
3942
+ /** Positive whole cents; at most the balance (400 `exceeds_balance`). */
3943
+ amountCents: number;
3944
+ /** Informational: `anticipo` while it is owed, then `saldo`. Never `refund` (use `refundPayment`). */
3945
+ kind?: 'anticipo' | 'saldo' | 'other';
3946
+ /** How the money moved: one of the business's payment accounts… */
3947
+ accountId?: string;
3948
+ /** …or a method key (`efectivo`, `nequi`, `transferencia`…). One of the two is required (400 `method_required`). */
3949
+ method?: string;
3950
+ source?: 'owner' | 'driver';
3951
+ reference?: string;
3952
+ note?: string;
3953
+ /** Who of the business recorded it (≤ 120). */
3954
+ actor?: string;
3955
+ /** Your own reference (e.g. a POS ticket id); object, ≤ 1000 chars. */
3956
+ externalRef?: Record<string, unknown>;
3957
+ /** 8–120 of `A-Za-z0-9_.:-`, chosen and kept by the CALLER: the same key + body replays (`replayed: true`); another body → 409 `idempotency_conflict`. */
3958
+ idempotencyKey: string;
3959
+ }
3960
+ /** `POST :id/payments/refund` — money given back. */
3961
+ export interface RefundCasePaymentInput {
3962
+ /** Positive whole cents, at most what is paid (400 `exceeds_paid`). */
3963
+ amountCents: number;
3964
+ /** What the business keeps of what was paid. On a case cancelled under a policy, anything but the suggestion needs `reason` (400 `reason_required`). */
3965
+ retainedCents?: number;
3966
+ reason?: string;
3967
+ accountId?: string;
3968
+ method?: string;
3969
+ actor?: string;
3970
+ idempotencyKey: string;
3971
+ }
3972
+ /** What every ledger write answers: the case as it is now and the entry written. */
3973
+ export interface CasePaymentWriteResult {
3974
+ case: CaseView;
3975
+ entry: CasePaymentEntry;
3976
+ /** True when the same `idempotencyKey` + body had already been applied. */
3977
+ replayed: boolean;
3978
+ }
3979
+ /** PDK-RENTAL-DEAL R1 — the status of a rental quote. `requested`: the business owes a version (none yet, or the last one was withdrawn). */
3980
+ export type CaseQuoteStatus = 'requested' | 'sent' | 'changes_requested' | 'accepted' | 'rejected' | 'expired' | 'withdrawn';
3981
+ /** PDK-RENTAL-DEAL R1 — `sent`: waiting for the customer; the others are final for that version (`changes_requested`: the business sends the next). */
3982
+ export type CaseQuoteVersionStatus = 'sent' | 'accepted' | 'rejected' | 'changes_requested' | 'superseded' | 'expired' | 'withdrawn';
3983
+ /** PDK-RENTAL-DEAL R1b — what the customer asked the business for, recorded by the App (`cases.customerRequest`). */
3984
+ export type CaseCustomerRequestKind = 'asks_cancel' | 'asks_change';
3985
+ /** PDK-RENTAL-DEAL R1 — one line of a quote as the customer reads it. `unitCents` = one unit as charged (over the whole range for a rented item); `amountCents` = `unitCents` × `qty`. */
3986
+ export interface CaseQuoteLine {
3987
+ /** The receipt line's key. An extra the business added is `quote#n` here and becomes `off#n` on the receipt once accepted (`CaseQuoteVersion.extras[].key`). */
3988
+ key: string;
3989
+ title: string;
3990
+ qty: number;
3991
+ unit?: string;
3992
+ options?: Array<{
3993
+ group: string;
3994
+ name: string;
3995
+ deltaCents: number;
3996
+ priceMode?: RentalOptionMode;
3997
+ }>;
3998
+ periods?: {
3999
+ unit: string;
4000
+ count: number;
4001
+ unitCents: number | null;
4002
+ };
4003
+ unitCents: number;
4004
+ amountCents: number;
4005
+ /** The business priced this line in this version. */
4006
+ quoted?: true;
4007
+ /** A line the business added (transporte, depósito…). `perTrip`: charged once, not × the periods. */
4008
+ extra?: true;
4009
+ perTrip?: true;
4010
+ note?: string;
4011
+ breakdown?: CaseLinePriceBreakdownItem[];
4012
+ }
4013
+ /** PDK-RENTAL-DEAL R1 — a price as the version froze it (`unitCents`: ONE unit over the whole range, what `linePrices` stores). */
4014
+ export interface CaseQuotePrice {
4015
+ line: string;
4016
+ unitCents: number;
4017
+ per: 'range' | 'period';
4018
+ /** What was typed (`unitCents` ÷ periods when `per` is `period`). */
4019
+ inputCents: number;
4020
+ note?: string;
4021
+ breakdown?: CaseLinePriceBreakdownItem[];
4022
+ }
4023
+ /** PDK-RENTAL-DEAL R1 — a line the business added in a version, as frozen (`unitCents`: one unit as charged). `key`: its `off#n` on the receipt, once accepted. */
4024
+ export interface CaseQuoteExtra {
4025
+ key?: string;
4026
+ title: string;
4027
+ qty: number;
4028
+ unitCents: number;
4029
+ inputCents: number;
4030
+ perTrip: boolean;
4031
+ note?: string;
4032
+ }
4033
+ /** PDK-RENTAL-DEAL R1 — one immutable quote version, as the business reads it (`CaseView.quote.versions`). */
4034
+ export interface CaseQuoteVersion {
4035
+ version: number;
4036
+ id: string;
4037
+ status: CaseQuoteVersionStatus;
4038
+ sentAt: string;
4039
+ /** ISO instant: unanswered after it, the quote expires. */
4040
+ validUntil: string;
4041
+ /** The business's conditions note (what is included, cancellation…). */
4042
+ note: string | null;
4043
+ by: CaseLinePriceActor;
4044
+ currency: string | null;
4045
+ /** The whole order as it will be charged if this version is accepted. */
4046
+ lines: CaseQuoteLine[];
4047
+ deliveryCents: number | null;
4048
+ totalCents: number;
4049
+ /** The receipt revision it was made on. */
4050
+ revision: number;
4051
+ /** The inputs, resolved (what accepting applies). */
4052
+ prices: CaseQuotePrice[];
4053
+ extras: CaseQuoteExtra[];
4054
+ answeredAt?: string;
4055
+ answeredBy?: 'customer' | 'business' | 'system';
4056
+ /** The customer's words (`changes_requested`, or a reason when they rejected). */
4057
+ comment?: string;
4058
+ /** PDK-RENTAL-DEAL R7 — the payment plan sent with this version and the anticipo it makes on this version's total (promoted to `payment.plan` when the customer accepts THIS version). */
4059
+ paymentPlan?: CasePaymentPlanInput & {
4060
+ anticipoCents: number;
4061
+ };
4062
+ }
4063
+ /** PDK-RENTAL-DEAL R1 — `CaseView.quote`. */
4064
+ export interface CaseQuote {
4065
+ status: CaseQuoteStatus;
4066
+ requestedAt: string;
4067
+ /** The latest version (waiting for the customer, or how it ended); null before the first. */
4068
+ current: CaseQuoteVersion | null;
4069
+ /** Every version, oldest first. */
4070
+ versions: CaseQuoteVersion[];
4071
+ /** The version the customer accepted: the agreement. */
4072
+ agreedVersion: number | null;
4073
+ }
4074
+ /** PDK-RENTAL-DEAL R1 — a version on the public link: no inputs and no who. */
4075
+ export interface CaseReceiptQuoteVersion {
4076
+ version: number;
4077
+ status: CaseQuoteVersionStatus;
4078
+ sentAt: string;
4079
+ validUntil: string;
4080
+ note: string | null;
4081
+ currency: string | null;
4082
+ lines: CaseQuoteLine[];
4083
+ deliveryCents: number | null;
4084
+ totalCents: number;
4085
+ answeredAt?: string;
4086
+ comment?: string;
4087
+ /** PDK-RENTAL-DEAL R7 — the anticipo this version asks for and the cancellation policy, as the customer reads them before accepting. */
4088
+ payment?: {
4089
+ anticipoPercent: number;
4090
+ anticipoCents: number;
4091
+ anticipoDueHours?: number;
4092
+ cancelPolicyText: string;
4093
+ };
4094
+ }
4095
+ /** PDK-RENTAL-DEAL R1 — what a customer may do on a quote's receipt: `cancel` is the case's own cancel (`receiptCancel`). */
4096
+ export type CaseQuoteAction = 'accept' | 'reject' | 'changes_requested' | 'cancel';
4097
+ /** PDK-RENTAL-DEAL R1 — `CaseReceipt.quote`. */
4098
+ export interface CaseReceiptQuote {
4099
+ status: CaseQuoteStatus;
4100
+ requestedAt: string;
4101
+ /** The version in force (waiting for the customer, else the latest); null before the first. */
4102
+ current: CaseReceiptQuoteVersion | null;
4103
+ /** Every version, oldest first (the current one included). */
4104
+ versions: CaseReceiptQuoteVersion[];
4105
+ agreedVersion: number | null;
4106
+ /** The lines the business has not priced yet («a cotizar»): catalog lines (`quoteOptions`) and the free ones the customer asked for. */
4107
+ pendingLines: Array<{
4108
+ key: string;
4109
+ title: string;
4110
+ qty: number;
4111
+ quoteOptions?: string[];
4112
+ }>;
4113
+ /** What the customer may do now. `accept` / `reject` / `changes_requested` only while a version waits and is valid. */
4114
+ actions: CaseQuoteAction[];
4115
+ }
4116
+ /** PDK-RENTAL-DEAL R1 — what `cases.sendQuote` sends. */
4117
+ export interface SendCaseQuoteInput {
4118
+ /**
4119
+ * The price of every line nobody priced (receipt `key`: a catalog line with a `quote` option, or a pending free line `off#n`); a priced
4120
+ * catalog line may be re-priced too. 400 `prices_missing` (with `lines`) when a pending one has none. `unitCents` is ONE unit over the
4121
+ * WHOLE range (`per: 'range'`, default) or for ONE period (`per: 'period'`, × the rental's periods); 0 = «gratis». `breakdown` adds up to `unitCents`.
4122
+ */
4123
+ prices: Array<{
4124
+ line: string;
4125
+ unitCents: number;
4126
+ per?: 'range' | 'period';
4127
+ note?: string;
4128
+ breakdown?: CaseLinePriceBreakdownItem[];
4129
+ }>;
4130
+ /** Lines the business adds (transporte ida/regreso, depósito, horas extra…), at most 20: `unitCents` × `qty`, × the periods unless `perTrip`. */
4131
+ extras?: Array<{
4132
+ title: string;
4133
+ qty?: number;
4134
+ unitCents: number;
4135
+ perTrip?: boolean;
4136
+ note?: string;
4137
+ }>;
4138
+ /** ISO instant with offset, in the future and at most 90 days ahead. Unanswered after it, the quote expires and the case ends `cancelled` (by `system`). */
4139
+ validUntil: string;
4140
+ /** Conditions (≤ 1000): what is included, cancellation, deposit. */
4141
+ note?: string;
4142
+ /** Who of the business sends it (default `{ id: 'business' }`). */
4143
+ by?: CaseLinePriceActor;
4144
+ /**
4145
+ * PDK-RENTAL-DEAL R7 — the payment plan of THIS version (anticipo %, deadline, cancellation policy); a version sent without one keeps the plan
4146
+ * the quote request came with. It is frozen on the case when the customer accepts this version. 400 `invalid_payment_plan` / `invalid_cancel_policy`.
4147
+ */
4148
+ paymentPlan?: CasePaymentPlanInput;
4149
+ }
4150
+ /** PDK-RENTAL-DEAL R1 — the answer to a quote version: `cases.receiptAnswerQuote` (the customer) / `cases.answerQuote` (the business, by phone). */
4151
+ export interface CaseQuoteAnswerInput {
4152
+ answer: 'accept' | 'reject' | 'changes_requested';
4153
+ /** ≤ 1000. Required with `changes_requested`; with `reject` it is the reason (kept as the case's note, ≤ 500). */
4154
+ comment?: string;
4155
+ /** The version being answered: 409 `quote_stale` when it was replaced meanwhile. */
4156
+ version?: number;
4157
+ }
3594
4158
  /** `PATCH /api/v1/cases/:id/rental` — reschedule or extend: the new range (you already hold it). */
3595
4159
  export interface UpdateCaseRentalInput {
3596
4160
  startsAt: string;
@@ -3622,7 +4186,7 @@ export interface MoveCaseSlotInput {
3622
4186
  }
3623
4187
  import type { AppBillingWebhookEvent } from './resources/billing';
3624
4188
  import type { ContactPropertiesPatch } from './resources/contacts';
3625
- export type AppCaseWebhookEventName = 'case.submitted' | 'case.state_changed' | 'case.closed' | 'case.customer_request' | 'case.payment_changed' | 'case.proposal';
4189
+ export type AppCaseWebhookEventName = 'case.submitted' | 'case.state_changed' | 'case.closed' | 'case.customer_request' | 'case.payment_changed' | 'case.proposal' | 'case.change' | 'case.deposit_overdue';
3626
4190
  export type AppWebhookEventName = AppCaseWebhookEventName | 'conversation.message' | 'channel.status_changed' | 'billing.plan_changed' | 'billing.trial_ended';
3627
4191
  export interface AppWebhook {
3628
4192
  url: string;
@@ -3691,7 +4255,37 @@ export interface AppCaseWebhookEvent extends AppWebhookEventBase {
3691
4255
  paymentStatus?: CasePaymentStatus;
3692
4256
  previousPaymentStatus?: CasePaymentStatus;
3693
4257
  /** `case.proposal` (AGF-PDK-DISPATCH-PROPOSAL): the business sent or withdrew changes, or they were answered. */
3694
- proposal?: 'sent' | 'accepted' | 'withdrawn' | 'redone';
4258
+ proposal?: 'sent' | 'accepted' | 'withdrawn' | 'redone' | 'quote_sent' | 'quote_accepted' | 'quote_rejected' | 'quote_changes_requested' | 'quote_expired';
4259
+ /**
4260
+ * PDK-RENTAL-DEAL R1 — with `proposal: 'quote_*'` (a `case.proposal` event; no new event name to subscribe to): the quote version it is about.
4261
+ * `quote_sent` (the business sent version N), `quote_accepted` (the case is now `accepted`), `quote_rejected` (the case ended `rejected`),
4262
+ * `quote_changes_requested` (read the version's `comment`; the case stays open), `quote_expired` (the case ended `cancelled` by `system`).
4263
+ */
4264
+ quoteVersion?: number;
4265
+ /**
4266
+ * `case.change` (PDK-SERVICE-CHANGES S3): a change request was `requested` (by the customer or the App), `accepted` or `rejected`
4267
+ * by the business, or `withdrawn` by the customer. `by` is who did this move; the case keeps its state while a change waits.
4268
+ */
4269
+ change?: 'requested' | 'accepted' | 'rejected' | 'withdrawn';
4270
+ /**
4271
+ * PDK-RENTAL-DEAL R7 — `case.payment_changed` / `case.deposit_overdue` on a case paid in parts: what it has paid, still owes and is asked now,
4272
+ * and the payment entry this move recorded. Absent on every case paid as a whole.
4273
+ */
4274
+ paidCents?: number;
4275
+ balanceCents?: number;
4276
+ dueNowCents?: number;
4277
+ entry?: {
4278
+ id: string;
4279
+ kind: CasePaymentEntryKind;
4280
+ amountCents: number;
4281
+ status: CasePaymentEntryStatus;
4282
+ method: string | null;
4283
+ source: CasePaymentEntrySource;
4284
+ receiptNo: string;
4285
+ };
4286
+ /** `case.deposit_overdue` (once, when money came in but the anticipo is still short after its deadline): the anticipo still owed and its (passed) deadline. No state change: the team decides. */
4287
+ anticipoDueCents?: number;
4288
+ dueAt?: string;
3695
4289
  /** AGF-ORDER-ORIGIN-POS — where the case came from (cases from before carry none). */
3696
4290
  origin?: CaseOrigin;
3697
4291
  };