@capxul/sdk 2.1.1 → 2.3.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,13 @@ 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
+ }
293
+ function toBudgetId(raw) {
294
+ return toNonEmptyStringBrand(raw, "budgetId");
295
+ }
288
296
  function toOrgId(raw) {
289
297
  return toNonEmptyStringBrand(raw, "orgId");
290
298
  }
@@ -328,6 +336,11 @@ function toCurrencyCode(raw) {
328
336
  if (typeof raw !== "string" || !SUPPORTED_CURRENCY_CODES.includes(raw)) throw Errors.invalidInput("currencyCode", invalidValueReason("unsupported currency", raw));
329
337
  return raw;
330
338
  }
339
+ function currencySymbolFor(code) {
340
+ const symbol = CURRENCY_SYMBOLS[code];
341
+ if (symbol === void 0) throw Errors.invalidInput("currencyCode", `no symbol registered for "${String(code)}"`);
342
+ return symbol;
343
+ }
331
344
  function toKycTier(raw) {
332
345
  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
346
  return raw;
@@ -475,4 +488,4 @@ Layer.effect(AuthCachePortTag, Effect.sync(() => new InMemoryAuthCacheAdapter())
475
488
  cause
476
489
  }))));
477
490
  //#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 };
491
+ export { toPartyId as A, toDurationMs as C, toJwtToken as D, toEpochSeconds as E, CAPXUL_ERROR_CODES as F, CapxulError as I, EXPECTED_OPERATION_OUTCOMES as L, toRoleKey as M, toSessionToken as N, toKycTier as O, decodeConvexError as P, Errors as R, toCurrencyCode as S, toEpochMs as T, toAppId as _, AuthCacheError as a, toChainId as b, BYTES32_RE as c, WEI_RE as d, ZERO_BYTES32 as f, toAllowedOrigin as g, toAddress as h, parseCachedJwt as i, toPublishableKey as j, toOrgId 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, toEmail as w, toCountryCode as x, toBudgetId as y, isCapxulError as z };