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