@vllnt/convex-wallet 0.1.0-canary.6d92230
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/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/client/index.d.ts +109 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +105 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +45 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +3 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +42 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +105 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +7 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/crons.d.ts +12 -0
- package/dist/component/crons.d.ts.map +1 -0
- package/dist/component/crons.js +19 -0
- package/dist/component/crons.js.map +1 -0
- package/dist/component/internal_mutations.d.ts +20 -0
- package/dist/component/internal_mutations.d.ts.map +1 -0
- package/dist/component/internal_mutations.js +52 -0
- package/dist/component/internal_mutations.js.map +1 -0
- package/dist/component/mutations.d.ts +79 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +243 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/queries.d.ts +43 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +70 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +45 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +33 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/validators.d.ts +73 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +45 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/react/index.d.ts +37 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +30 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared.d.ts +84 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +91 -0
- package/dist/shared.js.map +1 -0
- package/package.json +112 -0
- package/src/client/index.ts +257 -0
- package/src/client/types.ts +51 -0
- package/src/component/_generated/api.ts +58 -0
- package/src/component/_generated/component.ts +118 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/convex.config.ts +9 -0
- package/src/component/crons.ts +29 -0
- package/src/component/internal_mutations.ts +58 -0
- package/src/component/mutations.ts +279 -0
- package/src/component/queries.ts +76 -0
- package/src/component/schema.ts +33 -0
- package/src/component/validators.ts +58 -0
- package/src/react/index.test.tsx +61 -0
- package/src/react/index.tsx +50 -0
- package/src/shared.ts +123 -0
- package/src/test.ts +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bntvllnt
|
|
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
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<!-- Badges -->
|
|
2
|
+
[](https://www.convex.dev/components)
|
|
3
|
+
[](https://www.npmjs.com/package/@vllnt/convex-wallet)
|
|
4
|
+
[](https://github.com/vllnt/convex-wallet/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
# @vllnt/convex-wallet
|
|
8
|
+
|
|
9
|
+
Consumable balances and economy ledger with atomic spend and lazy regen, as a Convex component — hold per-subject balances of any opaque currency (coins, energy, gems, credits).
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const wallet = new Wallet(components.wallet, {
|
|
13
|
+
currencies: { energy: { regen: { amount: 1, intervalMs: 10_000, cap: 100 } } },
|
|
14
|
+
});
|
|
15
|
+
await wallet.spend(ctx, subjectRef, "coins", 5, "purchase"); // atomic, never negative
|
|
16
|
+
const energy = await wallet.balance(ctx, subjectRef, "energy"); // regen-aware
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- **Atomic spend** — debits ride the Convex mutation transaction; never goes negative, never double-spends.
|
|
22
|
+
- **Abuse-guarded amounts** — every value-moving call rejects non-finite or non-positive amounts (`INVALID_AMOUNT`).
|
|
23
|
+
- **Typed ledger** — every earn / spend / transfer records a signed `delta` (the actual change), `reason`, and timestamp.
|
|
24
|
+
- **Idempotent grants & spend** — credit/debit exactly once per `idempotencyKey`, scoped per `(subjectRef, currency)`.
|
|
25
|
+
- **Lazy time-regen** — energy-style currencies regenerate on read from the server clock, no cron.
|
|
26
|
+
- **Per-currency `max` ceiling, multi-currency, transfers** — with a `SELF_TRANSFER` guard.
|
|
27
|
+
- **Typed error codes, self-pruning ledger cron, opaque host refs.**
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pnpm add @vllnt/convex-wallet
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Peer dependency: `convex@^1.41.0`.
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// convex/convex.config.ts
|
|
41
|
+
import { defineApp } from "convex/server";
|
|
42
|
+
import wallet from "@vllnt/convex-wallet/convex.config";
|
|
43
|
+
|
|
44
|
+
const app = defineApp();
|
|
45
|
+
app.use(wallet);
|
|
46
|
+
export default app;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
// convex/economy.ts — host owns auth + payment confirmation.
|
|
51
|
+
import { components } from "./_generated/api";
|
|
52
|
+
import { mutation, query } from "./_generated/server";
|
|
53
|
+
import { v } from "convex/values";
|
|
54
|
+
import { Wallet } from "@vllnt/convex-wallet";
|
|
55
|
+
|
|
56
|
+
// `energy` regenerates 1 unit / 10s up to 100; `gems` caps at 9999; `coins` is static.
|
|
57
|
+
const wallet = new Wallet(components.wallet, {
|
|
58
|
+
currencies: {
|
|
59
|
+
energy: { regen: { amount: 1, intervalMs: 10_000, cap: 100 } },
|
|
60
|
+
gems: { max: 9999 },
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const buy = mutation({
|
|
65
|
+
args: { userId: v.string(), cost: v.number() },
|
|
66
|
+
handler: (ctx, { userId, cost }) => wallet.spend(ctx, userId, "coins", cost, "purchase"),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Call AFTER the host has verified the IAP — idempotent on the receipt id.
|
|
70
|
+
export const creditPurchase = mutation({
|
|
71
|
+
args: { userId: v.string(), coins: v.number(), receiptId: v.string() },
|
|
72
|
+
handler: (ctx, { userId, coins, receiptId }) =>
|
|
73
|
+
wallet.grant(ctx, userId, "coins", coins, "iap", receiptId),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const energy = query({
|
|
77
|
+
args: { userId: v.string() },
|
|
78
|
+
handler: (ctx, { userId }) => wallet.balance(ctx, userId, "energy"),
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## API Reference
|
|
83
|
+
|
|
84
|
+
| Method | Kind | Result |
|
|
85
|
+
|--------|------|--------|
|
|
86
|
+
| `earn(ctx, subjectRef, currency, amount, reason, opts?)` | mutation | `{ balance }` (clamped to `max`) |
|
|
87
|
+
| `grant(ctx, subjectRef, currency, amount, reason, idempotencyKey)` | mutation | `{ balance }` (credited once per key) |
|
|
88
|
+
| `spend(ctx, subjectRef, currency, amount, reason, opts?)` | mutation | `{ ok, balance, code? }` |
|
|
89
|
+
| `transfer(ctx, fromRef, toRef, currency, amount, reason)` | mutation | `{ ok, balance, code? }` |
|
|
90
|
+
| `balance(ctx, subjectRef, currency)` | query | `number` (regen-aware) |
|
|
91
|
+
| `balances(ctx, subjectRef)` | query | `{ currency, amount }[]` |
|
|
92
|
+
| `history(ctx, subjectRef, currency, limit?)` | query | `LedgerEntry[]` (newest-first) |
|
|
93
|
+
|
|
94
|
+
Full reference: [docs/API.md](docs/API.md) — including per-currency config, error codes (`INVALID_AMOUNT`, `INVALID_REGEN`, `INSUFFICIENT`, `SELF_TRANSFER`), and the regen model.
|
|
95
|
+
|
|
96
|
+
## React
|
|
97
|
+
|
|
98
|
+
Optional, tree-shakeable hooks at `@vllnt/convex-wallet/react`; `react` is an optional peer dep. Pass the host's own re-exported query refs — the component never imports your `api`.
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
import { useBalance, useBalances } from "@vllnt/convex-wallet/react";
|
|
102
|
+
import { api } from "../convex/_generated/api";
|
|
103
|
+
|
|
104
|
+
const energy = useBalance(api.economy.energy, { subjectRef: userId, currency: "energy" });
|
|
105
|
+
const all = useBalances(api.economy.allBalances, { subjectRef: userId });
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
| Hook | Args | Result |
|
|
109
|
+
|------|------|--------|
|
|
110
|
+
| `useBalance(balanceRef, { subjectRef, currency })` | host's `balance` query ref | `number \| undefined` |
|
|
111
|
+
| `useBalances(balancesRef, { subjectRef })` | host's `balances` query ref | `BalanceEntry[] \| undefined` |
|
|
112
|
+
|
|
113
|
+
## Security
|
|
114
|
+
|
|
115
|
+
- Auth- and payment-agnostic — the host gates access and verifies any IAP / Stripe purchase before calling `grant`.
|
|
116
|
+
- Tables are sandboxed; spend and transfer are atomic, so balances never go negative and grants never double-credit.
|
|
117
|
+
- Amounts and regen configs are validated, and time is server-sourced — a forged or replayed clock can't drive extra regen.
|
|
118
|
+
|
|
119
|
+
See [docs/API.md](docs/API.md).
|
|
120
|
+
|
|
121
|
+
## Testing
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pnpm test # single run
|
|
125
|
+
pnpm test:coverage # enforced 100% on covered files
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Tests run against the real component runtime via `convex-test` (`@edge-runtime/vm`), not mocks.
|
|
129
|
+
|
|
130
|
+
## Contributing
|
|
131
|
+
|
|
132
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
133
|
+
|
|
134
|
+
## Author
|
|
135
|
+
|
|
136
|
+
Built by [bntvllnt](https://github.com/bntvllnt) · [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
137
|
+
|
|
138
|
+
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
|
|
139
|
+
|
|
140
|
+
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { FunctionArgs, FunctionReference, FunctionReturnType } from "convex/server";
|
|
2
|
+
import type { BalanceEntry, ErrorCode, LedgerEntry, RegenConfig, SpendResult, WalletOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The wallet component's function references, as exposed on the host via
|
|
5
|
+
* `components.wallet`.
|
|
6
|
+
*/
|
|
7
|
+
export interface WalletComponent {
|
|
8
|
+
mutations: {
|
|
9
|
+
earn: FunctionReference<"mutation", "internal", {
|
|
10
|
+
subjectRef: string;
|
|
11
|
+
currency: string;
|
|
12
|
+
amount: number;
|
|
13
|
+
reason: string;
|
|
14
|
+
idempotencyKey?: string;
|
|
15
|
+
regen?: RegenConfig;
|
|
16
|
+
max?: number;
|
|
17
|
+
}, {
|
|
18
|
+
balance: number;
|
|
19
|
+
}>;
|
|
20
|
+
spend: FunctionReference<"mutation", "internal", {
|
|
21
|
+
subjectRef: string;
|
|
22
|
+
currency: string;
|
|
23
|
+
amount: number;
|
|
24
|
+
reason: string;
|
|
25
|
+
idempotencyKey?: string;
|
|
26
|
+
regen?: RegenConfig;
|
|
27
|
+
}, SpendResult>;
|
|
28
|
+
transfer: FunctionReference<"mutation", "internal", {
|
|
29
|
+
fromRef: string;
|
|
30
|
+
toRef: string;
|
|
31
|
+
currency: string;
|
|
32
|
+
amount: number;
|
|
33
|
+
reason: string;
|
|
34
|
+
regen?: RegenConfig;
|
|
35
|
+
max?: number;
|
|
36
|
+
}, SpendResult>;
|
|
37
|
+
};
|
|
38
|
+
queries: {
|
|
39
|
+
balance: FunctionReference<"query", "internal", {
|
|
40
|
+
subjectRef: string;
|
|
41
|
+
currency: string;
|
|
42
|
+
regen?: RegenConfig;
|
|
43
|
+
}, number>;
|
|
44
|
+
balances: FunctionReference<"query", "internal", {
|
|
45
|
+
subjectRef: string;
|
|
46
|
+
regen?: Record<string, RegenConfig>;
|
|
47
|
+
}, BalanceEntry[]>;
|
|
48
|
+
history: FunctionReference<"query", "internal", {
|
|
49
|
+
subjectRef: string;
|
|
50
|
+
currency: string;
|
|
51
|
+
limit: number;
|
|
52
|
+
}, LedgerEntry[]>;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
interface RunQueryCtx {
|
|
56
|
+
runQuery<Q extends FunctionReference<"query", "internal">>(reference: Q, args: FunctionArgs<Q>): Promise<FunctionReturnType<Q>>;
|
|
57
|
+
}
|
|
58
|
+
interface RunMutationCtx {
|
|
59
|
+
runMutation<M extends FunctionReference<"mutation", "internal">>(reference: M, args: FunctionArgs<M>): Promise<FunctionReturnType<M>>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Consumer-facing client for the consumable-balances wallet. The host owns auth,
|
|
63
|
+
* payment confirmation, and meaning: it resolves identity, verifies any IAP /
|
|
64
|
+
* Stripe purchase, then passes an opaque `subjectRef` and a `currency` string
|
|
65
|
+
* in. The client injects each currency's `regen` rule and `max` ceiling per
|
|
66
|
+
* call; the component reads the server clock (`Date.now()`) itself.
|
|
67
|
+
*/
|
|
68
|
+
export declare class Wallet {
|
|
69
|
+
private readonly component;
|
|
70
|
+
private readonly currencies;
|
|
71
|
+
private readonly defaultHistoryLimit;
|
|
72
|
+
constructor(component: WalletComponent, options?: WalletOptions);
|
|
73
|
+
private regenFor;
|
|
74
|
+
private maxFor;
|
|
75
|
+
/** The per-currency regen map for the multi-currency {@link balances} read. */
|
|
76
|
+
private regenMap;
|
|
77
|
+
/** Credit `amount` of `currency` to `subjectRef`. Returns the new balance. */
|
|
78
|
+
earn(ctx: RunMutationCtx, subjectRef: string, currency: string, amount: number, reason: string, opts?: {
|
|
79
|
+
idempotencyKey?: string;
|
|
80
|
+
}): Promise<{
|
|
81
|
+
balance: number;
|
|
82
|
+
}>;
|
|
83
|
+
/**
|
|
84
|
+
* Idempotent grant — credit only once per `idempotencyKey`. Use after the
|
|
85
|
+
* host has verified an IAP / Stripe purchase. Returns the new balance.
|
|
86
|
+
*/
|
|
87
|
+
grant(ctx: RunMutationCtx, subjectRef: string, currency: string, amount: number, reason: string, idempotencyKey: string): Promise<{
|
|
88
|
+
balance: number;
|
|
89
|
+
}>;
|
|
90
|
+
/**
|
|
91
|
+
* Debit `amount` of `currency` from `subjectRef`. Never goes negative.
|
|
92
|
+
* When `opts.idempotencyKey` is supplied and already recorded for this
|
|
93
|
+
* `(subjectRef, currency)`, this is a no-op replay — the current
|
|
94
|
+
* (regen-aware) balance is returned without a second debit or ledger row.
|
|
95
|
+
*/
|
|
96
|
+
spend(ctx: RunMutationCtx, subjectRef: string, currency: string, amount: number, reason: string, opts?: {
|
|
97
|
+
idempotencyKey?: string;
|
|
98
|
+
}): Promise<SpendResult>;
|
|
99
|
+
/** Move `amount` of `currency` from `fromRef` to `toRef` in one transaction. */
|
|
100
|
+
transfer(ctx: RunMutationCtx, fromRef: string, toRef: string, currency: string, amount: number, reason: string): Promise<SpendResult>;
|
|
101
|
+
/** Regen-aware single-currency balance for `subjectRef`. Missing → 0. */
|
|
102
|
+
balance(ctx: RunQueryCtx, subjectRef: string, currency: string): Promise<number>;
|
|
103
|
+
/** All currency balances held by `subjectRef`, regen-aware (matches {@link balance}). */
|
|
104
|
+
balances(ctx: RunQueryCtx, subjectRef: string): Promise<BalanceEntry[]>;
|
|
105
|
+
/** Newest-first ledger history for one currency. */
|
|
106
|
+
history(ctx: RunQueryCtx, subjectRef: string, currency: string, limit?: number): Promise<LedgerEntry[]>;
|
|
107
|
+
}
|
|
108
|
+
export type { BalanceEntry, ErrorCode, LedgerEntry, RegenConfig, SpendResult, WalletOptions, };
|
|
109
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,YAAY,EAEZ,SAAS,EACT,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAGpB;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE;QACT,IAAI,EAAE,iBAAiB,CACrB,UAAU,EACV,UAAU,EACV;YACE,UAAU,EAAE,MAAM,CAAC;YACnB,QAAQ,EAAE,MAAM,CAAC;YACjB,MAAM,EAAE,MAAM,CAAC;YACf,MAAM,EAAE,MAAM,CAAC;YACf,cAAc,CAAC,EAAE,MAAM,CAAC;YACxB,KAAK,CAAC,EAAE,WAAW,CAAC;YACpB,GAAG,CAAC,EAAE,MAAM,CAAC;SACd,EACD;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CACpB,CAAC;QACF,KAAK,EAAE,iBAAiB,CACtB,UAAU,EACV,UAAU,EACV;YACE,UAAU,EAAE,MAAM,CAAC;YACnB,QAAQ,EAAE,MAAM,CAAC;YACjB,MAAM,EAAE,MAAM,CAAC;YACf,MAAM,EAAE,MAAM,CAAC;YACf,cAAc,CAAC,EAAE,MAAM,CAAC;YACxB,KAAK,CAAC,EAAE,WAAW,CAAC;SACrB,EACD,WAAW,CACZ,CAAC;QACF,QAAQ,EAAE,iBAAiB,CACzB,UAAU,EACV,UAAU,EACV;YACE,OAAO,EAAE,MAAM,CAAC;YAChB,KAAK,EAAE,MAAM,CAAC;YACd,QAAQ,EAAE,MAAM,CAAC;YACjB,MAAM,EAAE,MAAM,CAAC;YACf,MAAM,EAAE,MAAM,CAAC;YACf,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AAO,CAAC,MAAM,CAAC;IAQhF,yFAAyF;IACzF,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAOvE,oDAAoD;IACpD,OAAO,CACL,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,EAAE,CAAC;CAO1B;AAED,YAAY,EACV,YAAY,EACZ,SAAS,EACT,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,GACd,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DEFAULT_HISTORY_LIMIT } from "../shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* Consumer-facing client for the consumable-balances wallet. The host owns auth,
|
|
4
|
+
* payment confirmation, and meaning: it resolves identity, verifies any IAP /
|
|
5
|
+
* Stripe purchase, then passes an opaque `subjectRef` and a `currency` string
|
|
6
|
+
* in. The client injects each currency's `regen` rule and `max` ceiling per
|
|
7
|
+
* call; the component reads the server clock (`Date.now()`) itself.
|
|
8
|
+
*/
|
|
9
|
+
export class Wallet {
|
|
10
|
+
component;
|
|
11
|
+
currencies;
|
|
12
|
+
defaultHistoryLimit;
|
|
13
|
+
constructor(component, options = {}) {
|
|
14
|
+
this.component = component;
|
|
15
|
+
this.currencies = options.currencies ?? {};
|
|
16
|
+
this.defaultHistoryLimit = options.defaultHistoryLimit ?? DEFAULT_HISTORY_LIMIT;
|
|
17
|
+
}
|
|
18
|
+
regenFor(currency) {
|
|
19
|
+
return this.currencies[currency]?.regen;
|
|
20
|
+
}
|
|
21
|
+
maxFor(currency) {
|
|
22
|
+
return this.currencies[currency]?.max;
|
|
23
|
+
}
|
|
24
|
+
/** The per-currency regen map for the multi-currency {@link balances} read. */
|
|
25
|
+
regenMap() {
|
|
26
|
+
const out = {};
|
|
27
|
+
for (const [currency, config] of Object.entries(this.currencies)) {
|
|
28
|
+
if (config.regen !== undefined) {
|
|
29
|
+
out[currency] = config.regen;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return Object.keys(out).length === 0 ? undefined : out;
|
|
33
|
+
}
|
|
34
|
+
/** Credit `amount` of `currency` to `subjectRef`. Returns the new balance. */
|
|
35
|
+
earn(ctx, subjectRef, currency, amount, reason, opts = {}) {
|
|
36
|
+
return ctx.runMutation(this.component.mutations.earn, {
|
|
37
|
+
subjectRef,
|
|
38
|
+
currency,
|
|
39
|
+
amount,
|
|
40
|
+
reason,
|
|
41
|
+
idempotencyKey: opts.idempotencyKey,
|
|
42
|
+
regen: this.regenFor(currency),
|
|
43
|
+
max: this.maxFor(currency),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Idempotent grant — credit only once per `idempotencyKey`. Use after the
|
|
48
|
+
* host has verified an IAP / Stripe purchase. Returns the new balance.
|
|
49
|
+
*/
|
|
50
|
+
grant(ctx, subjectRef, currency, amount, reason, idempotencyKey) {
|
|
51
|
+
return this.earn(ctx, subjectRef, currency, amount, reason, { idempotencyKey });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Debit `amount` of `currency` from `subjectRef`. Never goes negative.
|
|
55
|
+
* When `opts.idempotencyKey` is supplied and already recorded for this
|
|
56
|
+
* `(subjectRef, currency)`, this is a no-op replay — the current
|
|
57
|
+
* (regen-aware) balance is returned without a second debit or ledger row.
|
|
58
|
+
*/
|
|
59
|
+
spend(ctx, subjectRef, currency, amount, reason, opts = {}) {
|
|
60
|
+
return ctx.runMutation(this.component.mutations.spend, {
|
|
61
|
+
subjectRef,
|
|
62
|
+
currency,
|
|
63
|
+
amount,
|
|
64
|
+
reason,
|
|
65
|
+
idempotencyKey: opts.idempotencyKey,
|
|
66
|
+
regen: this.regenFor(currency),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Move `amount` of `currency` from `fromRef` to `toRef` in one transaction. */
|
|
70
|
+
transfer(ctx, fromRef, toRef, currency, amount, reason) {
|
|
71
|
+
return ctx.runMutation(this.component.mutations.transfer, {
|
|
72
|
+
fromRef,
|
|
73
|
+
toRef,
|
|
74
|
+
currency,
|
|
75
|
+
amount,
|
|
76
|
+
reason,
|
|
77
|
+
regen: this.regenFor(currency),
|
|
78
|
+
max: this.maxFor(currency),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/** Regen-aware single-currency balance for `subjectRef`. Missing → 0. */
|
|
82
|
+
balance(ctx, subjectRef, currency) {
|
|
83
|
+
return ctx.runQuery(this.component.queries.balance, {
|
|
84
|
+
subjectRef,
|
|
85
|
+
currency,
|
|
86
|
+
regen: this.regenFor(currency),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** All currency balances held by `subjectRef`, regen-aware (matches {@link balance}). */
|
|
90
|
+
balances(ctx, subjectRef) {
|
|
91
|
+
return ctx.runQuery(this.component.queries.balances, {
|
|
92
|
+
subjectRef,
|
|
93
|
+
regen: this.regenMap(),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** Newest-first ledger history for one currency. */
|
|
97
|
+
history(ctx, subjectRef, currency, limit) {
|
|
98
|
+
return ctx.runQuery(this.component.queries.history, {
|
|
99
|
+
subjectRef,
|
|
100
|
+
currency,
|
|
101
|
+
limit: limit ?? this.defaultHistoryLimit,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAsFrD;;;;;;GAMG;AACH,MAAM,OAAO,MAAM;IAKE;IAJF,UAAU,CAAiC;IAC3C,mBAAmB,CAAS;IAE7C,YACmB,SAA0B,EAC3C,UAAyB,EAAE;QADV,cAAS,GAA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;SAC/B,CAAC,CAAC;IACL,CAAC;IAED,yFAAyF;IACzF,QAAQ,CAAC,GAAgB,EAAE,UAAkB;QAC3C,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE;YACnD,UAAU;YACV,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE;SACvB,CAAC,CAAC;IACL,CAAC;IAED,oDAAoD;IACpD,OAAO,CACL,GAAgB,EAChB,UAAkB,EAClB,QAAgB,EAChB,KAAc;QAEd,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE;YAClD,UAAU;YACV,QAAQ;YACR,KAAK,EAAE,KAAK,IAAI,IAAI,CAAC,mBAAmB;SACzC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Public TypeScript surface for the wallet client. */
|
|
2
|
+
import type { ErrorCode, RegenConfig } from "../shared.js";
|
|
3
|
+
export type { ErrorCode, RegenConfig };
|
|
4
|
+
/**
|
|
5
|
+
* Result of a spend/transfer that may be rejected. `code` is a stable,
|
|
6
|
+
* machine-readable failure tag, present only when `ok` is false.
|
|
7
|
+
*/
|
|
8
|
+
export interface SpendResult {
|
|
9
|
+
ok: boolean;
|
|
10
|
+
balance: number;
|
|
11
|
+
/** Stable failure tag when `ok` is false: `INSUFFICIENT` | `SELF_TRANSFER`. */
|
|
12
|
+
code?: ErrorCode;
|
|
13
|
+
}
|
|
14
|
+
/** A single currency balance in the multi-currency overview. */
|
|
15
|
+
export interface BalanceEntry {
|
|
16
|
+
currency: string;
|
|
17
|
+
amount: number;
|
|
18
|
+
}
|
|
19
|
+
/** A ledger row as returned by {@link Wallet.history}. */
|
|
20
|
+
export interface LedgerEntry {
|
|
21
|
+
currency: string;
|
|
22
|
+
/** Signed change: positive on earn/receive, negative on spend/send. */
|
|
23
|
+
delta: number;
|
|
24
|
+
reason: string;
|
|
25
|
+
idempotencyKey?: string;
|
|
26
|
+
createdAt: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Per-currency configuration. Omit `regen` for static (coin/gem) currencies.
|
|
30
|
+
* `max` is an optional hard ceiling on the stored balance for this currency —
|
|
31
|
+
* credits are clamped to it.
|
|
32
|
+
*/
|
|
33
|
+
export interface CurrencyConfig {
|
|
34
|
+
regen?: RegenConfig;
|
|
35
|
+
/** Hard cap on the stored balance for this currency. Credits clamp to it. */
|
|
36
|
+
max?: number;
|
|
37
|
+
}
|
|
38
|
+
/** Construction options for the {@link Wallet} client. */
|
|
39
|
+
export interface WalletOptions {
|
|
40
|
+
/** Per-currency rules, keyed by the opaque currency string. */
|
|
41
|
+
currencies?: Record<string, CurrencyConfig>;
|
|
42
|
+
/** Default page size for {@link Wallet.history}. Default `50`. */
|
|
43
|
+
defaultHistoryLimit?: number;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AAEvC;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,gEAAgE;AAChE,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,0DAA0D;AAC1D,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,0DAA0D;AAC1D,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,kEAAkE;IAClE,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,uDAAuD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated `api` utility.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type * as crons from "../crons.js";
|
|
10
|
+
import type * as internal_mutations from "../internal_mutations.js";
|
|
11
|
+
import type * as mutations from "../mutations.js";
|
|
12
|
+
import type * as queries from "../queries.js";
|
|
13
|
+
import type * as validators from "../validators.js";
|
|
14
|
+
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
15
|
+
declare const fullApi: ApiFromModules<{
|
|
16
|
+
crons: typeof crons;
|
|
17
|
+
internal_mutations: typeof internal_mutations;
|
|
18
|
+
mutations: typeof mutations;
|
|
19
|
+
queries: typeof queries;
|
|
20
|
+
validators: typeof validators;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
24
|
+
*
|
|
25
|
+
* Usage:
|
|
26
|
+
* ```js
|
|
27
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
31
|
+
/**
|
|
32
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
33
|
+
*
|
|
34
|
+
* Usage:
|
|
35
|
+
* ```js
|
|
36
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
40
|
+
export declare const components: {};
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,KAAK,kBAAkB,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,OAAO,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAGvB,QAAA,MAAM,OAAO,EAAE,cAAc,CAAC;IAC5B,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;IAC9C,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,UAAU,EAAE,OAAO,UAAU,CAAC;CAC/B,CAAiB,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,EAAE,SAAS,CACzB,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CACjB,CAAC;AAElB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,CAC9B,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CACnB,CAAC;AAElB,eAAO,MAAM,UAAU,EAAqC,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `api` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
11
|
+
const fullApi = anyApi;
|
|
12
|
+
/**
|
|
13
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```js
|
|
17
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const api = anyApi;
|
|
21
|
+
/**
|
|
22
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* ```js
|
|
26
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const internal = anyApi;
|
|
30
|
+
export const components = componentsGeneric();
|
|
31
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAaH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,OAAO,GAMR,MAAa,CAAC;AAEnB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAa,CAAC;AAElB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAGjB,MAAa,CAAC;AAElB,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAAmB,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated `ComponentApi` utility.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { FunctionReference } from "convex/server";
|
|
10
|
+
/**
|
|
11
|
+
* A utility for referencing a Convex component's exposed API.
|
|
12
|
+
*
|
|
13
|
+
* Useful when expecting a parameter like `components.myComponent`.
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```ts
|
|
16
|
+
* async function myFunction(ctx: QueryCtx, component: ComponentApi) {
|
|
17
|
+
* return ctx.runQuery(component.someFile.someQuery, { ...args });
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
22
|
+
mutations: {
|
|
23
|
+
earn: FunctionReference<"mutation", "internal", {
|
|
24
|
+
amount: number;
|
|
25
|
+
currency: string;
|
|
26
|
+
idempotencyKey?: string;
|
|
27
|
+
max?: number;
|
|
28
|
+
reason: string;
|
|
29
|
+
regen?: {
|
|
30
|
+
amount: number;
|
|
31
|
+
cap: number;
|
|
32
|
+
intervalMs: number;
|
|
33
|
+
};
|
|
34
|
+
subjectRef: string;
|
|
35
|
+
}, {
|
|
36
|
+
balance: number;
|
|
37
|
+
}, Name>;
|
|
38
|
+
spend: FunctionReference<"mutation", "internal", {
|
|
39
|
+
amount: number;
|
|
40
|
+
currency: string;
|
|
41
|
+
reason: string;
|
|
42
|
+
regen?: {
|
|
43
|
+
amount: number;
|
|
44
|
+
cap: number;
|
|
45
|
+
intervalMs: number;
|
|
46
|
+
};
|
|
47
|
+
subjectRef: string;
|
|
48
|
+
}, {
|
|
49
|
+
balance: number;
|
|
50
|
+
code?: "INSUFFICIENT" | "SELF_TRANSFER";
|
|
51
|
+
ok: boolean;
|
|
52
|
+
}, Name>;
|
|
53
|
+
transfer: FunctionReference<"mutation", "internal", {
|
|
54
|
+
amount: number;
|
|
55
|
+
currency: string;
|
|
56
|
+
fromRef: string;
|
|
57
|
+
max?: number;
|
|
58
|
+
reason: string;
|
|
59
|
+
regen?: {
|
|
60
|
+
amount: number;
|
|
61
|
+
cap: number;
|
|
62
|
+
intervalMs: number;
|
|
63
|
+
};
|
|
64
|
+
toRef: string;
|
|
65
|
+
}, {
|
|
66
|
+
balance: number;
|
|
67
|
+
code?: "INSUFFICIENT" | "SELF_TRANSFER";
|
|
68
|
+
ok: boolean;
|
|
69
|
+
}, Name>;
|
|
70
|
+
};
|
|
71
|
+
queries: {
|
|
72
|
+
balance: FunctionReference<"query", "internal", {
|
|
73
|
+
currency: string;
|
|
74
|
+
regen?: {
|
|
75
|
+
amount: number;
|
|
76
|
+
cap: number;
|
|
77
|
+
intervalMs: number;
|
|
78
|
+
};
|
|
79
|
+
subjectRef: string;
|
|
80
|
+
}, number, Name>;
|
|
81
|
+
balances: FunctionReference<"query", "internal", {
|
|
82
|
+
regen?: Record<string, {
|
|
83
|
+
amount: number;
|
|
84
|
+
cap: number;
|
|
85
|
+
intervalMs: number;
|
|
86
|
+
}>;
|
|
87
|
+
subjectRef: string;
|
|
88
|
+
}, Array<{
|
|
89
|
+
amount: number;
|
|
90
|
+
currency: string;
|
|
91
|
+
}>, Name>;
|
|
92
|
+
history: FunctionReference<"query", "internal", {
|
|
93
|
+
currency: string;
|
|
94
|
+
limit: number;
|
|
95
|
+
subjectRef: string;
|
|
96
|
+
}, Array<{
|
|
97
|
+
createdAt: number;
|
|
98
|
+
currency: string;
|
|
99
|
+
delta: number;
|
|
100
|
+
idempotencyKey?: string;
|
|
101
|
+
reason: string;
|
|
102
|
+
}>, Name>;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/component.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,CAAC,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,IAC3E;IACE,SAAS,EAAE;QACT,IAAI,EAAE,iBAAiB,CACrB,UAAU,EACV,UAAU,EACV;YACE,MAAM,EAAE,MAAM,CAAC;YACf,QAAQ,EAAE,MAAM,CAAC;YACjB,cAAc,CAAC,EAAE,MAAM,CAAC;YACxB,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,MAAM,CAAC;YACf,KAAK,CAAC,EAAE;gBAAE,MAAM,EAAE,MAAM,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAC;gBAAC,UAAU,EAAE,MAAM,CAAA;aAAE,CAAC;YAC5D,UAAU,EAAE,MAAM,CAAC;SACpB,EACD;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,EACnB,IAAI,CACL,CAAC;QACF,KAAK,EAAE,iBAAiB,CACtB,UAAU,EACV,UAAU,EACV;YACE,MAAM,EAAE,MAAM,CAAC;YACf,QAAQ,EAAE,MAAM,CAAC;YACjB,MAAM,EAAE,MAAM,CAAC;YACf,KAAK,CAAC,EAAE;gBAAE,MAAM,EAAE,MAAM,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAC;gBAAC,UAAU,EAAE,MAAM,CAAA;aAAE,CAAC;YAC5D,UAAU,EAAE,MAAM,CAAC;SACpB,EACD;YACE,OAAO,EAAE,MAAM,CAAC;YAChB,IAAI,CAAC,EAAE,cAA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AC,EAC3C,IAAI,CACL,CAAC;QACF,OAAO,EAAE,iBAAiB,CACxB,OAAO,EACP,UAAU,EACV;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAA;SAAE,EACvD,KAAK,CAAC;YACJ,SAAS,EAAE,MAAM,CAAC;YAClB,QAAQ,EAAE,MAAM,CAAC;YACjB,KAAK,EAAE,MAAM,CAAC;YACd,cAAc,CAAC,EAAE,MAAM,CAAC;YACxB,MAAM,EAAE,MAAM,CAAC;SAChB,CAAC,EACF,IAAI,CACL,CAAC;KACH,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/component/_generated/component.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG"}
|