@coreviz/sdk 1.1.2 → 1.1.3

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 CHANGED
@@ -217,6 +217,44 @@ The SDK also exposes namespaced methods for programmatically managing your CoreV
217
217
 
218
218
  ---
219
219
 
220
+ ## Account
221
+
222
+ ### `coreviz.me()`
223
+
224
+ Return the current authenticated user and their default organization.
225
+
226
+ **Returns:** `Promise<UserContext>` — `{ userId, email, name, organizationId, organizationName }`
227
+
228
+ ```typescript
229
+ const { name, email, organizationId } = await coreviz.me();
230
+ ```
231
+
232
+ ---
233
+
234
+ ### `coreviz.baseUrl`
235
+
236
+ The API base URL this instance is configured to use (read-only getter).
237
+
238
+ ```typescript
239
+ console.log(coreviz.baseUrl); // 'https://lab.coreviz.io'
240
+ ```
241
+
242
+ ---
243
+
244
+ ## Organizations
245
+
246
+ ### `coreviz.organizations.list()`
247
+
248
+ List all organizations the current user belongs to. Falls back to the user's default organization if the org-list endpoint is unavailable.
249
+
250
+ **Returns:** `Promise<Organization[]>` — each `{ id, name, slug }`
251
+
252
+ ```typescript
253
+ const orgs = await coreviz.organizations.list();
254
+ ```
255
+
256
+ ---
257
+
220
258
  ## Collections
221
259
 
222
260
  ### `coreviz.collections.list(organizationId?)`
@@ -245,14 +283,20 @@ const collection = await coreviz.collections.get('abc123');
245
283
 
246
284
  ---
247
285
 
248
- ### `coreviz.collections.create(name, icon?)`
286
+ ### `coreviz.collections.create(name, icon?, organizationId?)`
249
287
 
250
288
  Create a new collection.
251
289
 
290
+ - `organizationId` (string, optional): Target organization. Defaults to the current user's organization.
291
+
252
292
  **Returns:** `Promise<Collection>`
253
293
 
254
294
  ```typescript
295
+ // Create in current user's org
255
296
  const collection = await coreviz.collections.create('Product Photos', '📦');
297
+
298
+ // Create in a specific org
299
+ const collection = await coreviz.collections.create('Product Photos', '📦', 'org_abc123');
256
300
  ```
257
301
 
258
302
  ---
package/dist/coreviz.d.ts CHANGED
@@ -126,6 +126,18 @@ export interface UploadResult {
126
126
  url: string;
127
127
  message: string;
128
128
  }
129
+ export interface Organization {
130
+ id: string;
131
+ name: string;
132
+ slug: string;
133
+ }
134
+ export interface OrganizationsNamespace {
135
+ /**
136
+ * List all organizations the current user belongs to.
137
+ * Returns at minimum the user's default organization from /api/me.
138
+ */
139
+ list(): Promise<Organization[]>;
140
+ }
129
141
  export interface CollectionsNamespace {
130
142
  /**
131
143
  * List all collections in an organization.
@@ -134,8 +146,13 @@ export interface CollectionsNamespace {
134
146
  list(organizationId?: string): Promise<Collection[]>;
135
147
  /** Get a single collection by ID */
136
148
  get(collectionId: string): Promise<Collection>;
137
- /** Create a new collection in the user's current organization */
138
- create(name: string, icon?: string): Promise<Collection>;
149
+ /**
150
+ * Create a new collection.
151
+ * @param name - Display name for the collection.
152
+ * @param icon - Optional emoji or icon name.
153
+ * @param organizationId - Target organization. Defaults to the current user's organization.
154
+ */
155
+ create(name: string, icon?: string, organizationId?: string): Promise<Collection>;
139
156
  /** Update a collection's name or icon */
140
157
  update(collectionId: string, updates: CollectionUpdateOptions): Promise<Collection>;
141
158
  }
@@ -231,10 +248,15 @@ export declare class CoreViz {
231
248
  private _baseUrl;
232
249
  private _orgIdCache;
233
250
  collections: CollectionsNamespace;
251
+ organizations: OrganizationsNamespace;
234
252
  media: MediaNamespace;
235
253
  folders: FoldersNamespace;
236
254
  tags: TagsNamespace;
237
255
  constructor(config?: CoreVizConfig);
256
+ /** Return the current authenticated user and their default organization. */
257
+ me(): Promise<UserContext>;
258
+ /** The API base URL this instance is configured to use. */
259
+ get baseUrl(): string;
238
260
  private getHeaders;
239
261
  /** Resolve the current user's org ID (cached after first call) */
240
262
  private _me;
package/dist/coreviz.js CHANGED
@@ -42,6 +42,21 @@ class CoreViz {
42
42
  this.token = config.token;
43
43
  this._baseUrl = config.baseUrl || 'https://lab.coreviz.io';
44
44
  // ── Management namespaces ────────────────────────────────────────────
45
+ this.organizations = {
46
+ list: async () => {
47
+ // Try the Better Auth organization list endpoint first
48
+ try {
49
+ const data = await this._fetch('/api/auth/organization/list');
50
+ const orgs = Array.isArray(data) ? data : data.organizations ?? [];
51
+ if (orgs.length > 0)
52
+ return orgs;
53
+ }
54
+ catch { /* endpoint may not exist on all deployments */ }
55
+ // Fall back to the single org returned by /api/me
56
+ const me = await this._me();
57
+ return [{ id: me.organizationId, name: me.organizationName ?? me.organizationId, slug: me.organizationId }];
58
+ },
59
+ };
45
60
  this.collections = {
46
61
  list: async (organizationId) => {
47
62
  const orgId = organizationId || (await this._me()).organizationId;
@@ -52,9 +67,9 @@ class CoreViz {
52
67
  const data = await this._fetch(`/api/dataset/${collectionId}`);
53
68
  return data.dataset;
54
69
  },
55
- create: async (name, icon) => {
56
- const { organizationId } = await this._me();
57
- const data = await this._fetchMethod('POST', `/api/organization/${organizationId}/datasets`, {
70
+ create: async (name, icon, organizationId) => {
71
+ const orgId = organizationId || (await this._me()).organizationId;
72
+ const data = await this._fetchMethod('POST', `/api/organization/${orgId}/datasets`, {
58
73
  name,
59
74
  ...(icon ? { icon } : {}),
60
75
  });
@@ -237,6 +252,15 @@ class CoreViz {
237
252
  },
238
253
  };
239
254
  }
255
+ // ── Public helpers ───────────────────────────────────────────────────────
256
+ /** Return the current authenticated user and their default organization. */
257
+ async me() {
258
+ return this._me();
259
+ }
260
+ /** The API base URL this instance is configured to use. */
261
+ get baseUrl() {
262
+ return this._baseUrl;
263
+ }
240
264
  // ── Private helpers ──────────────────────────────────────────────────────
241
265
  getHeaders() {
242
266
  const headers = {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CoreViz, CoreVizConfig, DescribeOptions, EditOptions, TagOptions, TagResponse, EmbedOptions, EmbedResponse, GenerateOptions, UserContext, Collection, Media, MediaObject, MediaFrame, Folder, BrowseOptions, BrowseResult, SearchResult, SearchOptions, SimilarityOptions, UploadOptions, UploadResult, CollectionsNamespace, MediaNamespace, FoldersNamespace, TagsNamespace, FolderUpdateOptions, CollectionUpdateOptions, DeleteVersionResult } from './coreviz';
1
+ import { CoreViz, CoreVizConfig, DescribeOptions, EditOptions, TagOptions, TagResponse, EmbedOptions, EmbedResponse, GenerateOptions, UserContext, Organization, Collection, Media, MediaObject, MediaFrame, Folder, BrowseOptions, BrowseResult, SearchResult, SearchOptions, SimilarityOptions, UploadOptions, UploadResult, OrganizationsNamespace, CollectionsNamespace, MediaNamespace, FoldersNamespace, TagsNamespace, FolderUpdateOptions, CollectionUpdateOptions, DeleteVersionResult } from './coreviz';
2
2
  import { resize } from './resize';
3
3
  export { CoreViz, resize };
4
- export type { CoreVizConfig, DescribeOptions, EditOptions, TagOptions, TagResponse, EmbedOptions, EmbedResponse, GenerateOptions, UserContext, Collection, Media, MediaObject, MediaFrame, Folder, BrowseOptions, BrowseResult, SearchResult, SearchOptions, SimilarityOptions, UploadOptions, UploadResult, CollectionsNamespace, MediaNamespace, FoldersNamespace, TagsNamespace, FolderUpdateOptions, CollectionUpdateOptions, DeleteVersionResult };
4
+ export type { CoreVizConfig, DescribeOptions, EditOptions, TagOptions, TagResponse, EmbedOptions, EmbedResponse, GenerateOptions, UserContext, Organization, Collection, Media, MediaObject, MediaFrame, Folder, BrowseOptions, BrowseResult, SearchResult, SearchOptions, SimilarityOptions, UploadOptions, UploadResult, OrganizationsNamespace, CollectionsNamespace, MediaNamespace, FoldersNamespace, TagsNamespace, FolderUpdateOptions, CollectionUpdateOptions, DeleteVersionResult };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreviz/sdk",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "CoreViz SDK",
5
5
  "main": "dist/index.js",
6
6
  "react-native": "dist/index.native.js",