@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 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
@@ -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 { toSessionToken as A, toEpochMs as C, toOrgId as D, toKycTier as E, isCapxulError as F, CapxulError as M, EXPECTED_OPERATION_OUTCOMES as N, toPublishableKey as O, Errors as P, toEmail as S, toJwtToken as T, toAuthUserId as _, AuthCacheError as a, toCurrencyCode as b, BYTES32_RE as c, WEI_RE as d, ZERO_BYTES32 as f, toAppId as g, toAllowedOrigin as h, parseCachedJwt as i, decodeConvexError as j, toRoleKey as k, EVM_ADDRESS_RE as l, toAddress as m, BrowserAuthCacheAdapter as n, AuthCachePortTag as o, toAccountId as p, parseAuthSession as r, APP_ID_RE as s, InMemoryAuthCacheAdapter as t, SUPPORTED_CURRENCY_CODES as u, toChainId as v, toEpochSeconds as w, toDurationMs as x, toCountryCode as y };
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 };