@kittl/sdk 0.0.8 → 1.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.
@@ -0,0 +1,328 @@
1
+ declare class SdkBadInputError extends Error {
2
+ readonly name: "SdkBadInputError";
3
+ readonly cause?: Error;
4
+ constructor(message: string, cause?: Error);
5
+ }
6
+ declare class SdkInternalError extends Error {
7
+ readonly name: "SdkInternalError";
8
+ readonly cause?: Error;
9
+ constructor(message: string, cause?: Error);
10
+ }
11
+ declare const UploadType: {
12
+ readonly EXTENSION: "EXTENSION";
13
+ readonly AI_GENERATED: "AI_GENERATED";
14
+ readonly AI_GENERATED_SETS: "AI_GENERATED_SETS";
15
+ readonly AI_UPSCALED: "AI_UPSCALED";
16
+ readonly AI_EDITED: "AI_EDITED";
17
+ readonly MOCKUP: "MOCKUP";
18
+ readonly CLIPPED: "CLIPPED";
19
+ readonly BRAND_KIT: "BRAND_KIT";
20
+ readonly QUICK_EDIT: "QUICK_EDIT";
21
+ };
22
+ export declare const kittl: SharedFileBrowserKittlSDK;
23
+ /**
24
+ * Unwraps an {@link SdkResult}, returning its value on success and throwing its
25
+ * error on failure. This lets callers use regular `try`/`catch` control flow
26
+ * around direct SDK calls instead of branching on `isOk` every time — branching
27
+ * on `isOk` directly remains fully supported.
28
+ *
29
+ * @typeParam T - The success value type carried by the result.
30
+ * @param result - The {@link SdkResult} returned by an SDK call.
31
+ * @returns The success value when `result.isOk` is `true`.
32
+ * @throws The result's `error` when `result.isOk` is `false`.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * import { kittl, unwrapResult } from '@kittl/sdk/editorContentPanel';
37
+ *
38
+ * try {
39
+ * const image = unwrapResult(await kittl.project.design.api.image.addImage(params));
40
+ * console.log('Added image:', image.id);
41
+ * } catch (error) {
42
+ * console.error('Failed to add image:', error);
43
+ * }
44
+ * ```
45
+ *
46
+ * @public
47
+ */
48
+ export declare function unwrapResult<T>(result: SdkResult<T, Error>): T;
49
+ export interface AsyncAuthAPI {
50
+ startAuth: (request: AuthStartRequest) => Promise<SdkResult<AuthStartResult>>;
51
+ exchangeCode: (request: AuthExchangeRequest) => Promise<SdkResult<AuthTokenResponse>>;
52
+ getAuthToken: (request: AuthGetTokenRequest) => Promise<SdkResult<AuthTokenResponse | null>>;
53
+ refreshToken: (request: AuthRefreshRequest) => Promise<SdkResult<AuthTokenResponse>>;
54
+ getUserToken: () => Promise<SdkResult<UserTokenResult>>;
55
+ logout: (request: AuthLogoutRequest) => Promise<SdkResult<void>>;
56
+ }
57
+ export interface AuthExchangeRequest {
58
+ code: string;
59
+ code_verifier?: string;
60
+ provider: string;
61
+ params?: Record<string, unknown>;
62
+ headers?: Record<string, string>;
63
+ }
64
+ export interface AuthGetTokenRequest {
65
+ provider: string;
66
+ }
67
+ export interface AuthLogoutRequest {
68
+ provider?: string;
69
+ }
70
+ export interface AuthRefreshRequest {
71
+ provider: string;
72
+ }
73
+ export interface AuthStartRequest {
74
+ provider: string;
75
+ params?: Record<string, string | number | boolean>;
76
+ generatePKCE?: boolean;
77
+ }
78
+ export interface AuthStartResult {
79
+ code: string;
80
+ code_verifier?: string;
81
+ }
82
+ /**
83
+ * Token response returned by the token endpoint (code exchange or refresh).
84
+ */
85
+ export interface AuthTokenResponse {
86
+ access_token?: string;
87
+ refresh_token?: string;
88
+ expires_in?: number;
89
+ [key: string]: unknown;
90
+ }
91
+ /** Historical registration surface retained for existing extensions. */
92
+ export interface FileBrowserAPI {
93
+ /** @deprecated Use context.registerUploadBrowser on the sharedFileBrowser entrypoint. */
94
+ registerUploadBrowser: UploadBrowserRegistrationAPI["registerUploadBrowser"];
95
+ }
96
+ /**
97
+ * File browser registration API exposed to content panels and shared file browsers.
98
+ *
99
+ * @public
100
+ */
101
+ export interface KittlSDKFileBrowserAPI {
102
+ /**
103
+ * File browser API for registering custom file browser tabs in the upload modal.
104
+ * Allows extensions to provide custom content sources that appear as tabs in the upload gallery.
105
+ */
106
+ fileBrowser: FileBrowserAPI;
107
+ }
108
+ /**
109
+ * Lifecycle fields shared by every public SDK mounting point.
110
+ *
111
+ * @public
112
+ */
113
+ export interface KittlSDKLifecycle {
114
+ /**
115
+ * Whether the SDK is loaded and has called the onLoadedCallback.
116
+ */
117
+ loaded: boolean;
118
+ /**
119
+ * Callback function called when the extension is loaded.
120
+ */
121
+ onLoadedCallback: (() => void) | null;
122
+ /**
123
+ * Sets a callback to be called when the extension is ready.
124
+ */
125
+ onReady: (cb: () => void) => void;
126
+ }
127
+ /**
128
+ * Host-agnostic APIs every mounting-point SDK entrypoint exposes.
129
+ *
130
+ * @public
131
+ */
132
+ export interface KittlSDKSharedAPIs {
133
+ /**
134
+ * Auth API for extension OAuth flows via the host page.
135
+ */
136
+ auth: AsyncAuthAPI;
137
+ }
138
+ /** Registers an extension-owned content source using the existing callback protocol. */
139
+ export interface UploadBrowserRegistrationAPI {
140
+ /** Registers a tab whose fetchContent callback remains inside this iframe. */
141
+ registerUploadBrowser: (tab: Omit<FileBrowserTab, "onEvent">) => Promise<SdkResponse<void>>;
142
+ }
143
+ export interface UserTokenResult {
144
+ success: true;
145
+ token: string;
146
+ }
147
+ /**
148
+ * Union of nodes a dynamic tab can return.
149
+ */
150
+ export type FileBrowserContent = FileBrowserItem | FileBrowserFolder;
151
+ /**
152
+ * Input arguments for a file browser content request.
153
+ */
154
+ export type FileBrowserFetchContentParams = {
155
+ /** Folder or entry id to load. Omit to load the root content. */
156
+ id?: string;
157
+ /** Optional pagination cursor for fetching the next slice of content. */
158
+ next?: string | number;
159
+ /**
160
+ * Media kinds the current session accepts, so a tab backed by an API that
161
+ * can filter server-side does not spend a page on entries the gallery will
162
+ * hide anyway.
163
+ *
164
+ * This is an optimisation hint, not a contract: the host still drops
165
+ * entries of an unwanted kind before rendering, so a tab that ignores this
166
+ * stays correct. `undefined` means the session did not narrow its kinds.
167
+ */
168
+ formats?: readonly FileBrowserMediaFormat[];
169
+ };
170
+ /**
171
+ * Result returned from a file browser content request.
172
+ */
173
+ export type FileBrowserFetchContentResult = {
174
+ /** Content nodes returned for the requested folder or root view. */
175
+ content: FileBrowserContent[];
176
+ /** Optional cursor for loading the next page of the same folder view. */
177
+ next?: string | number;
178
+ error?: string;
179
+ };
180
+ /**
181
+ * Nested folder node returned by a dynamic gallery tab.
182
+ */
183
+ export type FileBrowserFolder = {
184
+ type: "folder";
185
+ label: string;
186
+ id: string;
187
+ preview?: string;
188
+ /**
189
+ * Optional eager-loaded children for this folder.
190
+ *
191
+ * When omitted, consumers should call the tab's
192
+ * `fetchContent({ id: folder.id })` method to load the folder contents on
193
+ * demand.
194
+ */
195
+ content?: Array<FileBrowserContent>;
196
+ };
197
+ /**
198
+ * Leaf asset returned by a dynamic gallery tab.
199
+ */
200
+ export type FileBrowserItem = {
201
+ type: "item";
202
+ label: string;
203
+ id: string;
204
+ preview?: string;
205
+ /**
206
+ * Optional looping preview played while the tile is hovered — e.g. an
207
+ * animated WEBP or GIF of a video's opening seconds.
208
+ *
209
+ * Only used for video items, which fall back to their static `preview` when
210
+ * this is omitted.
211
+ */
212
+ animatedPreview?: string;
213
+ content: {
214
+ data: string;
215
+ /** Optional MIME type used when materializing the selected asset. */
216
+ mimeType?: string;
217
+ /** Persisted upload classification. */
218
+ uploadType?: UploadType;
219
+ };
220
+ };
221
+ /**
222
+ * Media kind a file browser session can deal in.
223
+ *
224
+ * Both kinds are browsable and selectable; only images have an upload path.
225
+ */
226
+ export type FileBrowserMediaFormat = "image" | "video";
227
+ /**
228
+ * Registration contract for a file browser tab in the upload panel.
229
+ */
230
+ export type FileBrowserTab = {
231
+ /** Unique identifier for the browser tab */
232
+ id: string;
233
+ /** Display label for the tab */
234
+ label: string;
235
+ /** Optional display order. Lower values render first. */
236
+ order?: number;
237
+ /** Optional product empty-state treatment. Omit for the generic state. */
238
+ emptyState?: FileBrowserTabEmptyState;
239
+ /**
240
+ * Media kinds this tab is able to return.
241
+ *
242
+ * Unlike the `formats` hint handed to `fetchContent` — what the session
243
+ * wants — this is what the tab has. The host hides the whole tab when the
244
+ * two sets do not intersect, so a session that only wants video never opens
245
+ * an image-only tab just to find it empty.
246
+ *
247
+ * Omit (or pass an empty array) when the tab can return any kind, or when it
248
+ * cannot know in advance; such a tab is always shown and its entries are
249
+ * filtered on render as before.
250
+ */
251
+ supportedFormats?: readonly FileBrowserMediaFormat[];
252
+ /**
253
+ * Loads root content, a specific folder, or a specific entry.
254
+ *
255
+ * If a returned folder has `content === undefined`, call
256
+ * `fetchContent({ id: folder.id })` to load that folder lazily.
257
+ *
258
+ * If the returned result exposes `next`, pass it back as
259
+ * `fetchContent({ id, next })` to load the next page for that folder view.
260
+ *
261
+ * The provider may also call `fetchContent({ id })` to refresh one specific
262
+ * entry when invalidation is requested.
263
+ */
264
+ fetchContent: (params?: FileBrowserFetchContentParams) => Promise<FileBrowserFetchContentResult>;
265
+ /** Optional lifecycle hook emitted by the host gallery. */
266
+ onEvent?: (event: FileBrowserTabEvent) => void;
267
+ };
268
+ /** Product empty-state treatment shown when a tab has no content. */
269
+ export type FileBrowserTabEmptyState = "aiCreations" | "uploads";
270
+ /** Lifecycle event emitted by the host gallery. */
271
+ export type FileBrowserTabEvent = "close" | "open" | "upload";
272
+ /**
273
+ * Unified SDK error type that encompasses all possible SDK errors.
274
+ * Use the `name` property to discriminate between error types.
275
+ *
276
+ * @public
277
+ */
278
+ export type SdkError = SdkBadInputError | SdkInternalError;
279
+ export type SdkResponse<T> = {
280
+ isOk: true;
281
+ result: T;
282
+ } | {
283
+ isOk: false;
284
+ error: Error;
285
+ };
286
+ /**
287
+ * A result type that represents the result of a synchronous operation.
288
+ *
289
+ * This is the standard return type for sync SDK methods that can fail.
290
+ * It provides a type-safe way to handle both success and error cases without throwing.
291
+ *
292
+ * @typeParam T - The success value type
293
+ * @typeParam E - The error type
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * const result = someApi.syncOperation({ ... });
298
+ *
299
+ * if (result.isOk) {
300
+ * console.log('Success:', result.result);
301
+ * } else {
302
+ * console.error('Failed:', result.error.message);
303
+ * }
304
+ * ```
305
+ *
306
+ * @public
307
+ */
308
+ export type SdkResult<T, E = SdkError> = {
309
+ isOk: true;
310
+ result: T;
311
+ error?: never;
312
+ } | {
313
+ isOk: false;
314
+ result?: never;
315
+ error: E;
316
+ };
317
+ export type UploadType = (typeof UploadType)[keyof typeof UploadType];
318
+ /** Public SDK shape for shared file browser extensions, which run hidden. */
319
+ type SharedFileBrowserKittlSDK = KittlSDKLifecycle & KittlSDKSharedAPIs & {
320
+ /** Tab registration only: hidden file browsers get no host context. */
321
+ context: UploadBrowserRegistrationAPI;
322
+ } & KittlSDKFileBrowserAPI;
323
+
324
+ export {
325
+ SharedFileBrowserKittlSDK as KittlSDK,
326
+ };
327
+
328
+ export {};