@tinycloud/sdk-core 2.0.1 → 2.0.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/dist/index.cjs +3816 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +3867 -0
  4. package/dist/index.d.ts +3861 -21
  5. package/dist/index.js +3767 -61
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -5
  8. package/dist/TinyCloud.d.ts +0 -271
  9. package/dist/TinyCloud.d.ts.map +0 -1
  10. package/dist/TinyCloud.js +0 -458
  11. package/dist/TinyCloud.js.map +0 -1
  12. package/dist/TinyCloud.schema.d.ts +0 -173
  13. package/dist/TinyCloud.schema.d.ts.map +0 -1
  14. package/dist/TinyCloud.schema.js +0 -136
  15. package/dist/TinyCloud.schema.js.map +0 -1
  16. package/dist/TinyCloud.schema.test.d.ts +0 -5
  17. package/dist/TinyCloud.schema.test.d.ts.map +0 -1
  18. package/dist/TinyCloud.schema.test.js +0 -286
  19. package/dist/TinyCloud.schema.test.js.map +0 -1
  20. package/dist/authorization/CapabilityKeyRegistry.d.ts +0 -317
  21. package/dist/authorization/CapabilityKeyRegistry.d.ts.map +0 -1
  22. package/dist/authorization/CapabilityKeyRegistry.js +0 -509
  23. package/dist/authorization/CapabilityKeyRegistry.js.map +0 -1
  24. package/dist/authorization/authorization.schema.d.ts +0 -233
  25. package/dist/authorization/authorization.schema.d.ts.map +0 -1
  26. package/dist/authorization/authorization.schema.js +0 -220
  27. package/dist/authorization/authorization.schema.js.map +0 -1
  28. package/dist/authorization/authorization.schema.test.d.ts +0 -5
  29. package/dist/authorization/authorization.schema.test.d.ts.map +0 -1
  30. package/dist/authorization/authorization.schema.test.js +0 -618
  31. package/dist/authorization/authorization.schema.test.js.map +0 -1
  32. package/dist/authorization/index.d.ts +0 -38
  33. package/dist/authorization/index.d.ts.map +0 -1
  34. package/dist/authorization/index.js +0 -52
  35. package/dist/authorization/index.js.map +0 -1
  36. package/dist/authorization/spaceCreation.d.ts +0 -96
  37. package/dist/authorization/spaceCreation.d.ts.map +0 -1
  38. package/dist/authorization/spaceCreation.js +0 -35
  39. package/dist/authorization/spaceCreation.js.map +0 -1
  40. package/dist/authorization/spaceCreation.schema.d.ts +0 -67
  41. package/dist/authorization/spaceCreation.schema.d.ts.map +0 -1
  42. package/dist/authorization/spaceCreation.schema.js +0 -95
  43. package/dist/authorization/spaceCreation.schema.js.map +0 -1
  44. package/dist/authorization/spaceCreation.schema.test.d.ts +0 -5
  45. package/dist/authorization/spaceCreation.schema.test.d.ts.map +0 -1
  46. package/dist/authorization/spaceCreation.schema.test.js +0 -168
  47. package/dist/authorization/spaceCreation.schema.test.js.map +0 -1
  48. package/dist/authorization/strategies.d.ts +0 -134
  49. package/dist/authorization/strategies.d.ts.map +0 -1
  50. package/dist/authorization/strategies.js +0 -15
  51. package/dist/authorization/strategies.js.map +0 -1
  52. package/dist/authorization/strategies.schema.d.ts +0 -185
  53. package/dist/authorization/strategies.schema.d.ts.map +0 -1
  54. package/dist/authorization/strategies.schema.js +0 -147
  55. package/dist/authorization/strategies.schema.js.map +0 -1
  56. package/dist/authorization/strategies.schema.test.d.ts +0 -5
  57. package/dist/authorization/strategies.schema.test.d.ts.map +0 -1
  58. package/dist/authorization/strategies.schema.test.js +0 -253
  59. package/dist/authorization/strategies.schema.test.js.map +0 -1
  60. package/dist/client-types.d.ts +0 -128
  61. package/dist/client-types.d.ts.map +0 -1
  62. package/dist/client-types.js +0 -40
  63. package/dist/client-types.js.map +0 -1
  64. package/dist/delegations/DelegationManager.d.ts +0 -164
  65. package/dist/delegations/DelegationManager.d.ts.map +0 -1
  66. package/dist/delegations/DelegationManager.js +0 -428
  67. package/dist/delegations/DelegationManager.js.map +0 -1
  68. package/dist/delegations/SharingService.d.ts +0 -341
  69. package/dist/delegations/SharingService.d.ts.map +0 -1
  70. package/dist/delegations/SharingService.js +0 -722
  71. package/dist/delegations/SharingService.js.map +0 -1
  72. package/dist/delegations/SharingService.schema.d.ts +0 -409
  73. package/dist/delegations/SharingService.schema.d.ts.map +0 -1
  74. package/dist/delegations/SharingService.schema.js +0 -222
  75. package/dist/delegations/SharingService.schema.js.map +0 -1
  76. package/dist/delegations/index.d.ts +0 -38
  77. package/dist/delegations/index.d.ts.map +0 -1
  78. package/dist/delegations/index.js +0 -42
  79. package/dist/delegations/index.js.map +0 -1
  80. package/dist/delegations/types.d.ts +0 -13
  81. package/dist/delegations/types.d.ts.map +0 -1
  82. package/dist/delegations/types.js +0 -42
  83. package/dist/delegations/types.js.map +0 -1
  84. package/dist/delegations/types.schema.d.ts +0 -1773
  85. package/dist/delegations/types.schema.d.ts.map +0 -1
  86. package/dist/delegations/types.schema.js +0 -535
  87. package/dist/delegations/types.schema.js.map +0 -1
  88. package/dist/delegations/types.schema.test.d.ts +0 -5
  89. package/dist/delegations/types.schema.test.d.ts.map +0 -1
  90. package/dist/delegations/types.schema.test.js +0 -627
  91. package/dist/delegations/types.schema.test.js.map +0 -1
  92. package/dist/ens.d.ts +0 -17
  93. package/dist/ens.d.ts.map +0 -1
  94. package/dist/ens.js +0 -10
  95. package/dist/ens.js.map +0 -1
  96. package/dist/index.d.ts.map +0 -1
  97. package/dist/json-schema.d.ts +0 -327
  98. package/dist/json-schema.d.ts.map +0 -1
  99. package/dist/json-schema.js +0 -703
  100. package/dist/json-schema.js.map +0 -1
  101. package/dist/json-schema.test.d.ts +0 -7
  102. package/dist/json-schema.test.d.ts.map +0 -1
  103. package/dist/json-schema.test.js +0 -365
  104. package/dist/json-schema.test.js.map +0 -1
  105. package/dist/notifications.d.ts +0 -33
  106. package/dist/notifications.d.ts.map +0 -1
  107. package/dist/notifications.js +0 -15
  108. package/dist/notifications.js.map +0 -1
  109. package/dist/signer.d.ts +0 -28
  110. package/dist/signer.d.ts.map +0 -1
  111. package/dist/signer.js +0 -2
  112. package/dist/signer.js.map +0 -1
  113. package/dist/space.d.ts +0 -57
  114. package/dist/space.d.ts.map +0 -1
  115. package/dist/space.js +0 -87
  116. package/dist/space.js.map +0 -1
  117. package/dist/space.schema.d.ts +0 -65
  118. package/dist/space.schema.d.ts.map +0 -1
  119. package/dist/space.schema.js +0 -65
  120. package/dist/space.schema.js.map +0 -1
  121. package/dist/space.schema.test.d.ts +0 -5
  122. package/dist/space.schema.test.d.ts.map +0 -1
  123. package/dist/space.schema.test.js +0 -148
  124. package/dist/space.schema.test.js.map +0 -1
  125. package/dist/space.test.d.ts +0 -5
  126. package/dist/space.test.d.ts.map +0 -1
  127. package/dist/space.test.js +0 -87
  128. package/dist/space.test.js.map +0 -1
  129. package/dist/spaces/Space.d.ts +0 -175
  130. package/dist/spaces/Space.d.ts.map +0 -1
  131. package/dist/spaces/Space.js +0 -84
  132. package/dist/spaces/Space.js.map +0 -1
  133. package/dist/spaces/SpaceService.d.ts +0 -291
  134. package/dist/spaces/SpaceService.d.ts.map +0 -1
  135. package/dist/spaces/SpaceService.js +0 -740
  136. package/dist/spaces/SpaceService.js.map +0 -1
  137. package/dist/spaces/index.d.ts +0 -11
  138. package/dist/spaces/index.d.ts.map +0 -1
  139. package/dist/spaces/index.js +0 -22
  140. package/dist/spaces/index.js.map +0 -1
  141. package/dist/spaces/spaces.schema.d.ts +0 -421
  142. package/dist/spaces/spaces.schema.d.ts.map +0 -1
  143. package/dist/spaces/spaces.schema.js +0 -342
  144. package/dist/spaces/spaces.schema.js.map +0 -1
  145. package/dist/spaces/spaces.schema.test.d.ts +0 -5
  146. package/dist/spaces/spaces.schema.test.d.ts.map +0 -1
  147. package/dist/spaces/spaces.schema.test.js +0 -471
  148. package/dist/spaces/spaces.schema.test.js.map +0 -1
  149. package/dist/storage.d.ts +0 -47
  150. package/dist/storage.d.ts.map +0 -1
  151. package/dist/storage.js +0 -14
  152. package/dist/storage.js.map +0 -1
  153. package/dist/storage.schema.d.ts +0 -291
  154. package/dist/storage.schema.d.ts.map +0 -1
  155. package/dist/storage.schema.js +0 -189
  156. package/dist/storage.schema.js.map +0 -1
  157. package/dist/storage.schema.test.d.ts +0 -5
  158. package/dist/storage.schema.test.d.ts.map +0 -1
  159. package/dist/storage.schema.test.js +0 -346
  160. package/dist/storage.schema.test.js.map +0 -1
  161. package/dist/userAuthorization.d.ts +0 -117
  162. package/dist/userAuthorization.d.ts.map +0 -1
  163. package/dist/userAuthorization.js +0 -3
  164. package/dist/userAuthorization.js.map +0 -1
  165. package/dist/userAuthorization.schema.d.ts +0 -260
  166. package/dist/userAuthorization.schema.d.ts.map +0 -1
  167. package/dist/userAuthorization.schema.js +0 -169
  168. package/dist/userAuthorization.schema.js.map +0 -1
  169. package/dist/userAuthorization.schema.test.d.ts +0 -5
  170. package/dist/userAuthorization.schema.test.d.ts.map +0 -1
  171. package/dist/userAuthorization.schema.test.js +0 -356
  172. package/dist/userAuthorization.schema.test.js.map +0 -1
  173. package/dist/version.d.ts +0 -32
  174. package/dist/version.d.ts.map +0 -1
  175. package/dist/version.js +0 -59
  176. package/dist/version.js.map +0 -1
  177. package/dist/wasm-validation.d.ts +0 -291
  178. package/dist/wasm-validation.d.ts.map +0 -1
  179. package/dist/wasm-validation.js +0 -221
  180. package/dist/wasm-validation.js.map +0 -1
  181. package/dist/wasm-validation.test.d.ts +0 -5
  182. package/dist/wasm-validation.test.d.ts.map +0 -1
  183. package/dist/wasm-validation.test.js +0 -233
  184. package/dist/wasm-validation.test.js.map +0 -1
  185. package/dist/wasm.d.ts +0 -66
  186. package/dist/wasm.d.ts.map +0 -1
  187. package/dist/wasm.js +0 -10
  188. package/dist/wasm.js.map +0 -1
package/dist/TinyCloud.js DELETED
@@ -1,458 +0,0 @@
1
- import { ServiceContext, KVService, SQLService, DuckDbService, ok, err, serviceError, ErrorCodes, } from "@tinycloud/sdk-services";
2
- import { makePublicSpaceId } from "./spaces/SpaceService";
3
- /**
4
- * TinyCloud SDK - Unified entry point for web and node.
5
- *
6
- * This class provides the main SDK interface. Platform-specific behavior
7
- * is injected through the IUserAuthorization implementation:
8
- * - WebUserAuthorization for browser environments
9
- * - NodeUserAuthorization for Node.js environments
10
- *
11
- * @example
12
- * ```typescript
13
- * // Web usage
14
- * import { TinyCloud } from '@tinycloud/sdk-core';
15
- * import { WebUserAuthorization } from '@tinycloud/web-sdk';
16
- *
17
- * const auth = new WebUserAuthorization({ ... });
18
- * const tc = new TinyCloud(auth);
19
- * await tc.signIn();
20
- * const result = await tc.kv.put('key', 'value');
21
- *
22
- * // Node usage
23
- * import { TinyCloud } from '@tinycloud/sdk-core';
24
- * import { NodeUserAuthorization, PrivateKeySigner } from '@tinycloud/node-sdk';
25
- *
26
- * const signer = new PrivateKeySigner(process.env.PRIVATE_KEY);
27
- * const auth = new NodeUserAuthorization({
28
- * signStrategy: { type: 'auto-sign' },
29
- * signer,
30
- * domain: 'api.myapp.com'
31
- * });
32
- * const tc = new TinyCloud(auth);
33
- * await tc.signIn();
34
- * ```
35
- */
36
- export class TinyCloud {
37
- /**
38
- * Create a new TinyCloud SDK instance.
39
- *
40
- * @param userAuthorization - Platform-specific authorization implementation
41
- * @param config - Optional SDK configuration
42
- */
43
- constructor(userAuthorization, config) {
44
- /**
45
- * Registered extensions.
46
- */
47
- this.extensions = [];
48
- /**
49
- * Registered services by name.
50
- */
51
- this._services = new Map();
52
- /**
53
- * Whether services have been initialized.
54
- */
55
- this._servicesInitialized = false;
56
- this.userAuthorization = userAuthorization;
57
- this.config = config || {};
58
- }
59
- // === Service Management ===
60
- /**
61
- * Initialize services with platform dependencies.
62
- * Must be called before using services.
63
- *
64
- * @param invoke - Platform-specific invoke function from WASM binding
65
- * @param hosts - TinyCloud host URLs (optional, uses config.hosts)
66
- * @param fetchFn - Custom fetch implementation (optional)
67
- */
68
- initializeServices(invoke, hosts, fetchFn) {
69
- const effectiveInvoke = invoke ?? this.config.invoke;
70
- const effectiveHosts = hosts ?? this.config.hosts;
71
- if (!effectiveInvoke) {
72
- throw new Error("invoke function is required to initialize services. " +
73
- "Provide it via config.invoke or initializeServices().");
74
- }
75
- if (!effectiveHosts || effectiveHosts.length === 0) {
76
- throw new Error("hosts are required to initialize services. " +
77
- "Provide them via config.hosts or initializeServices().");
78
- }
79
- // Create service context
80
- this._serviceContext = new ServiceContext({
81
- invoke: effectiveInvoke,
82
- fetch: fetchFn ?? this.config.fetch ?? globalThis.fetch.bind(globalThis),
83
- hosts: effectiveHosts,
84
- retryPolicy: this.config.retryPolicy,
85
- });
86
- // Register default services (can be overridden via config.services)
87
- const serviceConstructors = {
88
- kv: KVService,
89
- sql: SQLService,
90
- duckdb: DuckDbService,
91
- ...this.config.services,
92
- };
93
- // Create and register services
94
- for (const [name, ServiceClass] of Object.entries(serviceConstructors)) {
95
- const serviceConfig = this.config.serviceConfigs?.[name] ?? {};
96
- const service = new ServiceClass(serviceConfig);
97
- service.initialize(this._serviceContext);
98
- this._serviceContext.registerService(name, service);
99
- this._services.set(name, service);
100
- }
101
- this._servicesInitialized = true;
102
- }
103
- /**
104
- * Get the service context.
105
- * @throws Error if services are not initialized
106
- */
107
- get serviceContext() {
108
- if (!this._serviceContext) {
109
- throw new Error("Services not initialized. Call initializeServices() first.");
110
- }
111
- return this._serviceContext;
112
- }
113
- /**
114
- * Get a registered service by name.
115
- *
116
- * @param name - Service name (e.g., 'kv')
117
- * @returns The service instance or undefined
118
- */
119
- getService(name) {
120
- return this._services.get(name);
121
- }
122
- /**
123
- * Get the KV service.
124
- * @throws Error if services are not initialized
125
- */
126
- get kv() {
127
- if (!this._servicesInitialized) {
128
- throw new Error("Services not initialized. Call initializeServices() first, " +
129
- "or use TinyCloudWeb/TinyCloudNode which handles this automatically.");
130
- }
131
- const service = this._services.get("kv");
132
- if (!service) {
133
- throw new Error("KV service is not registered.");
134
- }
135
- return service;
136
- }
137
- /**
138
- * Get the SQL service.
139
- * @throws Error if services are not initialized
140
- */
141
- get sql() {
142
- if (!this._servicesInitialized) {
143
- throw new Error("Services not initialized. Call initializeServices() first, " +
144
- "or use TinyCloudWeb/TinyCloudNode which handles this automatically.");
145
- }
146
- const service = this._services.get("sql");
147
- if (!service) {
148
- throw new Error("SQL service is not registered.");
149
- }
150
- return service;
151
- }
152
- /**
153
- * Get the DuckDB service.
154
- * @throws Error if services are not initialized
155
- */
156
- get duckdb() {
157
- if (!this._servicesInitialized) {
158
- throw new Error("Services not initialized. Call initializeServices() first, " +
159
- "or use TinyCloudWeb/TinyCloudNode which handles this automatically.");
160
- }
161
- const service = this._services.get("duckdb");
162
- if (!service) {
163
- throw new Error("DuckDB service is not registered.");
164
- }
165
- return service;
166
- }
167
- /**
168
- * Get the Data Vault service.
169
- * @throws Error if services are not initialized or vault service is not registered
170
- */
171
- get vault() {
172
- if (!this._servicesInitialized) {
173
- throw new Error("Services not initialized. Call initializeServices() first, " +
174
- "or use TinyCloudWeb/TinyCloudNode which handles this automatically.");
175
- }
176
- const service = this._services.get("vault");
177
- if (!service) {
178
- throw new Error("Vault service is not registered.");
179
- }
180
- return service;
181
- }
182
- /**
183
- * Notify services of session change.
184
- * Called internally after sign-in and sign-out.
185
- *
186
- * @param session - The new session, or null if signed out
187
- */
188
- notifyServicesOfSessionChange(session) {
189
- if (this._serviceContext) {
190
- this._serviceContext.setSession(session);
191
- }
192
- }
193
- /**
194
- * Abort all pending service operations.
195
- * Called internally before sign-out.
196
- */
197
- abortServiceOperations() {
198
- if (this._serviceContext) {
199
- this._serviceContext.abort();
200
- }
201
- }
202
- /**
203
- * Convert ClientSession to ServiceSession.
204
- * Returns null if session lacks required fields.
205
- */
206
- toServiceSession(clientSession) {
207
- if (!clientSession)
208
- return null;
209
- // TinyCloudSession contains the required fields
210
- const tcSession = clientSession.tinycloudSession;
211
- if (!tcSession)
212
- return null;
213
- return {
214
- delegationHeader: tcSession.delegationHeader,
215
- delegationCid: tcSession.delegationCid,
216
- spaceId: tcSession.spaceId,
217
- verificationMethod: tcSession.verificationMethod,
218
- jwk: tcSession.jwk,
219
- };
220
- }
221
- /**
222
- * Add an extension to the SDK.
223
- * Extensions can add capabilities and lifecycle hooks.
224
- */
225
- extend(extension) {
226
- this.extensions.push(extension);
227
- this.userAuthorization.extend(extension);
228
- }
229
- /**
230
- * Check if an extension is enabled.
231
- * @param namespace - The extension namespace to check
232
- */
233
- isExtensionEnabled(namespace) {
234
- return this.extensions.some((ext) => ext.namespace === namespace);
235
- }
236
- // === Authentication Methods (delegate to userAuthorization) ===
237
- /**
238
- * Get the current session, if signed in.
239
- */
240
- get session() {
241
- return this.userAuthorization.session;
242
- }
243
- /**
244
- * Check if the user is signed in.
245
- */
246
- get isSignedIn() {
247
- return !!this.userAuthorization.session;
248
- }
249
- /**
250
- * Sign in and create a new session.
251
- * Notifies services of the new session after successful sign-in.
252
- * @returns The new session
253
- */
254
- async signIn() {
255
- const session = await this.userAuthorization.signIn();
256
- // Notify services of the new session
257
- const serviceSession = this.toServiceSession(session);
258
- this.notifyServicesOfSessionChange(serviceSession);
259
- return session;
260
- }
261
- /**
262
- * Sign out and clear the current session.
263
- * Aborts pending service operations and notifies services.
264
- */
265
- async signOut() {
266
- // Abort all pending operations before sign-out
267
- this.abortServiceOperations();
268
- await this.userAuthorization.signOut();
269
- // Clear cached public KV service
270
- this._publicKV = undefined;
271
- // Clear session from services
272
- this.notifyServicesOfSessionChange(null);
273
- }
274
- /**
275
- * Get the current wallet address.
276
- */
277
- address() {
278
- return this.userAuthorization.address();
279
- }
280
- /**
281
- * Get the current chain ID.
282
- */
283
- chainId() {
284
- return this.userAuthorization.chainId();
285
- }
286
- /**
287
- * Sign a message with the connected wallet.
288
- * @param message - Message to sign
289
- */
290
- async signMessage(message) {
291
- return this.userAuthorization.signMessage(message);
292
- }
293
- /**
294
- * Construct the deterministic public space ID for a given address and chain ID.
295
- *
296
- * @param address - Ethereum address (0x-prefixed)
297
- * @param chainId - Chain ID (e.g., 1 for mainnet)
298
- * @returns The public space ID
299
- */
300
- static makePublicSpaceId(address, chainId) {
301
- return makePublicSpaceId(address, chainId);
302
- }
303
- /**
304
- * Ensure the user's public space exists.
305
- * Creates it via spaces.create('public') if it doesn't.
306
- * Called automatically by modules that need to publish data.
307
- *
308
- * Requires the user to be signed in and services to be initialized.
309
- */
310
- async ensurePublicSpace() {
311
- const address = this.address();
312
- const chainId = this.chainId();
313
- if (!address || !chainId) {
314
- return err(serviceError(ErrorCodes.AUTH_REQUIRED, "Must be signed in to ensure public space", "public-space"));
315
- }
316
- if (!this._serviceContext) {
317
- return err(serviceError(ErrorCodes.AUTH_REQUIRED, "Services not initialized. Call initializeServices() or signIn() first.", "public-space"));
318
- }
319
- const spaceId = makePublicSpaceId(address, chainId);
320
- // Check if it already exists via invoke
321
- try {
322
- const session = this._serviceContext.session;
323
- if (!session) {
324
- return err(serviceError(ErrorCodes.AUTH_REQUIRED, "No active session", "public-space"));
325
- }
326
- const headers = this._serviceContext.invoke(session, "space", spaceId, "tinycloud.space/info");
327
- const response = await this._serviceContext.fetch(`${this._serviceContext.hosts[0]}/invoke`, { method: "POST", headers, body: JSON.stringify({ spaceId }) });
328
- if (response.ok) {
329
- return ok(undefined);
330
- }
331
- if (response.status === 404) {
332
- // Space doesn't exist — create it
333
- const createHeaders = this._serviceContext.invoke(session, "space", "public", "tinycloud.space/create");
334
- const createResponse = await this._serviceContext.fetch(`${this._serviceContext.hosts[0]}/invoke`, {
335
- method: "POST",
336
- headers: createHeaders,
337
- body: JSON.stringify({ name: "public" }),
338
- });
339
- if (!createResponse.ok) {
340
- // 409 means it already exists — that's fine
341
- if (createResponse.status === 409) {
342
- return ok(undefined);
343
- }
344
- const errorText = await createResponse.text();
345
- return err(serviceError(ErrorCodes.NETWORK_ERROR, `Failed to create public space: ${createResponse.status} - ${errorText}`, "public-space"));
346
- }
347
- return ok(undefined);
348
- }
349
- // Other error from info check
350
- const errorText = await response.text();
351
- return err(serviceError(ErrorCodes.NETWORK_ERROR, `Failed to check public space: ${response.status} - ${errorText}`, "public-space"));
352
- }
353
- catch (error) {
354
- return err(serviceError(ErrorCodes.NETWORK_ERROR, `Network error ensuring public space: ${String(error)}`, "public-space", { cause: error instanceof Error ? error : undefined }));
355
- }
356
- }
357
- /**
358
- * Get a KVService scoped to the user's own public space.
359
- * Writes require authentication (owner/delegate).
360
- *
361
- * @throws Error if not signed in or services not initialized
362
- */
363
- get publicKV() {
364
- if (!this._servicesInitialized || !this._serviceContext) {
365
- throw new Error("Services not initialized. Call initializeServices() first, " +
366
- "or use TinyCloudWeb/TinyCloudNode which handles this automatically.");
367
- }
368
- const address = this.address();
369
- const chainId = this.chainId();
370
- if (!address || !chainId) {
371
- throw new Error("Must be signed in to access publicKV.");
372
- }
373
- // Return cached instance if available
374
- if (this._publicKV) {
375
- return this._publicKV;
376
- }
377
- const publicSpaceId = makePublicSpaceId(address, chainId);
378
- const session = this._serviceContext.session;
379
- if (!session) {
380
- throw new Error("No active session. Sign in first.");
381
- }
382
- // Create a KV service with a context that targets the public space
383
- const publicKV = new KVService({ prefix: "" });
384
- const publicContext = new ServiceContext({
385
- invoke: this._serviceContext.invoke,
386
- fetch: this._serviceContext.fetch,
387
- hosts: this._serviceContext.hosts,
388
- retryPolicy: this.config.retryPolicy,
389
- });
390
- publicContext.setSession({
391
- ...session,
392
- spaceId: publicSpaceId,
393
- });
394
- publicKV.initialize(publicContext);
395
- this._publicKV = publicKV;
396
- return this._publicKV;
397
- }
398
- /**
399
- * Read from any user's public space (unauthenticated).
400
- * Uses the public REST endpoint — no session needed.
401
- *
402
- * @param host - TinyCloud server URL (e.g., "https://node.tinycloud.xyz")
403
- * @param spaceId - Full public space ID
404
- * @param key - Key to read
405
- * @param fetchFn - Optional custom fetch function
406
- * @returns The data at the key
407
- */
408
- static async readPublicSpace(host, spaceId, key, fetchFn) {
409
- const doFetch = fetchFn ?? globalThis.fetch.bind(globalThis);
410
- const encodedKey = key.split('/').map(encodeURIComponent).join('/');
411
- const url = `${host}/public/${encodeURIComponent(spaceId)}/kv/${encodedKey}`;
412
- try {
413
- const response = await doFetch(url, { method: "GET" });
414
- if (!response.ok) {
415
- if (response.status === 404) {
416
- return err(serviceError(ErrorCodes.NOT_FOUND, `Key not found: ${key} in space ${spaceId}`, "public-space"));
417
- }
418
- const errorText = await response.text();
419
- return err(serviceError(ErrorCodes.NETWORK_ERROR, `Failed to read public space: ${response.status} - ${errorText}`, "public-space", { meta: { status: response.status } }));
420
- }
421
- const contentType = response.headers.get("content-type");
422
- let data;
423
- if (contentType?.includes("application/json")) {
424
- data = (await response.json());
425
- }
426
- else {
427
- const text = await response.text();
428
- // Try parsing as JSON, fall back to raw text
429
- try {
430
- data = JSON.parse(text);
431
- }
432
- catch {
433
- data = text;
434
- }
435
- }
436
- return ok(data);
437
- }
438
- catch (error) {
439
- return err(serviceError(ErrorCodes.NETWORK_ERROR, `Network error reading public space: ${String(error)}`, "public-space", { cause: error instanceof Error ? error : undefined }));
440
- }
441
- }
442
- /**
443
- * Read from any user's public space by address (unauthenticated).
444
- * Convenience method that constructs the space ID from address and chain ID.
445
- *
446
- * @param host - TinyCloud server URL
447
- * @param address - Ethereum address (0x-prefixed)
448
- * @param chainId - Chain ID (e.g., 1 for mainnet)
449
- * @param key - Key to read
450
- * @param fetchFn - Optional custom fetch function
451
- * @returns The data at the key
452
- */
453
- static async readPublicKey(host, address, chainId, key, fetchFn) {
454
- const spaceId = makePublicSpaceId(address, chainId);
455
- return TinyCloud.readPublicSpace(host, spaceId, key, fetchFn);
456
- }
457
- }
458
- //# sourceMappingURL=TinyCloud.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TinyCloud.js","sourceRoot":"","sources":["../src/TinyCloud.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,cAAc,EAId,SAAS,EAET,UAAU,EAEV,aAAa,EASb,EAAE,EACF,GAAG,EACH,YAAY,EAEZ,UAAU,GACX,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AA8D1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,OAAO,SAAS;IAkCpB;;;;;OAKG;IACH,YAAY,iBAA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C9C,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAM,CAAC;YACtC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnC,6CAA6C;gBAC7C,IAAI,CAAC;oBACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;gBAC/B,CAAC;gBAAC,MAAM,CAAC;oBACP,IAAI,GAAG,IAAoB,CAAC;gBAC9B,CAAC;YACH,CAAC;YAED,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,GAAG,CACR,YAAY,CACV,UAAU,CAAC,aAAa,EACxB,uCAAuC,MAAM,CAAC,KAAK,CAAC,EAAE,EACtD,cAAc,EACd,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EAAE,CACtD,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,KAAK,CAAC,aAAa,CACxB,IAAY,EACZ,OAAe,EACf,OAAe,EACf,GAAW,EACX,OAAuB;QAEvB,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,OAAO,SAAS,CAAC,eAAe,CAAI,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC;CAEF"}
@@ -1,173 +0,0 @@
1
- /**
2
- * Zod schemas for TinyCloud SDK configuration types.
3
- *
4
- * These schemas provide runtime validation for TinyCloud configuration.
5
- * Types are derived from schemas using z.infer<>.
6
- *
7
- * @packageDocumentation
8
- */
9
- import { z } from "zod";
10
- import type { Result } from "./delegations/types.schema";
11
- import type { ValidationError } from "./storage.schema";
12
- import type { InvokeFunction, FetchFunction, ServiceConstructor } from "@tinycloud/sdk-services";
13
- /**
14
- * Schema for backoff strategy.
15
- */
16
- export declare const BackoffStrategySchema: z.ZodEnum<["none", "linear", "exponential"]>;
17
- export type BackoffStrategy = z.infer<typeof BackoffStrategySchema>;
18
- /**
19
- * Schema for retry policy configuration.
20
- */
21
- export declare const RetryPolicySchema: z.ZodObject<{
22
- /** Maximum number of attempts (including initial) */
23
- maxAttempts: z.ZodNumber;
24
- /** Backoff strategy between retries */
25
- backoff: z.ZodEnum<["none", "linear", "exponential"]>;
26
- /** Base delay in milliseconds for backoff calculation */
27
- baseDelayMs: z.ZodNumber;
28
- /** Maximum delay in milliseconds between retries */
29
- maxDelayMs: z.ZodNumber;
30
- /** Error codes that should trigger a retry */
31
- retryableErrors: z.ZodArray<z.ZodString, "many">;
32
- }, "strip", z.ZodTypeAny, {
33
- maxAttempts: number;
34
- backoff: "none" | "linear" | "exponential";
35
- baseDelayMs: number;
36
- maxDelayMs: number;
37
- retryableErrors: string[];
38
- }, {
39
- maxAttempts: number;
40
- backoff: "none" | "linear" | "exponential";
41
- baseDelayMs: number;
42
- maxDelayMs: number;
43
- retryableErrors: string[];
44
- }>;
45
- export type RetryPolicy = z.infer<typeof RetryPolicySchema>;
46
- /**
47
- * Schema for partial retry policy (all fields optional).
48
- */
49
- export declare const PartialRetryPolicySchema: z.ZodObject<{
50
- maxAttempts: z.ZodOptional<z.ZodNumber>;
51
- backoff: z.ZodOptional<z.ZodEnum<["none", "linear", "exponential"]>>;
52
- baseDelayMs: z.ZodOptional<z.ZodNumber>;
53
- maxDelayMs: z.ZodOptional<z.ZodNumber>;
54
- retryableErrors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
55
- }, "strip", z.ZodTypeAny, {
56
- maxAttempts?: number | undefined;
57
- backoff?: "none" | "linear" | "exponential" | undefined;
58
- baseDelayMs?: number | undefined;
59
- maxDelayMs?: number | undefined;
60
- retryableErrors?: string[] | undefined;
61
- }, {
62
- maxAttempts?: number | undefined;
63
- backoff?: "none" | "linear" | "exponential" | undefined;
64
- baseDelayMs?: number | undefined;
65
- maxDelayMs?: number | undefined;
66
- retryableErrors?: string[] | undefined;
67
- }>;
68
- export type PartialRetryPolicy = z.infer<typeof PartialRetryPolicySchema>;
69
- /**
70
- * Schema for TinyCloud SDK configuration.
71
- */
72
- export declare const TinyCloudConfigSchema: z.ZodObject<{
73
- /** Whether to automatically resolve ENS names */
74
- resolveEns: z.ZodOptional<z.ZodBoolean>;
75
- /**
76
- * TinyCloud host URLs.
77
- * Required when using services.
78
- */
79
- hosts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
80
- /**
81
- * Platform-specific invoke function from WASM binding.
82
- * Required when using services.
83
- */
84
- invoke: z.ZodOptional<z.ZodEffects<z.ZodUnknown, InvokeFunction, unknown>>;
85
- /**
86
- * Custom fetch implementation.
87
- * Defaults to globalThis.fetch.
88
- */
89
- fetch: z.ZodOptional<z.ZodEffects<z.ZodUnknown, FetchFunction, unknown>>;
90
- /**
91
- * Service constructors to register.
92
- * Built-in services (like KVService) are registered by default unless overridden.
93
- */
94
- services: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodUnknown, ServiceConstructor<Record<string, unknown>, import("@tinycloud/sdk-services").IService>, unknown>>>;
95
- /**
96
- * Per-service configuration.
97
- */
98
- serviceConfigs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
99
- /**
100
- * Retry policy for service operations.
101
- */
102
- retryPolicy: z.ZodOptional<z.ZodObject<{
103
- maxAttempts: z.ZodOptional<z.ZodNumber>;
104
- backoff: z.ZodOptional<z.ZodEnum<["none", "linear", "exponential"]>>;
105
- baseDelayMs: z.ZodOptional<z.ZodNumber>;
106
- maxDelayMs: z.ZodOptional<z.ZodNumber>;
107
- retryableErrors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
108
- }, "strip", z.ZodTypeAny, {
109
- maxAttempts?: number | undefined;
110
- backoff?: "none" | "linear" | "exponential" | undefined;
111
- baseDelayMs?: number | undefined;
112
- maxDelayMs?: number | undefined;
113
- retryableErrors?: string[] | undefined;
114
- }, {
115
- maxAttempts?: number | undefined;
116
- backoff?: "none" | "linear" | "exponential" | undefined;
117
- baseDelayMs?: number | undefined;
118
- maxDelayMs?: number | undefined;
119
- retryableErrors?: string[] | undefined;
120
- }>>;
121
- }, "strip", z.ZodTypeAny, {
122
- hosts?: string[] | undefined;
123
- invoke?: InvokeFunction | undefined;
124
- fetch?: FetchFunction | undefined;
125
- resolveEns?: boolean | undefined;
126
- services?: Record<string, ServiceConstructor<Record<string, unknown>, import("@tinycloud/sdk-services").IService>> | undefined;
127
- serviceConfigs?: Record<string, Record<string, unknown>> | undefined;
128
- retryPolicy?: {
129
- maxAttempts?: number | undefined;
130
- backoff?: "none" | "linear" | "exponential" | undefined;
131
- baseDelayMs?: number | undefined;
132
- maxDelayMs?: number | undefined;
133
- retryableErrors?: string[] | undefined;
134
- } | undefined;
135
- }, {
136
- hosts?: string[] | undefined;
137
- invoke?: unknown;
138
- fetch?: unknown;
139
- resolveEns?: boolean | undefined;
140
- services?: Record<string, unknown> | undefined;
141
- serviceConfigs?: Record<string, Record<string, unknown>> | undefined;
142
- retryPolicy?: {
143
- maxAttempts?: number | undefined;
144
- backoff?: "none" | "linear" | "exponential" | undefined;
145
- baseDelayMs?: number | undefined;
146
- maxDelayMs?: number | undefined;
147
- retryableErrors?: string[] | undefined;
148
- } | undefined;
149
- }>;
150
- export type TinyCloudConfig = z.infer<typeof TinyCloudConfigSchema>;
151
- /**
152
- * Validates a TinyCloudConfig object and returns a Result.
153
- *
154
- * @param data - Unknown data to validate
155
- * @returns Result with validated data or validation error
156
- *
157
- * @example
158
- * ```typescript
159
- * const result = validateTinyCloudConfig(rawConfig);
160
- * if (result.ok) {
161
- * // result.data is typed as TinyCloudConfig
162
- * console.log(result.data.hosts);
163
- * } else {
164
- * console.error(result.error.message);
165
- * }
166
- * ```
167
- */
168
- export declare function validateTinyCloudConfig(data: unknown): Result<TinyCloudConfig, ValidationError>;
169
- /**
170
- * Validates a RetryPolicy object and returns a Result.
171
- */
172
- export declare function validateRetryPolicy(data: unknown): Result<RetryPolicy, ValidationError>;
173
- //# sourceMappingURL=TinyCloud.schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TinyCloud.schema.d.ts","sourceRoot":"","sources":["../src/TinyCloud.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAMjC;;GAEG;AACH,eAAO,MAAM,qBAAqB,8CAA4C,CAAC;AAC/E,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,iBAAiB;IAC5B,qDAAqD;;IAErD,uCAAuC;;IAEvC,yDAAyD;;IAEzD,oDAAoD;;IAEpD,8CAA8C;;;;;;;;;;;;;;EAE9C,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;EAA8B,CAAC;AACpE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAM1E;;GAEG;AACH,eAAO,MAAM,qBAAqB;IAChC,iDAAiD;;IAKjD;;;OAGG;;IAGH;;;OAGG;;IAUH;;;OAGG;;IAUH;;;OAGG;;IAWH;;OAEG;;IAGH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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