@unisource/sdk 1.0.0 → 1.1.0-beta.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,126 @@
1
+ import { z } from "zod";
2
+ //#region src/primitives.ts
3
+ const nonEmptyString = z.string().trim().min(1);
4
+ const positiveInt = z.number().int().positive();
5
+ const nonNegativeInt = z.number().int().nonnegative();
6
+ const unixTimestamp = z.number().int().nonnegative();
7
+ const FILES_DEFAULT_LIMIT = 25;
8
+ /** Maximum items per list-page response (used by all v2 list endpoints). */
9
+ const LIST_MAX_LIMIT = 100;
10
+ /** @deprecated Use LIST_MAX_LIMIT — semantically applies to all v2 list endpoints, not just files. */
11
+ const FILES_MAX_LIMIT = 100;
12
+ /**
13
+ * Storage backend a file lives on.
14
+ * - 'r2' — Cloudflare R2 via presigned PUT / multipart
15
+ * - 'appwrite' — Appwrite Storage via direct browser SDK upload
16
+ *
17
+ * `recommendedUploadDestinationSchema` adds the meta-value 'hybrid' which is
18
+ * only valid as a service-wide setting (the upload manager picks r2/appwrite
19
+ * per-file based on size).
20
+ */
21
+ const uploadDestinationSchema = z.enum(["r2", "appwrite"]);
22
+ const recommendedUploadDestinationSchema = z.enum([
23
+ "r2",
24
+ "appwrite",
25
+ "hybrid"
26
+ ]);
27
+ const uploadStatusSchema = z.enum([
28
+ "pending",
29
+ "completed",
30
+ "failed"
31
+ ]);
32
+ const apiErrorSchema = z.object({
33
+ error: nonEmptyString,
34
+ message: nonEmptyString
35
+ });
36
+ //#endregion
37
+ //#region src/folders.ts
38
+ const folderSchema = z.object({
39
+ id: nonEmptyString,
40
+ service_id: nonEmptyString,
41
+ user_id: nonEmptyString,
42
+ parent_id: nonEmptyString.nullable(),
43
+ name: nonEmptyString,
44
+ color_tag: z.string().nullable(),
45
+ is_trashed: z.boolean(),
46
+ trashed_at: positiveInt.nullable(),
47
+ created_at: positiveInt,
48
+ updated_at: positiveInt
49
+ });
50
+ const folderListQuerySchema = z.object({
51
+ parent_id: nonEmptyString.nullable().optional(),
52
+ trashed: z.boolean().optional(),
53
+ is_trashed: z.boolean().optional(),
54
+ cursor: nonEmptyString.optional(),
55
+ limit: z.number().int().min(1).max(100).optional()
56
+ }).refine((v) => !(v.trashed !== void 0 && v.is_trashed !== void 0), { message: "Use either trashed or is_trashed, not both" });
57
+ const folderListResponseSchema = z.object({
58
+ items: z.array(folderSchema),
59
+ next_cursor: z.string().nullable(),
60
+ limit: positiveInt
61
+ });
62
+ const folderCreateRequestSchema = z.object({
63
+ name: nonEmptyString,
64
+ parent_id: nonEmptyString.optional(),
65
+ color_tag: z.string().optional()
66
+ });
67
+ const folderCreateResponseSchema = z.object({ folder: folderSchema });
68
+ const folderUpdateRequestSchema = z.object({
69
+ name: nonEmptyString.optional(),
70
+ color_tag: z.string().nullable().optional()
71
+ }).refine((v) => v.name !== void 0 || v.color_tag !== void 0, { message: "At least one of name or color_tag must be provided" });
72
+ const folderUpdateResponseSchema = z.object({ folder: folderSchema });
73
+ const folderDeleteResponseSchema = z.object({
74
+ success: z.literal(true),
75
+ id: nonEmptyString,
76
+ permanent: z.boolean(),
77
+ folders_deleted: z.number().int().nonnegative().optional()
78
+ });
79
+ const folderDetailResponseSchema = z.object({ folder: folderSchema });
80
+ const folderRestoreResponseSchema = z.object({
81
+ success: z.literal(true),
82
+ id: nonEmptyString
83
+ });
84
+ //#endregion
85
+ //#region src/v2/legacy-draft.ts
86
+ const fileRecordsListV2QuerySchema = z.object({
87
+ folder_id: nonEmptyString.nullable().optional().transform((v) => v === "null" ? null : v),
88
+ is_trashed: z.enum(["true", "false"]).transform((v) => v === "true").optional(),
89
+ search: z.string().optional(),
90
+ mime_type: z.string().optional(),
91
+ sort_by: z.enum([
92
+ "created_at",
93
+ "name",
94
+ "size"
95
+ ]).optional(),
96
+ sort_dir: z.enum(["asc", "desc"]).optional(),
97
+ cursor: nonEmptyString.optional(),
98
+ limit: z.coerce.number().int().min(1).max(100).optional()
99
+ });
100
+ const bulkFileIdsSchema = z.object({ ids: z.array(nonEmptyString).min(1).max(100) });
101
+ const bulkFileMoveRequestSchema = z.object({
102
+ ids: z.array(nonEmptyString).min(1).max(100),
103
+ folder_id: nonEmptyString.nullable().optional()
104
+ });
105
+ const bulkOperationResponseSchema = z.object({
106
+ success: z.boolean(),
107
+ processed_count: z.number().int().nonnegative(),
108
+ failed_ids: z.array(nonEmptyString).optional()
109
+ });
110
+ const folderListV2QuerySchema = z.object({
111
+ parent_id: nonEmptyString.nullable().optional().transform((v) => v === "null" ? null : v),
112
+ is_trashed: z.enum(["true", "false"]).transform((v) => v === "true").optional(),
113
+ search: z.string().optional(),
114
+ sort_by: z.enum(["created_at", "name"]).optional(),
115
+ sort_dir: z.enum(["asc", "desc"]).optional(),
116
+ cursor: nonEmptyString.optional(),
117
+ limit: z.coerce.number().int().min(1).max(100).optional()
118
+ });
119
+ const bulkFolderIdsSchema = z.object({ ids: z.array(nonEmptyString).min(1).max(100) });
120
+ const bulkFolderMoveRequestSchema = z.object({
121
+ ids: z.array(nonEmptyString).min(1).max(100),
122
+ parent_id: nonEmptyString.nullable().optional()
123
+ });
124
+ const folderBreadcrumbsResponseSchema = z.object({ breadcrumbs: z.array(folderSchema) });
125
+ //#endregion
126
+ export { nonEmptyString as C, unixTimestamp as D, recommendedUploadDestinationSchema as E, uploadDestinationSchema as O, apiErrorSchema as S, positiveInt as T, folderUpdateRequestSchema as _, bulkOperationResponseSchema as a, FILES_MAX_LIMIT as b, folderListV2QuerySchema as c, folderDeleteResponseSchema as d, folderDetailResponseSchema as f, folderSchema as g, folderRestoreResponseSchema as h, bulkFolderMoveRequestSchema as i, uploadStatusSchema as k, folderCreateRequestSchema as l, folderListResponseSchema as m, bulkFileMoveRequestSchema as n, fileRecordsListV2QuerySchema as o, folderListQuerySchema as p, bulkFolderIdsSchema as r, folderBreadcrumbsResponseSchema as s, bulkFileIdsSchema as t, folderCreateResponseSchema as u, folderUpdateResponseSchema as v, nonNegativeInt as w, LIST_MAX_LIMIT as x, FILES_DEFAULT_LIMIT as y };
@@ -0,0 +1,212 @@
1
+ import { a as BulkOperationResponse, c as FolderListV2Query, d as bulkFolderIdsSchema, f as bulkFolderMoveRequestSchema, g as folderListV2QuerySchema, h as folderBreadcrumbsResponseSchema, i as BulkFolderMoveRequest, l as bulkFileIdsSchema, m as fileRecordsListV2QuerySchema, n as BulkFileMoveRequest, o as FileRecordsListV2Query, p as bulkOperationResponseSchema, r as BulkFolderIds, s as FolderBreadcrumbsResponse, t as BulkFileIds, u as bulkFileMoveRequestSchema } from "../legacy-draft-7fqlx-KW.mjs";
2
+ import { z } from "zod";
3
+
4
+ //#region src/v2/types.d.ts
5
+ type SortBy = 'created_at' | 'updated_at' | 'name' | 'size';
6
+ type SortDir = 'asc' | 'desc';
7
+ type TrashFilter = 'active' | 'trashed' | 'all';
8
+ interface V2ListQuery {
9
+ folder_id?: string | null;
10
+ search?: string;
11
+ mime_type?: string;
12
+ trash?: TrashFilter;
13
+ sort_by?: SortBy;
14
+ sort_dir?: SortDir;
15
+ cursor?: string;
16
+ limit?: number;
17
+ }
18
+ interface V2Page {
19
+ limit: number;
20
+ next_cursor: string | null;
21
+ }
22
+ interface V2ListResponse<T> {
23
+ items: T[];
24
+ page: V2Page;
25
+ }
26
+ interface V2ErrorBody {
27
+ error: {
28
+ code: string;
29
+ message: string;
30
+ details?: unknown;
31
+ request_id: string;
32
+ };
33
+ }
34
+ //#endregion
35
+ //#region src/v2/files.d.ts
36
+ declare const v2FileSchema: z.ZodObject<{
37
+ id: z.ZodString;
38
+ service_id: z.ZodString;
39
+ user_id: z.ZodString;
40
+ folder_id: z.ZodNullable<z.ZodString>;
41
+ upload_id: z.ZodNullable<z.ZodString>;
42
+ filename: z.ZodString;
43
+ size: z.ZodNumber;
44
+ mime_type: z.ZodString;
45
+ storage_destination: z.ZodEnum<{
46
+ appwrite: "appwrite";
47
+ r2: "r2";
48
+ }>;
49
+ is_trashed: z.ZodBoolean;
50
+ trashed_at: z.ZodNullable<z.ZodNumber>;
51
+ created_at: z.ZodNumber;
52
+ updated_at: z.ZodNumber;
53
+ }, z.core.$strip>;
54
+ type V2File = z.infer<typeof v2FileSchema>;
55
+ //#endregion
56
+ //#region src/v2/folders.d.ts
57
+ declare const v2FolderSchema: z.ZodObject<{
58
+ id: z.ZodString;
59
+ service_id: z.ZodString;
60
+ user_id: z.ZodString;
61
+ parent_id: z.ZodNullable<z.ZodString>;
62
+ name: z.ZodString;
63
+ color_tag: z.ZodNullable<z.ZodString>;
64
+ is_trashed: z.ZodBoolean;
65
+ trashed_at: z.ZodNullable<z.ZodNumber>;
66
+ created_at: z.ZodNumber;
67
+ updated_at: z.ZodNumber;
68
+ }, z.core.$strip>;
69
+ type V2Folder = z.infer<typeof v2FolderSchema>;
70
+ declare const v2FolderListQuerySchema: z.ZodObject<{
71
+ parent_id: z.ZodOptional<z.ZodString>;
72
+ search: z.ZodOptional<z.ZodString>;
73
+ trash: z.ZodOptional<z.ZodEnum<{
74
+ active: "active";
75
+ all: "all";
76
+ trashed: "trashed";
77
+ }>>;
78
+ sort_by: z.ZodOptional<z.ZodEnum<{
79
+ created_at: "created_at";
80
+ name: "name";
81
+ updated_at: "updated_at";
82
+ }>>;
83
+ sort_dir: z.ZodOptional<z.ZodEnum<{
84
+ asc: "asc";
85
+ desc: "desc";
86
+ }>>;
87
+ cursor: z.ZodOptional<z.ZodString>;
88
+ limit: z.ZodOptional<z.ZodNumber>;
89
+ }, z.core.$strip>;
90
+ type V2FolderListQuery = z.infer<typeof v2FolderListQuerySchema>;
91
+ declare const v2FolderListResponseSchema: z.ZodObject<{
92
+ items: z.ZodArray<z.ZodObject<{
93
+ id: z.ZodString;
94
+ service_id: z.ZodString;
95
+ user_id: z.ZodString;
96
+ parent_id: z.ZodNullable<z.ZodString>;
97
+ name: z.ZodString;
98
+ color_tag: z.ZodNullable<z.ZodString>;
99
+ is_trashed: z.ZodBoolean;
100
+ trashed_at: z.ZodNullable<z.ZodNumber>;
101
+ created_at: z.ZodNumber;
102
+ updated_at: z.ZodNumber;
103
+ }, z.core.$strip>>;
104
+ page: z.ZodObject<{
105
+ limit: z.ZodNumber;
106
+ next_cursor: z.ZodNullable<z.ZodString>;
107
+ }, z.core.$strip>;
108
+ }, z.core.$strip>;
109
+ type V2FolderListResponse = z.infer<typeof v2FolderListResponseSchema>;
110
+ //#endregion
111
+ //#region src/v2/schemas.d.ts
112
+ declare const v2ListQuerySchema: z.ZodObject<{
113
+ folder_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
114
+ search: z.ZodOptional<z.ZodString>;
115
+ mime_type: z.ZodOptional<z.ZodString>;
116
+ trash: z.ZodOptional<z.ZodEnum<{
117
+ active: "active";
118
+ all: "all";
119
+ trashed: "trashed";
120
+ }>>;
121
+ sort_by: z.ZodOptional<z.ZodEnum<{
122
+ created_at: "created_at";
123
+ name: "name";
124
+ size: "size";
125
+ updated_at: "updated_at";
126
+ }>>;
127
+ sort_dir: z.ZodOptional<z.ZodEnum<{
128
+ asc: "asc";
129
+ desc: "desc";
130
+ }>>;
131
+ cursor: z.ZodOptional<z.ZodString>;
132
+ limit: z.ZodOptional<z.ZodNumber>;
133
+ }, z.core.$strip>;
134
+ declare const v2PageSchema: z.ZodObject<{
135
+ limit: z.ZodNumber;
136
+ next_cursor: z.ZodNullable<z.ZodString>;
137
+ }, z.core.$strip>;
138
+ declare function v2ListResponseSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
139
+ items: z.ZodArray<T>;
140
+ page: z.ZodObject<{
141
+ limit: z.ZodNumber;
142
+ next_cursor: z.ZodNullable<z.ZodString>;
143
+ }, z.core.$strip>;
144
+ }, z.core.$strip>;
145
+ declare const v2ErrorSchema: z.ZodObject<{
146
+ error: z.ZodObject<{
147
+ code: z.ZodString;
148
+ message: z.ZodString;
149
+ details: z.ZodOptional<z.ZodUnknown>;
150
+ request_id: z.ZodString;
151
+ }, z.core.$strip>;
152
+ }, z.core.$strip>;
153
+ declare const v2FilesListResponseSchema: z.ZodObject<{
154
+ items: z.ZodArray<z.ZodObject<{
155
+ id: z.ZodString;
156
+ service_id: z.ZodString;
157
+ user_id: z.ZodString;
158
+ folder_id: z.ZodNullable<z.ZodString>;
159
+ upload_id: z.ZodNullable<z.ZodString>;
160
+ filename: z.ZodString;
161
+ size: z.ZodNumber;
162
+ mime_type: z.ZodString;
163
+ storage_destination: z.ZodEnum<{
164
+ appwrite: "appwrite";
165
+ r2: "r2";
166
+ }>;
167
+ is_trashed: z.ZodBoolean;
168
+ trashed_at: z.ZodNullable<z.ZodNumber>;
169
+ created_at: z.ZodNumber;
170
+ updated_at: z.ZodNumber;
171
+ }, z.core.$strip>>;
172
+ page: z.ZodObject<{
173
+ limit: z.ZodNumber;
174
+ next_cursor: z.ZodNullable<z.ZodString>;
175
+ }, z.core.$strip>;
176
+ }, z.core.$strip>;
177
+ //#endregion
178
+ //#region src/v2/errors.d.ts
179
+ declare class UnisourceV2Error extends Error {
180
+ readonly status: number;
181
+ readonly code: string;
182
+ readonly requestId: string;
183
+ readonly details?: unknown;
184
+ constructor(message: string, status: number, code: string, requestId: string, details?: unknown);
185
+ }
186
+ //#endregion
187
+ //#region src/v2/client.d.ts
188
+ interface UnisourceV2ClientConfig {
189
+ baseUrl: string;
190
+ serviceId: string;
191
+ getToken: () => string | null | undefined | Promise<string | null | undefined>;
192
+ /** Set to true to suppress the beta warning in console */
193
+ silentBeta?: boolean;
194
+ }
195
+ declare class UnisourceV2Client {
196
+ private config;
197
+ constructor(config: UnisourceV2ClientConfig);
198
+ readonly files: {
199
+ list: (query?: V2ListQuery, signal?: AbortSignal, options?: {
200
+ asUser?: string;
201
+ }) => Promise<V2ListResponse<V2File>>;
202
+ };
203
+ readonly folders: {
204
+ list: (query?: V2FolderListQuery, signal?: AbortSignal, options?: {
205
+ asUser?: string;
206
+ }) => Promise<V2FolderListResponse>;
207
+ };
208
+ private _filesList;
209
+ private _foldersList;
210
+ }
211
+ //#endregion
212
+ export { BulkFileIds, BulkFileMoveRequest, BulkFolderIds, BulkFolderMoveRequest, BulkOperationResponse, FileRecordsListV2Query, FolderBreadcrumbsResponse, FolderListV2Query, SortBy, SortDir, TrashFilter, UnisourceV2Client, type UnisourceV2ClientConfig, UnisourceV2Error, V2ErrorBody, V2File, V2Folder, V2FolderListQuery, V2FolderListResponse, V2ListQuery, V2ListResponse, V2Page, bulkFileIdsSchema, bulkFileMoveRequestSchema, bulkFolderIdsSchema, bulkFolderMoveRequestSchema, bulkOperationResponseSchema, fileRecordsListV2QuerySchema, folderBreadcrumbsResponseSchema, folderListV2QuerySchema, v2ErrorSchema, v2FileSchema, v2FilesListResponseSchema, v2FolderListQuerySchema, v2FolderListResponseSchema, v2FolderSchema, v2ListQuerySchema, v2ListResponseSchema, v2PageSchema };
@@ -0,0 +1,194 @@
1
+ import { a as bulkOperationResponseSchema, c as folderListV2QuerySchema, i as bulkFolderMoveRequestSchema, n as bulkFileMoveRequestSchema, o as fileRecordsListV2QuerySchema, r as bulkFolderIdsSchema, s as folderBreadcrumbsResponseSchema, t as bulkFileIdsSchema } from "../legacy-draft-D0hgtTqN.mjs";
2
+ import { z } from "zod";
3
+ //#region src/v2/files.ts
4
+ const v2FileSchema = z.object({
5
+ id: z.string(),
6
+ service_id: z.string(),
7
+ user_id: z.string(),
8
+ folder_id: z.string().nullable(),
9
+ upload_id: z.string().nullable(),
10
+ filename: z.string(),
11
+ size: z.number(),
12
+ mime_type: z.string(),
13
+ storage_destination: z.enum(["r2", "appwrite"]),
14
+ is_trashed: z.boolean(),
15
+ trashed_at: z.number().nullable(),
16
+ created_at: z.number(),
17
+ updated_at: z.number()
18
+ });
19
+ //#endregion
20
+ //#region src/v2/schemas.ts
21
+ const v2ListQuerySchema = z.object({
22
+ folder_id: z.string().nullable().optional(),
23
+ search: z.string().optional(),
24
+ mime_type: z.string().optional(),
25
+ trash: z.enum([
26
+ "active",
27
+ "trashed",
28
+ "all"
29
+ ]).optional(),
30
+ sort_by: z.enum([
31
+ "created_at",
32
+ "updated_at",
33
+ "name",
34
+ "size"
35
+ ]).optional(),
36
+ sort_dir: z.enum(["asc", "desc"]).optional(),
37
+ cursor: z.string().optional(),
38
+ limit: z.number().int().min(1).optional()
39
+ });
40
+ const v2PageSchema = z.object({
41
+ limit: z.number(),
42
+ next_cursor: z.string().nullable()
43
+ });
44
+ function v2ListResponseSchema(itemSchema) {
45
+ return z.object({
46
+ items: z.array(itemSchema),
47
+ page: v2PageSchema
48
+ });
49
+ }
50
+ const v2ErrorSchema = z.object({ error: z.object({
51
+ code: z.string(),
52
+ message: z.string(),
53
+ details: z.unknown().optional(),
54
+ request_id: z.string()
55
+ }) });
56
+ const v2FilesListResponseSchema = v2ListResponseSchema(v2FileSchema);
57
+ //#endregion
58
+ //#region src/v2/folders.ts
59
+ const v2FolderSchema = z.object({
60
+ id: z.string(),
61
+ service_id: z.string(),
62
+ user_id: z.string(),
63
+ parent_id: z.string().nullable(),
64
+ name: z.string(),
65
+ color_tag: z.string().nullable(),
66
+ is_trashed: z.boolean(),
67
+ trashed_at: z.number().nullable(),
68
+ created_at: z.number(),
69
+ updated_at: z.number()
70
+ });
71
+ const v2FolderListQuerySchema = z.object({
72
+ parent_id: z.string().optional(),
73
+ search: z.string().max(100).optional(),
74
+ trash: z.enum([
75
+ "active",
76
+ "trashed",
77
+ "all"
78
+ ]).optional(),
79
+ sort_by: z.enum([
80
+ "created_at",
81
+ "updated_at",
82
+ "name"
83
+ ]).optional(),
84
+ sort_dir: z.enum(["asc", "desc"]).optional(),
85
+ cursor: z.string().optional(),
86
+ limit: z.number().int().min(1).max(100).optional()
87
+ });
88
+ const v2FolderListResponseSchema = v2ListResponseSchema(v2FolderSchema);
89
+ //#endregion
90
+ //#region src/v2/errors.ts
91
+ var UnisourceV2Error = class extends Error {
92
+ constructor(message, status, code, requestId, details) {
93
+ super(message);
94
+ this.status = status;
95
+ this.code = code;
96
+ this.requestId = requestId;
97
+ this.details = details;
98
+ this.name = "UnisourceV2Error";
99
+ }
100
+ };
101
+ //#endregion
102
+ //#region src/v2/client.ts
103
+ let warned = false;
104
+ function parseErrorBody(value) {
105
+ if (!value || typeof value !== "object") return {};
106
+ const error = value.error;
107
+ if (!error || typeof error !== "object") return {};
108
+ const payload = error;
109
+ return { error: {
110
+ code: typeof payload.code === "string" ? payload.code : void 0,
111
+ message: typeof payload.message === "string" ? payload.message : void 0,
112
+ details: payload.details
113
+ } };
114
+ }
115
+ var UnisourceV2Client = class {
116
+ config;
117
+ constructor(config) {
118
+ this.config = config;
119
+ if (!warned && !config.silentBeta) {
120
+ console.warn("[unisource-sdk] V2 API is in beta. Breaking changes possible. See https://docs.unisource.example/v2 for stability commitments.");
121
+ warned = true;
122
+ }
123
+ }
124
+ files = { list: (query, signal, options) => this._filesList(query, signal, options) };
125
+ folders = { list: (query, signal, options) => this._foldersList(query, signal, options) };
126
+ async _filesList(query, signal, options) {
127
+ const token = await this.config.getToken();
128
+ const headers = { "X-Service-ID": this.config.serviceId };
129
+ if (token) headers["Authorization"] = `Bearer ${token}`;
130
+ if (options?.asUser) headers["X-Target-User-ID"] = options.asUser;
131
+ const url = new URL("/v2/files", this.config.baseUrl);
132
+ if (query) for (const [k, v] of Object.entries(query)) {
133
+ if (v === void 0) continue;
134
+ url.searchParams.set(k, v === null ? "null" : String(v));
135
+ }
136
+ let response;
137
+ try {
138
+ response = await fetch(url.toString(), {
139
+ method: "GET",
140
+ headers,
141
+ signal
142
+ });
143
+ } catch (err) {
144
+ throw new Error(`Network request failed: ${err}`);
145
+ }
146
+ if (!response.ok) {
147
+ const requestId = response.headers.get("X-Request-Id") ?? "unknown";
148
+ let body;
149
+ try {
150
+ body = parseErrorBody(await response.json());
151
+ } catch {
152
+ body = {};
153
+ }
154
+ throw new UnisourceV2Error(body.error?.message ?? response.statusText, response.status, body.error?.code ?? "unknown", requestId, body.error?.details);
155
+ }
156
+ const data = await response.json();
157
+ return v2ListResponseSchema(v2FileSchema).parse(data);
158
+ }
159
+ async _foldersList(query, signal, options) {
160
+ const token = await this.config.getToken();
161
+ const headers = { "X-Service-ID": this.config.serviceId };
162
+ if (token) headers["Authorization"] = `Bearer ${token}`;
163
+ if (options?.asUser) headers["X-Target-User-ID"] = options.asUser;
164
+ const url = new URL("/v2/folders", this.config.baseUrl);
165
+ if (query) for (const [k, v] of Object.entries(query)) {
166
+ if (v === void 0) continue;
167
+ url.searchParams.set(k, v === null ? "null" : String(v));
168
+ }
169
+ let response;
170
+ try {
171
+ response = await fetch(url.toString(), {
172
+ method: "GET",
173
+ headers,
174
+ signal
175
+ });
176
+ } catch (err) {
177
+ throw new Error(`Network request failed: ${err}`);
178
+ }
179
+ if (!response.ok) {
180
+ const requestId = response.headers.get("X-Request-Id") ?? "unknown";
181
+ let body;
182
+ try {
183
+ body = parseErrorBody(await response.json());
184
+ } catch {
185
+ body = {};
186
+ }
187
+ throw new UnisourceV2Error(body.error?.message ?? response.statusText, response.status, body.error?.code ?? "unknown", requestId, body.error?.details);
188
+ }
189
+ const data = await response.json();
190
+ return v2FolderListResponseSchema.parse(data);
191
+ }
192
+ };
193
+ //#endregion
194
+ export { UnisourceV2Client, UnisourceV2Error, bulkFileIdsSchema, bulkFileMoveRequestSchema, bulkFolderIdsSchema, bulkFolderMoveRequestSchema, bulkOperationResponseSchema, fileRecordsListV2QuerySchema, folderBreadcrumbsResponseSchema, folderListV2QuerySchema, v2ErrorSchema, v2FileSchema, v2FilesListResponseSchema, v2FolderListQuerySchema, v2FolderListResponseSchema, v2FolderSchema, v2ListQuerySchema, v2ListResponseSchema, v2PageSchema };
package/package.json CHANGED
@@ -2,14 +2,9 @@
2
2
  "name": "@unisource/sdk",
3
3
  "private": false,
4
4
  "type": "module",
5
- "version": "1.0.0",
5
+ "version": "1.1.0-beta.1",
6
6
  "description": "Wspolne kontrakty danych dla backendu i frontendu UniSource.",
7
7
  "license": "MIT",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/Dan1el-19/UniSource.git",
11
- "directory": "packages/unisource-sdk"
12
- },
13
8
  "publishConfig": {
14
9
  "access": "public"
15
10
  },
@@ -19,13 +14,24 @@
19
14
  "import": "./dist/index.mjs",
20
15
  "default": "./dist/index.mjs"
21
16
  },
17
+ "./v2": {
18
+ "types": "./dist/v2/index.d.mts",
19
+ "import": "./dist/v2/index.mjs",
20
+ "default": "./dist/v2/index.mjs"
21
+ },
22
22
  "./package.json": "./package.json"
23
23
  },
24
24
  "types": "./dist/index.d.mts",
25
25
  "files": [
26
- "dist",
27
- "src"
26
+ "dist"
28
27
  ],
28
+ "scripts": {
29
+ "build": "tsdown",
30
+ "dev": "tsdown --watch",
31
+ "test": "pnpm run build && vitest",
32
+ "typecheck": "tsc --noEmit",
33
+ "prepublishOnly": "pnpm run build"
34
+ },
29
35
  "devDependencies": {
30
36
  "@types/node": "^25.5.0",
31
37
  "@typescript/native-preview": "7.0.0-dev.20260328.1",
@@ -36,10 +42,9 @@
36
42
  "dependencies": {
37
43
  "zod": "^4.3.6"
38
44
  },
39
- "scripts": {
40
- "build": "tsdown",
41
- "dev": "tsdown --watch",
42
- "test": "pnpm run build && vitest",
43
- "typecheck": "tsc --noEmit"
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/Dan1el-19/UniSource.git",
48
+ "directory": "packages/unisource-sdk"
44
49
  }
45
- }
50
+ }