@mediaviz/sdk 0.1.0 → 1.0.59
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/LICENSE +21 -0
- package/dist/sdk.cjs +33 -240
- package/dist/sdk.esm.js +34 -239
- package/dist/sdk.umd.js +33 -240
- package/package.json +14 -8
- package/MediaViz.js +0 -126
- package/_oauth.js +0 -3
- package/admin.js +0 -93
- package/ai_model_credits.js +0 -22
- package/company.js +0 -54
- package/curated_albums.js +0 -85
- package/custom_albums.js +0 -78
- package/email_tokens.js +0 -64
- package/errors.js +0 -81
- package/health.js +0 -20
- package/index.js +0 -21
- package/keywords.js +0 -123
- package/oauth/.prettierrc +0 -6
- package/oauth/README.md +0 -76
- package/oauth/browser-smoke-test.html +0 -45
- package/oauth/implementation_plan.json +0 -106
- package/oauth/package-lock.json +0 -5236
- package/oauth/package.json +0 -28
- package/oauth/rollup.config.js +0 -21
- package/oauth/smoke-test.js +0 -27
- package/oauth/spec.md +0 -187
- package/oauth/src/__tests__/browser-smoke-test.test.js +0 -38
- package/oauth/src/__tests__/client.test.js +0 -556
- package/oauth/src/__tests__/errors.test.js +0 -73
- package/oauth/src/__tests__/http.test.js +0 -102
- package/oauth/src/__tests__/index.test.js +0 -53
- package/oauth/src/__tests__/package-fields.test.js +0 -29
- package/oauth/src/__tests__/pkce.test.js +0 -55
- package/oauth/src/__tests__/rollup-build.test.js +0 -58
- package/oauth/src/__tests__/smoke-test.test.js +0 -26
- package/oauth/src/__tests__/types.test.js +0 -29
- package/oauth/src/client.js +0 -180
- package/oauth/src/errors.js +0 -32
- package/oauth/src/http.js +0 -52
- package/oauth/src/index.js +0 -7
- package/oauth/src/pkce.js +0 -50
- package/oauth/src/types.js +0 -67
- package/oauth_authorization.js +0 -53
- package/oauth_clients.js +0 -18
- package/oauth_login.js +0 -24
- package/oauth_token.js +0 -30
- package/person.js +0 -54
- package/photos.js +0 -106
- package/photoupload.js +0 -55
- package/projects.js +0 -191
- package/rollup.config.js +0 -12
- package/search.js +0 -99
- package/users.js +0 -137
package/oauth/src/types.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Object} OAuthClientConfig
|
|
3
|
-
* @property {string} baseUrl - Base URL of the OAuth server
|
|
4
|
-
* @property {string} clientId - Registered client_id
|
|
5
|
-
* @property {string} clientSecret - Registered client_secret
|
|
6
|
-
* @property {string} redirectUri - Registered redirect URI
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {Object} TokenResponse
|
|
11
|
-
* @property {string} access_token - Signed JWT access token
|
|
12
|
-
* @property {string} token_type - Always "bearer"
|
|
13
|
-
* @property {number} expires_in - Seconds until access token expires
|
|
14
|
-
* @property {string} refresh_token - Opaque refresh token
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @typedef {Object} TokenPayload
|
|
19
|
-
* @property {string} user_id - ID of the authenticated user
|
|
20
|
-
* @property {string} client_id - ID of the OAuth client
|
|
21
|
-
* @property {string} jti - Unique token ID
|
|
22
|
-
* @property {number} iat - Issued-at timestamp (Unix seconds)
|
|
23
|
-
* @property {number} exp - Expiry timestamp (Unix seconds)
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @typedef {Object} AuthorizationUrlResult
|
|
28
|
-
* @property {string} url - Full authorization URL
|
|
29
|
-
* @property {string} state - CSRF state value; persist between redirect and callback
|
|
30
|
-
* @property {string} code_verifier - PKCE verifier; persist between redirect and callback
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @typedef {Object} AuthenticatedResponse
|
|
35
|
-
* @property {Object} data - Parsed JSON response body from resource server
|
|
36
|
-
* @property {TokenResponse|null} updatedTokens - Non-null only when token refresh occurred
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @typedef {Object} ClientRegistrationRequest
|
|
41
|
-
* @property {string} baseUrl - Base URL of the OAuth server
|
|
42
|
-
* @property {string} clientName - Human-readable client name
|
|
43
|
-
* @property {string} clientType - "public" or "confidential"
|
|
44
|
-
* @property {string[]} redirectUris - HTTPS redirect URIs
|
|
45
|
-
* @property {boolean} isFirstParty - Whether this is a first-party client
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @typedef {Object} ClientRegistrationResponse
|
|
50
|
-
* @property {string} client_id - Assigned client ID
|
|
51
|
-
* @property {string} client_name - Registered client name
|
|
52
|
-
* @property {string} client_type - "public" or "confidential"
|
|
53
|
-
* @property {string[]} redirect_uris - Registered redirect URIs
|
|
54
|
-
* @property {string} [client_secret] - Only present for confidential clients
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
const OAuthErrorCode = Object.freeze({
|
|
58
|
-
INVALID_REQUEST: 'invalid_request',
|
|
59
|
-
INVALID_CLIENT: 'invalid_client',
|
|
60
|
-
INVALID_GRANT: 'invalid_grant',
|
|
61
|
-
UNAUTHORIZED_CLIENT: 'unauthorized_client',
|
|
62
|
-
UNSUPPORTED_GRANT_TYPE: 'unsupported_grant_type',
|
|
63
|
-
ACCESS_DENIED: 'access_denied',
|
|
64
|
-
SERVER_ERROR: 'server_error',
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
module.exports = { OAuthErrorCode };
|
package/oauth_authorization.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { handleResponse } from './errors.js';
|
|
2
|
-
|
|
3
|
-
export class OauthAuthorization {
|
|
4
|
-
constructor(ctx) { this._ctx = ctx; }
|
|
5
|
-
|
|
6
|
-
async authorize({ responseType, clientId, redirectUri, state, codeChallenge, codeChallengeMethod } = {}) {
|
|
7
|
-
let path = `/oauth/authorize`;
|
|
8
|
-
const query = new URLSearchParams();
|
|
9
|
-
if (responseType !== undefined) (Array.isArray(responseType) ? responseType : [responseType]).forEach(v => query.append('response_type', v));
|
|
10
|
-
if (clientId !== undefined) (Array.isArray(clientId) ? clientId : [clientId]).forEach(v => query.append('client_id', v));
|
|
11
|
-
if (redirectUri !== undefined) (Array.isArray(redirectUri) ? redirectUri : [redirectUri]).forEach(v => query.append('redirect_uri', v));
|
|
12
|
-
if (state !== undefined) (Array.isArray(state) ? state : [state]).forEach(v => query.append('state', v));
|
|
13
|
-
if (codeChallenge !== undefined) (Array.isArray(codeChallenge) ? codeChallenge : [codeChallenge]).forEach(v => query.append('code_challenge', v));
|
|
14
|
-
if (codeChallengeMethod !== undefined) (Array.isArray(codeChallengeMethod) ? codeChallengeMethod : [codeChallengeMethod]).forEach(v => query.append('code_challenge_method', v));
|
|
15
|
-
const qs = query.toString();
|
|
16
|
-
if (qs) path += '?' + qs;
|
|
17
|
-
const resp = await fetch(this._ctx.baseUrl + path, { method: 'GET' });
|
|
18
|
-
return handleResponse(resp);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async getConsent(sessionId) {
|
|
22
|
-
const resp = await fetch(this._ctx.baseUrl + `/oauth/consent/${encodeURIComponent(sessionId)}`, { method: 'GET' });
|
|
23
|
-
return handleResponse(resp);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async postApproveConsent(sessionId, { restartUrl }) {
|
|
27
|
-
const resp = await fetch(this._ctx.baseUrl + `/oauth/consent/${encodeURIComponent(sessionId)}/approve`, {
|
|
28
|
-
method: 'POST',
|
|
29
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
30
|
-
body: new URLSearchParams({ restart_url: restartUrl }).toString(),
|
|
31
|
-
});
|
|
32
|
-
return handleResponse(resp);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async postDenyConsent(sessionId, { restartUrl }) {
|
|
36
|
-
const resp = await fetch(this._ctx.baseUrl + `/oauth/consent/${encodeURIComponent(sessionId)}/deny`, {
|
|
37
|
-
method: 'POST',
|
|
38
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
39
|
-
body: new URLSearchParams({ restart_url: restartUrl }).toString(),
|
|
40
|
-
});
|
|
41
|
-
return handleResponse(resp);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async getSwitchUser(sessionId, { restartUrl } = {}) {
|
|
45
|
-
let path = `/oauth/consent/${encodeURIComponent(sessionId)}/switch-user`;
|
|
46
|
-
const query = new URLSearchParams();
|
|
47
|
-
if (restartUrl !== undefined) (Array.isArray(restartUrl) ? restartUrl : [restartUrl]).forEach(v => query.append('restart_url', v));
|
|
48
|
-
const qs = query.toString();
|
|
49
|
-
if (qs) path += '?' + qs;
|
|
50
|
-
const resp = await fetch(this._ctx.baseUrl + path, { method: 'GET' });
|
|
51
|
-
return handleResponse(resp);
|
|
52
|
-
}
|
|
53
|
-
}
|
package/oauth_clients.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
function stripUndef(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
|
|
2
|
-
|
|
3
|
-
export class OauthClients {
|
|
4
|
-
constructor(ctx) { this._ctx = ctx; }
|
|
5
|
-
|
|
6
|
-
async createClient(clientName, clientType, redirectUris, isFirstParty) {
|
|
7
|
-
this._ctx.requireTokens();
|
|
8
|
-
const path = `/oauth/clients`;
|
|
9
|
-
const body = stripUndef({
|
|
10
|
-
client_name: clientName,
|
|
11
|
-
client_type: clientType,
|
|
12
|
-
redirect_uris: redirectUris,
|
|
13
|
-
is_first_party: isFirstParty,
|
|
14
|
-
});
|
|
15
|
-
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
16
|
-
return data;
|
|
17
|
-
}
|
|
18
|
-
}
|
package/oauth_login.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { handleResponse } from './errors.js';
|
|
2
|
-
|
|
3
|
-
export class OauthLogin {
|
|
4
|
-
constructor(ctx) { this._ctx = ctx; }
|
|
5
|
-
|
|
6
|
-
async getLogin({ next } = {}) {
|
|
7
|
-
let path = `/api/v1/oauth/login`;
|
|
8
|
-
const query = new URLSearchParams();
|
|
9
|
-
if (next !== undefined) (Array.isArray(next) ? next : [next]).forEach(v => query.append('next', v));
|
|
10
|
-
const qs = query.toString();
|
|
11
|
-
if (qs) path += '?' + qs;
|
|
12
|
-
const resp = await fetch(this._ctx.baseUrl + path, { method: 'GET' });
|
|
13
|
-
return handleResponse(resp);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async postLogin({ email, password, next }) {
|
|
17
|
-
const resp = await fetch(this._ctx.baseUrl + `/api/v1/oauth/login`, {
|
|
18
|
-
method: 'POST',
|
|
19
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
20
|
-
body: new URLSearchParams({ email, password, next }).toString(),
|
|
21
|
-
});
|
|
22
|
-
return handleResponse(resp);
|
|
23
|
-
}
|
|
24
|
-
}
|
package/oauth_token.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { handleResponse } from './errors.js';
|
|
2
|
-
|
|
3
|
-
export class OauthToken {
|
|
4
|
-
constructor(ctx) { this._ctx = ctx; }
|
|
5
|
-
|
|
6
|
-
async token({ grantType, code, redirectUri, clientId, codeVerifier, refreshToken, clientSecret }) {
|
|
7
|
-
const resp = await fetch(this._ctx.baseUrl + `/oauth/token`, {
|
|
8
|
-
method: 'POST',
|
|
9
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
10
|
-
body: new URLSearchParams({ grant_type: grantType, code, redirect_uri: redirectUri, client_id: clientId, code_verifier: codeVerifier, refresh_token: refreshToken, client_secret: clientSecret }).toString(),
|
|
11
|
-
});
|
|
12
|
-
return handleResponse(resp);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async adminRevokeUserTokens(userId) {
|
|
16
|
-
this._ctx.requireTokens();
|
|
17
|
-
const path = `/oauth/admin/users/${encodeURIComponent(userId)}/revoke-tokens`;
|
|
18
|
-
const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async revoke({ token, tokenTypeHint, clientId }) {
|
|
23
|
-
const resp = await fetch(this._ctx.baseUrl + `/oauth/revoke`, {
|
|
24
|
-
method: 'POST',
|
|
25
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
26
|
-
body: new URLSearchParams({ token, token_type_hint: tokenTypeHint, client_id: clientId }).toString(),
|
|
27
|
-
});
|
|
28
|
-
return handleResponse(resp);
|
|
29
|
-
}
|
|
30
|
-
}
|
package/person.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export class Person {
|
|
2
|
-
constructor(ctx) { this._ctx = ctx; }
|
|
3
|
-
|
|
4
|
-
async updatePerson(projectTableName, personId, { personName } = {}) {
|
|
5
|
-
this._ctx.requireTokens();
|
|
6
|
-
let path = `/api/v1/person/${encodeURIComponent(projectTableName)}/${encodeURIComponent(personId)}`;
|
|
7
|
-
const query = new URLSearchParams();
|
|
8
|
-
if (personName !== undefined) (Array.isArray(personName) ? personName : [personName]).forEach(v => query.append('person_name', v));
|
|
9
|
-
const qs = query.toString();
|
|
10
|
-
if (qs) path += '?' + qs;
|
|
11
|
-
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async combinePersons(projectTableName, destinationPersonId, oldPersonId) {
|
|
16
|
-
this._ctx.requireTokens();
|
|
17
|
-
const path = `/api/v1/person/${encodeURIComponent(projectTableName)}/combine/${encodeURIComponent(destinationPersonId)}/${encodeURIComponent(oldPersonId)}`;
|
|
18
|
-
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async splitPersons(projectTableName, id, { newName, destinationPersonId } = {}) {
|
|
23
|
-
this._ctx.requireTokens();
|
|
24
|
-
let path = `/api/v1/person/${encodeURIComponent(projectTableName)}/split/${encodeURIComponent(id)}/`;
|
|
25
|
-
const query = new URLSearchParams();
|
|
26
|
-
if (newName !== undefined) (Array.isArray(newName) ? newName : [newName]).forEach(v => query.append('new_name', v));
|
|
27
|
-
if (destinationPersonId !== undefined) (Array.isArray(destinationPersonId) ? destinationPersonId : [destinationPersonId]).forEach(v => query.append('destination_person_id', v));
|
|
28
|
-
const qs = query.toString();
|
|
29
|
-
if (qs) path += '?' + qs;
|
|
30
|
-
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
|
|
31
|
-
return data;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async getAllPersonsFromProject(projectTableName) {
|
|
35
|
-
this._ctx.requireTokens();
|
|
36
|
-
const path = `/api/v1/person/${encodeURIComponent(projectTableName)}/`;
|
|
37
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
38
|
-
return data;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async getAllPersonNamesFromProject(projectTableName) {
|
|
42
|
-
this._ctx.requireTokens();
|
|
43
|
-
const path = `/api/v1/person/${encodeURIComponent(projectTableName)}/names`;
|
|
44
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async getAllPersonsFromPhoto(projectTableName, photoId) {
|
|
49
|
-
this._ctx.requireTokens();
|
|
50
|
-
const path = `/api/v1/person/${encodeURIComponent(projectTableName)}/photo/${encodeURIComponent(photoId)}`;
|
|
51
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
52
|
-
return data;
|
|
53
|
-
}
|
|
54
|
-
}
|
package/photos.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
export class Photos {
|
|
2
|
-
constructor(ctx) { this._ctx = ctx; }
|
|
3
|
-
|
|
4
|
-
async addPhotoToProject({ photo, tableName, sourceResolutionX, sourceResolutionY, dateTaken, latitude, longitude, filePath, title, clientSideId }) {
|
|
5
|
-
this._ctx.requireTokens();
|
|
6
|
-
const path = `/api/v1/photos/`;
|
|
7
|
-
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 });
|
|
8
|
-
return data;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async getPhotoFromProject(tableName, photoId, { keywordListId } = {}) {
|
|
12
|
-
this._ctx.requireTokens();
|
|
13
|
-
let path = `/api/v1/photos/${encodeURIComponent(tableName)}/${encodeURIComponent(photoId)}`;
|
|
14
|
-
const query = new URLSearchParams();
|
|
15
|
-
if (keywordListId !== undefined) (Array.isArray(keywordListId) ? keywordListId : [keywordListId]).forEach(v => query.append('keyword_list_id', v));
|
|
16
|
-
const qs = query.toString();
|
|
17
|
-
if (qs) path += '?' + qs;
|
|
18
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async getPhotoFaceDetailsFromProject(tableName, photoId) {
|
|
23
|
-
this._ctx.requireTokens();
|
|
24
|
-
const path = `/api/v1/photos/face_details/${encodeURIComponent(tableName)}/${encodeURIComponent(photoId)}`;
|
|
25
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async getProjectPhotoIdsByTableName(tableName, { ascOrDesc, lastId, limit, includeAll, startDate, endDate, noDateTaken } = {}) {
|
|
30
|
-
this._ctx.requireTokens();
|
|
31
|
-
let path = `/api/v1/photos/${encodeURIComponent(tableName)}/`;
|
|
32
|
-
const query = new URLSearchParams();
|
|
33
|
-
if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
|
|
34
|
-
if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
|
|
35
|
-
if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
|
|
36
|
-
if (includeAll !== undefined) (Array.isArray(includeAll) ? includeAll : [includeAll]).forEach(v => query.append('include_all', v));
|
|
37
|
-
if (startDate !== undefined) (Array.isArray(startDate) ? startDate : [startDate]).forEach(v => query.append('start_date', v));
|
|
38
|
-
if (endDate !== undefined) (Array.isArray(endDate) ? endDate : [endDate]).forEach(v => query.append('end_date', v));
|
|
39
|
-
if (noDateTaken !== undefined) (Array.isArray(noDateTaken) ? noDateTaken : [noDateTaken]).forEach(v => query.append('no_date_taken', v));
|
|
40
|
-
const qs = query.toString();
|
|
41
|
-
if (qs) path += '?' + qs;
|
|
42
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
43
|
-
return data;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getRankedProjectPhotoIdsByTableName(tableName, { ascOrDesc, lastId, limit, startDate, endDate, noDateTaken } = {}) {
|
|
47
|
-
this._ctx.requireTokens();
|
|
48
|
-
let path = `/api/v1/photos/ranked/${encodeURIComponent(tableName)}/`;
|
|
49
|
-
const query = new URLSearchParams();
|
|
50
|
-
if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
|
|
51
|
-
if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
|
|
52
|
-
if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
|
|
53
|
-
if (startDate !== undefined) (Array.isArray(startDate) ? startDate : [startDate]).forEach(v => query.append('start_date', v));
|
|
54
|
-
if (endDate !== undefined) (Array.isArray(endDate) ? endDate : [endDate]).forEach(v => query.append('end_date', v));
|
|
55
|
-
if (noDateTaken !== undefined) (Array.isArray(noDateTaken) ? noDateTaken : [noDateTaken]).forEach(v => query.append('no_date_taken', v));
|
|
56
|
-
const qs = query.toString();
|
|
57
|
-
if (qs) path += '?' + qs;
|
|
58
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
59
|
-
return data;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async getProjectMonthYearsWithPhotos(tableName) {
|
|
63
|
-
this._ctx.requireTokens();
|
|
64
|
-
const path = `/api/v1/photo_month_years/${encodeURIComponent(tableName)}`;
|
|
65
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
66
|
-
return data;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async getProjectThumbnail(tableName) {
|
|
70
|
-
this._ctx.requireTokens();
|
|
71
|
-
const path = `/api/v1/photos_project/${encodeURIComponent(tableName)}`;
|
|
72
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
73
|
-
return data;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async updatePhotoInProject({ tableName, photoId, photoData } = {}) {
|
|
77
|
-
this._ctx.requireTokens();
|
|
78
|
-
let path = `/api/v1/photos_update`;
|
|
79
|
-
const query = new URLSearchParams();
|
|
80
|
-
if (tableName !== undefined) (Array.isArray(tableName) ? tableName : [tableName]).forEach(v => query.append('table_name', v));
|
|
81
|
-
if (photoId !== undefined) (Array.isArray(photoId) ? photoId : [photoId]).forEach(v => query.append('photo_id', v));
|
|
82
|
-
if (photoData !== undefined) (Array.isArray(photoData) ? photoData : [photoData]).forEach(v => query.append('photo_data', v));
|
|
83
|
-
const qs = query.toString();
|
|
84
|
-
if (qs) path += '?' + qs;
|
|
85
|
-
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
|
|
86
|
-
return data;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async updatePhotoRanking(tableName, photoId, newCategory) {
|
|
90
|
-
this._ctx.requireTokens();
|
|
91
|
-
const path = `/api/v1/photos_update/${encodeURIComponent(tableName)}/id/${encodeURIComponent(photoId)}/rank/${encodeURIComponent(newCategory)}`;
|
|
92
|
-
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
|
|
93
|
-
return data;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async deletePhotoFromProject(tableName, { photoIds } = {}) {
|
|
97
|
-
this._ctx.requireTokens();
|
|
98
|
-
let path = `/api/v1/photos/${encodeURIComponent(tableName)}/delete/`;
|
|
99
|
-
const query = new URLSearchParams();
|
|
100
|
-
if (photoIds !== undefined) (Array.isArray(photoIds) ? photoIds : [photoIds]).forEach(v => query.append('photo_ids', v));
|
|
101
|
-
const qs = query.toString();
|
|
102
|
-
if (qs) path += '?' + qs;
|
|
103
|
-
const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
|
|
104
|
-
return data;
|
|
105
|
-
}
|
|
106
|
-
}
|
package/photoupload.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { handleResponse } from './errors.js';
|
|
2
|
-
import { Projects } from './projects.js';
|
|
3
|
-
|
|
4
|
-
export class Photoupload {
|
|
5
|
-
constructor(ctx) { this._ctx = ctx; this._caches = {}; }
|
|
6
|
-
|
|
7
|
-
async uploadPhotoToMediaviz(companyId, userId, projectTableName, title, { fileContent, mimetype, filePath }, { clientSideId, blur, colors, faceRecognition, imageDescribe, imageClassification, imageComparison, size, sourceResolutionX, sourceResolutionY, dateTaken, latitude, longitude, ocr } = {}) {
|
|
8
|
-
this._ctx.requireTokens();
|
|
9
|
-
const baseUrl = this._ctx.requireHost('photoUpload');
|
|
10
|
-
const headers = {
|
|
11
|
-
'Content-Type': 'application/json',
|
|
12
|
-
'Authorization': this._ctx.accessToken,
|
|
13
|
-
'x-company-id': companyId,
|
|
14
|
-
'x-user-id': userId,
|
|
15
|
-
'x-project-table-name': projectTableName,
|
|
16
|
-
'x-title': title,
|
|
17
|
-
};
|
|
18
|
-
if (clientSideId !== undefined) headers['x-client-side-id'] = clientSideId;
|
|
19
|
-
if (blur !== undefined) headers['x-blur'] = blur;
|
|
20
|
-
if (colors !== undefined) headers['x-colors'] = colors;
|
|
21
|
-
if (faceRecognition !== undefined) headers['x-face-recognition'] = faceRecognition;
|
|
22
|
-
if (imageDescribe !== undefined) headers['x-image-describe'] = imageDescribe;
|
|
23
|
-
if (imageClassification !== undefined) headers['x-image-classification'] = imageClassification;
|
|
24
|
-
if (imageComparison !== undefined) headers['x-image-comparison'] = imageComparison;
|
|
25
|
-
if (size !== undefined) headers['x-size'] = size;
|
|
26
|
-
if (sourceResolutionX !== undefined) headers['x-source-resolution-x'] = sourceResolutionX;
|
|
27
|
-
if (sourceResolutionY !== undefined) headers['x-source-resolution-y'] = sourceResolutionY;
|
|
28
|
-
if (dateTaken !== undefined) headers['x-date-taken'] = dateTaken;
|
|
29
|
-
if (latitude !== undefined) headers['x-latitude'] = latitude;
|
|
30
|
-
if (longitude !== undefined) headers['x-longitude'] = longitude;
|
|
31
|
-
if (ocr !== undefined) headers['x-ocr'] = ocr;
|
|
32
|
-
const resp = await fetch(baseUrl + `/photo_upload`, {
|
|
33
|
-
method: 'POST',
|
|
34
|
-
headers,
|
|
35
|
-
body: JSON.stringify({ file_content: fileContent, mimetype, file_path: filePath }),
|
|
36
|
-
});
|
|
37
|
-
return handleResponse(resp);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async uploadPhoto(projectTableName, companyId, userId, photoIndex, photo) {
|
|
41
|
-
this._ctx.requireTokens();
|
|
42
|
-
|
|
43
|
-
if (!this._caches['_get_template']) this._caches['_get_template'] = new Map();
|
|
44
|
-
const _cacheKey_get_template = `upload_template:${projectTableName}`;
|
|
45
|
-
let template = this._caches['_get_template'].get(_cacheKey_get_template);
|
|
46
|
-
if (template === undefined) {
|
|
47
|
-
template = (await this._ctx.client.request(`/api/v1/project_outcome/${encodeURIComponent(projectTableName)}`, 'GET', this._ctx.accessToken, this._ctx.refreshToken)).data;
|
|
48
|
-
this._caches['_get_template'].set(_cacheKey_get_template, template);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
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 });
|
|
52
|
-
|
|
53
|
-
return upload_result;
|
|
54
|
-
}
|
|
55
|
-
}
|
package/projects.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
function stripUndef(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
|
|
2
|
-
|
|
3
|
-
export class Projects {
|
|
4
|
-
constructor(ctx) { this._ctx = ctx; }
|
|
5
|
-
|
|
6
|
-
async createProjectAndRun(name, private_ = undefined, type = undefined, description = undefined, directory = undefined, photoUploadVector = undefined, thumbnail = undefined, runName = undefined, { outcomes, models } = {}) {
|
|
7
|
-
this._ctx.requireTokens();
|
|
8
|
-
let path = `/api/v1/project_outcome/`;
|
|
9
|
-
const query = new URLSearchParams();
|
|
10
|
-
if (outcomes !== undefined) (Array.isArray(outcomes) ? outcomes : [outcomes]).forEach(v => query.append('outcomes', v));
|
|
11
|
-
if (models !== undefined) (Array.isArray(models) ? models : [models]).forEach(v => query.append('models', v));
|
|
12
|
-
const qs = query.toString();
|
|
13
|
-
if (qs) path += '?' + qs;
|
|
14
|
-
const body = stripUndef({
|
|
15
|
-
name: name,
|
|
16
|
-
private: private_,
|
|
17
|
-
type: type,
|
|
18
|
-
description: description,
|
|
19
|
-
directory: directory,
|
|
20
|
-
photo_upload_vector: photoUploadVector,
|
|
21
|
-
thumbnail: thumbnail,
|
|
22
|
-
run_name: runName,
|
|
23
|
-
});
|
|
24
|
-
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async markProjectUploadComplete(projectTableName, { skippedFileCount } = {}) {
|
|
29
|
-
this._ctx.requireTokens();
|
|
30
|
-
let path = `/api/v1/project/${encodeURIComponent(projectTableName)}/upload_complete/`;
|
|
31
|
-
const query = new URLSearchParams();
|
|
32
|
-
if (skippedFileCount !== undefined) (Array.isArray(skippedFileCount) ? skippedFileCount : [skippedFileCount]).forEach(v => query.append('skipped_file_count', v));
|
|
33
|
-
const qs = query.toString();
|
|
34
|
-
if (qs) path += '?' + qs;
|
|
35
|
-
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
|
|
36
|
-
return data;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async checkProjectStatus(projectTableName) {
|
|
40
|
-
this._ctx.requireTokens();
|
|
41
|
-
const path = `/api/v1/project/status/${encodeURIComponent(projectTableName)}`;
|
|
42
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
43
|
-
return data;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getProjectPrelimModelRequestTemplate(projectTableName) {
|
|
47
|
-
this._ctx.requireTokens();
|
|
48
|
-
const path = `/api/v1/project_outcome/${encodeURIComponent(projectTableName)}`;
|
|
49
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
50
|
-
return data;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async getUserProjects() {
|
|
54
|
-
this._ctx.requireTokens();
|
|
55
|
-
const path = `/api/v1/projects/user`;
|
|
56
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
57
|
-
return data;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async getAdminProjects() {
|
|
61
|
-
this._ctx.requireTokens();
|
|
62
|
-
const path = `/api/v1/projects/admin`;
|
|
63
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
64
|
-
return data;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async getAllUserProjectsAdmin(userId) {
|
|
68
|
-
this._ctx.requireTokens();
|
|
69
|
-
const path = `/api/v1/projects/admin/user/${encodeURIComponent(userId)}`;
|
|
70
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
71
|
-
return data;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async getProjectById(projectId) {
|
|
75
|
-
this._ctx.requireTokens();
|
|
76
|
-
const path = `/api/v1/projects/${encodeURIComponent(projectId)}`;
|
|
77
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
78
|
-
return data;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async getProjectByDirectory(directory) {
|
|
82
|
-
this._ctx.requireTokens();
|
|
83
|
-
const path = `/api/v1/projects/directory/${encodeURIComponent(directory)}`;
|
|
84
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
85
|
-
return data;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async updateProject(projectId, { private: private_, type, description, directory, name, thumbnail } = {}) {
|
|
89
|
-
this._ctx.requireTokens();
|
|
90
|
-
const path = `/api/v1/projects/${encodeURIComponent(projectId)}`;
|
|
91
|
-
const body = stripUndef({
|
|
92
|
-
private: private_,
|
|
93
|
-
type: type,
|
|
94
|
-
description: description,
|
|
95
|
-
directory: directory,
|
|
96
|
-
name: name,
|
|
97
|
-
thumbnail: thumbnail,
|
|
98
|
-
});
|
|
99
|
-
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
100
|
-
return data;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async updateProjectPhotoCount(tableName, { filesFailedCount } = {}) {
|
|
104
|
-
this._ctx.requireTokens();
|
|
105
|
-
let path = `/api/v1/projects_photos/${encodeURIComponent(tableName)}/`;
|
|
106
|
-
const query = new URLSearchParams();
|
|
107
|
-
if (filesFailedCount !== undefined) (Array.isArray(filesFailedCount) ? filesFailedCount : [filesFailedCount]).forEach(v => query.append('files_failed_count', v));
|
|
108
|
-
const qs = query.toString();
|
|
109
|
-
if (qs) path += '?' + qs;
|
|
110
|
-
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
|
|
111
|
-
return data;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async updateProjectCreateUploadReport(tableName, { filesFailedCount } = {}) {
|
|
115
|
-
this._ctx.requireTokens();
|
|
116
|
-
let path = `/api/v1/project_upload_report/${encodeURIComponent(tableName)}/`;
|
|
117
|
-
const query = new URLSearchParams();
|
|
118
|
-
if (filesFailedCount !== undefined) (Array.isArray(filesFailedCount) ? filesFailedCount : [filesFailedCount]).forEach(v => query.append('files_failed_count', v));
|
|
119
|
-
const qs = query.toString();
|
|
120
|
-
if (qs) path += '?' + qs;
|
|
121
|
-
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
|
|
122
|
-
return data;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async requestProjectSimilarityQueue(projectTableName, level) {
|
|
126
|
-
this._ctx.requireTokens();
|
|
127
|
-
const path = `/api/v1/projects_similarity_queue/${encodeURIComponent(projectTableName)}/level/${encodeURIComponent(level)}`;
|
|
128
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
129
|
-
return data;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async requestProjectEvidenceQueue(projectTableName) {
|
|
133
|
-
this._ctx.requireTokens();
|
|
134
|
-
const path = `/api/v1/projects_evidence_queue/${encodeURIComponent(projectTableName)}`;
|
|
135
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
136
|
-
return data;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async requestProjectPersonhoodQueue(projectTableName) {
|
|
140
|
-
this._ctx.requireTokens();
|
|
141
|
-
const path = `/api/v1/projects_personhood_queue/${encodeURIComponent(projectTableName)}`;
|
|
142
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
143
|
-
return data;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async requestInsightsQueue(analysisLevel, identifier) {
|
|
147
|
-
this._ctx.requireTokens();
|
|
148
|
-
const path = `/api/v1/insights_queue/analysis_level/${encodeURIComponent(analysisLevel)}/identifier/${encodeURIComponent(identifier)}`;
|
|
149
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
150
|
-
return data;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async requestProjectExport(projectTableName) {
|
|
154
|
-
this._ctx.requireTokens();
|
|
155
|
-
const path = `/api/v1/projects_export/${encodeURIComponent(projectTableName)}`;
|
|
156
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
157
|
-
return data;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async requestProjectAdminExport(projectTableName) {
|
|
161
|
-
this._ctx.requireTokens();
|
|
162
|
-
const path = `/api/v1/projects_admin_export/${encodeURIComponent(projectTableName)}`;
|
|
163
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
164
|
-
return data;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async getProjectDataExportUploadStatus(projectTableName, modelName) {
|
|
168
|
-
this._ctx.requireTokens();
|
|
169
|
-
const path = `/api/v1/projects/${encodeURIComponent(projectTableName)}/upload_status/${encodeURIComponent(modelName)}`;
|
|
170
|
-
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
171
|
-
return data;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
async addProjectEvent(projectTableName, event, detail = undefined) {
|
|
175
|
-
this._ctx.requireTokens();
|
|
176
|
-
const path = `/api/v1/projects/${encodeURIComponent(projectTableName)}/event`;
|
|
177
|
-
const body = stripUndef({
|
|
178
|
-
event: event,
|
|
179
|
-
detail: detail,
|
|
180
|
-
});
|
|
181
|
-
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
182
|
-
return data;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async deleteProject(projectId) {
|
|
186
|
-
this._ctx.requireTokens();
|
|
187
|
-
const path = `/api/v1/projects/${encodeURIComponent(projectId)}`;
|
|
188
|
-
const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
|
|
189
|
-
return data;
|
|
190
|
-
}
|
|
191
|
-
}
|
package/rollup.config.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
input: 'index.js',
|
|
6
|
-
output: [
|
|
7
|
-
{ file: 'dist/sdk.cjs', format: 'cjs', exports: 'named' },
|
|
8
|
-
{ file: 'dist/sdk.esm.js', format: 'es' },
|
|
9
|
-
{ file: 'dist/sdk.umd.js', format: 'umd', name: 'MediaVizSdk', exports: 'named' },
|
|
10
|
-
],
|
|
11
|
-
plugins: [resolve(), commonjs()],
|
|
12
|
-
};
|