@settlemint/dalp-sdk 3.1.26-main.37116470199 → 3.1.26
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 +172 -239
- package/dist/api-types.generated.d.ts +14160 -0
- package/dist/api-types.generated.d.ts.map +1 -0
- package/dist/{auth/permissions.d.ts → auth-permissions.d.ts} +8 -0
- package/dist/auth-permissions.d.ts.map +1 -0
- package/dist/{auth/wallet-plugins.d.ts → auth-wallet-plugins.d.ts} +6 -68
- package/dist/auth-wallet-plugins.d.ts.map +1 -0
- package/dist/auth.d.ts +115 -8
- package/dist/auth.d.ts.map +1 -0
- package/dist/bundler.d.ts +217 -0
- package/dist/bundler.d.ts.map +1 -0
- package/dist/chunk-xm8h1dzh.js +33 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/contract-errors.d.ts +4156 -0
- package/dist/contract-errors.d.ts.map +1 -0
- package/dist/contract.d.ts +22 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/cookie-store.d.ts +10 -0
- package/dist/cookie-store.d.ts.map +1 -0
- package/dist/dapi-errors.d.ts +654 -0
- package/dist/dapi-errors.d.ts.map +1 -0
- package/dist/errors.d.ts +637 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +45 -28
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96216 -150
- package/dist/platform.d.ts +41 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +13 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +10 -0
- package/dist/sdk-error.d.ts +74 -0
- package/dist/sdk-error.d.ts.map +1 -0
- package/dist/serializers.d.ts +41 -0
- package/dist/serializers.d.ts.map +1 -0
- package/dist/types.d.ts +114 -37
- package/dist/types.d.ts.map +1 -0
- package/dist/url.d.ts +1 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/verify-webhook.d.ts +28 -17
- package/dist/verify-webhook.d.ts.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.generated.d.ts +8 -0
- package/dist/version.generated.d.ts.map +1 -0
- package/dist/wait-for-transaction.d.ts +86 -44
- package/dist/wait-for-transaction.d.ts.map +1 -0
- package/dist/webhook-events.d.ts +33 -543
- package/dist/webhook-events.d.ts.map +1 -0
- package/package.json +34 -110
- package/dist/auth/client.d.ts +0 -103
- package/dist/auth/invite-step-up.d.ts +0 -2
- package/dist/auth/live.d.ts +0 -47
- package/dist/auth/native-passkey.d.ts +0 -9
- package/dist/auth-surface.d.ts +0 -2
- package/dist/auth.js +0 -525
- package/dist/chunk-4f4kjtt0.js +0 -149
- package/dist/chunk-b03ycwb7.js +0 -68
- package/dist/chunk-ghgcmyhk.js +0 -5
- package/dist/chunk-h241xecg.js +0 -1625
- package/dist/chunk-hqz56e6q.js +0 -4
- package/dist/chunk-k3ntysxx.js +0 -57
- package/dist/chunk-pjjrxre1.js +0 -36
- package/dist/chunk-qvtjb3dz.js +0 -102
- package/dist/chunk-v54k7mgr.js +0 -271
- package/dist/chunk-w361dpdk.js +0 -5
- package/dist/client/conditional-request.d.ts +0 -8
- package/dist/client/factory.d.ts +0 -4
- package/dist/client/query-serializer.d.ts +0 -1
- package/dist/client/request-compression.d.ts +0 -12
- package/dist/client/ssr-fetch.d.ts +0 -10
- package/dist/client/step-up-challenge.d.ts +0 -10
- package/dist/effect.d.ts +0 -38
- package/dist/effect.js +0 -87
- package/dist/errors/api-error.d.ts +0 -35
- package/dist/errors/error-codes.d.ts +0 -21
- package/dist/errors/find-current-error.d.ts +0 -2
- package/dist/errors/sdk-error.d.ts +0 -52
- package/dist/errors/sdk-error.js +0 -8
- package/dist/generated/api-types.d.ts +0 -69961
- package/dist/generated/console-routes.d.ts +0 -12
- package/dist/generated/error-catalog.d.ts +0 -9
- package/dist/generated/error-codes.d.ts +0 -9
- package/dist/generated/response-scalars.d.ts +0 -9
- package/dist/generated/response-schemas.d.ts +0 -9
- package/dist/generated/route-error-codes.d.ts +0 -9
- package/dist/generated/routes.d.ts +0 -12
- package/dist/proxy/builder.d.ts +0 -17
- package/dist/proxy/client-core.d.ts +0 -28
- package/dist/proxy/client.d.ts +0 -5
- package/dist/proxy/fetch-executor.d.ts +0 -6
- package/dist/proxy/flat-args.d.ts +0 -24
- package/dist/proxy/response-decode.d.ts +0 -37
- package/dist/proxy/sse.d.ts +0 -11
- package/dist/proxy/step-up-challenge.d.ts +0 -4
- package/dist/proxy/tanstack.d.ts +0 -6
- package/dist/proxy/transport.d.ts +0 -63
- package/dist/react-query.d.ts +0 -2
- package/dist/react-query.js +0 -12
- package/dist/readonly-deep.d.ts +0 -3
- package/dist/routes/console.d.ts +0 -14
- package/dist/routes/console.js +0 -25
- package/dist/routes/index.d.ts +0 -4
- package/dist/routes/index.js +0 -10
- package/dist/routes/types.d.ts +0 -72
- package/dist/runtime-exports.d.ts +0 -4
- package/dist/runtime-exports.js +0 -16
- package/dist/runtime.d.ts +0 -11
- package/dist/scalars/big-decimal.d.ts +0 -4
- package/dist/scalars/ethereum-address.d.ts +0 -5
- package/dist/scalars/exchange-rates.d.ts +0 -13
- package/dist/scalars/index.d.ts +0 -10
- package/dist/scalars/index.js +0 -102
- package/dist/scalars/organization-id.d.ts +0 -5
- package/dist/scalars/token-decimals.d.ts +0 -4
- package/dist/secret.d.ts +0 -12
- package/dist/sign-webhook-receipt.d.ts +0 -16
- package/dist/sign-webhook-receipt.js +0 -26
- package/dist/transport/cookie-store.d.ts +0 -9
- package/dist/transport/sse-lifecycle.d.ts +0 -24
- package/dist/verify-webhook.js +0 -8
- package/dist/wait-for-transaction.js +0 -151
package/dist/chunk-h241xecg.js
DELETED
|
@@ -1,1625 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DalpSdkError2
|
|
3
|
-
} from "./chunk-k3ntysxx.js";
|
|
4
|
-
import {
|
|
5
|
-
DALP_AUTH_SURFACE_HEADER2,
|
|
6
|
-
Secret2,
|
|
7
|
-
secret2,
|
|
8
|
-
unwrapSecret,
|
|
9
|
-
normalizeDalpBaseUrl,
|
|
10
|
-
detectDalpRuntime,
|
|
11
|
-
runtimeCredentials,
|
|
12
|
-
isBufferingFetch,
|
|
13
|
-
refuseBundledApiKey,
|
|
14
|
-
STEP_UP_CHALLENGE_HEADER,
|
|
15
|
-
WALLET_VERIFICATION_HEADER,
|
|
16
|
-
STEP_UP_CHALLENGE_PATH,
|
|
17
|
-
carriesWalletProof,
|
|
18
|
-
stepUpChallengeRequest
|
|
19
|
-
} from "./chunk-4f4kjtt0.js";
|
|
20
|
-
|
|
21
|
-
// src/errors/find-current-error.ts
|
|
22
|
-
var readProperty = (target, key) => Reflect.get(target, key);
|
|
23
|
-
var findCurrentError = (error, maxNodes = 20) => {
|
|
24
|
-
const queue = [error];
|
|
25
|
-
const seen = new Set;
|
|
26
|
-
let visited = 0;
|
|
27
|
-
while (queue.length > 0 && visited < maxNodes) {
|
|
28
|
-
const current = queue.shift();
|
|
29
|
-
if (current === null || current === undefined || seen.has(current)) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
seen.add(current);
|
|
33
|
-
visited += 1;
|
|
34
|
-
if (current instanceof DalpSdkError2) {
|
|
35
|
-
return current;
|
|
36
|
-
}
|
|
37
|
-
if (typeof current !== "object") {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
queue.push(readProperty(current, "cause"));
|
|
41
|
-
const reasons = readProperty(current, "reasons");
|
|
42
|
-
if (Array.isArray(reasons)) {
|
|
43
|
-
for (const reason of reasons) {
|
|
44
|
-
if (typeof reason === "object" && reason !== null) {
|
|
45
|
-
queue.push(readProperty(reason, "error"), readProperty(reason, "defect"));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/errors/api-error.ts
|
|
54
|
-
class DalpApiError2 extends Error {
|
|
55
|
-
id;
|
|
56
|
-
code;
|
|
57
|
-
routeId;
|
|
58
|
-
category;
|
|
59
|
-
status;
|
|
60
|
-
retryable;
|
|
61
|
-
why;
|
|
62
|
-
fix;
|
|
63
|
-
retryAfterSeconds;
|
|
64
|
-
data;
|
|
65
|
-
constructor(options) {
|
|
66
|
-
super(options.message, { cause: options.cause });
|
|
67
|
-
this.name = "DalpApiError";
|
|
68
|
-
this.id = options.id;
|
|
69
|
-
this.code = options.code;
|
|
70
|
-
this.routeId = options.routeId;
|
|
71
|
-
this.category = options.category;
|
|
72
|
-
this.status = options.status;
|
|
73
|
-
this.retryable = options.retryable;
|
|
74
|
-
this.why = options.why;
|
|
75
|
-
this.fix = options.fix;
|
|
76
|
-
this.retryAfterSeconds = options.retryAfterSeconds;
|
|
77
|
-
this.data = options.data;
|
|
78
|
-
}
|
|
79
|
-
static make(options) {
|
|
80
|
-
return new DalpApiError2(options);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
var isDalpApiError2 = (error) => error instanceof DalpApiError2;
|
|
84
|
-
var findDalpSdkError2 = findCurrentError;
|
|
85
|
-
var API_ERROR_CATEGORIES = new Set([
|
|
86
|
-
"client",
|
|
87
|
-
"auth",
|
|
88
|
-
"permission",
|
|
89
|
-
"domain",
|
|
90
|
-
"contract",
|
|
91
|
-
"dependency",
|
|
92
|
-
"operational",
|
|
93
|
-
"config",
|
|
94
|
-
"unknown"
|
|
95
|
-
]);
|
|
96
|
-
var mapSdkErrorCategory = (category) => {
|
|
97
|
-
if (category === "sdk.configuration") {
|
|
98
|
-
return "config";
|
|
99
|
-
}
|
|
100
|
-
if (API_ERROR_CATEGORIES.has(category)) {
|
|
101
|
-
return category;
|
|
102
|
-
}
|
|
103
|
-
return "operational";
|
|
104
|
-
};
|
|
105
|
-
var makeDalpApiError2 = (error) => {
|
|
106
|
-
const sdkError = findDalpSdkError2(error);
|
|
107
|
-
if (sdkError === undefined) {
|
|
108
|
-
return new DalpApiError2({
|
|
109
|
-
message: "DALP API request failed",
|
|
110
|
-
cause: error,
|
|
111
|
-
code: "sdk.transport.REQUEST_FAILED",
|
|
112
|
-
category: "dependency",
|
|
113
|
-
retryable: true,
|
|
114
|
-
why: "The DALP API request failed before the server returned a structured response.",
|
|
115
|
-
fix: "Check network connectivity and retry the request."
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
const detailsId = sdkError.details?.id;
|
|
119
|
-
return new DalpApiError2({
|
|
120
|
-
message: sdkError.message,
|
|
121
|
-
cause: sdkError,
|
|
122
|
-
id: typeof detailsId === "string" ? detailsId : undefined,
|
|
123
|
-
code: sdkError.code,
|
|
124
|
-
...sdkError.routeId === undefined ? {} : { routeId: sdkError.routeId },
|
|
125
|
-
category: mapSdkErrorCategory(sdkError.category),
|
|
126
|
-
retryable: sdkError.retryable,
|
|
127
|
-
why: sdkError.why,
|
|
128
|
-
fix: sdkError.fix,
|
|
129
|
-
status: sdkError.status,
|
|
130
|
-
retryAfterSeconds: sdkError.retryAfterSeconds,
|
|
131
|
-
data: sdkError.details
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// src/generated/error-codes.ts
|
|
136
|
-
var data = JSON.parse('{"version":1,"codes":["ACTIONS_STREAM_ORIGIN_REJECTED","ACTIVE_ORGANIZATION_REQUIRED","ADMIN_ACCESS_REQUIRED","AIRDROP_ADDON_NOT_FOUND","AIRDROP_NOT_FOUND_INDEXER","AIRDROP_NOT_IN_OWNER_SCOPE","ANCHOR_ENABLEMENT_REFUSED","ANCHOR_LOOKUP_REFUSED","ANCHOR_RETRY_REFUSED","ANCHOR_WRITE_REFUSED","API_MONITORING_LOG_ENTRY_NOT_FOUND","APPROVAL_NOT_FOUND","APPROVAL_REFUSED","APPROVER_SHORTFALL","ARTIFACT_UNAVAILABLE","ASSET_FILTER_FAMILY_MISMATCH","ASSET_REFERENCE_INVALID","ASSET_REF_INVALID","ASSET_SORT_FAMILY_MISMATCH","ASSET_TYPE_TEMPLATE_NOT_FOUND","ASSET_TYPE_TEMPLATE_STORAGE_LOCKED","AUTHORIZATION_CHECK_FAILED","AUTH_STORE_UNAVAILABLE","BAD_REQUEST","BLOCKCHAIN_AUTHORIZATION_DEPENDENCY_FAILED","BLOCKCHAIN_ROLE_REQUIRED","BLOCKCHAIN_SYSTEM_REQUIRED","CANTON_ALLOCATION_REQUEST_EXPIRED","CANTON_APPROVAL_DECISION_CONFLICT","CANTON_APPROVAL_DECISION_FORBIDDEN","CANTON_APPROVAL_EXPIRED","CANTON_CAPABILITY_UNAVAILABLE","CANTON_COMMAND_NO_LONGER_APPLIES","CANTON_FORCED_PATH_CONTRACT_STILL_LIVE","CANTON_INSTRUMENT_NOT_FOUND","CANTON_NETWORK_NOT_CONFIGURED","CANTON_NETWORK_NOT_ENABLED","CANTON_PARTY_WALLET_NOT_FOUND","CANTON_SETTLEMENT_BATCH_NOT_COVERABLE","CANTON_SUBMISSION_FAILED","CANTON_SUBMISSION_REJECTED","CANTON_TOKEN_OPERATION_REQUEST_INVALID","CHAIN_ID_HEADER_INVALID","CHAIN_NOT_AVAILABLE_FOR_ORGANIZATION","CHAIN_NOT_READY","CLAIM_TOPIC_ALREADY_EXISTS","CLAIM_TOPIC_EXCLUSION_ACKNOWLEDGEMENT_REQUIRED","CLAIM_TOPIC_EXCLUSION_REFUSED","COLLECTION_FILTER_VALUE_INVALID","COMPLIANCE_APPLICANT_CREATE_FAILED","COMPLIANCE_INVALID_STATE_TRANSITION","COMPLIANCE_SECRET_ROTATION_GRACE_EXPIRED","COMPLIANCE_TEMPLATE_NOT_READY","COMPLIANCE_TRANSACTION_REGISTER_FAILED","CONFLICT","CONTRACT_ERROR","CONVERSION_INTEREST_BACKLOG_PENDING","CONVERSION_WINDOW_CLOSED","CONVERSION_WINDOW_NOT_OPEN","CORPORATE_ACTION_APPROVAL_REFUSED","CORPORATE_ACTION_ASSET_TYPE","CORPORATE_ACTION_CASH_LEG_BURN_FEE","CORPORATE_ACTION_CASH_LEG_NEEDS_SMART_ACCOUNT","CORPORATE_ACTION_CASH_LEG_SELF_DENOMINATED","CORPORATE_ACTION_CASH_LEG_UNDERFUNDED","CORPORATE_ACTION_CASH_LEG_UNPAYABLE_HOLDER","CORPORATE_ACTION_CASH_LEG_UNVERIFIABLE_ASSET","CORPORATE_ACTION_CASH_LEG_WALLET_MISMATCH","CORPORATE_ACTION_CHILD_NOT_EMPTY","CORPORATE_ACTION_CHILD_UNAUTHORIZED","CORPORATE_ACTION_COMPLETE_ON_CREATE","CORPORATE_ACTION_DIVIDEND_UNLINKED","CORPORATE_ACTION_ELECTION_ABSENT","CORPORATE_ACTION_ELECTION_CLOSED","CORPORATE_ACTION_ELECTION_DEADLINE_INVALID","CORPORATE_ACTION_ELECTION_HOLDER_INELIGIBLE","CORPORATE_ACTION_ELECTION_HOLDER_UNAUTHORIZED","CORPORATE_ACTION_ELECTION_LOCKED","CORPORATE_ACTION_ELECTION_OPEN","CORPORATE_ACTION_ELECTION_OPTION_INVALID","CORPORATE_ACTION_ELECTION_SHAPE_INVALID","CORPORATE_ACTION_FOLLOW_UP_UNKNOWN","CORPORATE_ACTION_HISTORICAL_BALANCES","CORPORATE_ACTION_IDEMPOTENCY_CONFLICT","CORPORATE_ACTION_IN_FLIGHT","CORPORATE_ACTION_NOT_FOUND","CORPORATE_ACTION_PREVIEW_MISMATCH","CORPORATE_ACTION_PREVIEW_REQUIRED","CORPORATE_ACTION_PROGRAM_MISSING","CORPORATE_ACTION_SALE_DISABLED","CORPORATE_ACTION_SALE_MISSING","CORPORATE_ACTION_SALE_TOKEN_MISMATCH","CORPORATE_ACTION_SALE_UNKNOWN","CORPORATE_ACTION_SNAPSHOT_DRIFT","CORPORATE_ACTION_SNAPSHOT_NOT_READY","CORPORATE_ACTION_TOKEN_PAUSED","CORPORATE_ACTION_TOKEN_UNINDEXED","CORPORATE_ACTION_WRONG_STATUS","CUSTODY_ACCOUNT_NOT_FOUND_PUBLIC","CUSTODY_ACCOUNT_SELECTION_INVALID","CUSTODY_APPROVAL_PENDING","CUSTODY_APPROVAL_REJECTED","CUSTODY_CANTON_SIGNING_UNSUPPORTED","CUSTODY_CREDENTIALS_UNAVAILABLE","CUSTODY_PROOF_INVALID","CUSTODY_PROVIDER_CONFIG_CONFLICT","CUSTODY_PROVIDER_CONFIG_INVALID","CUSTODY_WALLET_NOT_SIGNER","DALP-0083","DEBUG_BUNDLE_WINDOW_INVALID","DEPLOYMENT_NOT_FOUND","DEPLOYMENT_STREAM_POLLING_FAILED","DEPLOYMENT_WORKFLOW_TERMINAL_FAILED","DURABLE_EXECUTION_ENGINE_CALL_CONFLICT","DURABLE_EXECUTION_ENGINE_CALL_FAILED","ENS_NOT_CONFIGURED","ERC20_METADATA_PROBE_UNAVAILABLE","EXCHANGE_RATE_CURRENCY_UNSUPPORTED","EXCHANGE_RATE_NOT_FOUND","EXTERNAL_TOKEN_REGISTRATION_REJECTED","FEEDS_FEED_ADDRESS_NOT_FOUND","FEEDS_SUBMIT_OBSERVED_AT_TOO_FAR_IN_FUTURE","FEED_ADDON_NOT_INSTALLED","FEED_BATCH_NOT_SUBMITTABLE","FEED_CONTRACT_INVALID","FEED_DIRECTORY_UNAVAILABLE","FEED_MANAGER_PERMISSION_REQUIRED","FEED_PRICE_NOT_REPRESENTABLE","FEED_ROUND_NOT_FOUND","FEED_SUBMISSION_NOT_AUTHORIZED","FEED_SUBMISSION_SIGNER_AMBIGUOUS","FEED_TOPIC_CONFLICT","FILING_NOT_FOUND","FINANCIAL_YIELD_OPERATION_REJECTED","FIXED_YIELD_DENOMINATION_ASSET_NOT_INDEXED","FIXED_YIELD_OPERATION_ADDON_NOT_FOUND","FIXED_YIELD_OPERATION_DENOMINATION_ASSET_NOT_INDEXED","FIXED_YIELD_OPERATION_DENOMINATION_METADATA_NOT_INDEXED","FIXED_YIELD_OPERATION_DEPLOYMENT_NOT_INDEXED","FIXED_YIELD_OPERATION_SCHEDULE_NOT_FOUND","FIXED_YIELD_OPERATION_SYSTEM_MISMATCH","FIXED_YIELD_OPERATION_TOKEN_LINKAGE_NOT_INDEXED","FORBIDDEN","GOVERNANCE_ACTION_NOT_IN_CATALOG","GOVERNANCE_BALLOT_RATE_LIMITED","GOVERNANCE_BALLOT_REJECTED","GOVERNANCE_DETACH_BLOCKED","GOVERNANCE_POLL_NOT_OPEN","GOVERNANCE_POLL_OPERATOR_REQUIRED","GOVERNANCE_STATE_UNAVAILABLE","GOVERNANCE_TIMELOCK_MISSING_ROLE","INDEXER_BARRIER_TIMEOUT","INPUT_VALIDATION_FAILED","INTERNAL_SERVER_ERROR","INVALID_REQUEST_EXECUTOR","INVITATION_CALLER_CREDENTIAL_REJECTED","INVITATION_CALLER_RATE_LIMITED","INVITATION_CREATE_NOT_PERMITTED","INVITATION_INVITER_NOT_A_MEMBER","INVITATION_LIMIT_REACHED","INVITATION_RECIPIENT_ALREADY_A_MEMBER","LEGACY_BOND_FEATURE_TREASURY_REQUIRED","LEGACY_BOND_NOT_INDEXED","LOGIN_2FA_REQUIRED","MARKET_CALENDAR_INVALID","MARKET_FIELD_IMMUTABLE","MARKET_LISTING_PENDING","MARKET_LISTING_QUEUE_REFUSED","MARKET_LISTING_REFUSED","MARKET_STATE_INVALID","MARKET_STREAM_NOT_FOUND","MARK_REFRESH_COOLDOWN","MARK_REFRESH_DEPENDENCY_FAILED","MATURITY_INSUFFICIENT_ALLOWANCE","MATURITY_NOT_MATURED","MATURITY_REDEMPTION_UNAVAILABLE","MATURITY_STATE_NOT_INDEXED","MATURITY_TREASURY_UNCLASSIFIED","MATURITY_TREASURY_WALLET_MISMATCH","METADATA_NOT_FOUND","MULTISIG_NOT_ENABLED","MULTI_NETWORK_ADMIN_REQUIRED","MULTI_NETWORK_DISABLE_BLOCKED","NOT_FOUND","OBLIGATION_NOT_FOUND","OFFCHAIN_ORGANIZATION_PERMISSION_REQUIRED","OFFCHAIN_USER_PERMISSION_REQUIRED","OIDC_MFA_INVALID","OIDC_MFA_UNAVAILABLE","OPERATIONS_CASE_NOT_FOUND","OPERATIONS_CASE_REFUSED","OPERATIONS_REINDEX_CONFLICT","OPERATION_FAMILY_UNSUPPORTED","ORDER_INTAKE_REJECTED","ORDER_PLACEMENT_IN_FLIGHT","ORDER_SIGNING_FAILED","ORGANIZATION_NOT_FOUND","ORGANIZATION_SUBMISSION_SIGNER_CLAIM_PURPOSE_MISSING","PORTFOLIO_PERSISTENCE_FAILED","PORTFOLIO_RESOURCE_NOT_FOUND","PRECONDITION_FAILED","PRICE_RESOLVER_ADDON_NOT_INSTALLED","PRIMARY_CUSTODY_ACCOUNT_REQUIRED","PROFILE_SECTION_NOT_FOUND","PROFILE_SECTION_STORAGE_LOCKED","PROFILE_SECTION_SYSTEM_READONLY","PROFILE_SECTION_SYSTEM_SLUG_TAKEN","REACH_BACK_EXCEEDED","REINDEX_REQUEST_INVALID","REINDEX_SERVICE_UNREACHABLE","REPORTING_COVERAGE_UNAVAILABLE","REPORTING_FILING_ROW_VERSION_CONFLICT","REPORTING_GENERATION_CONFLICT","REPORTING_UNAVAILABLE","REQUEST_CHAIN_SYSTEM_REQUIRED","REQUEST_CUSTODY_ACCOUNT_UNAVAILABLE","REQUEST_DEADLINE_EXCEEDED","REQUEST_EXECUTOR_FAMILY_UNSUPPORTED","REQUEST_EXECUTOR_UNAVAILABLE","REQUEST_PARTICIPANT_FORBIDDEN","RESERVATION_BUDGET_EXCEEDED","RESOLUTION_FAILED","RETURNS_SNAPSHOT_CONTENTION","SERVICE_UNAVAILABLE","SESSION_EVIDENCE_INVALID","SESSION_POLICY_DENIED","SESSION_RESOLUTION_FAILED","SESSION_REVOCATION_NOT_AUTHORIZED","SETTINGS_TEMPLATE_NAME_ALREADY_EXISTS","SETTINGS_THEME_PAYLOAD_EXCEEDS_SUPPORTED_LIMITS","SETTLEMENT_LEG_BLOCKED","STRICT_COMPLIANCE_PARAMS_INVALID","SYSTEM_ADDON_FACTORY_NOT_FOUND_INDEXER","SYSTEM_COMPLIANCE_MODULE_NOT_REGISTERED_REGISTRY","SYSTEM_IDENTITY_CLAIM_ISSUE","SYSTEM_NOT_FOUND","SYSTEM_PAYMASTER_NOT_FOUND_ADDRESS_INDEXED_LIST_AVAILABLE_PAYMASTERS_VIA_GET","SYSTEM_PAYMASTER_NOT_FOUND_ADDRESS_INDEXED_LIST_AVAILABLE_PAYMASTERS_VIA_GET_V2","SYSTEM_PAYMASTER_SPONSORSHIP_NOT_FOUND_ADDRESS","SYSTEM_TRUSTED_ISSUER_ID_INVALID","TENANT_WALLET_RESOLUTION_FAILED","TOKEN_ACCESS_INTERFACE_UNSUPPORTED","TOKEN_ACCESS_SYNC_RESULT_UNAVAILABLE","TOKEN_ACCESS_UNAUTHORIZED","TOKEN_AMOUNT_DENOMINATION_UNAVAILABLE","TOKEN_BATCH_TRANSFER_FROM_UNSUPPORTED","TOKEN_BRAND_LOGO_REJECTED","TOKEN_CHAIN_UNAVAILABLE","TOKEN_CLAIM_INDEXED_STATE_UNAVAILABLE","TOKEN_CLAIM_ISSUE_FAILED","TOKEN_CLAIM_SIGNING_REFUSED","TOKEN_CLAIM_VALIDATION_FAILED","TOKEN_COMPLIANCE_MODULE_BINDING_UNRESOLVED","TOKEN_CREATE_AMBIGUOUS_INTEREST_PROVIDER","TOKEN_CREATE_ASSET_FAMILY_DEPRECATED","TOKEN_CREATE_DENOMINATION_ASSET_NOT_ERC20","TOKEN_CREATE_DUPLICATE","TOKEN_CREATE_FACTORY_TYPE_NOT_FOUND","TOKEN_CREATE_FEATURES_INCOMPATIBLE","TOKEN_CREATE_INPUT_ENCODING_INVALID","TOKEN_CREATE_MARKCONVERTED_YIELD_INCOMPATIBLE","TOKEN_CREATE_RECOVERY_FAILED","TOKEN_CREATE_REQUIRED_PARAM_MISSING","TOKEN_CREATE_REQUIRED_WINDOW_EXPIRED","TOKEN_CREATE_TEMPLATEID_REQUIRED_DALP_ASSET_CREATION_SELECT_INSTRUMENT_TEMPLATE_CREATING","TOKEN_CREATE_USER_ADDRESS_DOES_NOT_ASSOCIATED_IDENTITY_CONTRACT","TOKEN_CREATE_WORKFLOW_PHASE_FAILED","TOKEN_CREATE_WORKFLOW_RESULT_INVALID","TOKEN_DOCUMENTS_DECLARED_FILE_SIZE_DOES_NOT_MATCH_ACTUAL_STORAGE","TOKEN_DOCUMENTS_DOCUMENT_GROUP_NOT_FOUND_REPLACEMENT","TOKEN_DOCUMENTS_DOCUMENT_NOT_FOUND","TOKEN_DOCUMENTS_DOCUMENT_TYPE_NOT_VALID_ASSET","TOKEN_DOCUMENTS_FAILED_TO_CREATE_DOCUMENT_RECORD","TOKEN_DOCUMENTS_FILE_NOT_FOUND_STORAGE_UPLOAD_FAILED","TOKEN_DOCUMENTS_INVALID_OBJECT_KEY","TOKEN_DOCUMENTS_READ_DOCUMENT_NOT_FOUND","TOKEN_DOCUMENTS_READ_HOLDER_REQUIRED","TOKEN_DOCUMENTS_READ_RESTRICTED","TOKEN_FEATURES_FIXED_TREASURY_YIELD_FEATURE_STATE_NOT_YET_INDEXED_INDEXER_PROCESSED_INITIA","TOKEN_FEATURES_NO_YIELD_AVAILABLE_CLAIM_FIRST_PERIOD_NOT_COMPLETED_YET","TOKEN_FEATURES_NO_YIELD_AVAILABLE_FOR_HOLDER","TOKEN_FEATURES_UNAVAILABLE","TOKEN_FEATURES_YIELD_FULLY_CONSUMED","TOKEN_FEATURE_ALREADY_ATTACHED","TOKEN_FEATURE_CONVERSION_INCOMPATIBLE","TOKEN_FEATURE_CONVERSION_PROVIDER_UNRESOLVABLE","TOKEN_FEATURE_DETACH_BLOCKED_BY_DEPENDENTS","TOKEN_FEATURE_DIVIDENDS_OUTSTANDING","TOKEN_FEATURE_FACTORY_NOT_FOUND","TOKEN_FEATURE_FEATURE_NOT_FOUND","TOKEN_FEATURE_NAME_MISMATCH","TOKEN_FEATURE_PERSISTENCE_FAILED","TOKEN_FEATURE_STALE_INDEX","TOKEN_FEATURE_UNCHANGED_ADDRESS","TOKEN_FEE_RATES_FROZEN","TOKEN_FORCED_TRANSFER_MISSING_ITEM","TOKEN_FUNDING_PAUSE_FAILED","TOKEN_HISTORICAL_BALANCE_BLOCK_NOT_INDEXED","TOKEN_INDEXER_DATA_INVALID","TOKEN_INDEXER_TOKEN_NOT_FOUND","TOKEN_ISSUANCE_RUN_CONFLICT","TOKEN_ISSUANCE_RUN_DECLARATION_INVALID","TOKEN_ISSUANCE_RUN_NOT_FOUND","TOKEN_LIFECYCLE_CUSTODIAN_REQUIRED","TOKEN_LIFECYCLE_VALIDATION_FAILED","TOKEN_LIST_FACTORY_NOT_FOUND","TOKEN_LIST_FACTORY_REGISTRY_UNAVAILABLE","TOKEN_LIST_FILTER_INVALID","TOKEN_LIST_METADATA_KEY_IDENTIFIER_INELIGIBLE","TOKEN_LIST_METADATA_KEY_NOT_BUCKETABLE","TOKEN_LIST_METADATA_KEY_UNKNOWN","TOKEN_METADATA_OFFCHAIN_IMMUTABLE","TOKEN_METADATA_VALUES_INVALID","TOKEN_MINT_AMOUNT_INVALID","TOKEN_MINT_MATURITY_REDEMPTION_MATURED","TOKEN_MUTATION_INSUFFICIENT_BALANCE","TOKEN_NOT_FOUND","TOKEN_OPERATION_INPUT_INVALID","TOKEN_PERMIT_ALREADY_RELAYED","TOKEN_PERMIT_DEADLINE_EXPIRED","TOKEN_PERMIT_FEATURE_UNAVAILABLE","TOKEN_PERMIT_NONCE_CONFLICT","TOKEN_PERMIT_NOT_FOUND","TOKEN_PERMIT_NOT_RELAYABLE","TOKEN_PERMIT_PERSISTENCE_FAILED","TOKEN_PERMIT_READ_REFUSED","TOKEN_PERMIT_SIGNING_FAILED","TOKEN_PERMIT_WALLET_UNAVAILABLE","TOKEN_PRICE_DENOMINATION_UNUSABLE","TOKEN_PRICE_FEED_FACTORY_MISSING","TOKEN_PRICE_FEED_FACTORY_UNAVAILABLE","TOKEN_PRICE_FEED_SIGNER_MISSING","TOKEN_PRICE_IDENTITY_REQUIRED","TOKEN_PRICE_INPUT_INVALID","TOKEN_PRICE_RESOLUTION_FAILED","TOKEN_PRICE_TOKEN_UNAVAILABLE","TOKEN_PRICE_UNSUPPORTED_TOKEN","TOKEN_PRICE_UPDATE_FAILED","TOKEN_QUEUE_WRITE_REFUSED","TOKEN_READ_DEPENDENCY_FAILED","TOKEN_SALE_ADDON_NOT_IN_OWNER_SCOPE_AUTHENTICATED","TOKEN_SALE_CANNOT_WITHDRAW_SALE_TOKEN_CURRENCY","TOKEN_SUPPLY_PAUSED","TOKEN_TRANSFER_APPROVAL_VALIDATION","TOKEN_TRANSFER_MISSING_ITEM","TOKEN_TRANSFER_PAUSED","TOKEN_WORKFLOW_FAILED","TOKEN_WRITE_OUTCOME_UNKNOWN","TOKEN_WRITE_PERSISTENCE_FAILED","TOKEN_WRITE_RECEIPT_INCOMPLETE","TOKEN_WRITE_REVERTED","TOO_MANY_REQUESTS","TRADE_BUST_APPROVAL_INVALID","TRADE_BUST_EXECUTION_REFUSED","TRADE_BUST_REFUSED","TRADING_VENUE_MARKET_NOT_FOUND","TRADING_VENUE_ORDER_NOT_FOUND","TRANSACTION_NOT_FOUND","TRANSACTION_PREPARATION_EXPIRED","TRANSACTION_PROVIDER_READ_FAILED","TRANSACTION_QUEUE_CONFIRMATION_TIMEOUT","TRANSACTION_QUEUE_DEAD_LETTER","TRANSACTION_QUEUE_UNPROCESSABLE","TREASURY_HEALTH_BOND_STATUS_UNAVAILABLE","TREASURY_HEALTH_TREASURY_MISMATCH","TREASURY_HEALTH_TREASURY_UNCONFIGURED","TREASURY_WALLET_MISMATCH","UNAUTHORIZED","UNPROCESSABLE_ENTITY","USER_ASSETS_METADATA_KEY_INVALID","USER_IMAGE_INVALID","USER_IMAGE_KEY_FORBIDDEN","USER_IMAGE_STORAGE_FAILED","USER_KYC_PROFILE_NOT_FOUND_ACTION","USER_MISSING_2FA","USER_SECURITY_TARGET_NOT_FOUND","VENUE_CONFIGURATION_REQUIRED","VENUE_CREATION_REFUSED","VENUE_DEPLOYMENT_PENDING","VENUE_ROLE_REQUIRED","VOTING_OPERATION_REJECTED","WALLET_STEP_UP_CHALLENGE_REFUSED","WALLET_VERIFICATION_CAPACITY","WALLET_VERIFICATION_DEPENDENCY_FAILED","WALLET_VERIFICATION_INVALID","WALLET_VERIFICATION_NOT_CONFIGURED","WALLET_VERIFICATION_REQUIRED","WALLET_VERIFICATION_THROTTLED","WEBHOOK_CREATE_IN_PROGRESS","WEBHOOK_DELIVERY_NOT_FOUND","WEBHOOK_ENDPOINT_DISABLED","WEBHOOK_ENDPOINT_LIMIT_REACHED","WEBHOOK_ENDPOINT_NOT_FOUND","WEBHOOK_FAT_ACK_INCOMPLETE","WEBHOOK_IDEMPOTENCY_KEY_REUSED","WEBHOOK_PENDING_RETARGET_REQUIRED","WEBHOOK_RECALL_NOT_AUTHORIZED","WEBHOOK_RECEIPT_NOT_FOUND","WEBHOOK_REPLAY_RANGE_TOO_LARGE","WEBHOOK_REPLAY_RATE_LIMITED","WEBHOOK_SIGNING_VERIFICATION_FAILED","WEBHOOK_SUBSCRIPTION_INVALID","WEBHOOK_SYSTEM_SCOPE_REQUIRED","WEBHOOK_URL_PRIVATE_RANGE","WEBHOOK_URL_SCHEME_REQUIRED","XVP_APPROVAL_NOT_FOUND","XVP_CREATE_COULD_NOT_RESOLVE_CREATED_SETTLEMENT_INDEXER_RETRIES","XVP_HASHLOCK_INVALID","XVP_HASHLOCK_REVEAL_NOT_REQUIRED","X_EXECUTOR_AA_DISABLED_FOR_ORG","X_EXECUTOR_AA_DISABLED_GLOBALLY","auth.apikey.THROTTLED","compliance.executor.DEPENDENCY_UNAVAILABLE","compliance.expression.NOT_NARROWED","compliance.kyc.DEPENDENCY_UNAVAILABLE","compliance.kyc.DOCUMENT_CONFLICT","compliance.kyc.EVIDENCE_DENIED","compliance.module.CONFIG_CONTRADICTION","compliance.module.STATE_INVALID","compliance.provider.CREDENTIALS_INVALID","compliance.provider.UNAVAILABLE","compliance.scope.DENIED","compliance.write.OUTCOME_UNKNOWN","core.database.QUERY_FAILED","custody.write.OUTCOME_UNKNOWN","dapi.assets.CONVERSION_FEATURE_PROBE_READ_FAILED","dapi.assets.TOKEN_ACCESS_LAST_ADMINISTRATOR","dapi.assets.TOKEN_ACCESS_PARTICIPANT_UNAVAILABLE","dapi.assets.TOKEN_ACCESS_ROLE_INVALID","dapi.assets.TOKEN_ACCESS_UNAVAILABLE","dapi.assets.TOKEN_CREATE_STREAM_LOOKUP_FAILED","dapi.assets.TOKEN_CREATE_STREAM_NOT_FOUND","dapi.assets.TOKEN_CREATE_STREAM_STEP_FAILED","dapi.assets.TOKEN_PRICE_ADMIN_REQUIRED","dapi.erc20_metadata.PROBE_FAILED","dapi.identity.CLAIM_ISSUE_DEPENDENCY_FAILED","dapi.identity.CLAIM_TOPIC_EXCLUSION_POLICY_DEPENDENCY_FAILED","dapi.identity.CLAIM_TOPIC_READ_DEPENDENCY_FAILED","dapi.identity.REGISTER_PENDING_DEPENDENCY_FAILED","dapi.runtime.EXTERNAL_MESSAGE_AUTHORIZATION_INVALID","dapi.runtime.EXTERNAL_MESSAGE_AUTHORIZATION_REQUIRED","dapi.runtime.INVALID_REQUEST_CUSTODY_ACCOUNT","dapi.runtime.REQUEST_CHAIN_LOOKUP_FAILED","dapi.transfer-simulation.UNAVAILABLE","exec.aa.READ_DEPENDENCY","exec.queue.DEPENDENCY","exec.queue.OUTCOME_UNKNOWN","party.dependency.FAILED","party.participant.WALLET_TYPE_CONFLICT","party.write.OUTCOME_UNKNOWN","platform.http.ACCESS_DENIED","platform.http.DEPENDENCY_UNAVAILABLE","platform.http.INVITATION_ALREADY_ACCEPTED","platform.http.INVITATION_CANCELED","platform.http.INVITATION_EXPIRED","platform.http.INVITATION_NATIONAL_ID_CONFLICT","platform.http.INVITATION_ORGANIZATION_ARCHIVED","platform.http.INVITATION_ROLES_NOT_AUTHORIZED","platform.http.NETWORK_CATALOG_INVALID","platform.http.NETWORK_DEFINITION_INVALID","platform.http.NETWORK_HAS_UPSTREAM_POOL","platform.http.NETWORK_IN_USE","platform.http.REINDEXING","platform.http.REQUEST_INVALID","platform.http.STORAGE_UNAVAILABLE","platform.write.OUTCOME_UNKNOWN","platform.write.ROLE_BATCH_FAILED","portfolio.http.WRITE_OUTCOME_UNKNOWN","portfolio.polls.SIGNING_PENDING","settlement.http.DEPENDENCY_UNAVAILABLE","settlement.http.PRECONDITION_FAILED","settlement.http.SECRET_FAILED","settlement.sale.DOCUMENT_REJECTED","wire.http.SESSION_REQUIRED"]}');
|
|
137
|
-
|
|
138
|
-
// src/errors/error-codes.ts
|
|
139
|
-
var PUBLISHED_ERROR_CODES = new Set(data.codes);
|
|
140
|
-
var SDK_LOCAL_ERROR_CODES = new Set([
|
|
141
|
-
"DALP_SDK_ERROR",
|
|
142
|
-
"sdk.transport.REQUEST_FAILED",
|
|
143
|
-
"sdk.transport.MALFORMED_RESPONSE",
|
|
144
|
-
"sdk.transport.UNPUBLISHED_ERROR_CODE",
|
|
145
|
-
"sdk.transport.UNVERIFIED_ERROR_CODE",
|
|
146
|
-
"sdk.response.MALFORMED_SUCCESS",
|
|
147
|
-
"sdk.stream.FAILED",
|
|
148
|
-
"sdk.stream.UNREADABLE_BODY",
|
|
149
|
-
"sdk.scalar.BIG_DECIMAL_INVALID",
|
|
150
|
-
"sdk.scalar.EVM_ADDRESS_INVALID",
|
|
151
|
-
"sdk.scalar.ORGANIZATION_ID_INVALID",
|
|
152
|
-
"sdk.scalar.TOKEN_DECIMALS_INVALID"
|
|
153
|
-
]);
|
|
154
|
-
var HTTP_STATUS_CODE = /^sdk\.transport\.HTTP_\d+$/u;
|
|
155
|
-
var isDalpErrorCode2 = (code) => PUBLISHED_ERROR_CODES.has(code);
|
|
156
|
-
var isDalpSdkLocalErrorCode2 = (code) => SDK_LOCAL_ERROR_CODES.has(code) || HTTP_STATUS_CODE.test(code);
|
|
157
|
-
var isDalpApiErrorCode2 = (code) => isDalpErrorCode2(code) || isDalpSdkLocalErrorCode2(code);
|
|
158
|
-
var routeErrorCodes;
|
|
159
|
-
var loadedRouteErrorCodes;
|
|
160
|
-
async function importRouteErrorCodes() {
|
|
161
|
-
const { data: data2 } = await import("./chunk-w361dpdk.js");
|
|
162
|
-
return data2;
|
|
163
|
-
}
|
|
164
|
-
async function loadRouteErrorCodes() {
|
|
165
|
-
routeErrorCodes ??= importRouteErrorCodes();
|
|
166
|
-
try {
|
|
167
|
-
loadedRouteErrorCodes = await routeErrorCodes;
|
|
168
|
-
return loadedRouteErrorCodes;
|
|
169
|
-
} catch (error) {
|
|
170
|
-
routeErrorCodes = undefined;
|
|
171
|
-
throw error;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
var routePublishes = (table, routeId, code) => (table.routes[routeId] ?? []).some((position) => data.codes[position] === code);
|
|
175
|
-
async function checkRouteErrorCode(routeId, code) {
|
|
176
|
-
if (!isDalpErrorCode2(code)) {
|
|
177
|
-
return { kind: "unpublished" };
|
|
178
|
-
}
|
|
179
|
-
let table;
|
|
180
|
-
try {
|
|
181
|
-
table = await loadRouteErrorCodes();
|
|
182
|
-
} catch {
|
|
183
|
-
return { kind: "unverified" };
|
|
184
|
-
}
|
|
185
|
-
return routePublishes(table, routeId, code) ? { kind: "published", code } : { kind: "unpublished" };
|
|
186
|
-
}
|
|
187
|
-
var answeredByRoute = (error, routeIds) => {
|
|
188
|
-
const { routeId, code } = error;
|
|
189
|
-
if (routeId === undefined || !routeIds.includes(routeId)) {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
if (isDalpSdkLocalErrorCode2(code)) {
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
return loadedRouteErrorCodes !== undefined && routePublishes(loadedRouteErrorCodes, routeId, code);
|
|
196
|
-
};
|
|
197
|
-
var isDalpRouteError2 = (error, ...routeIds) => isDalpApiError2(error) && answeredByRoute(error, routeIds);
|
|
198
|
-
|
|
199
|
-
// src/client/query-serializer.ts
|
|
200
|
-
function appendQueryValue(search, path, value) {
|
|
201
|
-
if (value === undefined || value === null) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (value instanceof Date) {
|
|
205
|
-
search.append(path, value.toISOString());
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
if (Array.isArray(value)) {
|
|
209
|
-
for (const [index, item] of value.entries()) {
|
|
210
|
-
const itemPath = typeof item === "object" && item !== null ? `${path}[${String(index)}]` : path;
|
|
211
|
-
appendQueryValue(search, itemPath, item);
|
|
212
|
-
}
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
if (typeof value === "object") {
|
|
216
|
-
for (const [key, item] of Object.entries(value)) {
|
|
217
|
-
appendQueryValue(search, `${path}[${key}]`, item);
|
|
218
|
-
}
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
search.append(path, String(value));
|
|
222
|
-
}
|
|
223
|
-
function serializeDalpQuery(query) {
|
|
224
|
-
const search = new URLSearchParams;
|
|
225
|
-
if (typeof query === "object" && query !== null) {
|
|
226
|
-
for (const [key, value] of Object.entries(query)) {
|
|
227
|
-
appendQueryValue(search, key, value);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return search.toString();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// src/client/request-compression.ts
|
|
234
|
-
var DALP_SDK_REQUEST_COMPRESSION_MIN_BODY_BYTES = 1024;
|
|
235
|
-
var DALP_SDK_REQUEST_COMPRESSION_MAX_BODY_BYTES = 16777216;
|
|
236
|
-
var NO_BODY_METHODS = new Set(["GET", "HEAD"]);
|
|
237
|
-
function bufferedBodySize(body) {
|
|
238
|
-
if (typeof body === "string") {
|
|
239
|
-
return Buffer.byteLength(body);
|
|
240
|
-
}
|
|
241
|
-
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {
|
|
242
|
-
return body.byteLength;
|
|
243
|
-
}
|
|
244
|
-
if (body instanceof Blob) {
|
|
245
|
-
return body.size;
|
|
246
|
-
}
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
function isCompressibleMediaType(contentType) {
|
|
250
|
-
const mediaType = contentType?.split(";")[0]?.trim().toLowerCase();
|
|
251
|
-
if (mediaType === undefined || mediaType === "") {
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
return mediaType === "application/json" || mediaType.endsWith("+json") || mediaType.startsWith("text/");
|
|
255
|
-
}
|
|
256
|
-
async function cancelReaderBestEffort(reader) {
|
|
257
|
-
try {
|
|
258
|
-
await reader.cancel();
|
|
259
|
-
} catch {}
|
|
260
|
-
}
|
|
261
|
-
async function readRequestBodyWithinCap(request, maxBodyBytes) {
|
|
262
|
-
let body;
|
|
263
|
-
try {
|
|
264
|
-
const { body: clonedBody } = request.clone();
|
|
265
|
-
body = clonedBody;
|
|
266
|
-
} catch {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
if (body === null) {
|
|
270
|
-
return Buffer.alloc(0);
|
|
271
|
-
}
|
|
272
|
-
const reader = body.getReader();
|
|
273
|
-
const chunks = [];
|
|
274
|
-
let totalBytes = 0;
|
|
275
|
-
try {
|
|
276
|
-
while (true) {
|
|
277
|
-
const next = await reader.read();
|
|
278
|
-
if (next.done) {
|
|
279
|
-
return Buffer.concat(chunks, totalBytes);
|
|
280
|
-
}
|
|
281
|
-
totalBytes += next.value.byteLength;
|
|
282
|
-
if (totalBytes > maxBodyBytes) {
|
|
283
|
-
cancelReaderBestEffort(reader);
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
chunks.push(next.value);
|
|
287
|
-
}
|
|
288
|
-
} catch {
|
|
289
|
-
return;
|
|
290
|
-
} finally {
|
|
291
|
-
reader.releaseLock();
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
function withRequestBodyCompression(fetchImpl, options) {
|
|
295
|
-
const minBodyBytes = options?.minBodyBytes ?? DALP_SDK_REQUEST_COMPRESSION_MIN_BODY_BYTES;
|
|
296
|
-
const maxBodyBytes = options?.maxBodyBytes ?? DALP_SDK_REQUEST_COMPRESSION_MAX_BODY_BYTES;
|
|
297
|
-
const requestCompressionFetch = async (input, init) => {
|
|
298
|
-
if (init?.compress !== undefined) {
|
|
299
|
-
return fetchImpl(input, init);
|
|
300
|
-
}
|
|
301
|
-
let request;
|
|
302
|
-
if (input instanceof Request) {
|
|
303
|
-
request = init === undefined ? input : new Request(input, init);
|
|
304
|
-
}
|
|
305
|
-
const method = (request?.method ?? init?.method ?? "GET").toUpperCase();
|
|
306
|
-
if (NO_BODY_METHODS.has(method)) {
|
|
307
|
-
return fetchImpl(input, init);
|
|
308
|
-
}
|
|
309
|
-
const headers = new Headers(request?.headers ?? init?.headers);
|
|
310
|
-
if (headers.get("content-encoding") !== null) {
|
|
311
|
-
return fetchImpl(input, init);
|
|
312
|
-
}
|
|
313
|
-
let compress;
|
|
314
|
-
let bufferedRequestBody;
|
|
315
|
-
if (request !== undefined && request.body !== null && isCompressibleMediaType(headers.get("content-type"))) {
|
|
316
|
-
bufferedRequestBody = await readRequestBodyWithinCap(request, maxBodyBytes);
|
|
317
|
-
if (bufferedRequestBody !== undefined && bufferedRequestBody.byteLength >= minBodyBytes) {
|
|
318
|
-
compress = "gzip";
|
|
319
|
-
}
|
|
320
|
-
} else if (init?.body !== null && init?.body !== undefined) {
|
|
321
|
-
const size = bufferedBodySize(init.body);
|
|
322
|
-
if (size !== undefined && size >= minBodyBytes && size <= maxBodyBytes) {
|
|
323
|
-
compress = "gzip";
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
if (compress === undefined) {
|
|
327
|
-
return fetchImpl(input, init);
|
|
328
|
-
}
|
|
329
|
-
if (request !== undefined && bufferedRequestBody !== undefined) {
|
|
330
|
-
return fetchImpl(request.url, {
|
|
331
|
-
...init,
|
|
332
|
-
body: bufferedRequestBody,
|
|
333
|
-
cache: init?.cache ?? request.cache,
|
|
334
|
-
compress,
|
|
335
|
-
credentials: init?.credentials ?? request.credentials,
|
|
336
|
-
headers: request.headers,
|
|
337
|
-
integrity: init?.integrity ?? request.integrity,
|
|
338
|
-
keepalive: init?.keepalive ?? request.keepalive,
|
|
339
|
-
method: request.method,
|
|
340
|
-
mode: init?.mode ?? request.mode,
|
|
341
|
-
redirect: init?.redirect ?? request.redirect,
|
|
342
|
-
referrer: init?.referrer ?? request.referrer,
|
|
343
|
-
referrerPolicy: init?.referrerPolicy ?? request.referrerPolicy,
|
|
344
|
-
signal: init?.signal ?? request.signal
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
return fetchImpl(input, { ...init, compress });
|
|
348
|
-
};
|
|
349
|
-
return Object.assign(requestCompressionFetch, {
|
|
350
|
-
preconnect: fetchImpl.preconnect
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// src/client/ssr-fetch.ts
|
|
355
|
-
class DalpSsrSecurityError extends Error {
|
|
356
|
-
name = "DalpSsrSecurityError";
|
|
357
|
-
}
|
|
358
|
-
var originOf = (value) => {
|
|
359
|
-
const url = new URL(value);
|
|
360
|
-
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
361
|
-
throw new DalpSsrSecurityError(`DALP SDK: ${url.protocol} is not an approved SSR protocol.`);
|
|
362
|
-
}
|
|
363
|
-
return url.origin;
|
|
364
|
-
};
|
|
365
|
-
var REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
366
|
-
var SENSITIVE_HEADERS = [
|
|
367
|
-
"authorization",
|
|
368
|
-
"baggage",
|
|
369
|
-
"cookie",
|
|
370
|
-
"idempotency-key",
|
|
371
|
-
"origin",
|
|
372
|
-
"referer",
|
|
373
|
-
"traceparent",
|
|
374
|
-
"tracestate",
|
|
375
|
-
"x-api-key",
|
|
376
|
-
"x-chain-id",
|
|
377
|
-
"x-executor",
|
|
378
|
-
"x-organization-id",
|
|
379
|
-
"x-participant",
|
|
380
|
-
"x-selected-signers"
|
|
381
|
-
];
|
|
382
|
-
var withoutSensitiveHeaders = (source) => {
|
|
383
|
-
const headers = new Headers(source);
|
|
384
|
-
for (const name of SENSITIVE_HEADERS) {
|
|
385
|
-
headers.delete(name);
|
|
386
|
-
}
|
|
387
|
-
return headers;
|
|
388
|
-
};
|
|
389
|
-
function createSsrFetch(options) {
|
|
390
|
-
const incoming = new Headers(options.requestHeaders);
|
|
391
|
-
const approvedOrigins = new Set([originOf(options.baseUrl), ...(options.allowedOrigins ?? []).map(originOf)]);
|
|
392
|
-
const ssrFetch = async (input, init) => {
|
|
393
|
-
const request = input instanceof Request && init === undefined ? input : new Request(input, init);
|
|
394
|
-
if (!approvedOrigins.has(new URL(request.url).origin)) {
|
|
395
|
-
throw new DalpSsrSecurityError(`DALP SDK: ${request.url} is not an approved SSR destination.`);
|
|
396
|
-
}
|
|
397
|
-
const cookie = incoming.get("cookie");
|
|
398
|
-
if (cookie !== null && !["GET", "HEAD", "OPTIONS"].includes(request.method)) {
|
|
399
|
-
const incomingOrigin = incoming.get("origin");
|
|
400
|
-
let trustedOrigin = false;
|
|
401
|
-
try {
|
|
402
|
-
trustedOrigin = incomingOrigin !== null && approvedOrigins.has(originOf(incomingOrigin));
|
|
403
|
-
} catch {
|
|
404
|
-
trustedOrigin = false;
|
|
405
|
-
}
|
|
406
|
-
if (!trustedOrigin || incoming.get("sec-fetch-site") === "cross-site") {
|
|
407
|
-
throw new DalpSsrSecurityError("DALP SDK: a cookie-authenticated SSR mutation requires a trusted Origin.");
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
const headers = new Headers(request.headers);
|
|
411
|
-
if (cookie === null) {
|
|
412
|
-
headers.delete("cookie");
|
|
413
|
-
} else {
|
|
414
|
-
headers.set("cookie", cookie);
|
|
415
|
-
}
|
|
416
|
-
for (const name of ["origin", "traceparent", "tracestate", "baggage"]) {
|
|
417
|
-
const value = incoming.get(name);
|
|
418
|
-
if (value !== null && !headers.has(name)) {
|
|
419
|
-
headers.set(name, value);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
let current = new Request(request, { headers, redirect: "manual" });
|
|
423
|
-
let sensitiveAllowed = true;
|
|
424
|
-
for (let redirectCount = 0;redirectCount <= 5; redirectCount += 1) {
|
|
425
|
-
const replay = current.clone();
|
|
426
|
-
const response = await options.fetch(current, { credentials: "omit", redirect: "manual" });
|
|
427
|
-
const location = response.headers.get("location");
|
|
428
|
-
if (!REDIRECT_STATUSES.has(response.status) || location === null) {
|
|
429
|
-
return response;
|
|
430
|
-
}
|
|
431
|
-
if (redirectCount === 5) {
|
|
432
|
-
throw new DalpSsrSecurityError("DALP SDK: SSR fetch exceeded the redirect limit.");
|
|
433
|
-
}
|
|
434
|
-
const nextUrl = new URL(location, current.url);
|
|
435
|
-
sensitiveAllowed = sensitiveAllowed && approvedOrigins.has(nextUrl.origin);
|
|
436
|
-
const redirectToGet = response.status === 303 || (response.status === 301 || response.status === 302) && replay.method === "POST";
|
|
437
|
-
const method = redirectToGet ? "GET" : replay.method;
|
|
438
|
-
if (!sensitiveAllowed && method !== "GET" && method !== "HEAD") {
|
|
439
|
-
throw new DalpSsrSecurityError("DALP SDK: refused to forward an SSR request body outside the trust boundary.");
|
|
440
|
-
}
|
|
441
|
-
const nextHeaders = sensitiveAllowed ? new Headers(replay.headers) : withoutSensitiveHeaders(replay.headers);
|
|
442
|
-
if (redirectToGet) {
|
|
443
|
-
nextHeaders.delete("content-length");
|
|
444
|
-
nextHeaders.delete("content-type");
|
|
445
|
-
}
|
|
446
|
-
current = new Request(nextUrl, {
|
|
447
|
-
body: method === "GET" || method === "HEAD" ? undefined : await replay.arrayBuffer(),
|
|
448
|
-
credentials: sensitiveAllowed ? replay.credentials : "omit",
|
|
449
|
-
headers: nextHeaders,
|
|
450
|
-
method,
|
|
451
|
-
redirect: "manual",
|
|
452
|
-
signal: replay.signal
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
throw new DalpSsrSecurityError("DALP SDK: unreachable redirect state.");
|
|
456
|
-
};
|
|
457
|
-
return Object.assign(ssrFetch, {
|
|
458
|
-
preconnect: options.fetch.preconnect ?? (() => {})
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// src/client/conditional-request.ts
|
|
463
|
-
var IF_NONE_MATCH = "If-None-Match";
|
|
464
|
-
var CONDITIONAL_RESPONSE_STORE_CAPACITY = 64;
|
|
465
|
-
var CONDITIONAL_RESPONSE_MAX_BODY_BYTES = 1048576;
|
|
466
|
-
var IDENTITY_RESET_PATH_SUFFIXES = [
|
|
467
|
-
"/api/auth/sign-out",
|
|
468
|
-
"/api/auth/revoke-session",
|
|
469
|
-
"/api/auth/revoke-other-sessions",
|
|
470
|
-
"/api/auth/organization/set-active"
|
|
471
|
-
];
|
|
472
|
-
var headerOrDefault = (headers, name) => headers.get(name)?.trim() || "default";
|
|
473
|
-
var tenantOf = (headers) => `${headerOrDefault(headers, "X-Organization-Id")}\x00${headerOrDefault(headers, "X-Participant")}`;
|
|
474
|
-
var resourceKey = (request) => {
|
|
475
|
-
const url = new URL(request.url);
|
|
476
|
-
return `${url.origin}${url.pathname}${url.search}\x00${tenantOf(request.headers)}`;
|
|
477
|
-
};
|
|
478
|
-
var isIdentityResetPath = (url) => {
|
|
479
|
-
const path = new URL(url).pathname;
|
|
480
|
-
return IDENTITY_RESET_PATH_SUFFIXES.some((suffix) => path === suffix || path.endsWith(suffix));
|
|
481
|
-
};
|
|
482
|
-
var isEventStream = (response) => (response.headers.get("content-type") ?? "").includes("text/event-stream");
|
|
483
|
-
var remember = (store, key, entry) => {
|
|
484
|
-
store.delete(key);
|
|
485
|
-
store.set(key, entry);
|
|
486
|
-
if (store.size > CONDITIONAL_RESPONSE_STORE_CAPACITY) {
|
|
487
|
-
const oldest = store.keys().next().value;
|
|
488
|
-
if (oldest !== undefined) {
|
|
489
|
-
store.delete(oldest);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
var touch = (store, key) => {
|
|
494
|
-
const entry = store.get(key);
|
|
495
|
-
if (entry === undefined) {
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
store.delete(key);
|
|
499
|
-
store.set(key, entry);
|
|
500
|
-
return entry;
|
|
501
|
-
};
|
|
502
|
-
var requestWithoutIfNoneMatch = (request) => {
|
|
503
|
-
const headers = new Headers;
|
|
504
|
-
for (const [name, value] of request.headers.entries()) {
|
|
505
|
-
if (name.toLowerCase() !== IF_NONE_MATCH.toLowerCase()) {
|
|
506
|
-
headers.append(name, value);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
return new Request(request.url, {
|
|
510
|
-
method: request.method,
|
|
511
|
-
headers,
|
|
512
|
-
signal: request.signal,
|
|
513
|
-
credentials: request.credentials,
|
|
514
|
-
redirect: request.redirect
|
|
515
|
-
});
|
|
516
|
-
};
|
|
517
|
-
async function captureSuccessfulGet(store, key, response) {
|
|
518
|
-
if (!response.ok || isEventStream(response)) {
|
|
519
|
-
return response;
|
|
520
|
-
}
|
|
521
|
-
const etag = response.headers.get("etag")?.trim();
|
|
522
|
-
if (etag === undefined || etag.length === 0) {
|
|
523
|
-
store.delete(key);
|
|
524
|
-
return response;
|
|
525
|
-
}
|
|
526
|
-
const body = await response.blob();
|
|
527
|
-
const headers = new Headers(response.headers);
|
|
528
|
-
headers.set("etag", etag);
|
|
529
|
-
if (body.size <= CONDITIONAL_RESPONSE_MAX_BODY_BYTES) {
|
|
530
|
-
remember(store, key, { body, etag, headers });
|
|
531
|
-
}
|
|
532
|
-
return new Response(body, {
|
|
533
|
-
headers,
|
|
534
|
-
status: response.status,
|
|
535
|
-
statusText: response.statusText
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
function withConditionalRequests(base) {
|
|
539
|
-
const state = { store: new Map, lastIdentity: undefined };
|
|
540
|
-
const syncIdentity = (headers) => {
|
|
541
|
-
const identity = tenantOf(headers);
|
|
542
|
-
if (state.lastIdentity !== undefined && identity !== state.lastIdentity) {
|
|
543
|
-
state.store.clear();
|
|
544
|
-
}
|
|
545
|
-
state.lastIdentity = identity;
|
|
546
|
-
};
|
|
547
|
-
const decorated = async (input, init) => {
|
|
548
|
-
const request = new Request(input, init);
|
|
549
|
-
syncIdentity(request.headers);
|
|
550
|
-
if (request.method !== "GET") {
|
|
551
|
-
const response = await base(request);
|
|
552
|
-
if (isIdentityResetPath(request.url) && response.ok) {
|
|
553
|
-
state.store.clear();
|
|
554
|
-
state.lastIdentity = undefined;
|
|
555
|
-
}
|
|
556
|
-
return response;
|
|
557
|
-
}
|
|
558
|
-
const key = resourceKey(request);
|
|
559
|
-
let sent = request;
|
|
560
|
-
if (!request.headers.has(IF_NONE_MATCH)) {
|
|
561
|
-
const entry = touch(state.store, key);
|
|
562
|
-
if (entry !== undefined) {
|
|
563
|
-
const headers = new Headers(request.headers);
|
|
564
|
-
headers.set(IF_NONE_MATCH, entry.etag);
|
|
565
|
-
sent = new Request(request, { headers });
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
const response = await base(sent);
|
|
569
|
-
if (response.status !== 304) {
|
|
570
|
-
return captureSuccessfulGet(state.store, key, response);
|
|
571
|
-
}
|
|
572
|
-
const entry = touch(state.store, key);
|
|
573
|
-
if (entry === undefined) {
|
|
574
|
-
const retried = await base(requestWithoutIfNoneMatch(sent));
|
|
575
|
-
return retried.status === 304 ? retried : captureSuccessfulGet(state.store, key, retried);
|
|
576
|
-
}
|
|
577
|
-
return new Response(entry.body, { status: 200, statusText: "OK", headers: entry.headers });
|
|
578
|
-
};
|
|
579
|
-
return {
|
|
580
|
-
fetch: decorated,
|
|
581
|
-
store: {
|
|
582
|
-
clear: () => {
|
|
583
|
-
state.store.clear();
|
|
584
|
-
state.lastIdentity = undefined;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
// src/proxy/flat-args.ts
|
|
591
|
-
function asFlatObject(value) {
|
|
592
|
-
return value === null || value === undefined || typeof value !== "object" ? {} : { ...value };
|
|
593
|
-
}
|
|
594
|
-
function assertPathParams(route, path) {
|
|
595
|
-
const missing = route.params.filter((name) => path[name] === undefined);
|
|
596
|
-
if (missing.length > 0) {
|
|
597
|
-
throw new TypeError(`Missing path parameter${missing.length === 1 ? "" : "s"} ${missing.map((name) => `\`${name}\``).join(", ")} for ${route.method} ${route.path}`);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
function splitFlatArgs(route, input) {
|
|
601
|
-
const source = asFlatObject(input);
|
|
602
|
-
const path = {};
|
|
603
|
-
const query = {};
|
|
604
|
-
const rest = {};
|
|
605
|
-
const pathParams = new Set(route.params);
|
|
606
|
-
const queryParams = new Set(route.hasPayload ? route.queryParams : []);
|
|
607
|
-
for (const [key, value] of Object.entries(source)) {
|
|
608
|
-
if (pathParams.has(key)) {
|
|
609
|
-
path[key] = value;
|
|
610
|
-
} else if (queryParams.has(key)) {
|
|
611
|
-
query[key] = value;
|
|
612
|
-
} else {
|
|
613
|
-
rest[key] = value;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
assertPathParams(route, path);
|
|
617
|
-
if (!route.hasPayload) {
|
|
618
|
-
return { path, query: rest, body: undefined };
|
|
619
|
-
}
|
|
620
|
-
if (input === null || input === undefined) {
|
|
621
|
-
return { path, query, body: undefined };
|
|
622
|
-
}
|
|
623
|
-
for (const name of route.bodyParams) {
|
|
624
|
-
const value = path[name];
|
|
625
|
-
if (value !== undefined) {
|
|
626
|
-
rest[name] = value;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return { path, query, body: rest };
|
|
630
|
-
}
|
|
631
|
-
function splitRequestParts(route, parts) {
|
|
632
|
-
const source = asFlatObject(parts);
|
|
633
|
-
const path = asFlatObject(source["params"]);
|
|
634
|
-
const query = asFlatObject(source["query"]);
|
|
635
|
-
assertPathParams(route, path);
|
|
636
|
-
if (!route.hasPayload) {
|
|
637
|
-
return { path, query, body: undefined };
|
|
638
|
-
}
|
|
639
|
-
const body = asFlatObject(source["body"]);
|
|
640
|
-
for (const name of route.bodyParams) {
|
|
641
|
-
if (body[name] === undefined && path[name] !== undefined) {
|
|
642
|
-
body[name] = path[name];
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
return { path, query, body };
|
|
646
|
-
}
|
|
647
|
-
function splitRequestInput(route, input) {
|
|
648
|
-
return "parts" in input ? splitRequestParts(route, input.parts) : splitFlatArgs(route, input.flat);
|
|
649
|
-
}
|
|
650
|
-
var PATH_PARAMETER = /:([A-Za-z0-9_]+)/gu;
|
|
651
|
-
function encodePathValue(value) {
|
|
652
|
-
return encodeURIComponent(typeof value === "string" ? value : String(value));
|
|
653
|
-
}
|
|
654
|
-
function buildPath(route, path) {
|
|
655
|
-
return route.path.replaceAll(PATH_PARAMETER, (_match, name) => encodePathValue(path[name]));
|
|
656
|
-
}
|
|
657
|
-
function pathTarget(route, path) {
|
|
658
|
-
const segments = Array.from(route.path.matchAll(PATH_PARAMETER), ([, name = ""]) => encodePathValue(path[name]));
|
|
659
|
-
return segments.length === 0 ? null : segments.join("/");
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// src/proxy/transport.ts
|
|
663
|
-
var CONTEXT_HEADERS = {
|
|
664
|
-
organizationId: "X-Organization-Id",
|
|
665
|
-
participant: "X-Participant",
|
|
666
|
-
executor: "X-Executor",
|
|
667
|
-
chainId: "X-Chain-Id",
|
|
668
|
-
selectedSigners: "X-Selected-Signers",
|
|
669
|
-
idempotencyKey: "Idempotency-Key"
|
|
670
|
-
};
|
|
671
|
-
function setNonEmptyHeader(headers, name, value) {
|
|
672
|
-
if (value !== undefined && String(value).trim().length > 0) {
|
|
673
|
-
headers.set(name, String(value));
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
function createDalpContextHeaders2(context) {
|
|
677
|
-
const headers = new Headers;
|
|
678
|
-
setNonEmptyHeader(headers, CONTEXT_HEADERS.organizationId, context.organizationId);
|
|
679
|
-
setNonEmptyHeader(headers, CONTEXT_HEADERS.participant, context.participant);
|
|
680
|
-
setNonEmptyHeader(headers, CONTEXT_HEADERS.executor, context.executor);
|
|
681
|
-
setNonEmptyHeader(headers, CONTEXT_HEADERS.chainId, context.chainId);
|
|
682
|
-
setNonEmptyHeader(headers, CONTEXT_HEADERS.idempotencyKey, context.idempotencyKey);
|
|
683
|
-
if (context.selectedSigners !== undefined && context.selectedSigners.length > 0) {
|
|
684
|
-
headers.set(CONTEXT_HEADERS.selectedSigners, JSON.stringify(context.selectedSigners));
|
|
685
|
-
}
|
|
686
|
-
return headers;
|
|
687
|
-
}
|
|
688
|
-
var DEFAULT_PREFER_WAIT_SECONDS = 15;
|
|
689
|
-
var MIN_PREFER_WAIT_SECONDS = 5;
|
|
690
|
-
var MAX_PREFER_WAIT_SECONDS = 99;
|
|
691
|
-
function preferDirective(timeoutMs) {
|
|
692
|
-
if (timeoutMs === undefined) {
|
|
693
|
-
return `wait=${String(DEFAULT_PREFER_WAIT_SECONDS)}`;
|
|
694
|
-
}
|
|
695
|
-
if (timeoutMs <= 0) {
|
|
696
|
-
return "respond-async";
|
|
697
|
-
}
|
|
698
|
-
const seconds = Math.min(MAX_PREFER_WAIT_SECONDS, Math.max(MIN_PREFER_WAIT_SECONDS, Math.ceil(timeoutMs / 1000)));
|
|
699
|
-
return `wait=${String(seconds)}`;
|
|
700
|
-
}
|
|
701
|
-
function createTransport(options) {
|
|
702
|
-
const baseUrl = normalizeDalpBaseUrl(String(options.baseUrl));
|
|
703
|
-
const runtime = options.runtime ?? detectDalpRuntime();
|
|
704
|
-
const baseFetch = options.fetch ?? globalThis.fetch;
|
|
705
|
-
const transportFetch = runtime === "server" ? withRequestBodyCompression(baseFetch) : baseFetch;
|
|
706
|
-
const { apiKey: apiKeyOption } = options;
|
|
707
|
-
let apiKey;
|
|
708
|
-
if (apiKeyOption === undefined) {
|
|
709
|
-
apiKey = undefined;
|
|
710
|
-
} else if (apiKeyOption instanceof Secret2) {
|
|
711
|
-
apiKey = apiKeyOption;
|
|
712
|
-
} else {
|
|
713
|
-
apiKey = secret2(apiKeyOption.trim());
|
|
714
|
-
}
|
|
715
|
-
if (apiKey !== undefined) {
|
|
716
|
-
refuseBundledApiKey(runtime);
|
|
717
|
-
}
|
|
718
|
-
const sessionFetch = options.ssr === undefined ? transportFetch : createSsrFetch({
|
|
719
|
-
allowedOrigins: options.ssr.allowedOrigins,
|
|
720
|
-
baseUrl,
|
|
721
|
-
fetch: transportFetch,
|
|
722
|
-
requestHeaders: options.ssr.requestHeaders
|
|
723
|
-
});
|
|
724
|
-
const conditional = withConditionalRequests(sessionFetch);
|
|
725
|
-
const contextHeaders = createDalpContextHeaders2(options.context ?? {});
|
|
726
|
-
if (options.authSurface !== undefined) {
|
|
727
|
-
contextHeaders.set(DALP_AUTH_SURFACE_HEADER2, options.authSurface);
|
|
728
|
-
}
|
|
729
|
-
if (runtime === "react-native") {
|
|
730
|
-
contextHeaders.set("Origin", new URL(baseUrl).origin);
|
|
731
|
-
}
|
|
732
|
-
return {
|
|
733
|
-
baseUrl,
|
|
734
|
-
fetch: conditional.fetch,
|
|
735
|
-
conditionalRequests: conditional.store,
|
|
736
|
-
credentials: runtimeCredentials(runtime),
|
|
737
|
-
apiKey,
|
|
738
|
-
contextHeaders,
|
|
739
|
-
settlementTimeoutMs: options.settlementTimeoutMs,
|
|
740
|
-
streamsResponseBody: !isBufferingFetch(baseFetch)
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
function callHeaders(transport, options) {
|
|
744
|
-
const headers = new Headers({ Accept: "application/json" });
|
|
745
|
-
if (transport.apiKey !== undefined) {
|
|
746
|
-
headers.set("X-Api-Key", unwrapSecret(transport.apiKey));
|
|
747
|
-
}
|
|
748
|
-
for (const [name, value] of transport.contextHeaders) {
|
|
749
|
-
if (!headers.has(name)) {
|
|
750
|
-
headers.set(name, value);
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
const extra = typeof options?.headers === "function" ? options.headers() : options?.headers ?? {};
|
|
754
|
-
for (const [name, value] of Object.entries(extra)) {
|
|
755
|
-
headers.set(name, value);
|
|
756
|
-
}
|
|
757
|
-
return headers;
|
|
758
|
-
}
|
|
759
|
-
function prepareRequest(transport, route, input, options) {
|
|
760
|
-
const split = splitRequestInput(route, input);
|
|
761
|
-
const query = serializeDalpQuery(split.query);
|
|
762
|
-
const url = `${transport.baseUrl}/api/v2${buildPath(route, split.path)}${query === "" ? "" : `?${query}`}`;
|
|
763
|
-
const headers = callHeaders(transport, options);
|
|
764
|
-
if (split.body !== undefined) {
|
|
765
|
-
headers.set("Content-Type", "application/json");
|
|
766
|
-
}
|
|
767
|
-
if (route.queueBacked && !headers.has("Prefer")) {
|
|
768
|
-
headers.set("Prefer", preferDirective(options?.settlementTimeoutMs ?? transport.settlementTimeoutMs));
|
|
769
|
-
}
|
|
770
|
-
return {
|
|
771
|
-
url,
|
|
772
|
-
method: route.method,
|
|
773
|
-
headers,
|
|
774
|
-
pathParams: split.path,
|
|
775
|
-
body: split.body === undefined ? undefined : JSON.stringify(split.body, wireValue)
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
function wireValue(_key, value) {
|
|
779
|
-
return typeof value === "bigint" ? value.toString() : value;
|
|
780
|
-
}
|
|
781
|
-
function readString(source, key) {
|
|
782
|
-
if (source === null || typeof source !== "object") {
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
const value = Reflect.get(source, key);
|
|
786
|
-
return typeof value === "string" ? value : undefined;
|
|
787
|
-
}
|
|
788
|
-
async function envelopeCode(payload, response, routeId) {
|
|
789
|
-
const rawCode = readString(payload, "code");
|
|
790
|
-
if (rawCode === undefined) {
|
|
791
|
-
return { routeId, code: `sdk.transport.HTTP_${response.status}` };
|
|
792
|
-
}
|
|
793
|
-
const checked = await checkRouteErrorCode(routeId, rawCode);
|
|
794
|
-
switch (checked.kind) {
|
|
795
|
-
case "published": {
|
|
796
|
-
return { routeId, code: checked.code };
|
|
797
|
-
}
|
|
798
|
-
case "unpublished": {
|
|
799
|
-
return { routeId, code: "sdk.transport.UNPUBLISHED_ERROR_CODE", rejectedCode: { unpublishedCode: rawCode } };
|
|
800
|
-
}
|
|
801
|
-
case "unverified": {
|
|
802
|
-
return { routeId, code: "sdk.transport.UNVERIFIED_ERROR_CODE", rejectedCode: { unverifiedCode: rawCode } };
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
function sdkErrorFromEnvelope(payload, response, { routeId, code, rejectedCode }) {
|
|
807
|
-
const envelope = payload !== null && typeof payload === "object" ? payload : {};
|
|
808
|
-
const rawData = Reflect.get(envelope, "data");
|
|
809
|
-
const envelopeData = rawData !== null && typeof rawData === "object" ? rawData : {};
|
|
810
|
-
const requestId = response.headers.get("x-request-id");
|
|
811
|
-
const data = requestId === null ? envelopeData : { requestId, ...envelopeData };
|
|
812
|
-
const retryable = Reflect.get(data, "retryable");
|
|
813
|
-
const retryAfter = response.headers.get("retry-after");
|
|
814
|
-
let retryAfterSeconds;
|
|
815
|
-
if (retryAfter !== null) {
|
|
816
|
-
if (/^\d+$/.test(retryAfter)) {
|
|
817
|
-
retryAfterSeconds = Number(retryAfter);
|
|
818
|
-
} else if (Number.isNaN(Number(retryAfter))) {
|
|
819
|
-
retryAfterSeconds = Math.max(0, Math.ceil((Date.parse(retryAfter) - Date.now()) / 1000));
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
const details = rejectedCode === undefined ? data : { ...data, ...rejectedCode };
|
|
823
|
-
return new DalpSdkError2({
|
|
824
|
-
code,
|
|
825
|
-
routeId,
|
|
826
|
-
category: readString(data, "category") ?? "dependency",
|
|
827
|
-
status: response.status,
|
|
828
|
-
retryable: typeof retryable === "boolean" ? retryable : response.status >= 500,
|
|
829
|
-
message: readString(envelope, "message") ?? `DALP API responded ${String(response.status)}`,
|
|
830
|
-
why: readString(data, "why") ?? `The platform answered ${String(response.status)}.`,
|
|
831
|
-
fix: readString(data, "fix") ?? "Inspect the response body and the request id before retrying.",
|
|
832
|
-
...retryAfterSeconds !== undefined && Number.isFinite(retryAfterSeconds) ? { retryAfterSeconds } : {},
|
|
833
|
-
...Object.keys(details).length === 0 ? {} : { details }
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
function malformedSuccessError(response, text, routeId) {
|
|
837
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
838
|
-
return new DalpSdkError2({
|
|
839
|
-
code: "sdk.transport.MALFORMED_RESPONSE",
|
|
840
|
-
routeId,
|
|
841
|
-
category: "dependency",
|
|
842
|
-
status: response.status,
|
|
843
|
-
retryable: true,
|
|
844
|
-
message: `DALP API responded ${String(response.status)} without a JSON body`,
|
|
845
|
-
why: text === "" ? "The platform answered with an empty body where the route declares a JSON body." : "The platform answered with a body that is not JSON, so the route's response schema cannot read it.",
|
|
846
|
-
fix: "Check the base URL and any proxy in front of the API: a sign-in page, an HTML error page, or a truncated body reached the client instead of the API response.",
|
|
847
|
-
details: { contentType, bodyLength: text.length, bodyPreview: text.slice(0, 120) }
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
async function raiseResponseError(response, routeId) {
|
|
851
|
-
const text = await response.text();
|
|
852
|
-
let payload;
|
|
853
|
-
try {
|
|
854
|
-
payload = text === "" ? undefined : JSON.parse(text);
|
|
855
|
-
} catch {
|
|
856
|
-
payload = text;
|
|
857
|
-
}
|
|
858
|
-
throw makeDalpApiError2(sdkErrorFromEnvelope(payload, response, await envelopeCode(payload, response, routeId)));
|
|
859
|
-
}
|
|
860
|
-
async function readBinaryResponse(response, routeId) {
|
|
861
|
-
if (!response.ok) {
|
|
862
|
-
return raiseResponseError(response, routeId);
|
|
863
|
-
}
|
|
864
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
865
|
-
}
|
|
866
|
-
async function readResponse(response, routeId, bodyDeclared) {
|
|
867
|
-
if (!response.ok) {
|
|
868
|
-
return raiseResponseError(response, routeId);
|
|
869
|
-
}
|
|
870
|
-
const text = await response.text();
|
|
871
|
-
if (text === "") {
|
|
872
|
-
if (bodyDeclared) {
|
|
873
|
-
throw makeDalpApiError2(malformedSuccessError(response, text, routeId));
|
|
874
|
-
}
|
|
875
|
-
return;
|
|
876
|
-
}
|
|
877
|
-
try {
|
|
878
|
-
return JSON.parse(text);
|
|
879
|
-
} catch {
|
|
880
|
-
throw makeDalpApiError2(malformedSuccessError(response, text, routeId));
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
// src/proxy/response-decode.ts
|
|
885
|
-
var MALFORMED_SUCCESS_ERROR_CODE2 = "sdk.response.MALFORMED_SUCCESS";
|
|
886
|
-
function kindOf(value) {
|
|
887
|
-
if (value === null) {
|
|
888
|
-
return "null";
|
|
889
|
-
}
|
|
890
|
-
if (Array.isArray(value)) {
|
|
891
|
-
return "array";
|
|
892
|
-
}
|
|
893
|
-
if (typeof value === "number") {
|
|
894
|
-
return Number.isInteger(value) ? "integer" : "number";
|
|
895
|
-
}
|
|
896
|
-
return typeof value;
|
|
897
|
-
}
|
|
898
|
-
function isObject(value) {
|
|
899
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
900
|
-
}
|
|
901
|
-
function matchesType(type, value) {
|
|
902
|
-
switch (type) {
|
|
903
|
-
case "string": {
|
|
904
|
-
return typeof value === "string";
|
|
905
|
-
}
|
|
906
|
-
case "number": {
|
|
907
|
-
return typeof value === "number";
|
|
908
|
-
}
|
|
909
|
-
case "integer": {
|
|
910
|
-
return Number.isInteger(value);
|
|
911
|
-
}
|
|
912
|
-
case "boolean": {
|
|
913
|
-
return typeof value === "boolean";
|
|
914
|
-
}
|
|
915
|
-
case "null": {
|
|
916
|
-
return value === null;
|
|
917
|
-
}
|
|
918
|
-
case "array": {
|
|
919
|
-
return Array.isArray(value);
|
|
920
|
-
}
|
|
921
|
-
case "object": {
|
|
922
|
-
return isObject(value);
|
|
923
|
-
}
|
|
924
|
-
default: {
|
|
925
|
-
return false;
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
function jsonEqual(left, right) {
|
|
930
|
-
if (left === right) {
|
|
931
|
-
return true;
|
|
932
|
-
}
|
|
933
|
-
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) {
|
|
934
|
-
return false;
|
|
935
|
-
}
|
|
936
|
-
if (Array.isArray(left) !== Array.isArray(right)) {
|
|
937
|
-
return false;
|
|
938
|
-
}
|
|
939
|
-
const leftKeys = Object.keys(left);
|
|
940
|
-
if (leftKeys.length !== Object.keys(right).length) {
|
|
941
|
-
return false;
|
|
942
|
-
}
|
|
943
|
-
return leftKeys.every((key) => Object.hasOwn(right, key) && jsonEqual(Reflect.get(left, key), Reflect.get(right, key)));
|
|
944
|
-
}
|
|
945
|
-
function depthOf(path) {
|
|
946
|
-
let depth = 0;
|
|
947
|
-
for (const character of path) {
|
|
948
|
-
if (character === "." || character === "[") {
|
|
949
|
-
depth += 1;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
return depth;
|
|
953
|
-
}
|
|
954
|
-
function compilePattern(pattern) {
|
|
955
|
-
try {
|
|
956
|
-
return new RegExp(pattern, "u");
|
|
957
|
-
} catch {
|
|
958
|
-
return new RegExp(pattern);
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
class ResponseSchemaChecker {
|
|
963
|
-
compiled = new Map;
|
|
964
|
-
patterns = new Map;
|
|
965
|
-
definitions;
|
|
966
|
-
constructor(definitions) {
|
|
967
|
-
this.definitions = definitions;
|
|
968
|
-
}
|
|
969
|
-
validate(node, value) {
|
|
970
|
-
return this.compile(node)(value);
|
|
971
|
-
}
|
|
972
|
-
explain(node, value, path = "$") {
|
|
973
|
-
if (this.validate(node, value)) {
|
|
974
|
-
return;
|
|
975
|
-
}
|
|
976
|
-
if (node.$ref !== undefined) {
|
|
977
|
-
return this.explain(this.definition(node.$ref), value, path);
|
|
978
|
-
}
|
|
979
|
-
const typeMismatch = this.explainType(node, value, path);
|
|
980
|
-
if (typeMismatch !== undefined) {
|
|
981
|
-
return typeMismatch;
|
|
982
|
-
}
|
|
983
|
-
return this.explainValue(node, value, path) ?? this.explainObject(node, value, path) ?? this.explainArray(node, value, path) ?? this.explainComposition(node, value, path) ?? {
|
|
984
|
-
path,
|
|
985
|
-
expected: "a value matching the schema",
|
|
986
|
-
received: kindOf(value)
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
definition(name) {
|
|
990
|
-
const node = this.definitions[name];
|
|
991
|
-
if (node === undefined) {
|
|
992
|
-
throw new TypeError(`DALP SDK response schema references the missing definition ${name}`);
|
|
993
|
-
}
|
|
994
|
-
return node;
|
|
995
|
-
}
|
|
996
|
-
pattern(source) {
|
|
997
|
-
let compiled = this.patterns.get(source);
|
|
998
|
-
if (compiled === undefined) {
|
|
999
|
-
compiled = compilePattern(source);
|
|
1000
|
-
this.patterns.set(source, compiled);
|
|
1001
|
-
}
|
|
1002
|
-
return compiled;
|
|
1003
|
-
}
|
|
1004
|
-
compile(node) {
|
|
1005
|
-
const cached = this.compiled.get(node);
|
|
1006
|
-
if (cached !== undefined) {
|
|
1007
|
-
return cached;
|
|
1008
|
-
}
|
|
1009
|
-
const built = this.build(node);
|
|
1010
|
-
this.compiled.set(node, built);
|
|
1011
|
-
return built;
|
|
1012
|
-
}
|
|
1013
|
-
build(node) {
|
|
1014
|
-
const checks = [];
|
|
1015
|
-
if (node.$ref !== undefined) {
|
|
1016
|
-
const name = node.$ref;
|
|
1017
|
-
let target;
|
|
1018
|
-
checks.push((value) => (target ??= this.compile(this.definition(name)))(value));
|
|
1019
|
-
}
|
|
1020
|
-
if (node.type !== undefined) {
|
|
1021
|
-
const types = typeof node.type === "string" ? [node.type] : node.type;
|
|
1022
|
-
checks.push(types.length === 1 ? (value) => matchesType(types[0], value) : (value) => types.some((type) => matchesType(type, value)));
|
|
1023
|
-
}
|
|
1024
|
-
this.buildValueChecks(node, checks);
|
|
1025
|
-
this.buildObjectChecks(node, checks);
|
|
1026
|
-
this.buildArrayChecks(node, checks);
|
|
1027
|
-
this.buildCompositionChecks(node, checks);
|
|
1028
|
-
if (checks.length === 0) {
|
|
1029
|
-
return () => true;
|
|
1030
|
-
}
|
|
1031
|
-
if (checks.length === 1) {
|
|
1032
|
-
return checks[0];
|
|
1033
|
-
}
|
|
1034
|
-
return (value) => {
|
|
1035
|
-
for (const check of checks) {
|
|
1036
|
-
if (!check(value)) {
|
|
1037
|
-
return false;
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
return true;
|
|
1041
|
-
};
|
|
1042
|
-
}
|
|
1043
|
-
buildValueChecks(node, checks) {
|
|
1044
|
-
if (node.enum !== undefined) {
|
|
1045
|
-
const members = node.enum;
|
|
1046
|
-
const primitives = new Set(members.filter((member) => member === null || typeof member !== "object"));
|
|
1047
|
-
checks.push((value) => primitives.has(value) || members.some((member) => typeof member === "object" && jsonEqual(member, value)));
|
|
1048
|
-
}
|
|
1049
|
-
if ("const" in node) {
|
|
1050
|
-
const expected = node.const;
|
|
1051
|
-
checks.push((value) => jsonEqual(expected, value));
|
|
1052
|
-
}
|
|
1053
|
-
const { pattern, minLength, maxLength, minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf } = node;
|
|
1054
|
-
if (pattern !== undefined) {
|
|
1055
|
-
const regex = this.pattern(pattern);
|
|
1056
|
-
checks.push((value) => typeof value !== "string" || regex.test(value));
|
|
1057
|
-
}
|
|
1058
|
-
if (minLength !== undefined) {
|
|
1059
|
-
checks.push((value) => typeof value !== "string" || value.length >= minLength);
|
|
1060
|
-
}
|
|
1061
|
-
if (maxLength !== undefined) {
|
|
1062
|
-
checks.push((value) => typeof value !== "string" || value.length <= maxLength);
|
|
1063
|
-
}
|
|
1064
|
-
if (minimum !== undefined) {
|
|
1065
|
-
checks.push((value) => typeof value !== "number" || value >= minimum);
|
|
1066
|
-
}
|
|
1067
|
-
if (maximum !== undefined) {
|
|
1068
|
-
checks.push((value) => typeof value !== "number" || value <= maximum);
|
|
1069
|
-
}
|
|
1070
|
-
if (exclusiveMinimum !== undefined) {
|
|
1071
|
-
checks.push((value) => typeof value !== "number" || value > exclusiveMinimum);
|
|
1072
|
-
}
|
|
1073
|
-
if (exclusiveMaximum !== undefined) {
|
|
1074
|
-
checks.push((value) => typeof value !== "number" || value < exclusiveMaximum);
|
|
1075
|
-
}
|
|
1076
|
-
if (multipleOf !== undefined) {
|
|
1077
|
-
checks.push((value) => typeof value !== "number" || Number.isInteger(value / multipleOf));
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
buildObjectChecks(node, checks) {
|
|
1081
|
-
const { properties, required, additionalProperties, propertyNames } = node;
|
|
1082
|
-
if (required !== undefined && required.length > 0) {
|
|
1083
|
-
checks.push((value) => !isObject(value) || required.every((key) => Object.hasOwn(value, key)));
|
|
1084
|
-
}
|
|
1085
|
-
if (properties !== undefined) {
|
|
1086
|
-
const entries = Object.entries(properties).map(([key, child]) => [key, this.compile(child)]);
|
|
1087
|
-
checks.push((value) => {
|
|
1088
|
-
if (!isObject(value)) {
|
|
1089
|
-
return true;
|
|
1090
|
-
}
|
|
1091
|
-
for (const [key, check] of entries) {
|
|
1092
|
-
if (Object.hasOwn(value, key) && !check(Reflect.get(value, key))) {
|
|
1093
|
-
return false;
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
return true;
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
if (typeof additionalProperties === "object") {
|
|
1100
|
-
const declared = new Set(Object.keys(properties ?? {}));
|
|
1101
|
-
const check = this.compile(additionalProperties);
|
|
1102
|
-
checks.push((value) => {
|
|
1103
|
-
if (!isObject(value)) {
|
|
1104
|
-
return true;
|
|
1105
|
-
}
|
|
1106
|
-
for (const key in value) {
|
|
1107
|
-
if (Object.hasOwn(value, key) && !declared.has(key) && !check(Reflect.get(value, key))) {
|
|
1108
|
-
return false;
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
return true;
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
if (propertyNames !== undefined) {
|
|
1115
|
-
const check = this.compile(propertyNames);
|
|
1116
|
-
checks.push((value) => !isObject(value) || Object.keys(value).every(check));
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
buildArrayChecks(node, checks) {
|
|
1120
|
-
const { items, prefixItems, minItems, maxItems } = node;
|
|
1121
|
-
const prefix = (prefixItems ?? []).map((child) => this.compile(child));
|
|
1122
|
-
if (prefix.length > 0) {
|
|
1123
|
-
checks.push((value) => !Array.isArray(value) || prefix.every((check, index) => index >= value.length || check(value[index])));
|
|
1124
|
-
}
|
|
1125
|
-
if (items !== undefined) {
|
|
1126
|
-
const check = this.compile(items);
|
|
1127
|
-
const from = prefix.length;
|
|
1128
|
-
checks.push((value) => {
|
|
1129
|
-
if (!Array.isArray(value)) {
|
|
1130
|
-
return true;
|
|
1131
|
-
}
|
|
1132
|
-
for (let index = from;index < value.length; index += 1) {
|
|
1133
|
-
if (!check(value[index])) {
|
|
1134
|
-
return false;
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
return true;
|
|
1138
|
-
});
|
|
1139
|
-
}
|
|
1140
|
-
if (minItems !== undefined) {
|
|
1141
|
-
checks.push((value) => !Array.isArray(value) || value.length >= minItems);
|
|
1142
|
-
}
|
|
1143
|
-
if (maxItems !== undefined) {
|
|
1144
|
-
checks.push((value) => !Array.isArray(value) || value.length <= maxItems);
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
buildCompositionChecks(node, checks) {
|
|
1148
|
-
if (node.allOf !== undefined) {
|
|
1149
|
-
const all = node.allOf.map((child) => this.compile(child));
|
|
1150
|
-
checks.push((value) => all.every((check) => check(value)));
|
|
1151
|
-
}
|
|
1152
|
-
if (node.anyOf !== undefined) {
|
|
1153
|
-
const any = node.anyOf.map((child) => this.compile(child));
|
|
1154
|
-
checks.push((value) => any.some((check) => check(value)));
|
|
1155
|
-
}
|
|
1156
|
-
if (node.oneOf !== undefined) {
|
|
1157
|
-
const one = node.oneOf.map((child) => this.compile(child));
|
|
1158
|
-
checks.push((value) => one.filter((check) => check(value)).length === 1);
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
explainType(node, value, path) {
|
|
1162
|
-
if (node.type === undefined) {
|
|
1163
|
-
return;
|
|
1164
|
-
}
|
|
1165
|
-
const types = typeof node.type === "string" ? [node.type] : node.type;
|
|
1166
|
-
return types.some((type) => matchesType(type, value)) ? undefined : { path, expected: types.join(" | "), received: kindOf(value) };
|
|
1167
|
-
}
|
|
1168
|
-
explainValue(node, value, path) {
|
|
1169
|
-
const checks = [];
|
|
1170
|
-
this.buildValueChecks(node, checks);
|
|
1171
|
-
if (checks.every((check) => check(value))) {
|
|
1172
|
-
return;
|
|
1173
|
-
}
|
|
1174
|
-
let expected = "a value within the schema's bounds";
|
|
1175
|
-
if (node.enum !== undefined) {
|
|
1176
|
-
expected = `one of ${String(node.enum.length)} allowed values`;
|
|
1177
|
-
} else if ("const" in node) {
|
|
1178
|
-
expected = "the schema's constant value";
|
|
1179
|
-
} else if (node.pattern !== undefined && typeof value === "string" && !this.pattern(node.pattern).test(value)) {
|
|
1180
|
-
expected = "a string matching the schema pattern";
|
|
1181
|
-
}
|
|
1182
|
-
return { path, expected, received: kindOf(value) };
|
|
1183
|
-
}
|
|
1184
|
-
explainObject(node, value, path) {
|
|
1185
|
-
if (!isObject(value)) {
|
|
1186
|
-
return;
|
|
1187
|
-
}
|
|
1188
|
-
for (const key of node.required ?? []) {
|
|
1189
|
-
if (!Object.hasOwn(value, key)) {
|
|
1190
|
-
return { path: `${path}.${key}`, expected: "a required property", received: "missing" };
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
const properties = node.properties ?? {};
|
|
1194
|
-
for (const [key, child] of Object.entries(properties)) {
|
|
1195
|
-
if (Object.hasOwn(value, key)) {
|
|
1196
|
-
const mismatch = this.explain(child, Reflect.get(value, key), `${path}.${key}`);
|
|
1197
|
-
if (mismatch !== undefined) {
|
|
1198
|
-
return mismatch;
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
const extra = node.additionalProperties;
|
|
1203
|
-
for (const key of Object.keys(value)) {
|
|
1204
|
-
if (node.propertyNames !== undefined && !this.validate(node.propertyNames, key)) {
|
|
1205
|
-
return { path: `${path}.{key}`, expected: "a property name matching the schema", received: "string" };
|
|
1206
|
-
}
|
|
1207
|
-
if (typeof extra === "object" && !Object.hasOwn(properties, key)) {
|
|
1208
|
-
const mismatch = this.explain(extra, Reflect.get(value, key), `${path}.{key}`);
|
|
1209
|
-
if (mismatch !== undefined) {
|
|
1210
|
-
return mismatch;
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
return;
|
|
1215
|
-
}
|
|
1216
|
-
explainArray(node, value, path) {
|
|
1217
|
-
if (!Array.isArray(value)) {
|
|
1218
|
-
return;
|
|
1219
|
-
}
|
|
1220
|
-
const { minItems, maxItems, prefixItems = [], items } = node;
|
|
1221
|
-
if (minItems !== undefined && value.length < minItems || maxItems !== undefined && value.length > maxItems) {
|
|
1222
|
-
return { path, expected: "an array length within the schema's bounds", received: "array" };
|
|
1223
|
-
}
|
|
1224
|
-
for (const [index, element] of value.entries()) {
|
|
1225
|
-
const child = index < prefixItems.length ? prefixItems[index] : items;
|
|
1226
|
-
const mismatch = child === undefined ? undefined : this.explain(child, element, `${path}[${String(index)}]`);
|
|
1227
|
-
if (mismatch !== undefined) {
|
|
1228
|
-
return mismatch;
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
return;
|
|
1232
|
-
}
|
|
1233
|
-
explainComposition(node, value, path) {
|
|
1234
|
-
for (const child of node.allOf ?? []) {
|
|
1235
|
-
const mismatch = this.explain(child, value, path);
|
|
1236
|
-
if (mismatch !== undefined) {
|
|
1237
|
-
return mismatch;
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
const variants = node.anyOf ?? node.oneOf;
|
|
1241
|
-
if (variants === undefined || variants.some((child) => this.validate(child, value))) {
|
|
1242
|
-
return;
|
|
1243
|
-
}
|
|
1244
|
-
const tagged = variants.filter((child) => this.tagsMatch(child, value));
|
|
1245
|
-
const candidates = tagged.length === 1 ? tagged : variants;
|
|
1246
|
-
let deepest;
|
|
1247
|
-
for (const child of candidates) {
|
|
1248
|
-
const mismatch = this.explain(child, value, path);
|
|
1249
|
-
if (mismatch !== undefined && (deepest === undefined || depthOf(mismatch.path) > depthOf(deepest.path))) {
|
|
1250
|
-
deepest = mismatch;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
return deepest !== undefined && (tagged.length === 1 || deepest.path !== path) ? deepest : { path, expected: `one of ${String(variants.length)} variants`, received: kindOf(value) };
|
|
1254
|
-
}
|
|
1255
|
-
tagsMatch(node, value) {
|
|
1256
|
-
const resolved = node.$ref === undefined ? node : this.definition(node.$ref);
|
|
1257
|
-
if (!isObject(value) || resolved.properties === undefined) {
|
|
1258
|
-
return false;
|
|
1259
|
-
}
|
|
1260
|
-
let tags = 0;
|
|
1261
|
-
for (const [key, child] of Object.entries(resolved.properties)) {
|
|
1262
|
-
const property = child.$ref === undefined ? child : this.definition(child.$ref);
|
|
1263
|
-
const tag = property.enum?.length === 1 ? property.enum[0] : property.const;
|
|
1264
|
-
if (tag === undefined) {
|
|
1265
|
-
continue;
|
|
1266
|
-
}
|
|
1267
|
-
if (!jsonEqual(tag, Reflect.get(value, key))) {
|
|
1268
|
-
return false;
|
|
1269
|
-
}
|
|
1270
|
-
tags += 1;
|
|
1271
|
-
}
|
|
1272
|
-
return tags > 0;
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
function malformedSuccess(routeId, status, mismatch) {
|
|
1276
|
-
return makeDalpApiError2(new DalpSdkError2({
|
|
1277
|
-
code: MALFORMED_SUCCESS_ERROR_CODE2,
|
|
1278
|
-
routeId,
|
|
1279
|
-
category: "dependency",
|
|
1280
|
-
status,
|
|
1281
|
-
retryable: false,
|
|
1282
|
-
message: `DALP API responded ${String(status)} to ${routeId} with a body that does not match the route's schema at ${mismatch.path}`,
|
|
1283
|
-
why: `The success body failed the ${routeId} response schema: ${mismatch.path} should be ${mismatch.expected}, but it is ${mismatch.received}.`,
|
|
1284
|
-
fix: "Check that the SDK version matches the platform version. If they match, report the route id and field path: the platform served a body its own contract does not allow.",
|
|
1285
|
-
details: { routeId, status, path: mismatch.path, expected: mismatch.expected, received: mismatch.received }
|
|
1286
|
-
}));
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
class ResponseDecoder {
|
|
1290
|
-
checker;
|
|
1291
|
-
table;
|
|
1292
|
-
constructor(table) {
|
|
1293
|
-
this.table = table;
|
|
1294
|
-
this.checker = new ResponseSchemaChecker(table.definitions);
|
|
1295
|
-
}
|
|
1296
|
-
declaresBody(routeId, status) {
|
|
1297
|
-
return this.table.routes[routeId]?.[String(status)] !== null;
|
|
1298
|
-
}
|
|
1299
|
-
decode(routeId, status, payload) {
|
|
1300
|
-
const statuses = this.table.routes[routeId];
|
|
1301
|
-
const schema = statuses?.[String(status)];
|
|
1302
|
-
if (schema === undefined) {
|
|
1303
|
-
throw malformedSuccess(routeId, status, {
|
|
1304
|
-
path: "$",
|
|
1305
|
-
expected: statuses === undefined ? "a route the SDK knows" : `a status the route declares (${Object.keys(statuses).join(", ")})`,
|
|
1306
|
-
received: statuses === undefined ? "an unknown route" : `status ${String(status)}`
|
|
1307
|
-
});
|
|
1308
|
-
}
|
|
1309
|
-
if (schema === null) {
|
|
1310
|
-
if (payload === undefined) {
|
|
1311
|
-
return;
|
|
1312
|
-
}
|
|
1313
|
-
throw malformedSuccess(routeId, status, { path: "$", expected: "no body", received: kindOf(payload) });
|
|
1314
|
-
}
|
|
1315
|
-
if (this.checker.validate(schema, payload)) {
|
|
1316
|
-
return payload;
|
|
1317
|
-
}
|
|
1318
|
-
throw malformedSuccess(routeId, status, this.checker.explain(schema, payload) ?? { path: "$", expected: "the route's schema", received: kindOf(payload) });
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
var shared;
|
|
1322
|
-
async function importResponseDecoder() {
|
|
1323
|
-
const { data } = await import("./chunk-ghgcmyhk.js");
|
|
1324
|
-
return new ResponseDecoder(data);
|
|
1325
|
-
}
|
|
1326
|
-
async function loadResponseDecoder() {
|
|
1327
|
-
shared ??= importResponseDecoder();
|
|
1328
|
-
try {
|
|
1329
|
-
return await shared;
|
|
1330
|
-
} catch (error) {
|
|
1331
|
-
shared = undefined;
|
|
1332
|
-
throw error;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
// src/proxy/sse.ts
|
|
1337
|
-
var RESERVED_STREAM_FAILURE_EVENT2 = "effect/http-api/stream/failure";
|
|
1338
|
-
var RELEASE_CANDIDATE_SERVER_STREAM_FAILURE_EVENT = "effect/httpapi/stream/failure";
|
|
1339
|
-
var STREAM_FAILED_ERROR_CODE2 = "sdk.stream.FAILED";
|
|
1340
|
-
var STREAM_UNREADABLE_BODY_ERROR_CODE2 = "sdk.stream.UNREADABLE_BODY";
|
|
1341
|
-
function isReadableBody(body) {
|
|
1342
|
-
return typeof body === "object" && body !== null && typeof Reflect.get(body, "getReader") === "function";
|
|
1343
|
-
}
|
|
1344
|
-
function unreadableBodyError(routeId) {
|
|
1345
|
-
return makeDalpApiError2(new DalpSdkError2({
|
|
1346
|
-
code: STREAM_UNREADABLE_BODY_ERROR_CODE2,
|
|
1347
|
-
routeId,
|
|
1348
|
-
category: "sdk.configuration",
|
|
1349
|
-
retryable: false,
|
|
1350
|
-
message: "The fetch this client uses cannot stream a response body.",
|
|
1351
|
-
why: "React Native's built-in fetch resolves only after the whole response has arrived and exposes no `response.body`, so a stream never yields a frame.",
|
|
1352
|
-
fix: 'Pass a streaming fetch as `fetch`; on React Native that is `fetch` from "expo/fetch", wrapped with the cookie store.'
|
|
1353
|
-
}));
|
|
1354
|
-
}
|
|
1355
|
-
function parseFrame(raw) {
|
|
1356
|
-
try {
|
|
1357
|
-
return JSON.parse(raw.data);
|
|
1358
|
-
} catch {
|
|
1359
|
-
return raw.data;
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
function dispatchFrame(raw, decodeFrame, routeId) {
|
|
1363
|
-
if (raw.event === RESERVED_STREAM_FAILURE_EVENT2 || raw.event === RELEASE_CANDIDATE_SERVER_STREAM_FAILURE_EVENT) {
|
|
1364
|
-
throw makeDalpApiError2(new DalpSdkError2({
|
|
1365
|
-
code: STREAM_FAILED_ERROR_CODE2,
|
|
1366
|
-
...routeId === undefined ? {} : { routeId },
|
|
1367
|
-
category: "dependency",
|
|
1368
|
-
retryable: true,
|
|
1369
|
-
message: "The DALP API stream failed before it completed.",
|
|
1370
|
-
why: "The route ended the stream with its reserved failure event, so the remaining frames were never sent.",
|
|
1371
|
-
fix: "Retry the stream. If it fails again, read the route's logs for the failure the server recorded.",
|
|
1372
|
-
details: { cause: raw.data }
|
|
1373
|
-
}));
|
|
1374
|
-
}
|
|
1375
|
-
const frame = parseFrame(raw);
|
|
1376
|
-
return decodeFrame === undefined ? frame : decodeFrame(frame);
|
|
1377
|
-
}
|
|
1378
|
-
function readBlock(block) {
|
|
1379
|
-
let event = "message";
|
|
1380
|
-
const data = [];
|
|
1381
|
-
for (const line of block.split(`
|
|
1382
|
-
`)) {
|
|
1383
|
-
if (line === "" || line.startsWith(":")) {
|
|
1384
|
-
continue;
|
|
1385
|
-
}
|
|
1386
|
-
const separator = line.indexOf(":");
|
|
1387
|
-
const field = separator === -1 ? line : line.slice(0, separator);
|
|
1388
|
-
const rest = separator === -1 ? "" : line.slice(separator + 1).replace(/^ /u, "");
|
|
1389
|
-
if (field === "event") {
|
|
1390
|
-
event = rest;
|
|
1391
|
-
} else if (field === "data") {
|
|
1392
|
-
data.push(rest);
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
return data.length === 0 ? undefined : { event, data: data.join(`
|
|
1396
|
-
`) };
|
|
1397
|
-
}
|
|
1398
|
-
async function* decodeEventStream2(body, decodeFrame, routeId) {
|
|
1399
|
-
const reader = body.getReader();
|
|
1400
|
-
const decoder = new TextDecoder;
|
|
1401
|
-
let buffer = "";
|
|
1402
|
-
try {
|
|
1403
|
-
for (;; ) {
|
|
1404
|
-
const chunk = await reader.read();
|
|
1405
|
-
if (chunk.done) {
|
|
1406
|
-
break;
|
|
1407
|
-
}
|
|
1408
|
-
buffer += decoder.decode(chunk.value, { stream: true });
|
|
1409
|
-
buffer = buffer.replaceAll(`\r
|
|
1410
|
-
`, `
|
|
1411
|
-
`);
|
|
1412
|
-
let boundary = buffer.indexOf(`
|
|
1413
|
-
|
|
1414
|
-
`);
|
|
1415
|
-
while (boundary !== -1) {
|
|
1416
|
-
const raw = readBlock(buffer.slice(0, boundary));
|
|
1417
|
-
buffer = buffer.slice(boundary + 2);
|
|
1418
|
-
if (raw !== undefined) {
|
|
1419
|
-
yield dispatchFrame(raw, decodeFrame, routeId);
|
|
1420
|
-
}
|
|
1421
|
-
boundary = buffer.indexOf(`
|
|
1422
|
-
|
|
1423
|
-
`);
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
const trailing = readBlock(buffer);
|
|
1427
|
-
if (trailing !== undefined) {
|
|
1428
|
-
yield dispatchFrame(trailing, decodeFrame, routeId);
|
|
1429
|
-
}
|
|
1430
|
-
} finally {
|
|
1431
|
-
await reader.cancel().catch(() => {});
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
async function* openEventStream(transport, route, routeId, input, options, signal, closed) {
|
|
1435
|
-
if (!transport.streamsResponseBody) {
|
|
1436
|
-
throw unreadableBodyError(routeId);
|
|
1437
|
-
}
|
|
1438
|
-
const prepared = prepareRequest(transport, route, input, options);
|
|
1439
|
-
prepared.headers.set("Accept", "text/event-stream");
|
|
1440
|
-
const response = await transport.fetch(prepared.url, {
|
|
1441
|
-
method: prepared.method,
|
|
1442
|
-
headers: prepared.headers,
|
|
1443
|
-
credentials: transport.credentials,
|
|
1444
|
-
...prepared.body === undefined ? {} : { body: prepared.body },
|
|
1445
|
-
signal
|
|
1446
|
-
});
|
|
1447
|
-
if (!response.ok) {
|
|
1448
|
-
await raiseResponseError(response, routeId);
|
|
1449
|
-
}
|
|
1450
|
-
const { body, status } = response;
|
|
1451
|
-
if (body === null) {
|
|
1452
|
-
return;
|
|
1453
|
-
}
|
|
1454
|
-
if (!isReadableBody(body)) {
|
|
1455
|
-
throw unreadableBodyError(routeId);
|
|
1456
|
-
}
|
|
1457
|
-
const decoder = await loadResponseDecoder();
|
|
1458
|
-
try {
|
|
1459
|
-
yield* decodeEventStream2(body, (frame) => decoder.decode(routeId, status, frame), routeId);
|
|
1460
|
-
} catch (error) {
|
|
1461
|
-
if (!closed.byConsumer) {
|
|
1462
|
-
throw error;
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
function streamRequest(transport, route, routeId, input, options) {
|
|
1467
|
-
const closing = new AbortController;
|
|
1468
|
-
const callerSignal = options?.signal;
|
|
1469
|
-
if (callerSignal !== undefined) {
|
|
1470
|
-
if (callerSignal.aborted) {
|
|
1471
|
-
closing.abort(callerSignal.reason);
|
|
1472
|
-
} else {
|
|
1473
|
-
callerSignal.addEventListener("abort", () => closing.abort(callerSignal.reason), { once: true });
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
const closed = { byConsumer: false };
|
|
1477
|
-
const frames = openEventStream(transport, route, routeId, input, options, closing.signal, closed);
|
|
1478
|
-
const close = () => {
|
|
1479
|
-
closed.byConsumer = true;
|
|
1480
|
-
closing.abort();
|
|
1481
|
-
};
|
|
1482
|
-
return {
|
|
1483
|
-
[Symbol.asyncIterator]() {
|
|
1484
|
-
return this;
|
|
1485
|
-
},
|
|
1486
|
-
next: (...args) => frames.next(...args),
|
|
1487
|
-
return: (value) => {
|
|
1488
|
-
close();
|
|
1489
|
-
return frames.return(value);
|
|
1490
|
-
},
|
|
1491
|
-
throw: (error) => {
|
|
1492
|
-
close();
|
|
1493
|
-
return frames.throw(error);
|
|
1494
|
-
},
|
|
1495
|
-
async[Symbol.asyncDispose]() {
|
|
1496
|
-
close();
|
|
1497
|
-
await frames.return(undefined);
|
|
1498
|
-
}
|
|
1499
|
-
};
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
// ../wire/http-contract/src/headers.ts
|
|
1503
|
-
import { Function } from "effect";
|
|
1504
|
-
var X_EXECUTOR_HEADER = "X-Executor";
|
|
1505
|
-
var X_CUSTODY_ACCOUNT_ID_HEADER = "X-Custody-Account-Id";
|
|
1506
|
-
var X_CHAIN_ID_HEADER = "X-Chain-Id";
|
|
1507
|
-
var X_NETWORK_ID_HEADER = "X-Network-Id";
|
|
1508
|
-
var getHeaderValue = Function.dual(2, (headers, variants) => {
|
|
1509
|
-
for (const variant of variants) {
|
|
1510
|
-
const value = headers[variant];
|
|
1511
|
-
const single = Array.isArray(value) ? value[0] : value;
|
|
1512
|
-
if (single !== undefined && single !== "") {
|
|
1513
|
-
return single;
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
return;
|
|
1517
|
-
});
|
|
1518
|
-
|
|
1519
|
-
// ../wire/http-contract/src/step-up-scoped-target.ts
|
|
1520
|
-
function stepUpScopedTarget(input) {
|
|
1521
|
-
const { target, getHeader } = input;
|
|
1522
|
-
const scope = [
|
|
1523
|
-
getHeader(X_CHAIN_ID_HEADER) ?? null,
|
|
1524
|
-
getHeader(X_NETWORK_ID_HEADER) ?? null,
|
|
1525
|
-
getHeader(X_EXECUTOR_HEADER) ?? null,
|
|
1526
|
-
getHeader(X_CUSTODY_ACCOUNT_ID_HEADER) ?? null
|
|
1527
|
-
];
|
|
1528
|
-
return scope.every((value) => value === null) ? target : JSON.stringify([target, ...scope]);
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
// src/proxy/step-up-challenge.ts
|
|
1532
|
-
var ISSUE_ROUTE_ID = "auth.stepUpChallenges.v2/user/issueStepUpChallenge";
|
|
1533
|
-
async function issueChallenge(transport, route, prepared, body, options) {
|
|
1534
|
-
const headers = callHeaders(transport, options);
|
|
1535
|
-
headers.delete(CONTEXT_HEADERS.idempotencyKey);
|
|
1536
|
-
headers.delete(WALLET_VERIFICATION_HEADER);
|
|
1537
|
-
headers.set("Content-Type", "application/json");
|
|
1538
|
-
const request = await stepUpChallengeRequest(`${route.method} /api/v2${route.path}`, stepUpScopedTarget({
|
|
1539
|
-
target: pathTarget(route, prepared.pathParams),
|
|
1540
|
-
getHeader: (name) => prepared.headers.get(name)
|
|
1541
|
-
}), body);
|
|
1542
|
-
const response = await transport.fetch(`${transport.baseUrl}${STEP_UP_CHALLENGE_PATH}`, {
|
|
1543
|
-
method: "POST",
|
|
1544
|
-
headers,
|
|
1545
|
-
credentials: transport.credentials,
|
|
1546
|
-
body: JSON.stringify(request),
|
|
1547
|
-
...options?.signal === undefined ? {} : { signal: options.signal }
|
|
1548
|
-
});
|
|
1549
|
-
const decoder = await loadResponseDecoder();
|
|
1550
|
-
const payload = await readResponse(response, ISSUE_ROUTE_ID, true);
|
|
1551
|
-
const issued = decoder.decode(ISSUE_ROUTE_ID, response.status, payload);
|
|
1552
|
-
return issued.data.challengeId;
|
|
1553
|
-
}
|
|
1554
|
-
async function presentStepUpChallenge(transport, route, prepared, options) {
|
|
1555
|
-
if (prepared.headers.has("X-Api-Key") || prepared.headers.has(STEP_UP_CHALLENGE_HEADER)) {
|
|
1556
|
-
return;
|
|
1557
|
-
}
|
|
1558
|
-
const body = prepared.body === undefined ? null : JSON.parse(prepared.body);
|
|
1559
|
-
if (!carriesWalletProof(body) && !prepared.headers.has(WALLET_VERIFICATION_HEADER)) {
|
|
1560
|
-
return;
|
|
1561
|
-
}
|
|
1562
|
-
prepared.headers.set(STEP_UP_CHALLENGE_HEADER, await issueChallenge(transport, route, prepared, body, options));
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
// src/proxy/fetch-executor.ts
|
|
1566
|
-
async function sendRequest(transport, route, routeId, input, options) {
|
|
1567
|
-
const prepared = prepareRequest(transport, route, input, options);
|
|
1568
|
-
await presentStepUpChallenge(transport, route, prepared, options);
|
|
1569
|
-
const response = await transport.fetch(prepared.url, {
|
|
1570
|
-
method: prepared.method,
|
|
1571
|
-
headers: prepared.headers,
|
|
1572
|
-
credentials: transport.credentials,
|
|
1573
|
-
...prepared.body === undefined ? {} : { body: prepared.body },
|
|
1574
|
-
...options?.signal === undefined ? {} : { signal: options.signal }
|
|
1575
|
-
});
|
|
1576
|
-
if (route.serializer === "binary") {
|
|
1577
|
-
return readBinaryResponse(response, routeId);
|
|
1578
|
-
}
|
|
1579
|
-
const decoder = await loadResponseDecoder();
|
|
1580
|
-
const payload = await readResponse(response, routeId, decoder.declaresBody(routeId, response.status));
|
|
1581
|
-
return decoder.decode(routeId, response.status, payload);
|
|
1582
|
-
}
|
|
1583
|
-
function createFetchExecutor(transport) {
|
|
1584
|
-
return (route, id, input, options) => route.serializer === "sse" ? streamRequest(transport, route, id, { flat: input }, options) : sendRequest(transport, route, id, { flat: input }, options);
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
// src/proxy/tanstack.ts
|
|
1588
|
-
function canonicalize2(value) {
|
|
1589
|
-
if (Array.isArray(value)) {
|
|
1590
|
-
return value.map(canonicalize2);
|
|
1591
|
-
}
|
|
1592
|
-
if (value === null || typeof value !== "object") {
|
|
1593
|
-
return value;
|
|
1594
|
-
}
|
|
1595
|
-
const entries = [];
|
|
1596
|
-
for (const key of Object.keys(value).sort((left, right) => left.localeCompare(right))) {
|
|
1597
|
-
const entry = Reflect.get(value, key);
|
|
1598
|
-
if (entry !== undefined) {
|
|
1599
|
-
entries.push([key, canonicalize2(entry)]);
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
return Object.fromEntries(entries);
|
|
1603
|
-
}
|
|
1604
|
-
function queryKeyFor2(id, input) {
|
|
1605
|
-
const canonical = canonicalize2(input);
|
|
1606
|
-
return canonical === undefined ? ["dalp", id] : ["dalp", id, canonical];
|
|
1607
|
-
}
|
|
1608
|
-
var UI_SETTLEMENT_TIMEOUT_MS2 = 30000;
|
|
1609
|
-
function createTanstackFactories(transport) {
|
|
1610
|
-
return {
|
|
1611
|
-
queryOptions: (route, id, input, options) => ({
|
|
1612
|
-
queryKey: queryKeyFor2(id, input),
|
|
1613
|
-
queryFn: (context) => sendRequest(transport, route, id, { flat: input }, {
|
|
1614
|
-
...options,
|
|
1615
|
-
...context.signal === undefined ? {} : { signal: context.signal }
|
|
1616
|
-
})
|
|
1617
|
-
}),
|
|
1618
|
-
mutationOptions: (route, id, options) => ({
|
|
1619
|
-
mutationKey: ["dalp", id],
|
|
1620
|
-
mutationFn: (input) => sendRequest(transport, route, id, { flat: input }, { settlementTimeoutMs: UI_SETTLEMENT_TIMEOUT_MS2, ...options })
|
|
1621
|
-
})
|
|
1622
|
-
};
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
export { DalpApiError2, isDalpApiError2, findDalpSdkError2, makeDalpApiError2, isDalpErrorCode2, isDalpSdkLocalErrorCode2, isDalpApiErrorCode2, answeredByRoute, isDalpRouteError2, createDalpContextHeaders2, createTransport, MALFORMED_SUCCESS_ERROR_CODE2, RESERVED_STREAM_FAILURE_EVENT2, STREAM_FAILED_ERROR_CODE2, STREAM_UNREADABLE_BODY_ERROR_CODE2, decodeEventStream2, streamRequest, sendRequest, createFetchExecutor, canonicalize2, queryKeyFor2, UI_SETTLEMENT_TIMEOUT_MS2, createTanstackFactories };
|