@capxul/sdk 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/dist/{InMemoryAuthCacheAdapter-Rc8tCtml.mjs → InMemoryAuthCacheAdapter-PycLJWeW.mjs} +12 -2
- package/dist/{create-capxul-client-CMUq5w10.mjs → create-capxul-client-B8qMV-_e.mjs} +727 -530
- package/dist/index.d.mts +25 -64
- package/dist/index.mjs +141 -88
- package/dist/node/index.d.mts +1 -1
- package/dist/node/index.mjs +1 -1
- package/dist/{create-capxul-client-DmV6qEq4.d.mts → observation-BwPo8qeo.d.mts} +103 -17
- package/dist/{signer-Bj4F-RwT.d.mts → signer-D4roBkcX.d.mts} +94 -1
- package/dist/testing/index.d.mts +3 -1
- package/dist/testing/index.mjs +4 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -19,6 +19,30 @@ const client = created.value;
|
|
|
19
19
|
Every public operation resolves a `Promise<CapxulResult<T>>`. Domain failures
|
|
20
20
|
are values, not thrown exceptions.
|
|
21
21
|
|
|
22
|
+
## Money input and display
|
|
23
|
+
|
|
24
|
+
Use the public money helpers at form and display boundaries. They do not
|
|
25
|
+
convert a money value to a JavaScript number.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { formatMoney, parseMoney } from "@capxul/sdk";
|
|
29
|
+
|
|
30
|
+
const amount = parseMoney("1,000.25", {
|
|
31
|
+
currency: account.available.currency,
|
|
32
|
+
decimals: account.available.decimals,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if ("kind" in amount) {
|
|
36
|
+
console.error(amount.reason); // closed code — the app owns the sentence (ADR-0023)
|
|
37
|
+
} else {
|
|
38
|
+
console.log(formatMoney(amount)); // $1,000.25
|
|
39
|
+
console.log(formatMoney(amount, { grammar: "code" })); // 1,000.25 USD
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`parseMoney` returns validation errors as values. `formatMoney` rejects a
|
|
44
|
+
malformed `Money` record with `INVALID_INPUT`.
|
|
45
|
+
|
|
22
46
|
## Observability
|
|
23
47
|
|
|
24
48
|
Hosts can attach the PostHog client they already initialized through one
|
package/dist/{InMemoryAuthCacheAdapter-Rc8tCtml.mjs → InMemoryAuthCacheAdapter-PycLJWeW.mjs}
RENAMED
|
@@ -263,10 +263,11 @@ const SUPPORTED_CURRENCIES = [
|
|
|
263
263
|
}
|
|
264
264
|
];
|
|
265
265
|
const SUPPORTED_CURRENCY_CODES = SUPPORTED_CURRENCIES.map((currency) => currency.code);
|
|
266
|
-
Object.fromEntries(SUPPORTED_CURRENCIES.map((currency) => [currency.code, currency.symbol]));
|
|
266
|
+
const CURRENCY_SYMBOLS = Object.fromEntries(SUPPORTED_CURRENCIES.map((currency) => [currency.code, currency.symbol]));
|
|
267
267
|
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
268
268
|
const COUNTRY_CODE_RE = /^[A-Z]{2}$/;
|
|
269
269
|
const ACCOUNT_ID_RE = /^account_[0-9A-Za-z]+$/;
|
|
270
|
+
const PARTY_ID_RE = /^party_[0-9A-Za-z]+$/;
|
|
270
271
|
const APP_ID_RE = /^app_[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
|
|
271
272
|
const WEI_RE = /^[0-9]+$/;
|
|
272
273
|
Math.floor(Number.MAX_SAFE_INTEGER / 1e3);
|
|
@@ -285,6 +286,10 @@ function toAccountId(raw) {
|
|
|
285
286
|
if (typeof raw !== "string" || !ACCOUNT_ID_RE.test(raw)) throw Errors.invalidInput("accountId", invalidValueReason("must be account_ plus an alphanumeric id", raw));
|
|
286
287
|
return raw;
|
|
287
288
|
}
|
|
289
|
+
function toPartyId(raw) {
|
|
290
|
+
if (typeof raw !== "string" || !PARTY_ID_RE.test(raw)) throw Errors.invalidInput("partyId", invalidValueReason("must be party_ plus an alphanumeric id", raw));
|
|
291
|
+
return raw;
|
|
292
|
+
}
|
|
288
293
|
function toOrgId(raw) {
|
|
289
294
|
return toNonEmptyStringBrand(raw, "orgId");
|
|
290
295
|
}
|
|
@@ -328,6 +333,11 @@ function toCurrencyCode(raw) {
|
|
|
328
333
|
if (typeof raw !== "string" || !SUPPORTED_CURRENCY_CODES.includes(raw)) throw Errors.invalidInput("currencyCode", invalidValueReason("unsupported currency", raw));
|
|
329
334
|
return raw;
|
|
330
335
|
}
|
|
336
|
+
function currencySymbolFor(code) {
|
|
337
|
+
const symbol = CURRENCY_SYMBOLS[code];
|
|
338
|
+
if (symbol === void 0) throw Errors.invalidInput("currencyCode", `no symbol registered for "${String(code)}"`);
|
|
339
|
+
return symbol;
|
|
340
|
+
}
|
|
331
341
|
function toKycTier(raw) {
|
|
332
342
|
if (typeof raw !== "number" || !Number.isInteger(raw) || raw < 0 || raw > 3) throw Errors.invalidInput("kycTier", invalidValueReason("must be an integer in [0, 3]", raw));
|
|
333
343
|
return raw;
|
|
@@ -475,4 +485,4 @@ Layer.effect(AuthCachePortTag, Effect.sync(() => new InMemoryAuthCacheAdapter())
|
|
|
475
485
|
cause
|
|
476
486
|
}))));
|
|
477
487
|
//#endregion
|
|
478
|
-
export {
|
|
488
|
+
export { toPublishableKey as A, toEmail as C, toKycTier as D, toJwtToken as E, CapxulError as F, EXPECTED_OPERATION_OUTCOMES as I, Errors as L, toSessionToken as M, decodeConvexError as N, toOrgId as O, CAPXUL_ERROR_CODES as P, isCapxulError as R, toDurationMs as S, toEpochSeconds as T, toAppId as _, AuthCacheError as a, toCountryCode as b, BYTES32_RE as c, WEI_RE as d, ZERO_BYTES32 as f, toAllowedOrigin as g, toAddress as h, parseCachedJwt as i, toRoleKey as j, toPartyId as k, EVM_ADDRESS_RE as l, toAccountId as m, BrowserAuthCacheAdapter as n, AuthCachePortTag as o, currencySymbolFor as p, parseAuthSession as r, APP_ID_RE as s, InMemoryAuthCacheAdapter as t, SUPPORTED_CURRENCY_CODES as u, toAuthUserId as v, toEpochMs as w, toCurrencyCode as x, toChainId as y };
|