@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/search.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export class Search {
|
|
2
|
+
constructor(ctx) { this._ctx = ctx; }
|
|
3
|
+
|
|
4
|
+
async searchProjectPhotos(projectTableName, { andParams, andStringParams, orParams, orStringParams, notParams, notStringParams, dateMin, dateMax, dateNullAnd, dateNullOr, dateOrder, customAlbumId, bestOfSimilarSetsOnly, curatedAlbumId, splitByTier } = {}) {
|
|
5
|
+
this._ctx.requireTokens();
|
|
6
|
+
let path = `/api/v1/search/${encodeURIComponent(projectTableName)}/`;
|
|
7
|
+
const query = new URLSearchParams();
|
|
8
|
+
if (andParams !== undefined) (Array.isArray(andParams) ? andParams : [andParams]).forEach(v => query.append('and_params', v));
|
|
9
|
+
if (andStringParams !== undefined) (Array.isArray(andStringParams) ? andStringParams : [andStringParams]).forEach(v => query.append('and_string_params', v));
|
|
10
|
+
if (orParams !== undefined) (Array.isArray(orParams) ? orParams : [orParams]).forEach(v => query.append('or_params', v));
|
|
11
|
+
if (orStringParams !== undefined) (Array.isArray(orStringParams) ? orStringParams : [orStringParams]).forEach(v => query.append('or_string_params', v));
|
|
12
|
+
if (notParams !== undefined) (Array.isArray(notParams) ? notParams : [notParams]).forEach(v => query.append('not_params', v));
|
|
13
|
+
if (notStringParams !== undefined) (Array.isArray(notStringParams) ? notStringParams : [notStringParams]).forEach(v => query.append('not_string_params', v));
|
|
14
|
+
if (dateMin !== undefined) (Array.isArray(dateMin) ? dateMin : [dateMin]).forEach(v => query.append('date_min', v));
|
|
15
|
+
if (dateMax !== undefined) (Array.isArray(dateMax) ? dateMax : [dateMax]).forEach(v => query.append('date_max', v));
|
|
16
|
+
if (dateNullAnd !== undefined) (Array.isArray(dateNullAnd) ? dateNullAnd : [dateNullAnd]).forEach(v => query.append('date_null_and', v));
|
|
17
|
+
if (dateNullOr !== undefined) (Array.isArray(dateNullOr) ? dateNullOr : [dateNullOr]).forEach(v => query.append('date_null_or', v));
|
|
18
|
+
if (dateOrder !== undefined) (Array.isArray(dateOrder) ? dateOrder : [dateOrder]).forEach(v => query.append('date_order', v));
|
|
19
|
+
if (customAlbumId !== undefined) (Array.isArray(customAlbumId) ? customAlbumId : [customAlbumId]).forEach(v => query.append('custom_album_id', v));
|
|
20
|
+
if (bestOfSimilarSetsOnly !== undefined) (Array.isArray(bestOfSimilarSetsOnly) ? bestOfSimilarSetsOnly : [bestOfSimilarSetsOnly]).forEach(v => query.append('best_of_similar_sets_only', v));
|
|
21
|
+
if (curatedAlbumId !== undefined) (Array.isArray(curatedAlbumId) ? curatedAlbumId : [curatedAlbumId]).forEach(v => query.append('curated_album_id', v));
|
|
22
|
+
if (splitByTier !== undefined) (Array.isArray(splitByTier) ? splitByTier : [splitByTier]).forEach(v => query.append('split_by_tier', v));
|
|
23
|
+
const qs = query.toString();
|
|
24
|
+
if (qs) path += '?' + qs;
|
|
25
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async searchProjectPhotosText(projectTableName, { q, size } = {}) {
|
|
30
|
+
this._ctx.requireTokens();
|
|
31
|
+
let path = `/api/v1/search/text/${encodeURIComponent(projectTableName)}/`;
|
|
32
|
+
const query = new URLSearchParams();
|
|
33
|
+
if (q !== undefined) (Array.isArray(q) ? q : [q]).forEach(v => query.append('q', v));
|
|
34
|
+
if (size !== undefined) (Array.isArray(size) ? size : [size]).forEach(v => query.append('size', v));
|
|
35
|
+
const qs = query.toString();
|
|
36
|
+
if (qs) path += '?' + qs;
|
|
37
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async searchProjectPhotosNaturalLanguage(projectTableName, { searchText, size } = {}) {
|
|
42
|
+
this._ctx.requireTokens();
|
|
43
|
+
let path = `/api/v1/search/nl/${encodeURIComponent(projectTableName)}/`;
|
|
44
|
+
const query = new URLSearchParams();
|
|
45
|
+
if (searchText !== undefined) (Array.isArray(searchText) ? searchText : [searchText]).forEach(v => query.append('search_text', v));
|
|
46
|
+
if (size !== undefined) (Array.isArray(size) ? size : [size]).forEach(v => query.append('size', 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 getProjectSavedSearches(projectTableName) {
|
|
54
|
+
this._ctx.requireTokens();
|
|
55
|
+
const path = `/api/v1/search/saved/${encodeURIComponent(projectTableName)}/`;
|
|
56
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async getSavedSearchById(searchId) {
|
|
61
|
+
this._ctx.requireTokens();
|
|
62
|
+
const path = `/api/v1/search/${encodeURIComponent(searchId)}`;
|
|
63
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async saveProjectPhotosSearch(projectTableName, { searchName, andParams, andStringParams, orParams, orStringParams, notParams, notStringParams, dateMin, dateMax, dateNullAnd, dateNullOr, dateOrder, customAlbumId, bestOfSimilarSetsOnly, curatedAlbumId, splitByTier } = {}) {
|
|
68
|
+
this._ctx.requireTokens();
|
|
69
|
+
let path = `/api/v1/search/${encodeURIComponent(projectTableName)}/`;
|
|
70
|
+
const query = new URLSearchParams();
|
|
71
|
+
if (searchName !== undefined) (Array.isArray(searchName) ? searchName : [searchName]).forEach(v => query.append('search_name', v));
|
|
72
|
+
if (andParams !== undefined) (Array.isArray(andParams) ? andParams : [andParams]).forEach(v => query.append('and_params', v));
|
|
73
|
+
if (andStringParams !== undefined) (Array.isArray(andStringParams) ? andStringParams : [andStringParams]).forEach(v => query.append('and_string_params', v));
|
|
74
|
+
if (orParams !== undefined) (Array.isArray(orParams) ? orParams : [orParams]).forEach(v => query.append('or_params', v));
|
|
75
|
+
if (orStringParams !== undefined) (Array.isArray(orStringParams) ? orStringParams : [orStringParams]).forEach(v => query.append('or_string_params', v));
|
|
76
|
+
if (notParams !== undefined) (Array.isArray(notParams) ? notParams : [notParams]).forEach(v => query.append('not_params', v));
|
|
77
|
+
if (notStringParams !== undefined) (Array.isArray(notStringParams) ? notStringParams : [notStringParams]).forEach(v => query.append('not_string_params', v));
|
|
78
|
+
if (dateMin !== undefined) (Array.isArray(dateMin) ? dateMin : [dateMin]).forEach(v => query.append('date_min', v));
|
|
79
|
+
if (dateMax !== undefined) (Array.isArray(dateMax) ? dateMax : [dateMax]).forEach(v => query.append('date_max', v));
|
|
80
|
+
if (dateNullAnd !== undefined) (Array.isArray(dateNullAnd) ? dateNullAnd : [dateNullAnd]).forEach(v => query.append('date_null_and', v));
|
|
81
|
+
if (dateNullOr !== undefined) (Array.isArray(dateNullOr) ? dateNullOr : [dateNullOr]).forEach(v => query.append('date_null_or', v));
|
|
82
|
+
if (dateOrder !== undefined) (Array.isArray(dateOrder) ? dateOrder : [dateOrder]).forEach(v => query.append('date_order', v));
|
|
83
|
+
if (customAlbumId !== undefined) (Array.isArray(customAlbumId) ? customAlbumId : [customAlbumId]).forEach(v => query.append('custom_album_id', v));
|
|
84
|
+
if (bestOfSimilarSetsOnly !== undefined) (Array.isArray(bestOfSimilarSetsOnly) ? bestOfSimilarSetsOnly : [bestOfSimilarSetsOnly]).forEach(v => query.append('best_of_similar_sets_only', v));
|
|
85
|
+
if (curatedAlbumId !== undefined) (Array.isArray(curatedAlbumId) ? curatedAlbumId : [curatedAlbumId]).forEach(v => query.append('curated_album_id', v));
|
|
86
|
+
if (splitByTier !== undefined) (Array.isArray(splitByTier) ? splitByTier : [splitByTier]).forEach(v => query.append('split_by_tier', v));
|
|
87
|
+
const qs = query.toString();
|
|
88
|
+
if (qs) path += '?' + qs;
|
|
89
|
+
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken);
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async deleteSavedSearchById(searchId) {
|
|
94
|
+
this._ctx.requireTokens();
|
|
95
|
+
const path = `/api/v1/search/${encodeURIComponent(searchId)}`;
|
|
96
|
+
const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
|
|
97
|
+
return data;
|
|
98
|
+
}
|
|
99
|
+
}
|
package/users.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { handleResponse } from './errors.js';
|
|
2
|
+
|
|
3
|
+
function stripUndef(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
|
|
4
|
+
|
|
5
|
+
export class Users {
|
|
6
|
+
constructor(ctx) { this._ctx = ctx; }
|
|
7
|
+
|
|
8
|
+
async createUser(name, email, accountType, companyId = undefined, profilePicture = undefined, paymentPlanType = undefined) {
|
|
9
|
+
this._ctx.requireTokens();
|
|
10
|
+
const path = `/api/v1/users/`;
|
|
11
|
+
const body = stripUndef({
|
|
12
|
+
name: name,
|
|
13
|
+
email: email,
|
|
14
|
+
company_id: companyId,
|
|
15
|
+
profile_picture: profilePicture,
|
|
16
|
+
payment_plan_type: paymentPlanType,
|
|
17
|
+
account_type: accountType,
|
|
18
|
+
});
|
|
19
|
+
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async createUserAndCompany(name, email, password, companyId = undefined, profilePicture = undefined, paymentPlanType = undefined, companyName = undefined, credits = undefined, { inviteToken } = {}) {
|
|
24
|
+
let path = `/api/v1/users/new_company/`;
|
|
25
|
+
const query = new URLSearchParams();
|
|
26
|
+
if (inviteToken !== undefined) (Array.isArray(inviteToken) ? inviteToken : [inviteToken]).forEach(v => query.append('invite_token', v));
|
|
27
|
+
const qs = query.toString();
|
|
28
|
+
if (qs) path += '?' + qs;
|
|
29
|
+
const body = stripUndef({
|
|
30
|
+
name: name,
|
|
31
|
+
email: email,
|
|
32
|
+
company_id: companyId,
|
|
33
|
+
profile_picture: profilePicture,
|
|
34
|
+
payment_plan_type: paymentPlanType,
|
|
35
|
+
password: password,
|
|
36
|
+
company_name: companyName,
|
|
37
|
+
credits: credits,
|
|
38
|
+
});
|
|
39
|
+
const resp = await fetch(this._ctx.baseUrl + path, {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: { 'Content-Type': 'application/json' },
|
|
42
|
+
body: JSON.stringify(body),
|
|
43
|
+
});
|
|
44
|
+
return handleResponse(resp);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async changePassword(oldPassword, newPassword) {
|
|
48
|
+
this._ctx.requireTokens();
|
|
49
|
+
const path = `/api/v1/user/change_password`;
|
|
50
|
+
const body = stripUndef({
|
|
51
|
+
old_password: oldPassword,
|
|
52
|
+
new_password: newPassword,
|
|
53
|
+
});
|
|
54
|
+
const { data } = await this._ctx.client.request(path, 'POST', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async getUserId() {
|
|
59
|
+
this._ctx.requireTokens();
|
|
60
|
+
const path = `/api/v1/users`;
|
|
61
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
62
|
+
return data;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async getUser(userId) {
|
|
66
|
+
this._ctx.requireTokens();
|
|
67
|
+
const path = `/api/v1/users/${encodeURIComponent(userId)}`;
|
|
68
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async getAllUsersByCompany(companyId) {
|
|
73
|
+
this._ctx.requireTokens();
|
|
74
|
+
const path = `/api/v1/users/company/${encodeURIComponent(companyId)}`;
|
|
75
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async getAllUsers(ascOrDesc, { lastId, limit } = {}) {
|
|
80
|
+
this._ctx.requireTokens();
|
|
81
|
+
let path = `/api/v1/users/admin/sort/${encodeURIComponent(ascOrDesc)}/`;
|
|
82
|
+
const query = new URLSearchParams();
|
|
83
|
+
if (lastId !== undefined) (Array.isArray(lastId) ? lastId : [lastId]).forEach(v => query.append('last_id', v));
|
|
84
|
+
if (limit !== undefined) (Array.isArray(limit) ? limit : [limit]).forEach(v => query.append('limit', v));
|
|
85
|
+
const qs = query.toString();
|
|
86
|
+
if (qs) path += '?' + qs;
|
|
87
|
+
const { data } = await this._ctx.client.request(path, 'GET', this._ctx.accessToken, this._ctx.refreshToken);
|
|
88
|
+
return data;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async updateUser(userId, { name, email, password, companyId, accountType, profilePicture, location, phoneNumber, birthday } = {}) {
|
|
92
|
+
this._ctx.requireTokens();
|
|
93
|
+
const path = `/api/v1/users/${encodeURIComponent(userId)}`;
|
|
94
|
+
const body = stripUndef({
|
|
95
|
+
name: name,
|
|
96
|
+
email: email,
|
|
97
|
+
password: password,
|
|
98
|
+
company_id: companyId,
|
|
99
|
+
account_type: accountType,
|
|
100
|
+
profile_picture: profilePicture,
|
|
101
|
+
location: location,
|
|
102
|
+
phone_number: phoneNumber,
|
|
103
|
+
birthday: birthday,
|
|
104
|
+
});
|
|
105
|
+
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async updateUserByAdmin(userId, { name, email, password, companyId, accountType, profilePicture, location, phoneNumber, birthday } = {}) {
|
|
110
|
+
this._ctx.requireTokens();
|
|
111
|
+
const path = `/api/v1/users/admin/${encodeURIComponent(userId)}`;
|
|
112
|
+
const body = stripUndef({
|
|
113
|
+
name: name,
|
|
114
|
+
email: email,
|
|
115
|
+
password: password,
|
|
116
|
+
company_id: companyId,
|
|
117
|
+
account_type: accountType,
|
|
118
|
+
profile_picture: profilePicture,
|
|
119
|
+
location: location,
|
|
120
|
+
phone_number: phoneNumber,
|
|
121
|
+
birthday: birthday,
|
|
122
|
+
});
|
|
123
|
+
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
124
|
+
return data;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async deleteUser(userId, { newCompanyOwnerId } = {}) {
|
|
128
|
+
this._ctx.requireTokens();
|
|
129
|
+
let path = `/api/v1/users/delete/${encodeURIComponent(userId)}`;
|
|
130
|
+
const query = new URLSearchParams();
|
|
131
|
+
if (newCompanyOwnerId !== undefined) (Array.isArray(newCompanyOwnerId) ? newCompanyOwnerId : [newCompanyOwnerId]).forEach(v => query.append('new_company_owner_id', v));
|
|
132
|
+
const qs = query.toString();
|
|
133
|
+
if (qs) path += '?' + qs;
|
|
134
|
+
const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
|
|
135
|
+
return data;
|
|
136
|
+
}
|
|
137
|
+
}
|