@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/MediaViz.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Auto-generated — do not edit
|
|
2
|
+
import { OAuthClient } from './_oauth.js';
|
|
3
|
+
import { AiModelCredits } from './ai_model_credits.js';
|
|
4
|
+
import { Admin } from './admin.js';
|
|
5
|
+
import { Company } from './company.js';
|
|
6
|
+
import { CuratedAlbums } from './curated_albums.js';
|
|
7
|
+
import { CustomAlbums } from './custom_albums.js';
|
|
8
|
+
import { EmailTokens } from './email_tokens.js';
|
|
9
|
+
import { Health } from './health.js';
|
|
10
|
+
import { Keywords } from './keywords.js';
|
|
11
|
+
import { OauthAuthorization } from './oauth_authorization.js';
|
|
12
|
+
import { OauthClients } from './oauth_clients.js';
|
|
13
|
+
import { OauthToken } from './oauth_token.js';
|
|
14
|
+
import { OauthLogin } from './oauth_login.js';
|
|
15
|
+
import { Person } from './person.js';
|
|
16
|
+
import { Photoupload } from './photoupload.js';
|
|
17
|
+
import { Photos } from './photos.js';
|
|
18
|
+
import { Projects } from './projects.js';
|
|
19
|
+
import { Search } from './search.js';
|
|
20
|
+
import { Users } from './users.js';
|
|
21
|
+
|
|
22
|
+
function _env(key) {
|
|
23
|
+
if (typeof process !== 'undefined' && process.env) return process.env[key];
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class _Context {
|
|
28
|
+
constructor(mv) { this._mv = mv; }
|
|
29
|
+
get client() { return this._mv._oauthClient; }
|
|
30
|
+
get accessToken() { return this._mv._accessToken; }
|
|
31
|
+
get refreshToken() { return this._mv._refreshToken; }
|
|
32
|
+
get baseUrl() { return this._mv._config.baseUrl; }
|
|
33
|
+
get hosts() { return this._mv._hosts; }
|
|
34
|
+
requireHost(key) {
|
|
35
|
+
const url = this._mv._hosts[key];
|
|
36
|
+
if (!url) throw new Error(`Host '${key}' not configured. Pass hosts.${key} in MediaViz constructor or set the corresponding env var.`);
|
|
37
|
+
return url;
|
|
38
|
+
}
|
|
39
|
+
requireTokens() {
|
|
40
|
+
if (!this._mv._accessToken) throw new Error('Not authenticated. Call authenticate(), handleCallback(), or setTokens() first.');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class _TokenTrackingClient {
|
|
45
|
+
constructor(mv, inner) { this._mv = mv; this._inner = inner; }
|
|
46
|
+
async request(url, method, accessToken, refreshToken, body) {
|
|
47
|
+
const onRefreshSuccess = (newTokens) => {
|
|
48
|
+
this._mv._accessToken = newTokens.access_token;
|
|
49
|
+
this._mv._refreshToken = newTokens.refresh_token;
|
|
50
|
+
if (this._mv._onTokenRefresh) this._mv._onTokenRefresh(newTokens);
|
|
51
|
+
};
|
|
52
|
+
return this._inner.request(url, method, accessToken, refreshToken, body, onRefreshSuccess);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class MediaViz {
|
|
57
|
+
constructor(config = {}) {
|
|
58
|
+
this._config = {
|
|
59
|
+
clientId: config.clientId ?? _env('MEDIAVIZ_CLIENT_ID'),
|
|
60
|
+
clientSecret: config.clientSecret ?? _env('MEDIAVIZ_CLIENT_SECRET'),
|
|
61
|
+
baseUrl: config.baseUrl ?? _env('MEDIAVIZ_BASE_URL') ?? 'https://api.mediaviz.ai',
|
|
62
|
+
redirectUri: config.redirectUri ?? _env('MEDIAVIZ_REDIRECT_URI'),
|
|
63
|
+
};
|
|
64
|
+
this._hosts = {
|
|
65
|
+
photoUpload: config.hosts?.photoUpload ?? _env('MEDIAVIZ_PHOTO_UPLOAD_URL'),
|
|
66
|
+
...(config.hosts || {}),
|
|
67
|
+
};
|
|
68
|
+
this._accessToken = config.accessToken ?? null;
|
|
69
|
+
this._refreshToken = config.refreshToken ?? null;
|
|
70
|
+
this._onTokenRefresh = config.onTokenRefresh ?? null;
|
|
71
|
+
|
|
72
|
+
const _inner = new OAuthClient({
|
|
73
|
+
clientId: this._config.clientId,
|
|
74
|
+
clientSecret: this._config.clientSecret,
|
|
75
|
+
baseUrl: this._config.baseUrl,
|
|
76
|
+
redirectUri: this._config.redirectUri,
|
|
77
|
+
});
|
|
78
|
+
this._oauthClient = new _TokenTrackingClient(this, _inner);
|
|
79
|
+
|
|
80
|
+
const _ctx = new _Context(this);
|
|
81
|
+
this.aiModelCredits = new AiModelCredits(_ctx);
|
|
82
|
+
this.admin = new Admin(_ctx);
|
|
83
|
+
this.company = new Company(_ctx);
|
|
84
|
+
this.curatedAlbums = new CuratedAlbums(_ctx);
|
|
85
|
+
this.customAlbums = new CustomAlbums(_ctx);
|
|
86
|
+
this.emailTokens = new EmailTokens(_ctx);
|
|
87
|
+
this.health = new Health(_ctx);
|
|
88
|
+
this.keywords = new Keywords(_ctx);
|
|
89
|
+
this.oAuthAuthorization = new OauthAuthorization(_ctx);
|
|
90
|
+
this.oAuthClients = new OauthClients(_ctx);
|
|
91
|
+
this.oAuthToken = new OauthToken(_ctx);
|
|
92
|
+
this.oauthLogin = new OauthLogin(_ctx);
|
|
93
|
+
this.person = new Person(_ctx);
|
|
94
|
+
this.photoUpload = new Photoupload(_ctx);
|
|
95
|
+
this.photos = new Photos(_ctx);
|
|
96
|
+
this.projects = new Projects(_ctx);
|
|
97
|
+
this.search = new Search(_ctx);
|
|
98
|
+
this.users = new Users(_ctx);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async authenticate() {
|
|
102
|
+
const tokens = await this._oauthClient._inner.getClientCredentialsToken();
|
|
103
|
+
this._accessToken = tokens.access_token;
|
|
104
|
+
this._refreshToken = tokens.refresh_token ?? null;
|
|
105
|
+
return tokens;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async getAuthorizationUrl(state) {
|
|
109
|
+
return this._oauthClient._inner.generateAuthorizationUrl(state);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async handleCallback(code, codeVerifier) {
|
|
113
|
+
const tokens = await this._oauthClient._inner.exchangeCode(code, codeVerifier);
|
|
114
|
+
this._accessToken = tokens.access_token;
|
|
115
|
+
this._refreshToken = tokens.refresh_token;
|
|
116
|
+
return tokens;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
setTokens(accessToken, refreshToken) {
|
|
120
|
+
this._accessToken = accessToken;
|
|
121
|
+
this._refreshToken = refreshToken;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
get accessToken() { return this._accessToken; }
|
|
125
|
+
get refreshToken() { return this._refreshToken; }
|
|
126
|
+
}
|
package/_oauth.js
ADDED
package/admin.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export class Admin {
|
|
2
|
+
constructor(ctx) { this._ctx = ctx; }
|
|
3
|
+
|
|
4
|
+
async insertLabelCategoryMatrix() {
|
|
5
|
+
this._ctx.requireTokens();
|
|
6
|
+
const path = `/api/v1/admin/insert_label_category_matrix`;
|
|
7
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async generateMidLevelCategoryKeywordAlignment() {
|
|
12
|
+
this._ctx.requireTokens();
|
|
13
|
+
const path = `/api/v1/admin/generate_mid_level_category_keyword_alignment`;
|
|
14
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getCategoryLabels(category) {
|
|
19
|
+
this._ctx.requireTokens();
|
|
20
|
+
const path = `/api/v1/admin/category_labels/${encodeURIComponent(category)}`;
|
|
21
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async adminDumpCompanyNlpIndex(companyId) {
|
|
26
|
+
this._ctx.requireTokens();
|
|
27
|
+
const path = `/api/v1/admin/dump_company_nlp_index/${encodeURIComponent(companyId)}`;
|
|
28
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async getAllKeywordGroupsAndSubgroups() {
|
|
33
|
+
this._ctx.requireTokens();
|
|
34
|
+
const path = `/api/v1/admin/keyword_group`;
|
|
35
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async getKeywordGroupsLabelsByKeywordGroup(keywordGroup, { subgroup } = {}) {
|
|
40
|
+
this._ctx.requireTokens();
|
|
41
|
+
let path = `/api/v1/admin/keyword_group/${encodeURIComponent(keywordGroup)}/`;
|
|
42
|
+
const query = new URLSearchParams();
|
|
43
|
+
if (subgroup !== undefined) (Array.isArray(subgroup) ? subgroup : [subgroup]).forEach(v => query.append('subgroup', v));
|
|
44
|
+
const qs = query.toString();
|
|
45
|
+
if (qs) path += '?' + qs;
|
|
46
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async adminCreateCompanyNlpIndexes({ companyIds } = {}) {
|
|
51
|
+
this._ctx.requireTokens();
|
|
52
|
+
let path = `/api/v1/admin/create_company_nlp_indexes/`;
|
|
53
|
+
const query = new URLSearchParams();
|
|
54
|
+
if (companyIds !== undefined) (Array.isArray(companyIds) ? companyIds : [companyIds]).forEach(v => query.append('company_ids', v));
|
|
55
|
+
const qs = query.toString();
|
|
56
|
+
if (qs) path += '?' + qs;
|
|
57
|
+
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async adminDeleteCompanyNlpIndexes({ companyIds } = {}) {
|
|
62
|
+
this._ctx.requireTokens();
|
|
63
|
+
let path = `/api/v1/admin/delete_company_nlp_indexes/`;
|
|
64
|
+
const query = new URLSearchParams();
|
|
65
|
+
if (companyIds !== undefined) (Array.isArray(companyIds) ? companyIds : [companyIds]).forEach(v => query.append('company_ids', v));
|
|
66
|
+
const qs = query.toString();
|
|
67
|
+
if (qs) path += '?' + qs;
|
|
68
|
+
const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async adminDeleteUserProjects({ userIds } = {}) {
|
|
73
|
+
this._ctx.requireTokens();
|
|
74
|
+
let path = `/api/v1/admin/delete_user_projects/`;
|
|
75
|
+
const query = new URLSearchParams();
|
|
76
|
+
if (userIds !== undefined) (Array.isArray(userIds) ? userIds : [userIds]).forEach(v => query.append('user_ids', v));
|
|
77
|
+
const qs = query.toString();
|
|
78
|
+
if (qs) path += '?' + qs;
|
|
79
|
+
const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async adminDeleteUser({ userIds } = {}) {
|
|
84
|
+
this._ctx.requireTokens();
|
|
85
|
+
let path = `/api/v1/admin/delete_user/`;
|
|
86
|
+
const query = new URLSearchParams();
|
|
87
|
+
if (userIds !== undefined) (Array.isArray(userIds) ? userIds : [userIds]).forEach(v => query.append('user_ids', v));
|
|
88
|
+
const qs = query.toString();
|
|
89
|
+
if (qs) path += '?' + qs;
|
|
90
|
+
const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class AiModelCredits {
|
|
2
|
+
constructor(ctx) { this._ctx = ctx; }
|
|
3
|
+
|
|
4
|
+
async getModelCreditRelationship(modelName) {
|
|
5
|
+
this._ctx.requireTokens();
|
|
6
|
+
const path = `/api/v1/model_credit/${encodeURIComponent(modelName)}`;
|
|
7
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async upsertModelCreditRelationship({ modelName, newCreditValue } = {}) {
|
|
12
|
+
this._ctx.requireTokens();
|
|
13
|
+
let path = `/api/v1/model_credit/upsert`;
|
|
14
|
+
const query = new URLSearchParams();
|
|
15
|
+
if (modelName !== undefined) (Array.isArray(modelName) ? modelName : [modelName]).forEach(v => query.append('model_name', v));
|
|
16
|
+
if (newCreditValue !== undefined) (Array.isArray(newCreditValue) ? newCreditValue : [newCreditValue]).forEach(v => query.append('new_credit_value', v));
|
|
17
|
+
const qs = query.toString();
|
|
18
|
+
if (qs) path += '?' + qs;
|
|
19
|
+
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/company.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export class Company {
|
|
2
|
+
constructor(ctx) { this._ctx = ctx; }
|
|
3
|
+
|
|
4
|
+
async getAllCompanies() {
|
|
5
|
+
this._ctx.requireTokens();
|
|
6
|
+
const path = `/api/v1/company/`;
|
|
7
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async getCompanyById(companyId) {
|
|
12
|
+
this._ctx.requireTokens();
|
|
13
|
+
const path = `/api/v1/company/${encodeURIComponent(companyId)}`;
|
|
14
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async confirmCompanyCreditBalance(companyId, { photoCount, modelsList } = {}) {
|
|
19
|
+
this._ctx.requireTokens();
|
|
20
|
+
let path = `/api/v1/company/credit_balance/${encodeURIComponent(companyId)}`;
|
|
21
|
+
const query = new URLSearchParams();
|
|
22
|
+
if (photoCount !== undefined) (Array.isArray(photoCount) ? photoCount : [photoCount]).forEach(v => query.append('photo_count', v));
|
|
23
|
+
if (modelsList !== undefined) (Array.isArray(modelsList) ? modelsList : [modelsList]).forEach(v => query.append('models_list', v));
|
|
24
|
+
const qs = query.toString();
|
|
25
|
+
if (qs) path += '?' + qs;
|
|
26
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async adminListActiveCompanyTokens() {
|
|
31
|
+
this._ctx.requireTokens();
|
|
32
|
+
const path = `/api/v1/company/admin_create/`;
|
|
33
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async adminCreateCompanyToken({ email } = {}) {
|
|
38
|
+
this._ctx.requireTokens();
|
|
39
|
+
let path = `/api/v1/company/admin_create/`;
|
|
40
|
+
const query = new URLSearchParams();
|
|
41
|
+
if (email !== undefined) (Array.isArray(email) ? email : [email]).forEach(v => query.append('email', v));
|
|
42
|
+
const qs = query.toString();
|
|
43
|
+
if (qs) path += '?' + qs;
|
|
44
|
+
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async adminRevokeCompanyToken(tokenId) {
|
|
49
|
+
this._ctx.requireTokens();
|
|
50
|
+
const path = `/api/v1/company/admin_create/${encodeURIComponent(tokenId)}/revoke/`;
|
|
51
|
+
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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 CuratedAlbums {
|
|
4
|
+
constructor(ctx) { this._ctx = ctx; }
|
|
5
|
+
|
|
6
|
+
async createCuratedAlbum(projectTableName, name, description = undefined, confidenceValue = undefined) {
|
|
7
|
+
this._ctx.requireTokens();
|
|
8
|
+
const path = `/api/v1/curated_album/project/${encodeURIComponent(projectTableName)}`;
|
|
9
|
+
const body = stripUndef({
|
|
10
|
+
name: name,
|
|
11
|
+
description: description,
|
|
12
|
+
confidence_value: confidenceValue,
|
|
13
|
+
});
|
|
14
|
+
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getAllProjectCuratedAlbums(projectTableName) {
|
|
19
|
+
this._ctx.requireTokens();
|
|
20
|
+
const path = `/api/v1/curated_album/project/${encodeURIComponent(projectTableName)}`;
|
|
21
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getCuratedAlbumPhotos(albumId, { ascOrDesc, lastId, limit, confidenceValue } = {}) {
|
|
26
|
+
this._ctx.requireTokens();
|
|
27
|
+
let path = `/api/v1/curated_album/photos/${encodeURIComponent(albumId)}/`;
|
|
28
|
+
const query = new URLSearchParams();
|
|
29
|
+
if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
|
|
30
|
+
if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
|
|
31
|
+
if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
|
|
32
|
+
if (confidenceValue !== undefined) (Array.isArray(confidenceValue) ? confidenceValue : [confidenceValue]).forEach(v => query.append('confidence_value', v));
|
|
33
|
+
const qs = query.toString();
|
|
34
|
+
if (qs) path += '?' + qs;
|
|
35
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async getCuratedAlbumPhotosRanked(albumId, { ascOrDesc, lastId, limit, confidenceValue } = {}) {
|
|
40
|
+
this._ctx.requireTokens();
|
|
41
|
+
let path = `/api/v1/curated_album/photos/ranked/${encodeURIComponent(albumId)}/`;
|
|
42
|
+
const query = new URLSearchParams();
|
|
43
|
+
if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
|
|
44
|
+
if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
|
|
45
|
+
if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
|
|
46
|
+
if (confidenceValue !== undefined) (Array.isArray(confidenceValue) ? confidenceValue : [confidenceValue]).forEach(v => query.append('confidence_value', v));
|
|
47
|
+
const qs = query.toString();
|
|
48
|
+
if (qs) path += '?' + qs;
|
|
49
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async getCuratedAlbumById(albumId) {
|
|
54
|
+
this._ctx.requireTokens();
|
|
55
|
+
const path = `/api/v1/curated_album/${encodeURIComponent(albumId)}`;
|
|
56
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async updateCuratedAlbum(albumId, { name, description, confidenceValue } = {}) {
|
|
61
|
+
this._ctx.requireTokens();
|
|
62
|
+
const path = `/api/v1/curated_album/${encodeURIComponent(albumId)}`;
|
|
63
|
+
const body = stripUndef({
|
|
64
|
+
name: name,
|
|
65
|
+
description: description,
|
|
66
|
+
confidence_value: confidenceValue,
|
|
67
|
+
});
|
|
68
|
+
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async deleteCuratedAlbum(albumId) {
|
|
73
|
+
this._ctx.requireTokens();
|
|
74
|
+
const path = `/api/v1/curated_album/${encodeURIComponent(albumId)}`;
|
|
75
|
+
const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async convertCuratedAlbumToCustom(albumId) {
|
|
80
|
+
this._ctx.requireTokens();
|
|
81
|
+
const path = `/api/v1/curated_album/${encodeURIComponent(albumId)}/convert`;
|
|
82
|
+
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
|
|
83
|
+
return data;
|
|
84
|
+
}
|
|
85
|
+
}
|
package/custom_albums.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
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 CustomAlbums {
|
|
4
|
+
constructor(ctx) { this._ctx = ctx; }
|
|
5
|
+
|
|
6
|
+
async getCustomAlbumDetailById(customAlbumId) {
|
|
7
|
+
this._ctx.requireTokens();
|
|
8
|
+
const path = `/api/v1/custom_album/${encodeURIComponent(customAlbumId)}`;
|
|
9
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async getAllProjectCustomAlbums(projectTableName) {
|
|
14
|
+
this._ctx.requireTokens();
|
|
15
|
+
const path = `/api/v1/custom_album/project/${encodeURIComponent(projectTableName)}`;
|
|
16
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getCustomAlbumPhotosById(customAlbumId, { ascOrDesc, lastId, limit } = {}) {
|
|
21
|
+
this._ctx.requireTokens();
|
|
22
|
+
let path = `/api/v1/custom_album/photos/${encodeURIComponent(customAlbumId)}/`;
|
|
23
|
+
const query = new URLSearchParams();
|
|
24
|
+
if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
|
|
25
|
+
if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
|
|
26
|
+
if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
|
|
27
|
+
const qs = query.toString();
|
|
28
|
+
if (qs) path += '?' + qs;
|
|
29
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getRankedCustomAlbumById(customAlbumId, { ascOrDesc, lastId, limit } = {}) {
|
|
34
|
+
this._ctx.requireTokens();
|
|
35
|
+
let path = `/api/v1/custom_album/photos/ranked/${encodeURIComponent(customAlbumId)}/`;
|
|
36
|
+
const query = new URLSearchParams();
|
|
37
|
+
if (ascOrDesc !== undefined) (Array.isArray(ascOrDesc) ? ascOrDesc : [ascOrDesc]).forEach(v => query.append('asc_or_desc', v));
|
|
38
|
+
if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
|
|
39
|
+
if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', 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 createProjectCustomAlbum(projectTableName, { name, description, photoIdInclusionList, photoIdRemovalList } = {}) {
|
|
47
|
+
this._ctx.requireTokens();
|
|
48
|
+
const path = `/api/v1/custom_album/project/${encodeURIComponent(projectTableName)}`;
|
|
49
|
+
const body = stripUndef({
|
|
50
|
+
name: name,
|
|
51
|
+
description: description,
|
|
52
|
+
photo_id_inclusion_list: photoIdInclusionList,
|
|
53
|
+
photo_id_removal_list: photoIdRemovalList,
|
|
54
|
+
});
|
|
55
|
+
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async updateCustomAlbum(albumId, { name, description, photoIdInclusionList, photoIdRemovalList } = {}) {
|
|
60
|
+
this._ctx.requireTokens();
|
|
61
|
+
const path = `/api/v1/custom_album/${encodeURIComponent(albumId)}`;
|
|
62
|
+
const body = stripUndef({
|
|
63
|
+
name: name,
|
|
64
|
+
description: description,
|
|
65
|
+
photo_id_inclusion_list: photoIdInclusionList,
|
|
66
|
+
photo_id_removal_list: photoIdRemovalList,
|
|
67
|
+
});
|
|
68
|
+
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async deleteCustomAlbum(albumId) {
|
|
73
|
+
this._ctx.requireTokens();
|
|
74
|
+
const path = `/api/v1/custom_album/${encodeURIComponent(albumId)}`;
|
|
75
|
+
const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
}
|