@sanity/sdk 0.0.0-alpha.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/dist/index.d.ts +339 -0
- package/dist/index.js +492 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -0
- package/src/_exports/index.ts +39 -0
- package/src/auth/authStore.test.ts +296 -0
- package/src/auth/authStore.ts +125 -0
- package/src/auth/getAuthStore.test.ts +14 -0
- package/src/auth/getInternalAuthStore.ts +20 -0
- package/src/auth/internalAuthStore.test.ts +334 -0
- package/src/auth/internalAuthStore.ts +519 -0
- package/src/client/getClient.test.ts +41 -0
- package/src/client/getClient.ts +13 -0
- package/src/client/getSubscribableClient.test.ts +71 -0
- package/src/client/getSubscribableClient.ts +17 -0
- package/src/client/store/actions/getClientEvents.test.ts +95 -0
- package/src/client/store/actions/getClientEvents.ts +33 -0
- package/src/client/store/actions/getOrCreateClient.test.ts +56 -0
- package/src/client/store/actions/getOrCreateClient.ts +40 -0
- package/src/client/store/actions/receiveToken.test.ts +18 -0
- package/src/client/store/actions/receiveToken.ts +31 -0
- package/src/client/store/clientStore.test.ts +152 -0
- package/src/client/store/clientStore.ts +98 -0
- package/src/documentList/documentListStore.test.ts +575 -0
- package/src/documentList/documentListStore.ts +269 -0
- package/src/documents/.keep +0 -0
- package/src/instance/identity.test.ts +46 -0
- package/src/instance/identity.ts +28 -0
- package/src/instance/sanityInstance.test.ts +66 -0
- package/src/instance/sanityInstance.ts +64 -0
- package/src/instance/types.d.ts +29 -0
- package/src/schema/schemaStore.test.ts +30 -0
- package/src/schema/schemaStore.ts +32 -0
- package/src/store/createStore.test.ts +108 -0
- package/src/store/createStore.ts +106 -0
- package/src/tsdoc.json +39 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import {ClientConfig} from '@sanity/client'
|
|
2
|
+
import {InternalStores} from '../instance/types'
|
|
3
|
+
import {SanityClient} from '@sanity/client'
|
|
4
|
+
import {SanityInstance} from '../instance/types'
|
|
5
|
+
import type {SanityInstance as SanityInstance_2} from './types'
|
|
6
|
+
import {SdkIdentity} from '../instance/types'
|
|
7
|
+
import type {StoreApi} from 'zustand'
|
|
8
|
+
import {Subscribable} from 'rxjs'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for creating an auth store.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare interface AuthConfig {
|
|
16
|
+
/**
|
|
17
|
+
* The initial location href to use when handling auth callbacks.
|
|
18
|
+
* Defaults to the current window location if available.
|
|
19
|
+
*/
|
|
20
|
+
initialLocationHref?: string
|
|
21
|
+
/**
|
|
22
|
+
* Factory function to create a SanityClient instance.
|
|
23
|
+
* Defaults to the standard Sanity client factory if not provided.
|
|
24
|
+
*/
|
|
25
|
+
clientFactory?: (config: ClientConfig) => SanityClient
|
|
26
|
+
/**
|
|
27
|
+
* Custom authentication providers to use instead of or in addition to the default ones.
|
|
28
|
+
* Can be an array of providers or a function that takes the default providers and returns
|
|
29
|
+
* a modified array or a Promise resolving to one.
|
|
30
|
+
*/
|
|
31
|
+
providers?: AuthProvider[] | ((prev: AuthProvider[]) => AuthProvider[] | Promise<AuthProvider[]>)
|
|
32
|
+
/**
|
|
33
|
+
* The API hostname for requests. Usually leave this undefined, but it can be set
|
|
34
|
+
* if using a custom domain or CNAME for the API endpoint.
|
|
35
|
+
*/
|
|
36
|
+
apiHost?: string
|
|
37
|
+
/**
|
|
38
|
+
* Storage implementation to persist authentication state.
|
|
39
|
+
* Defaults to `localStorage` if available.
|
|
40
|
+
*/
|
|
41
|
+
storageArea?: Storage
|
|
42
|
+
/**
|
|
43
|
+
* A callback URL for your application.
|
|
44
|
+
* If none is provided, the auth API will redirect back to the current location (`location.href`).
|
|
45
|
+
* When handling callbacks, this URL's pathname is checked to ensure it matches the callback.
|
|
46
|
+
*/
|
|
47
|
+
callbackUrl?: string
|
|
48
|
+
/**
|
|
49
|
+
* A static authentication token to use instead of handling the OAuth flow.
|
|
50
|
+
* When provided, the auth store will remain in a logged-in state with this token,
|
|
51
|
+
* ignoring any storage or callback handling.
|
|
52
|
+
*/
|
|
53
|
+
token?: string
|
|
54
|
+
/**
|
|
55
|
+
* The authentication scope.
|
|
56
|
+
* If set to 'project', requests are scoped to the project-level.
|
|
57
|
+
* If set to 'org', requests are scoped to the organization-level.
|
|
58
|
+
* Defaults to 'project'.
|
|
59
|
+
*/
|
|
60
|
+
authScope?: 'project' | 'org'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Configuration for an authentication provider
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
export declare interface AuthProvider {
|
|
68
|
+
/**
|
|
69
|
+
* Unique identifier for the auth provider (e.g., 'google', 'github')
|
|
70
|
+
*/
|
|
71
|
+
name: string
|
|
72
|
+
/**
|
|
73
|
+
* Display name for the auth provider in the UI
|
|
74
|
+
*/
|
|
75
|
+
title: string
|
|
76
|
+
/**
|
|
77
|
+
* Complete authentication URL including callback and token parameters
|
|
78
|
+
*/
|
|
79
|
+
url: string
|
|
80
|
+
/**
|
|
81
|
+
* Optional URL for direct sign-up flow
|
|
82
|
+
*/
|
|
83
|
+
signUpUrl?: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Represents the various states the authentication store can be in.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export declare type AuthState =
|
|
92
|
+
| {
|
|
93
|
+
type: 'logged-in'
|
|
94
|
+
token: string
|
|
95
|
+
currentUser: CurrentUser | null
|
|
96
|
+
}
|
|
97
|
+
| {
|
|
98
|
+
type: 'logging-in'
|
|
99
|
+
isExchangingToken: boolean
|
|
100
|
+
}
|
|
101
|
+
| {
|
|
102
|
+
type: 'error'
|
|
103
|
+
error: unknown
|
|
104
|
+
}
|
|
105
|
+
| {
|
|
106
|
+
type: 'logged-out'
|
|
107
|
+
isDestroyingSession: boolean
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Public interface for the auth store.
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
export declare interface AuthStateSlice {
|
|
115
|
+
getState: () => AuthState
|
|
116
|
+
getInitialState: () => AuthState
|
|
117
|
+
subscribe: (listener: (state: AuthState, prevState: AuthState) => void) => () => void
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
export declare interface AuthStore {
|
|
124
|
+
authState: AuthStateSlice
|
|
125
|
+
tokenState: PublicTokenSlice
|
|
126
|
+
currentUserState: CurrentUserSlice
|
|
127
|
+
handleCallback: (locationHref?: string) => Promise<string | false>
|
|
128
|
+
logout: () => Promise<void>
|
|
129
|
+
dispose: () => void
|
|
130
|
+
getLoginUrls: () => AuthProvider[] | Promise<AuthProvider[]>
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Options used when retrieving a client via getOrCreateClient.
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
export declare interface ClientOptions {
|
|
138
|
+
apiVersion?: string
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Internal state of the client store.
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
export declare interface ClientState {
|
|
146
|
+
defaultClient: SanityClient
|
|
147
|
+
clients: Map<string, SanityClient>
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Collection of actions to retrieve or create clients.
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
export declare interface ClientStore {
|
|
155
|
+
getOrCreateClient: (options: ClientOptions) => SanityClient
|
|
156
|
+
receiveToken: (token: string | undefined) => void
|
|
157
|
+
getClientEvents: (options: ClientOptions) => Subscribable<SanityClient>
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Creates a `DocumentListStore` from a `SanityInstance`.
|
|
162
|
+
*
|
|
163
|
+
* @public
|
|
164
|
+
*
|
|
165
|
+
* See {@link SanityInstance} and {@link DocumentListStore}
|
|
166
|
+
*/
|
|
167
|
+
export declare function createDocumentListStore(instance: SanityInstance): DocumentListStore
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Returns a new instance of dependencies required for SanitySDK.
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
*
|
|
174
|
+
* @param config - The configuration for this instance
|
|
175
|
+
*
|
|
176
|
+
* @returns A new "instance" of a Sanity SDK, used to bind resources/configuration to it
|
|
177
|
+
*/
|
|
178
|
+
export declare function createSanityInstance({
|
|
179
|
+
projectId,
|
|
180
|
+
dataset,
|
|
181
|
+
...config
|
|
182
|
+
}: SanityConfig): SanityInstance_2
|
|
183
|
+
|
|
184
|
+
/** @public */
|
|
185
|
+
export declare interface CurrentUser {
|
|
186
|
+
id: string
|
|
187
|
+
name: string
|
|
188
|
+
email: string
|
|
189
|
+
profileImage?: string
|
|
190
|
+
provider?: string
|
|
191
|
+
/** @deprecated use `roles` instead */
|
|
192
|
+
role: string
|
|
193
|
+
roles: Role[]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Public interface for the auth store slice that contains the current user.
|
|
198
|
+
*
|
|
199
|
+
* @public
|
|
200
|
+
*/
|
|
201
|
+
export declare interface CurrentUserSlice {
|
|
202
|
+
getState: () => CurrentUser | null
|
|
203
|
+
getInitialState: () => CurrentUser | null
|
|
204
|
+
subscribe: (
|
|
205
|
+
listener: (user: CurrentUser | null, prevUser: CurrentUser | null) => void,
|
|
206
|
+
) => () => void
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Represents an identifier to a Sanity document, containing its `_id` to pull
|
|
211
|
+
* the document from content lake and its `_type` to look up its schema type.
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
export declare interface DocumentHandle {
|
|
215
|
+
_id: string
|
|
216
|
+
_type: string
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Configuration options for filtering and sorting documents in a document list.
|
|
221
|
+
* @public
|
|
222
|
+
*/
|
|
223
|
+
export declare interface DocumentListOptions {
|
|
224
|
+
/** GROQ filter expression to query specific documents */
|
|
225
|
+
filter?: string
|
|
226
|
+
/** Array of sort ordering specifications to determine the order of results */
|
|
227
|
+
sort?: SortOrderingItem[]
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Represents the current state of a document list, including the query options
|
|
232
|
+
* and loading status.
|
|
233
|
+
* @public
|
|
234
|
+
*/
|
|
235
|
+
export declare interface DocumentListState extends DocumentListOptions {
|
|
236
|
+
/** Array of document handles in the current result set, or null if not yet loaded */
|
|
237
|
+
result: DocumentHandle[] | null
|
|
238
|
+
/** Indicates whether the document list is currently loading */
|
|
239
|
+
isPending: boolean
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Manages the state and operations for a list of Sanity documents.
|
|
244
|
+
* Provides methods to update options, load more documents, and subscribe to
|
|
245
|
+
* state changes.
|
|
246
|
+
*
|
|
247
|
+
* Implements a subscription model where you can register callback functions
|
|
248
|
+
* to be notified when the document list state changes.
|
|
249
|
+
* @public
|
|
250
|
+
*/
|
|
251
|
+
export declare interface DocumentListStore extends Subscribable<DocumentListState> {
|
|
252
|
+
/** Updates the filtering and sorting options for the document list */
|
|
253
|
+
setOptions: (options: DocumentListOptions) => void
|
|
254
|
+
/** Retrieves the current state of the document list synchronously */
|
|
255
|
+
getCurrent: () => DocumentListState
|
|
256
|
+
/** Loads the next page of documents */
|
|
257
|
+
loadMore: () => void
|
|
258
|
+
/** Cleans up resources and subscriptions when the store is no longer needed */
|
|
259
|
+
dispose: () => void
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Retrieves or creates an `AuthStore` for the given `SanityInstance`.
|
|
264
|
+
*
|
|
265
|
+
* @param instance - The `SanityInstance` to get or create the `AuthStore` for.
|
|
266
|
+
* @returns The `AuthStore` associated with the given `SanityInstance`.
|
|
267
|
+
*
|
|
268
|
+
* @public
|
|
269
|
+
*/
|
|
270
|
+
export declare const getAuthStore: (instance: SanityInstance) => AuthStore
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Retrieve a memoized client based on the apiVersion.
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
export declare const getClient: (options: ClientOptions, instance: SanityInstance) => SanityClient
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Creates a subscribable client based on the apiVersion.
|
|
280
|
+
* The client will update when the underlying store changes (e.g., on user authentication changes).
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
export declare const getSubscribableClient: (
|
|
284
|
+
options: ClientOptions,
|
|
285
|
+
instance: SanityInstance,
|
|
286
|
+
) => Subscribable<SanityClient>
|
|
287
|
+
|
|
288
|
+
export {InternalStores}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Public interface for the token store.
|
|
292
|
+
*
|
|
293
|
+
* @public
|
|
294
|
+
*/
|
|
295
|
+
export declare interface PublicTokenSlice {
|
|
296
|
+
getState: () => string | null
|
|
297
|
+
getInitialState: () => string | null
|
|
298
|
+
subscribe: (listener: (token: string | null, prevToken: string | null) => void) => () => void
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** @public */
|
|
302
|
+
export declare interface Role {
|
|
303
|
+
name: string
|
|
304
|
+
title: string
|
|
305
|
+
description?: string
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @public
|
|
310
|
+
*/
|
|
311
|
+
export declare interface SanityConfig {
|
|
312
|
+
projectId: string
|
|
313
|
+
dataset: string
|
|
314
|
+
auth?: AuthConfig
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export {SanityInstance}
|
|
318
|
+
|
|
319
|
+
/** @public */
|
|
320
|
+
export declare interface SchemaState {
|
|
321
|
+
schema: any
|
|
322
|
+
setSchema: (newSchema: any) => void
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** @public */
|
|
326
|
+
export declare type SchemaStore = StoreApi<SchemaState>
|
|
327
|
+
|
|
328
|
+
export {SdkIdentity}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Represents a sort ordering configuration.
|
|
332
|
+
* @public
|
|
333
|
+
*/
|
|
334
|
+
export declare interface SortOrderingItem {
|
|
335
|
+
field: string
|
|
336
|
+
direction: 'asc' | 'desc'
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export {}
|