@sybil-studio-devs/sdk 0.1.0 → 0.2.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/README.md +433 -146
- package/dist/atlas/index.d.mts +28 -0
- package/dist/atlas/index.d.ts +28 -0
- package/dist/atlas/index.js +418 -0
- package/dist/atlas/index.mjs +8 -0
- package/dist/chunk-B6RXZKRY.mjs +391 -0
- package/dist/chunk-IN53AFMQ.mjs +348 -0
- package/dist/chunk-MM27YV6Z.mjs +668 -0
- package/dist/client-BPFcAPV8.d.mts +428 -0
- package/dist/client-BPFcAPV8.d.ts +428 -0
- package/dist/index.d.mts +8 -394
- package/dist/index.d.ts +8 -394
- package/dist/index.js +1159 -7
- package/dist/index.mjs +19 -252
- package/dist/nexus/index.d.mts +34 -0
- package/dist/nexus/index.d.ts +34 -0
- package/dist/nexus/index.js +695 -0
- package/dist/nexus/index.mjs +8 -0
- package/dist/react/index.d.mts +235 -0
- package/dist/react/index.d.ts +235 -0
- package/dist/react/index.js +2354 -0
- package/dist/react/index.mjs +935 -0
- package/dist/types-BjxgQxBW.d.mts +182 -0
- package/dist/types-BjxgQxBW.d.ts +182 -0
- package/dist/types-DVY5_vpY.d.mts +258 -0
- package/dist/types-DVY5_vpY.d.ts +258 -0
- package/package.json +33 -5
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { f as AtlasEmbedConfig, k as AtlasInstance, d as AtlasSidebarData, a as AtlasPage, C as CreateAtlasPageParams, U as UpdateAtlasPageParams, i as AtlasLogEntry } from '../types-BjxgQxBW.mjs';
|
|
2
|
+
export { m as AtlasAPIError, l as AtlasAPIResponse, b as AtlasBlock, j as AtlasError, g as AtlasFeatures, h as AtlasLoggingConfig, e as AtlasSidebarPage, c as AtlasTeamspace, A as AtlasTheme } from '../types-BjxgQxBW.mjs';
|
|
3
|
+
|
|
4
|
+
declare function embedAtlas(config: AtlasEmbedConfig): AtlasInstance;
|
|
5
|
+
declare class AtlasClient {
|
|
6
|
+
private apiKey;
|
|
7
|
+
private baseUrl;
|
|
8
|
+
private workspaceId;
|
|
9
|
+
private logger;
|
|
10
|
+
constructor(config: {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
workspaceId: string;
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
logging?: AtlasEmbedConfig['logging'];
|
|
15
|
+
});
|
|
16
|
+
private request;
|
|
17
|
+
getSidebar(): Promise<AtlasSidebarData>;
|
|
18
|
+
getPage(pageId: string): Promise<AtlasPage>;
|
|
19
|
+
createPage(params?: CreateAtlasPageParams): Promise<AtlasPage>;
|
|
20
|
+
updatePage(pageId: string, params: UpdateAtlasPageParams): Promise<AtlasPage>;
|
|
21
|
+
deletePage(pageId: string): Promise<void>;
|
|
22
|
+
exportPage(pageId: string, format: 'pdf' | 'docx' | 'md'): Promise<Blob>;
|
|
23
|
+
toggleFavorite(pageId: string): Promise<AtlasPage>;
|
|
24
|
+
getLogs(): AtlasLogEntry[];
|
|
25
|
+
clearLogs(): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { AtlasClient, AtlasEmbedConfig, AtlasInstance, AtlasLogEntry, AtlasPage, AtlasSidebarData, CreateAtlasPageParams, UpdateAtlasPageParams, embedAtlas };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { f as AtlasEmbedConfig, k as AtlasInstance, d as AtlasSidebarData, a as AtlasPage, C as CreateAtlasPageParams, U as UpdateAtlasPageParams, i as AtlasLogEntry } from '../types-BjxgQxBW.js';
|
|
2
|
+
export { m as AtlasAPIError, l as AtlasAPIResponse, b as AtlasBlock, j as AtlasError, g as AtlasFeatures, h as AtlasLoggingConfig, e as AtlasSidebarPage, c as AtlasTeamspace, A as AtlasTheme } from '../types-BjxgQxBW.js';
|
|
3
|
+
|
|
4
|
+
declare function embedAtlas(config: AtlasEmbedConfig): AtlasInstance;
|
|
5
|
+
declare class AtlasClient {
|
|
6
|
+
private apiKey;
|
|
7
|
+
private baseUrl;
|
|
8
|
+
private workspaceId;
|
|
9
|
+
private logger;
|
|
10
|
+
constructor(config: {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
workspaceId: string;
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
logging?: AtlasEmbedConfig['logging'];
|
|
15
|
+
});
|
|
16
|
+
private request;
|
|
17
|
+
getSidebar(): Promise<AtlasSidebarData>;
|
|
18
|
+
getPage(pageId: string): Promise<AtlasPage>;
|
|
19
|
+
createPage(params?: CreateAtlasPageParams): Promise<AtlasPage>;
|
|
20
|
+
updatePage(pageId: string, params: UpdateAtlasPageParams): Promise<AtlasPage>;
|
|
21
|
+
deletePage(pageId: string): Promise<void>;
|
|
22
|
+
exportPage(pageId: string, format: 'pdf' | 'docx' | 'md'): Promise<Blob>;
|
|
23
|
+
toggleFavorite(pageId: string): Promise<AtlasPage>;
|
|
24
|
+
getLogs(): AtlasLogEntry[];
|
|
25
|
+
clearLogs(): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { AtlasClient, AtlasEmbedConfig, AtlasInstance, AtlasLogEntry, AtlasPage, AtlasSidebarData, CreateAtlasPageParams, UpdateAtlasPageParams, embedAtlas };
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/atlas/index.ts
|
|
21
|
+
var atlas_exports = {};
|
|
22
|
+
__export(atlas_exports, {
|
|
23
|
+
AtlasClient: () => AtlasClient,
|
|
24
|
+
embedAtlas: () => embedAtlas
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(atlas_exports);
|
|
27
|
+
|
|
28
|
+
// src/atlas/client.ts
|
|
29
|
+
var DEFAULT_BASE_URL = "https://app.sybil.studio";
|
|
30
|
+
var AtlasLogger = class {
|
|
31
|
+
constructor(config) {
|
|
32
|
+
this.logs = [];
|
|
33
|
+
this.config = config;
|
|
34
|
+
}
|
|
35
|
+
log(level, category, message, data, duration) {
|
|
36
|
+
if (!this.config?.enabled) return;
|
|
37
|
+
const levels = ["debug", "info", "warn", "error"];
|
|
38
|
+
const configLevel = this.config.level || "info";
|
|
39
|
+
if (levels.indexOf(level) < levels.indexOf(configLevel)) return;
|
|
40
|
+
const entry = {
|
|
41
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
42
|
+
level,
|
|
43
|
+
category,
|
|
44
|
+
message,
|
|
45
|
+
data,
|
|
46
|
+
duration
|
|
47
|
+
};
|
|
48
|
+
this.logs.push(entry);
|
|
49
|
+
this.config.onLog?.(entry);
|
|
50
|
+
if (typeof console !== "undefined") {
|
|
51
|
+
const prefix = `[Atlas SDK] [${category}]`;
|
|
52
|
+
switch (level) {
|
|
53
|
+
case "debug":
|
|
54
|
+
console.debug(prefix, message, data || "");
|
|
55
|
+
break;
|
|
56
|
+
case "info":
|
|
57
|
+
console.info(prefix, message, data || "");
|
|
58
|
+
break;
|
|
59
|
+
case "warn":
|
|
60
|
+
console.warn(prefix, message, data || "");
|
|
61
|
+
break;
|
|
62
|
+
case "error":
|
|
63
|
+
console.error(prefix, message, data || "");
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
getLogs() {
|
|
69
|
+
return [...this.logs];
|
|
70
|
+
}
|
|
71
|
+
clearLogs() {
|
|
72
|
+
this.logs = [];
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function embedAtlas(config) {
|
|
76
|
+
const {
|
|
77
|
+
apiKey,
|
|
78
|
+
workspaceId,
|
|
79
|
+
container,
|
|
80
|
+
baseUrl = DEFAULT_BASE_URL,
|
|
81
|
+
theme = "dark",
|
|
82
|
+
showSidebar = true,
|
|
83
|
+
sidebarWidth = 260,
|
|
84
|
+
sidebarCollapsible = true,
|
|
85
|
+
readOnly = false,
|
|
86
|
+
defaultPageId,
|
|
87
|
+
allowCreate = true,
|
|
88
|
+
allowDelete = true,
|
|
89
|
+
allowExport = true,
|
|
90
|
+
features = {},
|
|
91
|
+
logging,
|
|
92
|
+
onReady,
|
|
93
|
+
onPageChange,
|
|
94
|
+
onPageCreate,
|
|
95
|
+
onPageDelete,
|
|
96
|
+
onPageUpdate,
|
|
97
|
+
onError,
|
|
98
|
+
onNavigate
|
|
99
|
+
} = config;
|
|
100
|
+
const logger = new AtlasLogger(logging);
|
|
101
|
+
const startTime = Date.now();
|
|
102
|
+
logger.log("info", "render", "Initializing Atlas embed", {
|
|
103
|
+
workspaceId,
|
|
104
|
+
showSidebar,
|
|
105
|
+
readOnly,
|
|
106
|
+
features
|
|
107
|
+
});
|
|
108
|
+
const containerEl = typeof container === "string" ? document.querySelector(container) : container;
|
|
109
|
+
if (!containerEl) {
|
|
110
|
+
const error = {
|
|
111
|
+
code: "CONTAINER_NOT_FOUND",
|
|
112
|
+
message: "Container element not found",
|
|
113
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
114
|
+
};
|
|
115
|
+
onError?.(error);
|
|
116
|
+
throw new Error(error.message);
|
|
117
|
+
}
|
|
118
|
+
const params = new URLSearchParams({
|
|
119
|
+
apiKey,
|
|
120
|
+
workspaceId,
|
|
121
|
+
readOnly: readOnly.toString(),
|
|
122
|
+
showSidebar: showSidebar.toString(),
|
|
123
|
+
sidebarWidth: sidebarWidth.toString(),
|
|
124
|
+
sidebarCollapsible: sidebarCollapsible.toString(),
|
|
125
|
+
allowCreate: allowCreate.toString(),
|
|
126
|
+
allowDelete: allowDelete.toString(),
|
|
127
|
+
allowExport: allowExport.toString()
|
|
128
|
+
});
|
|
129
|
+
if (defaultPageId) params.set("defaultPageId", defaultPageId);
|
|
130
|
+
if (typeof theme === "string") {
|
|
131
|
+
params.set("theme", theme);
|
|
132
|
+
} else {
|
|
133
|
+
Object.entries(theme).forEach(([key, value]) => {
|
|
134
|
+
if (value) params.set(`theme_${key}`, value);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
Object.entries(features).forEach(([key, value]) => {
|
|
138
|
+
if (typeof value === "boolean") {
|
|
139
|
+
params.set(`feature_${key}`, value.toString());
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const iframe = document.createElement("iframe");
|
|
143
|
+
iframe.src = `${baseUrl}/embed/atlas?${params.toString()}`;
|
|
144
|
+
iframe.style.width = "100%";
|
|
145
|
+
iframe.style.height = "100%";
|
|
146
|
+
iframe.style.border = "none";
|
|
147
|
+
iframe.style.borderRadius = "8px";
|
|
148
|
+
iframe.allow = "clipboard-write";
|
|
149
|
+
let currentPage = null;
|
|
150
|
+
let isReady = false;
|
|
151
|
+
const createError = (code, message, status) => ({
|
|
152
|
+
code,
|
|
153
|
+
message,
|
|
154
|
+
status,
|
|
155
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
156
|
+
requestId: `req_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
|
|
157
|
+
});
|
|
158
|
+
const apiRequest = async (endpoint, options = {}) => {
|
|
159
|
+
const requestStart = Date.now();
|
|
160
|
+
const url = `${baseUrl}/api/sdk/v1${endpoint}`;
|
|
161
|
+
logger.log("debug", "api", `Request: ${options.method || "GET"} ${endpoint}`, {
|
|
162
|
+
url,
|
|
163
|
+
method: options.method || "GET"
|
|
164
|
+
});
|
|
165
|
+
try {
|
|
166
|
+
const response = await fetch(url, {
|
|
167
|
+
...options,
|
|
168
|
+
headers: {
|
|
169
|
+
"x-api-key": apiKey,
|
|
170
|
+
"Content-Type": "application/json",
|
|
171
|
+
...options.headers
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
const duration = Date.now() - requestStart;
|
|
175
|
+
if (!response.ok) {
|
|
176
|
+
const errorData = await response.json().catch(() => ({}));
|
|
177
|
+
const error = createError(
|
|
178
|
+
errorData.error?.code || "API_ERROR",
|
|
179
|
+
errorData.error?.message || `Request failed with status ${response.status}`,
|
|
180
|
+
response.status
|
|
181
|
+
);
|
|
182
|
+
logger.log("error", "api", `Request failed: ${endpoint}`, {
|
|
183
|
+
status: response.status,
|
|
184
|
+
error: errorData
|
|
185
|
+
}, duration);
|
|
186
|
+
onError?.(error);
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
const data = await response.json();
|
|
190
|
+
logger.log("debug", "api", `Response: ${endpoint}`, { status: response.status }, duration);
|
|
191
|
+
return data;
|
|
192
|
+
} catch (err) {
|
|
193
|
+
if (err.code) throw err;
|
|
194
|
+
const error = createError("NETWORK_ERROR", err.message);
|
|
195
|
+
logger.log("error", "api", "Network error", { error: err.message });
|
|
196
|
+
onError?.(error);
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
const postMessage = (type, payload) => {
|
|
201
|
+
iframe.contentWindow?.postMessage({ type, ...payload }, baseUrl);
|
|
202
|
+
};
|
|
203
|
+
const handleMessage = (event) => {
|
|
204
|
+
if (event.origin !== new URL(baseUrl).origin) return;
|
|
205
|
+
const { type, ...data } = event.data || {};
|
|
206
|
+
logger.log("debug", "render", `Message received: ${type}`, data);
|
|
207
|
+
switch (type) {
|
|
208
|
+
case "sybil:atlas:ready":
|
|
209
|
+
isReady = true;
|
|
210
|
+
logger.log("info", "render", "Atlas embed ready", {}, Date.now() - startTime);
|
|
211
|
+
onReady?.(instance);
|
|
212
|
+
break;
|
|
213
|
+
case "sybil:atlas:page:changed":
|
|
214
|
+
currentPage = data.page;
|
|
215
|
+
logger.log("info", "navigation", "Page changed", { pageId: data.page?.id });
|
|
216
|
+
onPageChange?.(data.page);
|
|
217
|
+
break;
|
|
218
|
+
case "sybil:atlas:page:created":
|
|
219
|
+
logger.log("info", "editor", "Page created", { pageId: data.page?.id });
|
|
220
|
+
onPageCreate?.(data.page);
|
|
221
|
+
break;
|
|
222
|
+
case "sybil:atlas:page:deleted":
|
|
223
|
+
logger.log("info", "editor", "Page deleted", { pageId: data.pageId });
|
|
224
|
+
onPageDelete?.(data.pageId);
|
|
225
|
+
break;
|
|
226
|
+
case "sybil:atlas:page:updated":
|
|
227
|
+
currentPage = data.page;
|
|
228
|
+
logger.log("debug", "sync", "Page updated", { pageId: data.page?.id });
|
|
229
|
+
onPageUpdate?.(data.page);
|
|
230
|
+
break;
|
|
231
|
+
case "sybil:atlas:navigate":
|
|
232
|
+
logger.log("info", "navigation", "Navigation requested", { pageId: data.pageId });
|
|
233
|
+
onNavigate?.(data.pageId);
|
|
234
|
+
break;
|
|
235
|
+
case "sybil:atlas:error":
|
|
236
|
+
const error = createError(data.code || "EMBED_ERROR", data.message);
|
|
237
|
+
logger.log("error", "render", "Embed error", data);
|
|
238
|
+
onError?.(error);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
window.addEventListener("message", handleMessage);
|
|
243
|
+
containerEl.appendChild(iframe);
|
|
244
|
+
const instance = {
|
|
245
|
+
getPages: async () => {
|
|
246
|
+
logger.log("info", "api", "Fetching pages");
|
|
247
|
+
const response = await apiRequest(
|
|
248
|
+
`/atlas/workspaces/${workspaceId}/sidebar`
|
|
249
|
+
);
|
|
250
|
+
return response.sidebar;
|
|
251
|
+
},
|
|
252
|
+
getPage: async (pageId) => {
|
|
253
|
+
logger.log("info", "api", "Fetching page", { pageId });
|
|
254
|
+
const response = await apiRequest(
|
|
255
|
+
`/atlas/pages/${pageId}`
|
|
256
|
+
);
|
|
257
|
+
return response.page;
|
|
258
|
+
},
|
|
259
|
+
createPage: async (params2) => {
|
|
260
|
+
logger.log("info", "api", "Creating page", params2);
|
|
261
|
+
const response = await apiRequest(
|
|
262
|
+
`/atlas/workspaces/${workspaceId}/pages`,
|
|
263
|
+
{
|
|
264
|
+
method: "POST",
|
|
265
|
+
body: JSON.stringify(params2)
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
postMessage("sybil:atlas:refresh");
|
|
269
|
+
return response.page;
|
|
270
|
+
},
|
|
271
|
+
updatePage: async (pageId, params2) => {
|
|
272
|
+
logger.log("info", "api", "Updating page", { pageId, ...params2 });
|
|
273
|
+
const response = await apiRequest(
|
|
274
|
+
`/atlas/pages/${pageId}`,
|
|
275
|
+
{
|
|
276
|
+
method: "PUT",
|
|
277
|
+
body: JSON.stringify(params2)
|
|
278
|
+
}
|
|
279
|
+
);
|
|
280
|
+
postMessage("sybil:atlas:refresh");
|
|
281
|
+
return response.page;
|
|
282
|
+
},
|
|
283
|
+
deletePage: async (pageId) => {
|
|
284
|
+
logger.log("info", "api", "Deleting page", { pageId });
|
|
285
|
+
await apiRequest(`/atlas/pages/${pageId}`, { method: "DELETE" });
|
|
286
|
+
postMessage("sybil:atlas:refresh");
|
|
287
|
+
},
|
|
288
|
+
navigateTo: (pageId) => {
|
|
289
|
+
logger.log("info", "navigation", "Navigating to page", { pageId });
|
|
290
|
+
postMessage("sybil:atlas:navigate", { pageId });
|
|
291
|
+
},
|
|
292
|
+
getCurrentPage: () => currentPage,
|
|
293
|
+
exportPage: async (pageId, format) => {
|
|
294
|
+
logger.log("info", "api", "Exporting page", { pageId, format });
|
|
295
|
+
const response = await fetch(
|
|
296
|
+
`${baseUrl}/api/sdk/v1/atlas/pages/${pageId}/export?format=${format}`,
|
|
297
|
+
{
|
|
298
|
+
headers: { "x-api-key": apiKey }
|
|
299
|
+
}
|
|
300
|
+
);
|
|
301
|
+
if (!response.ok) {
|
|
302
|
+
const error = createError("EXPORT_FAILED", "Failed to export page");
|
|
303
|
+
onError?.(error);
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
return response.blob();
|
|
307
|
+
},
|
|
308
|
+
toggleSidebar: () => {
|
|
309
|
+
logger.log("debug", "render", "Toggling sidebar");
|
|
310
|
+
postMessage("sybil:atlas:toggleSidebar");
|
|
311
|
+
},
|
|
312
|
+
setSidebarWidth: (width) => {
|
|
313
|
+
logger.log("debug", "render", "Setting sidebar width", { width });
|
|
314
|
+
postMessage("sybil:atlas:setSidebarWidth", { width });
|
|
315
|
+
},
|
|
316
|
+
setTheme: (newTheme) => {
|
|
317
|
+
logger.log("debug", "render", "Setting theme", { theme: newTheme });
|
|
318
|
+
postMessage("sybil:atlas:setTheme", { theme: newTheme });
|
|
319
|
+
},
|
|
320
|
+
refresh: async () => {
|
|
321
|
+
logger.log("info", "sync", "Refreshing");
|
|
322
|
+
postMessage("sybil:atlas:refresh");
|
|
323
|
+
},
|
|
324
|
+
destroy: () => {
|
|
325
|
+
logger.log("info", "render", "Destroying Atlas embed");
|
|
326
|
+
window.removeEventListener("message", handleMessage);
|
|
327
|
+
iframe.remove();
|
|
328
|
+
},
|
|
329
|
+
getLogs: () => logger.getLogs(),
|
|
330
|
+
clearLogs: () => logger.clearLogs()
|
|
331
|
+
};
|
|
332
|
+
return instance;
|
|
333
|
+
}
|
|
334
|
+
var AtlasClient = class {
|
|
335
|
+
constructor(config) {
|
|
336
|
+
this.apiKey = config.apiKey;
|
|
337
|
+
this.workspaceId = config.workspaceId;
|
|
338
|
+
this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
|
|
339
|
+
this.logger = new AtlasLogger(config.logging);
|
|
340
|
+
}
|
|
341
|
+
async request(endpoint, options = {}) {
|
|
342
|
+
const url = `${this.baseUrl}/api/sdk/v1${endpoint}`;
|
|
343
|
+
const startTime = Date.now();
|
|
344
|
+
this.logger.log("debug", "api", `Request: ${options.method || "GET"} ${endpoint}`);
|
|
345
|
+
const response = await fetch(url, {
|
|
346
|
+
...options,
|
|
347
|
+
headers: {
|
|
348
|
+
"x-api-key": this.apiKey,
|
|
349
|
+
"Content-Type": "application/json",
|
|
350
|
+
...options.headers
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
const duration = Date.now() - startTime;
|
|
354
|
+
if (!response.ok) {
|
|
355
|
+
const errorData = await response.json().catch(() => ({}));
|
|
356
|
+
this.logger.log("error", "api", `Request failed: ${endpoint}`, {
|
|
357
|
+
status: response.status,
|
|
358
|
+
error: errorData
|
|
359
|
+
}, duration);
|
|
360
|
+
throw new Error(errorData.error?.message || `Request failed with status ${response.status}`);
|
|
361
|
+
}
|
|
362
|
+
this.logger.log("debug", "api", `Response: ${endpoint}`, { status: response.status }, duration);
|
|
363
|
+
return response.json();
|
|
364
|
+
}
|
|
365
|
+
async getSidebar() {
|
|
366
|
+
const response = await this.request(
|
|
367
|
+
`/atlas/workspaces/${this.workspaceId}/sidebar`
|
|
368
|
+
);
|
|
369
|
+
return response.sidebar;
|
|
370
|
+
}
|
|
371
|
+
async getPage(pageId) {
|
|
372
|
+
const response = await this.request(`/atlas/pages/${pageId}`);
|
|
373
|
+
return response.page;
|
|
374
|
+
}
|
|
375
|
+
async createPage(params = {}) {
|
|
376
|
+
const response = await this.request(
|
|
377
|
+
`/atlas/workspaces/${this.workspaceId}/pages`,
|
|
378
|
+
{ method: "POST", body: JSON.stringify(params) }
|
|
379
|
+
);
|
|
380
|
+
return response.page;
|
|
381
|
+
}
|
|
382
|
+
async updatePage(pageId, params) {
|
|
383
|
+
const response = await this.request(
|
|
384
|
+
`/atlas/pages/${pageId}`,
|
|
385
|
+
{ method: "PUT", body: JSON.stringify(params) }
|
|
386
|
+
);
|
|
387
|
+
return response.page;
|
|
388
|
+
}
|
|
389
|
+
async deletePage(pageId) {
|
|
390
|
+
await this.request(`/atlas/pages/${pageId}`, { method: "DELETE" });
|
|
391
|
+
}
|
|
392
|
+
async exportPage(pageId, format) {
|
|
393
|
+
const response = await fetch(
|
|
394
|
+
`${this.baseUrl}/api/sdk/v1/atlas/pages/${pageId}/export?format=${format}`,
|
|
395
|
+
{ headers: { "x-api-key": this.apiKey } }
|
|
396
|
+
);
|
|
397
|
+
if (!response.ok) throw new Error("Failed to export page");
|
|
398
|
+
return response.blob();
|
|
399
|
+
}
|
|
400
|
+
async toggleFavorite(pageId) {
|
|
401
|
+
const response = await this.request(
|
|
402
|
+
`/atlas/pages/${pageId}/favorite`,
|
|
403
|
+
{ method: "POST" }
|
|
404
|
+
);
|
|
405
|
+
return response.page;
|
|
406
|
+
}
|
|
407
|
+
getLogs() {
|
|
408
|
+
return this.logger.getLogs();
|
|
409
|
+
}
|
|
410
|
+
clearLogs() {
|
|
411
|
+
this.logger.clearLogs();
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
415
|
+
0 && (module.exports = {
|
|
416
|
+
AtlasClient,
|
|
417
|
+
embedAtlas
|
|
418
|
+
});
|