@taxdao/fintax-mcp 0.2.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/README.md +220 -0
- package/dist/app/create-server.d.ts +18 -0
- package/dist/app/create-server.js +80 -0
- package/dist/app/create-server.js.map +1 -0
- package/dist/app/register-tools.d.ts +4 -0
- package/dist/app/register-tools.js +18 -0
- package/dist/app/register-tools.js.map +1 -0
- package/dist/audit/audit-context.d.ts +38 -0
- package/dist/audit/audit-context.js +167 -0
- package/dist/audit/audit-context.js.map +1 -0
- package/dist/audit/audit-sink.d.ts +20 -0
- package/dist/audit/audit-sink.js +6 -0
- package/dist/audit/audit-sink.js.map +1 -0
- package/dist/audit/file-audit-sink.d.ts +6 -0
- package/dist/audit/file-audit-sink.js +18 -0
- package/dist/audit/file-audit-sink.js.map +1 -0
- package/dist/auth/auth-session.d.ts +63 -0
- package/dist/auth/auth-session.js +226 -0
- package/dist/auth/auth-session.js.map +1 -0
- package/dist/auth/credentials.d.ts +6 -0
- package/dist/auth/credentials.js +12 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/org-token-provider.d.ts +15 -0
- package/dist/auth/org-token-provider.js +62 -0
- package/dist/auth/org-token-provider.js.map +1 -0
- package/dist/capabilities/capability.d.ts +100 -0
- package/dist/capabilities/capability.js +26 -0
- package/dist/capabilities/capability.js.map +1 -0
- package/dist/capabilities/create-capabilities.d.ts +2 -0
- package/dist/capabilities/create-capabilities.js +37 -0
- package/dist/capabilities/create-capabilities.js.map +1 -0
- package/dist/capabilities/define-capability.d.ts +39 -0
- package/dist/capabilities/define-capability.js +64 -0
- package/dist/capabilities/define-capability.js.map +1 -0
- package/dist/capabilities/definitions/accounting-balances.d.ts +4 -0
- package/dist/capabilities/definitions/accounting-balances.js +98 -0
- package/dist/capabilities/definitions/accounting-balances.js.map +1 -0
- package/dist/capabilities/definitions/accounting-context.d.ts +2 -0
- package/dist/capabilities/definitions/accounting-context.js +17 -0
- package/dist/capabilities/definitions/accounting-context.js.map +1 -0
- package/dist/capabilities/definitions/assets.d.ts +2 -0
- package/dist/capabilities/definitions/assets.js +367 -0
- package/dist/capabilities/definitions/assets.js.map +1 -0
- package/dist/capabilities/definitions/business-documents.d.ts +9 -0
- package/dist/capabilities/definitions/business-documents.js +386 -0
- package/dist/capabilities/definitions/business-documents.js.map +1 -0
- package/dist/capabilities/definitions/dashboard.d.ts +2 -0
- package/dist/capabilities/definitions/dashboard.js +153 -0
- package/dist/capabilities/definitions/dashboard.js.map +1 -0
- package/dist/capabilities/definitions/extended-operation-contracts.d.ts +597 -0
- package/dist/capabilities/definitions/extended-operation-contracts.js +1180 -0
- package/dist/capabilities/definitions/extended-operation-contracts.js.map +1 -0
- package/dist/capabilities/definitions/extended-operations.d.ts +2 -0
- package/dist/capabilities/definitions/extended-operations.js +699 -0
- package/dist/capabilities/definitions/extended-operations.js.map +1 -0
- package/dist/capabilities/definitions/financial-reports.d.ts +2 -0
- package/dist/capabilities/definitions/financial-reports.js +100 -0
- package/dist/capabilities/definitions/financial-reports.js.map +1 -0
- package/dist/capabilities/definitions/fnd-import.d.ts +34 -0
- package/dist/capabilities/definitions/fnd-import.js +282 -0
- package/dist/capabilities/definitions/fnd-import.js.map +1 -0
- package/dist/capabilities/definitions/fund-accounts.d.ts +2 -0
- package/dist/capabilities/definitions/fund-accounts.js +188 -0
- package/dist/capabilities/definitions/fund-accounts.js.map +1 -0
- package/dist/capabilities/definitions/fund-balances.d.ts +2 -0
- package/dist/capabilities/definitions/fund-balances.js +84 -0
- package/dist/capabilities/definitions/fund-balances.js.map +1 -0
- package/dist/capabilities/definitions/journals.d.ts +10 -0
- package/dist/capabilities/definitions/journals.js +224 -0
- package/dist/capabilities/definitions/journals.js.map +1 -0
- package/dist/capabilities/definitions/master-data.d.ts +2 -0
- package/dist/capabilities/definitions/master-data.js +451 -0
- package/dist/capabilities/definitions/master-data.js.map +1 -0
- package/dist/capabilities/definitions/pnl.d.ts +2 -0
- package/dist/capabilities/definitions/pnl.js +139 -0
- package/dist/capabilities/definitions/pnl.js.map +1 -0
- package/dist/capabilities/definitions/reference-data.d.ts +2 -0
- package/dist/capabilities/definitions/reference-data.js +169 -0
- package/dist/capabilities/definitions/reference-data.js.map +1 -0
- package/dist/capabilities/definitions/transaction-drafts.d.ts +2 -0
- package/dist/capabilities/definitions/transaction-drafts.js +157 -0
- package/dist/capabilities/definitions/transaction-drafts.js.map +1 -0
- package/dist/capabilities/definitions/transactions.d.ts +168 -0
- package/dist/capabilities/definitions/transactions.js +79 -0
- package/dist/capabilities/definitions/transactions.js.map +1 -0
- package/dist/capabilities/executor.d.ts +19 -0
- package/dist/capabilities/executor.js +134 -0
- package/dist/capabilities/executor.js.map +1 -0
- package/dist/capabilities/registry.d.ts +7 -0
- package/dist/capabilities/registry.js +51 -0
- package/dist/capabilities/registry.js.map +1 -0
- package/dist/clients/base-client.d.ts +5 -0
- package/dist/clients/base-client.js +13 -0
- package/dist/clients/base-client.js.map +1 -0
- package/dist/clients/http-client.d.ts +29 -0
- package/dist/clients/http-client.js +167 -0
- package/dist/clients/http-client.js.map +1 -0
- package/dist/clients/suite-client.d.ts +5 -0
- package/dist/clients/suite-client.js +5 -0
- package/dist/clients/suite-client.js.map +1 -0
- package/dist/concurrency/lock-manager.d.ts +4 -0
- package/dist/concurrency/lock-manager.js +23 -0
- package/dist/concurrency/lock-manager.js.map +1 -0
- package/dist/config/load-config.d.ts +2 -0
- package/dist/config/load-config.js +18 -0
- package/dist/config/load-config.js.map +1 -0
- package/dist/config/schema.d.ts +24 -0
- package/dist/config/schema.js +85 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/errors/fintax-error.d.ts +24 -0
- package/dist/errors/fintax-error.js +21 -0
- package/dist/errors/fintax-error.js.map +1 -0
- package/dist/errors/normalize-error.d.ts +3 -0
- package/dist/errors/normalize-error.js +67 -0
- package/dist/errors/normalize-error.js.map +1 -0
- package/dist/files/artifact-store.d.ts +17 -0
- package/dist/files/artifact-store.js +74 -0
- package/dist/files/artifact-store.js.map +1 -0
- package/dist/files/input-policy.d.ts +28 -0
- package/dist/files/input-policy.js +109 -0
- package/dist/files/input-policy.js.map +1 -0
- package/dist/files/roots-provider.d.ts +14 -0
- package/dist/files/roots-provider.js +47 -0
- package/dist/files/roots-provider.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/logger.d.ts +3 -0
- package/dist/logging/logger.js +13 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/policies/idempotency.d.ts +32 -0
- package/dist/policies/idempotency.js +155 -0
- package/dist/policies/idempotency.js.map +1 -0
- package/dist/policies/job-reference.d.ts +16 -0
- package/dist/policies/job-reference.js +62 -0
- package/dist/policies/job-reference.js.map +1 -0
- package/dist/policies/operation-plan.d.ts +27 -0
- package/dist/policies/operation-plan.js +99 -0
- package/dist/policies/operation-plan.js.map +1 -0
- package/dist/policies/redaction.d.ts +2 -0
- package/dist/policies/redaction.js +29 -0
- package/dist/policies/redaction.js.map +1 -0
- package/dist/policies/retry.d.ts +8 -0
- package/dist/policies/retry.js +19 -0
- package/dist/policies/retry.js.map +1 -0
- package/dist/responses/tool-response.d.ts +4 -0
- package/dist/responses/tool-response.js +24 -0
- package/dist/responses/tool-response.js.map +1 -0
- package/dist/schemas/common.d.ts +226 -0
- package/dist/schemas/common.js +133 -0
- package/dist/schemas/common.js.map +1 -0
- package/dist/schemas/domains/accounting-balances.d.ts +497 -0
- package/dist/schemas/domains/accounting-balances.js +226 -0
- package/dist/schemas/domains/accounting-balances.js.map +1 -0
- package/dist/schemas/domains/accounting-context.d.ts +118 -0
- package/dist/schemas/domains/accounting-context.js +54 -0
- package/dist/schemas/domains/accounting-context.js.map +1 -0
- package/dist/schemas/domains/assets.d.ts +2508 -0
- package/dist/schemas/domains/assets.js +960 -0
- package/dist/schemas/domains/assets.js.map +1 -0
- package/dist/schemas/domains/business-documents.d.ts +4406 -0
- package/dist/schemas/domains/business-documents.js +1153 -0
- package/dist/schemas/domains/business-documents.js.map +1 -0
- package/dist/schemas/domains/configuration.d.ts +518 -0
- package/dist/schemas/domains/configuration.js +504 -0
- package/dist/schemas/domains/configuration.js.map +1 -0
- package/dist/schemas/domains/dashboard.d.ts +339 -0
- package/dist/schemas/domains/dashboard.js +211 -0
- package/dist/schemas/domains/dashboard.js.map +1 -0
- package/dist/schemas/domains/extended-operation-results.d.ts +1588 -0
- package/dist/schemas/domains/extended-operation-results.js +275 -0
- package/dist/schemas/domains/extended-operation-results.js.map +1 -0
- package/dist/schemas/domains/extended-operations.d.ts +1061 -0
- package/dist/schemas/domains/extended-operations.js +567 -0
- package/dist/schemas/domains/extended-operations.js.map +1 -0
- package/dist/schemas/domains/extended-query-results.d.ts +1688 -0
- package/dist/schemas/domains/extended-query-results.js +337 -0
- package/dist/schemas/domains/extended-query-results.js.map +1 -0
- package/dist/schemas/domains/financial-reports.d.ts +540 -0
- package/dist/schemas/domains/financial-reports.js +206 -0
- package/dist/schemas/domains/financial-reports.js.map +1 -0
- package/dist/schemas/domains/fnd-import.d.ts +912 -0
- package/dist/schemas/domains/fnd-import.js +396 -0
- package/dist/schemas/domains/fnd-import.js.map +1 -0
- package/dist/schemas/domains/fund-accounts.d.ts +1092 -0
- package/dist/schemas/domains/fund-accounts.js +410 -0
- package/dist/schemas/domains/fund-accounts.js.map +1 -0
- package/dist/schemas/domains/fund-balances.d.ts +476 -0
- package/dist/schemas/domains/fund-balances.js +233 -0
- package/dist/schemas/domains/fund-balances.js.map +1 -0
- package/dist/schemas/domains/journals.d.ts +1619 -0
- package/dist/schemas/domains/journals.js +615 -0
- package/dist/schemas/domains/journals.js.map +1 -0
- package/dist/schemas/domains/master-data.d.ts +2010 -0
- package/dist/schemas/domains/master-data.js +799 -0
- package/dist/schemas/domains/master-data.js.map +1 -0
- package/dist/schemas/domains/pnl.d.ts +837 -0
- package/dist/schemas/domains/pnl.js +469 -0
- package/dist/schemas/domains/pnl.js.map +1 -0
- package/dist/schemas/domains/reference-data.d.ts +227 -0
- package/dist/schemas/domains/reference-data.js +144 -0
- package/dist/schemas/domains/reference-data.js.map +1 -0
- package/dist/schemas/domains/transaction-drafts.d.ts +903 -0
- package/dist/schemas/domains/transaction-drafts.js +242 -0
- package/dist/schemas/domains/transaction-drafts.js.map +1 -0
- package/dist/schemas/domains/transactions.d.ts +910 -0
- package/dist/schemas/domains/transactions.js +266 -0
- package/dist/schemas/domains/transactions.js.map +1 -0
- package/dist/schemas/primitives.d.ts +6 -0
- package/dist/schemas/primitives.js +11 -0
- package/dist/schemas/primitives.js.map +1 -0
- package/dist/schemas/public-input.d.ts +3 -0
- package/dist/schemas/public-input.js +524 -0
- package/dist/schemas/public-input.js.map +1 -0
- package/dist/tools/core-edit/idempotent-write.d.ts +23 -0
- package/dist/tools/core-edit/idempotent-write.js +58 -0
- package/dist/tools/core-edit/idempotent-write.js.map +1 -0
- package/dist/tools/core-edit/save-asset.d.ts +5 -0
- package/dist/tools/core-edit/save-asset.js +334 -0
- package/dist/tools/core-edit/save-asset.js.map +1 -0
- package/dist/tools/core-edit/save-business-document-draft.d.ts +2 -0
- package/dist/tools/core-edit/save-business-document-draft.js +128 -0
- package/dist/tools/core-edit/save-business-document-draft.js.map +1 -0
- package/dist/tools/core-edit/save-fund-account.d.ts +2 -0
- package/dist/tools/core-edit/save-fund-account.js +138 -0
- package/dist/tools/core-edit/save-fund-account.js.map +1 -0
- package/dist/tools/core-edit/save-journal-draft.d.ts +2 -0
- package/dist/tools/core-edit/save-journal-draft.js +122 -0
- package/dist/tools/core-edit/save-journal-draft.js.map +1 -0
- package/dist/tools/core-edit/save-master-data.d.ts +2 -0
- package/dist/tools/core-edit/save-master-data.js +153 -0
- package/dist/tools/core-edit/save-master-data.js.map +1 -0
- package/dist/tools/core-edit/save-transaction-draft.d.ts +2 -0
- package/dist/tools/core-edit/save-transaction-draft.js +128 -0
- package/dist/tools/core-edit/save-transaction-draft.js.map +1 -0
- package/dist/tools/core-read/export-business-documents.d.ts +2 -0
- package/dist/tools/core-read/export-business-documents.js +67 -0
- package/dist/tools/core-read/export-business-documents.js.map +1 -0
- package/dist/tools/core-read/export-journals.d.ts +2 -0
- package/dist/tools/core-read/export-journals.js +56 -0
- package/dist/tools/core-read/export-journals.js.map +1 -0
- package/dist/tools/core-read/export-transactions.d.ts +2 -0
- package/dist/tools/core-read/export-transactions.js +67 -0
- package/dist/tools/core-read/export-transactions.js.map +1 -0
- package/dist/tools/core-read/query-accounting-balances.d.ts +2 -0
- package/dist/tools/core-read/query-accounting-balances.js +135 -0
- package/dist/tools/core-read/query-accounting-balances.js.map +1 -0
- package/dist/tools/core-read/query-accounting-context.d.ts +2 -0
- package/dist/tools/core-read/query-accounting-context.js +76 -0
- package/dist/tools/core-read/query-accounting-context.js.map +1 -0
- package/dist/tools/core-read/query-assets.d.ts +2 -0
- package/dist/tools/core-read/query-assets.js +425 -0
- package/dist/tools/core-read/query-assets.js.map +1 -0
- package/dist/tools/core-read/query-business-documents.d.ts +9 -0
- package/dist/tools/core-read/query-business-documents.js +620 -0
- package/dist/tools/core-read/query-business-documents.js.map +1 -0
- package/dist/tools/core-read/query-dashboard.d.ts +2 -0
- package/dist/tools/core-read/query-dashboard.js +144 -0
- package/dist/tools/core-read/query-dashboard.js.map +1 -0
- package/dist/tools/core-read/query-financial-reports.d.ts +2 -0
- package/dist/tools/core-read/query-financial-reports.js +171 -0
- package/dist/tools/core-read/query-financial-reports.js.map +1 -0
- package/dist/tools/core-read/query-fund-accounts.d.ts +2 -0
- package/dist/tools/core-read/query-fund-accounts.js +140 -0
- package/dist/tools/core-read/query-fund-accounts.js.map +1 -0
- package/dist/tools/core-read/query-fund-balances.d.ts +2 -0
- package/dist/tools/core-read/query-fund-balances.js +150 -0
- package/dist/tools/core-read/query-fund-balances.js.map +1 -0
- package/dist/tools/core-read/query-journals.d.ts +2 -0
- package/dist/tools/core-read/query-journals.js +277 -0
- package/dist/tools/core-read/query-journals.js.map +1 -0
- package/dist/tools/core-read/query-master-data.d.ts +2 -0
- package/dist/tools/core-read/query-master-data.js +363 -0
- package/dist/tools/core-read/query-master-data.js.map +1 -0
- package/dist/tools/core-read/query-pnl.d.ts +2 -0
- package/dist/tools/core-read/query-pnl.js +244 -0
- package/dist/tools/core-read/query-pnl.js.map +1 -0
- package/dist/tools/core-read/query-reference-data.d.ts +2 -0
- package/dist/tools/core-read/query-reference-data.js +293 -0
- package/dist/tools/core-read/query-reference-data.js.map +1 -0
- package/dist/tools/core-read/query-transactions.d.ts +2 -0
- package/dist/tools/core-read/query-transactions.js +58 -0
- package/dist/tools/core-read/query-transactions.js.map +1 -0
- package/dist/tools/create-tools.d.ts +3 -0
- package/dist/tools/create-tools.js +88 -0
- package/dist/tools/create-tools.js.map +1 -0
- package/dist/tools/extended/asset-operation-tools.d.ts +9 -0
- package/dist/tools/extended/asset-operation-tools.js +419 -0
- package/dist/tools/extended/asset-operation-tools.js.map +1 -0
- package/dist/tools/extended/automation-tools.d.ts +7 -0
- package/dist/tools/extended/automation-tools.js +333 -0
- package/dist/tools/extended/automation-tools.js.map +1 -0
- package/dist/tools/extended/configuration-tools.d.ts +14 -0
- package/dist/tools/extended/configuration-tools.js +871 -0
- package/dist/tools/extended/configuration-tools.js.map +1 -0
- package/dist/tools/extended/period-end-tools.d.ts +11 -0
- package/dist/tools/extended/period-end-tools.js +480 -0
- package/dist/tools/extended/period-end-tools.js.map +1 -0
- package/dist/tools/extended/query-output.d.ts +2589 -0
- package/dist/tools/extended/query-output.js +610 -0
- package/dist/tools/extended/query-output.js.map +1 -0
- package/dist/tools/extended/tool-support.d.ts +56 -0
- package/dist/tools/extended/tool-support.js +198 -0
- package/dist/tools/extended/tool-support.js.map +1 -0
- package/dist/tools/extended/workflow-tools.d.ts +10 -0
- package/dist/tools/extended/workflow-tools.js +678 -0
- package/dist/tools/extended/workflow-tools.js.map +1 -0
- package/dist/tools/fnd-import/execute-import.d.ts +2 -0
- package/dist/tools/fnd-import/execute-import.js +201 -0
- package/dist/tools/fnd-import/execute-import.js.map +1 -0
- package/dist/tools/fnd-import/get-import-template.d.ts +2 -0
- package/dist/tools/fnd-import/get-import-template.js +66 -0
- package/dist/tools/fnd-import/get-import-template.js.map +1 -0
- package/dist/tools/fnd-import/get-job-status.d.ts +8 -0
- package/dist/tools/fnd-import/get-job-status.js +201 -0
- package/dist/tools/fnd-import/get-job-status.js.map +1 -0
- package/dist/tools/fnd-import/prepare-import.d.ts +31 -0
- package/dist/tools/fnd-import/prepare-import.js +214 -0
- package/dist/tools/fnd-import/prepare-import.js.map +1 -0
- package/dist/tools/fnd-import/public-import-result.d.ts +18 -0
- package/dist/tools/fnd-import/public-import-result.js +35 -0
- package/dist/tools/fnd-import/public-import-result.js.map +1 -0
- package/dist/tools/tool-definition.d.ts +45 -0
- package/dist/tools/tool-definition.js +11 -0
- package/dist/tools/tool-definition.js.map +1 -0
- package/dist/tools/tool-handler.d.ts +27 -0
- package/dist/tools/tool-handler.js +196 -0
- package/dist/tools/tool-handler.js.map +1 -0
- package/dist/tools/transaction-item.d.ts +225 -0
- package/dist/tools/transaction-item.js +109 -0
- package/dist/tools/transaction-item.js.map +1 -0
- package/dist/transport/draining-transport.d.ts +14 -0
- package/dist/transport/draining-transport.js +36 -0
- package/dist/transport/draining-transport.js.map +1 -0
- package/dist/transport/stdio.d.ts +2 -0
- package/dist/transport/stdio.js +5 -0
- package/dist/transport/stdio.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { FinTaxError } from '../errors/fintax-error.js';
|
|
2
|
+
import { hashOperationValue } from './operation-plan.js';
|
|
3
|
+
const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
|
|
4
|
+
const DEFAULT_MAX_ENTRIES = 10_000;
|
|
5
|
+
function storedFailure(error) {
|
|
6
|
+
return {
|
|
7
|
+
code: error.code,
|
|
8
|
+
message: error.message,
|
|
9
|
+
retryable: error.retryable,
|
|
10
|
+
fieldErrors: error.fieldErrors,
|
|
11
|
+
...(error.status === undefined ? {} : { status: error.status }),
|
|
12
|
+
...(error.recovery === undefined ? {} : { recovery: error.recovery }),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function restoreFailure(failure) {
|
|
16
|
+
return new FinTaxError(failure.code, failure.message, {
|
|
17
|
+
retryable: failure.retryable,
|
|
18
|
+
fieldErrors: failure.fieldErrors,
|
|
19
|
+
...(failure.status === undefined ? {} : { status: failure.status }),
|
|
20
|
+
...(failure.recovery === undefined ? {} : { recovery: failure.recovery }),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export class IdempotencyManager {
|
|
24
|
+
#locks;
|
|
25
|
+
#ttlMs;
|
|
26
|
+
#maxEntries;
|
|
27
|
+
#now;
|
|
28
|
+
#records = new Map();
|
|
29
|
+
constructor(locks, options = {}) {
|
|
30
|
+
this.#locks = locks;
|
|
31
|
+
this.#ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
32
|
+
this.#maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
|
|
33
|
+
this.#now = options.now ?? Date.now;
|
|
34
|
+
}
|
|
35
|
+
begin(binding) {
|
|
36
|
+
const scope = this.#scope(binding);
|
|
37
|
+
return this.#locks.withLock(`idempotency:${digestScope(scope)}`, () => {
|
|
38
|
+
const now = this.#now();
|
|
39
|
+
this.#prune(now);
|
|
40
|
+
const existing = this.#records.get(scope);
|
|
41
|
+
if (existing === undefined) {
|
|
42
|
+
this.#records.set(scope, {
|
|
43
|
+
state: 'in_progress',
|
|
44
|
+
fingerprint: binding.fingerprint,
|
|
45
|
+
...(binding.recovery === undefined
|
|
46
|
+
? {}
|
|
47
|
+
: { recovery: binding.recovery }),
|
|
48
|
+
updatedAt: now,
|
|
49
|
+
});
|
|
50
|
+
return Promise.resolve({ kind: 'started' });
|
|
51
|
+
}
|
|
52
|
+
if (existing.fingerprint !== binding.fingerprint) {
|
|
53
|
+
throw new FinTaxError('CONFLICT', 'The idempotency key was used for a different operation; generate a new idempotency_key for the new operation');
|
|
54
|
+
}
|
|
55
|
+
if (existing.state === 'completed') {
|
|
56
|
+
return Promise.resolve({
|
|
57
|
+
kind: 'replayed',
|
|
58
|
+
result: existing.result,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (existing.state === 'failed')
|
|
62
|
+
throw restoreFailure(existing.failure);
|
|
63
|
+
if (existing.updatedAt < now - this.#ttlMs) {
|
|
64
|
+
const failure = new FinTaxError('UPSTREAM_UNAVAILABLE', 'The idempotent request state has expired and the result is unknown; follow the recovery guidance to query the final state and do not retry execution', {
|
|
65
|
+
retryable: false,
|
|
66
|
+
...(existing.recovery === undefined
|
|
67
|
+
? {}
|
|
68
|
+
: { recovery: existing.recovery }),
|
|
69
|
+
});
|
|
70
|
+
this.#records.set(scope, {
|
|
71
|
+
state: 'failed',
|
|
72
|
+
fingerprint: existing.fingerprint,
|
|
73
|
+
failure: storedFailure(failure),
|
|
74
|
+
updatedAt: now,
|
|
75
|
+
});
|
|
76
|
+
throw failure;
|
|
77
|
+
}
|
|
78
|
+
throw new FinTaxError('CONFLICT', 'The same idempotent request is already being processed; do not execute it again', {
|
|
79
|
+
retryable: false,
|
|
80
|
+
...(existing.recovery === undefined
|
|
81
|
+
? {}
|
|
82
|
+
: { recovery: existing.recovery }),
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
complete(binding, result) {
|
|
87
|
+
return this.#replace(binding, {
|
|
88
|
+
state: 'completed',
|
|
89
|
+
fingerprint: binding.fingerprint,
|
|
90
|
+
result,
|
|
91
|
+
updatedAt: this.#now(),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
fail(binding, error) {
|
|
95
|
+
return this.#replace(binding, {
|
|
96
|
+
state: 'failed',
|
|
97
|
+
fingerprint: binding.fingerprint,
|
|
98
|
+
failure: storedFailure(error),
|
|
99
|
+
updatedAt: this.#now(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
abandon(binding) {
|
|
103
|
+
const scope = this.#scope(binding);
|
|
104
|
+
return this.#locks.withLock(`idempotency:${digestScope(scope)}`, () => {
|
|
105
|
+
const existing = this.#records.get(scope);
|
|
106
|
+
if (existing?.state === 'in_progress' &&
|
|
107
|
+
existing.fingerprint === binding.fingerprint) {
|
|
108
|
+
this.#records.delete(scope);
|
|
109
|
+
}
|
|
110
|
+
return Promise.resolve();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
#replace(binding, replacement) {
|
|
114
|
+
const scope = this.#scope(binding);
|
|
115
|
+
return this.#locks.withLock(`idempotency:${digestScope(scope)}`, () => {
|
|
116
|
+
const existing = this.#records.get(scope);
|
|
117
|
+
if (existing?.state !== 'in_progress' ||
|
|
118
|
+
existing.fingerprint !== binding.fingerprint) {
|
|
119
|
+
throw new Error('Idempotency claim is not active');
|
|
120
|
+
}
|
|
121
|
+
this.#records.set(scope, replacement);
|
|
122
|
+
return Promise.resolve();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
#scope(binding) {
|
|
126
|
+
return [
|
|
127
|
+
binding.tool,
|
|
128
|
+
binding.userId,
|
|
129
|
+
binding.tenantId,
|
|
130
|
+
binding.orgId ?? 'no-org',
|
|
131
|
+
binding.key,
|
|
132
|
+
].join(':');
|
|
133
|
+
}
|
|
134
|
+
#prune(now) {
|
|
135
|
+
const cutoff = now - this.#ttlMs;
|
|
136
|
+
for (const [scope, record] of this.#records) {
|
|
137
|
+
if (record.state !== 'in_progress' && record.updatedAt < cutoff) {
|
|
138
|
+
this.#records.delete(scope);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (this.#records.size < this.#maxEntries)
|
|
142
|
+
return;
|
|
143
|
+
const oldest = [...this.#records.entries()].sort(([, left], [, right]) => left.updatedAt - right.updatedAt);
|
|
144
|
+
for (const [scope, record] of oldest) {
|
|
145
|
+
if (this.#records.size < this.#maxEntries)
|
|
146
|
+
break;
|
|
147
|
+
if (record.state !== 'in_progress')
|
|
148
|
+
this.#records.delete(scope);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function digestScope(scope) {
|
|
153
|
+
return hashOperationValue({ namespace: 'idempotency-scope', scope });
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=idempotency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idempotency.js","sourceRoot":"","sources":["../../src/policies/idempotency.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAgDzD,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC3C,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAEnC,SAAS,aAAa,CAAC,KAAkB;IACvC,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAC/D,GAAG,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,OAAsB;IAC5C,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE;QACpD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,WA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AC5C,IAAI,MAAM,CAAC,KAAK,KAAK,aAAa,IAAI,MAAM,CAAC,SAAS,GAAG,MAAM,EAAE,CAAC;gBAChE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW;YAAE,OAAO;QAClD,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAC9C,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAC1D,CAAC;QACF,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;YACrC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW;gBAAE,MAAM;YACjD,IAAI,MAAM,CAAC,KAAK,KAAK,aAAa;gBAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;CACF;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,OAAO,kBAAkB,CAAC,EAAE,SAAS,EAAE,mBAAmB,EAAE,KAAK,EAAE,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function createFndImportJobId(batchId: string): string;
|
|
2
|
+
export declare function parseFndImportJobId(jobId: string): string;
|
|
3
|
+
export declare function createPnlCalculationJobId(runId: string): string;
|
|
4
|
+
export declare function createAutoFlowJobId(flowId: string, loopSeq: number): string;
|
|
5
|
+
export type ParsedJobReference = {
|
|
6
|
+
readonly type: 'fnd-import';
|
|
7
|
+
readonly id: string;
|
|
8
|
+
} | {
|
|
9
|
+
readonly type: 'pnl-calculation';
|
|
10
|
+
readonly id: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: 'auto-flow';
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly loopSeq: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function parseJobReference(jobId: string): ParsedJobReference;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import { FinTaxError } from '../errors/fintax-error.js';
|
|
3
|
+
const FND_IMPORT_JOB_PREFIX = 'fnd-import:';
|
|
4
|
+
const PNL_CALCULATION_JOB_PREFIX = 'pnl-calculation:';
|
|
5
|
+
const AUTO_FLOW_JOB_PREFIX = 'auto-flow:';
|
|
6
|
+
function createJobId(prefix, id) {
|
|
7
|
+
return `${prefix}${z.uuid().parse(id)}`;
|
|
8
|
+
}
|
|
9
|
+
function parseJobId(jobId, prefix) {
|
|
10
|
+
if (!jobId.startsWith(prefix)) {
|
|
11
|
+
throw new FinTaxError('VALIDATION_FAILED', 'Unsupported job_id type');
|
|
12
|
+
}
|
|
13
|
+
const parsed = z.uuid().safeParse(jobId.slice(prefix.length));
|
|
14
|
+
if (!parsed.success) {
|
|
15
|
+
throw new FinTaxError('VALIDATION_FAILED', 'Invalid job_id format', {
|
|
16
|
+
cause: parsed.error,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return parsed.data;
|
|
20
|
+
}
|
|
21
|
+
export function createFndImportJobId(batchId) {
|
|
22
|
+
return createJobId(FND_IMPORT_JOB_PREFIX, batchId);
|
|
23
|
+
}
|
|
24
|
+
export function parseFndImportJobId(jobId) {
|
|
25
|
+
return parseJobId(jobId, FND_IMPORT_JOB_PREFIX);
|
|
26
|
+
}
|
|
27
|
+
export function createPnlCalculationJobId(runId) {
|
|
28
|
+
return createJobId(PNL_CALCULATION_JOB_PREFIX, runId);
|
|
29
|
+
}
|
|
30
|
+
export function createAutoFlowJobId(flowId, loopSeq) {
|
|
31
|
+
return `${createJobId(AUTO_FLOW_JOB_PREFIX, flowId)}:${z
|
|
32
|
+
.number()
|
|
33
|
+
.int()
|
|
34
|
+
.positive()
|
|
35
|
+
.parse(loopSeq)}`;
|
|
36
|
+
}
|
|
37
|
+
export function parseJobReference(jobId) {
|
|
38
|
+
if (jobId.startsWith(FND_IMPORT_JOB_PREFIX)) {
|
|
39
|
+
return { type: 'fnd-import', id: parseFndImportJobId(jobId) };
|
|
40
|
+
}
|
|
41
|
+
if (jobId.startsWith(PNL_CALCULATION_JOB_PREFIX)) {
|
|
42
|
+
return {
|
|
43
|
+
type: 'pnl-calculation',
|
|
44
|
+
id: parseJobId(jobId, PNL_CALCULATION_JOB_PREFIX),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (jobId.startsWith(AUTO_FLOW_JOB_PREFIX)) {
|
|
48
|
+
const [id, loopSeq, ...extra] = jobId
|
|
49
|
+
.slice(AUTO_FLOW_JOB_PREFIX.length)
|
|
50
|
+
.split(':');
|
|
51
|
+
if (id === undefined || loopSeq === undefined || extra.length > 0) {
|
|
52
|
+
throw new FinTaxError('VALIDATION_FAILED', 'Invalid job_id format');
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
type: 'auto-flow',
|
|
56
|
+
id: z.uuid().parse(id),
|
|
57
|
+
loopSeq: z.coerce.number().int().positive().parse(loopSeq),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
throw new FinTaxError('VALIDATION_FAILED', 'Unsupported job_id type');
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=job-reference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-reference.js","sourceRoot":"","sources":["../../src/policies/job-reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,qBAAqB,GAAG,aAAa,CAAC;AAC5C,MAAM,0BAA0B,GAAG,kBAAkB,CAAC;AACtD,MA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|
|
3
|
+
readonly tool: string;
|
|
4
|
+
readonly subject_id: string;
|
|
5
|
+
readonly subject_version: string;
|
|
6
|
+
readonly user_id: string;
|
|
7
|
+
readonly tenant_id: string;
|
|
8
|
+
readonly org_id?: string;
|
|
9
|
+
readonly parameter_hash: string;
|
|
10
|
+
readonly preview_hash: string;
|
|
11
|
+
readonly file_id?: string;
|
|
12
|
+
readonly file_hash?: string;
|
|
13
|
+
readonly payload?: Readonly<Record<string, unknown>>;
|
|
14
|
+
}
|
|
15
|
+
export interface IssuedOperationPlan {
|
|
16
|
+
readonly operationPlanId: string;
|
|
17
|
+
readonly confirmationToken: string;
|
|
18
|
+
readonly expiresAt: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function hashOperationValue(value: unknown): string;
|
|
21
|
+
export declare class OperationPlanManager {
|
|
22
|
+
#private;
|
|
23
|
+
constructor(locks: LockManager);
|
|
24
|
+
issue(binding: OperationBinding, ttlMs?: number): IssuedOperationPlan;
|
|
25
|
+
consume(operationPlanId: string, confirmationToken: string, expectedTool: string): Promise<OperationBinding>;
|
|
26
|
+
inspect(operationPlanId: string, confirmationToken: string, expectedTool: string): OperationBinding;
|
|
27
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { FinTaxError } from '../errors/fintax-error.js';
|
|
3
|
+
function canonicalize(value) {
|
|
4
|
+
if (Array.isArray(value)) {
|
|
5
|
+
return `[${value.map((entry) => canonicalize(entry)).join(',')}]`;
|
|
6
|
+
}
|
|
7
|
+
if (value !== null && typeof value === 'object') {
|
|
8
|
+
return `{${Object.entries(value)
|
|
9
|
+
.filter(([, entry]) => entry !== undefined)
|
|
10
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
11
|
+
.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalize(entry)}`)
|
|
12
|
+
.join(',')}}`;
|
|
13
|
+
}
|
|
14
|
+
return JSON.stringify(value);
|
|
15
|
+
}
|
|
16
|
+
export function hashOperationValue(value) {
|
|
17
|
+
return createHmac('sha256', 'fintax-mcp-canonical-hash')
|
|
18
|
+
.update(canonicalize(value))
|
|
19
|
+
.digest('hex');
|
|
20
|
+
}
|
|
21
|
+
export class OperationPlanManager {
|
|
22
|
+
#locks;
|
|
23
|
+
#plans = new Map();
|
|
24
|
+
constructor(locks) {
|
|
25
|
+
this.#locks = locks;
|
|
26
|
+
}
|
|
27
|
+
issue(binding, ttlMs = 10 * 60 * 1000) {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
this.#pruneExpired(now);
|
|
30
|
+
const expiresAtMs = now + ttlMs;
|
|
31
|
+
const expiresAt = new Date(expiresAtMs).toISOString();
|
|
32
|
+
let operationPlanId = this.#newHandle();
|
|
33
|
+
while (this.#plans.has(operationPlanId)) {
|
|
34
|
+
operationPlanId = this.#newHandle();
|
|
35
|
+
}
|
|
36
|
+
let confirmationToken = this.#newHandle();
|
|
37
|
+
while (confirmationToken === operationPlanId) {
|
|
38
|
+
confirmationToken = this.#newHandle();
|
|
39
|
+
}
|
|
40
|
+
this.#plans.set(operationPlanId, {
|
|
41
|
+
confirmationToken,
|
|
42
|
+
binding: Object.freeze({ ...binding }),
|
|
43
|
+
expiresAtMs,
|
|
44
|
+
consumed: false,
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
operationPlanId,
|
|
48
|
+
confirmationToken,
|
|
49
|
+
expiresAt,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async consume(operationPlanId, confirmationToken, expectedTool) {
|
|
53
|
+
return this.#locks.withLock(`confirmation:${hashOperationValue(confirmationToken)}`, () => {
|
|
54
|
+
const plan = this.#inspectPair(operationPlanId, confirmationToken, expectedTool);
|
|
55
|
+
if (plan.consumed) {
|
|
56
|
+
throw new FinTaxError('CONFIRMATION_REQUIRED', 'The confirmation credential has already been used; run the preparation step again');
|
|
57
|
+
}
|
|
58
|
+
plan.consumed = true;
|
|
59
|
+
return Promise.resolve({ ...plan.binding });
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
inspect(operationPlanId, confirmationToken, expectedTool) {
|
|
63
|
+
return {
|
|
64
|
+
...this.#inspectPair(operationPlanId, confirmationToken, expectedTool)
|
|
65
|
+
.binding,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
#inspectPair(operationPlanId, confirmationToken, expectedTool) {
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
this.#pruneExpired(now);
|
|
71
|
+
const plan = this.#plans.get(operationPlanId);
|
|
72
|
+
if (plan === undefined ||
|
|
73
|
+
plan.expiresAtMs <= now ||
|
|
74
|
+
plan.binding.tool !== expectedTool ||
|
|
75
|
+
!this.#equalHandles(plan.confirmationToken, confirmationToken)) {
|
|
76
|
+
if (plan !== undefined && plan.expiresAtMs <= now) {
|
|
77
|
+
this.#plans.delete(operationPlanId);
|
|
78
|
+
}
|
|
79
|
+
throw new FinTaxError('CONFIRMATION_REQUIRED', 'The operation plan or confirmation credential is invalid or expired; run the preparation step again');
|
|
80
|
+
}
|
|
81
|
+
return plan;
|
|
82
|
+
}
|
|
83
|
+
#newHandle() {
|
|
84
|
+
return randomBytes(32).toString('base64url');
|
|
85
|
+
}
|
|
86
|
+
#equalHandles(expected, actual) {
|
|
87
|
+
const expectedBytes = Buffer.from(expected);
|
|
88
|
+
const actualBytes = Buffer.from(actual);
|
|
89
|
+
return (expectedBytes.length === actualBytes.length &&
|
|
90
|
+
timingSafeEqual(expectedBytes, actualBytes));
|
|
91
|
+
}
|
|
92
|
+
#pruneExpired(now) {
|
|
93
|
+
for (const [operationPlanId, plan] of this.#plans) {
|
|
94
|
+
if (plan.expiresAtMs <= now)
|
|
95
|
+
this.#plans.delete(operationPlanId);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=operation-plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-plan.js","sourceRo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AO,IAAI,CAAC;IACd,CAAC;IAED,UAAU;QACR,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAED,aAAa,CAAC,QAAgB,EAAE,MAAc;QAC5C,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,CACL,aAAa,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM;YAC3C,eAAe,CAAC,aAAa,EAAE,WAAW,CAAC,CAC5C,CAAC;IACJ,CAAC;IAED,aAAa,CAAC,GAAW;QACvB,KAAK,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAClD,IAAI,IAAI,CAAC,WAAW,IAAI,GAAG;gBAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const SENSITIVE_KEYS = new Set([
|
|
2
|
+
'access_token',
|
|
3
|
+
'authorization',
|
|
4
|
+
'confirmation_token',
|
|
5
|
+
'cookie',
|
|
6
|
+
'password',
|
|
7
|
+
'refresh_token',
|
|
8
|
+
'set-cookie',
|
|
9
|
+
'token',
|
|
10
|
+
]);
|
|
11
|
+
const OMITTED_KEYS = new Set(['file_content', 'lines', 'raw_file']);
|
|
12
|
+
export function redact(value) {
|
|
13
|
+
if (Array.isArray(value))
|
|
14
|
+
return value.map((entry) => redact(entry));
|
|
15
|
+
if (value === null || typeof value !== 'object')
|
|
16
|
+
return value;
|
|
17
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => {
|
|
18
|
+
const normalized = key.toLowerCase();
|
|
19
|
+
if (SENSITIVE_KEYS.has(normalized))
|
|
20
|
+
return [key, '[REDACTED]'];
|
|
21
|
+
if (OMITTED_KEYS.has(normalized))
|
|
22
|
+
return [key, '[OMITTED]'];
|
|
23
|
+
return [key, redact(entry)];
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
export function shortHash(value) {
|
|
27
|
+
return value.length <= 12 ? value : `${value.slice(0, 8)}...`;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=redaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.js","sourceRoot":"","sources":["../../src/policies/redaction.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,cAAc;IACd,eAAe;IACf,oBAAoB;IACpB,QAAQ;IACR,UAAU;IACV,eAAe;IACf,YAAY;IACZ,OAAO;CACR,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAEpE,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACrE,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE9D,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACzC,MAAM,UAAU,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QACrC,IAAI,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC;YAAE,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAC/D,IAAI,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC;YAAE,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAC5D,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9B,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface RetryOptions {
|
|
2
|
+
readonly retries: number;
|
|
3
|
+
readonly baseDelayMs?: number;
|
|
4
|
+
readonly shouldRetry: (error: unknown, attempt: number) => boolean;
|
|
5
|
+
readonly sleep?: (milliseconds: number) => Promise<void>;
|
|
6
|
+
readonly random?: () => number;
|
|
7
|
+
}
|
|
8
|
+
export declare function withRetry<T>(operation: (attempt: number) => Promise<T>, options: RetryOptions): Promise<T>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const defaultSleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
2
|
+
export async function withRetry(operation, options) {
|
|
3
|
+
const sleep = options.sleep ?? defaultSleep;
|
|
4
|
+
const random = options.random ?? Math.random;
|
|
5
|
+
const baseDelayMs = options.baseDelayMs ?? 100;
|
|
6
|
+
for (let attempt = 0;; attempt += 1) {
|
|
7
|
+
try {
|
|
8
|
+
return await operation(attempt);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (attempt >= options.retries || !options.shouldRetry(error, attempt)) {
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
const jitter = 0.5 + random();
|
|
15
|
+
await sleep(baseDelayMs * 2 ** attempt * jitter);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/policies/retry.ts"],"names":[],"mappings":"AAQA,MAAM,YAAY,GAAG,CAAC,YAAoB,EAAE,EAAE,CAC5C,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;AAEpE,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,SAA0C,EAC1C,OAAqB;IAErB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAAC;IAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;IAC7C,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,GAAG,CAAC;IAE/C,KAAK,IAAI,OAAO,GAAG,CAAC,GAAI,OAAO,IAAI,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;gBACvE,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,MAAM,GAAG,GAAG,GAAG,MAAM,EAAE,CAAC;YAC9B,MAAM,KAAK,CAAC,WAAW,GAAG,CAAC,IAAI,OAAO,GAAG,MAAM,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import type { FinTaxError } from '../errors/fintax-error.js';
|
|
3
|
+
export declare function createToolSuccess(output: Record<string, unknown>, summary: string): CallToolResult;
|
|
4
|
+
export declare function createToolFailure(error: FinTaxError, traceId: string): CallToolResult;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function createToolSuccess(output, summary) {
|
|
2
|
+
return {
|
|
3
|
+
content: [{ type: 'text', text: summary }],
|
|
4
|
+
structuredContent: output,
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export function createToolFailure(error, traceId) {
|
|
8
|
+
const failure = {
|
|
9
|
+
ok: false,
|
|
10
|
+
error: {
|
|
11
|
+
code: error.code,
|
|
12
|
+
message: error.message,
|
|
13
|
+
retryable: error.retryable,
|
|
14
|
+
field_errors: [...error.fieldErrors],
|
|
15
|
+
...(error.recovery === undefined ? {} : { recovery: error.recovery }),
|
|
16
|
+
},
|
|
17
|
+
trace_id: traceId,
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
content: [{ type: 'text', text: JSON.stringify(failure) }],
|
|
21
|
+
isError: true,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=tool-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-response.js","sourceRoot":"","sources":["../../src/responses/tool-response.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,iBAAiB,CAC/B,MAA+B,EAC/B,OAAe;IAEf,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QAC1C,iBAAiB,EAAE,MAAM;KAC1B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,KAAkB,EAClB,OAAe;IAEf,MAAM,OAAO,GAAgB;QAC3B,EAAE,EAAE,KAAK;QACT,KAAK,EAAE;YACL,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,YAAY,EAAE,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC;YACpC,GAAG,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;SACtE;QACD,QAAQ,EAAE,OAAO;KAClB,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1D,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|