@tinycloudlabs/sdk-core 1.0.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.
- package/LICENSE.md +320 -0
- package/dist/TinyCloud.d.ts +206 -0
- package/dist/TinyCloud.d.ts.map +1 -0
- package/dist/TinyCloud.js +244 -0
- package/dist/TinyCloud.js.map +1 -0
- package/dist/TinyCloud.schema.d.ts +173 -0
- package/dist/TinyCloud.schema.d.ts.map +1 -0
- package/dist/TinyCloud.schema.js +136 -0
- package/dist/TinyCloud.schema.js.map +1 -0
- package/dist/TinyCloud.schema.test.d.ts +5 -0
- package/dist/TinyCloud.schema.test.d.ts.map +1 -0
- package/dist/TinyCloud.schema.test.js +286 -0
- package/dist/TinyCloud.schema.test.js.map +1 -0
- package/dist/authorization/CapabilityKeyRegistry.d.ts +317 -0
- package/dist/authorization/CapabilityKeyRegistry.d.ts.map +1 -0
- package/dist/authorization/CapabilityKeyRegistry.js +509 -0
- package/dist/authorization/CapabilityKeyRegistry.js.map +1 -0
- package/dist/authorization/authorization.schema.d.ts +233 -0
- package/dist/authorization/authorization.schema.d.ts.map +1 -0
- package/dist/authorization/authorization.schema.js +220 -0
- package/dist/authorization/authorization.schema.js.map +1 -0
- package/dist/authorization/authorization.schema.test.d.ts +5 -0
- package/dist/authorization/authorization.schema.test.d.ts.map +1 -0
- package/dist/authorization/authorization.schema.test.js +618 -0
- package/dist/authorization/authorization.schema.test.js.map +1 -0
- package/dist/authorization/index.d.ts +38 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +52 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/authorization/spaceCreation.d.ts +96 -0
- package/dist/authorization/spaceCreation.d.ts.map +1 -0
- package/dist/authorization/spaceCreation.js +35 -0
- package/dist/authorization/spaceCreation.js.map +1 -0
- package/dist/authorization/spaceCreation.schema.d.ts +67 -0
- package/dist/authorization/spaceCreation.schema.d.ts.map +1 -0
- package/dist/authorization/spaceCreation.schema.js +95 -0
- package/dist/authorization/spaceCreation.schema.js.map +1 -0
- package/dist/authorization/spaceCreation.schema.test.d.ts +5 -0
- package/dist/authorization/spaceCreation.schema.test.d.ts.map +1 -0
- package/dist/authorization/spaceCreation.schema.test.js +168 -0
- package/dist/authorization/spaceCreation.schema.test.js.map +1 -0
- package/dist/authorization/strategies.d.ts +134 -0
- package/dist/authorization/strategies.d.ts.map +1 -0
- package/dist/authorization/strategies.js +15 -0
- package/dist/authorization/strategies.js.map +1 -0
- package/dist/authorization/strategies.schema.d.ts +185 -0
- package/dist/authorization/strategies.schema.d.ts.map +1 -0
- package/dist/authorization/strategies.schema.js +147 -0
- package/dist/authorization/strategies.schema.js.map +1 -0
- package/dist/authorization/strategies.schema.test.d.ts +5 -0
- package/dist/authorization/strategies.schema.test.d.ts.map +1 -0
- package/dist/authorization/strategies.schema.test.js +253 -0
- package/dist/authorization/strategies.schema.test.js.map +1 -0
- package/dist/delegations/DelegationManager.d.ts +164 -0
- package/dist/delegations/DelegationManager.d.ts.map +1 -0
- package/dist/delegations/DelegationManager.js +428 -0
- package/dist/delegations/DelegationManager.js.map +1 -0
- package/dist/delegations/SharingService.d.ts +279 -0
- package/dist/delegations/SharingService.d.ts.map +1 -0
- package/dist/delegations/SharingService.js +558 -0
- package/dist/delegations/SharingService.js.map +1 -0
- package/dist/delegations/SharingService.schema.d.ts +401 -0
- package/dist/delegations/SharingService.schema.d.ts.map +1 -0
- package/dist/delegations/SharingService.schema.js +211 -0
- package/dist/delegations/SharingService.schema.js.map +1 -0
- package/dist/delegations/index.d.ts +38 -0
- package/dist/delegations/index.d.ts.map +1 -0
- package/dist/delegations/index.js +42 -0
- package/dist/delegations/index.js.map +1 -0
- package/dist/delegations/types.d.ts +13 -0
- package/dist/delegations/types.d.ts.map +1 -0
- package/dist/delegations/types.js +42 -0
- package/dist/delegations/types.js.map +1 -0
- package/dist/delegations/types.schema.d.ts +1641 -0
- package/dist/delegations/types.schema.d.ts.map +1 -0
- package/dist/delegations/types.schema.js +535 -0
- package/dist/delegations/types.schema.js.map +1 -0
- package/dist/delegations/types.schema.test.d.ts +5 -0
- package/dist/delegations/types.schema.test.d.ts.map +1 -0
- package/dist/delegations/types.schema.test.js +627 -0
- package/dist/delegations/types.schema.test.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/json-schema.d.ts +327 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +703 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/json-schema.test.d.ts +7 -0
- package/dist/json-schema.test.d.ts.map +1 -0
- package/dist/json-schema.test.js +365 -0
- package/dist/json-schema.test.js.map +1 -0
- package/dist/signer.d.ts +28 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +2 -0
- package/dist/signer.js.map +1 -0
- package/dist/space.d.ts +53 -0
- package/dist/space.d.ts.map +1 -0
- package/dist/space.js +67 -0
- package/dist/space.js.map +1 -0
- package/dist/space.schema.d.ts +65 -0
- package/dist/space.schema.d.ts.map +1 -0
- package/dist/space.schema.js +65 -0
- package/dist/space.schema.js.map +1 -0
- package/dist/space.schema.test.d.ts +5 -0
- package/dist/space.schema.test.d.ts.map +1 -0
- package/dist/space.schema.test.js +148 -0
- package/dist/space.schema.test.js.map +1 -0
- package/dist/spaces/Space.d.ts +175 -0
- package/dist/spaces/Space.d.ts.map +1 -0
- package/dist/spaces/Space.js +84 -0
- package/dist/spaces/Space.js.map +1 -0
- package/dist/spaces/SpaceService.d.ts +271 -0
- package/dist/spaces/SpaceService.d.ts.map +1 -0
- package/dist/spaces/SpaceService.js +715 -0
- package/dist/spaces/SpaceService.js.map +1 -0
- package/dist/spaces/index.d.ts +11 -0
- package/dist/spaces/index.d.ts.map +1 -0
- package/dist/spaces/index.js +20 -0
- package/dist/spaces/index.js.map +1 -0
- package/dist/spaces/spaces.schema.d.ts +421 -0
- package/dist/spaces/spaces.schema.d.ts.map +1 -0
- package/dist/spaces/spaces.schema.js +342 -0
- package/dist/spaces/spaces.schema.js.map +1 -0
- package/dist/spaces/spaces.schema.test.d.ts +5 -0
- package/dist/spaces/spaces.schema.test.d.ts.map +1 -0
- package/dist/spaces/spaces.schema.test.js +471 -0
- package/dist/spaces/spaces.schema.test.js.map +1 -0
- package/dist/storage.d.ts +47 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +14 -0
- package/dist/storage.js.map +1 -0
- package/dist/storage.schema.d.ts +277 -0
- package/dist/storage.schema.d.ts.map +1 -0
- package/dist/storage.schema.js +185 -0
- package/dist/storage.schema.js.map +1 -0
- package/dist/storage.schema.test.d.ts +5 -0
- package/dist/storage.schema.test.d.ts.map +1 -0
- package/dist/storage.schema.test.js +346 -0
- package/dist/storage.schema.test.js.map +1 -0
- package/dist/userAuthorization.d.ts +99 -0
- package/dist/userAuthorization.d.ts.map +1 -0
- package/dist/userAuthorization.js +3 -0
- package/dist/userAuthorization.js.map +1 -0
- package/dist/userAuthorization.schema.d.ts +259 -0
- package/dist/userAuthorization.schema.d.ts.map +1 -0
- package/dist/userAuthorization.schema.js +175 -0
- package/dist/userAuthorization.schema.js.map +1 -0
- package/dist/userAuthorization.schema.test.d.ts +5 -0
- package/dist/userAuthorization.schema.test.d.ts.map +1 -0
- package/dist/userAuthorization.schema.test.js +356 -0
- package/dist/userAuthorization.schema.test.js.map +1 -0
- package/dist/version.d.ts +30 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +54 -0
- package/dist/version.js.map +1 -0
- package/dist/wasm-validation.d.ts +287 -0
- package/dist/wasm-validation.d.ts.map +1 -0
- package/dist/wasm-validation.js +219 -0
- package/dist/wasm-validation.js.map +1 -0
- package/dist/wasm-validation.test.d.ts +5 -0
- package/dist/wasm-validation.test.d.ts.map +1 -0
- package/dist/wasm-validation.test.js +233 -0
- package/dist/wasm-validation.test.js.map +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for UserAuthorization configuration types.
|
|
3
|
+
*
|
|
4
|
+
* These schemas provide runtime validation for authorization 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 { ISigner } from "./signer";
|
|
13
|
+
import type { ISessionStorage } from "./storage";
|
|
14
|
+
import type { Extension, SiweConfig } from "@tinycloudlabs/web-core/client";
|
|
15
|
+
/**
|
|
16
|
+
* Schema for partial SIWE message overrides.
|
|
17
|
+
*
|
|
18
|
+
* This extends the base SiweConfig with additional common fields.
|
|
19
|
+
*/
|
|
20
|
+
export declare const PartialSiweMessageSchema: z.ZodObject<{
|
|
21
|
+
/** Ethereum address of the signer */
|
|
22
|
+
address: z.ZodOptional<z.ZodString>;
|
|
23
|
+
/** Chain ID for the signing context */
|
|
24
|
+
chainId: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
/** URI for the SIWE message */
|
|
26
|
+
uri: z.ZodOptional<z.ZodString>;
|
|
27
|
+
/** SIWE version (typically "1") */
|
|
28
|
+
version: z.ZodOptional<z.ZodString>;
|
|
29
|
+
/** Domain for the SIWE message */
|
|
30
|
+
domain: z.ZodOptional<z.ZodString>;
|
|
31
|
+
/** Statement for the SIWE message */
|
|
32
|
+
statement: z.ZodOptional<z.ZodString>;
|
|
33
|
+
/** Nonce for replay protection */
|
|
34
|
+
nonce: z.ZodOptional<z.ZodString>;
|
|
35
|
+
/** Issued at timestamp */
|
|
36
|
+
issuedAt: z.ZodOptional<z.ZodString>;
|
|
37
|
+
/** Expiration time */
|
|
38
|
+
expirationTime: z.ZodOptional<z.ZodString>;
|
|
39
|
+
/** Not before time */
|
|
40
|
+
notBefore: z.ZodOptional<z.ZodString>;
|
|
41
|
+
/** Request ID */
|
|
42
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
43
|
+
/** Resources array */
|
|
44
|
+
resources: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
notBefore?: string | undefined;
|
|
47
|
+
statement?: string | undefined;
|
|
48
|
+
version?: string | undefined;
|
|
49
|
+
domain?: string | undefined;
|
|
50
|
+
address?: string | undefined;
|
|
51
|
+
chainId?: number | undefined;
|
|
52
|
+
nonce?: string | undefined;
|
|
53
|
+
issuedAt?: string | undefined;
|
|
54
|
+
expirationTime?: string | undefined;
|
|
55
|
+
requestId?: string | undefined;
|
|
56
|
+
resources?: string[] | undefined;
|
|
57
|
+
uri?: string | undefined;
|
|
58
|
+
}, {
|
|
59
|
+
notBefore?: string | undefined;
|
|
60
|
+
statement?: string | undefined;
|
|
61
|
+
version?: string | undefined;
|
|
62
|
+
domain?: string | undefined;
|
|
63
|
+
address?: string | undefined;
|
|
64
|
+
chainId?: number | undefined;
|
|
65
|
+
nonce?: string | undefined;
|
|
66
|
+
issuedAt?: string | undefined;
|
|
67
|
+
expirationTime?: string | undefined;
|
|
68
|
+
requestId?: string | undefined;
|
|
69
|
+
resources?: string[] | undefined;
|
|
70
|
+
uri?: string | undefined;
|
|
71
|
+
}>;
|
|
72
|
+
export type PartialSiweMessage = z.infer<typeof PartialSiweMessageSchema>;
|
|
73
|
+
/**
|
|
74
|
+
* Schema for UserAuthorization configuration.
|
|
75
|
+
*
|
|
76
|
+
* Note: ISigner, ISessionStorage, Extension, and SiweConfig are external types
|
|
77
|
+
* that cannot be fully validated at runtime. We use z.unknown() for these.
|
|
78
|
+
*/
|
|
79
|
+
export declare const UserAuthorizationConfigSchema: z.ZodObject<{
|
|
80
|
+
/**
|
|
81
|
+
* The signer to use for signing.
|
|
82
|
+
* Validation-exempt: ISigner is an interface with methods.
|
|
83
|
+
*/
|
|
84
|
+
signer: z.ZodEffects<z.ZodUnknown, ISigner, unknown>;
|
|
85
|
+
/**
|
|
86
|
+
* Session storage implementation.
|
|
87
|
+
* Optional - defaults to platform-specific storage.
|
|
88
|
+
*/
|
|
89
|
+
sessionStorage: z.ZodOptional<z.ZodEffects<z.ZodUnknown, ISessionStorage | undefined, unknown>>;
|
|
90
|
+
/**
|
|
91
|
+
* Default SIWE configuration.
|
|
92
|
+
* Optional - merged with defaults.
|
|
93
|
+
*/
|
|
94
|
+
siweConfig: z.ZodOptional<z.ZodEffects<z.ZodUnknown, SiweConfig | undefined, unknown>>;
|
|
95
|
+
/**
|
|
96
|
+
* Domain for SIWE messages.
|
|
97
|
+
* Defaults to current window location for web, required for node.
|
|
98
|
+
*/
|
|
99
|
+
domain: z.ZodOptional<z.ZodString>;
|
|
100
|
+
/**
|
|
101
|
+
* Extensions to apply to the authorization flow.
|
|
102
|
+
*/
|
|
103
|
+
extensions: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodUnknown, Extension, unknown>, "many">>;
|
|
104
|
+
/**
|
|
105
|
+
* Strategy for handling sign requests.
|
|
106
|
+
* Default: auto-sign for node, callback for web.
|
|
107
|
+
*/
|
|
108
|
+
signStrategy: z.ZodOptional<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
109
|
+
type: z.ZodLiteral<"auto-sign">;
|
|
110
|
+
}, "strip", z.ZodTypeAny, {
|
|
111
|
+
type: "auto-sign";
|
|
112
|
+
}, {
|
|
113
|
+
type: "auto-sign";
|
|
114
|
+
}>, z.ZodObject<{
|
|
115
|
+
type: z.ZodLiteral<"auto-reject">;
|
|
116
|
+
}, "strip", z.ZodTypeAny, {
|
|
117
|
+
type: "auto-reject";
|
|
118
|
+
}, {
|
|
119
|
+
type: "auto-reject";
|
|
120
|
+
}>, z.ZodObject<{
|
|
121
|
+
type: z.ZodLiteral<"callback">;
|
|
122
|
+
handler: z.ZodEffects<z.ZodUnknown, import("./authorization/strategies.schema").SignCallback, unknown>;
|
|
123
|
+
}, "strip", z.ZodTypeAny, {
|
|
124
|
+
type: "callback";
|
|
125
|
+
handler: import("./authorization/strategies.schema").SignCallback;
|
|
126
|
+
}, {
|
|
127
|
+
type: "callback";
|
|
128
|
+
handler?: unknown;
|
|
129
|
+
}>, z.ZodObject<{
|
|
130
|
+
type: z.ZodLiteral<"event-emitter">;
|
|
131
|
+
emitter: z.ZodEffects<z.ZodUnknown, EventTarget, unknown>;
|
|
132
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
133
|
+
}, "strip", z.ZodTypeAny, {
|
|
134
|
+
type: "event-emitter";
|
|
135
|
+
emitter: EventTarget;
|
|
136
|
+
timeout?: number | undefined;
|
|
137
|
+
}, {
|
|
138
|
+
type: "event-emitter";
|
|
139
|
+
emitter?: unknown;
|
|
140
|
+
timeout?: number | undefined;
|
|
141
|
+
}>]>>;
|
|
142
|
+
/**
|
|
143
|
+
* Handler for space creation confirmation.
|
|
144
|
+
* Default: AutoApproveSpaceCreationHandler.
|
|
145
|
+
*/
|
|
146
|
+
spaceCreationHandler: z.ZodOptional<z.ZodObject<{
|
|
147
|
+
confirmSpaceCreation: z.ZodEffects<z.ZodUnknown, (context: import("./authorization/spaceCreation.schema").SpaceCreationContext) => Promise<boolean>, unknown>;
|
|
148
|
+
onSpaceCreated: z.ZodOptional<z.ZodEffects<z.ZodUnknown, ((context: import("./authorization/spaceCreation.schema").SpaceCreationContext) => void) | undefined, unknown>>;
|
|
149
|
+
onSpaceCreationFailed: z.ZodOptional<z.ZodEffects<z.ZodUnknown, ((context: import("./authorization/spaceCreation.schema").SpaceCreationContext, error: Error) => void) | undefined, unknown>>;
|
|
150
|
+
}, "strip", z.ZodTypeAny, {
|
|
151
|
+
confirmSpaceCreation: (context: import("./authorization/spaceCreation.schema").SpaceCreationContext) => Promise<boolean>;
|
|
152
|
+
onSpaceCreated?: ((context: import("./authorization/spaceCreation.schema").SpaceCreationContext) => void) | undefined;
|
|
153
|
+
onSpaceCreationFailed?: ((context: import("./authorization/spaceCreation.schema").SpaceCreationContext, error: Error) => void) | undefined;
|
|
154
|
+
}, {
|
|
155
|
+
confirmSpaceCreation?: unknown;
|
|
156
|
+
onSpaceCreated?: unknown;
|
|
157
|
+
onSpaceCreationFailed?: unknown;
|
|
158
|
+
}>>;
|
|
159
|
+
/**
|
|
160
|
+
* Whether to automatically create space if it doesn't exist.
|
|
161
|
+
* Default: true.
|
|
162
|
+
*/
|
|
163
|
+
autoCreateSpace: z.ZodOptional<z.ZodBoolean>;
|
|
164
|
+
/**
|
|
165
|
+
* Space name prefix.
|
|
166
|
+
* Default: "default".
|
|
167
|
+
*/
|
|
168
|
+
spacePrefix: z.ZodOptional<z.ZodString>;
|
|
169
|
+
/**
|
|
170
|
+
* TinyCloud host URLs.
|
|
171
|
+
*/
|
|
172
|
+
tinycloudHosts: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
173
|
+
/**
|
|
174
|
+
* Session expiration in milliseconds.
|
|
175
|
+
* Default: 24 hours.
|
|
176
|
+
*/
|
|
177
|
+
sessionExpirationMs: z.ZodOptional<z.ZodNumber>;
|
|
178
|
+
}, "strip", z.ZodTypeAny, {
|
|
179
|
+
signer: ISigner;
|
|
180
|
+
domain?: string | undefined;
|
|
181
|
+
sessionStorage?: ISessionStorage | undefined;
|
|
182
|
+
siweConfig?: SiweConfig | undefined;
|
|
183
|
+
extensions?: Extension[] | undefined;
|
|
184
|
+
signStrategy?: {
|
|
185
|
+
type: "auto-sign";
|
|
186
|
+
} | {
|
|
187
|
+
type: "auto-reject";
|
|
188
|
+
} | {
|
|
189
|
+
type: "callback";
|
|
190
|
+
handler: import("./authorization/strategies.schema").SignCallback;
|
|
191
|
+
} | {
|
|
192
|
+
type: "event-emitter";
|
|
193
|
+
emitter: EventTarget;
|
|
194
|
+
timeout?: number | undefined;
|
|
195
|
+
} | undefined;
|
|
196
|
+
spaceCreationHandler?: {
|
|
197
|
+
confirmSpaceCreation: (context: import("./authorization/spaceCreation.schema").SpaceCreationContext) => Promise<boolean>;
|
|
198
|
+
onSpaceCreated?: ((context: import("./authorization/spaceCreation.schema").SpaceCreationContext) => void) | undefined;
|
|
199
|
+
onSpaceCreationFailed?: ((context: import("./authorization/spaceCreation.schema").SpaceCreationContext, error: Error) => void) | undefined;
|
|
200
|
+
} | undefined;
|
|
201
|
+
autoCreateSpace?: boolean | undefined;
|
|
202
|
+
spacePrefix?: string | undefined;
|
|
203
|
+
tinycloudHosts?: string[] | undefined;
|
|
204
|
+
sessionExpirationMs?: number | undefined;
|
|
205
|
+
}, {
|
|
206
|
+
domain?: string | undefined;
|
|
207
|
+
signer?: unknown;
|
|
208
|
+
sessionStorage?: unknown;
|
|
209
|
+
siweConfig?: unknown;
|
|
210
|
+
extensions?: unknown[] | undefined;
|
|
211
|
+
signStrategy?: {
|
|
212
|
+
type: "auto-sign";
|
|
213
|
+
} | {
|
|
214
|
+
type: "auto-reject";
|
|
215
|
+
} | {
|
|
216
|
+
type: "callback";
|
|
217
|
+
handler?: unknown;
|
|
218
|
+
} | {
|
|
219
|
+
type: "event-emitter";
|
|
220
|
+
emitter?: unknown;
|
|
221
|
+
timeout?: number | undefined;
|
|
222
|
+
} | undefined;
|
|
223
|
+
spaceCreationHandler?: {
|
|
224
|
+
confirmSpaceCreation?: unknown;
|
|
225
|
+
onSpaceCreated?: unknown;
|
|
226
|
+
onSpaceCreationFailed?: unknown;
|
|
227
|
+
} | undefined;
|
|
228
|
+
autoCreateSpace?: boolean | undefined;
|
|
229
|
+
spacePrefix?: string | undefined;
|
|
230
|
+
tinycloudHosts?: string[] | undefined;
|
|
231
|
+
sessionExpirationMs?: number | undefined;
|
|
232
|
+
}>;
|
|
233
|
+
export type UserAuthorizationConfig = z.infer<typeof UserAuthorizationConfigSchema>;
|
|
234
|
+
/**
|
|
235
|
+
* Validates a UserAuthorizationConfig object and returns a Result.
|
|
236
|
+
*
|
|
237
|
+
* @param data - Unknown data to validate
|
|
238
|
+
* @returns Result with validated data or validation error
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const result = validateUserAuthorizationConfig(rawConfig);
|
|
243
|
+
* if (result.ok) {
|
|
244
|
+
* // result.data is typed as UserAuthorizationConfig
|
|
245
|
+
* console.log(result.data.domain);
|
|
246
|
+
* } else {
|
|
247
|
+
* console.error(result.error.message);
|
|
248
|
+
* }
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
export declare function validateUserAuthorizationConfig(data: unknown): Result<UserAuthorizationConfig, ValidationError>;
|
|
252
|
+
/**
|
|
253
|
+
* Validates a PartialSiweMessage object and returns a Result.
|
|
254
|
+
*
|
|
255
|
+
* @param data - Unknown data to validate
|
|
256
|
+
* @returns Result with validated data or validation error
|
|
257
|
+
*/
|
|
258
|
+
export declare function validatePartialSiweMessage(data: unknown): Result<PartialSiweMessage, ValidationError>;
|
|
259
|
+
//# sourceMappingURL=userAuthorization.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userAuthorization.schema.d.ts","sourceRoot":"","sources":["../src/userAuthorization.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;AAGxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAM5E;;;;GAIG;AACH,eAAO,MAAM,wBAAwB;IACnC,qCAAqC;;IAErC,uCAAuC;;IAEvC,+BAA+B;;IAE/B,mCAAmC;;IAEnC,kCAAkC;;IAElC,qCAAqC;;IAErC,kCAAkC;;IAElC,0BAA0B;;IAE1B,sBAAsB;;IAEtB,sBAAsB;;IAEtB,iBAAiB;;IAEjB,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEtB,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAM1E;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B;IACxC;;;OAGG;;IAMH;;;OAGG;;IAUH;;;OAGG;;IAUH;;;OAGG;;IAGH;;OAEG;;IAYH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAGH;;;OAGG;;;;;;;;;;;;;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;OAEG;;IAGH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEH,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAMpF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,uBAAuB,EAAE,eAAe,CAAC,CAclD;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAc7C"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for UserAuthorization configuration types.
|
|
3
|
+
*
|
|
4
|
+
* These schemas provide runtime validation for authorization configuration.
|
|
5
|
+
* Types are derived from schemas using z.infer<>.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { SignStrategySchema } from "./authorization/strategies.schema";
|
|
11
|
+
import { SpaceCreationHandlerSchema } from "./authorization/spaceCreation.schema";
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// Partial SIWE Message Schema
|
|
14
|
+
// =============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Schema for partial SIWE message overrides.
|
|
17
|
+
*
|
|
18
|
+
* This extends the base SiweConfig with additional common fields.
|
|
19
|
+
*/
|
|
20
|
+
export const PartialSiweMessageSchema = z.object({
|
|
21
|
+
/** Ethereum address of the signer */
|
|
22
|
+
address: z.string().optional(),
|
|
23
|
+
/** Chain ID for the signing context */
|
|
24
|
+
chainId: z.number().int().positive().optional(),
|
|
25
|
+
/** URI for the SIWE message */
|
|
26
|
+
uri: z.string().optional(),
|
|
27
|
+
/** SIWE version (typically "1") */
|
|
28
|
+
version: z.string().optional(),
|
|
29
|
+
/** Domain for the SIWE message */
|
|
30
|
+
domain: z.string().optional(),
|
|
31
|
+
/** Statement for the SIWE message */
|
|
32
|
+
statement: z.string().optional(),
|
|
33
|
+
/** Nonce for replay protection */
|
|
34
|
+
nonce: z.string().optional(),
|
|
35
|
+
/** Issued at timestamp */
|
|
36
|
+
issuedAt: z.string().optional(),
|
|
37
|
+
/** Expiration time */
|
|
38
|
+
expirationTime: z.string().optional(),
|
|
39
|
+
/** Not before time */
|
|
40
|
+
notBefore: z.string().optional(),
|
|
41
|
+
/** Request ID */
|
|
42
|
+
requestId: z.string().optional(),
|
|
43
|
+
/** Resources array */
|
|
44
|
+
resources: z.array(z.string()).optional(),
|
|
45
|
+
});
|
|
46
|
+
// =============================================================================
|
|
47
|
+
// User Authorization Config Schema
|
|
48
|
+
// =============================================================================
|
|
49
|
+
/**
|
|
50
|
+
* Schema for UserAuthorization configuration.
|
|
51
|
+
*
|
|
52
|
+
* Note: ISigner, ISessionStorage, Extension, and SiweConfig are external types
|
|
53
|
+
* that cannot be fully validated at runtime. We use z.unknown() for these.
|
|
54
|
+
*/
|
|
55
|
+
export const UserAuthorizationConfigSchema = z.object({
|
|
56
|
+
/**
|
|
57
|
+
* The signer to use for signing.
|
|
58
|
+
* Validation-exempt: ISigner is an interface with methods.
|
|
59
|
+
*/
|
|
60
|
+
signer: z.unknown().refine((val) => val !== null && typeof val === "object", { message: "Expected an ISigner object" }),
|
|
61
|
+
/**
|
|
62
|
+
* Session storage implementation.
|
|
63
|
+
* Optional - defaults to platform-specific storage.
|
|
64
|
+
*/
|
|
65
|
+
sessionStorage: z
|
|
66
|
+
.unknown()
|
|
67
|
+
.refine((val) => val === undefined || (val !== null && typeof val === "object"), { message: "Expected an ISessionStorage object or undefined" })
|
|
68
|
+
.optional(),
|
|
69
|
+
/**
|
|
70
|
+
* Default SIWE configuration.
|
|
71
|
+
* Optional - merged with defaults.
|
|
72
|
+
*/
|
|
73
|
+
siweConfig: z
|
|
74
|
+
.unknown()
|
|
75
|
+
.refine((val) => val === undefined || (val !== null && typeof val === "object"), { message: "Expected a SiweConfig object or undefined" })
|
|
76
|
+
.optional(),
|
|
77
|
+
/**
|
|
78
|
+
* Domain for SIWE messages.
|
|
79
|
+
* Defaults to current window location for web, required for node.
|
|
80
|
+
*/
|
|
81
|
+
domain: z.string().optional(),
|
|
82
|
+
/**
|
|
83
|
+
* Extensions to apply to the authorization flow.
|
|
84
|
+
*/
|
|
85
|
+
extensions: z
|
|
86
|
+
.array(z.unknown().refine((val) => val !== null && typeof val === "object", { message: "Expected an Extension object" }))
|
|
87
|
+
.optional(),
|
|
88
|
+
// Strategy configuration (added for auth module unification)
|
|
89
|
+
/**
|
|
90
|
+
* Strategy for handling sign requests.
|
|
91
|
+
* Default: auto-sign for node, callback for web.
|
|
92
|
+
*/
|
|
93
|
+
signStrategy: SignStrategySchema.optional(),
|
|
94
|
+
/**
|
|
95
|
+
* Handler for space creation confirmation.
|
|
96
|
+
* Default: AutoApproveSpaceCreationHandler.
|
|
97
|
+
*/
|
|
98
|
+
spaceCreationHandler: SpaceCreationHandlerSchema.optional(),
|
|
99
|
+
/**
|
|
100
|
+
* Whether to automatically create space if it doesn't exist.
|
|
101
|
+
* Default: true.
|
|
102
|
+
*/
|
|
103
|
+
autoCreateSpace: z.boolean().optional(),
|
|
104
|
+
/**
|
|
105
|
+
* Space name prefix.
|
|
106
|
+
* Default: "default".
|
|
107
|
+
*/
|
|
108
|
+
spacePrefix: z.string().optional(),
|
|
109
|
+
/**
|
|
110
|
+
* TinyCloud host URLs.
|
|
111
|
+
*/
|
|
112
|
+
tinycloudHosts: z.array(z.string()).optional(),
|
|
113
|
+
/**
|
|
114
|
+
* Session expiration in milliseconds.
|
|
115
|
+
* Default: 24 hours.
|
|
116
|
+
*/
|
|
117
|
+
sessionExpirationMs: z.number().int().positive().optional(),
|
|
118
|
+
});
|
|
119
|
+
// =============================================================================
|
|
120
|
+
// Validation Helpers
|
|
121
|
+
// =============================================================================
|
|
122
|
+
/**
|
|
123
|
+
* Validates a UserAuthorizationConfig object and returns a Result.
|
|
124
|
+
*
|
|
125
|
+
* @param data - Unknown data to validate
|
|
126
|
+
* @returns Result with validated data or validation error
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const result = validateUserAuthorizationConfig(rawConfig);
|
|
131
|
+
* if (result.ok) {
|
|
132
|
+
* // result.data is typed as UserAuthorizationConfig
|
|
133
|
+
* console.log(result.data.domain);
|
|
134
|
+
* } else {
|
|
135
|
+
* console.error(result.error.message);
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export function validateUserAuthorizationConfig(data) {
|
|
140
|
+
const result = UserAuthorizationConfigSchema.safeParse(data);
|
|
141
|
+
if (!result.success) {
|
|
142
|
+
return {
|
|
143
|
+
ok: false,
|
|
144
|
+
error: {
|
|
145
|
+
code: "VALIDATION_ERROR",
|
|
146
|
+
message: result.error.message,
|
|
147
|
+
service: "authorization",
|
|
148
|
+
meta: { issues: result.error.issues },
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return { ok: true, data: result.data };
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Validates a PartialSiweMessage object and returns a Result.
|
|
156
|
+
*
|
|
157
|
+
* @param data - Unknown data to validate
|
|
158
|
+
* @returns Result with validated data or validation error
|
|
159
|
+
*/
|
|
160
|
+
export function validatePartialSiweMessage(data) {
|
|
161
|
+
const result = PartialSiweMessageSchema.safeParse(data);
|
|
162
|
+
if (!result.success) {
|
|
163
|
+
return {
|
|
164
|
+
ok: false,
|
|
165
|
+
error: {
|
|
166
|
+
code: "VALIDATION_ERROR",
|
|
167
|
+
message: result.error.message,
|
|
168
|
+
service: "authorization",
|
|
169
|
+
meta: { issues: result.error.issues },
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return { ok: true, data: result.data };
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=userAuthorization.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userAuthorization.schema.js","sourceRoot":"","sources":["../src/userAuthorization.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAKlF,gFAAgF;AAChF,8BAA8B;AAC9B,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,qCAAqC;IACrC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,uCAAuC;IACvC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC/C,+BAA+B;IAC/B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1B,mCAAmC;IACnC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,kCAAkC;IAClC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SAAS,CAAC,IAAI,CAAC,CAAC;IAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO;YACL,EAAE,EAAE,KAAK;YACT,KAAK,EAAE;gBACL,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO;gBAC7B,OAAO,EAAE,eAAe;gBACxB,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;aACtC;SACF,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,IAAa;IAEb,MAAM,MAAM,GAAG,wBAAwB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACxD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO;YACL,EAAE,EAAE,KAAK;YACT,KAAK,EAAE;gBACL,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO;gBAC7B,OAAO,EAAE,eAAe;gBACxB,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;aACtC;SACF,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userAuthorization.schema.test.d.ts","sourceRoot":"","sources":["../src/userAuthorization.schema.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|