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