@agentforge-io/sdk-server 4.82.0 → 4.84.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 +3 -0
- package/dist/client.js +2 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +14 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +7 -2
- package/dist/resources/cases.d.ts +51 -2
- package/dist/resources/cases.js +63 -1
- package/dist/resources/credit.d.ts +205 -0
- package/dist/resources/credit.js +165 -0
- package/dist/types.d.ts +239 -2
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { ReferenceResource } from './resources/reference';
|
|
|
23
23
|
import { BusinessRolesResource } from './resources/business-roles';
|
|
24
24
|
import { ToolsResource } from './resources/tools';
|
|
25
25
|
import { BillingResource } from './resources/billing';
|
|
26
|
+
import { CreditResource } from './resources/credit';
|
|
26
27
|
export interface AgentForgeClientOptions {
|
|
27
28
|
/** Platform base URL — e.g. http://localhost:3032 in dev. */
|
|
28
29
|
baseURL: string;
|
|
@@ -121,6 +122,8 @@ export declare class AgentForgeClient {
|
|
|
121
122
|
readonly reference: ReferenceResource;
|
|
122
123
|
/** PDK-BILLING — the installed tenant's plan, trial and subscription (use `af.forTenant(id).billing`). */
|
|
123
124
|
readonly billing: BillingResource;
|
|
125
|
+
/** PDK-STORE-CREDIT — the business's customer accounts («fiado»): abonos, write-offs, statements. */
|
|
126
|
+
readonly credit: CreditResource;
|
|
124
127
|
constructor(opts: AgentForgeClientOptions);
|
|
125
128
|
/**
|
|
126
129
|
* A client that acts inside `tenantId`, a tenant where this App is
|
package/dist/client.js
CHANGED
|
@@ -45,6 +45,7 @@ const reference_1 = require("./resources/reference");
|
|
|
45
45
|
const business_roles_1 = require("./resources/business-roles");
|
|
46
46
|
const tools_1 = require("./resources/tools");
|
|
47
47
|
const billing_1 = require("./resources/billing");
|
|
48
|
+
const credit_1 = require("./resources/credit");
|
|
48
49
|
/** Header that selects an installed tenant for an App secret. */
|
|
49
50
|
exports.INSTALLED_TENANT_HEADER = 'x-af-tenant';
|
|
50
51
|
class AgentForgeClient {
|
|
@@ -96,6 +97,7 @@ class AgentForgeClient {
|
|
|
96
97
|
this.catalog = new catalog_1.CatalogResource(this);
|
|
97
98
|
this.reference = new reference_1.ReferenceResource(this);
|
|
98
99
|
this.billing = new billing_1.BillingResource(this);
|
|
100
|
+
this.credit = new credit_1.CreditResource(this);
|
|
99
101
|
}
|
|
100
102
|
/**
|
|
101
103
|
* A client that acts inside `tenantId`, a tenant where this App is
|
package/dist/errors.d.ts
CHANGED
|
@@ -52,6 +52,18 @@ export declare class AgentForgeBillingError extends AgentForgeError {
|
|
|
52
52
|
readonly code: AgentForgeBillingErrorCode;
|
|
53
53
|
constructor(status: number, code: AgentForgeBillingErrorCode, message: string, body?: string);
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* PDK-STORE-CREDIT — the coded refusals of `af.credit.*` and `af.cases.setOnAccount`. `code` narrows to this union.
|
|
57
|
+
* 404 `contact_not_found` / `not_found`; 409 `over_limit` / `account_blocked` / `already_charged` / `already_on_account` /
|
|
58
|
+
* `already_reversed` / `idempotency_conflict` (the key was used for a different request) / `payment_spent` /
|
|
59
|
+
* `account_merged`; 503 `ledger_guard_missing`; the rest 400. A refusal is final: do not retry it with another key.
|
|
60
|
+
*/
|
|
61
|
+
export type AgentForgeCreditErrorCode = 'invalid_amount' | 'invalid_input' | 'contact_not_found' | 'account_blocked' | 'account_merged' | 'over_limit' | 'overpayment' | 'nothing_owed' | 'not_found' | 'already_reversed' | 'idempotency_conflict' | 'payment_spent' | 'exceeds_credit' | 'adjust_below_paid' | 'ledger_guard_missing' | 'wrong_kind' | 'already_charged' | 'contact_erased' | 'already_on_account' | 'fiado_needs_contact' | 'fiado_contact_mismatch' | 'contact_not_in_tenant' | 'fiado_needs_name_and_phone' | 'fiado_needs_total' | 'down_payment_covers_order';
|
|
62
|
+
export declare const AGENTFORGE_CREDIT_ERROR_CODES: readonly AgentForgeCreditErrorCode[];
|
|
63
|
+
export declare class AgentForgeCreditError extends AgentForgeError {
|
|
64
|
+
readonly code: AgentForgeCreditErrorCode;
|
|
65
|
+
constructor(status: number, code: AgentForgeCreditErrorCode, message: string, body?: string);
|
|
66
|
+
}
|
|
55
67
|
export declare class AgentForgeNetworkError extends Error {
|
|
56
68
|
readonly cause: Error;
|
|
57
69
|
constructor(message: string, cause: Error);
|
package/dist/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgentForgeNetworkError = exports.AgentForgeBillingError = exports.AGENTFORGE_BILLING_ERROR_CODES = exports.AgentForgeDuplicateContactError = exports.AgentForgeNotFoundError = exports.AgentForgeAuthError = exports.AgentForgeError = void 0;
|
|
3
|
+
exports.AgentForgeNetworkError = exports.AgentForgeCreditError = exports.AGENTFORGE_CREDIT_ERROR_CODES = exports.AgentForgeBillingError = exports.AGENTFORGE_BILLING_ERROR_CODES = exports.AgentForgeDuplicateContactError = exports.AgentForgeNotFoundError = exports.AgentForgeAuthError = exports.AgentForgeError = void 0;
|
|
4
4
|
class AgentForgeError extends Error {
|
|
5
5
|
constructor(status, message, body, code) {
|
|
6
6
|
super(message);
|
|
@@ -103,6 +103,19 @@ class AgentForgeBillingError extends AgentForgeError {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
exports.AgentForgeBillingError = AgentForgeBillingError;
|
|
106
|
+
exports.AGENTFORGE_CREDIT_ERROR_CODES = [
|
|
107
|
+
'invalid_amount', 'invalid_input', 'contact_not_found', 'account_blocked', 'account_merged', 'over_limit', 'overpayment',
|
|
108
|
+
'nothing_owed', 'not_found', 'already_reversed', 'idempotency_conflict', 'payment_spent', 'exceeds_credit', 'adjust_below_paid',
|
|
109
|
+
'ledger_guard_missing', 'wrong_kind', 'already_charged', 'contact_erased', 'already_on_account', 'fiado_needs_contact',
|
|
110
|
+
'fiado_contact_mismatch', 'contact_not_in_tenant', 'fiado_needs_name_and_phone', 'fiado_needs_total', 'down_payment_covers_order',
|
|
111
|
+
];
|
|
112
|
+
class AgentForgeCreditError extends AgentForgeError {
|
|
113
|
+
constructor(status, code, message, body) {
|
|
114
|
+
super(status, message, body, code);
|
|
115
|
+
this.name = 'AgentForgeCreditError';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.AgentForgeCreditError = AgentForgeCreditError;
|
|
106
119
|
class AgentForgeNetworkError extends Error {
|
|
107
120
|
constructor(message, cause) {
|
|
108
121
|
super(message);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export { AgentForgeClient, INSTALLED_TENANT_HEADER } from './client';
|
|
2
2
|
export type { AgentForgeClientOptions, RequestOptions } from './client';
|
|
3
|
-
export { AgentForgeError, AgentForgeAuthError, AgentForgeNotFoundError, AgentForgeNetworkError, AgentForgeDuplicateContactError, AgentForgeBillingError, AGENTFORGE_BILLING_ERROR_CODES, } from './errors';
|
|
4
|
-
export type { AgentForgeBillingErrorCode } from './errors';
|
|
3
|
+
export { AgentForgeError, AgentForgeAuthError, AgentForgeNotFoundError, AgentForgeNetworkError, AgentForgeDuplicateContactError, AgentForgeBillingError, AGENTFORGE_BILLING_ERROR_CODES, AgentForgeCreditError, AGENTFORGE_CREDIT_ERROR_CODES, } from './errors';
|
|
4
|
+
export type { AgentForgeBillingErrorCode, AgentForgeCreditErrorCode } from './errors';
|
|
5
|
+
export { CreditResource, CreditAccountsResource } from './resources/credit';
|
|
6
|
+
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';
|
|
5
7
|
export { BillingResource } from './resources/billing';
|
|
6
8
|
export type { BillingCurrency, BillingEntitlement, BillingEntitlementStatus, BillingInterval, BillingLimits, BillingPlan, BillingInvoice, BillingInvoicePage, BillingInvoicesQuery, BillingPaymentMethod, BillingCheckoutInput, BillingStartTrialInput, AppBillingWebhookEvent, AppBillingWebhookEventName, AppBillingWebhookData, } from './resources/billing';
|
|
7
9
|
export { APP_WEBHOOK_HEADERS, TOOL_CALLBACK_HEADERS, ToolCallbackSignatureError, signToolCallbackPayload, verifyAppWebhook, verifyToolCallbackSignature, } from './webhooks';
|
|
8
10
|
export { WebhookResource, type SetAppWebhookInput } from './resources/webhook';
|
|
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, CheckSystemTemplateResult, TemplatePublishIssue, 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, CaseContactLink, CaseStateStep, CreateDirectOrderInput, CreateOpenOrderInput, OpenOrderFreeLine, OpenOrderLineMark, OpenOrderPayment, 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, ListCatalogCategoriesInput, 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, ReferenceMatchItemInput, ReferenceMatchDecisionKind, ReferenceMatchCandidate, ReferenceMatchDecision, ReferenceMatchInput, ReferenceMatchResult, ReferenceProductInput, ReferenceProductsBulkInput, ReferenceProductsBulkResult, ReferenceProduct, ListReferenceProductsInput, ReferenceProductPage, GoogleCalendarAccount, GoogleCalendarEventInput, GoogleCalendarUpsertResult, GoogleCalendarBusyInput, GoogleCalendarBusyResult, GoogleSheetsPickerInput, GoogleSheetsPickerSession, GoogleSheetsPickerErrorCode, GoogleSheetsPickerResult, RegisterToolsResult, ToolCallbackPayload, ToolCallRecord, ToolPermission, ToolPermissionMode, TokenUsage, TenantSecretEntry, UpdateAgentInput, InboxThreadMode, InboxMessageDirection, InboxMessageSource, InboxMessageType, InboxThreadCustomerProfileView, InboxThreadView, InboxMessageView, SupportKpiTotals, SupportKpiResponse, AgentAttentionLogRow, } from './types';
|
|
11
|
+
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, CheckSystemTemplateResult, TemplatePublishIssue, 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, CaseContactLink, CaseStateStep, CreateDirectOrderInput, CreateOpenOrderInput, CaseOffCatalogLine, CaseOffCatalogView, ConfirmCaseLineInput, CreateOffCatalogLineInput, OpenOrderFreeLine, OpenOrderLineMark, OpenOrderPayment, CreateDirectBookingInput, MoveCaseSlotInput, CaseSlot, CatalogAttendedAt, CatalogBookingRule, CaseOrigin, CaseOriginChannel, DirectOrderForm, DirectPaymentOption, CaseClosingMethod, CaseClosingOrder, CaseClosingReport, CaseClosingReceivables, CaseAccount, SetOnAccountInput, SetOnAccountResult, 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, ListCatalogCategoriesInput, 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, ReferenceMatchItemInput, ReferenceMatchDecisionKind, ReferenceMatchCandidate, ReferenceMatchDecision, ReferenceMatchInput, ReferenceMatchResult, ReferenceProductInput, ReferenceProductsBulkInput, ReferenceProductsBulkResult, ReferenceProduct, ListReferenceProductsInput, ReferenceProductPage, GoogleCalendarAccount, GoogleCalendarEventInput, GoogleCalendarUpsertResult, GoogleCalendarBusyInput, GoogleCalendarBusyResult, GoogleSheetsPickerInput, GoogleSheetsPickerSession, GoogleSheetsPickerErrorCode, GoogleSheetsPickerResult, RegisterToolsResult, ToolCallbackPayload, ToolCallRecord, ToolPermission, ToolPermissionMode, TokenUsage, TenantSecretEntry, UpdateAgentInput, InboxThreadMode, InboxMessageDirection, InboxMessageSource, InboxMessageType, InboxThreadCustomerProfileView, InboxThreadView, InboxMessageView, SupportKpiTotals, SupportKpiResponse, AgentAttentionLogRow, } from './types';
|
|
10
12
|
export { AgentsResource } from './resources/agents';
|
|
11
13
|
export { AnalyticsResource } from './resources/analytics';
|
|
12
14
|
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.
|
|
32
|
-
exports.ToolsResource = exports.TeamsResource = exports.SecretsResource = exports.ProvisioningResource = exports.CATALOG_IMPORT_MAX_ITEMS = exports.AgentForgeCatalogImportLimitError = exports.CatalogSourcesResource = exports.CatalogUnitsResource = exports.CatalogOptionGroupsResource = exports.CatalogMenuImportResource = exports.CatalogFileImportResource = exports.CatalogImportResource = exports.CatalogPhotosResource = exports.CatalogReviewsResource = void 0;
|
|
31
|
+
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.REFERENCE_BULK_MAX_ITEMS = exports.REFERENCE_MATCH_MAX_ITEMS = exports.AgentForgeReferenceLimitError = exports.ReferenceProductsResource = exports.ReferenceResource = 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.CreditAccountsResource = exports.CreditResource = exports.AGENTFORGE_CREDIT_ERROR_CODES = exports.AgentForgeCreditError = 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 = exports.CatalogMenuImportResource = exports.CatalogFileImportResource = exports.CatalogImportResource = exports.CatalogPhotosResource = exports.CatalogReviewsResource = exports.CatalogProductLikesResource = exports.CatalogProductReviewsResource = exports.CatalogProductsResource = exports.CatalogCategoriesResource = 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; } });
|
|
@@ -41,6 +41,11 @@ Object.defineProperty(exports, "AgentForgeNetworkError", { enumerable: true, get
|
|
|
41
41
|
Object.defineProperty(exports, "AgentForgeDuplicateContactError", { enumerable: true, get: function () { return errors_1.AgentForgeDuplicateContactError; } });
|
|
42
42
|
Object.defineProperty(exports, "AgentForgeBillingError", { enumerable: true, get: function () { return errors_1.AgentForgeBillingError; } });
|
|
43
43
|
Object.defineProperty(exports, "AGENTFORGE_BILLING_ERROR_CODES", { enumerable: true, get: function () { return errors_1.AGENTFORGE_BILLING_ERROR_CODES; } });
|
|
44
|
+
Object.defineProperty(exports, "AgentForgeCreditError", { enumerable: true, get: function () { return errors_1.AgentForgeCreditError; } });
|
|
45
|
+
Object.defineProperty(exports, "AGENTFORGE_CREDIT_ERROR_CODES", { enumerable: true, get: function () { return errors_1.AGENTFORGE_CREDIT_ERROR_CODES; } });
|
|
46
|
+
var credit_1 = require("./resources/credit");
|
|
47
|
+
Object.defineProperty(exports, "CreditResource", { enumerable: true, get: function () { return credit_1.CreditResource; } });
|
|
48
|
+
Object.defineProperty(exports, "CreditAccountsResource", { enumerable: true, get: function () { return credit_1.CreditAccountsResource; } });
|
|
44
49
|
var billing_1 = require("./resources/billing");
|
|
45
50
|
Object.defineProperty(exports, "BillingResource", { enumerable: true, get: function () { return billing_1.BillingResource; } });
|
|
46
51
|
var webhooks_1 = require("./webhooks");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentForgeClient } from '../client';
|
|
2
|
-
import type { CaseClosingReport, CaseProposalAnswer, CaseProposalInput, CaseReportPage, CasePaymentStatus, CaseReceipt, CaseState, CaseView, CreateDirectBookingInput, CreateDirectOrderInput, CreateOpenOrderInput, DirectOrderForm, ListCasesInput, MoveCaseSlotInput, ProductReview, ReceiptReviewables, SaveReceiptReviewInput } from '../types';
|
|
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';
|
|
3
3
|
export declare class CasesResource {
|
|
4
4
|
private readonly client;
|
|
5
5
|
constructor(client: AgentForgeClient);
|
|
@@ -9,10 +9,16 @@ export declare class CasesResource {
|
|
|
9
9
|
* `GET /api/v1/cases/reports/closing` — AGF-CASH-REGISTER: a closing between two
|
|
10
10
|
* instants, (`from`, `to`], so consecutive closings never count a payment twice
|
|
11
11
|
* nor miss one. 400 on a bad range; at most 400 days.
|
|
12
|
+
*
|
|
13
|
+
* PDK-STORE-CREDIT — `clampToClock: true` for a caller that chains closings (stores the returned `to` and starts the
|
|
14
|
+
* next from it): when its `to` is ahead of the platform's clock the report ends at the platform's clock, `to` says so
|
|
15
|
+
* and `requestedTo` is what was asked. Without it the request and the range are exactly what they always were. 400 when
|
|
16
|
+
* `from` itself is ahead of the platform's clock. An older platform ignores the flag.
|
|
12
17
|
*/
|
|
13
18
|
closingReport(input: {
|
|
14
19
|
from: string | Date;
|
|
15
20
|
to: string | Date;
|
|
21
|
+
clampToClock?: boolean;
|
|
16
22
|
}): Promise<CaseClosingReport>;
|
|
17
23
|
/**
|
|
18
24
|
* `GET /api/v1/cases/reports/orders` — AGF-CASH-REGISTER: the cases sent between two
|
|
@@ -27,6 +33,25 @@ export declare class CasesResource {
|
|
|
27
33
|
}): Promise<CaseReportPage>;
|
|
28
34
|
/** `GET /api/v1/cases/:id` — 404 when it is not this workspace's. */
|
|
29
35
|
get(caseId: string): Promise<CaseView>;
|
|
36
|
+
/**
|
|
37
|
+
* `POST /api/v1/cases/:id/lines/confirm` — PDK-OFF-CATALOG: the business answers ONE product the customer asked for
|
|
38
|
+
* that is not in the catalog (a free line, `input.key` = `CaseView.offCatalog.lines[].key`, e.g. `off#1`): `ready` with
|
|
39
|
+
* the price of one `unit`, `swap` with another thing and its price, or `out`. While other free lines still wait, only
|
|
40
|
+
* that line changes (no notice to the customer, the receipt keeps its revision). The confirmation that leaves none
|
|
41
|
+
* pending sets the total: the receipt is re-issued (revision + 1) and the customer is told through a proposal
|
|
42
|
+
* (`CaseView.proposal`, `offCatalog: true`) whose changes are the free lines (`price`, `out`, `swap`):
|
|
43
|
+
*
|
|
44
|
+
* - `requiresAnswer: true` when a line is out or swapped, or a line's amount is over what the customer said × 1.2
|
|
45
|
+
* (`askedPriceCents`): nothing is accepted silently; the customer answers on the receipt / chat
|
|
46
|
+
* (`receiptAnswerProposal`) and payment waits for it. A dropped line leaves the order.
|
|
47
|
+
* - otherwise `autoAcceptAt` (10 minutes later): the platform keeps no timer — your App answers
|
|
48
|
+
* `answerProposal(caseId, 'all')` once it passes (or earlier, if the customer pays/taps accept).
|
|
49
|
+
*
|
|
50
|
+
* Every line out and nothing else on the order cancels it. 400 when the order is still being edited by the customer,
|
|
51
|
+
* closed or confirmed, or the input is wrong; 404 unknown line; 409 a proposal is waiting (answer or withdraw it first).
|
|
52
|
+
* Returns the updated case.
|
|
53
|
+
*/
|
|
54
|
+
confirmLine(caseId: string, input: ConfirmCaseLineInput): Promise<CaseView>;
|
|
30
55
|
/**
|
|
31
56
|
* `POST /api/v1/cases/:id/weigh` — AGF-UNITS U3: what a line sold by value
|
|
32
57
|
* («$3.000 de queso») really weighed, in the product's unit (`line` = the
|
|
@@ -55,7 +80,12 @@ export declare class CasesResource {
|
|
|
55
80
|
* the answer. Replaces a pending proposal. 400 with the reason when one cannot be made.
|
|
56
81
|
*/
|
|
57
82
|
propose(caseId: string, input: CaseProposalInput): Promise<CaseView>;
|
|
58
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* `POST /api/v1/cases/:id/proposal/withdraw` — takes the pending proposal back: the order can move again.
|
|
85
|
+
* PDK-OFF-CATALOG: withdrawing the confirmation of free lines (`proposal.offCatalog`) is «corregir» — the lines it
|
|
86
|
+
* changed go back to pending (price/mark/swap cleared), the receipt is re-issued with a null total and the business
|
|
87
|
+
* confirms them again with `confirmLine`; the lines are never left confirmed without the customer's answer.
|
|
88
|
+
*/
|
|
59
89
|
withdrawProposal(caseId: string): Promise<CaseView>;
|
|
60
90
|
/**
|
|
61
91
|
* `POST /api/v1/cases/:id/proposal/answer` — the business records the customer's answer
|
|
@@ -92,6 +122,9 @@ export declare class CasesResource {
|
|
|
92
122
|
* `POST /api/v1/cases/:id/transition` — the business moves a case:
|
|
93
123
|
* `accepted` / `rejected` from `submitted`, then the type's states,
|
|
94
124
|
* `completed` or `cancelled`. 400 (with the allowed states) otherwise.
|
|
125
|
+
* PDK-OFF-CATALOG: moving to a confirmed state (`confirmed`, ready, out for delivery, `completed`) is refused with
|
|
126
|
+
* 400 `code: 'lines_pending'` while a free line is still pending (`offCatalog.pendingCount > 0`): confirm them
|
|
127
|
+
* first. `cancelled` / `rejected` stay allowed.
|
|
95
128
|
*/
|
|
96
129
|
transition(caseId: string, state: CaseState, opts?: {
|
|
97
130
|
note?: string;
|
|
@@ -174,6 +207,22 @@ export declare class CasesResource {
|
|
|
174
207
|
amountCents?: number;
|
|
175
208
|
accountId?: string;
|
|
176
209
|
}): Promise<CaseView>;
|
|
210
|
+
/**
|
|
211
|
+
* `POST /api/v1/cases/:id/payment/on-account` — PDK-STORE-CREDIT «Dejar como fiado»: status `on_account` and the ledger
|
|
212
|
+
* charge in one transaction, optionally with a down payment. Business only, after acceptance, with a contact that has a
|
|
213
|
+
* name and a phone, and a known total > 0. A retried `idempotencyKey` returns the same result (`replayed: true`); the
|
|
214
|
+
* SDK never retries by itself and never makes up a key. Refusals throw `AgentForgeCreditError` (`err.code`):
|
|
215
|
+
* 400 `fiado_needs_contact` / `fiado_contact_mismatch` / `contact_not_in_tenant` / `contact_erased` /
|
|
216
|
+
* `fiado_needs_name_and_phone` / `fiado_needs_total` / `down_payment_covers_order` / `invalid_amount`;
|
|
217
|
+
* 409 `over_limit` / `account_blocked` / `already_on_account` / `already_charged` / `idempotency_conflict` / `account_merged`.
|
|
218
|
+
* A refusal without a code (not accepted yet, the case ended undone) stays a plain `AgentForgeError`.
|
|
219
|
+
*/
|
|
220
|
+
setOnAccount(caseId: string, input: SetOnAccountInput): Promise<SetOnAccountResult>;
|
|
221
|
+
/**
|
|
222
|
+
* `GET /api/v1/cases/:id/account` — PDK-STORE-CREDIT: what ONE order owes on the customer account (for its receipt),
|
|
223
|
+
* never the account itself. `{ onAccount: false, payments: [] }` for an order that is not on account.
|
|
224
|
+
*/
|
|
225
|
+
account(caseId: string): Promise<CaseAccount>;
|
|
177
226
|
/**
|
|
178
227
|
* `POST /api/v1/cases/:id/payment/method` — AGF-PAYMENT-METHOD-BUSINESS: the business
|
|
179
228
|
* sets or changes how the customer pays (an `accountId` of `directForm().payment.options`;
|
package/dist/resources/cases.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// business states of their type.
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.CasesResource = void 0;
|
|
8
|
+
const credit_1 = require("./credit");
|
|
8
9
|
class CasesResource {
|
|
9
10
|
constructor(client) {
|
|
10
11
|
this.client = client;
|
|
@@ -38,10 +39,17 @@ class CasesResource {
|
|
|
38
39
|
* `GET /api/v1/cases/reports/closing` — AGF-CASH-REGISTER: a closing between two
|
|
39
40
|
* instants, (`from`, `to`], so consecutive closings never count a payment twice
|
|
40
41
|
* nor miss one. 400 on a bad range; at most 400 days.
|
|
42
|
+
*
|
|
43
|
+
* PDK-STORE-CREDIT — `clampToClock: true` for a caller that chains closings (stores the returned `to` and starts the
|
|
44
|
+
* next from it): when its `to` is ahead of the platform's clock the report ends at the platform's clock, `to` says so
|
|
45
|
+
* and `requestedTo` is what was asked. Without it the request and the range are exactly what they always were. 400 when
|
|
46
|
+
* `from` itself is ahead of the platform's clock. An older platform ignores the flag.
|
|
41
47
|
*/
|
|
42
48
|
async closingReport(input) {
|
|
43
49
|
const at = (v) => (v instanceof Date ? v.toISOString() : v);
|
|
44
50
|
const qs = new URLSearchParams({ from: at(input.from), to: at(input.to) });
|
|
51
|
+
if (input.clampToClock)
|
|
52
|
+
qs.set('clampToClock', 'true');
|
|
45
53
|
return this.client.request('GET', `/api/v1/cases/reports/closing?${qs}`);
|
|
46
54
|
}
|
|
47
55
|
/**
|
|
@@ -62,6 +70,27 @@ class CasesResource {
|
|
|
62
70
|
async get(caseId) {
|
|
63
71
|
return this.client.request('GET', `/api/v1/cases/${encodeURIComponent(caseId)}`);
|
|
64
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* `POST /api/v1/cases/:id/lines/confirm` — PDK-OFF-CATALOG: the business answers ONE product the customer asked for
|
|
75
|
+
* that is not in the catalog (a free line, `input.key` = `CaseView.offCatalog.lines[].key`, e.g. `off#1`): `ready` with
|
|
76
|
+
* the price of one `unit`, `swap` with another thing and its price, or `out`. While other free lines still wait, only
|
|
77
|
+
* that line changes (no notice to the customer, the receipt keeps its revision). The confirmation that leaves none
|
|
78
|
+
* pending sets the total: the receipt is re-issued (revision + 1) and the customer is told through a proposal
|
|
79
|
+
* (`CaseView.proposal`, `offCatalog: true`) whose changes are the free lines (`price`, `out`, `swap`):
|
|
80
|
+
*
|
|
81
|
+
* - `requiresAnswer: true` when a line is out or swapped, or a line's amount is over what the customer said × 1.2
|
|
82
|
+
* (`askedPriceCents`): nothing is accepted silently; the customer answers on the receipt / chat
|
|
83
|
+
* (`receiptAnswerProposal`) and payment waits for it. A dropped line leaves the order.
|
|
84
|
+
* - otherwise `autoAcceptAt` (10 minutes later): the platform keeps no timer — your App answers
|
|
85
|
+
* `answerProposal(caseId, 'all')` once it passes (or earlier, if the customer pays/taps accept).
|
|
86
|
+
*
|
|
87
|
+
* Every line out and nothing else on the order cancels it. 400 when the order is still being edited by the customer,
|
|
88
|
+
* closed or confirmed, or the input is wrong; 404 unknown line; 409 a proposal is waiting (answer or withdraw it first).
|
|
89
|
+
* Returns the updated case.
|
|
90
|
+
*/
|
|
91
|
+
async confirmLine(caseId, input) {
|
|
92
|
+
return this.client.request('POST', `/api/v1/cases/${encodeURIComponent(caseId)}/lines/confirm`, input);
|
|
93
|
+
}
|
|
65
94
|
/**
|
|
66
95
|
* `POST /api/v1/cases/:id/weigh` — AGF-UNITS U3: what a line sold by value
|
|
67
96
|
* («$3.000 de queso») really weighed, in the product's unit (`line` = the
|
|
@@ -93,7 +122,12 @@ class CasesResource {
|
|
|
93
122
|
async propose(caseId, input) {
|
|
94
123
|
return this.client.request('POST', `/api/v1/cases/${encodeURIComponent(caseId)}/proposal`, input);
|
|
95
124
|
}
|
|
96
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
* `POST /api/v1/cases/:id/proposal/withdraw` — takes the pending proposal back: the order can move again.
|
|
127
|
+
* PDK-OFF-CATALOG: withdrawing the confirmation of free lines (`proposal.offCatalog`) is «corregir» — the lines it
|
|
128
|
+
* changed go back to pending (price/mark/swap cleared), the receipt is re-issued with a null total and the business
|
|
129
|
+
* confirms them again with `confirmLine`; the lines are never left confirmed without the customer's answer.
|
|
130
|
+
*/
|
|
97
131
|
async withdrawProposal(caseId) {
|
|
98
132
|
return this.client.request('POST', `/api/v1/cases/${encodeURIComponent(caseId)}/proposal/withdraw`, {});
|
|
99
133
|
}
|
|
@@ -142,6 +176,9 @@ class CasesResource {
|
|
|
142
176
|
* `POST /api/v1/cases/:id/transition` — the business moves a case:
|
|
143
177
|
* `accepted` / `rejected` from `submitted`, then the type's states,
|
|
144
178
|
* `completed` or `cancelled`. 400 (with the allowed states) otherwise.
|
|
179
|
+
* PDK-OFF-CATALOG: moving to a confirmed state (`confirmed`, ready, out for delivery, `completed`) is refused with
|
|
180
|
+
* 400 `code: 'lines_pending'` while a free line is still pending (`offCatalog.pendingCount > 0`): confirm them
|
|
181
|
+
* first. `cancelled` / `rejected` stay allowed.
|
|
145
182
|
*/
|
|
146
183
|
async transition(caseId, state, opts = {}) {
|
|
147
184
|
return this.client.request('POST', `/api/v1/cases/${encodeURIComponent(caseId)}/transition`, {
|
|
@@ -247,6 +284,31 @@ class CasesResource {
|
|
|
247
284
|
...(opts.accountId ? { accountId: opts.accountId } : {}),
|
|
248
285
|
});
|
|
249
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* `POST /api/v1/cases/:id/payment/on-account` — PDK-STORE-CREDIT «Dejar como fiado»: status `on_account` and the ledger
|
|
289
|
+
* charge in one transaction, optionally with a down payment. Business only, after acceptance, with a contact that has a
|
|
290
|
+
* name and a phone, and a known total > 0. A retried `idempotencyKey` returns the same result (`replayed: true`); the
|
|
291
|
+
* SDK never retries by itself and never makes up a key. Refusals throw `AgentForgeCreditError` (`err.code`):
|
|
292
|
+
* 400 `fiado_needs_contact` / `fiado_contact_mismatch` / `contact_not_in_tenant` / `contact_erased` /
|
|
293
|
+
* `fiado_needs_name_and_phone` / `fiado_needs_total` / `down_payment_covers_order` / `invalid_amount`;
|
|
294
|
+
* 409 `over_limit` / `account_blocked` / `already_on_account` / `already_charged` / `idempotency_conflict` / `account_merged`.
|
|
295
|
+
* A refusal without a code (not accepted yet, the case ended undone) stays a plain `AgentForgeError`.
|
|
296
|
+
*/
|
|
297
|
+
async setOnAccount(caseId, input) {
|
|
298
|
+
try {
|
|
299
|
+
return await this.client.request('POST', `/api/v1/cases/${encodeURIComponent(caseId)}/payment/on-account`, input);
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
throw (0, credit_1.asCreditError)(err);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* `GET /api/v1/cases/:id/account` — PDK-STORE-CREDIT: what ONE order owes on the customer account (for its receipt),
|
|
307
|
+
* never the account itself. `{ onAccount: false, payments: [] }` for an order that is not on account.
|
|
308
|
+
*/
|
|
309
|
+
async account(caseId) {
|
|
310
|
+
return this.client.request('GET', `/api/v1/cases/${encodeURIComponent(caseId)}/account`);
|
|
311
|
+
}
|
|
250
312
|
/**
|
|
251
313
|
* `POST /api/v1/cases/:id/payment/method` — AGF-PAYMENT-METHOD-BUSINESS: the business
|
|
252
314
|
* sets or changes how the customer pays (an `accountId` of `directForm().payment.options`;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { AgentForgeClient } from '../client';
|
|
2
|
+
/** A credit-coded failure becomes the typed error; anything else (auth, network, an uncoded 404) is rethrown as is. */
|
|
3
|
+
export declare function asCreditError(err: unknown): unknown;
|
|
4
|
+
export type CreditEntryKind = 'charge' | 'payment' | 'charge_adjust' | 'charge_reversal' | 'opening' | 'write_off' | 'payment_reversal' | 'payout' | 'transfer';
|
|
5
|
+
export type CreditAgingBucket = 'current' | 'd1_30' | 'd31_60' | 'd61_plus';
|
|
6
|
+
export type CreditAccountStatus = 'active' | 'blocked' | 'merged';
|
|
7
|
+
export interface CreditEntry {
|
|
8
|
+
id: string;
|
|
9
|
+
seq: number;
|
|
10
|
+
accountId: string;
|
|
11
|
+
kind: CreditEntryKind;
|
|
12
|
+
/** + the customer owes more, − owes less. */
|
|
13
|
+
deltaCents: number;
|
|
14
|
+
caseId: string | null;
|
|
15
|
+
/** The order's short code as the business names it (absent on an older platform; only in the statement). */
|
|
16
|
+
caseCode?: string | null;
|
|
17
|
+
method: string | null;
|
|
18
|
+
paymentSnapshot: Record<string, unknown> | null;
|
|
19
|
+
reference: string | null;
|
|
20
|
+
note: string | null;
|
|
21
|
+
dueOn: string | null;
|
|
22
|
+
reversesId: string | null;
|
|
23
|
+
chargeId: string | null;
|
|
24
|
+
groupId: string | null;
|
|
25
|
+
sourceAt: string | null;
|
|
26
|
+
actor: string | null;
|
|
27
|
+
/** Server instant, ISO-8601 UTC with microseconds. */
|
|
28
|
+
occurredAt: string;
|
|
29
|
+
idempotencyKey: string;
|
|
30
|
+
}
|
|
31
|
+
export interface CreditAllocation {
|
|
32
|
+
id: string;
|
|
33
|
+
accountId: string;
|
|
34
|
+
sourceEntryId: string;
|
|
35
|
+
targetEntryId: string;
|
|
36
|
+
/** Signed: a reversal inserts negatives. */
|
|
37
|
+
cents: number;
|
|
38
|
+
causeEntryId: string;
|
|
39
|
+
}
|
|
40
|
+
export interface CreditDebt {
|
|
41
|
+
entryId: string;
|
|
42
|
+
kind: CreditEntryKind;
|
|
43
|
+
caseId: string | null;
|
|
44
|
+
/** The order's short code as the business names it (absent on an older platform). */
|
|
45
|
+
caseCode?: string | null;
|
|
46
|
+
totalCents: number;
|
|
47
|
+
outstandingCents: number;
|
|
48
|
+
dueOn: string | null;
|
|
49
|
+
chargedAt: string;
|
|
50
|
+
daysOverdue: number;
|
|
51
|
+
bucket: CreditAgingBucket;
|
|
52
|
+
}
|
|
53
|
+
export interface CreditAccount {
|
|
54
|
+
/** Null for a contact that never had an account (everything 0). */
|
|
55
|
+
accountId: string | null;
|
|
56
|
+
contactId: string;
|
|
57
|
+
status: CreditAccountStatus;
|
|
58
|
+
currency: string;
|
|
59
|
+
limitCents: number | null;
|
|
60
|
+
balanceCents: number;
|
|
61
|
+
owingCents: number;
|
|
62
|
+
/** Balance in the customer's favour (a reversal after paying): can be applied or paid out. */
|
|
63
|
+
creditCents: number;
|
|
64
|
+
debts: CreditDebt[];
|
|
65
|
+
}
|
|
66
|
+
/** What every write returns; a replay returns the SAME content with `replayed: true`. */
|
|
67
|
+
export interface CreditWriteResult {
|
|
68
|
+
replayed: boolean;
|
|
69
|
+
entries: CreditEntry[];
|
|
70
|
+
allocations: CreditAllocation[];
|
|
71
|
+
balanceCents: number;
|
|
72
|
+
accountId: string;
|
|
73
|
+
}
|
|
74
|
+
export interface CreditStatementRow extends CreditEntry {
|
|
75
|
+
/** The account's balance AFTER this row. */
|
|
76
|
+
runningBalanceCents: number;
|
|
77
|
+
}
|
|
78
|
+
export interface CreditAccountListRow {
|
|
79
|
+
accountId: string;
|
|
80
|
+
contactId: string;
|
|
81
|
+
displayName: string | null;
|
|
82
|
+
phone: string | null;
|
|
83
|
+
status: CreditAccountStatus;
|
|
84
|
+
balanceCents: number;
|
|
85
|
+
limitCents: number | null;
|
|
86
|
+
oldestOverdueDays: number;
|
|
87
|
+
aging: Record<CreditAgingBucket, number>;
|
|
88
|
+
}
|
|
89
|
+
export interface CreditAccountsQuery {
|
|
90
|
+
/** Default true: only accounts that owe. `false` lists all. */
|
|
91
|
+
owing?: boolean;
|
|
92
|
+
/** Only those with a debt past its due date. */
|
|
93
|
+
overdue?: boolean;
|
|
94
|
+
/** Matches the contact's name or phone. */
|
|
95
|
+
q?: string;
|
|
96
|
+
cursor?: string;
|
|
97
|
+
/** 1–100, default 50. */
|
|
98
|
+
limit?: number;
|
|
99
|
+
}
|
|
100
|
+
export interface CreditAccountsPage {
|
|
101
|
+
rows: CreditAccountListRow[];
|
|
102
|
+
nextCursor: string | null;
|
|
103
|
+
}
|
|
104
|
+
export interface CreditStatementQuery {
|
|
105
|
+
/** 1–200, default 50. */
|
|
106
|
+
limit?: number;
|
|
107
|
+
/** Pages backwards: pass the previous page's `nextBeforeSeq`. */
|
|
108
|
+
beforeSeq?: number;
|
|
109
|
+
}
|
|
110
|
+
export interface CreditStatement {
|
|
111
|
+
/** Newest first. */
|
|
112
|
+
rows: CreditStatementRow[];
|
|
113
|
+
nextBeforeSeq: number | null;
|
|
114
|
+
allocations: CreditAllocation[];
|
|
115
|
+
}
|
|
116
|
+
export interface UpdateCreditAccountInput {
|
|
117
|
+
status?: 'active' | 'blocked';
|
|
118
|
+
/** Whole cents, or `null` for no limit. */
|
|
119
|
+
limitCents?: number | null;
|
|
120
|
+
}
|
|
121
|
+
/** Fields every write takes. */
|
|
122
|
+
interface CreditWriteBase {
|
|
123
|
+
/** 8–100 of `A-Za-z0-9_.:-`. Chosen and kept by the caller. */
|
|
124
|
+
idempotencyKey: string;
|
|
125
|
+
/** Who did it, as the App names them (at most 120). */
|
|
126
|
+
actor?: string;
|
|
127
|
+
}
|
|
128
|
+
/** Which debts a payment or write-off is applied to; none = oldest debt first. */
|
|
129
|
+
interface CreditTargets {
|
|
130
|
+
/** `CreditDebt.entryId`s (at most 50). */
|
|
131
|
+
chargeEntryIds?: string[];
|
|
132
|
+
/** Order ids (at most 50). */
|
|
133
|
+
caseIds?: string[];
|
|
134
|
+
}
|
|
135
|
+
export interface CreditPayInput extends CreditWriteBase, CreditTargets {
|
|
136
|
+
/** Whole cents > 0. Refused above what the picked debts owe (`overpayment`). */
|
|
137
|
+
amountCents: number;
|
|
138
|
+
/** A key of the business's payment catalog (`efectivo`, `nequi`…). */
|
|
139
|
+
method: string;
|
|
140
|
+
/** At most 120. */
|
|
141
|
+
reference?: string;
|
|
142
|
+
/** At most 500. */
|
|
143
|
+
note?: string;
|
|
144
|
+
}
|
|
145
|
+
export interface CreditReversePaymentInput extends CreditWriteBase {
|
|
146
|
+
note?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface CreditWriteOffInput extends CreditWriteBase, CreditTargets {
|
|
149
|
+
amountCents: number;
|
|
150
|
+
/** The reason (required, at most 500). */
|
|
151
|
+
note: string;
|
|
152
|
+
}
|
|
153
|
+
export interface CreditOpeningInput extends CreditWriteBase {
|
|
154
|
+
amountCents: number;
|
|
155
|
+
/** `YYYY-MM-DD`. */
|
|
156
|
+
dueOn?: string;
|
|
157
|
+
note?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface CreditPayoutInput extends CreditWriteBase {
|
|
160
|
+
amountCents: number;
|
|
161
|
+
/** The method the money goes out by (catalog key). */
|
|
162
|
+
method: string;
|
|
163
|
+
reference?: string;
|
|
164
|
+
note?: string;
|
|
165
|
+
}
|
|
166
|
+
export declare class CreditAccountsResource {
|
|
167
|
+
private readonly call;
|
|
168
|
+
constructor(call: <T>(method: string, path: string, body?: unknown) => Promise<T>);
|
|
169
|
+
/** `GET /api/v1/credit/accounts` — most owed first, keyset-paged. */
|
|
170
|
+
list(input?: CreditAccountsQuery): Promise<CreditAccountsPage>;
|
|
171
|
+
/** `GET /api/v1/credit/accounts/:contactId` — balance, what is owed per order, credit in favour. 404 `contact_not_found`. */
|
|
172
|
+
get(contactId: string): Promise<CreditAccount>;
|
|
173
|
+
/** `PATCH /api/v1/credit/accounts/:contactId` — block / unblock and set the limit. Returns the account. */
|
|
174
|
+
update(contactId: string, input: UpdateCreditAccountInput): Promise<CreditAccount>;
|
|
175
|
+
/** `GET /api/v1/credit/accounts/:contactId/entries` — the statement, newest first, with the running balance. */
|
|
176
|
+
entries(contactId: string, input?: CreditStatementQuery): Promise<CreditStatement>;
|
|
177
|
+
}
|
|
178
|
+
export declare class CreditResource {
|
|
179
|
+
private readonly client;
|
|
180
|
+
readonly accounts: CreditAccountsResource;
|
|
181
|
+
constructor(client: AgentForgeClient);
|
|
182
|
+
private call;
|
|
183
|
+
/**
|
|
184
|
+
* `POST /api/v1/credit/accounts/:contactId/payments` — an abono. Oldest debt first unless `chargeEntryIds` / `caseIds`
|
|
185
|
+
* pick. The orders it covers become `paid` (`settledBy: 'account'`) in the same transaction. 400 `overpayment`,
|
|
186
|
+
* `nothing_owed`, `invalid_amount`; 409 `idempotency_conflict`. A blocked account still takes abonos (blocked = no new
|
|
187
|
+
* charges). An unknown `method` is a 400 without a code (plain `AgentForgeError`).
|
|
188
|
+
*/
|
|
189
|
+
pay(contactId: string, input: CreditPayInput): Promise<CreditWriteResult>;
|
|
190
|
+
/**
|
|
191
|
+
* `POST /api/v1/credit/accounts/:contactId/payments/:entryId/reverse` — an abono typed wrong, undone today. The orders it
|
|
192
|
+
* had covered go back on account. 409 `already_reversed`, `payment_spent`; 400 `wrong_kind`.
|
|
193
|
+
*/
|
|
194
|
+
reversePayment(contactId: string, paymentEntryId: string, input: CreditReversePaymentInput): Promise<CreditWriteResult>;
|
|
195
|
+
/**
|
|
196
|
+
* `POST /api/v1/credit/accounts/:contactId/write-offs` — debt given up (`note` = the reason). A written-off order stays
|
|
197
|
+
* `on_account`, never `paid`.
|
|
198
|
+
*/
|
|
199
|
+
writeOff(contactId: string, input: CreditWriteOffInput): Promise<CreditWriteResult>;
|
|
200
|
+
/** `POST /api/v1/credit/accounts/:contactId/openings` — debt carried over from the paper notebook. */
|
|
201
|
+
opening(contactId: string, input: CreditOpeningInput): Promise<CreditWriteResult>;
|
|
202
|
+
/** `POST /api/v1/credit/accounts/:contactId/payouts` — credit in the customer's favour handed back (money out). 400 `exceeds_credit`. */
|
|
203
|
+
payout(contactId: string, input: CreditPayoutInput): Promise<CreditWriteResult>;
|
|
204
|
+
}
|
|
205
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// credit resource (PDK-STORE-CREDIT S3) — the business's customer accounts («fiado»): one append-only ledger per
|
|
3
|
+
// contact. App secret (`sk_`) or tenant-wide `ak_` key; on an installed tenant call it through `af.forTenant(tenantId)`.
|
|
4
|
+
//
|
|
5
|
+
// - `accounts.list / get / update / entries` — who owes what, a statement, block / limit.
|
|
6
|
+
// - `pay` (abono) · `reversePayment` (an abono typed wrong, undone the same day) · `writeOff` (debt given up) ·
|
|
7
|
+
// `opening` (the paper notebook's old debt) · `payout` (credit in the customer's favour handed back).
|
|
8
|
+
// - A charge is NEVER created here: it follows an order (`cases.setOnAccount`), and a revision or cancelling it adjusts
|
|
9
|
+
// or reverses it.
|
|
10
|
+
//
|
|
11
|
+
// The platform does not know WHO may grant, reverse or write off: the host App decides before it calls.
|
|
12
|
+
//
|
|
13
|
+
// Every write needs an `idempotencyKey` (8–100 of `A-Za-z0-9_.:-`) that the CALLER chooses and keeps: the same key with the
|
|
14
|
+
// same request returns the same result with `replayed: true`; with a different request it is refused (`idempotency_conflict`).
|
|
15
|
+
// This SDK never retries a request and never invents a key — on a timeout or a network error, repeat the call with the
|
|
16
|
+
// SAME key. Money is whole cents. Refusals throw `AgentForgeCreditError` (`err.code`, `err.status`).
|
|
17
|
+
//
|
|
18
|
+
// Needs the platform change PDK-STORE-CREDIT S2; an older platform answers 404.
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.CreditResource = exports.CreditAccountsResource = void 0;
|
|
21
|
+
exports.asCreditError = asCreditError;
|
|
22
|
+
const errors_1 = require("../errors");
|
|
23
|
+
const CODES = new Set(errors_1.AGENTFORGE_CREDIT_ERROR_CODES);
|
|
24
|
+
/** A credit-coded failure becomes the typed error; anything else (auth, network, an uncoded 404) is rethrown as is. */
|
|
25
|
+
function asCreditError(err) {
|
|
26
|
+
if (err instanceof errors_1.AgentForgeError && err.code && CODES.has(err.code) && err.status !== 401 && err.status !== 403) {
|
|
27
|
+
let message = err.message;
|
|
28
|
+
if (err.body) {
|
|
29
|
+
try {
|
|
30
|
+
const b = JSON.parse(err.body);
|
|
31
|
+
if (typeof b.message === 'string')
|
|
32
|
+
message = b.message;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
/* keep the status message */
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return new errors_1.AgentForgeCreditError(err.status, err.code, message, err.body);
|
|
39
|
+
}
|
|
40
|
+
return err;
|
|
41
|
+
}
|
|
42
|
+
const BASE = '/api/v1/credit';
|
|
43
|
+
const acct = (contactId) => `${BASE}/accounts/${encodeURIComponent(contactId)}`;
|
|
44
|
+
class CreditAccountsResource {
|
|
45
|
+
constructor(call) {
|
|
46
|
+
this.call = call;
|
|
47
|
+
}
|
|
48
|
+
/** `GET /api/v1/credit/accounts` — most owed first, keyset-paged. */
|
|
49
|
+
async list(input = {}) {
|
|
50
|
+
const qs = new URLSearchParams();
|
|
51
|
+
if (input.owing === false)
|
|
52
|
+
qs.set('owing', 'false');
|
|
53
|
+
if (input.overdue)
|
|
54
|
+
qs.set('overdue', 'true');
|
|
55
|
+
if (input.q)
|
|
56
|
+
qs.set('q', input.q);
|
|
57
|
+
if (input.cursor)
|
|
58
|
+
qs.set('cursor', input.cursor);
|
|
59
|
+
if (input.limit !== undefined)
|
|
60
|
+
qs.set('limit', String(input.limit));
|
|
61
|
+
const q = qs.toString();
|
|
62
|
+
return this.call('GET', `${BASE}/accounts${q ? `?${q}` : ''}`);
|
|
63
|
+
}
|
|
64
|
+
/** `GET /api/v1/credit/accounts/:contactId` — balance, what is owed per order, credit in favour. 404 `contact_not_found`. */
|
|
65
|
+
async get(contactId) {
|
|
66
|
+
return this.call('GET', acct(contactId));
|
|
67
|
+
}
|
|
68
|
+
/** `PATCH /api/v1/credit/accounts/:contactId` — block / unblock and set the limit. Returns the account. */
|
|
69
|
+
async update(contactId, input) {
|
|
70
|
+
return this.call('PATCH', acct(contactId), {
|
|
71
|
+
...(input.status !== undefined ? { status: input.status } : {}),
|
|
72
|
+
...(input.limitCents !== undefined ? { limitCents: input.limitCents } : {}),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** `GET /api/v1/credit/accounts/:contactId/entries` — the statement, newest first, with the running balance. */
|
|
76
|
+
async entries(contactId, input = {}) {
|
|
77
|
+
const qs = new URLSearchParams();
|
|
78
|
+
if (input.limit !== undefined)
|
|
79
|
+
qs.set('limit', String(input.limit));
|
|
80
|
+
if (input.beforeSeq !== undefined)
|
|
81
|
+
qs.set('beforeSeq', String(input.beforeSeq));
|
|
82
|
+
const q = qs.toString();
|
|
83
|
+
return this.call('GET', `${acct(contactId)}/entries${q ? `?${q}` : ''}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.CreditAccountsResource = CreditAccountsResource;
|
|
87
|
+
class CreditResource {
|
|
88
|
+
constructor(client) {
|
|
89
|
+
this.client = client;
|
|
90
|
+
this.accounts = new CreditAccountsResource((m, p, b) => this.call(m, p, b));
|
|
91
|
+
}
|
|
92
|
+
async call(method, path, body) {
|
|
93
|
+
try {
|
|
94
|
+
return await this.client.request(method, path, body);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
throw asCreditError(err);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* `POST /api/v1/credit/accounts/:contactId/payments` — an abono. Oldest debt first unless `chargeEntryIds` / `caseIds`
|
|
102
|
+
* pick. The orders it covers become `paid` (`settledBy: 'account'`) in the same transaction. 400 `overpayment`,
|
|
103
|
+
* `nothing_owed`, `invalid_amount`; 409 `idempotency_conflict`. A blocked account still takes abonos (blocked = no new
|
|
104
|
+
* charges). An unknown `method` is a 400 without a code (plain `AgentForgeError`).
|
|
105
|
+
*/
|
|
106
|
+
async pay(contactId, input) {
|
|
107
|
+
return this.call('POST', `${acct(contactId)}/payments`, {
|
|
108
|
+
amountCents: input.amountCents,
|
|
109
|
+
method: input.method,
|
|
110
|
+
idempotencyKey: input.idempotencyKey,
|
|
111
|
+
reference: input.reference,
|
|
112
|
+
note: input.note,
|
|
113
|
+
actor: input.actor,
|
|
114
|
+
chargeEntryIds: input.chargeEntryIds,
|
|
115
|
+
caseIds: input.caseIds,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* `POST /api/v1/credit/accounts/:contactId/payments/:entryId/reverse` — an abono typed wrong, undone today. The orders it
|
|
120
|
+
* had covered go back on account. 409 `already_reversed`, `payment_spent`; 400 `wrong_kind`.
|
|
121
|
+
*/
|
|
122
|
+
async reversePayment(contactId, paymentEntryId, input) {
|
|
123
|
+
return this.call('POST', `${acct(contactId)}/payments/${encodeURIComponent(paymentEntryId)}/reverse`, {
|
|
124
|
+
idempotencyKey: input.idempotencyKey,
|
|
125
|
+
note: input.note,
|
|
126
|
+
actor: input.actor,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* `POST /api/v1/credit/accounts/:contactId/write-offs` — debt given up (`note` = the reason). A written-off order stays
|
|
131
|
+
* `on_account`, never `paid`.
|
|
132
|
+
*/
|
|
133
|
+
async writeOff(contactId, input) {
|
|
134
|
+
return this.call('POST', `${acct(contactId)}/write-offs`, {
|
|
135
|
+
amountCents: input.amountCents,
|
|
136
|
+
note: input.note,
|
|
137
|
+
idempotencyKey: input.idempotencyKey,
|
|
138
|
+
actor: input.actor,
|
|
139
|
+
chargeEntryIds: input.chargeEntryIds,
|
|
140
|
+
caseIds: input.caseIds,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/** `POST /api/v1/credit/accounts/:contactId/openings` — debt carried over from the paper notebook. */
|
|
144
|
+
async opening(contactId, input) {
|
|
145
|
+
return this.call('POST', `${acct(contactId)}/openings`, {
|
|
146
|
+
amountCents: input.amountCents,
|
|
147
|
+
idempotencyKey: input.idempotencyKey,
|
|
148
|
+
dueOn: input.dueOn,
|
|
149
|
+
note: input.note,
|
|
150
|
+
actor: input.actor,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** `POST /api/v1/credit/accounts/:contactId/payouts` — credit in the customer's favour handed back (money out). 400 `exceeds_credit`. */
|
|
154
|
+
async payout(contactId, input) {
|
|
155
|
+
return this.call('POST', `${acct(contactId)}/payouts`, {
|
|
156
|
+
amountCents: input.amountCents,
|
|
157
|
+
method: input.method,
|
|
158
|
+
idempotencyKey: input.idempotencyKey,
|
|
159
|
+
reference: input.reference,
|
|
160
|
+
note: input.note,
|
|
161
|
+
actor: input.actor,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.CreditResource = CreditResource;
|
package/dist/types.d.ts
CHANGED
|
@@ -727,6 +727,11 @@ export interface TeamSummary {
|
|
|
727
727
|
orchestrationMode: 'flat' | 'hierarchical';
|
|
728
728
|
/** AGF-CASES. What customers come for in the team's conversations. */
|
|
729
729
|
caseTypes?: CaseType[];
|
|
730
|
+
/** PDK-OFF-CATALOG — whether this business's assistant may add products that are not in the catalog to an order (`case_add_free_line`). Absent: no. */
|
|
731
|
+
offCatalog?: {
|
|
732
|
+
enabled: boolean;
|
|
733
|
+
maxLines: number;
|
|
734
|
+
};
|
|
730
735
|
[field: string]: unknown;
|
|
731
736
|
}
|
|
732
737
|
/** `PATCH /api/v1/teams/:id` body — only the fields sent change. */
|
|
@@ -758,6 +763,16 @@ export interface UpdateTeamInput {
|
|
|
758
763
|
* assistants open, fill and submit cases of these types. Validated by the
|
|
759
764
|
* platform; `null` or `[]` clears them (no cases). */
|
|
760
765
|
caseTypes?: CaseType[] | null;
|
|
766
|
+
/**
|
|
767
|
+
* PDK-OFF-CATALOG — the App's opt-in for this business: may its assistant add products that are not in the
|
|
768
|
+
* catalog to an order («comodín» lines)? `{ enabled: true, maxLines? }` (maxLines 1–50, default 15) turns on the
|
|
769
|
+
* `case_add_free_line` tool for the team's assistants; `{ enabled: false }` or `null` turns it off (the default).
|
|
770
|
+
* Orders already holding free lines keep them. A bad value is a 400.
|
|
771
|
+
*/
|
|
772
|
+
offCatalog?: {
|
|
773
|
+
enabled: boolean;
|
|
774
|
+
maxLines?: number;
|
|
775
|
+
} | null;
|
|
761
776
|
}
|
|
762
777
|
/** A team's weekly opening hours (AGF-HOURS). */
|
|
763
778
|
export interface TeamBusinessHours {
|
|
@@ -2506,7 +2521,16 @@ export interface CaseView {
|
|
|
2506
2521
|
revision: number;
|
|
2507
2522
|
/** PDK-BUG-006 — every product line of the receipt is to go (`takeaway`). Absent/false on mixed or eat-here orders, older receipts and older platforms. */
|
|
2508
2523
|
allTakeaway?: boolean;
|
|
2524
|
+
/** The receipt's total (null: a line is pending or has no fixed price). */
|
|
2525
|
+
totalCents?: number | null;
|
|
2526
|
+
currency?: string | null;
|
|
2527
|
+
/** PDK-OFF-CATALOG — the lines that already have a price added up (delivery not included); present only on an order with free lines (absent on an older platform). */
|
|
2528
|
+
confirmedSubtotalCents?: number;
|
|
2529
|
+
/** PDK-OFF-CATALOG — how many free lines still wait for the business; the total is null while it is above 0. */
|
|
2530
|
+
pendingLines?: number;
|
|
2509
2531
|
} | null;
|
|
2532
|
+
/** 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. */
|
|
2533
|
+
offCatalog?: CaseOffCatalogView | null;
|
|
2510
2534
|
/** What the customer asked after the business took the case (change, cancel), until the business moves it. */
|
|
2511
2535
|
customerRequest: {
|
|
2512
2536
|
kind: 'change' | 'cancel';
|
|
@@ -2537,13 +2561,79 @@ export interface CaseView {
|
|
|
2537
2561
|
*/
|
|
2538
2562
|
history?: CaseStateStep[];
|
|
2539
2563
|
}
|
|
2564
|
+
/**
|
|
2565
|
+
* PDK-OFF-CATALOG — one product the customer asked for by name that is not in the catalog. It is `pending` until the
|
|
2566
|
+
* business confirms it (`cases.confirmLine`): then it has a price and unit, or it is `out`, or `swap`ped.
|
|
2567
|
+
*/
|
|
2568
|
+
export interface CaseOffCatalogLine {
|
|
2569
|
+
/** The receipt line's key (`off#1`, `off#2`…): what `cases.confirmLine` names. */
|
|
2570
|
+
key: string;
|
|
2571
|
+
title: string;
|
|
2572
|
+
qty: number;
|
|
2573
|
+
unit?: string;
|
|
2574
|
+
note?: string;
|
|
2575
|
+
/** What the CUSTOMER said the whole line costs (cents) — never a price the assistant set. */
|
|
2576
|
+
askedPriceCents?: number;
|
|
2577
|
+
by: 'assistant' | 'checkout';
|
|
2578
|
+
addedAt: string;
|
|
2579
|
+
pending: boolean;
|
|
2580
|
+
mark?: 'ready' | 'out' | 'swap';
|
|
2581
|
+
/** Price of one `unit`, set by the business. */
|
|
2582
|
+
unitPriceCents?: number;
|
|
2583
|
+
swapText?: string;
|
|
2584
|
+
/** The catalog product this line became (set by the business), when it has been linked. */
|
|
2585
|
+
productId?: string;
|
|
2586
|
+
/** A strong catalog match found when the assistant added it. */
|
|
2587
|
+
suggestedProductId?: string;
|
|
2588
|
+
confirmedBy?: string;
|
|
2589
|
+
confirmedAt?: string;
|
|
2590
|
+
}
|
|
2591
|
+
/** PDK-OFF-CATALOG — the free lines of an order as `CaseView.offCatalog` reads them. */
|
|
2592
|
+
export interface CaseOffCatalogView {
|
|
2593
|
+
maxLines: number;
|
|
2594
|
+
/** Free lines still waiting for the business; the order's total is null while it is above 0. */
|
|
2595
|
+
pendingCount: number;
|
|
2596
|
+
/** Every free line the customer did not drop. */
|
|
2597
|
+
lines: CaseOffCatalogLine[];
|
|
2598
|
+
}
|
|
2599
|
+
/** PDK-OFF-CATALOG — what `cases.confirmLine` sends: the business answers ONE free line. */
|
|
2600
|
+
export interface ConfirmCaseLineInput {
|
|
2601
|
+
/** The free line's key (`CaseOffCatalogLine.key`, e.g. `off#1`). */
|
|
2602
|
+
key: string;
|
|
2603
|
+
/** `ready`: it has it, at `unitPriceCents`; `swap`: it delivers `swapText` instead, at `unitPriceCents`; `out`: it does not have it. */
|
|
2604
|
+
mark: 'ready' | 'out' | 'swap';
|
|
2605
|
+
/** Price of ONE `unit`, whole cents, 0..1e9. Required for `ready` and `swap`; refused for `out`. */
|
|
2606
|
+
unitPriceCents?: number;
|
|
2607
|
+
/** What `qty` and `unitPriceCents` are in («lb», «unidad»); default: the unit the customer used. <= 20 chars. */
|
|
2608
|
+
unit?: string;
|
|
2609
|
+
/** Required with `swap` (<= 120 chars), refused otherwise. */
|
|
2610
|
+
swapText?: string;
|
|
2611
|
+
/** The catalog product this line is, when the business already added it to its inventory (an active product of this business). */
|
|
2612
|
+
productId?: string;
|
|
2613
|
+
/** Who of the business confirmed it (a member reference or name); default `business`. */
|
|
2614
|
+
confirmedBy?: string;
|
|
2615
|
+
}
|
|
2616
|
+
/** PDK-OFF-CATALOG — one free line of `CreateDirectOrderInput.offCatalogLines`. */
|
|
2617
|
+
export interface CreateOffCatalogLineInput {
|
|
2618
|
+
title: string;
|
|
2619
|
+
/** > 0, at most 3 decimals, <= 100000. */
|
|
2620
|
+
qty: number;
|
|
2621
|
+
unit?: string;
|
|
2622
|
+
note?: string;
|
|
2623
|
+
/** What the customer says the whole line costs (cents): the business sees it when it confirms the price. */
|
|
2624
|
+
askedPriceCents?: number;
|
|
2625
|
+
/** A counter sale's «producto sin registrar»: the line is created already confirmed at this price of one `unit` (cents). Without it the line is «por confirmar». */
|
|
2626
|
+
unitPriceCents?: number;
|
|
2627
|
+
}
|
|
2540
2628
|
/**
|
|
2541
2629
|
* The payment's own lifecycle, apart from the case's states: `unpaid` →
|
|
2542
2630
|
* `awaiting_payment` (method chosen) → `pending_confirmation` (the customer
|
|
2543
2631
|
* reported it) → `paid` | `rejected`; then `refunded`, `partially_refunded`,
|
|
2544
2632
|
* `reversed`; `voided` when the order ended unpaid. Completing never marks it paid.
|
|
2545
2633
|
*/
|
|
2546
|
-
export type CasePaymentStatus = 'unpaid' | 'awaiting_payment' | 'pending_confirmation' | 'paid' | 'rejected' | 'refunded' | 'partially_refunded' | 'reversed' | 'voided'
|
|
2634
|
+
export type CasePaymentStatus = 'unpaid' | 'awaiting_payment' | 'pending_confirmation' | 'paid' | 'rejected' | 'refunded' | 'partially_refunded' | 'reversed' | 'voided'
|
|
2635
|
+
/** PDK-STORE-CREDIT — «Fiado»: left on the customer's account (`cases.setOnAccount`). Neither to collect nor payable by chat. Absent on an older platform. */
|
|
2636
|
+
| 'on_account';
|
|
2547
2637
|
/** The account the customer chose, as it was then (a later edit never rewrites a sale). */
|
|
2548
2638
|
export interface CasePaymentAccount {
|
|
2549
2639
|
id: string;
|
|
@@ -2589,12 +2679,18 @@ export interface CasePayment {
|
|
|
2589
2679
|
chosenAt?: 'checkout' | 'chat' | 'receipt';
|
|
2590
2680
|
/** The order ended undone after the customer reported (or the business confirmed) the payment: check it and refund. */
|
|
2591
2681
|
refundDue?: boolean;
|
|
2682
|
+
/**
|
|
2683
|
+
* PDK-STORE-CREDIT — `paid` because the customer account's abonos covered the order's fiado (money counted abono by
|
|
2684
|
+
* abono, never on the order). Absent otherwise and on an older platform; cleared when it goes back on account.
|
|
2685
|
+
*/
|
|
2686
|
+
settledBy?: 'account';
|
|
2592
2687
|
history: Array<{
|
|
2593
2688
|
status: CasePaymentStatus;
|
|
2594
2689
|
by: 'assistant' | 'customer' | 'business' | 'system';
|
|
2595
2690
|
at: string;
|
|
2596
2691
|
note?: string;
|
|
2597
2692
|
amountCents?: number;
|
|
2693
|
+
settledBy?: 'account';
|
|
2598
2694
|
}>;
|
|
2599
2695
|
}
|
|
2600
2696
|
/** The payment as a receipt's public link shows it (no proof image, only that one was sent). */
|
|
@@ -2667,6 +2763,17 @@ export interface CaseReceiptLine {
|
|
|
2667
2763
|
out?: true;
|
|
2668
2764
|
swapText?: string;
|
|
2669
2765
|
note?: string;
|
|
2766
|
+
/**
|
|
2767
|
+
* PDK-OFF-CATALOG — a «comodín» line: asked for by name, not in the catalog (no `productId` until the business
|
|
2768
|
+
* links one). `pending`: the business has not confirmed its price or availability (`unitCents` is null and the
|
|
2769
|
+
* receipt's `totalCents` stays null: show «por confirmar»). `askedPriceCents`: what the customer said the whole line
|
|
2770
|
+
* costs. `confirmedBy` / `confirmedAt`: who of the business set its price, and when. Absent on an older platform.
|
|
2771
|
+
*/
|
|
2772
|
+
offCatalog?: true;
|
|
2773
|
+
pending?: true;
|
|
2774
|
+
askedPriceCents?: number;
|
|
2775
|
+
confirmedBy?: string;
|
|
2776
|
+
confirmedAt?: string;
|
|
2670
2777
|
}
|
|
2671
2778
|
/** One option group's choice on a proposed alternative: the group and what was picked in it (ids, or names). */
|
|
2672
2779
|
export interface CaseProposalSwapOption {
|
|
@@ -2681,8 +2788,14 @@ export interface CaseProposalChange {
|
|
|
2681
2788
|
qty: number;
|
|
2682
2789
|
/** What the line costs now; null when it has no fixed price. */
|
|
2683
2790
|
amountCents: number | null;
|
|
2684
|
-
|
|
2791
|
+
/** `price` (PDK-OFF-CATALOG): the business confirmed the price of a free line (`newAmountCents`). */
|
|
2792
|
+
kind: 'out' | 'swap' | 'price';
|
|
2793
|
+
/** PDK-OFF-CATALOG — what a confirmed free line costs (`price`). */
|
|
2794
|
+
newAmountCents?: number;
|
|
2795
|
+
/** PDK-OFF-CATALOG — what the customer said the whole line costs. */
|
|
2796
|
+
askedAmountCents?: number;
|
|
2685
2797
|
swap?: {
|
|
2798
|
+
/** '' for a free line's alternative (`free: true`): it is text, not a catalog product, unless the business linked one. */
|
|
2686
2799
|
productId: string;
|
|
2687
2800
|
title: string;
|
|
2688
2801
|
/** One unit, in cents; null when its price is not fixed. */
|
|
@@ -2695,6 +2808,8 @@ export interface CaseProposalChange {
|
|
|
2695
2808
|
options?: CaseProposalSwapOption[];
|
|
2696
2809
|
/** The choice as the customer reads it («Arroz, Sin cebolla»). */
|
|
2697
2810
|
optionsLabel?: string;
|
|
2811
|
+
/** PDK-OFF-CATALOG — the alternative of a free line: text (`title`), not a catalog product. */
|
|
2812
|
+
free?: true;
|
|
2698
2813
|
};
|
|
2699
2814
|
/** The answer to an alternative (an out-of-stock line is always `drop`); absent while pending. */
|
|
2700
2815
|
answer?: 'keep' | 'drop';
|
|
@@ -2718,6 +2833,15 @@ export interface CaseProposal {
|
|
|
2718
2833
|
/** The total if every alternative is kept (once answered: with what was kept); null when it cannot be said. */
|
|
2719
2834
|
totalAfterCents: number | null;
|
|
2720
2835
|
currency: string | null;
|
|
2836
|
+
/** PDK-OFF-CATALOG — made by the business confirming free lines (`cases.confirmLine`), not proposed by hand. */
|
|
2837
|
+
offCatalog?: true;
|
|
2838
|
+
/** 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. */
|
|
2839
|
+
requiresAnswer?: boolean;
|
|
2840
|
+
/**
|
|
2841
|
+
* PDK-OFF-CATALOG — without `requiresAnswer`: silence accepts the confirmation from this instant (ISO, 10 minutes after
|
|
2842
|
+
* it was sent). The platform does not run a timer: the host App answers `cases.answerProposal(id, 'all')` when it passes.
|
|
2843
|
+
*/
|
|
2844
|
+
autoAcceptAt?: string;
|
|
2721
2845
|
}
|
|
2722
2846
|
/** What `cases.propose` sends: each change names a receipt line by its `key`. */
|
|
2723
2847
|
export interface CaseProposalInput {
|
|
@@ -2768,6 +2892,10 @@ export interface CaseReceipt {
|
|
|
2768
2892
|
/** PDK-ORDER-INVITE — an open order's `totalCents` was typed by the business (some line had no price): it is final, delivery included. Absent when the total is the sum of fixed prices (PDK-ORDER-PRICES). */
|
|
2769
2893
|
totalManual?: true;
|
|
2770
2894
|
currency: string | null;
|
|
2895
|
+
/** PDK-OFF-CATALOG — the sum of the lines that already have a price (delivery not included): «$X + N por confirmar» while `totalCents` is null. Present only with free lines. */
|
|
2896
|
+
confirmedSubtotalCents?: number;
|
|
2897
|
+
/** PDK-OFF-CATALOG — free lines still waiting for the business (`totalCents` is null while it is above 0). */
|
|
2898
|
+
pendingLines?: number;
|
|
2771
2899
|
fields: Array<{
|
|
2772
2900
|
label: string;
|
|
2773
2901
|
value: string;
|
|
@@ -2847,6 +2975,19 @@ export interface CreateDirectOrderInput {
|
|
|
2847
2975
|
};
|
|
2848
2976
|
/** AGF-ORDER-ORIGIN-POS — where it comes from; default `{ channel: 'page' }`. A `pos` sale needs `place` and `by`. */
|
|
2849
2977
|
origin?: CaseOrigin;
|
|
2978
|
+
/**
|
|
2979
|
+
* PDK-OFF-CATALOG — explicit opt-in (per business, decided by your App): the order may carry products that are not in
|
|
2980
|
+
* the catalog (`offCatalogLines`) for ANY origin. Without it `offCatalogLines` is a 400 and nothing changes.
|
|
2981
|
+
*/
|
|
2982
|
+
allowOffCatalog?: true;
|
|
2983
|
+
/** PDK-OFF-CATALOG — the most free lines this order takes (1–50, default 15). Needs `allowOffCatalog`. */
|
|
2984
|
+
maxOffCatalogLines?: number;
|
|
2985
|
+
/**
|
|
2986
|
+
* PDK-OFF-CATALOG — products asked for by name that are not in the catalog («comodín» lines). They are `pending`
|
|
2987
|
+
* («por confirmar») until the business confirms each one with `cases.confirmLine`; the receipt's `totalCents` is null
|
|
2988
|
+
* until then and nothing can be paid. `lines` may be `[]` when this has items. Needs `allowOffCatalog`.
|
|
2989
|
+
*/
|
|
2990
|
+
offCatalogLines?: CreateOffCatalogLineInput[];
|
|
2850
2991
|
/** Products of the business's catalog and how many of each. `options`: the choice for a
|
|
2851
2992
|
* product with option groups (AGF-MENU-OPTIONS M2; a required group left out → 400). */
|
|
2852
2993
|
lines: Array<{
|
|
@@ -3010,6 +3151,47 @@ export interface CaseClosingMethod {
|
|
|
3010
3151
|
collectedCents: number;
|
|
3011
3152
|
refundedCents: number;
|
|
3012
3153
|
netCents: number;
|
|
3154
|
+
/** PDK-STORE-CREDIT — the net of ORDER payments by this method. `fromSalesCents + fromAccountCents = netCents`. Absent on an older platform. */
|
|
3155
|
+
fromSalesCents?: number;
|
|
3156
|
+
/** PDK-STORE-CREDIT — the net of the customer ACCOUNTS' movements by this method: abonos − reversals − payouts. */
|
|
3157
|
+
fromAccountCents?: number;
|
|
3158
|
+
/** PDK-STORE-CREDIT — abonos received by this method (inside `collectedCents`). */
|
|
3159
|
+
accountReceivedCents?: number;
|
|
3160
|
+
/** PDK-STORE-CREDIT — abonos reversed + payouts by this method (inside `refundedCents`). */
|
|
3161
|
+
accountOutCents?: number;
|
|
3162
|
+
}
|
|
3163
|
+
/**
|
|
3164
|
+
* PDK-STORE-CREDIT — the customer accounts' part of a closing (always present on a platform that has them; all zeros for
|
|
3165
|
+
* a business that never used fiado). closing = opening + charged + prior debt + adjustments − abonos(net) − write-offs + payouts.
|
|
3166
|
+
*/
|
|
3167
|
+
export interface CaseClosingReceivables {
|
|
3168
|
+
openingCents: number;
|
|
3169
|
+
/** Fiado of the range: orders left on account (their whole total). */
|
|
3170
|
+
chargedCents: number;
|
|
3171
|
+
/** The paper notebook's old debt entered in the range. */
|
|
3172
|
+
priorDebtCents: number;
|
|
3173
|
+
/** Revised receipts (±) and cancelled orders (−) of orders on account. */
|
|
3174
|
+
adjustmentsCents: number;
|
|
3175
|
+
paymentsByMethod: Array<{
|
|
3176
|
+
method: string;
|
|
3177
|
+
methodName: string;
|
|
3178
|
+
receivedCents: number;
|
|
3179
|
+
reversedCents: number;
|
|
3180
|
+
netCents: number;
|
|
3181
|
+
}>;
|
|
3182
|
+
paymentsNetCents: number;
|
|
3183
|
+
writeOffCents: number;
|
|
3184
|
+
/** Credit in the customer's favour handed back (money out). */
|
|
3185
|
+
payoutCents: number;
|
|
3186
|
+
payoutsByMethod: Array<{
|
|
3187
|
+
method: string;
|
|
3188
|
+
methodName: string;
|
|
3189
|
+
cents: number;
|
|
3190
|
+
}>;
|
|
3191
|
+
closingCents: number;
|
|
3192
|
+
/** Customers who owe something at the end of the range. */
|
|
3193
|
+
customers: number;
|
|
3194
|
+
balanced: boolean;
|
|
3013
3195
|
}
|
|
3014
3196
|
/** AGF-CASH-REGISTER — one order sent in a closing's range. */
|
|
3015
3197
|
export interface CaseClosingOrder {
|
|
@@ -3078,7 +3260,18 @@ export interface CaseClosingReport {
|
|
|
3078
3260
|
netCents: number;
|
|
3079
3261
|
/** Payments confirmed whose order has no known total: in no sum. */
|
|
3080
3262
|
unpricedPayments: number;
|
|
3263
|
+
/** PDK-STORE-CREDIT — Σ `fromSalesCents` over the methods (what the orders' payments brought in, net). Absent on an older platform. */
|
|
3264
|
+
fromSalesCents?: number;
|
|
3265
|
+
/** PDK-STORE-CREDIT — Σ `fromAccountCents` (the customer accounts' abonos, net of reversals and payouts). */
|
|
3266
|
+
fromAccountCents?: number;
|
|
3081
3267
|
};
|
|
3268
|
+
/** PDK-STORE-CREDIT — customer accounts (fiado). Absent on an older platform. */
|
|
3269
|
+
receivables?: CaseClosingReceivables;
|
|
3270
|
+
/**
|
|
3271
|
+
* PDK-STORE-CREDIT — set only when `clampToClock` cut the range short: the `to` the caller asked for, which was ahead of the
|
|
3272
|
+
* platform's clock. `to` is then the clamped instant — the next closing must start from `to`, never from this.
|
|
3273
|
+
*/
|
|
3274
|
+
requestedTo?: string;
|
|
3082
3275
|
/** The cash the register should have received, for the count. */
|
|
3083
3276
|
cash: {
|
|
3084
3277
|
collectedCents: number;
|
|
@@ -3105,6 +3298,50 @@ export interface CaseClosingReport {
|
|
|
3105
3298
|
orders: CaseClosingOrder[];
|
|
3106
3299
|
ordersTruncated: boolean;
|
|
3107
3300
|
}
|
|
3301
|
+
/**
|
|
3302
|
+
* PDK-STORE-CREDIT — `cases.setOnAccount`: «Dejar como fiado». The status and the ledger charge are one transaction.
|
|
3303
|
+
* `idempotencyKey` (8–64 of `A-Za-z0-9_.:-`) is required: a retried key returns the same result with `replayed: true`.
|
|
3304
|
+
*/
|
|
3305
|
+
export interface SetOnAccountInput {
|
|
3306
|
+
idempotencyKey: string;
|
|
3307
|
+
/** Only when the case has no contact yet (a contact with a name and a phone). */
|
|
3308
|
+
contactId?: string;
|
|
3309
|
+
/** `YYYY-MM-DD`. */
|
|
3310
|
+
dueOn?: string;
|
|
3311
|
+
/** At most 500 characters. */
|
|
3312
|
+
note?: string;
|
|
3313
|
+
/** Leave it as fiado past the account's limit. The HOST decides who may; the platform does not know. */
|
|
3314
|
+
overrideLimit?: boolean;
|
|
3315
|
+
/** The App's default limit (cents) for an account with none of its own; checked with the down payment taken off. */
|
|
3316
|
+
defaultLimitCents?: number;
|
|
3317
|
+
/** Cash or transfer received now, by one of the business's payment accounts (an `accountId` of `directForm().payment.options`). */
|
|
3318
|
+
downPayment?: {
|
|
3319
|
+
amountCents: number;
|
|
3320
|
+
accountId: string;
|
|
3321
|
+
reference?: string;
|
|
3322
|
+
};
|
|
3323
|
+
/** Who did it, as the App names them (at most 120). */
|
|
3324
|
+
actor?: string;
|
|
3325
|
+
}
|
|
3326
|
+
/** `cases.setOnAccount` answers the case as `cases.get` does, plus whether the key had been used before. */
|
|
3327
|
+
export type SetOnAccountResult = CaseView & {
|
|
3328
|
+
replayed: boolean;
|
|
3329
|
+
};
|
|
3330
|
+
/** PDK-STORE-CREDIT — `cases.account(caseId)`: what ONE order owes on the customer account (never the account). */
|
|
3331
|
+
export interface CaseAccount {
|
|
3332
|
+
onAccount: boolean;
|
|
3333
|
+
/** 0 when not on account. */
|
|
3334
|
+
totalCents?: number;
|
|
3335
|
+
collectedCents?: number;
|
|
3336
|
+
writtenOffCents?: number;
|
|
3337
|
+
outstandingCents?: number;
|
|
3338
|
+
payments: Array<{
|
|
3339
|
+
entryId: string;
|
|
3340
|
+
method: string | null;
|
|
3341
|
+
cents: number;
|
|
3342
|
+
occurredAt: string;
|
|
3343
|
+
}>;
|
|
3344
|
+
}
|
|
3108
3345
|
export interface ListCasesInput {
|
|
3109
3346
|
state?: CaseState[];
|
|
3110
3347
|
type?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge-io/sdk-server",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.84.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",
|