@mediaviz/sdk 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/dist/sdk.cjs +99 -226
  3. package/dist/sdk.d.cts +503 -0
  4. package/dist/sdk.d.ts +503 -0
  5. package/dist/sdk.esm.d.ts +503 -0
  6. package/dist/sdk.esm.js +100 -226
  7. package/dist/sdk.umd.js +99 -226
  8. package/package.json +23 -10
  9. package/MediaViz.js +0 -126
  10. package/_oauth.js +0 -3
  11. package/admin.js +0 -93
  12. package/ai_model_credits.js +0 -22
  13. package/company.js +0 -54
  14. package/curated_albums.js +0 -85
  15. package/custom_albums.js +0 -78
  16. package/email_tokens.js +0 -64
  17. package/errors.js +0 -81
  18. package/health.js +0 -20
  19. package/index.js +0 -21
  20. package/keywords.js +0 -123
  21. package/oauth/.prettierrc +0 -6
  22. package/oauth/README.md +0 -76
  23. package/oauth/browser-smoke-test.html +0 -45
  24. package/oauth/implementation_plan.json +0 -106
  25. package/oauth/package-lock.json +0 -5236
  26. package/oauth/package.json +0 -28
  27. package/oauth/rollup.config.js +0 -21
  28. package/oauth/smoke-test.js +0 -27
  29. package/oauth/spec.md +0 -187
  30. package/oauth/src/__tests__/browser-smoke-test.test.js +0 -38
  31. package/oauth/src/__tests__/client.test.js +0 -556
  32. package/oauth/src/__tests__/errors.test.js +0 -73
  33. package/oauth/src/__tests__/http.test.js +0 -102
  34. package/oauth/src/__tests__/index.test.js +0 -53
  35. package/oauth/src/__tests__/package-fields.test.js +0 -29
  36. package/oauth/src/__tests__/pkce.test.js +0 -55
  37. package/oauth/src/__tests__/rollup-build.test.js +0 -58
  38. package/oauth/src/__tests__/smoke-test.test.js +0 -26
  39. package/oauth/src/__tests__/types.test.js +0 -29
  40. package/oauth/src/client.js +0 -180
  41. package/oauth/src/errors.js +0 -32
  42. package/oauth/src/http.js +0 -52
  43. package/oauth/src/index.js +0 -7
  44. package/oauth/src/pkce.js +0 -50
  45. package/oauth/src/types.js +0 -67
  46. package/oauth_authorization.js +0 -53
  47. package/oauth_clients.js +0 -18
  48. package/oauth_login.js +0 -24
  49. package/oauth_token.js +0 -30
  50. package/person.js +0 -54
  51. package/photos.js +0 -106
  52. package/photoupload.js +0 -55
  53. package/projects.js +0 -191
  54. package/rollup.config.js +0 -12
  55. package/search.js +0 -99
  56. package/users.js +0 -137
package/MediaViz.js DELETED
@@ -1,126 +0,0 @@
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 DELETED
@@ -1,3 +0,0 @@
1
- // Auto-generated — do not edit
2
- import _oauth from './oauth/src/index.js';
3
- export const { OAuthClient, OAuthError, OAuthErrorCode } = _oauth;
package/admin.js DELETED
@@ -1,93 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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 DELETED
@@ -1,54 +0,0 @@
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
- }
package/curated_albums.js DELETED
@@ -1,85 +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 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 DELETED
@@ -1,78 +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 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
- }
package/email_tokens.js DELETED
@@ -1,64 +0,0 @@
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 EmailTokens {
6
- constructor(ctx) { this._ctx = ctx; }
7
-
8
- async requestEmailVerification({ email } = {}) {
9
- let path = `/api/v1/request-email-verification`;
10
- const query = new URLSearchParams();
11
- if (email !== undefined) (Array.isArray(email) ? email : [email]).forEach(v => query.append('email', v));
12
- const qs = query.toString();
13
- if (qs) path += '?' + qs;
14
- const resp = await fetch(this._ctx.baseUrl + path, { method: 'POST' });
15
- return handleResponse(resp);
16
- }
17
-
18
- async verifyEmail(token) {
19
- const resp = await fetch(this._ctx.baseUrl + `/api/v1/verify-email/${encodeURIComponent(token)}`, { method: 'POST' });
20
- return handleResponse(resp);
21
- }
22
-
23
- async requestPasswordReset({ email } = {}) {
24
- let path = `/api/v1/request-password-reset`;
25
- const query = new URLSearchParams();
26
- if (email !== undefined) (Array.isArray(email) ? email : [email]).forEach(v => query.append('email', v));
27
- const qs = query.toString();
28
- if (qs) path += '?' + qs;
29
- const resp = await fetch(this._ctx.baseUrl + path, { method: 'POST' });
30
- return handleResponse(resp);
31
- }
32
-
33
- async validateToken(token) {
34
- const body = stripUndef({
35
- token: token,
36
- });
37
- const resp = await fetch(this._ctx.baseUrl + `/api/v1/validate-token`, {
38
- method: 'POST',
39
- headers: { 'Content-Type': 'application/json' },
40
- body: JSON.stringify(body),
41
- });
42
- return handleResponse(resp);
43
- }
44
-
45
- async resetPassword(token, newPassword) {
46
- const body = stripUndef({
47
- token: token,
48
- new_password: newPassword,
49
- });
50
- const resp = await fetch(this._ctx.baseUrl + `/api/v1/reset-password`, {
51
- method: 'POST',
52
- headers: { 'Content-Type': 'application/json' },
53
- body: JSON.stringify(body),
54
- });
55
- return handleResponse(resp);
56
- }
57
-
58
- async deleteUserEmailTokens(userId) {
59
- this._ctx.requireTokens();
60
- const path = `/api/v1/admin/email_tokens/by_user/${encodeURIComponent(userId)}`;
61
- const { data } = await this._ctx.client.request(path, 'DELETE', this._ctx.accessToken, this._ctx.refreshToken);
62
- return data;
63
- }
64
- }
package/errors.js DELETED
@@ -1,81 +0,0 @@
1
- // Auto-generated — do not edit
2
-
3
- export class ApiError extends Error {
4
- constructor(message, status, requestId, body) {
5
- super(message);
6
- this.name = 'ApiError';
7
- this.status = status;
8
- this.requestId = requestId;
9
- this.body = body;
10
- }
11
- }
12
-
13
- export class ValidationError extends ApiError {
14
- constructor(body, status, requestId) {
15
- const detail = body.detail ?? [];
16
- const message = Array.isArray(detail)
17
- ? detail.map(d => `${d.loc.join('.')}: ${d.msg}`).join('; ')
18
- : String(detail);
19
- super(message, status, requestId, body);
20
- this.name = 'ValidationError';
21
- this.fieldErrors = Array.isArray(detail)
22
- ? detail.map(d => ({ loc: d.loc, msg: d.msg, type: d.type }))
23
- : [];
24
- }
25
- }
26
-
27
- export class NotFoundError extends ApiError {
28
- constructor(body, status, requestId) {
29
- super(body.detail ?? 'Resource not found', status, requestId, body);
30
- this.name = 'NotFoundError';
31
- }
32
- }
33
-
34
- export class RateLimitError extends ApiError {
35
- constructor(body, status, requestId, headers) {
36
- super(body.detail ?? 'Rate limited', status, requestId, body);
37
- this.name = 'RateLimitError';
38
- this.retryAfter = parseInt(headers.get('retry-after') ?? '', 10) || null;
39
- }
40
- }
41
-
42
- export class ServerError extends ApiError {
43
- constructor(body, status, requestId) {
44
- super(body.detail ?? 'Internal server error', status, requestId, body);
45
- this.name = 'ServerError';
46
- }
47
- }
48
-
49
- export async function handleResponse(response) {
50
- const requestId = response.headers.get('x-request-id');
51
-
52
- if (response.ok) {
53
- return response.status === 204 ? null : response.json();
54
- }
55
-
56
- let body;
57
- try {
58
- body = await response.json();
59
- } catch {
60
- body = { detail: response.statusText };
61
- }
62
-
63
- switch (response.status) {
64
- case 422:
65
- throw new ValidationError(body, response.status, requestId);
66
- case 404:
67
- throw new NotFoundError(body, response.status, requestId);
68
- case 429:
69
- throw new RateLimitError(body, response.status, requestId, response.headers);
70
- default:
71
- if (response.status >= 500) {
72
- throw new ServerError(body, response.status, requestId);
73
- }
74
- throw new ApiError(
75
- body.detail ?? 'Unknown error',
76
- response.status,
77
- requestId,
78
- body
79
- );
80
- }
81
- }
package/health.js DELETED
@@ -1,20 +0,0 @@
1
- import { handleResponse } from './errors.js';
2
-
3
- export class Health {
4
- constructor(ctx) { this._ctx = ctx; }
5
-
6
- async healthCheck() {
7
- const resp = await fetch(this._ctx.baseUrl + `/api/v1/health/`, { method: 'GET' });
8
- return handleResponse(resp);
9
- }
10
-
11
- async livenessCheck() {
12
- const resp = await fetch(this._ctx.baseUrl + `/api/v1/health/live/`, { method: 'GET' });
13
- return handleResponse(resp);
14
- }
15
-
16
- async readinessCheck() {
17
- const resp = await fetch(this._ctx.baseUrl + `/api/v1/health/ready`, { method: 'GET' });
18
- return handleResponse(resp);
19
- }
20
- }
package/index.js DELETED
@@ -1,21 +0,0 @@
1
- export { MediaViz } from './MediaViz.js';
2
- export * from './errors.js';
3
- export * from './_oauth.js';
4
- export * from './admin.js';
5
- export * from './ai_model_credits.js';
6
- export * from './company.js';
7
- export * from './curated_albums.js';
8
- export * from './custom_albums.js';
9
- export * from './email_tokens.js';
10
- export * from './health.js';
11
- export * from './keywords.js';
12
- export * from './oauth_authorization.js';
13
- export * from './oauth_clients.js';
14
- export * from './oauth_login.js';
15
- export * from './oauth_token.js';
16
- export * from './person.js';
17
- export * from './photos.js';
18
- export * from './photoupload.js';
19
- export * from './projects.js';
20
- export * from './search.js';
21
- export * from './users.js';