@agentforge-io/sdk-server 4.68.0 → 4.70.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
@@ -21,6 +21,7 @@ import { CasesResource } from './resources/cases';
21
21
  import { CatalogResource } from './resources/catalog';
22
22
  import { BusinessRolesResource } from './resources/business-roles';
23
23
  import { ToolsResource } from './resources/tools';
24
+ import { BillingResource } from './resources/billing';
24
25
  export interface AgentForgeClientOptions {
25
26
  /** Platform base URL — e.g. http://localhost:3032 in dev. */
26
27
  baseURL: string;
@@ -115,6 +116,8 @@ export declare class AgentForgeClient {
115
116
  readonly reviews: BusinessReviewsResource;
116
117
  readonly businessRoles: BusinessRolesResource;
117
118
  readonly catalog: CatalogResource;
119
+ /** PDK-BILLING — the installed tenant's plan, trial and subscription (use `af.forTenant(id).billing`). */
120
+ readonly billing: BillingResource;
118
121
  constructor(opts: AgentForgeClientOptions);
119
122
  /**
120
123
  * A client that acts inside `tenantId`, a tenant where this App is
package/dist/client.js CHANGED
@@ -43,6 +43,7 @@ const cases_1 = require("./resources/cases");
43
43
  const catalog_1 = require("./resources/catalog");
44
44
  const business_roles_1 = require("./resources/business-roles");
45
45
  const tools_1 = require("./resources/tools");
46
+ const billing_1 = require("./resources/billing");
46
47
  /** Header that selects an installed tenant for an App secret. */
47
48
  exports.INSTALLED_TENANT_HEADER = 'x-af-tenant';
48
49
  class AgentForgeClient {
@@ -92,6 +93,7 @@ class AgentForgeClient {
92
93
  this.reviews = new reviews_1.BusinessReviewsResource(this);
93
94
  this.businessRoles = new business_roles_1.BusinessRolesResource(this);
94
95
  this.catalog = new catalog_1.CatalogResource(this);
96
+ this.billing = new billing_1.BillingResource(this);
95
97
  }
96
98
  /**
97
99
  * A client that acts inside `tenantId`, a tenant where this App is
package/dist/errors.d.ts CHANGED
@@ -35,6 +35,18 @@ export declare class AgentForgeDuplicateContactError extends AgentForgeError {
35
35
  readonly matchedBy: 'phone' | 'document';
36
36
  constructor(message: string, existingId: string, matchedBy: 'phone' | 'document', body?: string);
37
37
  }
38
+ /**
39
+ * PDK-BILLING — the coded errors of `af.billing.*`. `code` narrows to this union:
40
+ * `plan_not_found` (404), `trial_already_used` / `already_subscribed` /
41
+ * `no_subscription` (409), `plan_not_purchasable` / `invalid_request` (400),
42
+ * `not_configured` (503, the platform has no billing provider), `billing_unavailable` (502, the provider failed).
43
+ */
44
+ export type AgentForgeBillingErrorCode = 'plan_not_found' | 'trial_already_used' | 'already_subscribed' | 'no_subscription' | 'plan_not_purchasable' | 'invalid_request' | 'not_configured' | 'billing_unavailable';
45
+ export declare const AGENTFORGE_BILLING_ERROR_CODES: readonly AgentForgeBillingErrorCode[];
46
+ export declare class AgentForgeBillingError extends AgentForgeError {
47
+ readonly code: AgentForgeBillingErrorCode;
48
+ constructor(status: number, code: AgentForgeBillingErrorCode, message: string, body?: string);
49
+ }
38
50
  export declare class AgentForgeNetworkError extends Error {
39
51
  readonly cause: Error;
40
52
  constructor(message: string, cause: Error);
package/dist/errors.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Errores tipados que el SDK lanza. Las apps cliente pueden hacer
3
3
  // `instanceof AgentForgeAuthError` para distinguir 401/403 de otros fallos.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.AgentForgeNetworkError = exports.AgentForgeDuplicateContactError = exports.AgentForgeNotFoundError = exports.AgentForgeAuthError = exports.AgentForgeError = void 0;
5
+ exports.AgentForgeNetworkError = exports.AgentForgeBillingError = exports.AGENTFORGE_BILLING_ERROR_CODES = exports.AgentForgeDuplicateContactError = exports.AgentForgeNotFoundError = exports.AgentForgeAuthError = exports.AgentForgeError = void 0;
6
6
  class AgentForgeError extends Error {
7
7
  constructor(status, message, body, code) {
8
8
  super(message);
@@ -85,6 +85,23 @@ class AgentForgeDuplicateContactError extends AgentForgeError {
85
85
  }
86
86
  }
87
87
  exports.AgentForgeDuplicateContactError = AgentForgeDuplicateContactError;
88
+ exports.AGENTFORGE_BILLING_ERROR_CODES = [
89
+ 'plan_not_found',
90
+ 'trial_already_used',
91
+ 'already_subscribed',
92
+ 'no_subscription',
93
+ 'plan_not_purchasable',
94
+ 'invalid_request',
95
+ 'not_configured',
96
+ 'billing_unavailable',
97
+ ];
98
+ class AgentForgeBillingError extends AgentForgeError {
99
+ constructor(status, code, message, body) {
100
+ super(status, message, body, code);
101
+ this.name = 'AgentForgeBillingError';
102
+ }
103
+ }
104
+ exports.AgentForgeBillingError = AgentForgeBillingError;
88
105
  class AgentForgeNetworkError extends Error {
89
106
  constructor(message, cause) {
90
107
  super(message);
package/dist/index.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  export { AgentForgeClient, INSTALLED_TENANT_HEADER } from './client';
2
2
  export type { AgentForgeClientOptions, RequestOptions } from './client';
3
- export { AgentForgeError, AgentForgeAuthError, AgentForgeNotFoundError, AgentForgeNetworkError, AgentForgeDuplicateContactError, } from './errors';
3
+ export { AgentForgeError, AgentForgeAuthError, AgentForgeNotFoundError, AgentForgeNetworkError, AgentForgeDuplicateContactError, AgentForgeBillingError, AGENTFORGE_BILLING_ERROR_CODES, } from './errors';
4
+ export type { AgentForgeBillingErrorCode } from './errors';
5
+ export { BillingResource } from './resources/billing';
6
+ export type { BillingEntitlement, BillingEntitlementStatus, BillingInterval, BillingLimits, BillingPlan, BillingInvoice, BillingPaymentMethod, BillingCheckoutInput, BillingStartTrialInput, AppBillingWebhookEvent, AppBillingWebhookEventName, AppBillingWebhookData, } from './resources/billing';
4
7
  export { APP_WEBHOOK_HEADERS, TOOL_CALLBACK_HEADERS, ToolCallbackSignatureError, signToolCallbackPayload, verifyAppWebhook, verifyToolCallbackSignature, } from './webhooks';
5
8
  export { WebhookResource, type SetAppWebhookInput } from './resources/webhook';
6
- export type { AppWebhook, AppWebhookEvent, AppWebhookEventName, AppCaseWebhookEvent, AppCaseWebhookEventName, AppConversationMessageWebhookEvent, AppChannelStatusWebhookEvent, AgentMe, AgentSummary, AppUserConnectorStatus, ApprovalCopyBundle, ChannelContext, ChatStreamChunk, ChatStreamEvent, ChatTokenRecord, ConnectorDefaultsResult, ConnectorDefaultsSource, ConnectorResourceItem, ConnectorStatus, ConnectorToolInfo, ConversationHistory, ConversationStatus, CreateAgentInput, CreateClickupTaskInput, CreateClickupTaskResult, ExternalToolSummary, IssueChatTokenInput, ListAgentsResult, ListConnectorResourcesResult, McpServerConfig, MessageRecord, MessageRole, PublicAppBranding, PublicProfileBlock, PublicProfileTemplate, PublicTeamLanding, CreateTeamInput, UpdateTeamInput, TeamSummary, TeamDetail, TeamTheme, TeamBusinessHours, TeamWeekday, TeamProfileBlock, ProfileBlockPlacement, ProfileBlockPosition, CatalogBlockPreview, AppInstallation, TemplateConfigField, TemplateSummary, TemplateDetail, TemplateInstallStats, TemplatePublisher, TemplateAuthor, AppTemplatePolicy, TemplateCategoryRef, MarketplaceCategory, MarketplaceCategoryGroup, MarketplaceLocale, TemplateInstallResult, UpsertSystemTemplateInput, UpsertSystemTemplateResult, TemplateReview, TemplateRatingSummary, TemplateReviewsPage, BusinessReview, BusinessReviewsPage, ProductRatingSummary, ProductReview, ProductReviewOwner, ProductReviewsPage, ProductReviewsOwnerPage, ListProductReviewsInput, ListProductReviewsForOwnerInput, HideProductReviewInput, ProductLikeResult, ReceiptReviewable, ReceiptReviewables, SaveReceiptReviewInput, ListTemplateReviewsInput, SaveTemplateReviewInput, TemplateReportKind, CreateTemplateReportInput, TenantConfigEntry, Place, PlaceSuggestion, SearchPlacesInput, AutocompletePlacesInput, PlacesScope, CaseField, CaseBusinessState, CaseType, CaseState, CaseStateType, CasePayment, CasePaymentAccount, CasePaymentStatus, CaseReceiptPayment, CaseDestination, CaseView, CaseStateStep, CreateDirectOrderInput, CreateDirectBookingInput, MoveCaseSlotInput, CaseSlot, CatalogAttendedAt, CatalogBookingRule, CaseOrigin, CaseOriginChannel, DirectOrderForm, DirectPaymentOption, CaseClosingMethod, CaseClosingOrder, CaseClosingReport, CaseReportPage, CaseReceipt, CaseReceiptLine, CaseProposal, CaseProposalAnswer, CaseProposalChange, CaseProposalInput, ListCasesInput, AddressValue, DeliveryLocalPricing, DeliverySettings, PaymentMethodKind, PaymentSettings, PaymentSettingsInput, PaymentAccount, PaymentCountry, PaymentFieldDef, PaymentMethodDef, StructuredConfigInput, StructuredConfigEntry, DeliveryQuoteStatus, DeliveryQuoteInput, DeliveryPricePreview, DeliveryPricingPreview, DeliveryPricingPreviewInput, DeliveryRoute, DeliveryRouteInput, DeliveryQuote, AppSelf, AppOwner, AppSelfConnector, AppSelfConnectors, AppSelfConnectorTools, AppSelfConnectorToolsResponse, RegisterToolInput, RegisterToolsInput, BusinessRoleEntry, Catalog, CatalogCheckoutCta, CatalogCategory, CatalogProduct, CatalogProductPhoto, CatalogProductKind, CatalogProductStatus, CatalogPriceKind, CatalogAvailability, CatalogLockableField, CatalogProductPage, UpsertCatalogInput, CreateCatalogCategoryInput, UpdateCatalogCategoryInput, CreateCatalogProductInput, UpdateCatalogProductInput, ListCatalogProductsInput, CatalogPhotoUploadTarget, SignCatalogPhotoUploadInput, AttachCatalogPhotoInput, AttachCatalogCategoryImageInput, CatalogImportItem, CatalogImportPreview, CatalogImportApplyResult, CatalogFileMapping, CatalogFilePlan, CatalogFilePreview, CatalogFileApplyResult, CatalogFileInput, CatalogFilePreviewInput, CatalogMenuItem, CatalogMenuRead, CatalogMenuReadInput, CatalogMenuAttachInput, CatalogMenuChatFile, CatalogMenuKeepInSyncInput, CatalogMenuKeepInSyncResult, CatalogOption, CatalogOptionGroup, SaveCatalogOptionGroupInput, CatalogOptionChoice, CatalogOptionChange, CatalogOptionChangesPlan, CatalogUnit, SaveCatalogUnitInput, CatalogSaleRule, CatalogFileApplyInput, CatalogFileErrorCode, CatalogImportSourceStatus, CatalogImportColumnMapping, CatalogImportRunResult, CatalogImportSource, CreateCatalogImportSourceInput, UpdateCatalogImportSourceInput, PreviewCatalogImportSourceInput, CatalogImportSourcePreview, CatalogSheetTab, CatalogTemplateSheet, CreateCatalogTemplateSheetInput, GoogleSheetsPickerInput, GoogleSheetsPickerSession, GoogleSheetsPickerErrorCode, GoogleSheetsPickerResult, RegisterToolsResult, ToolCallbackPayload, ToolCallRecord, ToolPermission, ToolPermissionMode, TokenUsage, TenantSecretEntry, UpdateAgentInput, InboxThreadMode, InboxMessageDirection, InboxMessageSource, InboxMessageType, InboxThreadCustomerProfileView, InboxThreadView, InboxMessageView, SupportKpiTotals, SupportKpiResponse, AgentAttentionLogRow, } from './types';
9
+ export type { AppWebhook, AppWebhookEvent, AppWebhookEventName, AppCaseWebhookEvent, AppCaseWebhookEventName, AppConversationMessageWebhookEvent, AppChannelStatusWebhookEvent, AgentMe, AgentSummary, AppUserConnectorStatus, ApprovalCopyBundle, ChannelContext, ChatStreamChunk, ChatStreamEvent, ChatTokenRecord, ConnectorDefaultsResult, ConnectorDefaultsSource, ConnectorResourceItem, ConnectorStatus, ConnectorToolInfo, ConversationHistory, ConversationStatus, CreateAgentInput, CreateClickupTaskInput, CreateClickupTaskResult, ExternalToolSummary, IssueChatTokenInput, ListAgentsResult, ListConnectorResourcesResult, McpServerConfig, MessageRecord, MessageRole, PublicAppBranding, PublicProfileBlock, PublicProfileTemplate, PublicTeamLanding, CreateTeamInput, UpdateTeamInput, TeamSummary, TeamDetail, TeamTheme, TeamBusinessHours, TeamWeekday, TeamProfileBlock, ProfileBlockPlacement, ProfileBlockPosition, CatalogBlockPreview, ServiceCta, ServiceCtaAction, CatalogServicesBlockConfig, AppInstallation, TemplateConfigField, TemplateSummary, TemplateDetail, TemplateInstallStats, TemplatePublisher, TemplateAuthor, AppTemplatePolicy, TemplateCategoryRef, MarketplaceCategory, MarketplaceCategoryGroup, MarketplaceLocale, TemplateInstallResult, UpsertSystemTemplateInput, UpsertSystemTemplateResult, TemplateReview, TemplateRatingSummary, TemplateReviewsPage, BusinessReview, BusinessReviewsPage, ProductRatingSummary, ProductReview, ProductReviewOwner, ProductReviewsPage, ProductReviewsOwnerPage, ListProductReviewsInput, ListProductReviewsForOwnerInput, HideProductReviewInput, ProductLikeResult, ReceiptReviewable, ReceiptReviewables, SaveReceiptReviewInput, ListTemplateReviewsInput, SaveTemplateReviewInput, TemplateReportKind, CreateTemplateReportInput, TenantConfigEntry, Place, PlaceSuggestion, SearchPlacesInput, AutocompletePlacesInput, PlacesScope, CaseField, CaseBusinessState, CaseType, CaseState, CaseStateType, CasePayment, CasePaymentAccount, CasePaymentStatus, CaseReceiptPayment, CaseDestination, CaseView, CaseStateStep, CreateDirectOrderInput, CreateDirectBookingInput, MoveCaseSlotInput, CaseSlot, CatalogAttendedAt, CatalogBookingRule, CaseOrigin, CaseOriginChannel, DirectOrderForm, DirectPaymentOption, CaseClosingMethod, CaseClosingOrder, CaseClosingReport, CaseReportPage, CaseReceipt, CaseReceiptLine, CaseProposal, CaseProposalAnswer, CaseProposalChange, CaseProposalInput, ListCasesInput, AddressValue, DeliveryLocalPricing, DeliverySettings, PaymentMethodKind, PaymentSettings, PaymentSettingsInput, PaymentAccount, PaymentCountry, PaymentFieldDef, PaymentMethodDef, StructuredConfigInput, StructuredConfigEntry, DeliveryQuoteStatus, DeliveryQuoteInput, DeliveryPricePreview, DeliveryPricingPreview, DeliveryPricingPreviewInput, DeliveryRoute, DeliveryRouteInput, DeliveryQuote, AppSelf, AppOwner, AppSelfConnector, AppSelfConnectors, AppSelfConnectorTools, AppSelfConnectorToolsResponse, RegisterToolInput, RegisterToolsInput, BusinessRoleEntry, Catalog, CatalogCheckoutCta, CatalogCategory, CatalogProduct, CatalogProductPhoto, CatalogProductKind, CatalogProductStatus, CatalogPriceKind, CatalogAvailability, CatalogLockableField, CatalogProductPage, UpsertCatalogInput, CreateCatalogCategoryInput, UpdateCatalogCategoryInput, CreateCatalogProductInput, UpdateCatalogProductInput, ListCatalogProductsInput, CatalogPhotoUploadTarget, SignCatalogPhotoUploadInput, AttachCatalogPhotoInput, AttachCatalogCategoryImageInput, CatalogImportItem, CatalogImportPreview, CatalogImportApplyResult, CatalogFileMapping, CatalogFilePlan, CatalogFilePreview, CatalogFileApplyResult, CatalogFileInput, CatalogFilePreviewInput, CatalogMenuItem, CatalogMenuRead, CatalogMenuReadInput, CatalogMenuAttachInput, CatalogMenuChatFile, CatalogMenuKeepInSyncInput, CatalogMenuKeepInSyncResult, CatalogOption, CatalogOptionGroup, SaveCatalogOptionGroupInput, CatalogOptionChoice, CatalogOptionChange, CatalogOptionChangesPlan, CatalogUnit, SaveCatalogUnitInput, CatalogSaleRule, CatalogFileApplyInput, CatalogFileErrorCode, CatalogImportSourceStatus, CatalogImportColumnMapping, CatalogImportRunResult, CatalogImportSource, CreateCatalogImportSourceInput, UpdateCatalogImportSourceInput, PreviewCatalogImportSourceInput, CatalogImportSourcePreview, CatalogSheetTab, CatalogTemplateSheet, CreateCatalogTemplateSheetInput, GoogleSheetsPickerInput, GoogleSheetsPickerSession, GoogleSheetsPickerErrorCode, GoogleSheetsPickerResult, RegisterToolsResult, ToolCallbackPayload, ToolCallRecord, ToolPermission, ToolPermissionMode, TokenUsage, TenantSecretEntry, UpdateAgentInput, InboxThreadMode, InboxMessageDirection, InboxMessageSource, InboxMessageType, InboxThreadCustomerProfileView, InboxThreadView, InboxMessageView, SupportKpiTotals, SupportKpiResponse, AgentAttentionLogRow, } from './types';
7
10
  export { AgentsResource } from './resources/agents';
8
11
  export { AnalyticsResource } from './resources/analytics';
9
12
  export type { GetSupportKpisInput, GetAgentAttentionLogInput, } from './resources/analytics';
package/dist/index.js CHANGED
@@ -28,8 +28,8 @@
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.CatalogSourcesResource = exports.CatalogUnitsResource = exports.CatalogOptionGroupsResource = exports.CatalogMenuImportResource = exports.CatalogFileImportResource = exports.CatalogImportResource = exports.CatalogPhotosResource = exports.CatalogReviewsResource = exports.CatalogProductLikesResource = exports.CatalogProductReviewsResource = exports.CatalogProductsResource = exports.CatalogCategoriesResource = exports.CatalogResource = exports.BusinessRolesResource = exports.CasesResource = exports.DeliveryResource = exports.FilesResource = exports.ContactListsResource = exports.ContactTagsResource = exports.ContactAddressesResource = exports.ContactVerificationResource = exports.ContactsResource = exports.PlacesResource = exports.TenantConfigResource = exports.MarketplaceResource = exports.TemplateReportsResource = exports.TemplateReviewsResource = 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.AgentForgeDuplicateContactError = exports.AgentForgeNetworkError = exports.AgentForgeNotFoundError = exports.AgentForgeAuthError = exports.AgentForgeError = exports.INSTALLED_TENANT_HEADER = exports.AgentForgeClient = void 0;
32
- exports.ToolsResource = exports.TeamsResource = exports.SecretsResource = exports.ProvisioningResource = exports.CATALOG_IMPORT_MAX_ITEMS = exports.AgentForgeCatalogImportLimitError = void 0;
31
+ exports.CatalogMenuImportResource = exports.CatalogFileImportResource = exports.CatalogImportResource = exports.CatalogPhotosResource = exports.CatalogReviewsResource = exports.CatalogProductLikesResource = exports.CatalogProductReviewsResource = exports.CatalogProductsResource = exports.CatalogCategoriesResource = exports.CatalogResource = exports.BusinessRolesResource = exports.CasesResource = exports.DeliveryResource = exports.FilesResource = exports.ContactListsResource = exports.ContactTagsResource = exports.ContactAddressesResource = exports.ContactVerificationResource = exports.ContactsResource = exports.PlacesResource = exports.TenantConfigResource = exports.MarketplaceResource = exports.TemplateReportsResource = exports.TemplateReviewsResource = 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.BillingResource = exports.AGENTFORGE_BILLING_ERROR_CODES = exports.AgentForgeBillingError = exports.AgentForgeDuplicateContactError = exports.AgentForgeNetworkError = exports.AgentForgeNotFoundError = exports.AgentForgeAuthError = exports.AgentForgeError = exports.INSTALLED_TENANT_HEADER = exports.AgentForgeClient = void 0;
32
+ exports.ToolsResource = exports.TeamsResource = exports.SecretsResource = exports.ProvisioningResource = exports.CATALOG_IMPORT_MAX_ITEMS = exports.AgentForgeCatalogImportLimitError = exports.CatalogSourcesResource = exports.CatalogUnitsResource = exports.CatalogOptionGroupsResource = void 0;
33
33
  var client_1 = require("./client");
34
34
  Object.defineProperty(exports, "AgentForgeClient", { enumerable: true, get: function () { return client_1.AgentForgeClient; } });
35
35
  Object.defineProperty(exports, "INSTALLED_TENANT_HEADER", { enumerable: true, get: function () { return client_1.INSTALLED_TENANT_HEADER; } });
@@ -39,6 +39,10 @@ Object.defineProperty(exports, "AgentForgeAuthError", { enumerable: true, get: f
39
39
  Object.defineProperty(exports, "AgentForgeNotFoundError", { enumerable: true, get: function () { return errors_1.AgentForgeNotFoundError; } });
40
40
  Object.defineProperty(exports, "AgentForgeNetworkError", { enumerable: true, get: function () { return errors_1.AgentForgeNetworkError; } });
41
41
  Object.defineProperty(exports, "AgentForgeDuplicateContactError", { enumerable: true, get: function () { return errors_1.AgentForgeDuplicateContactError; } });
42
+ Object.defineProperty(exports, "AgentForgeBillingError", { enumerable: true, get: function () { return errors_1.AgentForgeBillingError; } });
43
+ Object.defineProperty(exports, "AGENTFORGE_BILLING_ERROR_CODES", { enumerable: true, get: function () { return errors_1.AGENTFORGE_BILLING_ERROR_CODES; } });
44
+ var billing_1 = require("./resources/billing");
45
+ Object.defineProperty(exports, "BillingResource", { enumerable: true, get: function () { return billing_1.BillingResource; } });
42
46
  var webhooks_1 = require("./webhooks");
43
47
  Object.defineProperty(exports, "APP_WEBHOOK_HEADERS", { enumerable: true, get: function () { return webhooks_1.APP_WEBHOOK_HEADERS; } });
44
48
  Object.defineProperty(exports, "TOOL_CALLBACK_HEADERS", { enumerable: true, get: function () { return webhooks_1.TOOL_CALLBACK_HEADERS; } });
@@ -0,0 +1,130 @@
1
+ import type { AgentForgeClient } from '../client';
2
+ export type BillingEntitlementStatus = 'free' | 'trialing' | 'active' | 'past_due' | 'canceled';
3
+ export type BillingInterval = 'month' | 'year';
4
+ /** The limits of a plan. `custom` carries the App's own (e.g. Poodleck's table). */
5
+ export interface BillingLimits {
6
+ resetInterval?: 'month' | 'day';
7
+ requestsPerMonth?: number;
8
+ tokensPerMonth?: number;
9
+ requestsPerDay?: number;
10
+ tokensPerDay?: number;
11
+ maxConcurrentConversations?: number;
12
+ maxAgents?: number;
13
+ maxTeams?: number;
14
+ maxAutomations?: number;
15
+ maxSkills?: number;
16
+ maxMcpServers?: number;
17
+ maxChatTokens?: number;
18
+ custom?: Record<string, number>;
19
+ }
20
+ /** What the tenant is entitled to right now. `canceled` + `cancelAtPeriodEnd` still has access until `currentPeriodEnd`. */
21
+ export interface BillingEntitlement {
22
+ planId: string;
23
+ planName: string;
24
+ status: BillingEntitlementStatus;
25
+ /** ISO. Set while on a trial (no-card or provider). */
26
+ trialEndsAt: string | null;
27
+ /** The tenant already had its (single) trial. */
28
+ trialUsed: boolean;
29
+ currentPeriodEnd: string | null;
30
+ cancelAtPeriodEnd: boolean;
31
+ priceInCents: number | null;
32
+ interval: BillingInterval | null;
33
+ currency: 'USD';
34
+ features: string[];
35
+ limits: BillingLimits;
36
+ subscriptionId: string | null;
37
+ }
38
+ export interface BillingPlan {
39
+ id: string;
40
+ name: string;
41
+ description: string | null;
42
+ priceInCents: number | null;
43
+ interval: BillingInterval | null;
44
+ currency: 'USD';
45
+ isDefault: boolean;
46
+ features: string[];
47
+ limits: BillingLimits;
48
+ }
49
+ export interface BillingInvoice {
50
+ id: string;
51
+ /** ISO. */
52
+ date: string;
53
+ amountCents: number;
54
+ currency: string;
55
+ status: string;
56
+ receiptUrl: string | null;
57
+ }
58
+ export interface BillingPaymentMethod {
59
+ /** Provider page where the customer updates the card. */
60
+ updateUrl: string | null;
61
+ brand: string | null;
62
+ last4: string | null;
63
+ }
64
+ export interface BillingStartTrialInput {
65
+ /** Slug of the plan to trial (not the default plan). */
66
+ planId: string;
67
+ /** 1 to 90. */
68
+ days: number;
69
+ }
70
+ export interface BillingCheckoutInput {
71
+ planId: string;
72
+ /** https (http only for localhost). */
73
+ successUrl: string;
74
+ /** Accepted; the provider has no cancel URL, so it is ignored for now. */
75
+ cancelUrl?: string;
76
+ email?: string;
77
+ name?: string;
78
+ }
79
+ export type AppBillingWebhookEventName = 'billing.plan_changed' | 'billing.trial_ended';
80
+ export interface AppBillingWebhookData {
81
+ /** Plan slug the tenant is on now. */
82
+ planId: string;
83
+ previousPlanId: string | null;
84
+ status: BillingEntitlementStatus;
85
+ /** e.g. `trial_expired`, `subscription_created`, `subscription_updated`, `plan_changed`, `trial_started`. */
86
+ reason: string;
87
+ at: string;
88
+ }
89
+ /**
90
+ * The tenant's plan changed, or its no-card trial ran out. Only to the App that owns the plan.
91
+ * Read the truth with `forTenant(tenantId).billing.entitlements()`; polling it is the backstop for a lost event.
92
+ */
93
+ export interface AppBillingWebhookEvent {
94
+ id: string;
95
+ createdAt: string;
96
+ tenantId: string;
97
+ type: AppBillingWebhookEventName;
98
+ data: AppBillingWebhookData;
99
+ }
100
+ export declare class BillingResource {
101
+ private readonly client;
102
+ constructor(client: AgentForgeClient);
103
+ private call;
104
+ /** `GET /api/v1/billing/entitlements` — plan, status, trial, period, limits. Self-heals an expired trial. */
105
+ entitlements(): Promise<BillingEntitlement>;
106
+ /** `POST /api/v1/billing/trial/start` — a no-card trial, once per tenant. `trial_already_used` / `already_subscribed` (409). */
107
+ startTrial(input: BillingStartTrialInput): Promise<BillingEntitlement>;
108
+ /** `GET /api/v1/billing/plans` — the App's plans, without provider refs. */
109
+ plans(): Promise<BillingPlan[]>;
110
+ /** `POST /api/v1/billing/checkout` — the hosted checkout `url`. `already_subscribed` (409) over a live subscription. */
111
+ checkout(input: BillingCheckoutInput): Promise<{
112
+ url: string;
113
+ }>;
114
+ /** `POST /api/v1/billing/change-plan` — upgrade charges at once; downgrade credits at the next renewal. `no_subscription` (409). */
115
+ changePlan(input: {
116
+ planId: string;
117
+ }): Promise<BillingEntitlement>;
118
+ /** `POST /api/v1/billing/cancel` — at period end: `status: 'canceled'`, `cancelAtPeriodEnd: true`, access until `currentPeriodEnd`. */
119
+ cancel(): Promise<BillingEntitlement>;
120
+ /** `POST /api/v1/billing/resume` — undo a scheduled cancel. */
121
+ resume(): Promise<BillingEntitlement>;
122
+ /** `GET /api/v1/billing/portal` — the provider's customer portal `url`. `no_subscription` (409) before the first purchase. */
123
+ portal(): Promise<{
124
+ url: string;
125
+ }>;
126
+ /** `GET /api/v1/billing/invoices` — newest first; `[]` while on a trial or free. */
127
+ invoices(): Promise<BillingInvoice[]>;
128
+ /** `GET /api/v1/billing/payment-method` — card summary and the update link. `no_subscription` (409) before the first purchase. */
129
+ paymentMethod(): Promise<BillingPaymentMethod>;
130
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ // billing resource (PDK-BILLING J5) — the plan, trial and subscription of an
3
+ // INSTALLED tenant (one Poodleck business = one tenant), called by its App.
4
+ //
5
+ // Auth: the App secret (`sk_`) + `x-af-tenant`, i.e. always through
6
+ // `af.forTenant(tenantId).billing`. The platform refuses `ak_` keys and the
7
+ // App's home tenant (403). Whether the human may see prices or invoices
8
+ // (owner / admin) is the App's decision.
9
+ //
10
+ // Plan ids are the App's short slugs (`free`, `pro`, …), never internal row ids.
11
+ // Failures with a billing code throw `AgentForgeBillingError` (`err.code`).
12
+ //
13
+ // Needs the platform change agentforge-platform#242.
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BillingResource = void 0;
16
+ const errors_1 = require("../errors");
17
+ const CODES = new Set(errors_1.AGENTFORGE_BILLING_ERROR_CODES);
18
+ /** A billing-coded failure becomes the typed error; anything else is rethrown as is. */
19
+ function asBilling(err) {
20
+ if (err instanceof errors_1.AgentForgeError && err.code && CODES.has(err.code) && err.status !== 401 && err.status !== 403) {
21
+ let message = err.message;
22
+ if (err.body) {
23
+ try {
24
+ const b = JSON.parse(err.body);
25
+ if (typeof b.message === 'string')
26
+ message = b.message;
27
+ }
28
+ catch {
29
+ /* keep the status message */
30
+ }
31
+ }
32
+ return new errors_1.AgentForgeBillingError(err.status, err.code, message, err.body);
33
+ }
34
+ return err;
35
+ }
36
+ const BASE = '/api/v1/billing';
37
+ class BillingResource {
38
+ constructor(client) {
39
+ this.client = client;
40
+ }
41
+ async call(method, path, body) {
42
+ try {
43
+ return await this.client.request(method, `${BASE}${path}`, body);
44
+ }
45
+ catch (err) {
46
+ throw asBilling(err);
47
+ }
48
+ }
49
+ /** `GET /api/v1/billing/entitlements` — plan, status, trial, period, limits. Self-heals an expired trial. */
50
+ entitlements() {
51
+ return this.call('GET', '/entitlements');
52
+ }
53
+ /** `POST /api/v1/billing/trial/start` — a no-card trial, once per tenant. `trial_already_used` / `already_subscribed` (409). */
54
+ startTrial(input) {
55
+ return this.call('POST', '/trial/start', input);
56
+ }
57
+ /** `GET /api/v1/billing/plans` — the App's plans, without provider refs. */
58
+ async plans() {
59
+ return (await this.call('GET', '/plans')).items;
60
+ }
61
+ /** `POST /api/v1/billing/checkout` — the hosted checkout `url`. `already_subscribed` (409) over a live subscription. */
62
+ checkout(input) {
63
+ return this.call('POST', '/checkout', input);
64
+ }
65
+ /** `POST /api/v1/billing/change-plan` — upgrade charges at once; downgrade credits at the next renewal. `no_subscription` (409). */
66
+ changePlan(input) {
67
+ return this.call('POST', '/change-plan', input);
68
+ }
69
+ /** `POST /api/v1/billing/cancel` — at period end: `status: 'canceled'`, `cancelAtPeriodEnd: true`, access until `currentPeriodEnd`. */
70
+ cancel() {
71
+ return this.call('POST', '/cancel');
72
+ }
73
+ /** `POST /api/v1/billing/resume` — undo a scheduled cancel. */
74
+ resume() {
75
+ return this.call('POST', '/resume');
76
+ }
77
+ /** `GET /api/v1/billing/portal` — the provider's customer portal `url`. `no_subscription` (409) before the first purchase. */
78
+ portal() {
79
+ return this.call('GET', '/portal');
80
+ }
81
+ /** `GET /api/v1/billing/invoices` — newest first; `[]` while on a trial or free. */
82
+ async invoices() {
83
+ return (await this.call('GET', '/invoices')).items;
84
+ }
85
+ /** `GET /api/v1/billing/payment-method` — card summary and the update link. `no_subscription` (409) before the first purchase. */
86
+ paymentMethod() {
87
+ return this.call('GET', '/payment-method');
88
+ }
89
+ }
90
+ exports.BillingResource = BillingResource;
package/dist/types.d.ts CHANGED
@@ -809,6 +809,48 @@ export interface ProfileBlockPlacement {
809
809
  export type ProfileBlockPosition = 'top-left' | 'top-center' | 'top-right' | 'middle-left' | 'middle-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
810
810
  /** Products a catalog block draws inline; the rest sit behind «Ver todo». Absent = `'all'`. */
811
811
  export type CatalogBlockPreview = 3 | 6 | 9 | 12 | 'all';
812
+ /** PDK-SERVICES — what a service's button does. */
813
+ export type ServiceCtaAction = 'book' | 'request' | 'cart' | 'chat' | 'whatsapp' | 'link';
814
+ /**
815
+ * PDK-SERVICES — a service's call to action (`CatalogProduct.cta`; only `kind: 'service'`).
816
+ * `label` 2–28 chars (trimmed; absent = the action's default), `helper` <= 60 chars,
817
+ * `value`: https URL (required for `link`) or a phone normalized to `+E.164` (optional for `whatsapp`,
818
+ * absent = the business's number); ignored for the other actions.
819
+ */
820
+ export interface ServiceCta {
821
+ action: ServiceCtaAction;
822
+ label?: string;
823
+ value?: string;
824
+ /** Show the price inside the button. */
825
+ showPrice?: boolean;
826
+ helper?: string;
827
+ }
828
+ /**
829
+ * PDK-SERVICES — presentation of the catalog block's «Servicios» tab. Every field is optional; an invalid
830
+ * value is dropped by the platform (not refused) and the reader's default applies.
831
+ */
832
+ export interface CatalogServicesBlockConfig {
833
+ /** Default `feed`. */
834
+ layout?: 'feed' | 'cards' | 'list' | 'carousel';
835
+ mediaRatio?: '4:5' | '1:1' | '16:9';
836
+ /** On the photo, inside the button, or under the title. */
837
+ pricePlacement?: 'media' | 'button' | 'title';
838
+ /** 0–4. */
839
+ descriptionLines?: number;
840
+ showHeader?: boolean;
841
+ showReactions?: boolean;
842
+ showDuration?: boolean;
843
+ showRating?: boolean;
844
+ /** Default button for every service of the page; a service's own `cta` wins. No `value`. */
845
+ cta?: Omit<ServiceCta, 'value'>;
846
+ /** Tab names, <= 24 chars each. */
847
+ tabLabels?: {
848
+ products?: string;
849
+ services?: string;
850
+ };
851
+ /** Default `products-first`. */
852
+ tabOrder?: 'products-first' | 'services-first';
853
+ }
812
854
  /** One block of a public page. `id` is minted by the platform when omitted. */
813
855
  export type TeamProfileBlock = {
814
856
  id?: string;
@@ -857,6 +899,7 @@ export type TeamProfileBlock = {
857
899
  kind: 'catalog';
858
900
  catalogId: string;
859
901
  preview?: CatalogBlockPreview;
902
+ services?: CatalogServicesBlockConfig;
860
903
  [field: string]: unknown;
861
904
  }
862
905
  /**
@@ -876,6 +919,7 @@ export type TeamProfileBlock = {
876
919
  serviceIds?: string[];
877
920
  customerPicksMember?: boolean;
878
921
  layout?: 'chips' | 'list';
922
+ startWith?: 'service' | 'time';
879
923
  });
880
924
  /** `GET /api/v1/teams/:id` — the team with its page settings, and its members. */
881
925
  export interface TeamDetail {
@@ -1294,6 +1338,8 @@ export interface CatalogProduct {
1294
1338
  saleRule?: CatalogSaleRule | null;
1295
1339
  /** AGF-AGENDA — a service's duration and buffer; null = not bookable. */
1296
1340
  booking?: CatalogBookingRule | null;
1341
+ /** PDK-SERVICES — a service's button; null = the default rule. Only `kind: 'service'`. */
1342
+ cta?: ServiceCta | null;
1297
1343
  lastSoldAt?: string | null;
1298
1344
  demandCount: number;
1299
1345
  /** AGF-PDK-PRODUCT-REVIEWS — over the visible reviews (absent on an older platform). */
@@ -1329,6 +1375,9 @@ export interface CreateCatalogProductInput {
1329
1375
  /** AGF-AGENDA — a service's `{ durationMinutes, bufferMinutes? }`; null makes it not bookable.
1330
1376
  * Only `kind: 'service'` (400 NOT_A_SERVICE), 5–720 and 0–120 minutes (400 INVALID_BOOKING). */
1331
1377
  booking?: CatalogBookingRule | null;
1378
+ /** PDK-SERVICES — a service's button `{ action, label?, value?, showPrice?, helper? }`; null clears it.
1379
+ * Only `kind: 'service'` (400 NOT_A_SERVICE); invalid values 400 INVALID_CTA. Turning the item into a product drops it. */
1380
+ cta?: ServiceCta | null;
1332
1381
  }
1333
1382
  export interface UpdateCatalogProductInput extends Partial<CreateCatalogProductInput> {
1334
1383
  sortOrder?: number;
@@ -2938,8 +2987,9 @@ export interface MoveCaseSlotInput {
2938
2987
  assigneeRef?: string | null;
2939
2988
  assigneeName?: string;
2940
2989
  }
2990
+ import type { AppBillingWebhookEvent } from './resources/billing';
2941
2991
  export type AppCaseWebhookEventName = 'case.submitted' | 'case.state_changed' | 'case.closed' | 'case.customer_request' | 'case.payment_changed' | 'case.proposal';
2942
- export type AppWebhookEventName = AppCaseWebhookEventName | 'conversation.message' | 'channel.status_changed';
2992
+ export type AppWebhookEventName = AppCaseWebhookEventName | 'conversation.message' | 'channel.status_changed' | 'billing.plan_changed' | 'billing.trial_ended';
2943
2993
  export interface AppWebhook {
2944
2994
  url: string;
2945
2995
  events: AppWebhookEventName[];
@@ -2959,7 +3009,7 @@ interface AppWebhookEventBase {
2959
3009
  * What the platform POSTs. No customer data: read with your own credential. Narrow on `type`.
2960
3010
  * A new event only arrives once the App lists it in `webhook.set({ events })`.
2961
3011
  */
2962
- export type AppWebhookEvent = AppCaseWebhookEvent | AppConversationMessageWebhookEvent | AppChannelStatusWebhookEvent;
3012
+ export type AppWebhookEvent = AppCaseWebhookEvent | AppConversationMessageWebhookEvent | AppChannelStatusWebhookEvent | AppBillingWebhookEvent;
2963
3013
  /**
2964
3014
  * A message was committed on a thread of one of this App's agents, on any inbox channel. Only to the App that owns the
2965
3015
  * agent. No text, sender name or phone: read it with `forTenant(tenantId).inbox.forAgent(agentId)`. A burst on one thread
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge-io/sdk-server",
3
- "version": "4.68.0",
3
+ "version": "4.70.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",