@wishknish/knishio-client-ts 0.9.4 → 0.9.6
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/dist/index.cjs +355 -253
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -28
- package/dist/index.d.ts +32 -28
- package/dist/index.iife.js +21183 -5371
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +355 -253
- package/dist/index.js.map +1 -1
- package/package.json +20 -23
- package/src/KnishIOClient.ts +37 -8
- package/src/core/AtomMeta.ts +12 -4
- package/src/core/Molecule.ts +61 -0
- package/src/core/Wallet.ts +7 -5
- package/src/index.ts +4 -1
- package/src/instance/rules/Callback.ts +1 -1
- package/src/libraries/GraphQLClient.ts +21 -7
- package/src/libraries/UrqlClientWrapper.ts +8 -3
- package/src/libraries/crypto.ts +4 -6
- package/src/mutation/MutationReplenishToken.ts +28 -0
- package/src/schemas/index.ts +31 -16
- package/src/types/assertions.ts +2 -2
- package/src/validation/ValidationService.ts +1 -3
- package/src/validation/schemas.ts +40 -16
|
@@ -55,6 +55,20 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
|
55
55
|
|
|
56
56
|
import { z } from 'zod'
|
|
57
57
|
|
|
58
|
+
// Zod 3's `.url()` returned the input UNCHANGED; Zod 4's `z.url()` returns the normalized
|
|
59
|
+
// `URL.href` (strips default ports, lowercases the host) with no opt-out. `KnishIOClientConfig
|
|
60
|
+
// .uri` and `KNISHIO_NODE_URI` both flow into the endpoint the client actually calls, so a
|
|
61
|
+
// refinement is used: it validates exactly as v3 did without rewriting the value.
|
|
62
|
+
const urlString = (message = 'Invalid URL') =>
|
|
63
|
+
z.string().refine((value) => {
|
|
64
|
+
try {
|
|
65
|
+
new URL(value)
|
|
66
|
+
return true
|
|
67
|
+
} catch {
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
}, message)
|
|
71
|
+
|
|
58
72
|
// =============================================================================
|
|
59
73
|
// CORE TYPE SCHEMAS (2025 TYPESCRIPT PATTERN)
|
|
60
74
|
// =============================================================================
|
|
@@ -92,7 +106,12 @@ export const TokenSlugSchema = createBrandedSchema('TokenSlug',
|
|
|
92
106
|
)
|
|
93
107
|
|
|
94
108
|
export const BatchIdSchema = createBrandedSchema('BatchId',
|
|
95
|
-
|
|
109
|
+
// 64 hex characters. generateBatchId (src/libraries/crypto.ts) returns either
|
|
110
|
+
// shake256(molecularHash + index, 256) — 256 bits, 64 hex chars — or randomString(64) over the
|
|
111
|
+
// alphabet 'abcdef0123456789'. A UUID shape matches nothing this SDK can produce, so the
|
|
112
|
+
// previous 8-4-4-4-12 regex rejected every real batch ID. Agrees with isBatchId in
|
|
113
|
+
// src/types/guards.ts.
|
|
114
|
+
z.string().regex(/^[0-9a-fA-F]{64}$/, 'Invalid batch ID format')
|
|
96
115
|
)
|
|
97
116
|
|
|
98
117
|
export const CellSlugSchema = createBrandedSchema('CellSlug',
|
|
@@ -152,7 +171,7 @@ export const AtomMetaDataSchema = z.object({
|
|
|
152
171
|
export const NormalizedMetaSchema = z.object({
|
|
153
172
|
key: z.string(),
|
|
154
173
|
value: z.union([z.string(), z.number(), z.boolean(), z.null()])
|
|
155
|
-
}).
|
|
174
|
+
}).loose() // Allow additional properties
|
|
156
175
|
|
|
157
176
|
// =============================================================================
|
|
158
177
|
// CORE ENTITY SCHEMAS
|
|
@@ -199,8 +218,8 @@ export const MoleculeParamsSchema = z.object({
|
|
|
199
218
|
|
|
200
219
|
export const KnishIOClientConfigSchema = z.object({
|
|
201
220
|
uri: z.union([
|
|
202
|
-
|
|
203
|
-
z.array(
|
|
221
|
+
urlString('Invalid URI format'),
|
|
222
|
+
z.array(urlString('Invalid URI format')).min(1)
|
|
204
223
|
]).optional(),
|
|
205
224
|
cellSlug: z.union([CellSlugSchema, z.string()]).optional(),
|
|
206
225
|
client: z.unknown().optional(),
|
|
@@ -213,13 +232,18 @@ export const KnishIOClientConfigSchema = z.object({
|
|
|
213
232
|
defaultRequestPolicy: z.enum(['cache-first', 'cache-only', 'network-only', 'cache-and-network']).nullable().optional()
|
|
214
233
|
}).strict()
|
|
215
234
|
|
|
216
|
-
// Environment configuration with validation
|
|
235
|
+
// Environment configuration with validation.
|
|
236
|
+
// NOTE: no `.default()` here. The outer `.partial()` wraps every field in `optional()`, so
|
|
237
|
+
// under Zod 3 these defaults never fired (an all-unset env parsed to `{}`). Under Zod 4 they
|
|
238
|
+
// DO fire, and because v4's `.default()` no longer parses the default value they would emit
|
|
239
|
+
// the raw strings 'false' and '4' where the consumer (ValidationService -> KnishIOClientConfig)
|
|
240
|
+
// requires a boolean and a number. Dropping them keeps v3's exact observable output.
|
|
217
241
|
export const EnvironmentConfigSchema = z.object({
|
|
218
|
-
NODE_ENV: z.enum(['development', 'production', 'test']).
|
|
219
|
-
KNISHIO_NODE_URI:
|
|
242
|
+
NODE_ENV: z.enum(['development', 'production', 'test']).optional(),
|
|
243
|
+
KNISHIO_NODE_URI: urlString().optional(),
|
|
220
244
|
KNISHIO_CELL_SLUG: z.string().optional(),
|
|
221
|
-
KNISHIO_LOGGING: z.string().transform(val => val === 'true').
|
|
222
|
-
KNISHIO_SERVER_SDK_VERSION: z.string().transform(val => parseInt(val, 10)).
|
|
245
|
+
KNISHIO_LOGGING: z.string().transform(val => val === 'true').optional(),
|
|
246
|
+
KNISHIO_SERVER_SDK_VERSION: z.string().transform(val => parseInt(val, 10)).optional()
|
|
223
247
|
}).partial()
|
|
224
248
|
|
|
225
249
|
// =============================================================================
|
|
@@ -233,7 +257,7 @@ export const TransferParamsSchema = z.object({
|
|
|
233
257
|
'Amount must be positive'
|
|
234
258
|
),
|
|
235
259
|
token: z.union([TokenSlugSchema, z.string()]).optional(),
|
|
236
|
-
callbackUrl:
|
|
260
|
+
callbackUrl: urlString().optional(),
|
|
237
261
|
metaType: z.string().optional(),
|
|
238
262
|
metaId: z.string().optional(),
|
|
239
263
|
meta: MetaDataSchema.optional()
|
|
@@ -282,7 +306,7 @@ export const MetaQueryParamsSchema = z.object({
|
|
|
282
306
|
value: z.string().optional(),
|
|
283
307
|
latest: z.boolean().optional(),
|
|
284
308
|
filter: z.string().optional(),
|
|
285
|
-
queryArgs: z.record(z.unknown()).optional(),
|
|
309
|
+
queryArgs: z.record(z.string(), z.unknown()).optional(),
|
|
286
310
|
count: z.number().int().min(0).optional(),
|
|
287
311
|
countBy: z.string().optional(),
|
|
288
312
|
cellSlug: z.union([CellSlugSchema, z.string()]).optional()
|
|
@@ -308,7 +332,7 @@ export const AuthTokenParamsSchema = z.object({
|
|
|
308
332
|
export const AuthParamsSchema = z.object({
|
|
309
333
|
cellSlug: z.union([CellSlugSchema, z.string()]).optional(),
|
|
310
334
|
encrypt: z.boolean().optional(),
|
|
311
|
-
callback: z.
|
|
335
|
+
callback: z.custom<(...args: unknown[]) => unknown>((value) => typeof value === 'function').optional()
|
|
312
336
|
}).strict()
|
|
313
337
|
|
|
314
338
|
export const GuestAuthParamsSchema = z.object({
|
|
@@ -321,7 +345,7 @@ export const GuestAuthParamsSchema = z.object({
|
|
|
321
345
|
|
|
322
346
|
export const GraphQLRequestSchema = z.object({
|
|
323
347
|
query: z.string().min(1),
|
|
324
|
-
variables: z.record(z.unknown()).optional(),
|
|
348
|
+
variables: z.record(z.string(), z.unknown()).optional(),
|
|
325
349
|
operationName: z.string().optional()
|
|
326
350
|
}).strict()
|
|
327
351
|
|
|
@@ -332,13 +356,13 @@ export const GraphQLErrorSchema = z.object({
|
|
|
332
356
|
column: z.number().int()
|
|
333
357
|
})).optional(),
|
|
334
358
|
path: z.array(z.union([z.string(), z.number()])).optional(),
|
|
335
|
-
extensions: z.record(z.unknown()).optional()
|
|
359
|
+
extensions: z.record(z.string(), z.unknown()).optional()
|
|
336
360
|
}).strict()
|
|
337
361
|
|
|
338
362
|
export const GraphQLResponseSchema = z.object({
|
|
339
363
|
data: z.unknown().optional(),
|
|
340
364
|
errors: z.array(GraphQLErrorSchema).optional(),
|
|
341
|
-
extensions: z.record(z.unknown()).optional()
|
|
365
|
+
extensions: z.record(z.string(), z.unknown()).optional()
|
|
342
366
|
}).strict()
|
|
343
367
|
|
|
344
368
|
// =============================================================================
|
|
@@ -357,7 +381,7 @@ export function safeParse<T>(schema: z.ZodType<T>, data: unknown) {
|
|
|
357
381
|
error: {
|
|
358
382
|
issues: result.error.issues,
|
|
359
383
|
message: result.error.message,
|
|
360
|
-
formatted: result.error
|
|
384
|
+
formatted: z.treeifyError(result.error)
|
|
361
385
|
}
|
|
362
386
|
}
|
|
363
387
|
}
|