@mediaviz/sdk 0.1.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.
Files changed (52) hide show
  1. package/MediaViz.js +126 -0
  2. package/_oauth.js +3 -0
  3. package/admin.js +93 -0
  4. package/ai_model_credits.js +22 -0
  5. package/company.js +54 -0
  6. package/curated_albums.js +85 -0
  7. package/custom_albums.js +78 -0
  8. package/dist/sdk.cjs +1976 -0
  9. package/dist/sdk.esm.js +1947 -0
  10. package/dist/sdk.umd.js +1982 -0
  11. package/email_tokens.js +64 -0
  12. package/errors.js +81 -0
  13. package/health.js +20 -0
  14. package/index.js +21 -0
  15. package/keywords.js +123 -0
  16. package/oauth/.prettierrc +6 -0
  17. package/oauth/README.md +76 -0
  18. package/oauth/browser-smoke-test.html +45 -0
  19. package/oauth/implementation_plan.json +106 -0
  20. package/oauth/package-lock.json +5236 -0
  21. package/oauth/package.json +28 -0
  22. package/oauth/rollup.config.js +21 -0
  23. package/oauth/smoke-test.js +27 -0
  24. package/oauth/spec.md +187 -0
  25. package/oauth/src/__tests__/browser-smoke-test.test.js +38 -0
  26. package/oauth/src/__tests__/client.test.js +556 -0
  27. package/oauth/src/__tests__/errors.test.js +73 -0
  28. package/oauth/src/__tests__/http.test.js +102 -0
  29. package/oauth/src/__tests__/index.test.js +53 -0
  30. package/oauth/src/__tests__/package-fields.test.js +29 -0
  31. package/oauth/src/__tests__/pkce.test.js +55 -0
  32. package/oauth/src/__tests__/rollup-build.test.js +58 -0
  33. package/oauth/src/__tests__/smoke-test.test.js +26 -0
  34. package/oauth/src/__tests__/types.test.js +29 -0
  35. package/oauth/src/client.js +180 -0
  36. package/oauth/src/errors.js +32 -0
  37. package/oauth/src/http.js +52 -0
  38. package/oauth/src/index.js +7 -0
  39. package/oauth/src/pkce.js +50 -0
  40. package/oauth/src/types.js +67 -0
  41. package/oauth_authorization.js +53 -0
  42. package/oauth_clients.js +18 -0
  43. package/oauth_login.js +24 -0
  44. package/oauth_token.js +30 -0
  45. package/package.json +27 -0
  46. package/person.js +54 -0
  47. package/photos.js +106 -0
  48. package/photoupload.js +55 -0
  49. package/projects.js +191 -0
  50. package/rollup.config.js +12 -0
  51. package/search.js +99 -0
  52. package/users.js +137 -0
package/dist/sdk.cjs ADDED
@@ -0,0 +1,1976 @@
1
+ 'use strict';
2
+
3
+ function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }
6
+
7
+ var pkce;
8
+ var hasRequiredPkce;
9
+
10
+ function requirePkce () {
11
+ if (hasRequiredPkce) return pkce;
12
+ hasRequiredPkce = 1;
13
+
14
+ // base64url-encode a Uint8Array without padding
15
+ function base64urlEncode(bytes) {
16
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
17
+ let result = '';
18
+ for (let i = 0; i < bytes.length; i += 3) {
19
+ const b0 = bytes[i];
20
+ const b1 = i + 1 < bytes.length ? bytes[i + 1] : 0;
21
+ const b2 = i + 2 < bytes.length ? bytes[i + 2] : 0;
22
+ result += chars[b0 >> 2];
23
+ result += chars[((b0 & 3) << 4) | (b1 >> 4)];
24
+ if (i + 1 < bytes.length) result += chars[((b1 & 0xf) << 2) | (b2 >> 6)];
25
+ if (i + 2 < bytes.length) result += chars[b2 & 0x3f];
26
+ }
27
+ return result;
28
+ }
29
+
30
+ /**
31
+ * Generates a 64-character PKCE code verifier from [A-Za-z0-9-._~].
32
+ * @returns {string}
33
+ */
34
+ function generateCodeVerifier() {
35
+ const bytes = new Uint8Array(48);
36
+ globalThis.crypto.getRandomValues(bytes);
37
+ return base64urlEncode(bytes).slice(0, 64);
38
+ }
39
+
40
+ /**
41
+ * Computes Base64URL(SHA256(verifier)) with no padding.
42
+ * @param {string} verifier
43
+ * @returns {Promise<string>}
44
+ */
45
+ async function generateCodeChallenge(verifier) {
46
+ const encoded = new TextEncoder().encode(verifier);
47
+ const hashBuf = await globalThis.crypto.subtle.digest('SHA-256', encoded);
48
+ return base64urlEncode(new Uint8Array(hashBuf));
49
+ }
50
+
51
+ /**
52
+ * Generates a cryptographically random 32-char hex state value.
53
+ * @returns {string}
54
+ */
55
+ function generateState() {
56
+ const bytes = new Uint8Array(16);
57
+ globalThis.crypto.getRandomValues(bytes);
58
+ return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
59
+ }
60
+
61
+ pkce = { generateCodeVerifier, generateCodeChallenge, generateState };
62
+ return pkce;
63
+ }
64
+
65
+ var errors;
66
+ var hasRequiredErrors;
67
+
68
+ function requireErrors () {
69
+ if (hasRequiredErrors) return errors;
70
+ hasRequiredErrors = 1;
71
+
72
+ class OAuthError extends Error {
73
+ /**
74
+ * @param {string} code - RFC 6749 error code
75
+ * @param {string} description - Human-readable description
76
+ * @param {number} httpStatus - HTTP status code
77
+ * @param {unknown} [body] - Raw response body (parsed JSON when available)
78
+ */
79
+ constructor(code, description, httpStatus, body = null) {
80
+ super(description);
81
+ this.name = 'OAuthError';
82
+ this.code = code;
83
+ this.description = description;
84
+ this.httpStatus = httpStatus;
85
+ this.body = body;
86
+ }
87
+
88
+ /**
89
+ * @param {number} status
90
+ * @param {unknown} body
91
+ * @returns {OAuthError}
92
+ */
93
+ static fromResponse(status, body) {
94
+ if (body && typeof body === 'object' && typeof body.error === 'string') {
95
+ return new OAuthError(body.error, body.error_description ?? '', status, body);
96
+ }
97
+ return new OAuthError('server_error', 'Unexpected server response', status, body);
98
+ }
99
+ }
100
+
101
+ errors = { OAuthError };
102
+ return errors;
103
+ }
104
+
105
+ var http;
106
+ var hasRequiredHttp;
107
+
108
+ function requireHttp () {
109
+ if (hasRequiredHttp) return http;
110
+ hasRequiredHttp = 1;
111
+
112
+ const { OAuthError } = requireErrors();
113
+
114
+ /**
115
+ * @param {string} url
116
+ * @param {Record<string, string>} params
117
+ * @param {Record<string, string>} [headers]
118
+ * @returns {Promise<unknown>}
119
+ */
120
+ async function postForm(url, params, headers = {}) {
121
+ const body = new URLSearchParams(params).toString();
122
+ const response = await fetch(url, {
123
+ method: 'POST',
124
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded', ...headers },
125
+ body,
126
+ });
127
+ const json = await response.json();
128
+ if (!response.ok) throw OAuthError.fromResponse(response.status, json);
129
+ return json;
130
+ }
131
+
132
+ /**
133
+ * @param {string} url
134
+ * @param {Record<string, string>} [headers]
135
+ * @returns {Promise<unknown>}
136
+ */
137
+ async function getJson(url, headers = {}) {
138
+ const response = await fetch(url, { headers });
139
+ const json = await response.json();
140
+ if (!response.ok) throw OAuthError.fromResponse(response.status, json);
141
+ return json;
142
+ }
143
+
144
+ /**
145
+ * @param {string} url
146
+ * @param {object} body
147
+ * @param {Record<string, string>} [headers]
148
+ * @returns {Promise<unknown>}
149
+ */
150
+ async function postJson(url, body, headers = {}) {
151
+ const response = await fetch(url, {
152
+ method: 'POST',
153
+ headers: { 'Content-Type': 'application/json', ...headers },
154
+ body: JSON.stringify(body),
155
+ });
156
+ const json = await response.json();
157
+ if (!response.ok) throw OAuthError.fromResponse(response.status, json);
158
+ return json;
159
+ }
160
+
161
+ http = { postForm, getJson, postJson };
162
+ return http;
163
+ }
164
+
165
+ var client;
166
+ var hasRequiredClient;
167
+
168
+ function requireClient () {
169
+ if (hasRequiredClient) return client;
170
+ hasRequiredClient = 1;
171
+
172
+ const { generateCodeVerifier, generateCodeChallenge, generateState } = requirePkce();
173
+ const { postForm, postJson } = requireHttp();
174
+ const { OAuthError } = requireErrors();
175
+
176
+ class OAuthClient {
177
+ /**
178
+ * @param {import('./types').OAuthClientConfig} config
179
+ */
180
+ constructor(config) {
181
+ this._config = config;
182
+ this._inFlightRefreshes = new Map();
183
+ }
184
+
185
+ /**
186
+ * @param {import('./types').ClientRegistrationRequest} params
187
+ * @returns {Promise<import('./types').ClientRegistrationResponse>}
188
+ */
189
+ static async registerClient(params) {
190
+ const baseUrl = params.baseUrl.replace(/\/+$/, '');
191
+ return postJson(`${baseUrl}/oauth/clients`, {
192
+ client_name: params.clientName,
193
+ client_type: params.clientType,
194
+ redirect_uris: params.redirectUris,
195
+ is_first_party: params.isFirstParty,
196
+ });
197
+ }
198
+
199
+ /**
200
+ * @param {string} [state]
201
+ * @returns {import('./types').AuthorizationUrlResult}
202
+ */
203
+ async generateAuthorizationUrl(state) {
204
+ const codeVerifier = generateCodeVerifier();
205
+ const codeChallenge = await generateCodeChallenge(codeVerifier);
206
+ const resolvedState = state ?? generateState();
207
+
208
+ const params = new URLSearchParams({
209
+ response_type: 'code',
210
+ client_id: this._config.clientId,
211
+ redirect_uri: this._config.redirectUri,
212
+ state: resolvedState,
213
+ code_challenge: codeChallenge,
214
+ code_challenge_method: 'S256',
215
+ });
216
+
217
+ return {
218
+ url: `${this._config.baseUrl}/oauth/authorize?${params}`,
219
+ state: resolvedState,
220
+ code_verifier: codeVerifier,
221
+ };
222
+ }
223
+
224
+ /**
225
+ * @param {string} code
226
+ * @param {string} codeVerifier
227
+ * @param {string} [redirectUri]
228
+ * @returns {Promise<import('./types').TokenResponse>}
229
+ */
230
+ async exchangeCode(code, codeVerifier, redirectUri) {
231
+ return postForm(`${this._config.baseUrl}/oauth/token`, {
232
+ grant_type: 'authorization_code',
233
+ code,
234
+ code_verifier: codeVerifier,
235
+ redirect_uri: redirectUri ?? this._config.redirectUri,
236
+ client_id: this._config.clientId,
237
+ client_secret: this._config.clientSecret,
238
+ });
239
+ }
240
+
241
+ /**
242
+ * RFC 6749 §4.4 — machine-to-machine token exchange. No user login.
243
+ * Returned TokenResponse has no refresh_token.
244
+ * @returns {Promise<import('./types').TokenResponse>}
245
+ */
246
+ async getClientCredentialsToken() {
247
+ return postForm(`${this._config.baseUrl}/oauth/token`, {
248
+ grant_type: 'client_credentials',
249
+ client_id: this._config.clientId,
250
+ client_secret: this._config.clientSecret,
251
+ });
252
+ }
253
+
254
+ /**
255
+ * @param {string} refreshToken
256
+ * @returns {Promise<import('./types').TokenResponse>}
257
+ */
258
+ async refreshAccessToken(refreshToken) {
259
+ return postForm(`${this._config.baseUrl}/oauth/token`, {
260
+ grant_type: 'refresh_token',
261
+ refresh_token: refreshToken,
262
+ client_id: this._config.clientId,
263
+ client_secret: this._config.clientSecret,
264
+ });
265
+ }
266
+
267
+ /**
268
+ * @param {string} token
269
+ * @param {string} [tokenTypeHint]
270
+ * @returns {Promise<void>}
271
+ */
272
+ async revokeToken(token, tokenTypeHint) {
273
+ const params = { token, client_id: this._config.clientId, client_secret: this._config.clientSecret };
274
+ if (tokenTypeHint) params.token_type_hint = tokenTypeHint;
275
+ await postForm(`${this._config.baseUrl}/oauth/revoke`, params);
276
+ }
277
+
278
+ /**
279
+ * Makes an authenticated request with 401-intercept-and-retry.
280
+ *
281
+ * `onRefreshSuccess` fires synchronously the moment the rotated tokens are received,
282
+ * BEFORE the retry. The server has already deleted the old refresh token by then;
283
+ * if the retry throws, the new tokens would otherwise be lost in this call frame.
284
+ * Long-lived callers MUST persist via this callback — not from the resolved value —
285
+ * to stay in sync with single-use refresh-token rotation (RFC 6749 §6).
286
+ *
287
+ * @param {string} url
288
+ * @param {string} method
289
+ * @param {string} accessToken
290
+ * @param {string} refreshToken
291
+ * @param {object} [body]
292
+ * @param {(newTokens: import('./types').TokenResponse) => void} [onRefreshSuccess]
293
+ * @returns {Promise<import('./types').AuthenticatedResponse>}
294
+ */
295
+ async request(url, method, accessToken, refreshToken, body, onRefreshSuccess) {
296
+ const buildOptions = (token) => {
297
+ const headers = { Authorization: `Bearer ${token}` };
298
+ const options = { method, headers };
299
+ if (body != null) {
300
+ headers['Content-Type'] = 'application/json';
301
+ options.body = JSON.stringify(body);
302
+ }
303
+ return options;
304
+ };
305
+
306
+ const firstResponse = await fetch(`${this._config.baseUrl}${url}`, buildOptions(accessToken));
307
+
308
+ if (firstResponse.status !== 401) {
309
+ const json = await firstResponse.json();
310
+ if (!firstResponse.ok) throw OAuthError.fromResponse(firstResponse.status, json);
311
+ return { data: json, updatedTokens: null };
312
+ }
313
+
314
+ // 401: attempt refresh — propagate OAuthError if refresh fails.
315
+ // Concurrent request() callers with the same refresh_token share one in-flight
316
+ // call so the server only sees one rotation (the second would get invalid_grant).
317
+ let pending = this._inFlightRefreshes.get(refreshToken);
318
+ if (!pending) {
319
+ pending = this.refreshAccessToken(refreshToken).finally(() => {
320
+ this._inFlightRefreshes.delete(refreshToken);
321
+ });
322
+ this._inFlightRefreshes.set(refreshToken, pending);
323
+ }
324
+ const newTokens = await pending;
325
+
326
+ if (onRefreshSuccess) onRefreshSuccess(newTokens);
327
+
328
+ const retryResponse = await fetch(`${this._config.baseUrl}${url}`, buildOptions(newTokens.access_token));
329
+ const retryJson = await retryResponse.json();
330
+ if (!retryResponse.ok) throw OAuthError.fromResponse(retryResponse.status, retryJson);
331
+ return { data: retryJson, updatedTokens: newTokens };
332
+ }
333
+
334
+ /**
335
+ * Decodes a JWT access token payload without verifying the signature.
336
+ * @param {string} accessToken
337
+ * @returns {import('./types').TokenPayload}
338
+ */
339
+ decodeAccessToken(accessToken) {
340
+ const segment = accessToken.split('.')[1];
341
+ if (!segment) throw new OAuthError('invalid_token', 'Malformed JWT', 400);
342
+ const b64 = segment.replace(/-/g, '+').replace(/_/g, '/').padEnd(Math.ceil(segment.length / 4) * 4, '=');
343
+ const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
344
+ const payload = JSON.parse(new TextDecoder().decode(bytes));
345
+ return payload;
346
+ }
347
+ }
348
+
349
+ client = { OAuthClient };
350
+ return client;
351
+ }
352
+
353
+ /**
354
+ * @typedef {Object} OAuthClientConfig
355
+ * @property {string} baseUrl - Base URL of the OAuth server
356
+ * @property {string} clientId - Registered client_id
357
+ * @property {string} clientSecret - Registered client_secret
358
+ * @property {string} redirectUri - Registered redirect URI
359
+ */
360
+
361
+ var types;
362
+ var hasRequiredTypes;
363
+
364
+ function requireTypes () {
365
+ if (hasRequiredTypes) return types;
366
+ hasRequiredTypes = 1;
367
+ /**
368
+ * @typedef {Object} TokenResponse
369
+ * @property {string} access_token - Signed JWT access token
370
+ * @property {string} token_type - Always "bearer"
371
+ * @property {number} expires_in - Seconds until access token expires
372
+ * @property {string} refresh_token - Opaque refresh token
373
+ */
374
+
375
+ /**
376
+ * @typedef {Object} TokenPayload
377
+ * @property {string} user_id - ID of the authenticated user
378
+ * @property {string} client_id - ID of the OAuth client
379
+ * @property {string} jti - Unique token ID
380
+ * @property {number} iat - Issued-at timestamp (Unix seconds)
381
+ * @property {number} exp - Expiry timestamp (Unix seconds)
382
+ */
383
+
384
+ /**
385
+ * @typedef {Object} AuthorizationUrlResult
386
+ * @property {string} url - Full authorization URL
387
+ * @property {string} state - CSRF state value; persist between redirect and callback
388
+ * @property {string} code_verifier - PKCE verifier; persist between redirect and callback
389
+ */
390
+
391
+ /**
392
+ * @typedef {Object} AuthenticatedResponse
393
+ * @property {Object} data - Parsed JSON response body from resource server
394
+ * @property {TokenResponse|null} updatedTokens - Non-null only when token refresh occurred
395
+ */
396
+
397
+ /**
398
+ * @typedef {Object} ClientRegistrationRequest
399
+ * @property {string} baseUrl - Base URL of the OAuth server
400
+ * @property {string} clientName - Human-readable client name
401
+ * @property {string} clientType - "public" or "confidential"
402
+ * @property {string[]} redirectUris - HTTPS redirect URIs
403
+ * @property {boolean} isFirstParty - Whether this is a first-party client
404
+ */
405
+
406
+ /**
407
+ * @typedef {Object} ClientRegistrationResponse
408
+ * @property {string} client_id - Assigned client ID
409
+ * @property {string} client_name - Registered client name
410
+ * @property {string} client_type - "public" or "confidential"
411
+ * @property {string[]} redirect_uris - Registered redirect URIs
412
+ * @property {string} [client_secret] - Only present for confidential clients
413
+ */
414
+
415
+ const OAuthErrorCode = Object.freeze({
416
+ INVALID_REQUEST: 'invalid_request',
417
+ INVALID_CLIENT: 'invalid_client',
418
+ INVALID_GRANT: 'invalid_grant',
419
+ UNAUTHORIZED_CLIENT: 'unauthorized_client',
420
+ UNSUPPORTED_GRANT_TYPE: 'unsupported_grant_type',
421
+ ACCESS_DENIED: 'access_denied',
422
+ SERVER_ERROR: 'server_error',
423
+ });
424
+
425
+ types = { OAuthErrorCode };
426
+ return types;
427
+ }
428
+
429
+ var src;
430
+ var hasRequiredSrc;
431
+
432
+ function requireSrc () {
433
+ if (hasRequiredSrc) return src;
434
+ hasRequiredSrc = 1;
435
+
436
+ const { OAuthClient } = requireClient();
437
+ const { OAuthError } = requireErrors();
438
+ const { OAuthErrorCode } = requireTypes();
439
+
440
+ src = { OAuthClient, OAuthError, OAuthErrorCode };
441
+ return src;
442
+ }
443
+
444
+ var srcExports = requireSrc();
445
+ var _oauth = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
446
+
447
+ // Auto-generated — do not edit
448
+ const { OAuthClient, OAuthError, OAuthErrorCode } = _oauth;
449
+
450
+ class AiModelCredits {
451
+ constructor(ctx) { this._ctx = ctx; }
452
+
453
+ async getModelCreditRelationship(modelName) {
454
+ this._ctx.requireTokens();
455
+ const path = `/api/v1/model_credit/${encodeURIComponent(modelName)}`;
456
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
457
+ return data;
458
+ }
459
+
460
+ async upsertModelCreditRelationship({ modelName, newCreditValue } = {}) {
461
+ this._ctx.requireTokens();
462
+ let path = `/api/v1/model_credit/upsert`;
463
+ const query = new URLSearchParams();
464
+ if (modelName !== undefined) (Array.isArray(modelName) ? modelName : [modelName]).forEach(v => query.append('model_name', v));
465
+ if (newCreditValue !== undefined) (Array.isArray(newCreditValue) ? newCreditValue : [newCreditValue]).forEach(v => query.append('new_credit_value', v));
466
+ const qs = query.toString();
467
+ if (qs) path += '?' + qs;
468
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
469
+ return data;
470
+ }
471
+ }
472
+
473
+ class Admin {
474
+ constructor(ctx) { this._ctx = ctx; }
475
+
476
+ async insertLabelCategoryMatrix() {
477
+ this._ctx.requireTokens();
478
+ const path = `/api/v1/admin/insert_label_category_matrix`;
479
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
480
+ return data;
481
+ }
482
+
483
+ async generateMidLevelCategoryKeywordAlignment() {
484
+ this._ctx.requireTokens();
485
+ const path = `/api/v1/admin/generate_mid_level_category_keyword_alignment`;
486
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
487
+ return data;
488
+ }
489
+
490
+ async getCategoryLabels(category) {
491
+ this._ctx.requireTokens();
492
+ const path = `/api/v1/admin/category_labels/${encodeURIComponent(category)}`;
493
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
494
+ return data;
495
+ }
496
+
497
+ async adminDumpCompanyNlpIndex(companyId) {
498
+ this._ctx.requireTokens();
499
+ const path = `/api/v1/admin/dump_company_nlp_index/${encodeURIComponent(companyId)}`;
500
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
501
+ return data;
502
+ }
503
+
504
+ async getAllKeywordGroupsAndSubgroups() {
505
+ this._ctx.requireTokens();
506
+ const path = `/api/v1/admin/keyword_group`;
507
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
508
+ return data;
509
+ }
510
+
511
+ async getKeywordGroupsLabelsByKeywordGroup(keywordGroup, { subgroup } = {}) {
512
+ this._ctx.requireTokens();
513
+ let path = `/api/v1/admin/keyword_group/${encodeURIComponent(keywordGroup)}/`;
514
+ const query = new URLSearchParams();
515
+ if (subgroup !== undefined) (Array.isArray(subgroup) ? subgroup : [subgroup]).forEach(v => query.append('subgroup', v));
516
+ const qs = query.toString();
517
+ if (qs) path += '?' + qs;
518
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
519
+ return data;
520
+ }
521
+
522
+ async adminCreateCompanyNlpIndexes({ companyIds } = {}) {
523
+ this._ctx.requireTokens();
524
+ let path = `/api/v1/admin/create_company_nlp_indexes/`;
525
+ const query = new URLSearchParams();
526
+ if (companyIds !== undefined) (Array.isArray(companyIds) ? companyIds : [companyIds]).forEach(v => query.append('company_ids', v));
527
+ const qs = query.toString();
528
+ if (qs) path += '?' + qs;
529
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
530
+ return data;
531
+ }
532
+
533
+ async adminDeleteCompanyNlpIndexes({ companyIds } = {}) {
534
+ this._ctx.requireTokens();
535
+ let path = `/api/v1/admin/delete_company_nlp_indexes/`;
536
+ const query = new URLSearchParams();
537
+ if (companyIds !== undefined) (Array.isArray(companyIds) ? companyIds : [companyIds]).forEach(v => query.append('company_ids', v));
538
+ const qs = query.toString();
539
+ if (qs) path += '?' + qs;
540
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
541
+ return data;
542
+ }
543
+
544
+ async adminDeleteUserProjects({ userIds } = {}) {
545
+ this._ctx.requireTokens();
546
+ let path = `/api/v1/admin/delete_user_projects/`;
547
+ const query = new URLSearchParams();
548
+ if (userIds !== undefined) (Array.isArray(userIds) ? userIds : [userIds]).forEach(v => query.append('user_ids', v));
549
+ const qs = query.toString();
550
+ if (qs) path += '?' + qs;
551
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
552
+ return data;
553
+ }
554
+
555
+ async adminDeleteUser({ userIds } = {}) {
556
+ this._ctx.requireTokens();
557
+ let path = `/api/v1/admin/delete_user/`;
558
+ const query = new URLSearchParams();
559
+ if (userIds !== undefined) (Array.isArray(userIds) ? userIds : [userIds]).forEach(v => query.append('user_ids', v));
560
+ const qs = query.toString();
561
+ if (qs) path += '?' + qs;
562
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
563
+ return data;
564
+ }
565
+ }
566
+
567
+ class Company {
568
+ constructor(ctx) { this._ctx = ctx; }
569
+
570
+ async getAllCompanies() {
571
+ this._ctx.requireTokens();
572
+ const path = `/api/v1/company/`;
573
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
574
+ return data;
575
+ }
576
+
577
+ async getCompanyById(companyId) {
578
+ this._ctx.requireTokens();
579
+ const path = `/api/v1/company/${encodeURIComponent(companyId)}`;
580
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
581
+ return data;
582
+ }
583
+
584
+ async confirmCompanyCreditBalance(companyId, { photoCount, modelsList } = {}) {
585
+ this._ctx.requireTokens();
586
+ let path = `/api/v1/company/credit_balance/${encodeURIComponent(companyId)}`;
587
+ const query = new URLSearchParams();
588
+ if (photoCount !== undefined) (Array.isArray(photoCount) ? photoCount : [photoCount]).forEach(v => query.append('photo_count', v));
589
+ if (modelsList !== undefined) (Array.isArray(modelsList) ? modelsList : [modelsList]).forEach(v => query.append('models_list', v));
590
+ const qs = query.toString();
591
+ if (qs) path += '?' + qs;
592
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
593
+ return data;
594
+ }
595
+
596
+ async adminListActiveCompanyTokens() {
597
+ this._ctx.requireTokens();
598
+ const path = `/api/v1/company/admin_create/`;
599
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
600
+ return data;
601
+ }
602
+
603
+ async adminCreateCompanyToken({ email } = {}) {
604
+ this._ctx.requireTokens();
605
+ let path = `/api/v1/company/admin_create/`;
606
+ const query = new URLSearchParams();
607
+ if (email !== undefined) (Array.isArray(email) ? email : [email]).forEach(v => query.append('email', v));
608
+ const qs = query.toString();
609
+ if (qs) path += '?' + qs;
610
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
611
+ return data;
612
+ }
613
+
614
+ async adminRevokeCompanyToken(tokenId) {
615
+ this._ctx.requireTokens();
616
+ const path = `/api/v1/company/admin_create/${encodeURIComponent(tokenId)}/revoke/`;
617
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
618
+ return data;
619
+ }
620
+ }
621
+
622
+ function stripUndef$6(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
623
+
624
+ class CuratedAlbums {
625
+ constructor(ctx) { this._ctx = ctx; }
626
+
627
+ async createCuratedAlbum(projectTableName, name, description = undefined, confidenceValue = undefined) {
628
+ this._ctx.requireTokens();
629
+ const path = `/api/v1/curated_album/project/${encodeURIComponent(projectTableName)}`;
630
+ const body = stripUndef$6({
631
+ name: name,
632
+ description: description,
633
+ confidence_value: confidenceValue,
634
+ });
635
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
636
+ return data;
637
+ }
638
+
639
+ async getAllProjectCuratedAlbums(projectTableName) {
640
+ this._ctx.requireTokens();
641
+ const path = `/api/v1/curated_album/project/${encodeURIComponent(projectTableName)}`;
642
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
643
+ return data;
644
+ }
645
+
646
+ async getCuratedAlbumPhotos(albumId, { ascOrDesc, lastId, limit, confidenceValue } = {}) {
647
+ this._ctx.requireTokens();
648
+ let path = `/api/v1/curated_album/photos/${encodeURIComponent(albumId)}/`;
649
+ const query = new URLSearchParams();
650
+ if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
651
+ if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
652
+ if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
653
+ if (confidenceValue !== undefined) (Array.isArray(confidenceValue) ? confidenceValue : [confidenceValue]).forEach(v => query.append('confidence_value', v));
654
+ const qs = query.toString();
655
+ if (qs) path += '?' + qs;
656
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
657
+ return data;
658
+ }
659
+
660
+ async getCuratedAlbumPhotosRanked(albumId, { ascOrDesc, lastId, limit, confidenceValue } = {}) {
661
+ this._ctx.requireTokens();
662
+ let path = `/api/v1/curated_album/photos/ranked/${encodeURIComponent(albumId)}/`;
663
+ const query = new URLSearchParams();
664
+ if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
665
+ if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
666
+ if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
667
+ if (confidenceValue !== undefined) (Array.isArray(confidenceValue) ? confidenceValue : [confidenceValue]).forEach(v => query.append('confidence_value', v));
668
+ const qs = query.toString();
669
+ if (qs) path += '?' + qs;
670
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
671
+ return data;
672
+ }
673
+
674
+ async getCuratedAlbumById(albumId) {
675
+ this._ctx.requireTokens();
676
+ const path = `/api/v1/curated_album/${encodeURIComponent(albumId)}`;
677
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
678
+ return data;
679
+ }
680
+
681
+ async updateCuratedAlbum(albumId, { name, description, confidenceValue } = {}) {
682
+ this._ctx.requireTokens();
683
+ const path = `/api/v1/curated_album/${encodeURIComponent(albumId)}`;
684
+ const body = stripUndef$6({
685
+ name: name,
686
+ description: description,
687
+ confidence_value: confidenceValue,
688
+ });
689
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
690
+ return data;
691
+ }
692
+
693
+ async deleteCuratedAlbum(albumId) {
694
+ this._ctx.requireTokens();
695
+ const path = `/api/v1/curated_album/${encodeURIComponent(albumId)}`;
696
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
697
+ return data;
698
+ }
699
+
700
+ async convertCuratedAlbumToCustom(albumId) {
701
+ this._ctx.requireTokens();
702
+ const path = `/api/v1/curated_album/${encodeURIComponent(albumId)}/convert`;
703
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
704
+ return data;
705
+ }
706
+ }
707
+
708
+ function stripUndef$5(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
709
+
710
+ class CustomAlbums {
711
+ constructor(ctx) { this._ctx = ctx; }
712
+
713
+ async getCustomAlbumDetailById(customAlbumId) {
714
+ this._ctx.requireTokens();
715
+ const path = `/api/v1/custom_album/${encodeURIComponent(customAlbumId)}`;
716
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
717
+ return data;
718
+ }
719
+
720
+ async getAllProjectCustomAlbums(projectTableName) {
721
+ this._ctx.requireTokens();
722
+ const path = `/api/v1/custom_album/project/${encodeURIComponent(projectTableName)}`;
723
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
724
+ return data;
725
+ }
726
+
727
+ async getCustomAlbumPhotosById(customAlbumId, { ascOrDesc, lastId, limit } = {}) {
728
+ this._ctx.requireTokens();
729
+ let path = `/api/v1/custom_album/photos/${encodeURIComponent(customAlbumId)}/`;
730
+ const query = new URLSearchParams();
731
+ if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
732
+ if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
733
+ if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
734
+ const qs = query.toString();
735
+ if (qs) path += '?' + qs;
736
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
737
+ return data;
738
+ }
739
+
740
+ async getRankedCustomAlbumById(customAlbumId, { ascOrDesc, lastId, limit } = {}) {
741
+ this._ctx.requireTokens();
742
+ let path = `/api/v1/custom_album/photos/ranked/${encodeURIComponent(customAlbumId)}/`;
743
+ const query = new URLSearchParams();
744
+ if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
745
+ if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
746
+ if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
747
+ const qs = query.toString();
748
+ if (qs) path += '?' + qs;
749
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
750
+ return data;
751
+ }
752
+
753
+ async createProjectCustomAlbum(projectTableName, { name, description, photoIdInclusionList, photoIdRemovalList } = {}) {
754
+ this._ctx.requireTokens();
755
+ const path = `/api/v1/custom_album/project/${encodeURIComponent(projectTableName)}`;
756
+ const body = stripUndef$5({
757
+ name: name,
758
+ description: description,
759
+ photo_id_inclusion_list: photoIdInclusionList,
760
+ photo_id_removal_list: photoIdRemovalList,
761
+ });
762
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
763
+ return data;
764
+ }
765
+
766
+ async updateCustomAlbum(albumId, { name, description, photoIdInclusionList, photoIdRemovalList } = {}) {
767
+ this._ctx.requireTokens();
768
+ const path = `/api/v1/custom_album/${encodeURIComponent(albumId)}`;
769
+ const body = stripUndef$5({
770
+ name: name,
771
+ description: description,
772
+ photo_id_inclusion_list: photoIdInclusionList,
773
+ photo_id_removal_list: photoIdRemovalList,
774
+ });
775
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
776
+ return data;
777
+ }
778
+
779
+ async deleteCustomAlbum(albumId) {
780
+ this._ctx.requireTokens();
781
+ const path = `/api/v1/custom_album/${encodeURIComponent(albumId)}`;
782
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
783
+ return data;
784
+ }
785
+ }
786
+
787
+ // Auto-generated — do not edit
788
+
789
+ class ApiError extends Error {
790
+ constructor(message, status, requestId, body) {
791
+ super(message);
792
+ this.name = 'ApiError';
793
+ this.status = status;
794
+ this.requestId = requestId;
795
+ this.body = body;
796
+ }
797
+ }
798
+
799
+ class ValidationError extends ApiError {
800
+ constructor(body, status, requestId) {
801
+ const detail = body.detail ?? [];
802
+ const message = Array.isArray(detail)
803
+ ? detail.map(d => `${d.loc.join('.')}: ${d.msg}`).join('; ')
804
+ : String(detail);
805
+ super(message, status, requestId, body);
806
+ this.name = 'ValidationError';
807
+ this.fieldErrors = Array.isArray(detail)
808
+ ? detail.map(d => ({ loc: d.loc, msg: d.msg, type: d.type }))
809
+ : [];
810
+ }
811
+ }
812
+
813
+ class NotFoundError extends ApiError {
814
+ constructor(body, status, requestId) {
815
+ super(body.detail ?? 'Resource not found', status, requestId, body);
816
+ this.name = 'NotFoundError';
817
+ }
818
+ }
819
+
820
+ class RateLimitError extends ApiError {
821
+ constructor(body, status, requestId, headers) {
822
+ super(body.detail ?? 'Rate limited', status, requestId, body);
823
+ this.name = 'RateLimitError';
824
+ this.retryAfter = parseInt(headers.get('retry-after') ?? '', 10) || null;
825
+ }
826
+ }
827
+
828
+ class ServerError extends ApiError {
829
+ constructor(body, status, requestId) {
830
+ super(body.detail ?? 'Internal server error', status, requestId, body);
831
+ this.name = 'ServerError';
832
+ }
833
+ }
834
+
835
+ async function handleResponse(response) {
836
+ const requestId = response.headers.get('x-request-id');
837
+
838
+ if (response.ok) {
839
+ return response.status === 204 ? null : response.json();
840
+ }
841
+
842
+ let body;
843
+ try {
844
+ body = await response.json();
845
+ } catch {
846
+ body = { detail: response.statusText };
847
+ }
848
+
849
+ switch (response.status) {
850
+ case 422:
851
+ throw new ValidationError(body, response.status, requestId);
852
+ case 404:
853
+ throw new NotFoundError(body, response.status, requestId);
854
+ case 429:
855
+ throw new RateLimitError(body, response.status, requestId, response.headers);
856
+ default:
857
+ if (response.status >= 500) {
858
+ throw new ServerError(body, response.status, requestId);
859
+ }
860
+ throw new ApiError(
861
+ body.detail ?? 'Unknown error',
862
+ response.status,
863
+ requestId,
864
+ body
865
+ );
866
+ }
867
+ }
868
+
869
+ function stripUndef$4(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
870
+
871
+ class EmailTokens {
872
+ constructor(ctx) { this._ctx = ctx; }
873
+
874
+ async requestEmailVerification({ email } = {}) {
875
+ let path = `/api/v1/request-email-verification`;
876
+ const query = new URLSearchParams();
877
+ if (email !== undefined) (Array.isArray(email) ? email : [email]).forEach(v => query.append('email', v));
878
+ const qs = query.toString();
879
+ if (qs) path += '?' + qs;
880
+ const resp = await fetch(this._ctx.baseUrl + path, { method: 'POST' });
881
+ return handleResponse(resp);
882
+ }
883
+
884
+ async verifyEmail(token) {
885
+ const resp = await fetch(this._ctx.baseUrl + `/api/v1/verify-email/${encodeURIComponent(token)}`, { method: 'POST' });
886
+ return handleResponse(resp);
887
+ }
888
+
889
+ async requestPasswordReset({ email } = {}) {
890
+ let path = `/api/v1/request-password-reset`;
891
+ const query = new URLSearchParams();
892
+ if (email !== undefined) (Array.isArray(email) ? email : [email]).forEach(v => query.append('email', v));
893
+ const qs = query.toString();
894
+ if (qs) path += '?' + qs;
895
+ const resp = await fetch(this._ctx.baseUrl + path, { method: 'POST' });
896
+ return handleResponse(resp);
897
+ }
898
+
899
+ async validateToken(token) {
900
+ const body = stripUndef$4({
901
+ token: token,
902
+ });
903
+ const resp = await fetch(this._ctx.baseUrl + `/api/v1/validate-token`, {
904
+ method: 'POST',
905
+ headers: { 'Content-Type': 'application/json' },
906
+ body: JSON.stringify(body),
907
+ });
908
+ return handleResponse(resp);
909
+ }
910
+
911
+ async resetPassword(token, newPassword) {
912
+ const body = stripUndef$4({
913
+ token: token,
914
+ new_password: newPassword,
915
+ });
916
+ const resp = await fetch(this._ctx.baseUrl + `/api/v1/reset-password`, {
917
+ method: 'POST',
918
+ headers: { 'Content-Type': 'application/json' },
919
+ body: JSON.stringify(body),
920
+ });
921
+ return handleResponse(resp);
922
+ }
923
+
924
+ async deleteUserEmailTokens(userId) {
925
+ this._ctx.requireTokens();
926
+ const path = `/api/v1/admin/email_tokens/by_user/${encodeURIComponent(userId)}`;
927
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
928
+ return data;
929
+ }
930
+ }
931
+
932
+ class Health {
933
+ constructor(ctx) { this._ctx = ctx; }
934
+
935
+ async healthCheck() {
936
+ const resp = await fetch(this._ctx.baseUrl + `/api/v1/health/`, { method: 'GET' });
937
+ return handleResponse(resp);
938
+ }
939
+
940
+ async livenessCheck() {
941
+ const resp = await fetch(this._ctx.baseUrl + `/api/v1/health/live/`, { method: 'GET' });
942
+ return handleResponse(resp);
943
+ }
944
+
945
+ async readinessCheck() {
946
+ const resp = await fetch(this._ctx.baseUrl + `/api/v1/health/ready`, { method: 'GET' });
947
+ return handleResponse(resp);
948
+ }
949
+ }
950
+
951
+ function stripUndef$3(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
952
+
953
+ class Keywords {
954
+ constructor(ctx) { this._ctx = ctx; }
955
+
956
+ async createKeywordFilteringList(name, projectList = undefined) {
957
+ this._ctx.requireTokens();
958
+ const path = `/api/v1/keyword/`;
959
+ const body = stripUndef$3({
960
+ name: name,
961
+ project_list: projectList,
962
+ });
963
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
964
+ return data;
965
+ }
966
+
967
+ async getUserKeywordFilteringLists() {
968
+ this._ctx.requireTokens();
969
+ const path = `/api/v1/keyword/user`;
970
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
971
+ return data;
972
+ }
973
+
974
+ async getKeywordFilteringListAndProjectsById(keywordListId) {
975
+ this._ctx.requireTokens();
976
+ const path = `/api/v1/keyword/${encodeURIComponent(keywordListId)}`;
977
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
978
+ return data;
979
+ }
980
+
981
+ async getKeywordFilteringListById(keywordListId) {
982
+ this._ctx.requireTokens();
983
+ const path = `/api/v1/keyword/list/${encodeURIComponent(keywordListId)}`;
984
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
985
+ return data;
986
+ }
987
+
988
+ async getExistingKeywordFilteringListByProject(projectTableName) {
989
+ this._ctx.requireTokens();
990
+ const path = `/api/v1/keyword/project/${encodeURIComponent(projectTableName)}`;
991
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
992
+ return data;
993
+ }
994
+
995
+ async getDefaultKeywordFilteringListByProject(projectTableName) {
996
+ this._ctx.requireTokens();
997
+ const path = `/api/v1/keyword/project/${encodeURIComponent(projectTableName)}/default`;
998
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
999
+ return data;
1000
+ }
1001
+
1002
+ async updateKeywordFilteringListLabels(keywordListId, listKeywordsToInclude, listKeywordsToExclude) {
1003
+ this._ctx.requireTokens();
1004
+ const path = `/api/v1/keyword/${encodeURIComponent(keywordListId)}`;
1005
+ const body = stripUndef$3({
1006
+ list_keywords_to_include: listKeywordsToInclude,
1007
+ list_keywords_to_exclude: listKeywordsToExclude,
1008
+ });
1009
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
1010
+ return data;
1011
+ }
1012
+
1013
+ async updateKeywordFilteringListDetails(keywordListId, { name, projectList } = {}) {
1014
+ this._ctx.requireTokens();
1015
+ const path = `/api/v1/keyword/details/${encodeURIComponent(keywordListId)}`;
1016
+ const body = stripUndef$3({
1017
+ name: name,
1018
+ project_list: projectList,
1019
+ });
1020
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
1021
+ return data;
1022
+ }
1023
+
1024
+ async addProjectsToKeywordFilteringList(keywordListId, { projectIds } = {}) {
1025
+ this._ctx.requireTokens();
1026
+ let path = `/api/v1/keyword/${encodeURIComponent(keywordListId)}/projects`;
1027
+ const query = new URLSearchParams();
1028
+ if (projectIds !== undefined) (Array.isArray(projectIds) ? projectIds : [projectIds]).forEach(v => query.append('project_ids', v));
1029
+ const qs = query.toString();
1030
+ if (qs) path += '?' + qs;
1031
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
1032
+ return data;
1033
+ }
1034
+
1035
+ async requestKeywordListExport(keywordListId) {
1036
+ this._ctx.requireTokens();
1037
+ const path = `/api/v1/keyword/export/${encodeURIComponent(keywordListId)}`;
1038
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1039
+ return data;
1040
+ }
1041
+
1042
+ async requestKeywordListExportStatus(keywordListId) {
1043
+ this._ctx.requireTokens();
1044
+ const path = `/api/v1/keyword/export_status/${encodeURIComponent(keywordListId)}`;
1045
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1046
+ return data;
1047
+ }
1048
+
1049
+ async getKeywordsAndIds() {
1050
+ this._ctx.requireTokens();
1051
+ const path = `/api/v1/keyword/all_keywords/id/label`;
1052
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1053
+ return data;
1054
+ }
1055
+
1056
+ async removeProjectsFromKeywordFilteringList(keywordListId, { projectIds } = {}) {
1057
+ this._ctx.requireTokens();
1058
+ let path = `/api/v1/keyword/${encodeURIComponent(keywordListId)}/projects`;
1059
+ const query = new URLSearchParams();
1060
+ if (projectIds !== undefined) (Array.isArray(projectIds) ? projectIds : [projectIds]).forEach(v => query.append('project_ids', v));
1061
+ const qs = query.toString();
1062
+ if (qs) path += '?' + qs;
1063
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
1064
+ return data;
1065
+ }
1066
+
1067
+ async deleteKeywordFilteringListById(keywordListId) {
1068
+ this._ctx.requireTokens();
1069
+ const path = `/api/v1/keyword/${encodeURIComponent(keywordListId)}`;
1070
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
1071
+ return data;
1072
+ }
1073
+ }
1074
+
1075
+ class OauthAuthorization {
1076
+ constructor(ctx) { this._ctx = ctx; }
1077
+
1078
+ async authorize({ responseType, clientId, redirectUri, state, codeChallenge, codeChallengeMethod } = {}) {
1079
+ let path = `/oauth/authorize`;
1080
+ const query = new URLSearchParams();
1081
+ if (responseType !== undefined) (Array.isArray(responseType) ? responseType : [responseType]).forEach(v => query.append('response_type', v));
1082
+ if (clientId !== undefined) (Array.isArray(clientId) ? clientId : [clientId]).forEach(v => query.append('client_id', v));
1083
+ if (redirectUri !== undefined) (Array.isArray(redirectUri) ? redirectUri : [redirectUri]).forEach(v => query.append('redirect_uri', v));
1084
+ if (state !== undefined) (Array.isArray(state) ? state : [state]).forEach(v => query.append('state', v));
1085
+ if (codeChallenge !== undefined) (Array.isArray(codeChallenge) ? codeChallenge : [codeChallenge]).forEach(v => query.append('code_challenge', v));
1086
+ if (codeChallengeMethod !== undefined) (Array.isArray(codeChallengeMethod) ? codeChallengeMethod : [codeChallengeMethod]).forEach(v => query.append('code_challenge_method', v));
1087
+ const qs = query.toString();
1088
+ if (qs) path += '?' + qs;
1089
+ const resp = await fetch(this._ctx.baseUrl + path, { method: 'GET' });
1090
+ return handleResponse(resp);
1091
+ }
1092
+
1093
+ async getConsent(sessionId) {
1094
+ const resp = await fetch(this._ctx.baseUrl + `/oauth/consent/${encodeURIComponent(sessionId)}`, { method: 'GET' });
1095
+ return handleResponse(resp);
1096
+ }
1097
+
1098
+ async postApproveConsent(sessionId, { restartUrl }) {
1099
+ const resp = await fetch(this._ctx.baseUrl + `/oauth/consent/${encodeURIComponent(sessionId)}/approve`, {
1100
+ method: 'POST',
1101
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1102
+ body: new URLSearchParams({ restart_url: restartUrl }).toString(),
1103
+ });
1104
+ return handleResponse(resp);
1105
+ }
1106
+
1107
+ async postDenyConsent(sessionId, { restartUrl }) {
1108
+ const resp = await fetch(this._ctx.baseUrl + `/oauth/consent/${encodeURIComponent(sessionId)}/deny`, {
1109
+ method: 'POST',
1110
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1111
+ body: new URLSearchParams({ restart_url: restartUrl }).toString(),
1112
+ });
1113
+ return handleResponse(resp);
1114
+ }
1115
+
1116
+ async getSwitchUser(sessionId, { restartUrl } = {}) {
1117
+ let path = `/oauth/consent/${encodeURIComponent(sessionId)}/switch-user`;
1118
+ const query = new URLSearchParams();
1119
+ if (restartUrl !== undefined) (Array.isArray(restartUrl) ? restartUrl : [restartUrl]).forEach(v => query.append('restart_url', v));
1120
+ const qs = query.toString();
1121
+ if (qs) path += '?' + qs;
1122
+ const resp = await fetch(this._ctx.baseUrl + path, { method: 'GET' });
1123
+ return handleResponse(resp);
1124
+ }
1125
+ }
1126
+
1127
+ function stripUndef$2(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
1128
+
1129
+ class OauthClients {
1130
+ constructor(ctx) { this._ctx = ctx; }
1131
+
1132
+ async createClient(clientName, clientType, redirectUris, isFirstParty) {
1133
+ this._ctx.requireTokens();
1134
+ const path = `/oauth/clients`;
1135
+ const body = stripUndef$2({
1136
+ client_name: clientName,
1137
+ client_type: clientType,
1138
+ redirect_uris: redirectUris,
1139
+ is_first_party: isFirstParty,
1140
+ });
1141
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
1142
+ return data;
1143
+ }
1144
+ }
1145
+
1146
+ class OauthToken {
1147
+ constructor(ctx) { this._ctx = ctx; }
1148
+
1149
+ async token({ grantType, code, redirectUri, clientId, codeVerifier, refreshToken, clientSecret }) {
1150
+ const resp = await fetch(this._ctx.baseUrl + `/oauth/token`, {
1151
+ method: 'POST',
1152
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1153
+ body: new URLSearchParams({ grant_type: grantType, code, redirect_uri: redirectUri, client_id: clientId, code_verifier: codeVerifier, refresh_token: refreshToken, client_secret: clientSecret }).toString(),
1154
+ });
1155
+ return handleResponse(resp);
1156
+ }
1157
+
1158
+ async adminRevokeUserTokens(userId) {
1159
+ this._ctx.requireTokens();
1160
+ const path = `/oauth/admin/users/${encodeURIComponent(userId)}/revoke-tokens`;
1161
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
1162
+ return data;
1163
+ }
1164
+
1165
+ async revoke({ token, tokenTypeHint, clientId }) {
1166
+ const resp = await fetch(this._ctx.baseUrl + `/oauth/revoke`, {
1167
+ method: 'POST',
1168
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1169
+ body: new URLSearchParams({ token, token_type_hint: tokenTypeHint, client_id: clientId }).toString(),
1170
+ });
1171
+ return handleResponse(resp);
1172
+ }
1173
+ }
1174
+
1175
+ class OauthLogin {
1176
+ constructor(ctx) { this._ctx = ctx; }
1177
+
1178
+ async getLogin({ next } = {}) {
1179
+ let path = `/api/v1/oauth/login`;
1180
+ const query = new URLSearchParams();
1181
+ if (next !== undefined) (Array.isArray(next) ? next : [next]).forEach(v => query.append('next', v));
1182
+ const qs = query.toString();
1183
+ if (qs) path += '?' + qs;
1184
+ const resp = await fetch(this._ctx.baseUrl + path, { method: 'GET' });
1185
+ return handleResponse(resp);
1186
+ }
1187
+
1188
+ async postLogin({ email, password, next }) {
1189
+ const resp = await fetch(this._ctx.baseUrl + `/api/v1/oauth/login`, {
1190
+ method: 'POST',
1191
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1192
+ body: new URLSearchParams({ email, password, next }).toString(),
1193
+ });
1194
+ return handleResponse(resp);
1195
+ }
1196
+ }
1197
+
1198
+ class Person {
1199
+ constructor(ctx) { this._ctx = ctx; }
1200
+
1201
+ async updatePerson(projectTableName, personId, { personName } = {}) {
1202
+ this._ctx.requireTokens();
1203
+ let path = `/api/v1/person/${encodeURIComponent(projectTableName)}/${encodeURIComponent(personId)}`;
1204
+ const query = new URLSearchParams();
1205
+ if (personName !== undefined) (Array.isArray(personName) ? personName : [personName]).forEach(v => query.append('person_name', v));
1206
+ const qs = query.toString();
1207
+ if (qs) path += '?' + qs;
1208
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
1209
+ return data;
1210
+ }
1211
+
1212
+ async combinePersons(projectTableName, destinationPersonId, oldPersonId) {
1213
+ this._ctx.requireTokens();
1214
+ const path = `/api/v1/person/${encodeURIComponent(projectTableName)}/combine/${encodeURIComponent(destinationPersonId)}/${encodeURIComponent(oldPersonId)}`;
1215
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
1216
+ return data;
1217
+ }
1218
+
1219
+ async splitPersons(projectTableName, id, { newName, destinationPersonId } = {}) {
1220
+ this._ctx.requireTokens();
1221
+ let path = `/api/v1/person/${encodeURIComponent(projectTableName)}/split/${encodeURIComponent(id)}/`;
1222
+ const query = new URLSearchParams();
1223
+ if (newName !== undefined) (Array.isArray(newName) ? newName : [newName]).forEach(v => query.append('new_name', v));
1224
+ if (destinationPersonId !== undefined) (Array.isArray(destinationPersonId) ? destinationPersonId : [destinationPersonId]).forEach(v => query.append('destination_person_id', v));
1225
+ const qs = query.toString();
1226
+ if (qs) path += '?' + qs;
1227
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
1228
+ return data;
1229
+ }
1230
+
1231
+ async getAllPersonsFromProject(projectTableName) {
1232
+ this._ctx.requireTokens();
1233
+ const path = `/api/v1/person/${encodeURIComponent(projectTableName)}/`;
1234
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1235
+ return data;
1236
+ }
1237
+
1238
+ async getAllPersonNamesFromProject(projectTableName) {
1239
+ this._ctx.requireTokens();
1240
+ const path = `/api/v1/person/${encodeURIComponent(projectTableName)}/names`;
1241
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1242
+ return data;
1243
+ }
1244
+
1245
+ async getAllPersonsFromPhoto(projectTableName, photoId) {
1246
+ this._ctx.requireTokens();
1247
+ const path = `/api/v1/person/${encodeURIComponent(projectTableName)}/photo/${encodeURIComponent(photoId)}`;
1248
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1249
+ return data;
1250
+ }
1251
+ }
1252
+
1253
+ function stripUndef$1(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
1254
+
1255
+ class Projects {
1256
+ constructor(ctx) { this._ctx = ctx; }
1257
+
1258
+ async createProjectAndRun(name, private_ = undefined, type = undefined, description = undefined, directory = undefined, photoUploadVector = undefined, thumbnail = undefined, runName = undefined, { outcomes, models } = {}) {
1259
+ this._ctx.requireTokens();
1260
+ let path = `/api/v1/project_outcome/`;
1261
+ const query = new URLSearchParams();
1262
+ if (outcomes !== undefined) (Array.isArray(outcomes) ? outcomes : [outcomes]).forEach(v => query.append('outcomes', v));
1263
+ if (models !== undefined) (Array.isArray(models) ? models : [models]).forEach(v => query.append('models', v));
1264
+ const qs = query.toString();
1265
+ if (qs) path += '?' + qs;
1266
+ const body = stripUndef$1({
1267
+ name: name,
1268
+ private: private_,
1269
+ type: type,
1270
+ description: description,
1271
+ directory: directory,
1272
+ photo_upload_vector: photoUploadVector,
1273
+ thumbnail: thumbnail,
1274
+ run_name: runName,
1275
+ });
1276
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
1277
+ return data;
1278
+ }
1279
+
1280
+ async markProjectUploadComplete(projectTableName, { skippedFileCount } = {}) {
1281
+ this._ctx.requireTokens();
1282
+ let path = `/api/v1/project/${encodeURIComponent(projectTableName)}/upload_complete/`;
1283
+ const query = new URLSearchParams();
1284
+ if (skippedFileCount !== undefined) (Array.isArray(skippedFileCount) ? skippedFileCount : [skippedFileCount]).forEach(v => query.append('skipped_file_count', v));
1285
+ const qs = query.toString();
1286
+ if (qs) path += '?' + qs;
1287
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
1288
+ return data;
1289
+ }
1290
+
1291
+ async checkProjectStatus(projectTableName) {
1292
+ this._ctx.requireTokens();
1293
+ const path = `/api/v1/project/status/${encodeURIComponent(projectTableName)}`;
1294
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1295
+ return data;
1296
+ }
1297
+
1298
+ async getProjectPrelimModelRequestTemplate(projectTableName) {
1299
+ this._ctx.requireTokens();
1300
+ const path = `/api/v1/project_outcome/${encodeURIComponent(projectTableName)}`;
1301
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1302
+ return data;
1303
+ }
1304
+
1305
+ async getUserProjects() {
1306
+ this._ctx.requireTokens();
1307
+ const path = `/api/v1/projects/user`;
1308
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1309
+ return data;
1310
+ }
1311
+
1312
+ async getAdminProjects() {
1313
+ this._ctx.requireTokens();
1314
+ const path = `/api/v1/projects/admin`;
1315
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1316
+ return data;
1317
+ }
1318
+
1319
+ async getAllUserProjectsAdmin(userId) {
1320
+ this._ctx.requireTokens();
1321
+ const path = `/api/v1/projects/admin/user/${encodeURIComponent(userId)}`;
1322
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1323
+ return data;
1324
+ }
1325
+
1326
+ async getProjectById(projectId) {
1327
+ this._ctx.requireTokens();
1328
+ const path = `/api/v1/projects/${encodeURIComponent(projectId)}`;
1329
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1330
+ return data;
1331
+ }
1332
+
1333
+ async getProjectByDirectory(directory) {
1334
+ this._ctx.requireTokens();
1335
+ const path = `/api/v1/projects/directory/${encodeURIComponent(directory)}`;
1336
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1337
+ return data;
1338
+ }
1339
+
1340
+ async updateProject(projectId, { private: private_, type, description, directory, name, thumbnail } = {}) {
1341
+ this._ctx.requireTokens();
1342
+ const path = `/api/v1/projects/${encodeURIComponent(projectId)}`;
1343
+ const body = stripUndef$1({
1344
+ private: private_,
1345
+ type: type,
1346
+ description: description,
1347
+ directory: directory,
1348
+ name: name,
1349
+ thumbnail: thumbnail,
1350
+ });
1351
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
1352
+ return data;
1353
+ }
1354
+
1355
+ async updateProjectPhotoCount(tableName, { filesFailedCount } = {}) {
1356
+ this._ctx.requireTokens();
1357
+ let path = `/api/v1/projects_photos/${encodeURIComponent(tableName)}/`;
1358
+ const query = new URLSearchParams();
1359
+ if (filesFailedCount !== undefined) (Array.isArray(filesFailedCount) ? filesFailedCount : [filesFailedCount]).forEach(v => query.append('files_failed_count', v));
1360
+ const qs = query.toString();
1361
+ if (qs) path += '?' + qs;
1362
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
1363
+ return data;
1364
+ }
1365
+
1366
+ async updateProjectCreateUploadReport(tableName, { filesFailedCount } = {}) {
1367
+ this._ctx.requireTokens();
1368
+ let path = `/api/v1/project_upload_report/${encodeURIComponent(tableName)}/`;
1369
+ const query = new URLSearchParams();
1370
+ if (filesFailedCount !== undefined) (Array.isArray(filesFailedCount) ? filesFailedCount : [filesFailedCount]).forEach(v => query.append('files_failed_count', v));
1371
+ const qs = query.toString();
1372
+ if (qs) path += '?' + qs;
1373
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
1374
+ return data;
1375
+ }
1376
+
1377
+ async requestProjectSimilarityQueue(projectTableName, level) {
1378
+ this._ctx.requireTokens();
1379
+ const path = `/api/v1/projects_similarity_queue/${encodeURIComponent(projectTableName)}/level/${encodeURIComponent(level)}`;
1380
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1381
+ return data;
1382
+ }
1383
+
1384
+ async requestProjectEvidenceQueue(projectTableName) {
1385
+ this._ctx.requireTokens();
1386
+ const path = `/api/v1/projects_evidence_queue/${encodeURIComponent(projectTableName)}`;
1387
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1388
+ return data;
1389
+ }
1390
+
1391
+ async requestProjectPersonhoodQueue(projectTableName) {
1392
+ this._ctx.requireTokens();
1393
+ const path = `/api/v1/projects_personhood_queue/${encodeURIComponent(projectTableName)}`;
1394
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1395
+ return data;
1396
+ }
1397
+
1398
+ async requestInsightsQueue(analysisLevel, identifier) {
1399
+ this._ctx.requireTokens();
1400
+ const path = `/api/v1/insights_queue/analysis_level/${encodeURIComponent(analysisLevel)}/identifier/${encodeURIComponent(identifier)}`;
1401
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1402
+ return data;
1403
+ }
1404
+
1405
+ async requestProjectExport(projectTableName) {
1406
+ this._ctx.requireTokens();
1407
+ const path = `/api/v1/projects_export/${encodeURIComponent(projectTableName)}`;
1408
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1409
+ return data;
1410
+ }
1411
+
1412
+ async requestProjectAdminExport(projectTableName) {
1413
+ this._ctx.requireTokens();
1414
+ const path = `/api/v1/projects_admin_export/${encodeURIComponent(projectTableName)}`;
1415
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1416
+ return data;
1417
+ }
1418
+
1419
+ async getProjectDataExportUploadStatus(projectTableName, modelName) {
1420
+ this._ctx.requireTokens();
1421
+ const path = `/api/v1/projects/${encodeURIComponent(projectTableName)}/upload_status/${encodeURIComponent(modelName)}`;
1422
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1423
+ return data;
1424
+ }
1425
+
1426
+ async addProjectEvent(projectTableName, event, detail = undefined) {
1427
+ this._ctx.requireTokens();
1428
+ const path = `/api/v1/projects/${encodeURIComponent(projectTableName)}/event`;
1429
+ const body = stripUndef$1({
1430
+ event: event,
1431
+ detail: detail,
1432
+ });
1433
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
1434
+ return data;
1435
+ }
1436
+
1437
+ async deleteProject(projectId) {
1438
+ this._ctx.requireTokens();
1439
+ const path = `/api/v1/projects/${encodeURIComponent(projectId)}`;
1440
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
1441
+ return data;
1442
+ }
1443
+ }
1444
+
1445
+ class Photoupload {
1446
+ constructor(ctx) { this._ctx = ctx; this._caches = {}; }
1447
+
1448
+ async uploadPhotoToMediaviz(companyId, userId, projectTableName, title, { fileContent, mimetype, filePath }, { clientSideId, blur, colors, faceRecognition, imageDescribe, imageClassification, imageComparison, size, sourceResolutionX, sourceResolutionY, dateTaken, latitude, longitude, ocr } = {}) {
1449
+ this._ctx.requireTokens();
1450
+ const baseUrl = this._ctx.requireHost('photoUpload');
1451
+ const headers = {
1452
+ 'Content-Type': 'application/json',
1453
+ 'Authorization': this._ctx.accessToken,
1454
+ 'x-company-id': companyId,
1455
+ 'x-user-id': userId,
1456
+ 'x-project-table-name': projectTableName,
1457
+ 'x-title': title,
1458
+ };
1459
+ if (clientSideId !== undefined) headers['x-client-side-id'] = clientSideId;
1460
+ if (blur !== undefined) headers['x-blur'] = blur;
1461
+ if (colors !== undefined) headers['x-colors'] = colors;
1462
+ if (faceRecognition !== undefined) headers['x-face-recognition'] = faceRecognition;
1463
+ if (imageDescribe !== undefined) headers['x-image-describe'] = imageDescribe;
1464
+ if (imageClassification !== undefined) headers['x-image-classification'] = imageClassification;
1465
+ if (imageComparison !== undefined) headers['x-image-comparison'] = imageComparison;
1466
+ if (size !== undefined) headers['x-size'] = size;
1467
+ if (sourceResolutionX !== undefined) headers['x-source-resolution-x'] = sourceResolutionX;
1468
+ if (sourceResolutionY !== undefined) headers['x-source-resolution-y'] = sourceResolutionY;
1469
+ if (dateTaken !== undefined) headers['x-date-taken'] = dateTaken;
1470
+ if (latitude !== undefined) headers['x-latitude'] = latitude;
1471
+ if (longitude !== undefined) headers['x-longitude'] = longitude;
1472
+ if (ocr !== undefined) headers['x-ocr'] = ocr;
1473
+ const resp = await fetch(baseUrl + `/photo_upload`, {
1474
+ method: 'POST',
1475
+ headers,
1476
+ body: JSON.stringify({ file_content: fileContent, mimetype, file_path: filePath }),
1477
+ });
1478
+ return handleResponse(resp);
1479
+ }
1480
+
1481
+ async uploadPhoto(projectTableName, companyId, userId, photoIndex, photo) {
1482
+ this._ctx.requireTokens();
1483
+
1484
+ if (!this._caches['_get_template']) this._caches['_get_template'] = new Map();
1485
+ const _cacheKey_get_template = `upload_template:${projectTableName}`;
1486
+ let template = this._caches['_get_template'].get(_cacheKey_get_template);
1487
+ if (template === undefined) {
1488
+ template = (await this._ctx.client.request(`/api/v1/project_outcome/${encodeURIComponent(projectTableName)}`, 'GET', this._ctx.accessToken, this._ctx.refreshToken)).data;
1489
+ this._caches['_get_template'].set(_cacheKey_get_template, template);
1490
+ }
1491
+
1492
+ const upload_result = await this.uploadPhotoToMediaviz(companyId, userId, projectTableName, photo.title, { fileContent: photo.fileContent, mimetype: photo.mimetype, filePath: photo.filePath }, { clientSideId: photo.clientSideId, blur: photo.blur, colors: photo.colors, faceRecognition: photo.faceRecognition, imageDescribe: photo.imageDescribe, imageClassification: photo.imageClassification, imageComparison: photo.imageComparison, size: photo.size, sourceResolutionX: photo.sourceResolutionX, sourceResolutionY: photo.sourceResolutionY, dateTaken: photo.dateTaken, latitude: photo.latitude, longitude: photo.longitude });
1493
+
1494
+ return upload_result;
1495
+ }
1496
+ }
1497
+
1498
+ class Photos {
1499
+ constructor(ctx) { this._ctx = ctx; }
1500
+
1501
+ async addPhotoToProject({ photo, tableName, sourceResolutionX, sourceResolutionY, dateTaken, latitude, longitude, filePath, title, clientSideId }) {
1502
+ this._ctx.requireTokens();
1503
+ const path = `/api/v1/photos/`;
1504
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, { photo, table_name: tableName, source_resolution_x: sourceResolutionX, source_resolution_y: sourceResolutionY, date_taken: dateTaken, latitude, longitude, file_path: filePath, title, client_side_id: clientSideId });
1505
+ return data;
1506
+ }
1507
+
1508
+ async getPhotoFromProject(tableName, photoId, { keywordListId } = {}) {
1509
+ this._ctx.requireTokens();
1510
+ let path = `/api/v1/photos/${encodeURIComponent(tableName)}/${encodeURIComponent(photoId)}`;
1511
+ const query = new URLSearchParams();
1512
+ if (keywordListId !== undefined) (Array.isArray(keywordListId) ? keywordListId : [keywordListId]).forEach(v => query.append('keyword_list_id', v));
1513
+ const qs = query.toString();
1514
+ if (qs) path += '?' + qs;
1515
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1516
+ return data;
1517
+ }
1518
+
1519
+ async getPhotoFaceDetailsFromProject(tableName, photoId) {
1520
+ this._ctx.requireTokens();
1521
+ const path = `/api/v1/photos/face_details/${encodeURIComponent(tableName)}/${encodeURIComponent(photoId)}`;
1522
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1523
+ return data;
1524
+ }
1525
+
1526
+ async getProjectPhotoIdsByTableName(tableName, { ascOrDesc, lastId, limit, includeAll, startDate, endDate, noDateTaken } = {}) {
1527
+ this._ctx.requireTokens();
1528
+ let path = `/api/v1/photos/${encodeURIComponent(tableName)}/`;
1529
+ const query = new URLSearchParams();
1530
+ if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
1531
+ if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
1532
+ if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
1533
+ if (includeAll !== undefined) (Array.isArray(includeAll) ? includeAll : [includeAll]).forEach(v => query.append('include_all', v));
1534
+ if (startDate !== undefined) (Array.isArray(startDate) ? startDate : [startDate]).forEach(v => query.append('start_date', v));
1535
+ if (endDate !== undefined) (Array.isArray(endDate) ? endDate : [endDate]).forEach(v => query.append('end_date', v));
1536
+ if (noDateTaken !== undefined) (Array.isArray(noDateTaken) ? noDateTaken : [noDateTaken]).forEach(v => query.append('no_date_taken', v));
1537
+ const qs = query.toString();
1538
+ if (qs) path += '?' + qs;
1539
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1540
+ return data;
1541
+ }
1542
+
1543
+ async getRankedProjectPhotoIdsByTableName(tableName, { ascOrDesc, lastId, limit, startDate, endDate, noDateTaken } = {}) {
1544
+ this._ctx.requireTokens();
1545
+ let path = `/api/v1/photos/ranked/${encodeURIComponent(tableName)}/`;
1546
+ const query = new URLSearchParams();
1547
+ if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
1548
+ if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
1549
+ if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
1550
+ if (startDate !== undefined) (Array.isArray(startDate) ? startDate : [startDate]).forEach(v => query.append('start_date', v));
1551
+ if (endDate !== undefined) (Array.isArray(endDate) ? endDate : [endDate]).forEach(v => query.append('end_date', v));
1552
+ if (noDateTaken !== undefined) (Array.isArray(noDateTaken) ? noDateTaken : [noDateTaken]).forEach(v => query.append('no_date_taken', v));
1553
+ const qs = query.toString();
1554
+ if (qs) path += '?' + qs;
1555
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1556
+ return data;
1557
+ }
1558
+
1559
+ async getProjectMonthYearsWithPhotos(tableName) {
1560
+ this._ctx.requireTokens();
1561
+ const path = `/api/v1/photo_month_years/${encodeURIComponent(tableName)}`;
1562
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1563
+ return data;
1564
+ }
1565
+
1566
+ async getProjectThumbnail(tableName) {
1567
+ this._ctx.requireTokens();
1568
+ const path = `/api/v1/photos_project/${encodeURIComponent(tableName)}`;
1569
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1570
+ return data;
1571
+ }
1572
+
1573
+ async updatePhotoInProject({ tableName, photoId, photoData } = {}) {
1574
+ this._ctx.requireTokens();
1575
+ let path = `/api/v1/photos_update`;
1576
+ const query = new URLSearchParams();
1577
+ if (tableName !== undefined) (Array.isArray(tableName) ? tableName : [tableName]).forEach(v => query.append('table_name', v));
1578
+ if (photoId !== undefined) (Array.isArray(photoId) ? photoId : [photoId]).forEach(v => query.append('photo_id', v));
1579
+ if (photoData !== undefined) (Array.isArray(photoData) ? photoData : [photoData]).forEach(v => query.append('photo_data', v));
1580
+ const qs = query.toString();
1581
+ if (qs) path += '?' + qs;
1582
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
1583
+ return data;
1584
+ }
1585
+
1586
+ async updatePhotoRanking(tableName, photoId, newCategory) {
1587
+ this._ctx.requireTokens();
1588
+ const path = `/api/v1/photos_update/${encodeURIComponent(tableName)}/id/${encodeURIComponent(photoId)}/rank/${encodeURIComponent(newCategory)}`;
1589
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
1590
+ return data;
1591
+ }
1592
+
1593
+ async deletePhotoFromProject(tableName, { photoIds } = {}) {
1594
+ this._ctx.requireTokens();
1595
+ let path = `/api/v1/photos/${encodeURIComponent(tableName)}/delete/`;
1596
+ const query = new URLSearchParams();
1597
+ if (photoIds !== undefined) (Array.isArray(photoIds) ? photoIds : [photoIds]).forEach(v => query.append('photo_ids', v));
1598
+ const qs = query.toString();
1599
+ if (qs) path += '?' + qs;
1600
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
1601
+ return data;
1602
+ }
1603
+ }
1604
+
1605
+ class Search {
1606
+ constructor(ctx) { this._ctx = ctx; }
1607
+
1608
+ async searchProjectPhotos(projectTableName, { andParams, andStringParams, orParams, orStringParams, notParams, notStringParams, dateMin, dateMax, dateNullAnd, dateNullOr, dateOrder, customAlbumId, bestOfSimilarSetsOnly, curatedAlbumId, splitByTier } = {}) {
1609
+ this._ctx.requireTokens();
1610
+ let path = `/api/v1/search/${encodeURIComponent(projectTableName)}/`;
1611
+ const query = new URLSearchParams();
1612
+ if (andParams !== undefined) (Array.isArray(andParams) ? andParams : [andParams]).forEach(v => query.append('and_params', v));
1613
+ if (andStringParams !== undefined) (Array.isArray(andStringParams) ? andStringParams : [andStringParams]).forEach(v => query.append('and_string_params', v));
1614
+ if (orParams !== undefined) (Array.isArray(orParams) ? orParams : [orParams]).forEach(v => query.append('or_params', v));
1615
+ if (orStringParams !== undefined) (Array.isArray(orStringParams) ? orStringParams : [orStringParams]).forEach(v => query.append('or_string_params', v));
1616
+ if (notParams !== undefined) (Array.isArray(notParams) ? notParams : [notParams]).forEach(v => query.append('not_params', v));
1617
+ if (notStringParams !== undefined) (Array.isArray(notStringParams) ? notStringParams : [notStringParams]).forEach(v => query.append('not_string_params', v));
1618
+ if (dateMin !== undefined) (Array.isArray(dateMin) ? dateMin : [dateMin]).forEach(v => query.append('date_min', v));
1619
+ if (dateMax !== undefined) (Array.isArray(dateMax) ? dateMax : [dateMax]).forEach(v => query.append('date_max', v));
1620
+ if (dateNullAnd !== undefined) (Array.isArray(dateNullAnd) ? dateNullAnd : [dateNullAnd]).forEach(v => query.append('date_null_and', v));
1621
+ if (dateNullOr !== undefined) (Array.isArray(dateNullOr) ? dateNullOr : [dateNullOr]).forEach(v => query.append('date_null_or', v));
1622
+ if (dateOrder !== undefined) (Array.isArray(dateOrder) ? dateOrder : [dateOrder]).forEach(v => query.append('date_order', v));
1623
+ if (customAlbumId !== undefined) (Array.isArray(customAlbumId) ? customAlbumId : [customAlbumId]).forEach(v => query.append('custom_album_id', v));
1624
+ if (bestOfSimilarSetsOnly !== undefined) (Array.isArray(bestOfSimilarSetsOnly) ? bestOfSimilarSetsOnly : [bestOfSimilarSetsOnly]).forEach(v => query.append('best_of_similar_sets_only', v));
1625
+ if (curatedAlbumId !== undefined) (Array.isArray(curatedAlbumId) ? curatedAlbumId : [curatedAlbumId]).forEach(v => query.append('curated_album_id', v));
1626
+ if (splitByTier !== undefined) (Array.isArray(splitByTier) ? splitByTier : [splitByTier]).forEach(v => query.append('split_by_tier', v));
1627
+ const qs = query.toString();
1628
+ if (qs) path += '?' + qs;
1629
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1630
+ return data;
1631
+ }
1632
+
1633
+ async searchProjectPhotosText(projectTableName, { q, size } = {}) {
1634
+ this._ctx.requireTokens();
1635
+ let path = `/api/v1/search/text/${encodeURIComponent(projectTableName)}/`;
1636
+ const query = new URLSearchParams();
1637
+ if (q !== undefined) (Array.isArray(q) ? q : [q]).forEach(v => query.append('q', v));
1638
+ if (size !== undefined) (Array.isArray(size) ? size : [size]).forEach(v => query.append('size', v));
1639
+ const qs = query.toString();
1640
+ if (qs) path += '?' + qs;
1641
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1642
+ return data;
1643
+ }
1644
+
1645
+ async searchProjectPhotosNaturalLanguage(projectTableName, { searchText, size } = {}) {
1646
+ this._ctx.requireTokens();
1647
+ let path = `/api/v1/search/nl/${encodeURIComponent(projectTableName)}/`;
1648
+ const query = new URLSearchParams();
1649
+ if (searchText !== undefined) (Array.isArray(searchText) ? searchText : [searchText]).forEach(v => query.append('search_text', v));
1650
+ if (size !== undefined) (Array.isArray(size) ? size : [size]).forEach(v => query.append('size', v));
1651
+ const qs = query.toString();
1652
+ if (qs) path += '?' + qs;
1653
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1654
+ return data;
1655
+ }
1656
+
1657
+ async getProjectSavedSearches(projectTableName) {
1658
+ this._ctx.requireTokens();
1659
+ const path = `/api/v1/search/saved/${encodeURIComponent(projectTableName)}/`;
1660
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1661
+ return data;
1662
+ }
1663
+
1664
+ async getSavedSearchById(searchId) {
1665
+ this._ctx.requireTokens();
1666
+ const path = `/api/v1/search/${encodeURIComponent(searchId)}`;
1667
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1668
+ return data;
1669
+ }
1670
+
1671
+ async saveProjectPhotosSearch(projectTableName, { searchName, andParams, andStringParams, orParams, orStringParams, notParams, notStringParams, dateMin, dateMax, dateNullAnd, dateNullOr, dateOrder, customAlbumId, bestOfSimilarSetsOnly, curatedAlbumId, splitByTier } = {}) {
1672
+ this._ctx.requireTokens();
1673
+ let path = `/api/v1/search/${encodeURIComponent(projectTableName)}/`;
1674
+ const query = new URLSearchParams();
1675
+ if (searchName !== undefined) (Array.isArray(searchName) ? searchName : [searchName]).forEach(v => query.append('search_name', v));
1676
+ if (andParams !== undefined) (Array.isArray(andParams) ? andParams : [andParams]).forEach(v => query.append('and_params', v));
1677
+ if (andStringParams !== undefined) (Array.isArray(andStringParams) ? andStringParams : [andStringParams]).forEach(v => query.append('and_string_params', v));
1678
+ if (orParams !== undefined) (Array.isArray(orParams) ? orParams : [orParams]).forEach(v => query.append('or_params', v));
1679
+ if (orStringParams !== undefined) (Array.isArray(orStringParams) ? orStringParams : [orStringParams]).forEach(v => query.append('or_string_params', v));
1680
+ if (notParams !== undefined) (Array.isArray(notParams) ? notParams : [notParams]).forEach(v => query.append('not_params', v));
1681
+ if (notStringParams !== undefined) (Array.isArray(notStringParams) ? notStringParams : [notStringParams]).forEach(v => query.append('not_string_params', v));
1682
+ if (dateMin !== undefined) (Array.isArray(dateMin) ? dateMin : [dateMin]).forEach(v => query.append('date_min', v));
1683
+ if (dateMax !== undefined) (Array.isArray(dateMax) ? dateMax : [dateMax]).forEach(v => query.append('date_max', v));
1684
+ if (dateNullAnd !== undefined) (Array.isArray(dateNullAnd) ? dateNullAnd : [dateNullAnd]).forEach(v => query.append('date_null_and', v));
1685
+ if (dateNullOr !== undefined) (Array.isArray(dateNullOr) ? dateNullOr : [dateNullOr]).forEach(v => query.append('date_null_or', v));
1686
+ if (dateOrder !== undefined) (Array.isArray(dateOrder) ? dateOrder : [dateOrder]).forEach(v => query.append('date_order', v));
1687
+ if (customAlbumId !== undefined) (Array.isArray(customAlbumId) ? customAlbumId : [customAlbumId]).forEach(v => query.append('custom_album_id', v));
1688
+ if (bestOfSimilarSetsOnly !== undefined) (Array.isArray(bestOfSimilarSetsOnly) ? bestOfSimilarSetsOnly : [bestOfSimilarSetsOnly]).forEach(v => query.append('best_of_similar_sets_only', v));
1689
+ if (curatedAlbumId !== undefined) (Array.isArray(curatedAlbumId) ? curatedAlbumId : [curatedAlbumId]).forEach(v => query.append('curated_album_id', v));
1690
+ if (splitByTier !== undefined) (Array.isArray(splitByTier) ? splitByTier : [splitByTier]).forEach(v => query.append('split_by_tier', v));
1691
+ const qs = query.toString();
1692
+ if (qs) path += '?' + qs;
1693
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
1694
+ return data;
1695
+ }
1696
+
1697
+ async deleteSavedSearchById(searchId) {
1698
+ this._ctx.requireTokens();
1699
+ const path = `/api/v1/search/${encodeURIComponent(searchId)}`;
1700
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
1701
+ return data;
1702
+ }
1703
+ }
1704
+
1705
+ function stripUndef(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
1706
+
1707
+ class Users {
1708
+ constructor(ctx) { this._ctx = ctx; }
1709
+
1710
+ async createUser(name, email, accountType, companyId = undefined, profilePicture = undefined, paymentPlanType = undefined) {
1711
+ this._ctx.requireTokens();
1712
+ const path = `/api/v1/users/`;
1713
+ const body = stripUndef({
1714
+ name: name,
1715
+ email: email,
1716
+ company_id: companyId,
1717
+ profile_picture: profilePicture,
1718
+ payment_plan_type: paymentPlanType,
1719
+ account_type: accountType,
1720
+ });
1721
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
1722
+ return data;
1723
+ }
1724
+
1725
+ async createUserAndCompany(name, email, password, companyId = undefined, profilePicture = undefined, paymentPlanType = undefined, companyName = undefined, credits = undefined, { inviteToken } = {}) {
1726
+ let path = `/api/v1/users/new_company/`;
1727
+ const query = new URLSearchParams();
1728
+ if (inviteToken !== undefined) (Array.isArray(inviteToken) ? inviteToken : [inviteToken]).forEach(v => query.append('invite_token', v));
1729
+ const qs = query.toString();
1730
+ if (qs) path += '?' + qs;
1731
+ const body = stripUndef({
1732
+ name: name,
1733
+ email: email,
1734
+ company_id: companyId,
1735
+ profile_picture: profilePicture,
1736
+ payment_plan_type: paymentPlanType,
1737
+ password: password,
1738
+ company_name: companyName,
1739
+ credits: credits,
1740
+ });
1741
+ const resp = await fetch(this._ctx.baseUrl + path, {
1742
+ method: 'POST',
1743
+ headers: { 'Content-Type': 'application/json' },
1744
+ body: JSON.stringify(body),
1745
+ });
1746
+ return handleResponse(resp);
1747
+ }
1748
+
1749
+ async changePassword(oldPassword, newPassword) {
1750
+ this._ctx.requireTokens();
1751
+ const path = `/api/v1/user/change_password`;
1752
+ const body = stripUndef({
1753
+ old_password: oldPassword,
1754
+ new_password: newPassword,
1755
+ });
1756
+ const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
1757
+ return data;
1758
+ }
1759
+
1760
+ async getUserId() {
1761
+ this._ctx.requireTokens();
1762
+ const path = `/api/v1/users`;
1763
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1764
+ return data;
1765
+ }
1766
+
1767
+ async getUser(userId) {
1768
+ this._ctx.requireTokens();
1769
+ const path = `/api/v1/users/${encodeURIComponent(userId)}`;
1770
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1771
+ return data;
1772
+ }
1773
+
1774
+ async getAllUsersByCompany(companyId) {
1775
+ this._ctx.requireTokens();
1776
+ const path = `/api/v1/users/company/${encodeURIComponent(companyId)}`;
1777
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1778
+ return data;
1779
+ }
1780
+
1781
+ async getAllUsers(ascOrDesc, { lastId, limit } = {}) {
1782
+ this._ctx.requireTokens();
1783
+ let path = `/api/v1/users/admin/sort/${encodeURIComponent(ascOrDesc)}/`;
1784
+ const query = new URLSearchParams();
1785
+ if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
1786
+ if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
1787
+ const qs = query.toString();
1788
+ if (qs) path += '?' + qs;
1789
+ const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
1790
+ return data;
1791
+ }
1792
+
1793
+ async updateUser(userId, { name, email, password, companyId, accountType, profilePicture, location, phoneNumber, birthday } = {}) {
1794
+ this._ctx.requireTokens();
1795
+ const path = `/api/v1/users/${encodeURIComponent(userId)}`;
1796
+ const body = stripUndef({
1797
+ name: name,
1798
+ email: email,
1799
+ password: password,
1800
+ company_id: companyId,
1801
+ account_type: accountType,
1802
+ profile_picture: profilePicture,
1803
+ location: location,
1804
+ phone_number: phoneNumber,
1805
+ birthday: birthday,
1806
+ });
1807
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
1808
+ return data;
1809
+ }
1810
+
1811
+ async updateUserByAdmin(userId, { name, email, password, companyId, accountType, profilePicture, location, phoneNumber, birthday } = {}) {
1812
+ this._ctx.requireTokens();
1813
+ const path = `/api/v1/users/admin/${encodeURIComponent(userId)}`;
1814
+ const body = stripUndef({
1815
+ name: name,
1816
+ email: email,
1817
+ password: password,
1818
+ company_id: companyId,
1819
+ account_type: accountType,
1820
+ profile_picture: profilePicture,
1821
+ location: location,
1822
+ phone_number: phoneNumber,
1823
+ birthday: birthday,
1824
+ });
1825
+ const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
1826
+ return data;
1827
+ }
1828
+
1829
+ async deleteUser(userId, { newCompanyOwnerId } = {}) {
1830
+ this._ctx.requireTokens();
1831
+ let path = `/api/v1/users/delete/${encodeURIComponent(userId)}`;
1832
+ const query = new URLSearchParams();
1833
+ if (newCompanyOwnerId !== undefined) (Array.isArray(newCompanyOwnerId) ? newCompanyOwnerId : [newCompanyOwnerId]).forEach(v => query.append('new_company_owner_id', v));
1834
+ const qs = query.toString();
1835
+ if (qs) path += '?' + qs;
1836
+ const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
1837
+ return data;
1838
+ }
1839
+ }
1840
+
1841
+ // Auto-generated — do not edit
1842
+
1843
+ function _env(key) {
1844
+ if (typeof process !== 'undefined' && process.env) return process.env[key];
1845
+ return undefined;
1846
+ }
1847
+
1848
+ class _Context {
1849
+ constructor(mv) { this._mv = mv; }
1850
+ get client() { return this._mv._oauthClient; }
1851
+ get accessToken() { return this._mv._accessToken; }
1852
+ get refreshToken() { return this._mv._refreshToken; }
1853
+ get baseUrl() { return this._mv._config.baseUrl; }
1854
+ get hosts() { return this._mv._hosts; }
1855
+ requireHost(key) {
1856
+ const url = this._mv._hosts[key];
1857
+ if (!url) throw new Error(`Host '${key}' not configured. Pass hosts.${key} in MediaViz constructor or set the corresponding env var.`);
1858
+ return url;
1859
+ }
1860
+ requireTokens() {
1861
+ if (!this._mv._accessToken) throw new Error('Not authenticated. Call authenticate(), handleCallback(), or setTokens() first.');
1862
+ }
1863
+ }
1864
+
1865
+ class _TokenTrackingClient {
1866
+ constructor(mv, inner) { this._mv = mv; this._inner = inner; }
1867
+ async request(url, method, accessToken, refreshToken, body) {
1868
+ const onRefreshSuccess = (newTokens) => {
1869
+ this._mv._accessToken = newTokens.access_token;
1870
+ this._mv._refreshToken = newTokens.refresh_token;
1871
+ if (this._mv._onTokenRefresh) this._mv._onTokenRefresh(newTokens);
1872
+ };
1873
+ return this._inner.request(url, method, accessToken, refreshToken, body, onRefreshSuccess);
1874
+ }
1875
+ }
1876
+
1877
+ class MediaViz {
1878
+ constructor(config = {}) {
1879
+ this._config = {
1880
+ clientId: config.clientId ?? _env('MEDIAVIZ_CLIENT_ID'),
1881
+ clientSecret: config.clientSecret ?? _env('MEDIAVIZ_CLIENT_SECRET'),
1882
+ baseUrl: config.baseUrl ?? _env('MEDIAVIZ_BASE_URL') ?? 'https://api.mediaviz.ai',
1883
+ redirectUri: config.redirectUri ?? _env('MEDIAVIZ_REDIRECT_URI'),
1884
+ };
1885
+ this._hosts = {
1886
+ photoUpload: config.hosts?.photoUpload ?? _env('MEDIAVIZ_PHOTO_UPLOAD_URL'),
1887
+ ...(config.hosts || {}),
1888
+ };
1889
+ this._accessToken = config.accessToken ?? null;
1890
+ this._refreshToken = config.refreshToken ?? null;
1891
+ this._onTokenRefresh = config.onTokenRefresh ?? null;
1892
+
1893
+ const _inner = new OAuthClient({
1894
+ clientId: this._config.clientId,
1895
+ clientSecret: this._config.clientSecret,
1896
+ baseUrl: this._config.baseUrl,
1897
+ redirectUri: this._config.redirectUri,
1898
+ });
1899
+ this._oauthClient = new _TokenTrackingClient(this, _inner);
1900
+
1901
+ const _ctx = new _Context(this);
1902
+ this.aiModelCredits = new AiModelCredits(_ctx);
1903
+ this.admin = new Admin(_ctx);
1904
+ this.company = new Company(_ctx);
1905
+ this.curatedAlbums = new CuratedAlbums(_ctx);
1906
+ this.customAlbums = new CustomAlbums(_ctx);
1907
+ this.emailTokens = new EmailTokens(_ctx);
1908
+ this.health = new Health(_ctx);
1909
+ this.keywords = new Keywords(_ctx);
1910
+ this.oAuthAuthorization = new OauthAuthorization(_ctx);
1911
+ this.oAuthClients = new OauthClients(_ctx);
1912
+ this.oAuthToken = new OauthToken(_ctx);
1913
+ this.oauthLogin = new OauthLogin(_ctx);
1914
+ this.person = new Person(_ctx);
1915
+ this.photoUpload = new Photoupload(_ctx);
1916
+ this.photos = new Photos(_ctx);
1917
+ this.projects = new Projects(_ctx);
1918
+ this.search = new Search(_ctx);
1919
+ this.users = new Users(_ctx);
1920
+ }
1921
+
1922
+ async authenticate() {
1923
+ const tokens = await this._oauthClient._inner.getClientCredentialsToken();
1924
+ this._accessToken = tokens.access_token;
1925
+ this._refreshToken = tokens.refresh_token ?? null;
1926
+ return tokens;
1927
+ }
1928
+
1929
+ async getAuthorizationUrl(state) {
1930
+ return this._oauthClient._inner.generateAuthorizationUrl(state);
1931
+ }
1932
+
1933
+ async handleCallback(code, codeVerifier) {
1934
+ const tokens = await this._oauthClient._inner.exchangeCode(code, codeVerifier);
1935
+ this._accessToken = tokens.access_token;
1936
+ this._refreshToken = tokens.refresh_token;
1937
+ return tokens;
1938
+ }
1939
+
1940
+ setTokens(accessToken, refreshToken) {
1941
+ this._accessToken = accessToken;
1942
+ this._refreshToken = refreshToken;
1943
+ }
1944
+
1945
+ get accessToken() { return this._accessToken; }
1946
+ get refreshToken() { return this._refreshToken; }
1947
+ }
1948
+
1949
+ exports.Admin = Admin;
1950
+ exports.AiModelCredits = AiModelCredits;
1951
+ exports.ApiError = ApiError;
1952
+ exports.Company = Company;
1953
+ exports.CuratedAlbums = CuratedAlbums;
1954
+ exports.CustomAlbums = CustomAlbums;
1955
+ exports.EmailTokens = EmailTokens;
1956
+ exports.Health = Health;
1957
+ exports.Keywords = Keywords;
1958
+ exports.MediaViz = MediaViz;
1959
+ exports.NotFoundError = NotFoundError;
1960
+ exports.OAuthClient = OAuthClient;
1961
+ exports.OAuthError = OAuthError;
1962
+ exports.OAuthErrorCode = OAuthErrorCode;
1963
+ exports.OauthAuthorization = OauthAuthorization;
1964
+ exports.OauthClients = OauthClients;
1965
+ exports.OauthLogin = OauthLogin;
1966
+ exports.OauthToken = OauthToken;
1967
+ exports.Person = Person;
1968
+ exports.Photos = Photos;
1969
+ exports.Photoupload = Photoupload;
1970
+ exports.Projects = Projects;
1971
+ exports.RateLimitError = RateLimitError;
1972
+ exports.Search = Search;
1973
+ exports.ServerError = ServerError;
1974
+ exports.Users = Users;
1975
+ exports.ValidationError = ValidationError;
1976
+ exports.handleResponse = handleResponse;