@mediaviz/sdk 1.8.0 → 1.9.0-dev.107
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/dist/sdk.cjs +246 -63
- package/dist/sdk.d.cts +14 -4
- package/dist/sdk.d.ts +14 -4
- package/dist/sdk.esm.d.ts +14 -4
- package/dist/sdk.esm.js +246 -64
- package/dist/sdk.umd.js +246 -63
- package/package.json +1 -1
package/dist/sdk.umd.js
CHANGED
|
@@ -8,36 +8,181 @@
|
|
|
8
8
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
var
|
|
12
|
-
var
|
|
11
|
+
var base64;
|
|
12
|
+
var hasRequiredBase64;
|
|
13
13
|
|
|
14
|
-
function
|
|
15
|
-
if (
|
|
16
|
-
|
|
14
|
+
function requireBase64 () {
|
|
15
|
+
if (hasRequiredBase64) return base64;
|
|
16
|
+
hasRequiredBase64 = 1;
|
|
17
|
+
|
|
18
|
+
// Base64URL codec, used by PKCE (encode) and JWT payload decoding (decode).
|
|
19
|
+
// Hand-rolled rather than delegating to atob/btoa, Buffer, or TextDecoder:
|
|
20
|
+
// none of those is present on every target runtime — React Native's Hermes has
|
|
21
|
+
// no Buffer and does not guarantee atob — and the alphabet here is URL-safe and
|
|
22
|
+
// unpadded, which the standard helpers do not produce.
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {Uint8Array} bytes
|
|
28
|
+
* @returns {string} unpadded base64url
|
|
29
|
+
*/
|
|
19
30
|
function base64urlEncode(bytes) {
|
|
20
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
21
31
|
let result = '';
|
|
22
32
|
for (let i = 0; i < bytes.length; i += 3) {
|
|
23
33
|
const b0 = bytes[i];
|
|
24
34
|
const b1 = i + 1 < bytes.length ? bytes[i + 1] : 0;
|
|
25
35
|
const b2 = i + 2 < bytes.length ? bytes[i + 2] : 0;
|
|
26
|
-
result +=
|
|
27
|
-
result +=
|
|
28
|
-
if (i + 1 < bytes.length) result +=
|
|
29
|
-
if (i + 2 < bytes.length) result +=
|
|
36
|
+
result += ALPHABET[b0 >> 2];
|
|
37
|
+
result += ALPHABET[((b0 & 3) << 4) | (b1 >> 4)];
|
|
38
|
+
if (i + 1 < bytes.length) result += ALPHABET[((b1 & 0xf) << 2) | (b2 >> 6)];
|
|
39
|
+
if (i + 2 < bytes.length) result += ALPHABET[b2 & 0x3f];
|
|
30
40
|
}
|
|
31
41
|
return result;
|
|
32
42
|
}
|
|
33
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Decodes base64url or standard base64, padded or not.
|
|
46
|
+
* @param {string} str
|
|
47
|
+
* @returns {Uint8Array}
|
|
48
|
+
*/
|
|
49
|
+
function base64urlDecode(str) {
|
|
50
|
+
const clean = String(str).replace(/=+$/, '');
|
|
51
|
+
const out = new Uint8Array((clean.length * 3) >> 2);
|
|
52
|
+
let acc = 0;
|
|
53
|
+
let bits = 0;
|
|
54
|
+
let i = 0;
|
|
55
|
+
for (const ch of clean) {
|
|
56
|
+
const value = decodeChar(ch);
|
|
57
|
+
if (value < 0) throw new TypeError(`Invalid base64url character: ${JSON.stringify(ch)}`);
|
|
58
|
+
acc = (acc << 6) | value;
|
|
59
|
+
bits += 6;
|
|
60
|
+
if (bits >= 8) {
|
|
61
|
+
bits -= 8;
|
|
62
|
+
out[i++] = (acc >> bits) & 0xff;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return out.subarray(0, i);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {Uint8Array} bytes
|
|
70
|
+
* @returns {string}
|
|
71
|
+
*/
|
|
72
|
+
function utf8Decode(bytes) {
|
|
73
|
+
let out = '';
|
|
74
|
+
let i = 0;
|
|
75
|
+
while (i < bytes.length) {
|
|
76
|
+
const b0 = bytes[i++];
|
|
77
|
+
let codePoint;
|
|
78
|
+
if (b0 < 0x80) codePoint = b0;
|
|
79
|
+
else if ((b0 & 0xe0) === 0xc0) codePoint = ((b0 & 0x1f) << 6) | (bytes[i++] & 0x3f);
|
|
80
|
+
else if ((b0 & 0xf0) === 0xe0)
|
|
81
|
+
codePoint = ((b0 & 0x0f) << 12) | ((bytes[i++] & 0x3f) << 6) | (bytes[i++] & 0x3f);
|
|
82
|
+
else
|
|
83
|
+
codePoint =
|
|
84
|
+
((b0 & 0x07) << 18) | ((bytes[i++] & 0x3f) << 12) | ((bytes[i++] & 0x3f) << 6) | (bytes[i++] & 0x3f);
|
|
85
|
+
out += String.fromCodePoint(codePoint);
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// helpers
|
|
91
|
+
function decodeChar(ch) {
|
|
92
|
+
// '+' and '/' map onto the URL-safe alphabet's '-' and '_' slots, so standard
|
|
93
|
+
// base64 decodes through the same table.
|
|
94
|
+
if (ch === '+') return 62;
|
|
95
|
+
if (ch === '/') return 63;
|
|
96
|
+
return ALPHABET.indexOf(ch);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
base64 = { base64urlEncode, base64urlDecode, utf8Decode };
|
|
100
|
+
return base64;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var crypto;
|
|
104
|
+
var hasRequiredCrypto;
|
|
105
|
+
|
|
106
|
+
function requireCrypto () {
|
|
107
|
+
if (hasRequiredCrypto) return crypto;
|
|
108
|
+
hasRequiredCrypto = 1;
|
|
109
|
+
|
|
110
|
+
// Crypto seam for PKCE.
|
|
111
|
+
//
|
|
112
|
+
// Defaults to WebCrypto, which covers browsers and Node >= 18. React Native's
|
|
113
|
+
// Hermes runtime provides neither half of what PKCE needs: there is no
|
|
114
|
+
// SubtleCrypto at all (so no SHA-256), and no crypto.getRandomValues without a
|
|
115
|
+
// polyfill. Hosts on such runtimes call configureCrypto() once at startup with
|
|
116
|
+
// native-backed equivalents (expo-crypto, react-native-quick-crypto).
|
|
117
|
+
|
|
118
|
+
/** @typedef {{getRandomValues: (bytes: Uint8Array) => Uint8Array, sha256: (bytes: Uint8Array) => Promise<Uint8Array>}} CryptoProvider */
|
|
119
|
+
|
|
120
|
+
let _provider = null;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Installs a crypto provider, replacing the WebCrypto default.
|
|
124
|
+
* @param {CryptoProvider} provider
|
|
125
|
+
*/
|
|
126
|
+
function configureCrypto(provider) {
|
|
127
|
+
if (!provider || typeof provider.getRandomValues !== 'function' || typeof provider.sha256 !== 'function') {
|
|
128
|
+
throw new TypeError(
|
|
129
|
+
'configureCrypto requires { getRandomValues(bytes) => bytes, sha256(bytes) => Promise<Uint8Array> }'
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
_provider = provider;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Restores the WebCrypto default. Primarily for tests. */
|
|
136
|
+
function resetCrypto() {
|
|
137
|
+
_provider = null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @returns {CryptoProvider}
|
|
142
|
+
*/
|
|
143
|
+
function getCrypto() {
|
|
144
|
+
return _provider ?? webCryptoProvider();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// helpers
|
|
148
|
+
function webCryptoProvider() {
|
|
149
|
+
const wc = globalThis.crypto;
|
|
150
|
+
// Named explicitly rather than letting a property access blow up deep inside
|
|
151
|
+
// PKCE: on React Native the failure is a missing polyfill, and the message
|
|
152
|
+
// has to say so.
|
|
153
|
+
if (!wc || typeof wc.getRandomValues !== 'function' || !wc.subtle) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
'No WebCrypto available in this runtime. On React Native (or any host without ' +
|
|
156
|
+
'SubtleCrypto), call configureCrypto({ getRandomValues, sha256 }) before using PKCE.'
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
getRandomValues: (bytes) => wc.getRandomValues(bytes),
|
|
161
|
+
sha256: async (bytes) => new Uint8Array(await wc.subtle.digest('SHA-256', bytes)),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
crypto = { configureCrypto, resetCrypto, getCrypto };
|
|
166
|
+
return crypto;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
var pkce;
|
|
170
|
+
var hasRequiredPkce;
|
|
171
|
+
|
|
172
|
+
function requirePkce () {
|
|
173
|
+
if (hasRequiredPkce) return pkce;
|
|
174
|
+
hasRequiredPkce = 1;
|
|
175
|
+
|
|
176
|
+
const { base64urlEncode } = requireBase64();
|
|
177
|
+
const { getCrypto } = requireCrypto();
|
|
178
|
+
|
|
34
179
|
/**
|
|
35
180
|
* Generates a 64-character PKCE code verifier from [A-Za-z0-9-._~].
|
|
36
181
|
* @returns {string}
|
|
37
182
|
*/
|
|
38
183
|
function generateCodeVerifier() {
|
|
39
184
|
const bytes = new Uint8Array(48);
|
|
40
|
-
|
|
185
|
+
getCrypto().getRandomValues(bytes);
|
|
41
186
|
return base64urlEncode(bytes).slice(0, 64);
|
|
42
187
|
}
|
|
43
188
|
|
|
@@ -47,9 +192,8 @@
|
|
|
47
192
|
* @returns {Promise<string>}
|
|
48
193
|
*/
|
|
49
194
|
async function generateCodeChallenge(verifier) {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
return base64urlEncode(new Uint8Array(hashBuf));
|
|
195
|
+
const hash = await getCrypto().sha256(asciiEncode(verifier));
|
|
196
|
+
return base64urlEncode(hash);
|
|
53
197
|
}
|
|
54
198
|
|
|
55
199
|
/**
|
|
@@ -58,8 +202,24 @@
|
|
|
58
202
|
*/
|
|
59
203
|
function generateState() {
|
|
60
204
|
const bytes = new Uint8Array(16);
|
|
61
|
-
|
|
62
|
-
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
205
|
+
getCrypto().getRandomValues(bytes);
|
|
206
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// helpers
|
|
210
|
+
|
|
211
|
+
// The RFC 7636 §4.1 verifier alphabet is ASCII-only, so a byte-per-char encode
|
|
212
|
+
// is exact and keeps TextEncoder — absent on some React Native versions — off
|
|
213
|
+
// the PKCE path entirely. A non-ASCII verifier is invalid input, not something
|
|
214
|
+
// to silently re-encode.
|
|
215
|
+
function asciiEncode(str) {
|
|
216
|
+
const out = new Uint8Array(str.length);
|
|
217
|
+
for (let i = 0; i < str.length; i++) {
|
|
218
|
+
const code = str.charCodeAt(i);
|
|
219
|
+
if (code > 0x7f) throw new TypeError('PKCE code_verifier must be ASCII (RFC 7636 §4.1)');
|
|
220
|
+
out[i] = code;
|
|
221
|
+
}
|
|
222
|
+
return out;
|
|
63
223
|
}
|
|
64
224
|
|
|
65
225
|
pkce = { generateCodeVerifier, generateCodeChallenge, generateState };
|
|
@@ -182,6 +342,7 @@
|
|
|
182
342
|
|
|
183
343
|
const { generateCodeVerifier, generateCodeChallenge, generateState } = requirePkce();
|
|
184
344
|
const { postForm, postJson } = requireHttp();
|
|
345
|
+
const { base64urlDecode, utf8Decode } = requireBase64();
|
|
185
346
|
const { OAuthError } = requireErrors();
|
|
186
347
|
|
|
187
348
|
// In-flight dedup key for client_credentials re-mints (no refresh_token to key on).
|
|
@@ -257,8 +418,7 @@
|
|
|
257
418
|
code,
|
|
258
419
|
code_verifier: codeVerifier,
|
|
259
420
|
redirect_uri: redirectUri ?? this._config.redirectUri,
|
|
260
|
-
|
|
261
|
-
client_secret: this._config.clientSecret,
|
|
421
|
+
...this._clientAuth(),
|
|
262
422
|
});
|
|
263
423
|
}
|
|
264
424
|
|
|
@@ -270,8 +430,7 @@
|
|
|
270
430
|
async getClientCredentialsToken() {
|
|
271
431
|
return postForm(`${this._config.baseUrl}/oauth/token`, {
|
|
272
432
|
grant_type: 'client_credentials',
|
|
273
|
-
|
|
274
|
-
client_secret: this._config.clientSecret,
|
|
433
|
+
...this._clientAuth(),
|
|
275
434
|
});
|
|
276
435
|
}
|
|
277
436
|
|
|
@@ -283,8 +442,7 @@
|
|
|
283
442
|
return postForm(`${this._config.baseUrl}/oauth/token`, {
|
|
284
443
|
grant_type: 'refresh_token',
|
|
285
444
|
refresh_token: refreshToken,
|
|
286
|
-
|
|
287
|
-
client_secret: this._config.clientSecret,
|
|
445
|
+
...this._clientAuth(),
|
|
288
446
|
});
|
|
289
447
|
}
|
|
290
448
|
|
|
@@ -294,7 +452,7 @@
|
|
|
294
452
|
* @returns {Promise<void>}
|
|
295
453
|
*/
|
|
296
454
|
async revokeToken(token, tokenTypeHint) {
|
|
297
|
-
const params = { token,
|
|
455
|
+
const params = { token, ...this._clientAuth() };
|
|
298
456
|
if (tokenTypeHint) params.token_type_hint = tokenTypeHint;
|
|
299
457
|
await postForm(`${this._config.baseUrl}/oauth/revoke`, params);
|
|
300
458
|
}
|
|
@@ -375,10 +533,22 @@
|
|
|
375
533
|
decodeAccessToken(accessToken) {
|
|
376
534
|
const segment = accessToken.split('.')[1];
|
|
377
535
|
if (!segment) throw new OAuthError('invalid_token', 'Malformed JWT', 400);
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
536
|
+
return JSON.parse(utf8Decode(base64urlDecode(segment)));
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Client-authentication params for a token-endpoint request.
|
|
541
|
+
*
|
|
542
|
+
* A public client (mobile, SPA) holds no secret, and the authorization server
|
|
543
|
+
* rejects the request outright if one is present, so the key is omitted
|
|
544
|
+
* entirely rather than sent empty. Passing it through unconditionally
|
|
545
|
+
* serializes `undefined` into the form body as that literal string.
|
|
546
|
+
* @returns {Record<string, string>}
|
|
547
|
+
*/
|
|
548
|
+
_clientAuth() {
|
|
549
|
+
const params = { client_id: this._config.clientId };
|
|
550
|
+
if (this._config.clientSecret) params.client_secret = this._config.clientSecret;
|
|
551
|
+
return params;
|
|
382
552
|
}
|
|
383
553
|
}
|
|
384
554
|
|
|
@@ -475,8 +645,9 @@
|
|
|
475
645
|
const { OAuthClient } = requireClient();
|
|
476
646
|
const { OAuthError } = requireErrors();
|
|
477
647
|
const { OAuthErrorCode } = requireTypes();
|
|
648
|
+
const { configureCrypto } = requireCrypto();
|
|
478
649
|
|
|
479
|
-
src$1 = { OAuthClient, OAuthError, OAuthErrorCode };
|
|
650
|
+
src$1 = { OAuthClient, OAuthError, OAuthErrorCode, configureCrypto };
|
|
480
651
|
return src$1;
|
|
481
652
|
}
|
|
482
653
|
|
|
@@ -484,7 +655,7 @@
|
|
|
484
655
|
var _oauth = /*@__PURE__*/getDefaultExportFromCjs(srcExports$1);
|
|
485
656
|
|
|
486
657
|
// Auto-generated — do not edit
|
|
487
|
-
const { OAuthClient, OAuthError, OAuthErrorCode } = _oauth;
|
|
658
|
+
const { OAuthClient, OAuthError, OAuthErrorCode, configureCrypto } = _oauth;
|
|
488
659
|
|
|
489
660
|
var signing;
|
|
490
661
|
var hasRequiredSigning;
|
|
@@ -501,12 +672,21 @@
|
|
|
501
672
|
// constant time. Web Crypto only, so the same code runs in Node >= 18 and
|
|
502
673
|
// browsers.
|
|
503
674
|
|
|
504
|
-
|
|
675
|
+
// Built on first use, not at import. These functions are a server-side concern
|
|
676
|
+
// (only the endpoint receiving a push verifies a signature), but the module is
|
|
677
|
+
// bundled into every SDK including React Native — and constructing this at
|
|
678
|
+
// module scope made merely importing the SDK crash on any runtime without a
|
|
679
|
+
// TextEncoder global.
|
|
680
|
+
let _encoderInstance = null;
|
|
681
|
+
function _encode(text) {
|
|
682
|
+
if (!_encoderInstance) _encoderInstance = new TextEncoder();
|
|
683
|
+
return _encoderInstance.encode(text);
|
|
684
|
+
}
|
|
505
685
|
|
|
506
686
|
async function signWebhookPayload(secret, timestamp, rawBody) {
|
|
507
687
|
const key = await globalThis.crypto.subtle.importKey(
|
|
508
|
-
'raw',
|
|
509
|
-
const payload = _concat(
|
|
688
|
+
'raw', _encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
689
|
+
const payload = _concat(_encode(`${timestamp}.`), toBytes(rawBody));
|
|
510
690
|
const digest = await globalThis.crypto.subtle.sign('HMAC', key, payload);
|
|
511
691
|
return 'sha256=' + _hex(new Uint8Array(digest));
|
|
512
692
|
}
|
|
@@ -530,7 +710,7 @@
|
|
|
530
710
|
|
|
531
711
|
// helpers
|
|
532
712
|
function toBytes(rawBody) {
|
|
533
|
-
if (typeof rawBody === 'string') return
|
|
713
|
+
if (typeof rawBody === 'string') return _encode(rawBody);
|
|
534
714
|
if (rawBody instanceof Uint8Array) return rawBody;
|
|
535
715
|
if (rawBody instanceof ArrayBuffer) return new Uint8Array(rawBody);
|
|
536
716
|
throw new TypeError('rawBody must be a string, Uint8Array, or ArrayBuffer');
|
|
@@ -973,7 +1153,7 @@
|
|
|
973
1153
|
}
|
|
974
1154
|
}
|
|
975
1155
|
|
|
976
|
-
function stripUndef$
|
|
1156
|
+
function stripUndef$8(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
|
|
977
1157
|
|
|
978
1158
|
class CuratedAlbums {
|
|
979
1159
|
constructor(ctx) { this._ctx = ctx; }
|
|
@@ -981,7 +1161,7 @@
|
|
|
981
1161
|
async createCuratedAlbum(projectTableName, name, description = undefined, confidenceValue = undefined) {
|
|
982
1162
|
this._ctx.requireTokens();
|
|
983
1163
|
const path = `/api/v1/curated_album/project/${encodeURIComponent(projectTableName)}`;
|
|
984
|
-
const body = stripUndef$
|
|
1164
|
+
const body = stripUndef$8({
|
|
985
1165
|
name: name,
|
|
986
1166
|
description: description,
|
|
987
1167
|
confidence_value: confidenceValue,
|
|
@@ -1035,7 +1215,7 @@
|
|
|
1035
1215
|
async updateCuratedAlbum(albumId, { name, description, confidenceValue } = {}) {
|
|
1036
1216
|
this._ctx.requireTokens();
|
|
1037
1217
|
const path = `/api/v1/curated_album/${encodeURIComponent(albumId)}`;
|
|
1038
|
-
const body = stripUndef$
|
|
1218
|
+
const body = stripUndef$8({
|
|
1039
1219
|
name: name,
|
|
1040
1220
|
description: description,
|
|
1041
1221
|
confidence_value: confidenceValue,
|
|
@@ -1059,7 +1239,7 @@
|
|
|
1059
1239
|
}
|
|
1060
1240
|
}
|
|
1061
1241
|
|
|
1062
|
-
function stripUndef$
|
|
1242
|
+
function stripUndef$7(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
|
|
1063
1243
|
|
|
1064
1244
|
class CustomAlbums {
|
|
1065
1245
|
constructor(ctx) { this._ctx = ctx; }
|
|
@@ -1107,7 +1287,7 @@
|
|
|
1107
1287
|
async createProjectCustomAlbum(projectTableName, { name, description, photoIdInclusionList, photoIdRemovalList } = {}) {
|
|
1108
1288
|
this._ctx.requireTokens();
|
|
1109
1289
|
const path = `/api/v1/custom_album/project/${encodeURIComponent(projectTableName)}`;
|
|
1110
|
-
const body = stripUndef$
|
|
1290
|
+
const body = stripUndef$7({
|
|
1111
1291
|
name: name,
|
|
1112
1292
|
description: description,
|
|
1113
1293
|
photo_id_inclusion_list: photoIdInclusionList,
|
|
@@ -1120,7 +1300,7 @@
|
|
|
1120
1300
|
async updateCustomAlbum(albumId, { name, description, photoIdInclusionList, photoIdRemovalList } = {}) {
|
|
1121
1301
|
this._ctx.requireTokens();
|
|
1122
1302
|
const path = `/api/v1/custom_album/${encodeURIComponent(albumId)}`;
|
|
1123
|
-
const body = stripUndef$
|
|
1303
|
+
const body = stripUndef$7({
|
|
1124
1304
|
name: name,
|
|
1125
1305
|
description: description,
|
|
1126
1306
|
photo_id_inclusion_list: photoIdInclusionList,
|
|
@@ -1220,7 +1400,7 @@
|
|
|
1220
1400
|
}
|
|
1221
1401
|
}
|
|
1222
1402
|
|
|
1223
|
-
function stripUndef$
|
|
1403
|
+
function stripUndef$6(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
|
|
1224
1404
|
|
|
1225
1405
|
class EmailTokens {
|
|
1226
1406
|
constructor(ctx) { this._ctx = ctx; }
|
|
@@ -1251,7 +1431,7 @@
|
|
|
1251
1431
|
}
|
|
1252
1432
|
|
|
1253
1433
|
async validateToken(token) {
|
|
1254
|
-
const body = stripUndef$
|
|
1434
|
+
const body = stripUndef$6({
|
|
1255
1435
|
token: token,
|
|
1256
1436
|
});
|
|
1257
1437
|
const resp = await fetch(this._ctx.baseUrl + `/api/v1/validate-token`, {
|
|
@@ -1263,7 +1443,7 @@
|
|
|
1263
1443
|
}
|
|
1264
1444
|
|
|
1265
1445
|
async resetPassword(token, newPassword) {
|
|
1266
|
-
const body = stripUndef$
|
|
1446
|
+
const body = stripUndef$6({
|
|
1267
1447
|
token: token,
|
|
1268
1448
|
new_password: newPassword,
|
|
1269
1449
|
});
|
|
@@ -1302,7 +1482,7 @@
|
|
|
1302
1482
|
}
|
|
1303
1483
|
}
|
|
1304
1484
|
|
|
1305
|
-
function stripUndef$
|
|
1485
|
+
function stripUndef$5(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
|
|
1306
1486
|
|
|
1307
1487
|
class Keywords {
|
|
1308
1488
|
constructor(ctx) { this._ctx = ctx; }
|
|
@@ -1310,7 +1490,7 @@
|
|
|
1310
1490
|
async createKeywordFilteringList(name, projectList = undefined) {
|
|
1311
1491
|
this._ctx.requireTokens();
|
|
1312
1492
|
const path = `/api/v1/keyword/`;
|
|
1313
|
-
const body = stripUndef$
|
|
1493
|
+
const body = stripUndef$5({
|
|
1314
1494
|
name: name,
|
|
1315
1495
|
project_list: projectList,
|
|
1316
1496
|
});
|
|
@@ -1363,7 +1543,7 @@
|
|
|
1363
1543
|
async updateKeywordFilteringListLabels(keywordListId, listKeywordsToInclude, listKeywordsToExclude) {
|
|
1364
1544
|
this._ctx.requireTokens();
|
|
1365
1545
|
const path = `/api/v1/keyword/${encodeURIComponent(keywordListId)}`;
|
|
1366
|
-
const body = stripUndef$
|
|
1546
|
+
const body = stripUndef$5({
|
|
1367
1547
|
list_keywords_to_include: listKeywordsToInclude,
|
|
1368
1548
|
list_keywords_to_exclude: listKeywordsToExclude,
|
|
1369
1549
|
});
|
|
@@ -1374,7 +1554,7 @@
|
|
|
1374
1554
|
async updateKeywordFilteringListDetails(keywordListId, { name, projectList } = {}) {
|
|
1375
1555
|
this._ctx.requireTokens();
|
|
1376
1556
|
const path = `/api/v1/keyword/details/${encodeURIComponent(keywordListId)}`;
|
|
1377
|
-
const body = stripUndef$
|
|
1557
|
+
const body = stripUndef$5({
|
|
1378
1558
|
name: name,
|
|
1379
1559
|
project_list: projectList,
|
|
1380
1560
|
});
|
|
@@ -1639,7 +1819,7 @@
|
|
|
1639
1819
|
}
|
|
1640
1820
|
}
|
|
1641
1821
|
|
|
1642
|
-
function stripUndef$
|
|
1822
|
+
function stripUndef$4(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
|
|
1643
1823
|
|
|
1644
1824
|
class Projects {
|
|
1645
1825
|
constructor(ctx) { this._ctx = ctx; }
|
|
@@ -1652,7 +1832,7 @@
|
|
|
1652
1832
|
if (models !== undefined) (Array.isArray(models) ? models : [models]).forEach(v => query.append('models', v));
|
|
1653
1833
|
const qs = query.toString();
|
|
1654
1834
|
if (qs) path += '?' + qs;
|
|
1655
|
-
const body = stripUndef$
|
|
1835
|
+
const body = stripUndef$4({
|
|
1656
1836
|
name: name,
|
|
1657
1837
|
private: private_,
|
|
1658
1838
|
type: type,
|
|
@@ -1722,7 +1902,7 @@
|
|
|
1722
1902
|
async updateProject(projectId, { private: private_, type, description, directory, name, thumbnail } = {}) {
|
|
1723
1903
|
this._ctx.requireTokens();
|
|
1724
1904
|
const path = `/api/v1/projects/${encodeURIComponent(projectId)}`;
|
|
1725
|
-
const body = stripUndef$
|
|
1905
|
+
const body = stripUndef$4({
|
|
1726
1906
|
private: private_,
|
|
1727
1907
|
type: type,
|
|
1728
1908
|
description: description,
|
|
@@ -1801,7 +1981,7 @@
|
|
|
1801
1981
|
async addProjectEvent(projectTableName, event, detail = undefined) {
|
|
1802
1982
|
this._ctx.requireTokens();
|
|
1803
1983
|
const path = `/api/v1/projects/${encodeURIComponent(projectTableName)}/event`;
|
|
1804
|
-
const body = stripUndef$
|
|
1984
|
+
const body = stripUndef$4({
|
|
1805
1985
|
event: event,
|
|
1806
1986
|
detail: detail,
|
|
1807
1987
|
});
|
|
@@ -1820,7 +2000,7 @@
|
|
|
1820
2000
|
class Photoupload {
|
|
1821
2001
|
constructor(ctx) { this._ctx = ctx; this._caches = {}; }
|
|
1822
2002
|
|
|
1823
|
-
async uploadPhotoToMediaviz(fileContent, filePath, mimetype, companyId, userId, projectTableName, blur, colors, faceRecognition, imageClassification, imageComparison, imageDescribe, ocr, { clientSideId, format, size, sourceResolutionX, sourceResolutionY, dateTaken, latitude, longitude } = {}) {
|
|
2003
|
+
async uploadPhotoToMediaviz(fileContent, filePath, mimetype, companyId, userId, projectTableName, blur, colors, faceRecognition, imageClassification, imageComparison, imageDescribe, ocr, judgment, { clientSideId, format, size, sourceResolutionX, sourceResolutionY, dateTaken, latitude, longitude } = {}) {
|
|
1824
2004
|
this._ctx.requireTokens();
|
|
1825
2005
|
const baseUrl = this._ctx.requireHost('photoUpload');
|
|
1826
2006
|
const headers = {
|
|
@@ -1830,7 +2010,7 @@
|
|
|
1830
2010
|
const resp = await fetch(baseUrl + `/photo_upload`, {
|
|
1831
2011
|
method: 'POST',
|
|
1832
2012
|
headers,
|
|
1833
|
-
body: JSON.stringify({ file_content: fileContent, file_path: filePath, mimetype, company_id: companyId, user_id: userId, project_table_name: projectTableName, blur, colors, face_recognition: faceRecognition, image_classification: imageClassification, image_comparison: imageComparison, image_describe: imageDescribe, ocr, client_side_id: clientSideId, format, size, source_resolution_x: sourceResolutionX, source_resolution_y: sourceResolutionY, date_taken: dateTaken, latitude, longitude }),
|
|
2013
|
+
body: JSON.stringify({ file_content: fileContent, file_path: filePath, mimetype, company_id: companyId, user_id: userId, project_table_name: projectTableName, blur, colors, face_recognition: faceRecognition, image_classification: imageClassification, image_comparison: imageComparison, image_describe: imageDescribe, ocr, judgment, client_side_id: clientSideId, format, size, source_resolution_x: sourceResolutionX, source_resolution_y: sourceResolutionY, date_taken: dateTaken, latitude, longitude }),
|
|
1834
2014
|
});
|
|
1835
2015
|
return handleResponse(resp);
|
|
1836
2016
|
}
|
|
@@ -1846,12 +2026,14 @@
|
|
|
1846
2026
|
this._caches['_get_template'].set(_cacheKey_get_template, template);
|
|
1847
2027
|
}
|
|
1848
2028
|
|
|
1849
|
-
const upload_result = await this.uploadPhotoToMediaviz(photo.fileContent, photo.filePath, photo.mimetype, companyId, userId, projectTableName, (((template?.body?.['blur'] ?? template?.headers?.['x-blur']) === true || (template?.body?.['blur'] ?? template?.headers?.['x-blur']) === 'true') ? 'true' : undefined), (((template?.body?.['colors'] ?? template?.headers?.['x-colors']) === true || (template?.body?.['colors'] ?? template?.headers?.['x-colors']) === 'true') ? 'true' : undefined), (((template?.body?.['face_recognition'] ?? template?.headers?.['x-face-recognition']) === true || (template?.body?.['face_recognition'] ?? template?.headers?.['x-face-recognition']) === 'true') ? 'true' : undefined), (((template?.body?.['image_classification'] ?? template?.headers?.['x-image-classification']) === true || (template?.body?.['image_classification'] ?? template?.headers?.['x-image-classification']) === 'true') ? 'true' : undefined), (((template?.body?.['image_comparison'] ?? template?.headers?.['x-image-comparison']) === true || (template?.body?.['image_comparison'] ?? template?.headers?.['x-image-comparison']) === 'true') ? 'true' : undefined), (((template?.body?.['image_describe'] ?? template?.headers?.['x-image-describe']) === true || (template?.body?.['image_describe'] ?? template?.headers?.['x-image-describe']) === 'true') ? 'true' : undefined), (((template?.body?.['ocr'] ?? template?.headers?.['x-ocr']) === true || (template?.body?.['ocr'] ?? template?.headers?.['x-ocr']) === 'true') ? 'true' : undefined), { clientSideId: photo.clientSideId, format: photo.format, size: photo.size, sourceResolutionX: photo.sourceResolutionX, sourceResolutionY: photo.sourceResolutionY, dateTaken: photo.dateTaken, latitude: photo.latitude, longitude: photo.longitude });
|
|
2029
|
+
const upload_result = await this.uploadPhotoToMediaviz(photo.fileContent, photo.filePath, photo.mimetype, companyId, userId, projectTableName, (((template?.body?.['blur'] ?? template?.headers?.['x-blur']) === true || (template?.body?.['blur'] ?? template?.headers?.['x-blur']) === 'true') ? 'true' : undefined), (((template?.body?.['colors'] ?? template?.headers?.['x-colors']) === true || (template?.body?.['colors'] ?? template?.headers?.['x-colors']) === 'true') ? 'true' : undefined), (((template?.body?.['face_recognition'] ?? template?.headers?.['x-face-recognition']) === true || (template?.body?.['face_recognition'] ?? template?.headers?.['x-face-recognition']) === 'true') ? 'true' : undefined), (((template?.body?.['image_classification'] ?? template?.headers?.['x-image-classification']) === true || (template?.body?.['image_classification'] ?? template?.headers?.['x-image-classification']) === 'true') ? 'true' : undefined), (((template?.body?.['image_comparison'] ?? template?.headers?.['x-image-comparison']) === true || (template?.body?.['image_comparison'] ?? template?.headers?.['x-image-comparison']) === 'true') ? 'true' : undefined), (((template?.body?.['image_describe'] ?? template?.headers?.['x-image-describe']) === true || (template?.body?.['image_describe'] ?? template?.headers?.['x-image-describe']) === 'true') ? 'true' : undefined), (((template?.body?.['ocr'] ?? template?.headers?.['x-ocr']) === true || (template?.body?.['ocr'] ?? template?.headers?.['x-ocr']) === 'true') ? 'true' : undefined), (((template?.body?.['judgment'] ?? template?.headers?.['x-judgment']) === true || (template?.body?.['judgment'] ?? template?.headers?.['x-judgment']) === 'true') ? 'true' : undefined), { clientSideId: photo.clientSideId, format: photo.format, size: photo.size, sourceResolutionX: photo.sourceResolutionX, sourceResolutionY: photo.sourceResolutionY, dateTaken: photo.dateTaken, latitude: photo.latitude, longitude: photo.longitude });
|
|
1850
2030
|
|
|
1851
2031
|
return upload_result;
|
|
1852
2032
|
}
|
|
1853
2033
|
}
|
|
1854
2034
|
|
|
2035
|
+
function stripUndef$3(o) { const r = {}; for (const k in o) if (o[k] !== undefined) r[k] = o[k]; return r; }
|
|
2036
|
+
|
|
1855
2037
|
class Photos {
|
|
1856
2038
|
constructor(ctx) { this._ctx = ctx; }
|
|
1857
2039
|
|
|
@@ -1913,16 +2095,16 @@
|
|
|
1913
2095
|
return data;
|
|
1914
2096
|
}
|
|
1915
2097
|
|
|
1916
|
-
async updatePhotoInProject(
|
|
2098
|
+
async updatePhotoInProject(tableName, photoId, { filePath, title, description, tags } = {}) {
|
|
1917
2099
|
this._ctx.requireTokens();
|
|
1918
|
-
|
|
1919
|
-
const
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken);
|
|
2100
|
+
const path = `/api/v1/photos_update/${encodeURIComponent(tableName)}/id/${encodeURIComponent(photoId)}`;
|
|
2101
|
+
const body = stripUndef$3({
|
|
2102
|
+
file_path: filePath,
|
|
2103
|
+
title: title,
|
|
2104
|
+
description: description,
|
|
2105
|
+
tags: tags,
|
|
2106
|
+
});
|
|
2107
|
+
const { data } = await this._ctx.client.request(path, 'PUT', this._ctx.accessToken, this._ctx.refreshToken, body);
|
|
1926
2108
|
return data;
|
|
1927
2109
|
}
|
|
1928
2110
|
|
|
@@ -2398,6 +2580,7 @@
|
|
|
2398
2580
|
exports.WEBHOOK_MODEL_COLUMNS = WEBHOOK_MODEL_COLUMNS;
|
|
2399
2581
|
exports.WEBHOOK_OUTCOME_MODELS = WEBHOOK_OUTCOME_MODELS;
|
|
2400
2582
|
exports.WebhookConsumer = WebhookConsumer;
|
|
2583
|
+
exports.configureCrypto = configureCrypto;
|
|
2401
2584
|
exports.handleResponse = handleResponse;
|
|
2402
2585
|
exports.selectResultColumns = selectResultColumns;
|
|
2403
2586
|
exports.signWebhookPayload = signWebhookPayload;
|