@agentforge-io/sdk-server 4.77.0 → 4.78.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
@@ -26,7 +26,7 @@ export type { ListMarketplaceCategoriesInput } from './resources/marketplace';
26
26
  export { TenantConfigResource } from './resources/config';
27
27
  export { PlacesResource } from './resources/places';
28
28
  export { ContactsResource, ContactVerificationResource, ContactAddressesResource, ContactTagsResource, ContactListsResource, } from './resources/contacts';
29
- export type { ContactVerificationChannel, LinkContactInput, LinkContactResult, AppContact, ContactAvatarUploadTarget, ClaimContactInput, ClaimContactResult, StartVerificationInput, StartVerificationResult, ConfirmVerificationInput, ConfirmVerificationResult, ContactDocumentType, ContactDocumentInput, ContactDocument, ContactMatchedBy, ContactSummary, BusinessContact, ContactPage, SearchContactsInput, CreateBusinessContactInput, UpdateBusinessContactInput, ContactAddress, ContactAddressInput, ContactTag, ContactList, } from './resources/contacts';
29
+ export type { ContactVerificationChannel, LinkContactInput, LinkContactResult, AppContact, ContactAvatarUploadTarget, ClaimContactInput, ClaimContactResult, StartVerificationInput, StartVerificationResult, ConfirmVerificationInput, ConfirmVerificationResult, ContactDocumentType, ContactDocumentInput, ContactDocument, ContactMatchedBy, ContactSummary, ContactSegment, ContactSort, ContactStats, ContactNote, BusinessContact, ContactPage, SearchContactsInput, CreateBusinessContactInput, UpdateBusinessContactInput, ContactAddress, ContactAddressInput, ContactTag, ContactList, } from './resources/contacts';
30
30
  export { FilesResource } from './resources/files';
31
31
  export type { AppFileKind, SignAppFileInput, AppFileUploadTarget } from './resources/files';
32
32
  export { DeliveryResource } from './resources/delivery';
@@ -29,6 +29,8 @@ class CasesResource {
29
29
  qs.set('slotTo', at(input.slotTo));
30
30
  if (input.assignee)
31
31
  qs.set('assignee', input.assignee);
32
+ if (input.contactId)
33
+ qs.set('contactId', input.contactId);
32
34
  const q = qs.toString();
33
35
  return (await this.client.request('GET', `/api/v1/cases${q ? `?${q}` : ''}`)).items;
34
36
  }
@@ -150,6 +150,58 @@ export interface ContactSummary {
150
150
  lastSeenAt: string | null;
151
151
  /** Why it matched `q`; `null` without a query. */
152
152
  matchedBy: ContactMatchedBy | null;
153
+ /**
154
+ * PDK-LOYALTY-CRM L1 — orders that count (sent and not cancelled / rejected / abandoned / no-show; drafts
155
+ * excluded). Absent on a platform older than L1.
156
+ */
157
+ ordersCount?: number;
158
+ /** ISO instant the latest counted order was sent, or `null`. Absent on an older platform. */
159
+ lastOrderAt?: string | null;
160
+ /**
161
+ * Receipt total in cents (delivery included) of the latest counted order — `null` when there is none or it is
162
+ * unpriced. Absent on an older platform.
163
+ */
164
+ lastOrderTotalCents?: number | null;
165
+ /** Currency of that receipt, or `null`. Absent on an older platform. */
166
+ lastOrderCurrency?: string | null;
167
+ }
168
+ /**
169
+ * PDK-LOYALTY-CRM L1 — behaviour segments of `search({ segment })`:
170
+ * `frequent` ≥ 3 orders in the last 90 days · `new` first order ≤ 30 days ago ·
171
+ * `inactive30|60|90` has orders and none in the last N days · `marketing` accepts promotions
172
+ * (`marketingConsent`). Orders count as in `ContactStats`.
173
+ */
174
+ export type ContactSegment = 'frequent' | 'new' | 'inactive30' | 'inactive60' | 'inactive90' | 'marketing';
175
+ /** `recent` (default: last seen) · `recent_order` (latest order first, never-ordered last) · `name`. */
176
+ export type ContactSort = 'recent' | 'recent_order' | 'name';
177
+ /**
178
+ * PDK-LOYALTY-CRM L1 — `contacts.stats(id)`. An order counts when the customer sent it and it is not lost:
179
+ * completed and in-progress states count; `cancelled`, `rejected`, `abandoned`, `no_show` and unsent drafts
180
+ * (`open`, `review`) never do. Orders of contacts merged into this one are included.
181
+ */
182
+ export interface ContactStats {
183
+ ordersCount: number;
184
+ /** Sum of the receipt totals (delivery included) of the counted orders that have a price. */
185
+ totalCents: number;
186
+ /** `totalCents` over the priced counted orders; 0 when none. */
187
+ avgTicketCents: number;
188
+ /** Currency of the latest priced order; `null` without orders. */
189
+ currency: string | null;
190
+ /** ISO instants a counted order was sent; `null` without orders. */
191
+ firstOrderAt: string | null;
192
+ lastOrderAt: string | null;
193
+ /** The latest counted order (`cases.get`). */
194
+ lastCaseId: string | null;
195
+ }
196
+ /** A timeline note on a contact, as an App sees it (`source: 'system'` for notes written through the SDK). */
197
+ export interface ContactNote {
198
+ id: string;
199
+ contactId: string;
200
+ body: string;
201
+ source: 'operator' | 'agent' | 'system';
202
+ pinned: boolean;
203
+ createdAt: string;
204
+ updatedAt: string;
153
205
  }
154
206
  export interface BusinessContact extends ContactSummary {
155
207
  marketingConsent: boolean;
@@ -171,6 +223,10 @@ export interface SearchContactsInput {
171
223
  tag?: string;
172
224
  /** List id. */
173
225
  list?: string;
226
+ /** PDK-LOYALTY-CRM L1 — behaviour segment (400 `invalid_segment` otherwise). */
227
+ segment?: ContactSegment;
228
+ /** PDK-LOYALTY-CRM L1 — default `recent` (400 `invalid_sort` otherwise). */
229
+ sort?: ContactSort;
174
230
  cursor?: string;
175
231
  /** 1-100, default 25. */
176
232
  limit?: number;
@@ -265,6 +321,20 @@ export declare class ContactAddressesResource {
265
321
  /** `DELETE …/addresses/:addressId`. */
266
322
  remove(contactId: string, addressId: string): Promise<void>;
267
323
  }
324
+ /** `contacts.notes` — timeline notes on a contact (PDK-LOYALTY-CRM L1). */
325
+ export declare class ContactNotesResource {
326
+ private readonly client;
327
+ constructor(client: AgentForgeClient);
328
+ /** `GET /api/v1/contacts/:id/notes` — pinned first, then newest first. 404 when not a contact of the business. */
329
+ list(contactId: string): Promise<ContactNote[]>;
330
+ /** `POST …/notes` — 1 to 5000 characters (400 `invalid_note`). Written as `source: 'system'` (the App). */
331
+ add(contactId: string, input: {
332
+ body: string;
333
+ pinned?: boolean;
334
+ }): Promise<ContactNote>;
335
+ /** `DELETE …/notes/:noteId` — soft delete; 404 `note_not_found` for a note of another contact. */
336
+ remove(contactId: string, noteId: string): Promise<void>;
337
+ }
268
338
  /** `contacts.tags` — the business's tag catalog (contacts keep the tag names). */
269
339
  export declare class ContactTagsResource {
270
340
  private readonly client;
@@ -324,15 +394,23 @@ export declare class ContactsResource {
324
394
  readonly addresses: ContactAddressesResource;
325
395
  readonly tags: ContactTagsResource;
326
396
  readonly lists: ContactListsResource;
397
+ readonly notes: ContactNotesResource;
327
398
  constructor(client: AgentForgeClient);
328
399
  /**
329
- * `GET /api/v1/contacts?q&tag&list&cursor&limit` — search the business's
400
+ * `GET /api/v1/contacts?q&tag&list&segment&sort&cursor&limit` — search the business's
330
401
  * contacts (excludes merged and deleted ones). With `q`: best match first
331
- * (exact phone/document, then name prefix, …); without: most recent first.
402
+ * (exact phone/document, then name prefix, …), then `sort`; without: `sort`
403
+ * (default most recently seen first). Rows carry `ordersCount` / `lastOrderAt`.
332
404
  */
333
405
  search(input?: SearchContactsInput): Promise<ContactPage>;
334
406
  /** Alias of `search` without `q` (the Contactos tab). */
335
407
  list(input?: Omit<SearchContactsInput, 'q'>): Promise<ContactPage>;
408
+ /**
409
+ * PDK-LOYALTY-CRM L1 — `GET /api/v1/contacts/:id/stats`: orders count, total, average ticket, first / last
410
+ * order and the last case. The contact's orders themselves: `cases.list({ contactId })`.
411
+ * Rejects with a 404 `AgentForgeNotFoundError` when it is not a contact of this business.
412
+ */
413
+ stats(contactId: string): Promise<ContactStats>;
336
414
  /**
337
415
  * `POST /api/v1/contacts`. Needs a name, a phone or a document. A phone or
338
416
  * document the business already has throws `AgentForgeDuplicateContactError`
@@ -27,7 +27,7 @@
27
27
  // - `getById(id)` · `update({ contactId, ... })` (documents, tags, consent).
28
28
  // - `addresses.*` · `tags.*` (per-business catalog) · `lists.*` (static lists).
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.ContactsResource = exports.ContactListsResource = exports.ContactTagsResource = exports.ContactAddressesResource = exports.ContactVerificationResource = void 0;
30
+ exports.ContactsResource = exports.ContactListsResource = exports.ContactTagsResource = exports.ContactNotesResource = exports.ContactAddressesResource = exports.ContactVerificationResource = void 0;
31
31
  const errors_1 = require("../errors");
32
32
  class ContactVerificationResource {
33
33
  constructor(client) {
@@ -107,6 +107,25 @@ class ContactAddressesResource {
107
107
  }
108
108
  }
109
109
  exports.ContactAddressesResource = ContactAddressesResource;
110
+ /** `contacts.notes` — timeline notes on a contact (PDK-LOYALTY-CRM L1). */
111
+ class ContactNotesResource {
112
+ constructor(client) {
113
+ this.client = client;
114
+ }
115
+ /** `GET /api/v1/contacts/:id/notes` — pinned first, then newest first. 404 when not a contact of the business. */
116
+ async list(contactId) {
117
+ return (await this.client.request('GET', `/api/v1/contacts/${q(contactId)}/notes`)).items;
118
+ }
119
+ /** `POST …/notes` — 1 to 5000 characters (400 `invalid_note`). Written as `source: 'system'` (the App). */
120
+ async add(contactId, input) {
121
+ return this.client.request('POST', `/api/v1/contacts/${q(contactId)}/notes`, input);
122
+ }
123
+ /** `DELETE …/notes/:noteId` — soft delete; 404 `note_not_found` for a note of another contact. */
124
+ async remove(contactId, noteId) {
125
+ await this.client.request('DELETE', `/api/v1/contacts/${q(contactId)}/notes/${q(noteId)}`);
126
+ }
127
+ }
128
+ exports.ContactNotesResource = ContactNotesResource;
110
129
  /** `contacts.tags` — the business's tag catalog (contacts keep the tag names). */
111
130
  class ContactTagsResource {
112
131
  constructor(client) {
@@ -173,11 +192,13 @@ class ContactsResource {
173
192
  this.addresses = new ContactAddressesResource(client);
174
193
  this.tags = new ContactTagsResource(client);
175
194
  this.lists = new ContactListsResource(client);
195
+ this.notes = new ContactNotesResource(client);
176
196
  }
177
197
  /**
178
- * `GET /api/v1/contacts?q&tag&list&cursor&limit` — search the business's
198
+ * `GET /api/v1/contacts?q&tag&list&segment&sort&cursor&limit` — search the business's
179
199
  * contacts (excludes merged and deleted ones). With `q`: best match first
180
- * (exact phone/document, then name prefix, …); without: most recent first.
200
+ * (exact phone/document, then name prefix, …), then `sort`; without: `sort`
201
+ * (default most recently seen first). Rows carry `ordersCount` / `lastOrderAt`.
181
202
  */
182
203
  async search(input = {}) {
183
204
  return this.client.request('GET', `/api/v1/contacts${query({ ...input })}`);
@@ -186,6 +207,14 @@ class ContactsResource {
186
207
  async list(input = {}) {
187
208
  return this.search(input);
188
209
  }
210
+ /**
211
+ * PDK-LOYALTY-CRM L1 — `GET /api/v1/contacts/:id/stats`: orders count, total, average ticket, first / last
212
+ * order and the last case. The contact's orders themselves: `cases.list({ contactId })`.
213
+ * Rejects with a 404 `AgentForgeNotFoundError` when it is not a contact of this business.
214
+ */
215
+ async stats(contactId) {
216
+ return this.client.request('GET', `/api/v1/contacts/${q(contactId)}/stats`);
217
+ }
189
218
  /**
190
219
  * `POST /api/v1/contacts`. Needs a name, a phone or a document. A phone or
191
220
  * document the business already has throws `AgentForgeDuplicateContactError`
package/dist/types.d.ts CHANGED
@@ -2407,6 +2407,8 @@ export interface CaseView {
2407
2407
  note: string | null;
2408
2408
  /** The conversation's user (app user id, phone…), when known. */
2409
2409
  customerRef: string | null;
2410
+ /** PDK-LOYALTY-CRM L1 — the business contact (`contacts.getById`) this case belongs to; `null` when none resolved (absent on an older platform). */
2411
+ contactId?: string | null;
2410
2412
  /** States the business can move it to now, each with what the customer is
2411
2413
  * told when it moves there (AGF-CASES C3; absent when nothing is said). */
2412
2414
  nextStates: Array<{
@@ -2779,6 +2781,7 @@ export interface CreateDirectOrderInput {
2779
2781
  ref: string;
2780
2782
  name?: string;
2781
2783
  phone?: string;
2784
+ contactId?: string;
2782
2785
  };
2783
2786
  /** AGF-ORDER-ORIGIN-POS — where it comes from; default `{ channel: 'page' }`. A `pos` sale needs `place` and `by`. */
2784
2787
  origin?: CaseOrigin;
@@ -2869,6 +2872,7 @@ export interface CreateOpenOrderInput {
2869
2872
  ref?: string;
2870
2873
  name?: string;
2871
2874
  phone?: string;
2875
+ contactId?: string;
2872
2876
  };
2873
2877
  origin: {
2874
2878
  channel: 'link';
@@ -3052,6 +3056,8 @@ export interface ListCasesInput {
3052
3056
  slotTo?: string | Date;
3053
3057
  /** AGF-AGENDA — one member's requests (your reference), or `none` for unassigned ones. */
3054
3058
  assignee?: string;
3059
+ /** PDK-LOYALTY-CRM L1 — one business contact's cases (also those of contacts merged into it). */
3060
+ contactId?: string;
3055
3061
  }
3056
3062
  /** The time a booking holds (a snapshot: your App's agenda decides what is free). */
3057
3063
  export interface CaseSlot {
@@ -3076,6 +3082,7 @@ export interface CreateDirectBookingInput {
3076
3082
  ref: string;
3077
3083
  name: string;
3078
3084
  phone: string;
3085
+ contactId?: string;
3079
3086
  };
3080
3087
  /** A catalog service of the business with a `booking` rule. */
3081
3088
  serviceId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge-io/sdk-server",
3
- "version": "4.77.0",
3
+ "version": "4.78.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",