azurite-checkout 0.0.0-stage → 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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/dist/_contract/common.d.ts +106 -0
  4. package/dist/_contract/common.js +189 -0
  5. package/dist/_contract/errors.d.ts +1184 -0
  6. package/dist/_contract/errors.js +321 -0
  7. package/dist/_contract/event-types.d.ts +7 -0
  8. package/dist/_contract/event-types.js +25 -0
  9. package/dist/_contract/events.d.ts +5320 -0
  10. package/dist/_contract/events.js +99 -0
  11. package/dist/_contract/idempotency.d.ts +18 -0
  12. package/dist/_contract/idempotency.js +21 -0
  13. package/dist/_contract/ids.d.ts +49 -0
  14. package/dist/_contract/ids.js +83 -0
  15. package/dist/_contract/keys.d.ts +27 -0
  16. package/dist/_contract/keys.js +33 -0
  17. package/dist/_contract/money.d.ts +63 -0
  18. package/dist/_contract/money.js +101 -0
  19. package/dist/_contract/objects.d.ts +736 -0
  20. package/dist/_contract/objects.js +384 -0
  21. package/dist/_contract/open.d.ts +23 -0
  22. package/dist/_contract/open.js +22 -0
  23. package/dist/_contract/route.d.ts +171 -0
  24. package/dist/_contract/route.js +65 -0
  25. package/dist/_contract/routes/v1-bodies.d.ts +361 -0
  26. package/dist/_contract/routes/v1-bodies.js +156 -0
  27. package/dist/_contract/routes/v1.d.ts +4473 -0
  28. package/dist/_contract/routes/v1.js +536 -0
  29. package/dist/call.d.ts +35 -0
  30. package/dist/call.js +151 -0
  31. package/dist/config.d.ts +41 -0
  32. package/dist/config.js +49 -0
  33. package/dist/contract.d.ts +9 -0
  34. package/dist/contract.js +10 -0
  35. package/dist/credit.d.ts +28 -0
  36. package/dist/credit.js +36 -0
  37. package/dist/effect.d.ts +19037 -0
  38. package/dist/effect.js +46 -0
  39. package/dist/errors.d.ts +90 -0
  40. package/dist/errors.js +113 -0
  41. package/dist/helpers.d.ts +82 -0
  42. package/dist/helpers.js +79 -0
  43. package/dist/index.d.ts +9586 -0
  44. package/dist/index.js +103 -0
  45. package/dist/issues.d.ts +8 -0
  46. package/dist/issues.js +10 -0
  47. package/dist/operations.d.ts +4582 -0
  48. package/dist/operations.js +146 -0
  49. package/dist/prepare.d.ts +19 -0
  50. package/dist/prepare.js +96 -0
  51. package/dist/run.d.ts +5 -0
  52. package/dist/run.js +12 -0
  53. package/dist/send.d.ts +19 -0
  54. package/dist/send.js +53 -0
  55. package/dist/shapes.d.ts +38 -0
  56. package/dist/shapes.js +1 -0
  57. package/dist/tools.d.ts +17 -0
  58. package/dist/tools.js +67 -0
  59. package/dist/webhooks.d.ts +58 -0
  60. package/dist/webhooks.js +121 -0
  61. package/llms.txt +204 -0
  62. package/package.json +47 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 the crypto-checkout authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # azurite-checkout
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Typed client for the checkout API: make invoices, check webhooks, give credit exactly once.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install azurite-checkout
9
+ ```
10
+
11
+ - **Two doors, same behaviour.** Promises: `import { createCheckout } from "azurite-checkout"`.
12
+ Effect: `import { Checkout } from "azurite-checkout/effect"`.
13
+ - **Never throws for an expected failure.** Every call returns `{ ok, data }` or `{ ok, error }`.
14
+ Each error has a fixed `code`, a plain-words `fix` and `retryable`.
15
+ - **Safe retries.** Network faults, timeouts, 429 and 5xx are retried with backoff. Creates carry
16
+ an idempotency key, kept across retries.
17
+ - **Checked both ways.** Your input is checked against the contract before sending; the server's
18
+ answer is checked before you see it.
19
+ - **Runs on** Node 22+, Bun, Deno and Cloudflare Workers. It refuses to start in a browser.
20
+
21
+ ## Start in four steps
22
+
23
+ 1. Get a practice key (`ck_practice_…`). Keep it in an environment variable, never in code.
24
+ 2. Make an invoice and send the customer to `pay_url`:
25
+
26
+ ```ts
27
+ const checkout = createCheckout({ apiKey: process.env.CHECKOUT_API_KEY ?? "", baseUrl });
28
+ const made = await checkout.invoices.create(
29
+ { amount: "20.00", currency: "USD", order_id: "topup-8841" },
30
+ { idempotencyKey: "invoice-topup-8841" },
31
+ );
32
+ if (made.ok) redirect(made.data.pay_url);
33
+ else console.error(made.error.code, made.error.fix);
34
+ ```
35
+
36
+ 3. On each webhook: `verifyWebhook` on the raw body, answer 2xx, then
37
+ `checkout.syncCredit(invoiceId, ledger)`. See `llms.txt`.
38
+ 4. Rehearse every case with `checkout.test.pay({ id, scenario })`. See `llms.txt`.
39
+
40
+ ## More
41
+
42
+ - [`llms.txt`](./llms.txt): the whole SDK on one page, written for people and AI agents.
43
+ - Every method has a doc comment with its fields and error codes; your editor shows it.
@@ -0,0 +1,106 @@
1
+ import { Effect, Schema } from "effect";
2
+ /** UTC time as text, to the second: `2026-12-04T03:00:00Z`. */
3
+ export declare const Timestamp: Schema.brand<Schema.String, "Timestamp">;
4
+ export type Timestamp = typeof Timestamp.Type;
5
+ /** Drops the part below a second. */
6
+ export declare const toTimestamp: (date: Date) => Timestamp;
7
+ /** Live uses real networks and real money. Practice uses neither. Their data never mixes. */
8
+ export declare const modes: readonly ["live", "practice"];
9
+ export declare const Mode: Schema.Literals<readonly ["live", "practice"]>;
10
+ export type Mode = typeof Mode.Type;
11
+ export declare const networkIds: readonly ["base", "polygon", "arbitrum", "bnb", "ethereum", "bitcoin", "litecoin", "solana", "tron"];
12
+ export type KnownNetworkId = (typeof networkIds)[number];
13
+ export declare const NetworkId: Schema.Union<readonly [Schema.Literals<readonly ["base", "polygon", "arbitrum", "bnb", "ethereum", "bitcoin", "litecoin", "solana", "tron"]>, Schema.brand<Schema.String, "UnknownValue">]>;
14
+ export type NetworkId = typeof NetworkId.Type;
15
+ export declare const addressFamilies: readonly ["evm", "bitcoin", "litecoin", "solana", "tron"];
16
+ /** Closed: adding one needs a new vault, so it never appears by surprise. */
17
+ export declare const AddressFamily: Schema.Literals<readonly ["evm", "bitcoin", "litecoin", "solana", "tron"]>;
18
+ export type AddressFamily = typeof AddressFamily.Type;
19
+ export declare const networkFamily: {
20
+ readonly base: "evm";
21
+ readonly polygon: "evm";
22
+ readonly arbitrum: "evm";
23
+ readonly bnb: "evm";
24
+ readonly ethereum: "evm";
25
+ readonly bitcoin: "bitcoin";
26
+ readonly litecoin: "litecoin";
27
+ readonly solana: "solana";
28
+ readonly tron: "tron";
29
+ };
30
+ export declare const coinIds: readonly ["usdc", "usdt", "btc", "eth", "ltc", "sol"];
31
+ export type KnownCoinId = (typeof coinIds)[number];
32
+ export declare const CoinId: Schema.Union<readonly [Schema.Literals<readonly ["usdc", "usdt", "btc", "eth", "ltc", "sol"]>, Schema.brand<Schema.String, "UnknownValue">]>;
33
+ export type CoinId = typeof CoinId.Type;
34
+ /** Every coin-on-a-network we know. Which ones a merchant offers is a setting. */
35
+ export declare const methodIds: readonly ["usdc_base", "usdc_polygon", "usdc_arbitrum", "usdt_polygon", "usdt_arbitrum", "usdt_bnb", "btc_bitcoin", "eth_ethereum", "usdc_ethereum", "usdt_ethereum", "ltc_litecoin", "sol_solana", "usdt_tron"];
36
+ export type KnownMethodId = (typeof methodIds)[number];
37
+ /** In answers. */
38
+ export declare const MethodId: Schema.Union<readonly [Schema.Literals<readonly ["usdc_base", "usdc_polygon", "usdc_arbitrum", "usdt_polygon", "usdt_arbitrum", "usdt_bnb", "btc_bitcoin", "eth_ethereum", "usdc_ethereum", "usdt_ethereum", "ltc_litecoin", "sol_solana", "usdt_tron"]>, Schema.brand<Schema.String, "UnknownValue">]>;
39
+ export type MethodId = typeof MethodId.Type;
40
+ /** In requests. Closed, so a typo is refused. */
41
+ export declare const MethodIdInput: Schema.Literals<readonly ["usdc_base", "usdc_polygon", "usdc_arbitrum", "usdt_polygon", "usdt_arbitrum", "usdt_bnb", "btc_bitcoin", "eth_ethereum", "usdc_ethereum", "usdt_ethereum", "ltc_litecoin", "sol_solana", "usdt_tron"]>;
42
+ /** Where coins and transactions are identified exactly. */
43
+ export declare const TxId: Schema.brand<Schema.String, "TxId">;
44
+ export type TxId = typeof TxId.Type;
45
+ export declare const ChainAddress: Schema.brand<Schema.String, "ChainAddress">;
46
+ export type ChainAddress = typeof ChainAddress.Type;
47
+ /**
48
+ * A secure web address. Used for everything we send people to or send data to: webhooks, logos,
49
+ * return and panel sites, and our own pages. Plain http could be read or changed on the way.
50
+ */
51
+ export declare const HttpsUrl: Schema.String;
52
+ /**
53
+ * Any web address, http allowed. Only for a waitlist answer's own website: we never send anyone
54
+ * or anything there, and some small businesses still have http-only sites.
55
+ */
56
+ export declare const UrlText: Schema.String;
57
+ /** A website's front door: https, host, no path. Return and panel sites must be secure. */
58
+ export declare const Origin: Schema.String;
59
+ export declare const Email: Schema.String;
60
+ export declare const Country: Schema.String;
61
+ export declare const Colour: Schema.String;
62
+ /** Your own order number. Letters, numbers and . _ : / # - only, so no email fits in it. */
63
+ export declare const OrderId: Schema.brand<Schema.String, "OrderId">;
64
+ export type OrderId = typeof OrderId.Type;
65
+ /** Your own code for a customer. Not a name or email. */
66
+ export declare const CustomerRef: Schema.brand<Schema.String, "CustomerRef">;
67
+ export type CustomerRef = typeof CustomerRef.Type;
68
+ /** Up to 20 of your own notes. */
69
+ export declare const Metadata: Schema.$Record<Schema.String, Schema.String>;
70
+ /** Seconds to pay: 15 minutes to 30 days. */
71
+ export declare const ExpiresIn: Schema.Int;
72
+ export declare const Reason: Schema.Trimmed;
73
+ /** In code it's a number. On the wire it's text, because it's in the web address. */
74
+ export declare const Limit: Schema.Union<readonly [Schema.Int, Schema.decodeTo<Schema.Int, Schema.String, never, never>]>;
75
+ /** A yes or no in a web address. */
76
+ export declare const Flag: Schema.Union<readonly [Schema.Boolean, Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ["true", "false"]>, never, never>]>;
77
+ /** Fields every list call takes. */
78
+ export declare const pageQuery: {
79
+ limit: Schema.optionalKey<Schema.Union<readonly [Schema.Int, Schema.decodeTo<Schema.Int, Schema.String, never, never>]>>;
80
+ cursor: Schema.optionalKey<Schema.brand<Schema.String, "Cursor">>;
81
+ };
82
+ /** Fields to pick a time range. `from` counts, `to` doesn't. */
83
+ export declare const rangeQuery: {
84
+ from: Schema.optionalKey<Schema.brand<Schema.String, "Timestamp">>;
85
+ to: Schema.optionalKey<Schema.brand<Schema.String, "Timestamp">>;
86
+ };
87
+ /** One page of a list. */
88
+ export declare const listPage: <S extends Schema.Top>(item: S, identifier: string) => Schema.Struct<{
89
+ readonly data: Schema.$Array<S>;
90
+ readonly next_cursor: Schema.NullOr<Schema.brand<Schema.String, "Cursor">>;
91
+ }>;
92
+ export declare const owner: {
93
+ merchant_id: Schema.brand<Schema.String, "MerchantId">;
94
+ mode: Schema.Literals<readonly ["live", "practice"]>;
95
+ };
96
+ /**
97
+ * Takes `{}` and nothing else. `Schema.Struct({})` alone lets any value but null through, even a
98
+ * string, and the request rules can't see its extra fields. This closes it.
99
+ */
100
+ export declare const closedEmpty: () => Schema.Struct<{}>;
101
+ /** The empty query or params. */
102
+ export declare const None: Schema.Struct<{}>;
103
+ /** The call takes no body. */
104
+ export declare const NoBody: Schema.Undefined;
105
+ /** Fills in a field when a value is made in code. Never when it's read. */
106
+ export declare const filled: <const A>(value: A) => Effect.Effect<A, never, never>;
@@ -0,0 +1,189 @@
1
+ import { Effect, Schema, SchemaGetter } from "effect";
2
+ import { Cursor, MerchantId } from "./ids.js";
3
+ import { d, openEnum, opt } from "./open.js";
4
+ /** UTC time as text, to the second: `2026-12-04T03:00:00Z`. */
5
+ export const Timestamp = Schema.String.check(Schema.isPattern(/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$/u, {
6
+ expected: 'a UTC time like "2026-12-04T03:00:00Z"',
7
+ }), Schema.makeFilter((value) => {
8
+ const time = Date.parse(value);
9
+ return Number.isFinite(time) && `${new Date(time).toISOString().slice(0, 19)}Z` === value;
10
+ }, { expected: "a date that exists", toJsonSchema: () => [{ format: "date-time" }, true] }))
11
+ .pipe(Schema.brand("Timestamp"))
12
+ .annotate({ identifier: "Timestamp", description: 'UTC time: "2026-12-04T03:00:00Z".' });
13
+ /** Drops the part below a second. */
14
+ export const toTimestamp = (date) => Timestamp.make(`${date.toISOString().slice(0, 19)}Z`);
15
+ /** Live uses real networks and real money. Practice uses neither. Their data never mixes. */
16
+ export const modes = ["live", "practice"];
17
+ export const Mode = Schema.Literals(modes).annotate({
18
+ identifier: "Mode",
19
+ description: "live is real money. practice is pretend.",
20
+ });
21
+ export const networkIds = [
22
+ "base",
23
+ "polygon",
24
+ "arbitrum",
25
+ "bnb",
26
+ "ethereum",
27
+ "bitcoin",
28
+ "litecoin",
29
+ "solana",
30
+ "tron",
31
+ ];
32
+ export const NetworkId = openEnum(networkIds).annotate({
33
+ identifier: "NetworkId",
34
+ description: "The network the coin moves on. More may be added.",
35
+ });
36
+ export const addressFamilies = ["evm", "bitcoin", "litecoin", "solana", "tron"];
37
+ /** Closed: adding one needs a new vault, so it never appears by surprise. */
38
+ export const AddressFamily = Schema.Literals(addressFamilies).annotate({
39
+ identifier: "AddressFamily",
40
+ description: "A kind of address. One evm address works on every Ethereum-style network.",
41
+ });
42
+ export const networkFamily = {
43
+ base: "evm",
44
+ polygon: "evm",
45
+ arbitrum: "evm",
46
+ bnb: "evm",
47
+ ethereum: "evm",
48
+ bitcoin: "bitcoin",
49
+ litecoin: "litecoin",
50
+ solana: "solana",
51
+ tron: "tron",
52
+ };
53
+ export const coinIds = ["usdc", "usdt", "btc", "eth", "ltc", "sol"];
54
+ export const CoinId = openEnum(coinIds).annotate({
55
+ identifier: "CoinId",
56
+ description: "The coin. On its own it isn't enough: always use it with the network.",
57
+ });
58
+ /** Every coin-on-a-network we know. Which ones a merchant offers is a setting. */
59
+ export const methodIds = [
60
+ "usdc_base",
61
+ "usdc_polygon",
62
+ "usdc_arbitrum",
63
+ "usdt_polygon",
64
+ "usdt_arbitrum",
65
+ "usdt_bnb",
66
+ "btc_bitcoin",
67
+ "eth_ethereum",
68
+ "usdc_ethereum",
69
+ "usdt_ethereum",
70
+ "ltc_litecoin",
71
+ "sol_solana",
72
+ "usdt_tron",
73
+ ];
74
+ /** In answers. */
75
+ export const MethodId = openEnum(methodIds).annotate({
76
+ identifier: "MethodId",
77
+ description: "One coin on one network: coin, underscore, network. More may be added.",
78
+ });
79
+ /** In requests. Closed, so a typo is refused. */
80
+ export const MethodIdInput = Schema.Literals(methodIds).annotate({
81
+ identifier: "MethodIdInput",
82
+ description: "One coin on one network.",
83
+ });
84
+ /** Where coins and transactions are identified exactly. */
85
+ export const TxId = Schema.String.check(Schema.isPattern(/^[0-9A-Za-z]{32,100}$/u, { expected: "a transaction number" }))
86
+ .pipe(Schema.brand("TxId"))
87
+ .annotate({ identifier: "TxId", description: "A transaction's number on its network." });
88
+ export const ChainAddress = Schema.String.check(Schema.isPattern(/^[0-9A-Za-z]{20,100}$/u, { expected: "a wallet address" }))
89
+ .pipe(Schema.brand("ChainAddress"))
90
+ .annotate({ identifier: "ChainAddress", description: "A wallet address on a network." });
91
+ const noSignIn = Schema.makeFilter((value) => {
92
+ if (!URL.canParse(value))
93
+ return false;
94
+ const url = new URL(value);
95
+ return url.username === "" && url.password === "";
96
+ }, { expected: "a working web address with no sign-in details", toJsonSchema: () => [{}, true] });
97
+ /**
98
+ * A secure web address. Used for everything we send people to or send data to: webhooks, logos,
99
+ * return and panel sites, and our own pages. Plain http could be read or changed on the way.
100
+ */
101
+ export const HttpsUrl = Schema.String.check(Schema.isMaxLength(2048), Schema.isPattern(/^https:\/\/[^\s]+$/u, { expected: "a web address starting with https://" }), noSignIn).annotate({
102
+ identifier: "HttpsUrl",
103
+ description: "A web address starting with https://, with no sign-in details in it.",
104
+ });
105
+ /**
106
+ * Any web address, http allowed. Only for a waitlist answer's own website: we never send anyone
107
+ * or anything there, and some small businesses still have http-only sites.
108
+ */
109
+ export const UrlText = Schema.String.check(Schema.isMaxLength(2048), Schema.isPattern(/^https?:\/\/[^\s]+$/u, { expected: "a web address starting with http" }), noSignIn).annotate({ identifier: "UrlText", description: "A web address, with no sign-in details in it." });
110
+ /** A website's front door: https, host, no path. Return and panel sites must be secure. */
111
+ export const Origin = Schema.String.check(Schema.isPattern(/^https:\/\/[a-z0-9.-]+(:[0-9]{1,5})?$/u, {
112
+ expected: 'a website like "https://shop.example"',
113
+ })).annotate({
114
+ identifier: "Origin",
115
+ description: 'A website, with no path: "https://shop.example".',
116
+ });
117
+ export const Email = Schema.String.check(Schema.isMaxLength(254), Schema.isPattern(/^[^\s@]+@[^\s@]+\.[^\s@]+$/u, { expected: "an email address" }));
118
+ export const Country = Schema.String.check(Schema.isPattern(/^[A-Z]{2}$/u, { expected: 'a 2-letter country code, like "GB"' }));
119
+ export const Colour = Schema.String.check(Schema.isPattern(/^#[0-9a-f]{6}$/u, { expected: 'a colour like "#1a2b3c"' }));
120
+ /** Your own order number. Letters, numbers and . _ : / # - only, so no email fits in it. */
121
+ export const OrderId = Schema.String.check(Schema.isPattern(/^[A-Za-z0-9._:/#-]{1,128}$/u, {
122
+ expected: "1 to 128 letters, numbers or . _ : / # -",
123
+ })).pipe(Schema.brand("OrderId"));
124
+ /** Your own code for a customer. Not a name or email. */
125
+ export const CustomerRef = Schema.String.check(Schema.isPattern(/^[A-Za-z0-9._:-]{1,128}$/u, {
126
+ expected: "1 to 128 letters, numbers or . _ : - (no names or emails)",
127
+ })).pipe(Schema.brand("CustomerRef"));
128
+ /** Up to 20 of your own notes. */
129
+ export const Metadata = Schema.Record(Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_.-]{1,40}$/u, { expected: "a short key" })), Schema.String.check(Schema.isMaxLength(500)))
130
+ .check(Schema.isMaxProperties(20))
131
+ .annotate({
132
+ identifier: "Metadata",
133
+ description: "Your own notes: up to 20 pairs of text. No personal details.",
134
+ });
135
+ /** Seconds to pay: 15 minutes to 30 days. */
136
+ export const ExpiresIn = Schema.Int.check(Schema.isBetween({ minimum: 900, maximum: 2_592_000 }));
137
+ export const Reason = Schema.Trimmed.check(Schema.isBetweenLength(3, 500));
138
+ /** Webhook and event cursor lists, invoice lists and so on: 1 to 100 rows a page. */
139
+ const LimitText = Schema.String.check(Schema.isPattern(/^([1-9][0-9]?|100)$/u, { expected: "a whole number from 1 to 100" })).pipe(Schema.decodeTo(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })), {
140
+ decode: SchemaGetter.transform((value) => Number(value)),
141
+ encode: SchemaGetter.transform((value) => String(value)),
142
+ }));
143
+ /** In code it's a number. On the wire it's text, because it's in the web address. */
144
+ export const Limit = Schema.Union([
145
+ Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })),
146
+ LimitText,
147
+ ]);
148
+ const FlagText = Schema.Literals(["true", "false"]).pipe(Schema.decodeTo(Schema.Boolean, {
149
+ decode: SchemaGetter.transform((value) => value === "true"),
150
+ encode: SchemaGetter.transform((value) => (value ? "true" : "false")),
151
+ }));
152
+ /** A yes or no in a web address. */
153
+ export const Flag = Schema.Union([Schema.Boolean, FlagText]);
154
+ /** Fields every list call takes. */
155
+ export const pageQuery = {
156
+ limit: opt(Limit, "How many to return, 1 to 100. 25 if left out."),
157
+ cursor: opt(Cursor, "next_cursor from the page before. Leave out for the first page."),
158
+ };
159
+ /** Fields to pick a time range. `from` counts, `to` doesn't. */
160
+ export const rangeQuery = {
161
+ from: opt(Timestamp, "Only things made at or after this time."),
162
+ to: opt(Timestamp, "Only things made before this time."),
163
+ };
164
+ /** One page of a list. */
165
+ export const listPage = (item, identifier) => Schema.Struct({
166
+ data: d(Schema.Array(item), "The rows on this page, newest first unless the call says not."),
167
+ next_cursor: d(Schema.NullOr(Cursor), "Send this as cursor to get the next page. null means this is the last page."),
168
+ }).annotate({ identifier, description: "One page of a list." });
169
+ export const owner = {
170
+ merchant_id: d(MerchantId, "The product this belongs to."),
171
+ mode: d(Mode, "live or practice."),
172
+ };
173
+ /**
174
+ * Takes `{}` and nothing else. `Schema.Struct({})` alone lets any value but null through, even a
175
+ * string, and the request rules can't see its extra fields. This closes it.
176
+ */
177
+ export const closedEmpty = () => Schema.Struct({}).check(Schema.makeFilter((value) => typeof value === "object" &&
178
+ value !== null &&
179
+ !Array.isArray(value) &&
180
+ Object.keys(value).length === 0, {
181
+ expected: "{} with no fields in it",
182
+ toJsonSchema: () => [{ type: "object", maxProperties: 0 }, true],
183
+ }));
184
+ /** The empty query or params. */
185
+ export const None = closedEmpty();
186
+ /** The call takes no body. */
187
+ export const NoBody = Schema.Undefined;
188
+ /** Fills in a field when a value is made in code. Never when it's read. */
189
+ export const filled = (value) => Effect.succeed(value);