@agentforge-io/sdk-server 4.33.0 → 4.34.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/client.d.ts CHANGED
@@ -5,6 +5,7 @@ import { ChatResource } from './resources/chat';
5
5
  import { ConnectorsResource } from './resources/connectors';
6
6
  import { InboxResource } from './resources/inbox';
7
7
  import { InstallationsResource } from './resources/installations';
8
+ import { ContactsResource } from './resources/contacts';
8
9
  import { WebhookResource } from './resources/webhook';
9
10
  import { ProvisioningResource } from './resources/provisioning';
10
11
  import { SecretsResource } from './resources/secrets';
@@ -91,6 +92,8 @@ export declare class AgentForgeClient {
91
92
  readonly connectors: ConnectorsResource;
92
93
  readonly inbox: InboxResource;
93
94
  readonly installations: InstallationsResource;
95
+ /** AGF-CUSTOMER-ACCOUNTS — the business's contacts for the App's end users. */
96
+ readonly contacts: ContactsResource;
94
97
  /** Where the platform sends this App its events (AGF-APP-WEBHOOKS). */
95
98
  readonly webhook: WebhookResource;
96
99
  readonly provisioning: ProvisioningResource;
package/dist/client.js CHANGED
@@ -27,6 +27,7 @@ const chat_1 = require("./resources/chat");
27
27
  const connectors_1 = require("./resources/connectors");
28
28
  const inbox_1 = require("./resources/inbox");
29
29
  const installations_1 = require("./resources/installations");
30
+ const contacts_1 = require("./resources/contacts");
30
31
  const webhook_1 = require("./resources/webhook");
31
32
  const provisioning_1 = require("./resources/provisioning");
32
33
  const secrets_1 = require("./resources/secrets");
@@ -73,6 +74,7 @@ class AgentForgeClient {
73
74
  this.connectors = new connectors_1.ConnectorsResource(this);
74
75
  this.inbox = new inbox_1.InboxResource(this);
75
76
  this.installations = new installations_1.InstallationsResource(this);
77
+ this.contacts = new contacts_1.ContactsResource(this);
76
78
  this.webhook = new webhook_1.WebhookResource(this);
77
79
  this.provisioning = new provisioning_1.ProvisioningResource(this);
78
80
  this.secrets = new secrets_1.SecretsResource(this);
package/dist/errors.js CHANGED
@@ -13,7 +13,10 @@ class AgentForgeError extends Error {
13
13
  }
14
14
  }
15
15
  exports.AgentForgeError = AgentForgeError;
16
- const ERROR_CODE = /^[A-Z][A-Z0-9_]+$/;
16
+ // `CASE_NOT_FOUND`-style codes, and the lowercase snake_case codes of the
17
+ // contacts / verification routes (`rate_limited`, `invalid_code`). Nest's
18
+ // status text ("Bad Request") matches neither.
19
+ const ERROR_CODE = /^(?:[A-Z][A-Z0-9_]+|[a-z][a-z0-9]*(?:_[a-z0-9]+)+)$/;
17
20
  function parseErrorCode(body) {
18
21
  if (!body)
19
22
  return undefined;
package/dist/index.d.ts CHANGED
@@ -21,6 +21,8 @@ export { MarketplaceResource } from './resources/marketplace';
21
21
  export type { ListMarketplaceCategoriesInput } from './resources/marketplace';
22
22
  export { TenantConfigResource } from './resources/config';
23
23
  export { PlacesResource } from './resources/places';
24
+ export { ContactsResource, ContactVerificationResource } from './resources/contacts';
25
+ export type { ContactVerificationChannel, LinkContactInput, LinkContactResult, AppContact, ContactAvatarUploadTarget, ClaimContactInput, ClaimContactResult, StartVerificationInput, StartVerificationResult, ConfirmVerificationInput, ConfirmVerificationResult, } from './resources/contacts';
24
26
  export { DeliveryResource } from './resources/delivery';
25
27
  export { CasesResource } from './resources/cases';
26
28
  export { BusinessRolesResource } from './resources/business-roles';
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@
28
28
  // const payload = af.tools.verifyCallback({ rawBody, signatureHeader, secretPlaintext });
29
29
  // await af.tools.respondToCallback({ resultUrl: payload.resultUrl, tenantId: payload.tenantId, secret, result });
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.ToolsResource = exports.TeamsResource = exports.SecretsResource = exports.ProvisioningResource = exports.CATALOG_IMPORT_MAX_ITEMS = exports.AgentForgeCatalogImportLimitError = exports.CatalogSourcesResource = exports.CatalogFileImportResource = exports.CatalogImportResource = exports.CatalogPhotosResource = exports.CatalogProductsResource = exports.CatalogCategoriesResource = exports.CatalogResource = exports.BusinessRolesResource = exports.CasesResource = exports.DeliveryResource = exports.PlacesResource = exports.TenantConfigResource = exports.MarketplaceResource = exports.TemplatesResource = exports.InstallationsResource = exports.InboxResource = exports.parseGoogleSheetsPickerResult = exports.ConnectorsResource = exports.ChatResource = exports.AppsResource = exports.AnalyticsResource = exports.AgentsResource = exports.WebhookResource = exports.verifyToolCallbackSignature = exports.verifyAppWebhook = exports.signToolCallbackPayload = exports.ToolCallbackSignatureError = exports.TOOL_CALLBACK_HEADERS = exports.APP_WEBHOOK_HEADERS = exports.AgentForgeNetworkError = exports.AgentForgeNotFoundError = exports.AgentForgeAuthError = exports.AgentForgeError = exports.INSTALLED_TENANT_HEADER = exports.AgentForgeClient = void 0;
31
+ exports.ToolsResource = exports.TeamsResource = exports.SecretsResource = exports.ProvisioningResource = exports.CATALOG_IMPORT_MAX_ITEMS = exports.AgentForgeCatalogImportLimitError = exports.CatalogSourcesResource = exports.CatalogFileImportResource = exports.CatalogImportResource = exports.CatalogPhotosResource = exports.CatalogProductsResource = exports.CatalogCategoriesResource = exports.CatalogResource = exports.BusinessRolesResource = exports.CasesResource = exports.DeliveryResource = exports.ContactVerificationResource = exports.ContactsResource = exports.PlacesResource = exports.TenantConfigResource = exports.MarketplaceResource = exports.TemplatesResource = exports.InstallationsResource = exports.InboxResource = exports.parseGoogleSheetsPickerResult = exports.ConnectorsResource = exports.ChatResource = exports.AppsResource = exports.AnalyticsResource = exports.AgentsResource = exports.WebhookResource = exports.verifyToolCallbackSignature = exports.verifyAppWebhook = exports.signToolCallbackPayload = exports.ToolCallbackSignatureError = exports.TOOL_CALLBACK_HEADERS = exports.APP_WEBHOOK_HEADERS = exports.AgentForgeNetworkError = exports.AgentForgeNotFoundError = exports.AgentForgeAuthError = exports.AgentForgeError = exports.INSTALLED_TENANT_HEADER = exports.AgentForgeClient = void 0;
32
32
  var client_1 = require("./client");
33
33
  Object.defineProperty(exports, "AgentForgeClient", { enumerable: true, get: function () { return client_1.AgentForgeClient; } });
34
34
  Object.defineProperty(exports, "INSTALLED_TENANT_HEADER", { enumerable: true, get: function () { return client_1.INSTALLED_TENANT_HEADER; } });
@@ -69,6 +69,9 @@ var config_1 = require("./resources/config");
69
69
  Object.defineProperty(exports, "TenantConfigResource", { enumerable: true, get: function () { return config_1.TenantConfigResource; } });
70
70
  var places_1 = require("./resources/places");
71
71
  Object.defineProperty(exports, "PlacesResource", { enumerable: true, get: function () { return places_1.PlacesResource; } });
72
+ var contacts_1 = require("./resources/contacts");
73
+ Object.defineProperty(exports, "ContactsResource", { enumerable: true, get: function () { return contacts_1.ContactsResource; } });
74
+ Object.defineProperty(exports, "ContactVerificationResource", { enumerable: true, get: function () { return contacts_1.ContactVerificationResource; } });
72
75
  var delivery_1 = require("./resources/delivery");
73
76
  Object.defineProperty(exports, "DeliveryResource", { enumerable: true, get: function () { return delivery_1.DeliveryResource; } });
74
77
  var cases_1 = require("./resources/cases");
@@ -0,0 +1,161 @@
1
+ import type { AgentForgeClient } from '../client';
2
+ /**
3
+ * `whatsapp` / `sms`: a code sent to the person (Twilio Verify). `email`: a
4
+ * code by email. `whatsapp_reply` («WhatsApp inverso»): the person sends the
5
+ * code FROM their WhatsApp to the platform's verification number — no
6
+ * template, no Meta business verification; poll `confirm` until it arrives.
7
+ */
8
+ export type ContactVerificationChannel = 'whatsapp' | 'sms' | 'email' | 'whatsapp_reply';
9
+ export interface LinkContactInput {
10
+ /** The App's id for its end user in THIS business (e.g. `cust:<handle>:<id>`). */
11
+ externalUserId: string;
12
+ name?: string;
13
+ /** E.164 (`+57…`). Unverified unless `verificationToken` proves it. */
14
+ phone?: {
15
+ e164: string;
16
+ verificationToken?: string;
17
+ };
18
+ /** `verified: true` = the App verified it itself (e.g. a Google ID token). */
19
+ email?: {
20
+ value: string;
21
+ verified?: boolean;
22
+ verificationToken?: string;
23
+ };
24
+ /** The consent the person accepted for this business. */
25
+ consent?: {
26
+ version: string;
27
+ at?: string;
28
+ };
29
+ /** The person's photo: an https URL (their sign-in provider's picture, or `avatar.signUpload`'s `publicUrl`). */
30
+ avatarUrl?: string;
31
+ /** Opaque partition the App stamps on the link. */
32
+ ownerRef?: string;
33
+ }
34
+ export interface LinkContactResult {
35
+ contactId: string;
36
+ created: boolean;
37
+ /** The link merged this person with an existing contact of the business. */
38
+ merged: boolean;
39
+ }
40
+ export interface AppContact {
41
+ contactId: string;
42
+ name: string | null;
43
+ phone: string | null;
44
+ phoneVerified: boolean;
45
+ email: string | null;
46
+ emailVerified: boolean;
47
+ consentVersion: string | null;
48
+ avatarUrl: string | null;
49
+ }
50
+ /** A signed PUT for an end user's photo: PUT the bytes to `uploadUrl`, then link/update with `avatarUrl: publicUrl`. */
51
+ export interface ContactAvatarUploadTarget {
52
+ uploadUrl: string;
53
+ publicUrl: string;
54
+ key: string;
55
+ expiresInSeconds: number;
56
+ }
57
+ export interface ClaimContactInput {
58
+ /** The signed-in end user that receives the history. */
59
+ externalUserId: string;
60
+ /** Anonymous end users of the same person on this business (≤ 20). */
61
+ fromExternalUserIds: string[];
62
+ }
63
+ export interface ClaimContactResult {
64
+ conversations: number;
65
+ messages: number;
66
+ approvals: number;
67
+ cases: number;
68
+ }
69
+ export interface StartVerificationInput {
70
+ channel: ContactVerificationChannel;
71
+ /** E.164 phone for whatsapp/sms, an email for email. */
72
+ to: string;
73
+ locale?: 'es' | 'en';
74
+ /** The name the person reads in the WhatsApp message / email («PoodleDeck»). */
75
+ brand?: string;
76
+ }
77
+ export interface StartVerificationResult {
78
+ sent: true;
79
+ channel: ContactVerificationChannel;
80
+ resendAfterSec: number;
81
+ expiresInSec: number;
82
+ /** `whatsapp_reply` only: what the person sends, to which number, and a wa.me link with it written. */
83
+ reply?: {
84
+ code: string;
85
+ to: string;
86
+ message: string;
87
+ link: string;
88
+ };
89
+ }
90
+ export interface ConfirmVerificationInput {
91
+ channel: ContactVerificationChannel;
92
+ to: string;
93
+ code: string;
94
+ }
95
+ export interface ConfirmVerificationResult {
96
+ verified: true;
97
+ kind: 'phone' | 'email';
98
+ /** Normalised value (E.164 / lowercase email). */
99
+ value: string;
100
+ channel: ContactVerificationChannel;
101
+ /** Proof for THIS App; send it on `contacts.link` in any business. */
102
+ verificationToken: string;
103
+ expiresAt: string;
104
+ }
105
+ export declare class ContactVerificationResource {
106
+ private readonly client;
107
+ constructor(client: AgentForgeClient);
108
+ /**
109
+ * `POST /api/v1/contacts/verification/start` — send a code. Errors carry
110
+ * `code`: `invalid_channel`, `invalid_phone`, `invalid_email`,
111
+ * `country_not_allowed`, `verification_failed` (channel not available for
112
+ * the number — offer SMS), `rate_limited` (body `retryAfterSec`),
113
+ * `verification_unavailable`.
114
+ */
115
+ start(input: StartVerificationInput): Promise<StartVerificationResult>;
116
+ /**
117
+ * `POST /api/v1/contacts/verification/confirm`. Errors: `invalid_code`
118
+ * (email codes add `attemptsLeft`), `code_expired`, `too_many_attempts`;
119
+ * `whatsapp_reply`: 409 `verification_pending` until the message arrives
120
+ * (poll every ~2 s), 410 `code_expired` after 10 minutes.
121
+ */
122
+ confirm(input: ConfirmVerificationInput): Promise<ConfirmVerificationResult>;
123
+ }
124
+ export declare class ContactsResource {
125
+ private readonly client;
126
+ readonly verification: ContactVerificationResource;
127
+ constructor(client: AgentForgeClient);
128
+ /**
129
+ * `POST /api/v1/contacts/avatar/sign-upload` — where to PUT an end user's
130
+ * photo (jpeg/png/webp/gif, 2 MB at most). App-wide: the same URL serves
131
+ * every business the App links the person to. Errors: `unsupported_type`,
132
+ * `too_large`, 501 `not_configured`.
133
+ */
134
+ signAvatarUpload(input: {
135
+ contentType: string;
136
+ contentLength?: number;
137
+ }): Promise<ContactAvatarUploadTarget>;
138
+ /** `POST /api/v1/contacts/link`. A phone without a valid token → `phone_verification_required`. */
139
+ link(input: LinkContactInput): Promise<LinkContactResult>;
140
+ /** `POST /api/v1/contacts/claim`. */
141
+ claim(input: ClaimContactInput): Promise<ClaimContactResult>;
142
+ /** `GET /api/v1/contacts?externalUserId=` — `null` when there is no contact. */
143
+ get(externalUserId: string): Promise<AppContact | null>;
144
+ /** `PATCH /api/v1/contacts` — name / phone (phone verified only with a token) / photo. 404 when unknown. */
145
+ update(input: {
146
+ externalUserId: string;
147
+ name?: string;
148
+ phone?: {
149
+ e164: string;
150
+ verificationToken?: string;
151
+ };
152
+ avatarUrl?: string;
153
+ }): Promise<AppContact>;
154
+ /**
155
+ * `DELETE /api/v1/contacts?externalUserId=` — the person stops sharing
156
+ * their data with this business: personal fields and identifiers are
157
+ * cleared, orders keep their record as «cliente eliminado». `false` when
158
+ * there was no contact.
159
+ */
160
+ remove(externalUserId: string): Promise<boolean>;
161
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ // contacts resource — the business's contacts for an App's own end users
3
+ // (AGF-CUSTOMER-ACCOUNTS CA-1/CA-2). App secret only; on an installed tenant
4
+ // call it through `af.forTenant(tenantId)` (one tenant per business).
5
+ //
6
+ // - `link(input)` — `POST /api/v1/contacts/link`. Find-or-create the
7
+ // contact of an end user (`externalUserId`) and attach name, phone,
8
+ // email, consent. A phone or email is verified only with a
9
+ // `verificationToken` from `verification.confirm`; a verified email may
10
+ // merge with an older contact of the business; a phone verified over
11
+ // WhatsApp merges with the business's WhatsApp contact. Idempotent.
12
+ // - `claim({ externalUserId, fromExternalUserIds })` — move anonymous end
13
+ // users' conversations and orders to the signed-in one.
14
+ // - `get(externalUserId)` (null when unknown) · `update(...)` · `remove(...)`
15
+ // (Ley 1581 suppression for this business).
16
+ // - `verification.start / confirm` — WhatsApp / SMS code (Twilio Verify on
17
+ // the platform) or email code; `confirm` returns the `verificationToken`
18
+ // the App keeps with its customer account (180 days) and sends on every
19
+ // `link`, in any business.
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.ContactsResource = exports.ContactVerificationResource = void 0;
22
+ const errors_1 = require("../errors");
23
+ class ContactVerificationResource {
24
+ constructor(client) {
25
+ this.client = client;
26
+ }
27
+ /**
28
+ * `POST /api/v1/contacts/verification/start` — send a code. Errors carry
29
+ * `code`: `invalid_channel`, `invalid_phone`, `invalid_email`,
30
+ * `country_not_allowed`, `verification_failed` (channel not available for
31
+ * the number — offer SMS), `rate_limited` (body `retryAfterSec`),
32
+ * `verification_unavailable`.
33
+ */
34
+ async start(input) {
35
+ return this.client.request('POST', '/api/v1/contacts/verification/start', input);
36
+ }
37
+ /**
38
+ * `POST /api/v1/contacts/verification/confirm`. Errors: `invalid_code`
39
+ * (email codes add `attemptsLeft`), `code_expired`, `too_many_attempts`;
40
+ * `whatsapp_reply`: 409 `verification_pending` until the message arrives
41
+ * (poll every ~2 s), 410 `code_expired` after 10 minutes.
42
+ */
43
+ async confirm(input) {
44
+ return this.client.request('POST', '/api/v1/contacts/verification/confirm', input);
45
+ }
46
+ }
47
+ exports.ContactVerificationResource = ContactVerificationResource;
48
+ class ContactsResource {
49
+ constructor(client) {
50
+ this.client = client;
51
+ this.verification = new ContactVerificationResource(client);
52
+ }
53
+ /**
54
+ * `POST /api/v1/contacts/avatar/sign-upload` — where to PUT an end user's
55
+ * photo (jpeg/png/webp/gif, 2 MB at most). App-wide: the same URL serves
56
+ * every business the App links the person to. Errors: `unsupported_type`,
57
+ * `too_large`, 501 `not_configured`.
58
+ */
59
+ async signAvatarUpload(input) {
60
+ return this.client.request('POST', '/api/v1/contacts/avatar/sign-upload', input);
61
+ }
62
+ /** `POST /api/v1/contacts/link`. A phone without a valid token → `phone_verification_required`. */
63
+ async link(input) {
64
+ return this.client.request('POST', '/api/v1/contacts/link', input);
65
+ }
66
+ /** `POST /api/v1/contacts/claim`. */
67
+ async claim(input) {
68
+ return this.client.request('POST', '/api/v1/contacts/claim', input);
69
+ }
70
+ /** `GET /api/v1/contacts?externalUserId=` — `null` when there is no contact. */
71
+ async get(externalUserId) {
72
+ try {
73
+ return await this.client.request('GET', `/api/v1/contacts?externalUserId=${encodeURIComponent(externalUserId)}`);
74
+ }
75
+ catch (err) {
76
+ if (err instanceof errors_1.AgentForgeNotFoundError)
77
+ return null;
78
+ throw err;
79
+ }
80
+ }
81
+ /** `PATCH /api/v1/contacts` — name / phone (phone verified only with a token) / photo. 404 when unknown. */
82
+ async update(input) {
83
+ return this.client.request('PATCH', '/api/v1/contacts', input);
84
+ }
85
+ /**
86
+ * `DELETE /api/v1/contacts?externalUserId=` — the person stops sharing
87
+ * their data with this business: personal fields and identifiers are
88
+ * cleared, orders keep their record as «cliente eliminado». `false` when
89
+ * there was no contact.
90
+ */
91
+ async remove(externalUserId) {
92
+ try {
93
+ await this.client.request('DELETE', `/api/v1/contacts?externalUserId=${encodeURIComponent(externalUserId)}`);
94
+ return true;
95
+ }
96
+ catch (err) {
97
+ if (err instanceof errors_1.AgentForgeNotFoundError)
98
+ return false;
99
+ throw err;
100
+ }
101
+ }
102
+ }
103
+ exports.ContactsResource = ContactsResource;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge-io/sdk-server",
3
- "version": "4.33.0",
3
+ "version": "4.34.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",