@1shotapi/1shotpay-common 0.1.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 ADDED
@@ -0,0 +1,75 @@
1
+ # @1shotapi/1shotpay-common
2
+
3
+ Shared types and utilities for the 1ShotPay client and server SDKs, and other 1ShotAPI services. Published as **@1shotapi/1shotpay-common**.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ yarn add @1shotapi/1shotpay-common
9
+ ```
10
+
11
+ ## Coding conventions
12
+
13
+ ### neverthrow (`ResultAsync`)
14
+
15
+ This package uses **neverthrow** to model success/error as values rather than exceptions:
16
+
17
+ - Functions often return `ResultAsync<T, E>` instead of throwing.
18
+ - You handle outcomes using `.map(...)`, `.andThen(...)`, and `.match(okFn, errFn)`.
19
+
20
+ This keeps error handling explicit and composable, and is shared across the client and server SDKs.
21
+
22
+ ### Branded Types (type-safe primitives)
23
+
24
+ Core primitives like `UserId`, `PayLinkId`, `DecimalAmount`, `EVMAccountAddress`, `URLString`, etc. are implemented as **branded types**. At runtime they are just strings or numbers, but at the type level they are distinct so you cannot accidentally mix them.
25
+
26
+ Example:
27
+
28
+ ```ts
29
+ import {
30
+ EVMAccountAddress,
31
+ DecimalAmount,
32
+ PayLinkId,
33
+ URLString,
34
+ UserId,
35
+ } from "@1shotapi/1shotpay-common";
36
+
37
+ const userId = UserId("123e4567-e89b-12d3-a456-426614174000");
38
+ const amount = DecimalAmount(0.01);
39
+ const address = EVMAccountAddress("0xADDRESS");
40
+ const payLinkId = PayLinkId("123e4567-e89b-12d3-a456-426614174000");
41
+ const mediaUrl = URLString("https://example.com/product.png");
42
+ ```
43
+
44
+ These branded constructors are simple wrappers from `ts-brand` and are the preferred way to construct values passed into other 1ShotPay/1ShotAPI APIs.
45
+
46
+ ### `resultAsyncToPromise()` (async/await bridge)
47
+
48
+ If you prefer `async/await` to chaining, `resultAsyncToPromise()` converts a `ResultAsync<T, Error>` into a `Promise<T>` that throws on error:
49
+
50
+ ```ts
51
+ import { resultAsyncToPromise } from "@1shotapi/1shotpay-common";
52
+
53
+ // given some ResultAsync<T, Error> value
54
+ const value = await resultAsyncToPromise(someResultAsync);
55
+ ```
56
+
57
+ ## Contents
58
+
59
+ - **Types:** enums, primitives (e.g. `EVMAccountAddress`, `BigNumberString`), domain models, errors
60
+ - **Utils:** `ObjectUtils`, x402 helpers (`x402ParseJsonOrBase64Json`, `x402GetChainIdFromNetwork`, etc.)
61
+
62
+ You usually depend on this package indirectly via `@1shotapi/1shotpay-client-sdk` or `@1shotapi/1shotpay-server-sdk`. Use it directly if you only need shared types/utilities.
63
+
64
+ ## Build & publish (from repo root)
65
+
66
+ ```bash
67
+ yarn workspace @1shotapi/1shotpay-common run build
68
+ yarn publish:common # build + npm publish
69
+ ```
70
+
71
+ ## Scripts (inside this package)
72
+
73
+ - `yarn build` — compile to `dist/`
74
+ - `yarn typecheck` — run `tsc --noEmit`
75
+ - `yarn clean` — remove `dist/`