run402 4.18.2 → 4.20.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.
@@ -0,0 +1,55 @@
1
+ /**
2
+ * `vouchers` namespace — redeem a promo code for platform credit.
3
+ *
4
+ * A promo code credits your organization with run402 prepaid credit. That
5
+ * credit spends like any other prepaid balance: a tier purchase settles from
6
+ * it with no on-chain payment.
7
+ *
8
+ * Two properties make this safe to call from anywhere in an agent's lifecycle:
9
+ *
10
+ * - **Order does not matter.** Redemption works as the very first authenticated
11
+ * call a brand-new wallet makes (the organization is provisioned on demand),
12
+ * or long after `run402 init`. There is no init-before-redeem requirement.
13
+ * - **Retrying is safe.** A repeat by the same organization returns the ORIGINAL
14
+ * result with `already_redeemed: true` and never credits twice, so a call that
15
+ * times out client-side can simply be re-issued.
16
+ *
17
+ * This namespace is deliberately thin and semantically blind: it forwards an
18
+ * opaque code string to one gateway route. It does not know what a code means,
19
+ * where it came from, or who issued it. Minting is not an agent operation —
20
+ * it needs a registered issuer key that no tenant holds.
21
+ */
22
+ import { assertNonEmptyString } from "../validation.js";
23
+ export class Vouchers {
24
+ client;
25
+ /** Alias of {@link redeem}. */
26
+ redeemCode;
27
+ constructor(client) {
28
+ this.client = client;
29
+ this.redeemCode = this.redeem.bind(this);
30
+ }
31
+ /**
32
+ * Redeem a promo code into the authenticated wallet's organization.
33
+ *
34
+ * The code is sent verbatim — the gateway owns the grammar and is forgiving
35
+ * about it (case-insensitive, hyphens optional, and the Crockford
36
+ * confusables `O`→`0` / `I`,`L`→`1` are mapped), so a client-side format
37
+ * check would only invent ways to reject a code the server would have
38
+ * accepted.
39
+ *
40
+ * Requires wallet (SIWX) auth. Errors carry the canonical envelope:
41
+ * `VOUCHER_NOT_FOUND` (404 — unknown *or* malformed, deliberately
42
+ * indistinguishable), `VOUCHER_EXPIRED` (410), `VOUCHER_ALREADY_REDEEMED`
43
+ * (409 — a different organization got there first), `PROMO_LIMIT_REACHED`
44
+ * (403), `RATE_LIMITED` (429).
45
+ */
46
+ async redeem(code) {
47
+ assertNonEmptyString(code, "code", "redeeming a promo code");
48
+ return this.client.request("/vouchers/v1/redemptions", {
49
+ method: "POST",
50
+ body: { code },
51
+ context: "redeeming a promo code",
52
+ });
53
+ }
54
+ }
55
+ //# sourceMappingURL=vouchers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vouchers.js","sourceRoot":"","sources":["../../src/namespaces/vouchers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAmCxD,MAAM,OAAO,QAAQ;IAIU;IAH7B,+BAA+B;IACtB,UAAU,CAAiD;IAEpE,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QACzC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,wBAAwB,CAAC,CAAC;QAC7D,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAsB,0BAA0B,EAAE;YAC1E,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,EAAE,IAAI,EAAE;YACd,OAAO,EAAE,wBAAwB;SAClC,CAAC,CAAC;IACL,CAAC;CACF"}