@circle-fin/daa-react-native-sdk 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DaaReactNativeSdk.podspec +63 -0
- package/LICENSE +176 -0
- package/README.md +217 -2
- package/android/build.gradle +97 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationExceptions.kt +47 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaRegistrationModule.kt +121 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaScaExceptions.kt +60 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaScaModule.kt +179 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyExceptions.kt +73 -0
- package/android/src/main/java/com/circle/daa/reactnative/DaaSecureKeyModule.kt +185 -0
- package/android/src/main/java/com/circle/daa/reactnative/InstallationIdentityStore.kt +73 -0
- package/android/src/main/java/com/circle/daa/reactnative/UnpaddedBase64Url.kt +45 -0
- package/build/DaaClient.d.ts +57 -0
- package/build/DaaClient.js +158 -0
- package/build/api/AccountLimitsClient.d.ts +79 -0
- package/build/api/AccountLimitsClient.js +142 -0
- package/build/api/AccountsClient.d.ts +95 -0
- package/build/api/AccountsClient.js +276 -0
- package/build/api/AchFiatAccountsClient.d.ts +92 -0
- package/build/api/AchFiatAccountsClient.js +142 -0
- package/build/api/AuthClient.d.ts +120 -0
- package/build/api/AuthClient.js +257 -0
- package/build/api/DaaUserClient.d.ts +124 -0
- package/build/api/DaaUserClient.js +245 -0
- package/build/api/DepositAddressesClient.d.ts +112 -0
- package/build/api/DepositAddressesClient.js +222 -0
- package/build/api/DepositsClient.d.ts +106 -0
- package/build/api/DepositsClient.js +183 -0
- package/build/api/FiatAccountsClient.d.ts +43 -0
- package/build/api/FiatAccountsClient.js +46 -0
- package/build/api/TransactionsClient.d.ts +64 -0
- package/build/api/TransactionsClient.js +120 -0
- package/build/api/TransfersClient.d.ts +104 -0
- package/build/api/TransfersClient.js +321 -0
- package/build/api/WireFiatAccountsClient.d.ts +99 -0
- package/build/api/WireFiatAccountsClient.js +156 -0
- package/build/api/WithdrawalsClient.d.ts +94 -0
- package/build/api/WithdrawalsClient.js +305 -0
- package/build/api/loginFailure.d.ts +43 -0
- package/build/api/loginFailure.js +64 -0
- package/build/api/pagination.d.ts +29 -0
- package/build/api/pagination.js +50 -0
- package/build/api/queryParameters.d.ts +23 -0
- package/build/api/queryParameters.js +77 -0
- package/build/api/resourceRequest.d.ts +60 -0
- package/build/api/resourceRequest.js +79 -0
- package/build/api/signedResource.d.ts +77 -0
- package/build/api/signedResource.js +168 -0
- package/build/auth/RegistrationFlowKey.d.ts +93 -0
- package/build/auth/RegistrationFlowKey.js +203 -0
- package/build/auth/daaRegistrationNative.d.ts +80 -0
- package/build/auth/daaRegistrationNative.js +184 -0
- package/build/auth/deviceAuthorization.d.ts +73 -0
- package/build/auth/deviceAuthorization.js +243 -0
- package/build/auth/ownerGrant.d.ts +29 -0
- package/build/auth/ownerGrant.js +90 -0
- package/build/auth/prepareReceipt.d.ts +150 -0
- package/build/auth/prepareReceipt.js +357 -0
- package/build/auth/registrationAuthorization.d.ts +48 -0
- package/build/auth/registrationAuthorization.js +243 -0
- package/build/auth/registrationCodeVerifier.d.ts +31 -0
- package/build/auth/registrationCodeVerifier.js +75 -0
- package/build/config.d.ts +79 -0
- package/build/config.js +116 -0
- package/build/crypto/base64url.d.ts +26 -0
- package/build/crypto/base64url.js +87 -0
- package/build/crypto/bytes.d.ts +27 -0
- package/build/crypto/bytes.js +32 -0
- package/build/crypto/es256Jws.d.ts +56 -0
- package/build/crypto/es256Jws.js +196 -0
- package/build/crypto/jwkThumbprint.d.ts +32 -0
- package/build/crypto/jwkThumbprint.js +49 -0
- package/build/crypto/random.d.ts +35 -0
- package/build/crypto/random.js +106 -0
- package/build/crypto/serialization.d.ts +26 -0
- package/build/crypto/serialization.js +43 -0
- package/build/crypto/sha256.d.ts +18 -0
- package/build/crypto/sha256.js +100 -0
- package/build/errors.d.ts +190 -0
- package/build/errors.js +252 -0
- package/build/index.d.ts +61 -0
- package/build/index.js +67 -0
- package/build/models/Account.d.ts +201 -0
- package/build/models/Account.js +147 -0
- package/build/models/AccountLimitsUsage.d.ts +169 -0
- package/build/models/AccountLimitsUsage.js +86 -0
- package/build/models/Ach.d.ts +135 -0
- package/build/models/Ach.js +184 -0
- package/build/models/AddressObject.d.ts +128 -0
- package/build/models/AddressObject.js +141 -0
- package/build/models/BusinessPii.d.ts +84 -0
- package/build/models/BusinessPii.js +142 -0
- package/build/models/CreateAccountRequest.d.ts +74 -0
- package/build/models/CreateAccountRequest.js +19 -0
- package/build/models/CreateTransferRequest.d.ts +91 -0
- package/build/models/CreateTransferRequest.js +19 -0
- package/build/models/CreateWithdrawalRequest.d.ts +99 -0
- package/build/models/CreateWithdrawalRequest.js +19 -0
- package/build/models/DaaUserContext.d.ts +96 -0
- package/build/models/DaaUserContext.js +133 -0
- package/build/models/Deposit.d.ts +241 -0
- package/build/models/Deposit.js +149 -0
- package/build/models/DepositSummary.d.ts +91 -0
- package/build/models/DepositSummary.js +114 -0
- package/build/models/FiatAccount.d.ts +99 -0
- package/build/models/FiatAccount.js +151 -0
- package/build/models/GenerateAddressRequest.d.ts +67 -0
- package/build/models/GenerateAddressRequest.js +68 -0
- package/build/models/Money.d.ts +76 -0
- package/build/models/Money.js +99 -0
- package/build/models/Page.d.ts +33 -0
- package/build/models/Page.js +57 -0
- package/build/models/PendingDeviceRegistration.d.ts +90 -0
- package/build/models/PendingDeviceRegistration.js +180 -0
- package/build/models/PreparedSocialLogin.d.ts +155 -0
- package/build/models/PreparedSocialLogin.js +235 -0
- package/build/models/Transaction.d.ts +187 -0
- package/build/models/Transaction.js +134 -0
- package/build/models/Transfer.d.ts +335 -0
- package/build/models/Transfer.js +240 -0
- package/build/models/Wire.d.ts +213 -0
- package/build/models/Wire.js +264 -0
- package/build/models/Withdrawal.d.ts +201 -0
- package/build/models/Withdrawal.js +156 -0
- package/build/models/redaction.d.ts +18 -0
- package/build/models/redaction.js +23 -0
- package/build/sca/ScaClient.d.ts +105 -0
- package/build/sca/ScaClient.js +193 -0
- package/build/securekey/InMemorySecureKey.d.ts +23 -0
- package/build/securekey/InMemorySecureKey.js +127 -0
- package/build/securekey/NativeSecureKey.d.ts +24 -0
- package/build/securekey/NativeSecureKey.js +178 -0
- package/build/securekey/NativeSecureKeyBridge.d.ts +83 -0
- package/build/securekey/NativeSecureKeyBridge.js +19 -0
- package/build/securekey/SecureKey.d.ts +137 -0
- package/build/securekey/SecureKey.js +19 -0
- package/build/securekey/alias.d.ts +88 -0
- package/build/securekey/alias.js +175 -0
- package/build/securekey/ownerAuthKeyResolver.d.ts +56 -0
- package/build/securekey/ownerAuthKeyResolver.js +63 -0
- package/build/securekey/resolveNativeBridge.d.ts +30 -0
- package/build/securekey/resolveNativeBridge.js +120 -0
- package/build/testing.d.ts +18 -0
- package/build/testing.js +34 -0
- package/build/transport/DaaTransport.d.ts +35 -0
- package/build/transport/DaaTransport.js +19 -0
- package/build/transport/headers.d.ts +30 -0
- package/build/transport/headers.js +45 -0
- package/build/validation/requestBody.d.ts +27 -0
- package/build/validation/requestBody.js +56 -0
- package/build/validation/uuid.d.ts +25 -0
- package/build/validation/uuid.js +33 -0
- package/build/wire/accountLimitsUsagePayload.d.ts +30 -0
- package/build/wire/accountLimitsUsagePayload.js +130 -0
- package/build/wire/accountPayload.d.ts +36 -0
- package/build/wire/accountPayload.js +100 -0
- package/build/wire/achPayload.d.ts +24 -0
- package/build/wire/achPayload.js +82 -0
- package/build/wire/addressObjectPayload.d.ts +44 -0
- package/build/wire/addressObjectPayload.js +64 -0
- package/build/wire/daaStatusCodes.d.ts +64 -0
- package/build/wire/daaStatusCodes.js +69 -0
- package/build/wire/dataEnvelope.d.ts +40 -0
- package/build/wire/dataEnvelope.js +79 -0
- package/build/wire/depositPayload.d.ts +42 -0
- package/build/wire/depositPayload.js +159 -0
- package/build/wire/deviceContextPayload.d.ts +33 -0
- package/build/wire/deviceContextPayload.js +57 -0
- package/build/wire/deviceRegistrationResultPayload.d.ts +32 -0
- package/build/wire/deviceRegistrationResultPayload.js +128 -0
- package/build/wire/errorEnvelope.d.ts +43 -0
- package/build/wire/errorEnvelope.js +85 -0
- package/build/wire/fiatAccountPayload.d.ts +37 -0
- package/build/wire/fiatAccountPayload.js +93 -0
- package/build/wire/instant.d.ts +27 -0
- package/build/wire/instant.js +91 -0
- package/build/wire/jsonNumber.d.ts +30 -0
- package/build/wire/jsonNumber.js +34 -0
- package/build/wire/moneyPayload.d.ts +30 -0
- package/build/wire/moneyPayload.js +56 -0
- package/build/wire/paginationLinks.d.ts +28 -0
- package/build/wire/paginationLinks.js +167 -0
- package/build/wire/payload.d.ts +60 -0
- package/build/wire/payload.js +121 -0
- package/build/wire/pendingRegistrationPayload.d.ts +32 -0
- package/build/wire/pendingRegistrationPayload.js +54 -0
- package/build/wire/socialLoginRequestPayload.d.ts +31 -0
- package/build/wire/socialLoginRequestPayload.js +72 -0
- package/build/wire/transactionPayload.d.ts +31 -0
- package/build/wire/transactionPayload.js +126 -0
- package/build/wire/transferPayload.d.ts +43 -0
- package/build/wire/transferPayload.js +218 -0
- package/build/wire/wireEnums.d.ts +22 -0
- package/build/wire/wireEnums.js +69 -0
- package/build/wire/wirePayload.d.ts +29 -0
- package/build/wire/wirePayload.js +138 -0
- package/build/wire/withdrawalPayload.d.ts +27 -0
- package/build/wire/withdrawalPayload.js +179 -0
- package/expo-module.config.json +14 -0
- package/ios/DaaRegistrationExceptions.swift +58 -0
- package/ios/DaaRegistrationModule.swift +143 -0
- package/ios/DaaScaExceptions.swift +96 -0
- package/ios/DaaScaModule.swift +125 -0
- package/ios/DaaSecureKeyExceptions.swift +77 -0
- package/ios/DaaSecureKeyModule.swift +162 -0
- package/ios/InstallationIdentityStore.swift +126 -0
- package/ios/UnpaddedBase64URL.swift +42 -0
- package/package.json +114 -4
- package/src/DaaClient.ts +171 -0
- package/src/api/AccountLimitsClient.ts +146 -0
- package/src/api/AccountsClient.ts +305 -0
- package/src/api/AchFiatAccountsClient.ts +147 -0
- package/src/api/AuthClient.ts +331 -0
- package/src/api/DaaUserClient.ts +270 -0
- package/src/api/DepositAddressesClient.ts +239 -0
- package/src/api/DepositsClient.ts +208 -0
- package/src/api/FiatAccountsClient.ts +50 -0
- package/src/api/TransactionsClient.ts +137 -0
- package/src/api/TransfersClient.ts +361 -0
- package/src/api/WireFiatAccountsClient.ts +172 -0
- package/src/api/WithdrawalsClient.ts +339 -0
- package/src/api/loginFailure.ts +75 -0
- package/src/api/pagination.ts +63 -0
- package/src/api/queryParameters.ts +82 -0
- package/src/api/resourceRequest.ts +135 -0
- package/src/api/signedResource.ts +267 -0
- package/src/auth/RegistrationFlowKey.ts +274 -0
- package/src/auth/daaRegistrationNative.ts +236 -0
- package/src/auth/deviceAuthorization.ts +302 -0
- package/src/auth/ownerGrant.ts +102 -0
- package/src/auth/prepareReceipt.ts +522 -0
- package/src/auth/registrationAuthorization.ts +306 -0
- package/src/auth/registrationCodeVerifier.ts +76 -0
- package/src/config.ts +156 -0
- package/src/crypto/base64url.ts +88 -0
- package/src/crypto/bytes.ts +30 -0
- package/src/crypto/es256Jws.ts +240 -0
- package/src/crypto/jwkThumbprint.ts +65 -0
- package/src/crypto/random.ts +113 -0
- package/src/crypto/serialization.ts +42 -0
- package/src/crypto/sha256.ts +105 -0
- package/src/errors.ts +319 -0
- package/src/index.ts +223 -0
- package/src/models/Account.ts +264 -0
- package/src/models/AccountLimitsUsage.ts +192 -0
- package/src/models/Ach.ts +269 -0
- package/src/models/AddressObject.ts +169 -0
- package/src/models/BusinessPii.ts +154 -0
- package/src/models/CreateAccountRequest.ts +109 -0
- package/src/models/CreateTransferRequest.ts +114 -0
- package/src/models/CreateWithdrawalRequest.ts +120 -0
- package/src/models/DaaUserContext.ts +172 -0
- package/src/models/Deposit.ts +307 -0
- package/src/models/DepositSummary.ts +142 -0
- package/src/models/FiatAccount.ts +195 -0
- package/src/models/GenerateAddressRequest.ts +101 -0
- package/src/models/Money.ts +91 -0
- package/src/models/Page.ts +48 -0
- package/src/models/PendingDeviceRegistration.ts +197 -0
- package/src/models/PreparedSocialLogin.ts +287 -0
- package/src/models/Transaction.ts +247 -0
- package/src/models/Transfer.ts +459 -0
- package/src/models/Wire.ts +405 -0
- package/src/models/Withdrawal.ts +283 -0
- package/src/models/redaction.ts +22 -0
- package/src/sca/ScaClient.ts +289 -0
- package/src/securekey/InMemorySecureKey.ts +138 -0
- package/src/securekey/NativeSecureKey.ts +179 -0
- package/src/securekey/NativeSecureKeyBridge.ts +109 -0
- package/src/securekey/SecureKey.ts +149 -0
- package/src/securekey/alias.ts +204 -0
- package/src/securekey/ownerAuthKeyResolver.ts +96 -0
- package/src/securekey/resolveNativeBridge.ts +185 -0
- package/src/testing.ts +32 -0
- package/src/transport/DaaTransport.ts +42 -0
- package/src/transport/headers.ts +46 -0
- package/src/validation/requestBody.ts +60 -0
- package/src/validation/uuid.ts +31 -0
- package/src/wire/accountLimitsUsagePayload.ts +182 -0
- package/src/wire/accountPayload.ts +108 -0
- package/src/wire/achPayload.ts +98 -0
- package/src/wire/addressObjectPayload.ts +64 -0
- package/src/wire/daaStatusCodes.ts +69 -0
- package/src/wire/dataEnvelope.ts +80 -0
- package/src/wire/depositPayload.ts +186 -0
- package/src/wire/deviceContextPayload.ts +58 -0
- package/src/wire/deviceRegistrationResultPayload.ts +153 -0
- package/src/wire/errorEnvelope.ts +87 -0
- package/src/wire/fiatAccountPayload.ts +112 -0
- package/src/wire/instant.ts +93 -0
- package/src/wire/jsonNumber.ts +33 -0
- package/src/wire/moneyPayload.ts +55 -0
- package/src/wire/paginationLinks.ts +204 -0
- package/src/wire/payload.ts +146 -0
- package/src/wire/pendingRegistrationPayload.ts +75 -0
- package/src/wire/socialLoginRequestPayload.ts +89 -0
- package/src/wire/transactionPayload.ts +145 -0
- package/src/wire/transferPayload.ts +249 -0
- package/src/wire/wireEnums.ts +74 -0
- package/src/wire/wirePayload.ts +160 -0
- package/src/wire/withdrawalPayload.ts +219 -0
- package/testing.d.ts +19 -0
- package/testing.js +25 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.toDeviceRegistrationResult = toDeviceRegistrationResult;
|
|
21
|
+
const DaaUserContext_1 = require("../models/DaaUserContext");
|
|
22
|
+
const deviceContextPayload_1 = require("./deviceContextPayload");
|
|
23
|
+
const instant_1 = require("./instant");
|
|
24
|
+
const payload_1 = require("./payload");
|
|
25
|
+
const RECOVERY_REF_MIN = 16;
|
|
26
|
+
const RECOVERY_REF_MAX = 512;
|
|
27
|
+
function toActiveContext(payload, sessionClientEntityId) {
|
|
28
|
+
return new DaaUserContext_1.DaaUserContext(DaaUserContext_1.DECODER_TOKEN, {
|
|
29
|
+
clientEntityId: sessionClientEntityId,
|
|
30
|
+
deviceContext: (0, deviceContextPayload_1.toDeviceContext)(payload),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The DeviceContext-shaped object Complete returns: a flat payload, or
|
|
35
|
+
* nested `context.deviceContext` / `context` when `status: "ACTIVE"`.
|
|
36
|
+
*/
|
|
37
|
+
function deviceContextPayloadFromComplete(payload) {
|
|
38
|
+
if ((0, payload_1.optionalString)(payload, 'status') !== 'ACTIVE') {
|
|
39
|
+
return payload;
|
|
40
|
+
}
|
|
41
|
+
const contextPayload = (0, payload_1.optionalObject)(payload, 'context');
|
|
42
|
+
if (contextPayload === null) {
|
|
43
|
+
throw new payload_1.MalformedPayloadError('context');
|
|
44
|
+
}
|
|
45
|
+
return (0, payload_1.optionalObject)(contextPayload, 'deviceContext') ?? contextPayload;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Map Complete's `data` payload.
|
|
49
|
+
*
|
|
50
|
+
* The service returns a flat `DeviceContext`. The wrapped `{ status, context }`
|
|
51
|
+
* shape and `RECOVERY_PENDING` are also decoded when present. An absent
|
|
52
|
+
* `status` is read as that flat shape only on a positive signal: it still needs
|
|
53
|
+
* `deviceCredentialStatus === 'active'` (enforced by `toDeviceContext`), and
|
|
54
|
+
* it must carry neither `recoveryReference` nor `expiresAt` — the fields that
|
|
55
|
+
* belong to the `RECOVERY_PENDING` shape. A payload carrying either alongside
|
|
56
|
+
* an absent `status` is ambiguous and is rejected rather than resolved toward
|
|
57
|
+
* the more privileged `ACTIVE` outcome. Extra members are otherwise ignored.
|
|
58
|
+
* `clientEntityId` comes from Social Session, not this payload.
|
|
59
|
+
*/
|
|
60
|
+
function toDeviceRegistrationResult(value, sessionClientEntityId) {
|
|
61
|
+
const payload = (0, payload_1.asObject)(value, 'payload');
|
|
62
|
+
const status = (0, payload_1.optionalString)(payload, 'status');
|
|
63
|
+
if (status === 'RECOVERY_PENDING') {
|
|
64
|
+
if ((0, payload_1.optionalObject)(payload, 'context') !== null) {
|
|
65
|
+
throw new payload_1.MalformedPayloadError('context');
|
|
66
|
+
}
|
|
67
|
+
const recoveryReference = (0, payload_1.requiredString)(payload, 'recoveryReference');
|
|
68
|
+
if (recoveryReference.length < RECOVERY_REF_MIN ||
|
|
69
|
+
recoveryReference.length > RECOVERY_REF_MAX) {
|
|
70
|
+
throw new payload_1.MalformedPayloadError('recoveryReference');
|
|
71
|
+
}
|
|
72
|
+
const result = Object.freeze({
|
|
73
|
+
status: 'RECOVERY_PENDING',
|
|
74
|
+
recoveryReference,
|
|
75
|
+
// `expiresAt` accepts both timestamp forms, like the other login-flow
|
|
76
|
+
// timestamps on this response.
|
|
77
|
+
expiresAt: (0, instant_1.requiredDateTime)(payload, 'expiresAt'),
|
|
78
|
+
});
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
if (status === 'ACTIVE') {
|
|
82
|
+
const contextPayload = (0, payload_1.optionalObject)(payload, 'context');
|
|
83
|
+
if (contextPayload === null) {
|
|
84
|
+
throw new payload_1.MalformedPayloadError('context');
|
|
85
|
+
}
|
|
86
|
+
const nestedClient = (0, payload_1.optionalString)(contextPayload, 'clientEntityId');
|
|
87
|
+
if (nestedClient !== null && nestedClient !== sessionClientEntityId) {
|
|
88
|
+
throw new payload_1.MalformedPayloadError('clientEntityId');
|
|
89
|
+
}
|
|
90
|
+
const devicePayload = deviceContextPayloadFromComplete(payload);
|
|
91
|
+
const result = Object.freeze({
|
|
92
|
+
status: 'ACTIVE',
|
|
93
|
+
context: new DaaUserContext_1.DaaUserContext(DaaUserContext_1.DECODER_TOKEN, {
|
|
94
|
+
clientEntityId: sessionClientEntityId,
|
|
95
|
+
deviceContext: (0, deviceContextPayload_1.toDeviceContext)(devicePayload),
|
|
96
|
+
}),
|
|
97
|
+
});
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
if (status !== null) {
|
|
101
|
+
throw new payload_1.MalformedPayloadError('status');
|
|
102
|
+
}
|
|
103
|
+
// Flat shape: only decodable on a positive ACTIVE signal, never on
|
|
104
|
+
// the mere absence of `status`. `toActiveContext` still requires
|
|
105
|
+
// `deviceCredentialStatus === 'active'`; this additionally refuses a
|
|
106
|
+
// payload that also carries a `RECOVERY_PENDING` field, rather than
|
|
107
|
+
// silently preferring the more privileged outcome. The error names
|
|
108
|
+
// whichever `RECOVERY_PENDING` field is actually present — `status` itself
|
|
109
|
+
// is absent here, not malformed.
|
|
110
|
+
const conflictingRecoveryField = hasPresentField(payload, 'recoveryReference')
|
|
111
|
+
? 'recoveryReference'
|
|
112
|
+
: hasPresentField(payload, 'expiresAt')
|
|
113
|
+
? 'expiresAt'
|
|
114
|
+
: null;
|
|
115
|
+
if (conflictingRecoveryField !== null) {
|
|
116
|
+
throw new payload_1.MalformedPayloadError(conflictingRecoveryField);
|
|
117
|
+
}
|
|
118
|
+
const result = Object.freeze({
|
|
119
|
+
status: 'ACTIVE',
|
|
120
|
+
context: toActiveContext(payload, sessionClientEntityId),
|
|
121
|
+
});
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
/** JSON `null` is treated as absence, matching `optionalString`/`optionalObject`. */
|
|
125
|
+
function hasPresentField(payload, name) {
|
|
126
|
+
const value = payload[name];
|
|
127
|
+
return value !== undefined && value !== null;
|
|
128
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The DAA status code from an error body, when the body carries a readable one.
|
|
20
|
+
*
|
|
21
|
+
* Best-effort by design: a failed call must still surface its HTTP status and
|
|
22
|
+
* correlation id when the provider returned an empty body, a proxy's HTML error
|
|
23
|
+
* page, or a shape the contract does not describe. Losing the whole error because
|
|
24
|
+
* its detail did not parse would be worse than losing the detail, so every failure
|
|
25
|
+
* here is `null`.
|
|
26
|
+
*
|
|
27
|
+
* Only the code is lifted. The envelope's `message` and `externalMessage` are
|
|
28
|
+
* provider-authored text from a response the SDK cannot vouch for, and the SDK
|
|
29
|
+
* error model has nowhere to put them that is not a log line.
|
|
30
|
+
*
|
|
31
|
+
* DAA sends the flat platform error body, with the code at the **root**:
|
|
32
|
+
* `{"code":420034,"message":"…","externalMessage":"…"}`. The SDK also
|
|
33
|
+
* accepts the code at `status.code`, but only when the root `code` is absent.
|
|
34
|
+
* A root `code` that is present decides alone, even when it is unreadable or
|
|
35
|
+
* unknown and `status.code` is a known code. Present means the key exists with
|
|
36
|
+
* a value other than `null`. Neither is under `data`: the `data` success
|
|
37
|
+
* wrapper is never applied to an error response.
|
|
38
|
+
*
|
|
39
|
+
* A decimal-string code comes back as the number. Any other string comes back
|
|
40
|
+
* unchanged so that an `api` error can still show it, but it classifies
|
|
41
|
+
* nothing: `isDaaStatus` matches numbers only.
|
|
42
|
+
*/
|
|
43
|
+
export declare function readDaaStatusCode(bytes: Uint8Array | null): string | number | null;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.readDaaStatusCode = readDaaStatusCode;
|
|
21
|
+
const jsonNumber_1 = require("./jsonNumber");
|
|
22
|
+
/**
|
|
23
|
+
* The DAA status code from an error body, when the body carries a readable one.
|
|
24
|
+
*
|
|
25
|
+
* Best-effort by design: a failed call must still surface its HTTP status and
|
|
26
|
+
* correlation id when the provider returned an empty body, a proxy's HTML error
|
|
27
|
+
* page, or a shape the contract does not describe. Losing the whole error because
|
|
28
|
+
* its detail did not parse would be worse than losing the detail, so every failure
|
|
29
|
+
* here is `null`.
|
|
30
|
+
*
|
|
31
|
+
* Only the code is lifted. The envelope's `message` and `externalMessage` are
|
|
32
|
+
* provider-authored text from a response the SDK cannot vouch for, and the SDK
|
|
33
|
+
* error model has nowhere to put them that is not a log line.
|
|
34
|
+
*
|
|
35
|
+
* DAA sends the flat platform error body, with the code at the **root**:
|
|
36
|
+
* `{"code":420034,"message":"…","externalMessage":"…"}`. The SDK also
|
|
37
|
+
* accepts the code at `status.code`, but only when the root `code` is absent.
|
|
38
|
+
* A root `code` that is present decides alone, even when it is unreadable or
|
|
39
|
+
* unknown and `status.code` is a known code. Present means the key exists with
|
|
40
|
+
* a value other than `null`. Neither is under `data`: the `data` success
|
|
41
|
+
* wrapper is never applied to an error response.
|
|
42
|
+
*
|
|
43
|
+
* A decimal-string code comes back as the number. Any other string comes back
|
|
44
|
+
* unchanged so that an `api` error can still show it, but it classifies
|
|
45
|
+
* nothing: `isDaaStatus` matches numbers only.
|
|
46
|
+
*/
|
|
47
|
+
function readDaaStatusCode(bytes) {
|
|
48
|
+
if (bytes === null || bytes.length === 0) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
let root;
|
|
52
|
+
try {
|
|
53
|
+
root = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (!isObject(root)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const flat = root['code'];
|
|
62
|
+
if (flat !== undefined && flat !== null) {
|
|
63
|
+
return codeValue(flat);
|
|
64
|
+
}
|
|
65
|
+
const status = root['status'];
|
|
66
|
+
return isObject(status) ? codeValue(status['code']) : null;
|
|
67
|
+
}
|
|
68
|
+
function isObject(value) {
|
|
69
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
70
|
+
}
|
|
71
|
+
function codeValue(code) {
|
|
72
|
+
// A numeric code arrives as a number from `JSON.parse`. A status code is
|
|
73
|
+
// small enough that no rounding question arises, so it is handed back as it
|
|
74
|
+
// came.
|
|
75
|
+
if (typeof code === 'number') {
|
|
76
|
+
return Number.isFinite(code) ? code : null;
|
|
77
|
+
}
|
|
78
|
+
if (typeof code !== 'string' || code.length === 0) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
// A code the service quoted is handed back as a number when it is one, so a
|
|
82
|
+
// consumer can compare it without knowing which shape arrived. A string that
|
|
83
|
+
// is not a number is kept only for diagnostics on the `api` error.
|
|
84
|
+
return jsonNumber_1.JSON_NUMBER.test(code) ? Number(code) : code;
|
|
85
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import type { FiatAccountStatus } from '../models/FiatAccount';
|
|
19
|
+
import { BankAddress, BillingDetails } from '../models/FiatAccount';
|
|
20
|
+
export declare function toFiatAccountStatus(raw: string): FiatAccountStatus;
|
|
21
|
+
export declare function optionalBoolean(payload: Record<string, unknown>, name: string, label?: string): boolean | null;
|
|
22
|
+
/**
|
|
23
|
+
* Decode the guaranteed `BillingDetails` shape.
|
|
24
|
+
*
|
|
25
|
+
* The service requires `name`, `city`, `country`, `line1`, and `postalCode` on
|
|
26
|
+
* every wire/ACH fiat account, unlike `Account`'s optional `BusinessPii`
|
|
27
|
+
* enrichment — so a fiat account missing one of these is a broken contract,
|
|
28
|
+
* not a partially-enriched record.
|
|
29
|
+
*/
|
|
30
|
+
export declare function toBillingDetails(value: unknown, label: string): BillingDetails;
|
|
31
|
+
export declare function requiredBillingDetails(payload: Record<string, unknown>, name: string): BillingDetails;
|
|
32
|
+
/**
|
|
33
|
+
* Decode the optional `BankAddress` shape. Only `country` is guaranteed when
|
|
34
|
+
* the object is present at all.
|
|
35
|
+
*/
|
|
36
|
+
export declare function toBankAddress(value: unknown, label: string): BankAddress;
|
|
37
|
+
export declare function optionalBankAddress(payload: Record<string, unknown>, name: string): BankAddress | null;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.toFiatAccountStatus = toFiatAccountStatus;
|
|
21
|
+
exports.optionalBoolean = optionalBoolean;
|
|
22
|
+
exports.toBillingDetails = toBillingDetails;
|
|
23
|
+
exports.requiredBillingDetails = requiredBillingDetails;
|
|
24
|
+
exports.toBankAddress = toBankAddress;
|
|
25
|
+
exports.optionalBankAddress = optionalBankAddress;
|
|
26
|
+
const FiatAccount_1 = require("../models/FiatAccount");
|
|
27
|
+
const payload_1 = require("./payload");
|
|
28
|
+
/** Decoders shared by the wire and ACH fiat-account payloads (`wirePayload.ts`, `achPayload.ts`). */
|
|
29
|
+
const STATUSES = new Map([
|
|
30
|
+
['pending', Object.freeze({ kind: 'pending' })],
|
|
31
|
+
['complete', Object.freeze({ kind: 'complete' })],
|
|
32
|
+
['failed', Object.freeze({ kind: 'failed' })],
|
|
33
|
+
]);
|
|
34
|
+
function toFiatAccountStatus(raw) {
|
|
35
|
+
return STATUSES.get(raw) ?? (0, payload_1.unrecognized)(raw);
|
|
36
|
+
}
|
|
37
|
+
function optionalBoolean(payload, name, label = name) {
|
|
38
|
+
const value = payload[name];
|
|
39
|
+
if (value === undefined || value === null) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (typeof value !== 'boolean') {
|
|
43
|
+
throw new payload_1.MalformedPayloadError(label);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Decode the guaranteed `BillingDetails` shape.
|
|
49
|
+
*
|
|
50
|
+
* The service requires `name`, `city`, `country`, `line1`, and `postalCode` on
|
|
51
|
+
* every wire/ACH fiat account, unlike `Account`'s optional `BusinessPii`
|
|
52
|
+
* enrichment — so a fiat account missing one of these is a broken contract,
|
|
53
|
+
* not a partially-enriched record.
|
|
54
|
+
*/
|
|
55
|
+
function toBillingDetails(value, label) {
|
|
56
|
+
const payload = (0, payload_1.asObject)(value, label);
|
|
57
|
+
return new FiatAccount_1.BillingDetails({
|
|
58
|
+
name: (0, payload_1.requiredString)(payload, 'name', `${label}.name`),
|
|
59
|
+
city: (0, payload_1.requiredString)(payload, 'city', `${label}.city`),
|
|
60
|
+
country: (0, payload_1.requiredString)(payload, 'country', `${label}.country`),
|
|
61
|
+
line1: (0, payload_1.requiredString)(payload, 'line1', `${label}.line1`),
|
|
62
|
+
line2: (0, payload_1.optionalString)(payload, 'line2', `${label}.line2`),
|
|
63
|
+
district: (0, payload_1.optionalString)(payload, 'district', `${label}.district`),
|
|
64
|
+
postalCode: (0, payload_1.requiredString)(payload, 'postalCode', `${label}.postalCode`),
|
|
65
|
+
valid: optionalBoolean(payload, 'valid', `${label}.valid`),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function requiredBillingDetails(payload, name) {
|
|
69
|
+
const value = payload[name];
|
|
70
|
+
if (value === undefined || value === null) {
|
|
71
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
72
|
+
}
|
|
73
|
+
return toBillingDetails(value, name);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Decode the optional `BankAddress` shape. Only `country` is guaranteed when
|
|
77
|
+
* the object is present at all.
|
|
78
|
+
*/
|
|
79
|
+
function toBankAddress(value, label) {
|
|
80
|
+
const payload = (0, payload_1.asObject)(value, label);
|
|
81
|
+
return new FiatAccount_1.BankAddress({
|
|
82
|
+
bankName: (0, payload_1.optionalString)(payload, 'bankName', `${label}.bankName`),
|
|
83
|
+
city: (0, payload_1.optionalString)(payload, 'city', `${label}.city`),
|
|
84
|
+
country: (0, payload_1.requiredString)(payload, 'country', `${label}.country`),
|
|
85
|
+
line1: (0, payload_1.optionalString)(payload, 'line1', `${label}.line1`),
|
|
86
|
+
line2: (0, payload_1.optionalString)(payload, 'line2', `${label}.line2`),
|
|
87
|
+
district: (0, payload_1.optionalString)(payload, 'district', `${label}.district`),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function optionalBankAddress(payload, name) {
|
|
91
|
+
const value = (0, payload_1.optionalObject)(payload, name);
|
|
92
|
+
return value === null ? null : toBankAddress(value, name);
|
|
93
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* A login-flow timestamp the service guarantees, in either form it sends.
|
|
20
|
+
*
|
|
21
|
+
* The contract OpenAPI declares an ISO-8601 string and the running service
|
|
22
|
+
* sends a JSON number of epoch milliseconds, so the SDK accepts both. A number
|
|
23
|
+
* is normalised to the string form at this boundary, so every public timestamp
|
|
24
|
+
* stays one stable type no matter which form arrived. Anything that is neither
|
|
25
|
+
* form still fails closed.
|
|
26
|
+
*/
|
|
27
|
+
export declare function requiredDateTime(payload: Record<string, unknown>, name: string): string;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.requiredDateTime = requiredDateTime;
|
|
21
|
+
const payload_1 = require("./payload");
|
|
22
|
+
// The two wire forms a login-flow timestamp arrives in, and the single form
|
|
23
|
+
// the login decoders hand on.
|
|
24
|
+
//
|
|
25
|
+
// By default the service serialises a timestamp as a JSON number: an integral
|
|
26
|
+
// count of epoch milliseconds, not fractional seconds. Most timestamps opt out
|
|
27
|
+
// and are sent as ISO-8601 strings: every response carrying a `createDate` /
|
|
28
|
+
// `updateDate` does. Exactly three responses do not — Prepare
|
|
29
|
+
// (`PreparedSocialLogin`), Session and the device context — and those three are
|
|
30
|
+
// the login flow's three responses. The number form is therefore not a
|
|
31
|
+
// service-wide habit but a property of precisely the fields these decoders
|
|
32
|
+
// read, which is why this lives on its own rather than in `payload.ts` beside
|
|
33
|
+
// `requiredString`: a resource `createDate` arriving as a number would be a real
|
|
34
|
+
// contract violation, and `deposit`/`transfer`/`withdrawal` must keep rejecting
|
|
35
|
+
// it.
|
|
36
|
+
//
|
|
37
|
+
// The three fields are `PreparedSocialLogin.expiresAt`,
|
|
38
|
+
// `SocialSession.expiresAt` and `DeviceContext.resolvedAt`. They are the same
|
|
39
|
+
// kind of field, serialised the same way, so all three accept both forms.
|
|
40
|
+
/**
|
|
41
|
+
* The ISO-8601 form the contract declares for an `Instant`, with a `T`
|
|
42
|
+
* separator. The service does not always send this form — see `requiredDateTime`
|
|
43
|
+
* — but it is the single form these decoders hand on.
|
|
44
|
+
*/
|
|
45
|
+
const DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
|
|
46
|
+
/**
|
|
47
|
+
* Render epoch milliseconds as the same ISO-8601 text the string form carries.
|
|
48
|
+
*
|
|
49
|
+
* Three checks, no coercions. A fractional, non-finite, or beyond-safe-integer
|
|
50
|
+
* value is not a count of milliseconds, and zero or below is a field that
|
|
51
|
+
* arrived as a number without being a timestamp. What survives that can still be
|
|
52
|
+
* outside the range `Date` represents, so the instant is checked before it is
|
|
53
|
+
* rendered. The rendered text then has to satisfy `DATE_TIME` exactly as the
|
|
54
|
+
* string form does — which is what bounds the year, rather than an invented
|
|
55
|
+
* constant: an epoch rendering `'+275760-09-13T00:00:00.000Z'` is rejected here
|
|
56
|
+
* for the same reason that string would be.
|
|
57
|
+
*/
|
|
58
|
+
function fromEpochMillis(value, name) {
|
|
59
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
60
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
61
|
+
}
|
|
62
|
+
const instant = new Date(value);
|
|
63
|
+
if (Number.isNaN(instant.getTime())) {
|
|
64
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
65
|
+
}
|
|
66
|
+
const text = instant.toISOString();
|
|
67
|
+
if (!DATE_TIME.test(text)) {
|
|
68
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
69
|
+
}
|
|
70
|
+
return text;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A login-flow timestamp the service guarantees, in either form it sends.
|
|
74
|
+
*
|
|
75
|
+
* The contract OpenAPI declares an ISO-8601 string and the running service
|
|
76
|
+
* sends a JSON number of epoch milliseconds, so the SDK accepts both. A number
|
|
77
|
+
* is normalised to the string form at this boundary, so every public timestamp
|
|
78
|
+
* stays one stable type no matter which form arrived. Anything that is neither
|
|
79
|
+
* form still fails closed.
|
|
80
|
+
*/
|
|
81
|
+
function requiredDateTime(payload, name) {
|
|
82
|
+
const raw = payload[name];
|
|
83
|
+
if (typeof raw === 'number') {
|
|
84
|
+
return fromEpochMillis(raw, name);
|
|
85
|
+
}
|
|
86
|
+
const value = (0, payload_1.requiredString)(payload, name);
|
|
87
|
+
if (!DATE_TIME.test(value)) {
|
|
88
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* RFC 8259's number grammar.
|
|
20
|
+
*
|
|
21
|
+
* The service sends `Money.amount` as a plain decimal JSON **string**, not a
|
|
22
|
+
* number. So the exact decimal survives
|
|
23
|
+
* `JSON.parse` untouched, and nothing on the way in checks that the text is a
|
|
24
|
+
* number at all — the OpenAPI's `type: number` describes the schema, not the
|
|
25
|
+
* wire.
|
|
26
|
+
*
|
|
27
|
+
* That makes this the **only** check on an amount rather than a second one, which
|
|
28
|
+
* is why it lives on its own rather than beside a decoder.
|
|
29
|
+
*/
|
|
30
|
+
export declare const JSON_NUMBER: RegExp;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.JSON_NUMBER = void 0;
|
|
21
|
+
// The JSON number grammar, applied to values that arrive as text.
|
|
22
|
+
/**
|
|
23
|
+
* RFC 8259's number grammar.
|
|
24
|
+
*
|
|
25
|
+
* The service sends `Money.amount` as a plain decimal JSON **string**, not a
|
|
26
|
+
* number. So the exact decimal survives
|
|
27
|
+
* `JSON.parse` untouched, and nothing on the way in checks that the text is a
|
|
28
|
+
* number at all — the OpenAPI's `type: number` describes the schema, not the
|
|
29
|
+
* wire.
|
|
30
|
+
*
|
|
31
|
+
* That makes this the **only** check on an amount rather than a second one, which
|
|
32
|
+
* is why it lives on its own rather than beside a decoder.
|
|
33
|
+
*/
|
|
34
|
+
exports.JSON_NUMBER = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { Money } from '../models/Money';
|
|
19
|
+
/**
|
|
20
|
+
* Decode the shared `Money` wire shape without coercing its decimal.
|
|
21
|
+
*
|
|
22
|
+
* The service serializes `amount` as a plain decimal JSON string. Accepting a JSON number would lose precision in
|
|
23
|
+
* `JSON.parse` before this decoder could inspect it, so only an RFC 8259
|
|
24
|
+
* number-shaped string is accepted. `Money` owns redaction of the amount.
|
|
25
|
+
*/
|
|
26
|
+
export declare function toMoney(value: unknown, label: string): Money;
|
|
27
|
+
/** Decode a guaranteed money field. */
|
|
28
|
+
export declare function requiredMoney(payload: Record<string, unknown>, name: string): Money;
|
|
29
|
+
/** Decode a money field the service may omit. JSON `null` is absence. */
|
|
30
|
+
export declare function optionalMoney(payload: Record<string, unknown>, name: string): Money | null;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.toMoney = toMoney;
|
|
21
|
+
exports.requiredMoney = requiredMoney;
|
|
22
|
+
exports.optionalMoney = optionalMoney;
|
|
23
|
+
const Money_1 = require("../models/Money");
|
|
24
|
+
const jsonNumber_1 = require("./jsonNumber");
|
|
25
|
+
const payload_1 = require("./payload");
|
|
26
|
+
/**
|
|
27
|
+
* Decode the shared `Money` wire shape without coercing its decimal.
|
|
28
|
+
*
|
|
29
|
+
* The service serializes `amount` as a plain decimal JSON string. Accepting a JSON number would lose precision in
|
|
30
|
+
* `JSON.parse` before this decoder could inspect it, so only an RFC 8259
|
|
31
|
+
* number-shaped string is accepted. `Money` owns redaction of the amount.
|
|
32
|
+
*/
|
|
33
|
+
function toMoney(value, label) {
|
|
34
|
+
const payload = (0, payload_1.asObject)(value, label);
|
|
35
|
+
const amount = (0, payload_1.requiredString)(payload, 'amount', `${label}.amount`);
|
|
36
|
+
if (!jsonNumber_1.JSON_NUMBER.test(amount)) {
|
|
37
|
+
throw new payload_1.MalformedPayloadError(`${label}.amount`);
|
|
38
|
+
}
|
|
39
|
+
return new Money_1.Money(amount, (0, payload_1.requiredString)(payload, 'currency', `${label}.currency`));
|
|
40
|
+
}
|
|
41
|
+
/** Decode a guaranteed money field. */
|
|
42
|
+
function requiredMoney(payload, name) {
|
|
43
|
+
const value = payload[name];
|
|
44
|
+
if (value === undefined || value === null) {
|
|
45
|
+
throw new payload_1.MalformedPayloadError(name);
|
|
46
|
+
}
|
|
47
|
+
return toMoney(value, name);
|
|
48
|
+
}
|
|
49
|
+
/** Decode a money field the service may omit. JSON `null` is absence. */
|
|
50
|
+
function optionalMoney(payload, name) {
|
|
51
|
+
const value = payload[name];
|
|
52
|
+
if (value === undefined || value === null) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return toMoney(value, name);
|
|
56
|
+
}
|