@goodz-core/sdk 0.2.0 → 0.3.1
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 +271 -83
- package/dist/alive/index.d.ts +175 -0
- package/dist/alive/index.js +4 -0
- package/dist/alive/index.js.map +1 -0
- package/dist/chunk-4SU7SU7K.js +227 -0
- package/dist/chunk-4SU7SU7K.js.map +1 -0
- package/dist/chunk-JAVMQXJM.js +27 -0
- package/dist/chunk-JAVMQXJM.js.map +1 -0
- package/dist/chunk-KLMCZG4N.js +102 -0
- package/dist/chunk-KLMCZG4N.js.map +1 -0
- package/dist/chunk-OUKZ2PRD.js +37 -0
- package/dist/chunk-OUKZ2PRD.js.map +1 -0
- package/dist/chunk-V73MMKHI.js +56 -0
- package/dist/chunk-V73MMKHI.js.map +1 -0
- package/dist/commerce/index.d.ts +462 -0
- package/dist/commerce/index.js +4 -0
- package/dist/commerce/index.js.map +1 -0
- package/dist/core/index.d.ts +76 -385
- package/dist/core/index.js +5 -1
- package/dist/exchange/index.d.ts +252 -0
- package/dist/exchange/index.js +4 -0
- package/dist/exchange/index.js.map +1 -0
- package/dist/index.d.ts +31 -4
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/transport-BOlScYEv.d.ts +377 -0
- package/package.json +20 -3
- package/dist/chunk-G7NKU6PT.js +0 -183
- package/dist/chunk-G7NKU6PT.js.map +0 -1
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @goodz-core/sdk — Public API Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Hand-crafted types mirroring GoodZ.Core's tRPC API surface.
|
|
5
|
+
* These are the source of truth for SDK consumers — they define
|
|
6
|
+
* the contract between apps and Core.
|
|
7
|
+
*
|
|
8
|
+
* Naming convention:
|
|
9
|
+
* Input types: {Namespace}{Method}Input
|
|
10
|
+
* Output types: {Namespace}{Method}Output
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
type SaleType = "direct" | "wholesale" | "retail_resale" | "gacha" | "trade";
|
|
15
|
+
type TransferReason = "purchase" | "gift" | "trade" | "admin_transfer";
|
|
16
|
+
type PurchaseChannel = "web" | "ios" | "android";
|
|
17
|
+
type ZcoinTxType = "DEPOSIT" | "PURCHASE" | "APP_PAYMENT" | "DIRECT_PURCHASE" | "REFUND" | "ADJUSTMENT" | "EXPIRY";
|
|
18
|
+
interface ZcoinGetMyBalanceOutput {
|
|
19
|
+
balance: number;
|
|
20
|
+
totalDeposited: number;
|
|
21
|
+
totalSpent: number;
|
|
22
|
+
version: number;
|
|
23
|
+
}
|
|
24
|
+
interface ZcoinGetMyHistoryInput {
|
|
25
|
+
limit?: number;
|
|
26
|
+
offset?: number;
|
|
27
|
+
txType?: ZcoinTxType;
|
|
28
|
+
}
|
|
29
|
+
interface ZcoinCommercialTransferInput {
|
|
30
|
+
/** ID of the card_instance to transfer */
|
|
31
|
+
instanceId: number;
|
|
32
|
+
/** Buyer's userId — will be debited Z-coin */
|
|
33
|
+
buyerUserId: number;
|
|
34
|
+
/** Seller's userId — must be current owner of the instance */
|
|
35
|
+
sellerUserId: number;
|
|
36
|
+
/** Transaction price in Z-coin hundredths (e.g. 1050 = 10.50 Z-coin) */
|
|
37
|
+
priceZcoin: number;
|
|
38
|
+
/** Type of sale — determines fee rules */
|
|
39
|
+
saleType: SaleType;
|
|
40
|
+
/** Idempotency key (e.g., Commerce order ID, Exchange trade ID) */
|
|
41
|
+
referenceId: string;
|
|
42
|
+
/** OAuth APP client ID of the calling application */
|
|
43
|
+
appClientId: string;
|
|
44
|
+
/** Human-readable description of the transaction */
|
|
45
|
+
description?: string;
|
|
46
|
+
/** Optional listing ID (for Exchange trades) */
|
|
47
|
+
listingId?: number;
|
|
48
|
+
}
|
|
49
|
+
interface ZcoinCommercialTransferOutput {
|
|
50
|
+
success: true;
|
|
51
|
+
tradeId: number;
|
|
52
|
+
zcoinTxId: number;
|
|
53
|
+
ownershipEventId: number;
|
|
54
|
+
platformFee: number;
|
|
55
|
+
sellerProceeds: number;
|
|
56
|
+
primarySaleFeeApplied: boolean;
|
|
57
|
+
primarySaleFeeMarked: boolean;
|
|
58
|
+
}
|
|
59
|
+
interface ZcoinMintAndChargeInput {
|
|
60
|
+
/** The card to mint (probability result from Commerce) */
|
|
61
|
+
cardId: number;
|
|
62
|
+
/** The buyer's user ID (will be debited Z-coin and receive the new instance) */
|
|
63
|
+
buyerUserId: number;
|
|
64
|
+
/** Price per unit in Z-coin hundredths (e.g. 1050 = 10.50 Z-coin) */
|
|
65
|
+
priceZcoin: number;
|
|
66
|
+
/** Type of sale */
|
|
67
|
+
saleType?: "gacha" | "direct";
|
|
68
|
+
/** Idempotency key (e.g., Commerce order ID) */
|
|
69
|
+
referenceId: string;
|
|
70
|
+
/** OAuth APP client ID of the calling application */
|
|
71
|
+
appClientId: string;
|
|
72
|
+
/** Human-readable description */
|
|
73
|
+
description?: string;
|
|
74
|
+
/** Number of instances to mint (default 1, max 10 for batch gacha) */
|
|
75
|
+
quantity?: number;
|
|
76
|
+
}
|
|
77
|
+
interface ZcoinMintAndChargeOutput {
|
|
78
|
+
success: boolean;
|
|
79
|
+
tradeId: number;
|
|
80
|
+
zcoinTxId: number;
|
|
81
|
+
platformFee: number;
|
|
82
|
+
sellerProceeds: number;
|
|
83
|
+
authorizationId: number;
|
|
84
|
+
remainingMints: number | null;
|
|
85
|
+
instances: Array<{
|
|
86
|
+
id: number;
|
|
87
|
+
instanceCode: string;
|
|
88
|
+
shortCode: string;
|
|
89
|
+
}>;
|
|
90
|
+
}
|
|
91
|
+
interface ZcoinChargeUserInput {
|
|
92
|
+
/** Z-coin amount to charge (in hundredths, e.g. 1050 = 10.50 Z-coin) */
|
|
93
|
+
amount: number;
|
|
94
|
+
/** OAuth app client ID making the charge */
|
|
95
|
+
appClientId: string;
|
|
96
|
+
/** Unique order/reference ID from the APP (for idempotency) */
|
|
97
|
+
appOrderId: string;
|
|
98
|
+
/** Human-readable description of what the user is paying for */
|
|
99
|
+
description: string;
|
|
100
|
+
}
|
|
101
|
+
interface ZcoinChargeUserOutput {
|
|
102
|
+
success: boolean;
|
|
103
|
+
transactionId: number;
|
|
104
|
+
amountCharged: number;
|
|
105
|
+
platformFee: number;
|
|
106
|
+
developerProceeds: number;
|
|
107
|
+
balanceAfter: number;
|
|
108
|
+
referenceId: string;
|
|
109
|
+
}
|
|
110
|
+
interface ZcoinCreateDirectPurchaseOrderInput {
|
|
111
|
+
/** The card instance to purchase */
|
|
112
|
+
instanceId: number;
|
|
113
|
+
/** The seller's user ID */
|
|
114
|
+
sellerUserId: number;
|
|
115
|
+
/** Price in Z-coin hundredths (e.g. 5000 = 50.00 Z-coin) */
|
|
116
|
+
priceZcoin: number;
|
|
117
|
+
/** Type of sale */
|
|
118
|
+
saleType: SaleType;
|
|
119
|
+
/** OAuth APP client ID */
|
|
120
|
+
appClientId: string;
|
|
121
|
+
/** Idempotency key from the calling APP */
|
|
122
|
+
referenceId: string;
|
|
123
|
+
/** Human-readable description */
|
|
124
|
+
description?: string;
|
|
125
|
+
/** Purchase channel */
|
|
126
|
+
channel?: PurchaseChannel;
|
|
127
|
+
/** Frontend origin for redirect URLs */
|
|
128
|
+
origin: string;
|
|
129
|
+
/** Optional listing ID (for Exchange trades) */
|
|
130
|
+
listingId?: number;
|
|
131
|
+
}
|
|
132
|
+
interface ZcoinCreateDirectPurchaseOrderOutput {
|
|
133
|
+
sessionId: string;
|
|
134
|
+
checkoutUrl: string;
|
|
135
|
+
priceZcoin: number;
|
|
136
|
+
fiatAmountCents: number;
|
|
137
|
+
groupId: string;
|
|
138
|
+
channel: PurchaseChannel;
|
|
139
|
+
status: "pending_payment";
|
|
140
|
+
}
|
|
141
|
+
interface ZcoinGetDepositPackagesInput {
|
|
142
|
+
channel?: PurchaseChannel;
|
|
143
|
+
}
|
|
144
|
+
interface ZcoinDepositPackage {
|
|
145
|
+
id: string;
|
|
146
|
+
zcoinAmount: number;
|
|
147
|
+
zcoinHundredths: number;
|
|
148
|
+
label: string;
|
|
149
|
+
basePriceCents: number;
|
|
150
|
+
totalPriceCents: number;
|
|
151
|
+
channel: PurchaseChannel;
|
|
152
|
+
featured: boolean;
|
|
153
|
+
}
|
|
154
|
+
interface ZcoinCreateDepositOrderInput {
|
|
155
|
+
/** Z-coin amount to purchase (display units, e.g. 100 or 100.50) */
|
|
156
|
+
amount: number;
|
|
157
|
+
/** Purchase channel */
|
|
158
|
+
channel?: PurchaseChannel;
|
|
159
|
+
/** Frontend origin for redirect URLs */
|
|
160
|
+
origin: string;
|
|
161
|
+
}
|
|
162
|
+
interface ZcoinCreateDepositOrderOutput {
|
|
163
|
+
sessionId: string;
|
|
164
|
+
checkoutUrl: string;
|
|
165
|
+
zcoinAmount: number;
|
|
166
|
+
fiatAmountCents: number;
|
|
167
|
+
channel: PurchaseChannel;
|
|
168
|
+
status: "pending_payment";
|
|
169
|
+
}
|
|
170
|
+
interface ZcoinGetDepositStatusInput {
|
|
171
|
+
sessionId: string;
|
|
172
|
+
}
|
|
173
|
+
interface ZcoinGetDepositStatusOutput {
|
|
174
|
+
sessionId: string;
|
|
175
|
+
paymentStatus: string;
|
|
176
|
+
status: string;
|
|
177
|
+
zcoinAmount: number;
|
|
178
|
+
amountTotal: number | null;
|
|
179
|
+
currency: string | null;
|
|
180
|
+
}
|
|
181
|
+
interface InventoryGetUserInventoryInput {
|
|
182
|
+
userId?: number;
|
|
183
|
+
openId?: string;
|
|
184
|
+
seriesId?: number;
|
|
185
|
+
limit?: number;
|
|
186
|
+
offset?: number;
|
|
187
|
+
}
|
|
188
|
+
interface InventoryConfirmOwnershipInput {
|
|
189
|
+
userId: number;
|
|
190
|
+
cardId: number;
|
|
191
|
+
}
|
|
192
|
+
interface InventoryConfirmOwnershipOutput {
|
|
193
|
+
owns: boolean;
|
|
194
|
+
count: number;
|
|
195
|
+
}
|
|
196
|
+
interface InventoryMintInput {
|
|
197
|
+
cardId: number;
|
|
198
|
+
toUserId: number;
|
|
199
|
+
quantity?: number;
|
|
200
|
+
referenceId?: string;
|
|
201
|
+
}
|
|
202
|
+
interface InventoryMintOutput {
|
|
203
|
+
success: boolean;
|
|
204
|
+
cardId: number;
|
|
205
|
+
toUserId: number;
|
|
206
|
+
quantity: number;
|
|
207
|
+
instances: Array<{
|
|
208
|
+
id: number;
|
|
209
|
+
instanceCode: string;
|
|
210
|
+
shortCode: string;
|
|
211
|
+
}>;
|
|
212
|
+
}
|
|
213
|
+
interface InventoryTransferInput {
|
|
214
|
+
instanceId: number;
|
|
215
|
+
toUserId: number;
|
|
216
|
+
reason?: TransferReason;
|
|
217
|
+
referenceId?: string;
|
|
218
|
+
expectedVersion?: number;
|
|
219
|
+
}
|
|
220
|
+
interface InventoryTransferOutput {
|
|
221
|
+
success: true;
|
|
222
|
+
idempotent: boolean;
|
|
223
|
+
instanceId: number;
|
|
224
|
+
fromUserId: number | null;
|
|
225
|
+
toUserId: number;
|
|
226
|
+
reason: string;
|
|
227
|
+
eventId?: number;
|
|
228
|
+
_deprecation_warning?: string;
|
|
229
|
+
}
|
|
230
|
+
interface InventoryTransferByCardInput {
|
|
231
|
+
cardId: number;
|
|
232
|
+
toUserId: number;
|
|
233
|
+
quantity?: number;
|
|
234
|
+
reason?: TransferReason;
|
|
235
|
+
referenceId?: string;
|
|
236
|
+
}
|
|
237
|
+
interface InventoryTransferByCardOutput {
|
|
238
|
+
success: true;
|
|
239
|
+
idempotent: boolean;
|
|
240
|
+
cardId: number;
|
|
241
|
+
fromUserId: number | null;
|
|
242
|
+
toUserId: number;
|
|
243
|
+
quantity: number;
|
|
244
|
+
reason: string;
|
|
245
|
+
_deprecation_warning?: string;
|
|
246
|
+
}
|
|
247
|
+
interface InventoryGrantMintAuthInput {
|
|
248
|
+
cardId: number;
|
|
249
|
+
granteeUserId: number;
|
|
250
|
+
granteeAppClientId?: string;
|
|
251
|
+
maxMintCount?: number;
|
|
252
|
+
validUntilMs?: number;
|
|
253
|
+
}
|
|
254
|
+
interface InventoryTransferHistoryInput {
|
|
255
|
+
instanceId?: number;
|
|
256
|
+
cardId?: number;
|
|
257
|
+
userId?: number;
|
|
258
|
+
limit?: number;
|
|
259
|
+
offset?: number;
|
|
260
|
+
}
|
|
261
|
+
interface CollectibleGetInstanceByIdInput {
|
|
262
|
+
instanceId: number;
|
|
263
|
+
claimToken?: string;
|
|
264
|
+
}
|
|
265
|
+
interface CollectibleGetPublicInstanceInput {
|
|
266
|
+
instanceCode: string;
|
|
267
|
+
}
|
|
268
|
+
interface CollectibleGetPublicInstancesBatchInput {
|
|
269
|
+
instanceIds: number[];
|
|
270
|
+
}
|
|
271
|
+
interface CollectibleGetCardProfileInput {
|
|
272
|
+
cardId: number;
|
|
273
|
+
}
|
|
274
|
+
interface CollectibleGetShellImageUrlInput {
|
|
275
|
+
cardId: number;
|
|
276
|
+
}
|
|
277
|
+
interface UserGetPublicProfileInput {
|
|
278
|
+
openId: string;
|
|
279
|
+
}
|
|
280
|
+
interface UserPublicProfile {
|
|
281
|
+
openId: string;
|
|
282
|
+
name: string;
|
|
283
|
+
avatarUrl: string | null;
|
|
284
|
+
joinedAt: Date;
|
|
285
|
+
stats: {
|
|
286
|
+
totalOwned: number;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
interface UserGetPublicProfileByIdInput {
|
|
290
|
+
userId: number;
|
|
291
|
+
}
|
|
292
|
+
interface AuthGetOAuthAppInfoInput {
|
|
293
|
+
clientId: string;
|
|
294
|
+
}
|
|
295
|
+
interface AuthOAuthAppInfo {
|
|
296
|
+
appName: string;
|
|
297
|
+
iconUrl: string | null;
|
|
298
|
+
websiteUrl: string | null;
|
|
299
|
+
}
|
|
300
|
+
interface AuthUser {
|
|
301
|
+
id: number;
|
|
302
|
+
openId: string;
|
|
303
|
+
name: string;
|
|
304
|
+
email: string | null;
|
|
305
|
+
avatarUrl: string | null;
|
|
306
|
+
role: "admin" | "user";
|
|
307
|
+
}
|
|
308
|
+
interface FranchiseGetInput {
|
|
309
|
+
id?: number;
|
|
310
|
+
slug?: string;
|
|
311
|
+
}
|
|
312
|
+
interface SeriesGetInput {
|
|
313
|
+
id?: number;
|
|
314
|
+
slug?: string;
|
|
315
|
+
}
|
|
316
|
+
interface SeriesListByFranchiseInput {
|
|
317
|
+
franchiseId: number;
|
|
318
|
+
}
|
|
319
|
+
interface CardGetInput {
|
|
320
|
+
id: number;
|
|
321
|
+
}
|
|
322
|
+
interface CardListBySeriesInput {
|
|
323
|
+
seriesId: number;
|
|
324
|
+
}
|
|
325
|
+
interface GoodZApiFieldError {
|
|
326
|
+
path: (string | number)[];
|
|
327
|
+
message: string;
|
|
328
|
+
code: string;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Structured error from GoodZ.Core API.
|
|
332
|
+
* Includes tRPC error code, HTTP status, and optional Zod validation details.
|
|
333
|
+
*/
|
|
334
|
+
interface GoodZErrorV2 {
|
|
335
|
+
type: string;
|
|
336
|
+
code: string;
|
|
337
|
+
message: string;
|
|
338
|
+
httpStatus: number;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* @goodz-core/sdk — HTTP Transport Layer
|
|
343
|
+
*
|
|
344
|
+
* Speaks the tRPC v11 HTTP wire protocol directly using fetch.
|
|
345
|
+
* Handles superjson serialization, batching, and error parsing.
|
|
346
|
+
*
|
|
347
|
+
* Wire format reference:
|
|
348
|
+
* - Queries: GET /api/trpc/{procedure}?input={superjson-encoded}
|
|
349
|
+
* - Mutations: POST /api/trpc/{procedure} body: {superjson-encoded}
|
|
350
|
+
* - Batch: GET /api/trpc/{p1},{p2}?input={0: ..., 1: ...}
|
|
351
|
+
*
|
|
352
|
+
* @internal
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
declare class GoodZApiError extends Error {
|
|
356
|
+
readonly code: string;
|
|
357
|
+
readonly httpStatus: number;
|
|
358
|
+
readonly path: string;
|
|
359
|
+
readonly zodErrors?: GoodZApiFieldError[];
|
|
360
|
+
readonly data?: unknown;
|
|
361
|
+
constructor(opts: {
|
|
362
|
+
message: string;
|
|
363
|
+
code: string;
|
|
364
|
+
httpStatus: number;
|
|
365
|
+
path: string;
|
|
366
|
+
zodErrors?: GoodZApiFieldError[];
|
|
367
|
+
data?: unknown;
|
|
368
|
+
});
|
|
369
|
+
/** Human-readable summary including field errors if present. */
|
|
370
|
+
toDetailedString(): string;
|
|
371
|
+
}
|
|
372
|
+
interface TransportConfig {
|
|
373
|
+
baseUrl: string;
|
|
374
|
+
getHeaders: () => Record<string, string> | Promise<Record<string, string>>;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export { type AuthGetOAuthAppInfoInput as A, type ZcoinCommercialTransferOutput as B, type CardGetInput as C, type ZcoinCreateDepositOrderInput as D, type ZcoinCreateDepositOrderOutput as E, type FranchiseGetInput as F, GoodZApiError as G, type ZcoinCreateDirectPurchaseOrderInput as H, type InventoryConfirmOwnershipInput as I, type ZcoinCreateDirectPurchaseOrderOutput as J, type ZcoinDepositPackage as K, type ZcoinGetDepositPackagesInput as L, type ZcoinGetDepositStatusInput as M, type ZcoinGetDepositStatusOutput as N, type ZcoinGetMyBalanceOutput as O, type PurchaseChannel as P, type ZcoinGetMyHistoryInput as Q, type ZcoinMintAndChargeInput as R, type SaleType as S, type TransferReason as T, type UserGetPublicProfileByIdInput as U, type ZcoinMintAndChargeOutput as V, type ZcoinTxType as W, type TransportConfig as X, type ZcoinChargeUserInput as Z, type AuthOAuthAppInfo as a, type AuthUser as b, type CardListBySeriesInput as c, type CollectibleGetCardProfileInput as d, type CollectibleGetInstanceByIdInput as e, type CollectibleGetPublicInstanceInput as f, type CollectibleGetPublicInstancesBatchInput as g, type CollectibleGetShellImageUrlInput as h, type GoodZApiFieldError as i, type GoodZErrorV2 as j, type InventoryConfirmOwnershipOutput as k, type InventoryGetUserInventoryInput as l, type InventoryGrantMintAuthInput as m, type InventoryMintInput as n, type InventoryMintOutput as o, type InventoryTransferByCardInput as p, type InventoryTransferByCardOutput as q, type InventoryTransferHistoryInput as r, type InventoryTransferInput as s, type InventoryTransferOutput as t, type SeriesGetInput as u, type SeriesListByFranchiseInput as v, type UserGetPublicProfileInput as w, type UserPublicProfile as x, type ZcoinChargeUserOutput as y, type ZcoinCommercialTransferInput as z };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodz-core/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Official SDK for GoodZ
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Official SDK for the GoodZ Ecosystem — unified API client for Core, Commerce, Exchange, and Alive. Includes OAuth helpers, Z-coin utilities, and React UI components.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -25,6 +25,18 @@
|
|
|
25
25
|
"./ui": {
|
|
26
26
|
"types": "./dist/ui/index.d.ts",
|
|
27
27
|
"import": "./dist/ui/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./commerce": {
|
|
30
|
+
"types": "./dist/commerce/index.d.ts",
|
|
31
|
+
"import": "./dist/commerce/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./exchange": {
|
|
34
|
+
"types": "./dist/exchange/index.d.ts",
|
|
35
|
+
"import": "./dist/exchange/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./alive": {
|
|
38
|
+
"types": "./dist/alive/index.d.ts",
|
|
39
|
+
"import": "./dist/alive/index.js"
|
|
28
40
|
}
|
|
29
41
|
},
|
|
30
42
|
"files": [
|
|
@@ -47,7 +59,12 @@
|
|
|
47
59
|
"zcoin",
|
|
48
60
|
"react",
|
|
49
61
|
"card-display",
|
|
50
|
-
"holographic"
|
|
62
|
+
"holographic",
|
|
63
|
+
"commerce",
|
|
64
|
+
"exchange",
|
|
65
|
+
"marketplace",
|
|
66
|
+
"gacha",
|
|
67
|
+
"nft"
|
|
51
68
|
],
|
|
52
69
|
"author": "GoodZ Team",
|
|
53
70
|
"license": "MIT",
|
package/dist/chunk-G7NKU6PT.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import superjson from 'superjson';
|
|
2
|
-
|
|
3
|
-
// src/transport.ts
|
|
4
|
-
var GoodZApiError = class extends Error {
|
|
5
|
-
code;
|
|
6
|
-
httpStatus;
|
|
7
|
-
path;
|
|
8
|
-
zodErrors;
|
|
9
|
-
data;
|
|
10
|
-
constructor(opts) {
|
|
11
|
-
super(opts.message);
|
|
12
|
-
this.name = "GoodZApiError";
|
|
13
|
-
this.code = opts.code;
|
|
14
|
-
this.httpStatus = opts.httpStatus;
|
|
15
|
-
this.path = opts.path;
|
|
16
|
-
this.zodErrors = opts.zodErrors;
|
|
17
|
-
this.data = opts.data;
|
|
18
|
-
}
|
|
19
|
-
/** Human-readable summary including field errors if present. */
|
|
20
|
-
toDetailedString() {
|
|
21
|
-
const parts = [
|
|
22
|
-
`[GoodZApiError] ${this.code} on ${this.path}: ${this.message}`
|
|
23
|
-
];
|
|
24
|
-
if (this.zodErrors?.length) {
|
|
25
|
-
parts.push("Field errors:");
|
|
26
|
-
for (const e of this.zodErrors) {
|
|
27
|
-
parts.push(` - ${e.path.join(".")}: ${e.message} (${e.code})`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return parts.join("\n");
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
async function callQuery(config, path, input) {
|
|
34
|
-
const url = `${config.baseUrl}/api/trpc/${path}`;
|
|
35
|
-
const headers = await config.getHeaders();
|
|
36
|
-
const serialized = input !== void 0 ? superjson.serialize(input) : void 0;
|
|
37
|
-
const queryUrl = serialized ? `${url}?input=${encodeURIComponent(JSON.stringify(serialized))}` : url;
|
|
38
|
-
const res = await fetch(queryUrl, {
|
|
39
|
-
method: "GET",
|
|
40
|
-
headers: {
|
|
41
|
-
...headers,
|
|
42
|
-
"Content-Type": "application/json"
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return parseResponse(res, path);
|
|
46
|
-
}
|
|
47
|
-
async function callMutation(config, path, input) {
|
|
48
|
-
const url = `${config.baseUrl}/api/trpc/${path}`;
|
|
49
|
-
const headers = await config.getHeaders();
|
|
50
|
-
const serialized = input !== void 0 ? superjson.serialize(input) : void 0;
|
|
51
|
-
const res = await fetch(url, {
|
|
52
|
-
method: "POST",
|
|
53
|
-
headers: {
|
|
54
|
-
...headers,
|
|
55
|
-
"Content-Type": "application/json"
|
|
56
|
-
},
|
|
57
|
-
body: serialized ? JSON.stringify(serialized) : void 0
|
|
58
|
-
});
|
|
59
|
-
return parseResponse(res, path);
|
|
60
|
-
}
|
|
61
|
-
async function parseResponse(res, path) {
|
|
62
|
-
const text = await res.text();
|
|
63
|
-
let body;
|
|
64
|
-
try {
|
|
65
|
-
body = JSON.parse(text);
|
|
66
|
-
} catch {
|
|
67
|
-
throw new GoodZApiError({
|
|
68
|
-
message: `Invalid JSON response: ${text.slice(0, 200)}`,
|
|
69
|
-
code: "PARSE_ERROR",
|
|
70
|
-
httpStatus: res.status,
|
|
71
|
-
path
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const envelope = Array.isArray(body) ? body[0] : body;
|
|
75
|
-
if (envelope?.error) {
|
|
76
|
-
const err = envelope.error;
|
|
77
|
-
const errJson = err?.json ?? err;
|
|
78
|
-
const errData = errJson?.data ?? {};
|
|
79
|
-
throw new GoodZApiError({
|
|
80
|
-
message: errJson?.message ?? "Unknown API error",
|
|
81
|
-
code: errData?.code ?? errJson?.code ?? "UNKNOWN",
|
|
82
|
-
httpStatus: errData?.httpStatus ?? res.status,
|
|
83
|
-
path: errData?.path ?? path,
|
|
84
|
-
zodErrors: errData?.zodError?.issues,
|
|
85
|
-
data: errData
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
const resultData = envelope?.result?.data;
|
|
89
|
-
if (resultData === void 0) {
|
|
90
|
-
if (res.ok) return void 0;
|
|
91
|
-
throw new GoodZApiError({
|
|
92
|
-
message: `Unexpected response shape from ${path}`,
|
|
93
|
-
code: "UNEXPECTED_RESPONSE",
|
|
94
|
-
httpStatus: res.status,
|
|
95
|
-
path
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (resultData && typeof resultData === "object" && "json" in resultData) {
|
|
99
|
-
return superjson.deserialize(resultData);
|
|
100
|
-
}
|
|
101
|
-
return resultData;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// src/core/index.ts
|
|
105
|
-
function createGoodZClient(config = {}) {
|
|
106
|
-
const {
|
|
107
|
-
coreUrl = "https://goodzcore.manus.space",
|
|
108
|
-
accessToken,
|
|
109
|
-
getAccessToken,
|
|
110
|
-
headers: customHeaders
|
|
111
|
-
} = config;
|
|
112
|
-
const transport = {
|
|
113
|
-
baseUrl: coreUrl.replace(/\/$/, ""),
|
|
114
|
-
getHeaders: async () => {
|
|
115
|
-
const h = { ...customHeaders };
|
|
116
|
-
const token = getAccessToken ? await getAccessToken() : accessToken;
|
|
117
|
-
if (token) {
|
|
118
|
-
h["Authorization"] = `Bearer ${token}`;
|
|
119
|
-
}
|
|
120
|
-
return h;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const q = (path) => (input) => callQuery(transport, path, input);
|
|
124
|
-
const m = (path) => (input) => callMutation(transport, path, input);
|
|
125
|
-
return {
|
|
126
|
-
// ── zcoin ──────────────────────────────────────────────
|
|
127
|
-
zcoin: {
|
|
128
|
-
getMyBalance: q("zcoin.getMyBalance"),
|
|
129
|
-
getMyHistory: q("zcoin.getMyHistory"),
|
|
130
|
-
getDepositPackages: q("zcoin.getDepositPackages"),
|
|
131
|
-
createDepositOrder: m("zcoin.createDepositOrder"),
|
|
132
|
-
getDepositStatus: q("zcoin.getDepositStatus"),
|
|
133
|
-
commercialTransfer: m("zcoin.commercialTransfer"),
|
|
134
|
-
mintAndCharge: m("zcoin.mintAndCharge"),
|
|
135
|
-
chargeUser: m("zcoin.chargeUser"),
|
|
136
|
-
createDirectPurchaseOrder: m("zcoin.createDirectPurchaseOrder")
|
|
137
|
-
},
|
|
138
|
-
// ── inventory ──────────────────────────────────────────
|
|
139
|
-
inventory: {
|
|
140
|
-
getUserInventory: q("inventory.getUserInventory"),
|
|
141
|
-
confirmOwnership: q("inventory.confirmOwnership"),
|
|
142
|
-
mint: m("inventory.mint"),
|
|
143
|
-
transfer: m("inventory.transfer"),
|
|
144
|
-
transferByCard: m("inventory.transferByCard"),
|
|
145
|
-
grantMintAuth: m("inventory.grantMintAuth"),
|
|
146
|
-
transferHistory: q("inventory.transferHistory")
|
|
147
|
-
},
|
|
148
|
-
// ── collectible ────────────────────────────────────────
|
|
149
|
-
collectible: {
|
|
150
|
-
getInstanceById: q("collectible.getInstanceById"),
|
|
151
|
-
getPublicInstance: q("collectible.getPublicInstance"),
|
|
152
|
-
getPublicInstancesBatch: q("collectible.getPublicInstancesBatch"),
|
|
153
|
-
getCardProfile: q("collectible.getCardProfile"),
|
|
154
|
-
getShellImageUrl: q("collectible.getShellImageUrl")
|
|
155
|
-
},
|
|
156
|
-
// ── user ───────────────────────────────────────────────
|
|
157
|
-
user: {
|
|
158
|
-
getPublicProfile: q("user.getPublicProfile"),
|
|
159
|
-
getPublicProfileById: q("user.getPublicProfileById")
|
|
160
|
-
},
|
|
161
|
-
// ── auth ───────────────────────────────────────────────
|
|
162
|
-
auth: {
|
|
163
|
-
me: q("auth.me"),
|
|
164
|
-
getOAuthAppInfo: q("auth.getOAuthAppInfo")
|
|
165
|
-
},
|
|
166
|
-
// ── ip (franchise/series/card) ─────────────────────────
|
|
167
|
-
ip: {
|
|
168
|
-
getFranchise: q("franchise.get"),
|
|
169
|
-
getSeries: q("series.get"),
|
|
170
|
-
listSeriesByFranchise: q("series.listByFranchise"),
|
|
171
|
-
getCard: q("card.get"),
|
|
172
|
-
listCardsBySeries: q("card.listBySeries")
|
|
173
|
-
},
|
|
174
|
-
// ── raw escape hatches ─────────────────────────────────
|
|
175
|
-
rawQuery: (path, input) => callQuery(transport, path, input),
|
|
176
|
-
rawMutation: (path, input) => callMutation(transport, path, input)
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
var createUserClient = createGoodZClient;
|
|
180
|
-
|
|
181
|
-
export { GoodZApiError, createGoodZClient, createUserClient };
|
|
182
|
-
//# sourceMappingURL=chunk-G7NKU6PT.js.map
|
|
183
|
-
//# sourceMappingURL=chunk-G7NKU6PT.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/transport.ts","../src/core/index.ts"],"names":[],"mappings":";;;AAmBO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EACvB,IAAA;AAAA,EACA,UAAA;AAAA,EACA,IAAA;AAAA,EACA,SAAA;AAAA,EACA,IAAA;AAAA,EAEhB,YAAY,IAAA,EAOT;AACD,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,aAAa,IAAA,CAAK,UAAA;AACvB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AAAA,EACnB;AAAA;AAAA,EAGA,gBAAA,GAA2B;AACzB,IAAA,MAAM,KAAA,GAAQ;AAAA,MACZ,CAAA,gBAAA,EAAmB,KAAK,IAAI,CAAA,IAAA,EAAO,KAAK,IAAI,CAAA,EAAA,EAAK,KAAK,OAAO,CAAA;AAAA,KAC/D;AACA,IAAA,IAAI,IAAA,CAAK,WAAW,MAAA,EAAQ;AAC1B,MAAA,KAAA,CAAM,KAAK,eAAe,CAAA;AAC1B,MAAA,KAAA,MAAW,CAAA,IAAK,KAAK,SAAA,EAAW;AAC9B,QAAA,KAAA,CAAM,IAAA,CAAK,CAAA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AAA,MACX,eAAA,EAAiB,EAAwC,6BAA6B,CAAA;AAAA,MACtF,iBAAA,EAAmB,EAA0C,+BAA+B,CAAA;AAAA,MAC5F,uBAAA,EAAyB,EAAkD,qCAAqC,CAAA;AAAA,MAChH,cAAA,EAAgB,EAAuC,4BAA4B,CAAA;AAAA,MACnF,gBAAA,EAAkB,EAAyC,8BAA8B;AAAA,KAC3F;AAAA;AAAA,IAGA,IAAA,EAAM;AAAA,MACJ,gBAAA,EAAkB,EAAgD,uBAAuB,CAAA;AAAA,MACzF,oBAAA,EAAsB,EAAoD,2BAA2B;AAAA,KACvG;AAAA;AAAA,IAGA,IAAA,EAAM;AAAA,MACJ,EAAA,EAAI,EAAyB,SAAS,CAAA;AAAA,MACtC,eAAA,EAAiB,EAAqD,sBAAsB;AAAA,KAC9F;AAAA;AAAA,IAGA,EAAA,EAAI;AAAA,MACF,YAAA,EAAc,EAA0B,eAAe,CAAA;AAAA,MACvD,SAAA,EAAW,EAAuB,YAAY,CAAA;AAAA,MAC9C,qBAAA,EAAuB,EAAqC,wBAAwB,CAAA;AAAA,MACpF,OAAA,EAAS,EAAqB,UAAU,CAAA;AAAA,MACxC,iBAAA,EAAmB,EAAgC,mBAAmB;AAAA,KACxE;AAAA;AAAA,IAGA,UAAU,CAAU,IAAA,EAAc,UAAgB,SAAA,CAAkB,SAAA,EAAW,MAAM,KAAK,CAAA;AAAA,IAC1F,aAAa,CAAU,IAAA,EAAc,UAAgB,YAAA,CAAqB,SAAA,EAAW,MAAM,KAAK;AAAA,GAClG;AACF;AAMO,IAAM,gBAAA,GAAmB","file":"chunk-G7NKU6PT.js","sourcesContent":["/**\n * @goodz-core/sdk — HTTP Transport Layer\n *\n * Speaks the tRPC v11 HTTP wire protocol directly using fetch.\n * Handles superjson serialization, batching, and error parsing.\n *\n * Wire format reference:\n * - Queries: GET /api/trpc/{procedure}?input={superjson-encoded}\n * - Mutations: POST /api/trpc/{procedure} body: {superjson-encoded}\n * - Batch: GET /api/trpc/{p1},{p2}?input={0: ..., 1: ...}\n *\n * @internal\n */\n\nimport superjson from \"superjson\";\nimport type { GoodZApiFieldError } from \"./types\";\n\n// ─── Error class ─────────────────────────────────────────────\n\nexport class GoodZApiError extends Error {\n public readonly code: string;\n public readonly httpStatus: number;\n public readonly path: string;\n public readonly zodErrors?: GoodZApiFieldError[];\n public readonly data?: unknown;\n\n constructor(opts: {\n message: string;\n code: string;\n httpStatus: number;\n path: string;\n zodErrors?: GoodZApiFieldError[];\n data?: unknown;\n }) {\n super(opts.message);\n this.name = \"GoodZApiError\";\n this.code = opts.code;\n this.httpStatus = opts.httpStatus;\n this.path = opts.path;\n this.zodErrors = opts.zodErrors;\n this.data = opts.data;\n }\n\n /** Human-readable summary including field errors if present. */\n toDetailedString(): string {\n const parts = [\n `[GoodZApiError] ${this.code} on ${this.path}: ${this.message}`,\n ];\n if (this.zodErrors?.length) {\n parts.push(\"Field errors:\");\n for (const e of this.zodErrors) {\n parts.push(` - ${e.path.join(\".\")}: ${e.message} (${e.code})`);\n }\n }\n return parts.join(\"\\n\");\n }\n}\n\n// ─── Transport config ────────────────────────────────────────\n\nexport interface TransportConfig {\n baseUrl: string;\n getHeaders: () => Record<string, string> | Promise<Record<string, string>>;\n}\n\n// ─── Core transport functions ────────────────────────────────\n\n/**\n * Call a tRPC query (GET request).\n * Uses POST with method override for compatibility with Commerce/Exchange\n * server-to-server patterns (some proxies strip GET bodies).\n */\nexport async function callQuery<TInput, TOutput>(\n config: TransportConfig,\n path: string,\n input?: TInput,\n): Promise<TOutput> {\n const url = `${config.baseUrl}/api/trpc/${path}`;\n const headers = await config.getHeaders();\n\n // Use GET with query params for queries (standard tRPC)\n const serialized = input !== undefined ? superjson.serialize(input) : undefined;\n const queryUrl = serialized\n ? `${url}?input=${encodeURIComponent(JSON.stringify(serialized))}`\n : url;\n\n const res = await fetch(queryUrl, {\n method: \"GET\",\n headers: {\n ...headers,\n \"Content-Type\": \"application/json\",\n },\n });\n\n return parseResponse<TOutput>(res, path);\n}\n\n/**\n * Call a tRPC mutation (POST request).\n */\nexport async function callMutation<TInput, TOutput>(\n config: TransportConfig,\n path: string,\n input?: TInput,\n): Promise<TOutput> {\n const url = `${config.baseUrl}/api/trpc/${path}`;\n const headers = await config.getHeaders();\n\n const serialized = input !== undefined ? superjson.serialize(input) : undefined;\n\n const res = await fetch(url, {\n method: \"POST\",\n headers: {\n ...headers,\n \"Content-Type\": \"application/json\",\n },\n body: serialized ? JSON.stringify(serialized) : undefined,\n });\n\n return parseResponse<TOutput>(res, path);\n}\n\n// ─── Response parser ─────────────────────────────────────────\n\nasync function parseResponse<T>(res: Response, path: string): Promise<T> {\n const text = await res.text();\n let body: any;\n\n try {\n body = JSON.parse(text);\n } catch {\n throw new GoodZApiError({\n message: `Invalid JSON response: ${text.slice(0, 200)}`,\n code: \"PARSE_ERROR\",\n httpStatus: res.status,\n path,\n });\n }\n\n // tRPC wraps responses in { result: { data: ... } }\n // Batch responses are arrays: [{ result: { data: ... } }]\n const envelope = Array.isArray(body) ? body[0] : body;\n\n // Check for tRPC error envelope\n if (envelope?.error) {\n const err = envelope.error;\n const errJson = err?.json ?? err;\n const errData = errJson?.data ?? {};\n\n throw new GoodZApiError({\n message: errJson?.message ?? \"Unknown API error\",\n code: errData?.code ?? errJson?.code ?? \"UNKNOWN\",\n httpStatus: errData?.httpStatus ?? res.status,\n path: errData?.path ?? path,\n zodErrors: errData?.zodError?.issues,\n data: errData,\n });\n }\n\n // Success path: extract and deserialize the data\n const resultData = envelope?.result?.data;\n if (resultData === undefined) {\n // Some queries return null/undefined legitimately\n if (res.ok) return undefined as T;\n\n throw new GoodZApiError({\n message: `Unexpected response shape from ${path}`,\n code: \"UNEXPECTED_RESPONSE\",\n httpStatus: res.status,\n path,\n });\n }\n\n // superjson wraps data in { json: ..., meta?: ... }\n // Check if it's a superjson envelope\n if (resultData && typeof resultData === \"object\" && \"json\" in resultData) {\n return superjson.deserialize(resultData) as T;\n }\n\n // Plain JSON (shouldn't happen with superjson transformer, but be safe)\n return resultData as T;\n}\n","/**\n * @goodz-core/sdk/core — Type-safe API client for GoodZ.Core\n *\n * Zero tRPC dependency — speaks the tRPC HTTP wire protocol directly\n * using fetch + superjson. All types are hand-crafted and self-contained.\n *\n * @example\n * ```ts\n * import { createGoodZClient } from \"@goodz-core/sdk/core\";\n *\n * const goodz = createGoodZClient({\n * coreUrl: \"https://goodzcore.manus.space\",\n * accessToken: \"your-jwt-token\",\n * });\n *\n * // Fully typed — IDE autocomplete for all inputs and outputs\n * const balance = await goodz.zcoin.getMyBalance();\n * const result = await goodz.zcoin.commercialTransfer({ ... });\n * const instance = await goodz.collectible.getInstanceById({ instanceId: 90447 });\n * ```\n *\n * @module\n */\n\nimport { callQuery, callMutation, GoodZApiError } from \"../transport\";\nimport type { TransportConfig } from \"../transport\";\nimport type {\n // zcoin\n ZcoinGetMyBalanceOutput,\n ZcoinGetMyHistoryInput,\n ZcoinCommercialTransferInput,\n ZcoinCommercialTransferOutput,\n ZcoinMintAndChargeInput,\n ZcoinMintAndChargeOutput,\n ZcoinChargeUserInput,\n ZcoinChargeUserOutput,\n ZcoinCreateDirectPurchaseOrderInput,\n ZcoinCreateDirectPurchaseOrderOutput,\n ZcoinGetDepositPackagesInput,\n ZcoinDepositPackage,\n ZcoinCreateDepositOrderInput,\n ZcoinCreateDepositOrderOutput,\n ZcoinGetDepositStatusInput,\n ZcoinGetDepositStatusOutput,\n // inventory\n InventoryGetUserInventoryInput,\n InventoryConfirmOwnershipInput,\n InventoryConfirmOwnershipOutput,\n InventoryMintInput,\n InventoryMintOutput,\n InventoryTransferInput,\n InventoryTransferOutput,\n InventoryTransferByCardInput,\n InventoryTransferByCardOutput,\n InventoryGrantMintAuthInput,\n InventoryTransferHistoryInput,\n // collectible\n CollectibleGetInstanceByIdInput,\n CollectibleGetPublicInstanceInput,\n CollectibleGetPublicInstancesBatchInput,\n CollectibleGetCardProfileInput,\n CollectibleGetShellImageUrlInput,\n // user\n UserGetPublicProfileInput,\n UserPublicProfile,\n UserGetPublicProfileByIdInput,\n // auth\n AuthGetOAuthAppInfoInput,\n AuthOAuthAppInfo,\n AuthUser,\n // ip\n FranchiseGetInput,\n SeriesGetInput,\n SeriesListByFranchiseInput,\n CardGetInput,\n CardListBySeriesInput,\n} from \"../types\";\n\n// ─── Re-export types and error class ─────────────────────────\n\nexport { GoodZApiError } from \"../transport\";\nexport type * from \"../types\";\n\n// ─── Client config ───────────────────────────────────────────\n\nexport interface GoodZClientConfig {\n /**\n * GoodZ.Core base URL.\n * @default \"https://goodzcore.manus.space\"\n */\n coreUrl?: string;\n\n /**\n * Static access token (JWT) for authentication.\n * For server-to-server calls, obtain this via OAuth client_credentials flow.\n * For user-context calls, pass the user's access token.\n */\n accessToken?: string;\n\n /**\n * Dynamic token provider — called before every request.\n * Use this when tokens may rotate (e.g., auto-refresh).\n * Takes precedence over `accessToken` if both are set.\n */\n getAccessToken?: () => string | Promise<string>;\n\n /**\n * Custom headers to include in every request.\n * Useful for passing app identifiers or tracing headers.\n */\n headers?: Record<string, string>;\n}\n\n// ─── Namespace interfaces (for type documentation) ───────────\n\nexport interface ZcoinNamespace {\n /** Get the authenticated user's Z-coin balance. */\n getMyBalance(): Promise<ZcoinGetMyBalanceOutput>;\n\n /** Get the authenticated user's Z-coin transaction history. */\n getMyHistory(input?: ZcoinGetMyHistoryInput): Promise<any[]>;\n\n /** Get available Z-coin deposit packages with pricing. */\n getDepositPackages(input?: ZcoinGetDepositPackagesInput): Promise<ZcoinDepositPackage[]>;\n\n /** Create a Stripe checkout session for Z-coin deposit. */\n createDepositOrder(input: ZcoinCreateDepositOrderInput): Promise<ZcoinCreateDepositOrderOutput>;\n\n /** Check the status of a deposit checkout session. */\n getDepositStatus(input: ZcoinGetDepositStatusInput): Promise<ZcoinGetDepositStatusOutput>;\n\n /**\n * Atomic commercial transfer: Z-coin payment + ownership transfer in one transaction.\n * This is the primary API for Commerce and Exchange purchase flows.\n *\n * Idempotent via referenceId — duplicate calls return the same result.\n *\n * @throws {GoodZApiError} BAD_REQUEST — insufficient balance\n * @throws {GoodZApiError} CONFLICT — version conflict (retry)\n * @throws {GoodZApiError} FORBIDDEN — seller doesn't own instance\n */\n commercialTransfer(input: ZcoinCommercialTransferInput): Promise<ZcoinCommercialTransferOutput>;\n\n /**\n * Mint a new card instance and charge the buyer in one atomic transaction.\n * Used by Commerce for gacha and direct-from-creator purchases.\n *\n * Requires mint authorization (granted via inventory.grantMintAuth).\n * Idempotent via referenceId.\n *\n * @throws {GoodZApiError} FORBIDDEN — no mint authorization\n * @throws {GoodZApiError} BAD_REQUEST — insufficient balance\n */\n mintAndCharge(input: ZcoinMintAndChargeInput): Promise<ZcoinMintAndChargeOutput>;\n\n /**\n * Charge a user's Z-coin balance for an in-app purchase.\n * Used by apps that sell non-GoodZ digital goods/services.\n *\n * Idempotent via appOrderId.\n *\n * @throws {GoodZApiError} BAD_REQUEST — insufficient balance\n * @throws {GoodZApiError} CONFLICT — version conflict\n */\n chargeUser(input: ZcoinChargeUserInput): Promise<ZcoinChargeUserOutput>;\n\n /**\n * Create a direct purchase checkout session (fiat → Z-coin → transfer).\n * Transparent intermediation: user sees fiat price, Core handles conversion.\n */\n createDirectPurchaseOrder(input: ZcoinCreateDirectPurchaseOrderInput): Promise<ZcoinCreateDirectPurchaseOrderOutput>;\n}\n\nexport interface InventoryNamespace {\n /** Get a user's inventory (owned card instances). */\n getUserInventory(input: InventoryGetUserInventoryInput): Promise<any[]>;\n\n /** Check if a user owns at least one instance of a specific card. */\n confirmOwnership(input: InventoryConfirmOwnershipInput): Promise<InventoryConfirmOwnershipOutput>;\n\n /**\n * Mint new card instances. Requires franchise ownership or admin role.\n * For Commerce/Exchange, use zcoin.mintAndCharge instead (includes payment).\n */\n mint(input: InventoryMintInput): Promise<InventoryMintOutput>;\n\n /**\n * Transfer a specific card instance to another user.\n * For commercial transfers, use zcoin.commercialTransfer instead.\n *\n * @deprecated for reason=\"purchase\"|\"trade\" — use commercialTransfer\n */\n transfer(input: InventoryTransferInput): Promise<InventoryTransferOutput>;\n\n /**\n * Transfer card instances by cardId (transfers oldest instances).\n * For commercial transfers, use zcoin.commercialTransfer instead.\n *\n * @deprecated for reason=\"purchase\"|\"trade\" — use commercialTransfer\n */\n transferByCard(input: InventoryTransferByCardInput): Promise<InventoryTransferByCardOutput>;\n\n /**\n * Grant mint authorization to another user/app for a specific card.\n * Required before Commerce can call zcoin.mintAndCharge for that card.\n */\n grantMintAuth(input: InventoryGrantMintAuthInput): Promise<any>;\n\n /** Get transfer/ownership history for an instance, card, or user. */\n transferHistory(input: InventoryTransferHistoryInput): Promise<any[]>;\n}\n\nexport interface CollectibleNamespace {\n /** Get a card instance by its numeric ID. Returns full instance data with card chain. */\n getInstanceById(input: CollectibleGetInstanceByIdInput): Promise<any>;\n\n /** Get a card instance by its instance code (public-facing identifier). */\n getPublicInstance(input: CollectibleGetPublicInstanceInput): Promise<any>;\n\n /** Batch-fetch multiple card instances by their IDs (max 100). */\n getPublicInstancesBatch(input: CollectibleGetPublicInstancesBatchInput): Promise<any[]>;\n\n /** Get the card profile (metadata, rarity, series info). */\n getCardProfile(input: CollectibleGetCardProfileInput): Promise<any>;\n\n /** Get the shell (packaging) image URL for a card. */\n getShellImageUrl(input: CollectibleGetShellImageUrlInput): Promise<any>;\n}\n\nexport interface UserNamespace {\n /** Get a user's public profile by openId. */\n getPublicProfile(input: UserGetPublicProfileInput): Promise<UserPublicProfile>;\n\n /** Get a user's public profile by internal userId. */\n getPublicProfileById(input: UserGetPublicProfileByIdInput): Promise<UserPublicProfile>;\n}\n\nexport interface AuthNamespace {\n /** Get the authenticated user's profile. Returns null if not authenticated. */\n me(): Promise<AuthUser | null>;\n\n /** Get public info about an OAuth app by its client ID. */\n getOAuthAppInfo(input: AuthGetOAuthAppInfoInput): Promise<AuthOAuthAppInfo | null>;\n}\n\nexport interface IpNamespace {\n /** Get a franchise by ID or slug. */\n getFranchise(input: FranchiseGetInput): Promise<any>;\n\n /** Get a series by ID or slug. */\n getSeries(input: SeriesGetInput): Promise<any>;\n\n /** List all series in a franchise. */\n listSeriesByFranchise(input: SeriesListByFranchiseInput): Promise<any[]>;\n\n /** Get a card by ID. */\n getCard(input: CardGetInput): Promise<any>;\n\n /** List all cards in a series. */\n listCardsBySeries(input: CardListBySeriesInput): Promise<any[]>;\n}\n\n// ─── GoodZClient type ────────────────────────────────────────\n\nexport interface GoodZClient {\n readonly zcoin: ZcoinNamespace;\n readonly inventory: InventoryNamespace;\n readonly collectible: CollectibleNamespace;\n readonly user: UserNamespace;\n readonly auth: AuthNamespace;\n readonly ip: IpNamespace;\n\n /**\n * Make a raw tRPC query call. Use this for routes not yet covered\n * by the typed namespaces.\n */\n rawQuery<T = any>(path: string, input?: any): Promise<T>;\n\n /**\n * Make a raw tRPC mutation call. Use this for routes not yet covered\n * by the typed namespaces.\n */\n rawMutation<T = any>(path: string, input?: any): Promise<T>;\n}\n\n// ─── Client factory ──────────────────────────────────────────\n\n/**\n * Create a type-safe GoodZ.Core API client.\n *\n * @example Server-to-server with static token\n * ```ts\n * const goodz = createGoodZClient({\n * accessToken: process.env.CORE_ACCESS_TOKEN,\n * });\n * ```\n *\n * @example With dynamic token provider (auto-refresh)\n * ```ts\n * const goodz = createGoodZClient({\n * getAccessToken: async () => {\n * const token = await refreshTokenIfNeeded();\n * return token;\n * },\n * });\n * ```\n *\n * @example Acting on behalf of a user\n * ```ts\n * const userGoodz = createGoodZClient({\n * accessToken: userAccessToken,\n * });\n * const balance = await userGoodz.zcoin.getMyBalance();\n * ```\n */\nexport function createGoodZClient(config: GoodZClientConfig = {}): GoodZClient {\n const {\n coreUrl = \"https://goodzcore.manus.space\",\n accessToken,\n getAccessToken,\n headers: customHeaders,\n } = config;\n\n const transport: TransportConfig = {\n baseUrl: coreUrl.replace(/\\/$/, \"\"),\n getHeaders: async () => {\n const h: Record<string, string> = { ...customHeaders };\n const token = getAccessToken ? await getAccessToken() : accessToken;\n if (token) {\n h[\"Authorization\"] = `Bearer ${token}`;\n }\n return h;\n },\n };\n\n // Helper shortcuts\n const q = <I, O>(path: string) => (input?: I) => callQuery<I, O>(transport, path, input);\n const m = <I, O>(path: string) => (input?: I) => callMutation<I, O>(transport, path, input);\n\n return {\n // ── zcoin ──────────────────────────────────────────────\n zcoin: {\n getMyBalance: q<void, ZcoinGetMyBalanceOutput>(\"zcoin.getMyBalance\"),\n getMyHistory: q<ZcoinGetMyHistoryInput, any[]>(\"zcoin.getMyHistory\"),\n getDepositPackages: q<ZcoinGetDepositPackagesInput, ZcoinDepositPackage[]>(\"zcoin.getDepositPackages\"),\n createDepositOrder: m<ZcoinCreateDepositOrderInput, ZcoinCreateDepositOrderOutput>(\"zcoin.createDepositOrder\"),\n getDepositStatus: q<ZcoinGetDepositStatusInput, ZcoinGetDepositStatusOutput>(\"zcoin.getDepositStatus\"),\n commercialTransfer: m<ZcoinCommercialTransferInput, ZcoinCommercialTransferOutput>(\"zcoin.commercialTransfer\"),\n mintAndCharge: m<ZcoinMintAndChargeInput, ZcoinMintAndChargeOutput>(\"zcoin.mintAndCharge\"),\n chargeUser: m<ZcoinChargeUserInput, ZcoinChargeUserOutput>(\"zcoin.chargeUser\"),\n createDirectPurchaseOrder: m<ZcoinCreateDirectPurchaseOrderInput, ZcoinCreateDirectPurchaseOrderOutput>(\"zcoin.createDirectPurchaseOrder\"),\n },\n\n // ── inventory ──────────────────────────────────────────\n inventory: {\n getUserInventory: q<InventoryGetUserInventoryInput, any[]>(\"inventory.getUserInventory\"),\n confirmOwnership: q<InventoryConfirmOwnershipInput, InventoryConfirmOwnershipOutput>(\"inventory.confirmOwnership\"),\n mint: m<InventoryMintInput, InventoryMintOutput>(\"inventory.mint\"),\n transfer: m<InventoryTransferInput, InventoryTransferOutput>(\"inventory.transfer\"),\n transferByCard: m<InventoryTransferByCardInput, InventoryTransferByCardOutput>(\"inventory.transferByCard\"),\n grantMintAuth: m<InventoryGrantMintAuthInput, any>(\"inventory.grantMintAuth\"),\n transferHistory: q<InventoryTransferHistoryInput, any[]>(\"inventory.transferHistory\"),\n },\n\n // ── collectible ────────────────────────────────────────\n collectible: {\n getInstanceById: q<CollectibleGetInstanceByIdInput, any>(\"collectible.getInstanceById\"),\n getPublicInstance: q<CollectibleGetPublicInstanceInput, any>(\"collectible.getPublicInstance\"),\n getPublicInstancesBatch: q<CollectibleGetPublicInstancesBatchInput, any[]>(\"collectible.getPublicInstancesBatch\"),\n getCardProfile: q<CollectibleGetCardProfileInput, any>(\"collectible.getCardProfile\"),\n getShellImageUrl: q<CollectibleGetShellImageUrlInput, any>(\"collectible.getShellImageUrl\"),\n },\n\n // ── user ───────────────────────────────────────────────\n user: {\n getPublicProfile: q<UserGetPublicProfileInput, UserPublicProfile>(\"user.getPublicProfile\"),\n getPublicProfileById: q<UserGetPublicProfileByIdInput, UserPublicProfile>(\"user.getPublicProfileById\"),\n },\n\n // ── auth ───────────────────────────────────────────────\n auth: {\n me: q<void, AuthUser | null>(\"auth.me\"),\n getOAuthAppInfo: q<AuthGetOAuthAppInfoInput, AuthOAuthAppInfo | null>(\"auth.getOAuthAppInfo\"),\n },\n\n // ── ip (franchise/series/card) ─────────────────────────\n ip: {\n getFranchise: q<FranchiseGetInput, any>(\"franchise.get\"),\n getSeries: q<SeriesGetInput, any>(\"series.get\"),\n listSeriesByFranchise: q<SeriesListByFranchiseInput, any[]>(\"series.listByFranchise\"),\n getCard: q<CardGetInput, any>(\"card.get\"),\n listCardsBySeries: q<CardListBySeriesInput, any[]>(\"card.listBySeries\"),\n },\n\n // ── raw escape hatches ─────────────────────────────────\n rawQuery: <T = any>(path: string, input?: any) => callQuery<any, T>(transport, path, input),\n rawMutation: <T = any>(path: string, input?: any) => callMutation<any, T>(transport, path, input),\n };\n}\n\n/**\n * Alias for createGoodZClient — creates a client acting on behalf of a user.\n * Semantically identical, but makes the intent clearer in server-to-server code.\n */\nexport const createUserClient = createGoodZClient;\n"]}
|