idmission-web-sdk 2.2.56 → 2.2.58

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.
@@ -211,7 +211,7 @@
211
211
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
212
212
  };
213
213
 
214
- var webSdkVersion = '2.2.56';
214
+ var webSdkVersion = '2.2.58';
215
215
 
216
216
  function getPlatform() {
217
217
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -2277,7 +2277,7 @@
2277
2277
  var uploadDocument = React.useCallback(function (src, metadata) {
2278
2278
  return new Promise(function (resolve, reject) {
2279
2279
  return __awaiter(void 0, void 0, void 0, function () {
2280
- var blob, _a, upload, _b, _c;
2280
+ var blob, _a, documentId, upload, _b, _c;
2281
2281
  var _d, _e;
2282
2282
  var _f;
2283
2283
  return __generator(this, function (_g) {
@@ -2315,9 +2315,22 @@
2315
2315
  percentage: (bytesUploaded / bytesTotal * 100).toFixed(2) + '%',
2316
2316
  metadata: metadata
2317
2317
  });
2318
+ }, _d.onAfterResponse = function (_req, res) {
2319
+ var contentType = res.getHeader('Content-Type');
2320
+ if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('application/json'))) return;
2321
+ var body = res.getBody();
2322
+ if (!body) return;
2323
+ try {
2324
+ var parsedId = JSON.parse(body).id;
2325
+ if (parsedId.startsWith('urn:documentsv1:')) {
2326
+ documentId = parsedId;
2327
+ }
2328
+ } catch (e) {
2329
+ warn('Failed to parse documents service response body', e);
2330
+ }
2318
2331
  }, _d.onSuccess = function () {
2319
2332
  var _a, _b;
2320
- var documentId = 'urn:documentsv1:' + ((_a = upload.url.split('/files/').pop()) === null || _a === void 0 ? void 0 : _a.split('+').shift());
2333
+ documentId || (documentId = "urn:documentsv1:".concat(getEnvFromUrl(upload.url), ":").concat((_a = upload.url.split('/files/').pop()) === null || _a === void 0 ? void 0 : _a.split('+').shift()));
2321
2334
  (_b = onDocumentUploaded.current) === null || _b === void 0 ? void 0 : _b.call(onDocumentUploaded, documentId, metadata);
2322
2335
  resolve(documentId);
2323
2336
  }, _d.onError = function (error) {
@@ -2872,6 +2885,20 @@
2872
2885
  };
2873
2886
  });
2874
2887
  }
2888
+ function getEnvFromUrl(url) {
2889
+ if (url.startsWith('https://portal-api.idmission.com')) {
2890
+ return 'prod';
2891
+ } else if (url.startsWith('https://portal-api-uat.idmission.com')) {
2892
+ return 'uat';
2893
+ } else if (url.startsWith('https://portal-api-demo.idmission.com')) {
2894
+ return 'demo';
2895
+ } else if (url.startsWith('https://portal-api-dev.idmission.com')) {
2896
+ return 'dev';
2897
+ } else if (url.startsWith('http://localhost:10000')) {
2898
+ return 'local';
2899
+ }
2900
+ return 'unknown';
2901
+ }
2875
2902
 
2876
2903
  // This could've been more streamlined with internal state instead of abusing
2877
2904
  // refs to such extent, but then composing hooks and components could not opt out of unnecessary renders.