@agentforge-io/sdk-server 4.86.0 → 4.87.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/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export type { AgentForgeClientOptions, RequestOptions } from './client';
3
3
  export { AgentForgeError, AgentForgeAuthError, AgentForgeNotFoundError, AgentForgeNetworkError, AgentForgeDuplicateContactError, AgentForgeBillingError, AGENTFORGE_BILLING_ERROR_CODES, AgentForgeCreditError, AGENTFORGE_CREDIT_ERROR_CODES, } from './errors';
4
4
  export type { AgentForgeBillingErrorCode, AgentForgeCreditErrorCode } from './errors';
5
5
  export { CreditResource, CreditAccountsResource } from './resources/credit';
6
+ export type { CreateDirectRentalInput, UpdateCaseRentalInput, CaseRental, RentalPeriodUnit } from './types';
6
7
  export type { CreditEntryKind, CreditAgingBucket, CreditAccountStatus, CreditEntry, CreditAllocation, CreditDebt, CreditAccount, CreditWriteResult, CreditStatementRow, CreditAccountListRow, CreditAccountsQuery, CreditAccountsPage, CreditStatementQuery, CreditStatement, UpdateCreditAccountInput, CreditPayInput, CreditReversePaymentInput, CreditWriteOffInput, CreditOpeningInput, CreditPayoutInput, } from './resources/credit';
7
8
  export { BillingResource } from './resources/billing';
8
9
  export type { BillingCurrency, BillingEntitlement, BillingEntitlementStatus, BillingInterval, BillingLimits, BillingPlan, BillingInvoice, BillingInvoicePage, BillingInvoicesQuery, BillingPaymentMethod, BillingCheckoutInput, BillingStartTrialInput, AppBillingWebhookEvent, AppBillingWebhookEventName, AppBillingWebhookData, } from './resources/billing';
@@ -1,5 +1,5 @@
1
1
  import type { AgentForgeClient } from '../client';
2
- import type { CaseAccount, ConfirmCaseLineInput, CaseClosingReport, CaseProposalAnswer, CaseProposalInput, CaseReportPage, CasePaymentStatus, CaseReceipt, CaseState, CaseView, CreateDirectBookingInput, CreateDirectOrderInput, CreateOpenOrderInput, DirectOrderForm, ListCasesInput, MoveCaseSlotInput, ProductReview, ReceiptReviewables, SaveReceiptReviewInput, SetOnAccountInput, SetOnAccountResult } from '../types';
2
+ import type { CaseAccount, ConfirmCaseLineInput, CaseClosingReport, CaseProposalAnswer, CaseProposalInput, CaseReportPage, CasePaymentStatus, CaseReceipt, CaseState, CaseView, CreateDirectBookingInput, CreateDirectOrderInput, CreateDirectRentalInput, CreateOpenOrderInput, DirectOrderForm, ListCasesInput, MoveCaseSlotInput, ProductReview, ReceiptReviewables, SaveReceiptReviewInput, SetOnAccountInput, SetOnAccountResult, UpdateCaseRentalInput } from '../types';
3
3
  export declare class CasesResource {
4
4
  private readonly client;
5
5
  constructor(client: AgentForgeClient);
@@ -161,6 +161,7 @@ export declare class CasesResource {
161
161
  */
162
162
  directForm(opts?: {
163
163
  type?: string;
164
+ rental?: boolean;
164
165
  }): Promise<DirectOrderForm>;
165
166
  /**
166
167
  * `POST /api/v1/cases/direct` — AGF-ORDER-WITHOUT-AI: an order placed without the
@@ -178,6 +179,24 @@ export declare class CasesResource {
178
179
  * duration. A retried `idempotencyKey` returns the same booking.
179
180
  */
180
181
  createDirectBooking(input: CreateDirectBookingInput): Promise<CaseView>;
182
+ /**
183
+ * `POST /api/v1/cases/direct-rental` — PDK-RENTAL-AVAILABILITY: an order of items rented over a time range (a machine
184
+ * Friday to Sunday). A direct order (holds, receipt, `case.submitted`, same errors) plus `rental`. The platform prices
185
+ * each line from the catalog — price of one period (options included) × units × `rental.periods.count` — and writes it on
186
+ * the receipt («2 × Retroexcavadora 320 × 3 días»); `CaseView.rental` carries the range. Hold the units in YOUR ledger
187
+ * first: the platform keeps what was rented, you own availability. Created `submitted`, or `confirmed` at once with
188
+ * `confirmation: 'instant'`. 400 for a bad range (end ≤ start, > 366 days, a count below what the range spans) or a
189
+ * line with `variantId`/`amountCents`; 409 when a product lacks stock. A retried `idempotencyKey` returns the same rental.
190
+ * R2d: `lines[].periodRateCents` (App sk_ key) prices a line with YOUR rate of one period instead of the catalog; still multiplied here.
191
+ */
192
+ createDirectRental(input: CreateDirectRentalInput): Promise<CaseView>;
193
+ /**
194
+ * `PATCH /api/v1/cases/:id/rental` — PDK-RENTAL-AVAILABILITY: reschedule or extend a rental you already moved in your
195
+ * ledger. Periods and prices are recomputed from the catalog and the receipt is re-issued (same link, revision + 1).
196
+ * Allowed after it is confirmed (an extension on site); 400 once it is closed or when the case is not a rental.
197
+ * R2d: `lines[].periodRateCents` re-prices a product (e.g. after changing `periods.unit` from `hora` to `dia`).
198
+ */
199
+ updateRental(caseId: string, input: UpdateCaseRentalInput): Promise<CaseView>;
181
200
  /**
182
201
  * `POST /api/v1/cases/:id/notice` — AGF-DELIVERY: tells the customer something through the
183
202
  * conversation's channel. The same `key` never says it twice.
@@ -28,6 +28,10 @@ class CasesResource {
28
28
  qs.set('slotFrom', at(input.slotFrom));
29
29
  if (input.slotTo)
30
30
  qs.set('slotTo', at(input.slotTo));
31
+ if (input.rentalFrom)
32
+ qs.set('rentalFrom', at(input.rentalFrom));
33
+ if (input.rentalTo)
34
+ qs.set('rentalTo', at(input.rentalTo));
31
35
  if (input.assignee)
32
36
  qs.set('assignee', input.assignee);
33
37
  if (input.contactId)
@@ -225,7 +229,14 @@ class CasesResource {
225
229
  * and the phone: the order type and its other fields (chips for a closed choice).
226
230
  */
227
231
  async directForm(opts = {}) {
228
- return this.client.request('GET', `/api/v1/cases/direct/form${opts.type ? `?type=${encodeURIComponent(opts.type)}` : ''}`);
232
+ const qs = new URLSearchParams();
233
+ if (opts.type)
234
+ qs.set('type', opts.type);
235
+ // PDK-RENTAL-AVAILABILITY: the form of a rental order's type («Reserva»).
236
+ if (opts.rental)
237
+ qs.set('rental', 'true');
238
+ const q = qs.toString();
239
+ return this.client.request('GET', `/api/v1/cases/direct/form${q ? `?${q}` : ''}`);
229
240
  }
230
241
  /**
231
242
  * `POST /api/v1/cases/direct` — AGF-ORDER-WITHOUT-AI: an order placed without the
@@ -247,6 +258,28 @@ class CasesResource {
247
258
  async createDirectBooking(input) {
248
259
  return this.client.request('POST', '/api/v1/cases/bookings', input);
249
260
  }
261
+ /**
262
+ * `POST /api/v1/cases/direct-rental` — PDK-RENTAL-AVAILABILITY: an order of items rented over a time range (a machine
263
+ * Friday to Sunday). A direct order (holds, receipt, `case.submitted`, same errors) plus `rental`. The platform prices
264
+ * each line from the catalog — price of one period (options included) × units × `rental.periods.count` — and writes it on
265
+ * the receipt («2 × Retroexcavadora 320 × 3 días»); `CaseView.rental` carries the range. Hold the units in YOUR ledger
266
+ * first: the platform keeps what was rented, you own availability. Created `submitted`, or `confirmed` at once with
267
+ * `confirmation: 'instant'`. 400 for a bad range (end ≤ start, > 366 days, a count below what the range spans) or a
268
+ * line with `variantId`/`amountCents`; 409 when a product lacks stock. A retried `idempotencyKey` returns the same rental.
269
+ * R2d: `lines[].periodRateCents` (App sk_ key) prices a line with YOUR rate of one period instead of the catalog; still multiplied here.
270
+ */
271
+ async createDirectRental(input) {
272
+ return this.client.request('POST', '/api/v1/cases/direct-rental', input);
273
+ }
274
+ /**
275
+ * `PATCH /api/v1/cases/:id/rental` — PDK-RENTAL-AVAILABILITY: reschedule or extend a rental you already moved in your
276
+ * ledger. Periods and prices are recomputed from the catalog and the receipt is re-issued (same link, revision + 1).
277
+ * Allowed after it is confirmed (an extension on site); 400 once it is closed or when the case is not a rental.
278
+ * R2d: `lines[].periodRateCents` re-prices a product (e.g. after changing `periods.unit` from `hora` to `dia`).
279
+ */
280
+ async updateRental(caseId, input) {
281
+ return this.client.request('PATCH', `/api/v1/cases/${encodeURIComponent(caseId)}/rental`, input);
282
+ }
250
283
  /**
251
284
  * `POST /api/v1/cases/:id/notice` — AGF-DELIVERY: tells the customer something through the
252
285
  * conversation's channel. The same `key` never says it twice.
package/dist/types.d.ts CHANGED
@@ -2565,6 +2565,10 @@ export interface CaseView {
2565
2565
  slot: (CaseSlot & {
2566
2566
  label: string;
2567
2567
  }) | null;
2568
+ /** PDK-RENTAL-AVAILABILITY — the time range a rental order holds and what it is charged for; null for any other case (absent on an older platform). */
2569
+ rental?: (CaseRental & {
2570
+ label: string;
2571
+ }) | null;
2568
2572
  /** AGF-DELIVERY D0 — where it is taken or performed (absent on an older platform). */
2569
2573
  destination?: CaseDestination | null;
2570
2574
  openedAt: string;
@@ -2748,6 +2752,16 @@ export interface CaseReceiptLine {
2748
2752
  currency: string;
2749
2753
  priceKind: 'fixed' | 'from' | 'per_unit' | 'on_request';
2750
2754
  unit?: string;
2755
+ /**
2756
+ * PDK-RENTAL-AVAILABILITY — a rented line (receipt of `cases.createDirectRental`): charged for `count` periods of `unit`.
2757
+ * `unitCents` of the line is then the price of ONE unit over the whole range (rate × count); `periods.unitCents` is the rate
2758
+ * per period. Show it as «{qty} × {title} × {count} {unit}».
2759
+ */
2760
+ periods?: {
2761
+ unit: RentalPeriodUnit;
2762
+ count: number;
2763
+ unitCents: number | null;
2764
+ };
2751
2765
  /** AGF-UNITS U2 — sold by measure: `qty` is in `unit` (0.75 lb), not a count of items. */
2752
2766
  measured?: boolean;
2753
2767
  /** PDK-SERVICE-CART — the line is a service. Absent: a product, a receipt issued before, or an older platform. */
@@ -3371,6 +3385,9 @@ export interface ListCasesInput {
3371
3385
  /** AGF-AGENDA — bookings whose time starts in [slotFrom, slotTo), earliest first. */
3372
3386
  slotFrom?: string | Date;
3373
3387
  slotTo?: string | Date;
3388
+ /** PDK-RENTAL-AVAILABILITY — rentals whose range overlaps [rentalFrom, rentalTo), earliest first. */
3389
+ rentalFrom?: string | Date;
3390
+ rentalTo?: string | Date;
3374
3391
  /** AGF-AGENDA — one member's requests (your reference), or `none` for unassigned ones. */
3375
3392
  assignee?: string;
3376
3393
  /** PDK-LOYALTY-CRM L1 — one business contact's cases (also those of contacts merged into it). */
@@ -3424,6 +3441,85 @@ export interface CreateDirectBookingInput {
3424
3441
  /** AGF-DELIVERY D0 — where it is performed: required for a service `attendedAt: 'customer'`, refused for one at the business. */
3425
3442
  destination?: CaseDestination;
3426
3443
  }
3444
+ /** The billing period of a rental. */
3445
+ export type RentalPeriodUnit = 'hora' | 'dia' | 'semana' | 'mes';
3446
+ /** The time a rental holds and what it is charged for (a snapshot: your App's rentals ledger decides what is free). */
3447
+ export interface CaseRental {
3448
+ /** ISO instants. */
3449
+ startsAt: string;
3450
+ endsAt: string;
3451
+ /** IANA zone the business reads it in. */
3452
+ timezone: string;
3453
+ /** The period and how many of them the range is charged for. */
3454
+ periods: {
3455
+ unit: RentalPeriodUnit;
3456
+ count: number;
3457
+ };
3458
+ /** The rate of ONE period of ONE unit per product id when your App priced the lines (`periodRateCents`); absent: the catalog price. */
3459
+ periodRates?: Record<string, number>;
3460
+ }
3461
+ /**
3462
+ * `POST /api/v1/cases/direct-rental` — an order of items rented over a time range. The body of `CreateDirectOrderInput`
3463
+ * (customer, lines, fields, destination, origin, payment, type, idempotencyKey…) plus `rental`. Without the options
3464
+ * that make no sense for a rental: no free lines, no value lines (`amountCents`), no redo (`reopens`).
3465
+ *
3466
+ * Each line's `quantity` is UNITS of the item; its price is computed by the platform from the catalog:
3467
+ * price of ONE period (with the chosen `options`) × units × `rental.periods.count`. Never send totals; an App that owns a rate
3468
+ * table sends only the rate of one period per line (`lines[].periodRateCents`, R2d).
3469
+ */
3470
+ export interface CreateDirectRentalInput extends Omit<CreateDirectOrderInput, 'lines' | 'reopens' | 'allowOffCatalog' | 'maxOffCatalogLines' | 'offCatalogLines'> {
3471
+ lines: Array<{
3472
+ productId: string;
3473
+ /** Units of the item (2 backhoes). */
3474
+ quantity: number;
3475
+ /** The choice for a product with option groups (con operador, combustible, transporte…). */
3476
+ options?: CatalogOptionChoice[];
3477
+ /**
3478
+ * PDK-RENTAL-AVAILABILITY R2d — the rate of ONE unit for ONE period (cents) from YOUR rate table (a machine is
3479
+ * $135.000/hora, $1.000.000/día, …). It replaces the catalog price; the chosen `options` deltas are still added and
3480
+ * the platform multiplies by units × `rental.periods.count`. Only for an App (an sk_ key bound to an App): 403 without it.
3481
+ * A positive integer; 400 `price overflow` when rate × units × periods would exceed 2147483647 cents (int32).
3482
+ * The same product on two lines must use the same rate. Send the SAME unit as `rental.periods.unit`.
3483
+ */
3484
+ periodRateCents?: number;
3485
+ }>;
3486
+ rental: {
3487
+ /** ISO instants with their offset (Z or ±hh:mm); at most 366 days apart. */
3488
+ startsAt: string;
3489
+ endsAt: string;
3490
+ /** IANA zone the business reads the range in. */
3491
+ timezone: string;
3492
+ periods: {
3493
+ /** The unit the product is priced in. */
3494
+ unit: RentalPeriodUnit;
3495
+ /** Optional: defaults to the periods the range spans (the last partial one counted). May be higher (a minimum of 3 days), never lower. */
3496
+ count?: number;
3497
+ };
3498
+ };
3499
+ /** `review` (default): the business accepts it (`submitted`); `instant`: `confirmed` as it is made (your ledger guarantees the units). */
3500
+ confirmation?: 'review' | 'instant';
3501
+ }
3502
+ /** `PATCH /api/v1/cases/:id/rental` — reschedule or extend: the new range (you already hold it). */
3503
+ export interface UpdateCaseRentalInput {
3504
+ startsAt: string;
3505
+ endsAt: string;
3506
+ /** Default: the rental's own zone. */
3507
+ timezone?: string;
3508
+ /** Default: the rental's own unit, count derived from the new range. */
3509
+ periods?: {
3510
+ unit?: RentalPeriodUnit;
3511
+ count?: number;
3512
+ };
3513
+ /**
3514
+ * R2d — the rate of one period for the new `periods.unit` (App sk_ key only). Rates sent earlier stay for the products
3515
+ * not listed; after a change of period unit send the new rate or the old one (of the other unit) is kept. Same validation as on create.
3516
+ */
3517
+ lines?: Array<{
3518
+ productId: string;
3519
+ periodRateCents: number;
3520
+ quantity?: number;
3521
+ }>;
3522
+ }
3427
3523
  /** `POST /api/v1/cases/:id/slot` — the new time (you already hold it), optionally another member. */
3428
3524
  export interface MoveCaseSlotInput {
3429
3525
  startsAt: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge-io/sdk-server",
3
- "version": "4.86.0",
3
+ "version": "4.87.0",
4
4
  "description": "Server-side SDK for backend apps integrating with AgentForge platform. Auth via ChatToken, ak_live_ API key or App secret (sk_live_), with App installations across tenants.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",