@atlaskit/media-client 37.2.36 → 37.3.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 (459) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/dist/cjs/client/file-fetcher/FileFetcherError.js +54 -0
  3. package/dist/cjs/client/file-fetcher/error.js +13 -52
  4. package/dist/cjs/client/file-fetcher/index.js +59 -46
  5. package/dist/cjs/client/file-fetcher/isFileFetcherError.js +10 -0
  6. package/dist/cjs/client/media-client.js +4 -4
  7. package/dist/cjs/client/media-store/MediaStore.js +100 -108
  8. package/dist/cjs/client/media-store/MediaStoreError.js +36 -0
  9. package/dist/cjs/client/media-store/cdnFeatureFlag.js +14 -0
  10. package/dist/cjs/client/media-store/decodeJwtToken.js +9 -0
  11. package/dist/cjs/client/media-store/error.js +13 -34
  12. package/dist/cjs/client/media-store/extendImageParams.js +23 -0
  13. package/dist/cjs/client/media-store/getMediaEnvironment.js +11 -0
  14. package/dist/cjs/client/media-store/getMediaRegion.js +11 -0
  15. package/dist/cjs/client/media-store/getValueFromSessionStorage.js +10 -0
  16. package/dist/cjs/client/media-store/isMediaStoreError.js +10 -0
  17. package/dist/cjs/client/media-store/jsonHeaders.js +10 -0
  18. package/dist/cjs/client/media-store/resolveAuth.js +10 -16
  19. package/dist/cjs/client/media-store/resolveInitialAuth.js +13 -0
  20. package/dist/cjs/client/media-store/setKeyValueInSessionStorage.js +19 -0
  21. package/dist/cjs/client/mobile-upload.js +9 -6
  22. package/dist/cjs/identifier.js +20 -15
  23. package/dist/cjs/index.js +60 -37
  24. package/dist/cjs/is-different-identifier.js +16 -0
  25. package/dist/cjs/is-external-image-identifier.js +9 -0
  26. package/dist/cjs/is-file-identifier.js +9 -0
  27. package/dist/cjs/models/artifacts.js +2 -2
  28. package/dist/cjs/models/errors/BaseMediaClientError.js +43 -0
  29. package/dist/cjs/models/errors/CommonMediaClientError.js +32 -0
  30. package/dist/cjs/models/errors/fromCommonMediaClientError.js +28 -0
  31. package/dist/cjs/models/errors/getMediaClientErrorReason.js +10 -0
  32. package/dist/cjs/models/errors/helpers.js +14 -8
  33. package/dist/cjs/models/errors/index.js +37 -96
  34. package/dist/cjs/models/errors/isCommonMediaClientError.js +17 -0
  35. package/dist/cjs/models/errors/isMediaClientError.js +9 -0
  36. package/dist/cjs/models/errors/toCommonMediaClientError.js +13 -0
  37. package/dist/cjs/models/file-state.js +75 -93
  38. package/dist/cjs/models/has-artifacts.js +9 -0
  39. package/dist/cjs/models/is-error-file-state.js +9 -0
  40. package/dist/cjs/models/is-final-file-state.js +9 -0
  41. package/dist/cjs/models/is-image-representation-ready.js +16 -0
  42. package/dist/cjs/models/is-non-error-final-file-state.js +9 -0
  43. package/dist/cjs/models/is-not-found-media-item-details.js +9 -0
  44. package/dist/cjs/models/is-previewable-file-state.js +10 -0
  45. package/dist/cjs/models/is-previewable-type.js +10 -0
  46. package/dist/cjs/models/is-processed-file-state.js +9 -0
  47. package/dist/cjs/models/is-processing-file-state.js +9 -0
  48. package/dist/cjs/models/is-uploading-file-state.js +9 -0
  49. package/dist/cjs/models/map-media-file-to-file-state.js +59 -0
  50. package/dist/cjs/models/map-media-item-to-file-state.js +18 -0
  51. package/dist/cjs/models/media.js +23 -10
  52. package/dist/cjs/uploader/{error.js → UploaderError.js} +2 -6
  53. package/dist/cjs/uploader/index.js +4 -4
  54. package/dist/cjs/uploader/isUploaderError.js +10 -0
  55. package/dist/cjs/utils/addFileAttrsToUrl.js +24 -0
  56. package/dist/cjs/utils/createBatchLoadingFunc.js +127 -0
  57. package/dist/cjs/utils/createFileDataLoader.js +1 -170
  58. package/dist/cjs/utils/createFileDataloader-2.js +15 -0
  59. package/dist/cjs/utils/getAttrsFromUrl.js +41 -0
  60. package/dist/cjs/utils/getItemsFromKeys.js +50 -0
  61. package/dist/cjs/utils/isCDNEnabled.js +15 -0
  62. package/dist/cjs/utils/isMediaBlobUrl.js +10 -0
  63. package/dist/cjs/utils/isPathBasedEnabled.js +14 -0
  64. package/dist/cjs/utils/mapRetryUrlToPathBasedUrl.js +24 -0
  65. package/dist/cjs/utils/mapToMediaCdnUrl.js +38 -0
  66. package/dist/cjs/utils/mapToPathBasedUrl.js +32 -0
  67. package/dist/cjs/utils/mediaCdn.js +2 -40
  68. package/dist/cjs/utils/mediaSubscribable/createMediaSubscribable.js +11 -0
  69. package/dist/cjs/utils/mediaSubscribable/fromObservable.js +13 -5
  70. package/dist/cjs/utils/mobileUpload/{error.js → MobileUploadError.js} +2 -6
  71. package/dist/cjs/utils/mobileUpload/{helpers.js → createMobileDownloadFileStream.js} +8 -18
  72. package/dist/cjs/utils/mobileUpload/createMobileFileStateSubject.js +16 -0
  73. package/dist/cjs/utils/mobileUpload/isMobileUploadError.js +10 -0
  74. package/dist/cjs/utils/mobileUpload/stateMachine/createMobileUploadService.js +10 -0
  75. package/dist/cjs/utils/mobileUpload/stateMachine/{index.js → createMobileUploadStateMachine.js} +8 -12
  76. package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +3 -3
  77. package/dist/cjs/utils/objectToQueryString.js +17 -0
  78. package/dist/cjs/utils/overrideMediaTypeIfUnknown.js +2 -2
  79. package/dist/cjs/utils/pathBasedUrl.js +2 -49
  80. package/dist/cjs/utils/polling/PollingError.js +36 -0
  81. package/dist/cjs/utils/polling/errors.js +13 -34
  82. package/dist/cjs/utils/polling/index.js +11 -6
  83. package/dist/cjs/utils/polling/isPollingError.js +10 -0
  84. package/dist/cjs/utils/rejectTimeout.js +11 -0
  85. package/dist/cjs/utils/request/RequestError.js +56 -0
  86. package/dist/cjs/utils/request/cloneRequestError.js +17 -0
  87. package/dist/cjs/utils/request/createMapResponseToBlob.js +43 -0
  88. package/dist/cjs/utils/request/createMapResponseToJson.js +43 -0
  89. package/dist/cjs/utils/request/createProcessFetchResponse.js +16 -0
  90. package/dist/cjs/utils/request/createRequestErrorFromResponse.js +20 -0
  91. package/dist/cjs/utils/request/createRequestErrorReason.js +30 -0
  92. package/dist/cjs/utils/request/createUrl.js +31 -0
  93. package/dist/cjs/utils/request/defaultShouldRetryError.js +12 -0
  94. package/dist/cjs/utils/request/errors.js +13 -54
  95. package/dist/cjs/utils/request/extendHeaders.js +21 -0
  96. package/dist/cjs/utils/request/extendTraceContext.js +16 -0
  97. package/dist/cjs/utils/request/extractMediaHeaders.js +15 -0
  98. package/dist/cjs/utils/request/fetchRetry.js +120 -0
  99. package/dist/cjs/utils/request/getStatusCode.js +11 -0
  100. package/dist/cjs/utils/request/helpers.js +198 -313
  101. package/dist/cjs/utils/request/index.js +36 -20
  102. package/dist/cjs/utils/request/isAbortedRequestError.js +9 -0
  103. package/dist/cjs/utils/request/isFetchNetworkError.js +10 -0
  104. package/dist/cjs/utils/request/isRateLimitedError.js +11 -0
  105. package/dist/cjs/utils/request/isRequestError.js +10 -0
  106. package/dist/cjs/utils/request/mapAuthToRequestHeaders.js +22 -0
  107. package/dist/cjs/utils/request/waitPromise.js +11 -0
  108. package/dist/cjs/utils/{setTimeoutPromise.js → resolveTimeout.js} +1 -6
  109. package/dist/cjs/utils/url.js +43 -63
  110. package/dist/es2019/client/file-fetcher/FileFetcherError.js +34 -0
  111. package/dist/es2019/client/file-fetcher/error.js +9 -37
  112. package/dist/es2019/client/file-fetcher/index.js +32 -17
  113. package/dist/es2019/client/file-fetcher/isFileFetcherError.js +4 -0
  114. package/dist/es2019/client/media-client.js +1 -1
  115. package/dist/es2019/client/media-store/MediaStore.js +35 -59
  116. package/dist/es2019/client/media-store/MediaStoreError.js +19 -0
  117. package/dist/es2019/client/media-store/cdnFeatureFlag.js +8 -0
  118. package/dist/es2019/client/media-store/decodeJwtToken.js +3 -0
  119. package/dist/es2019/client/media-store/error.js +9 -22
  120. package/dist/es2019/client/media-store/extendImageParams.js +14 -0
  121. package/dist/es2019/client/media-store/getMediaEnvironment.js +5 -0
  122. package/dist/es2019/client/media-store/getMediaRegion.js +5 -0
  123. package/dist/es2019/client/media-store/getValueFromSessionStorage.js +4 -0
  124. package/dist/es2019/client/media-store/isMediaStoreError.js +4 -0
  125. package/dist/es2019/client/media-store/jsonHeaders.js +4 -0
  126. package/dist/es2019/client/media-store/resolveAuth.js +2 -8
  127. package/dist/es2019/client/media-store/resolveInitialAuth.js +7 -0
  128. package/dist/es2019/client/media-store/setKeyValueInSessionStorage.js +13 -0
  129. package/dist/es2019/client/mobile-upload.js +5 -2
  130. package/dist/es2019/identifier.js +14 -14
  131. package/dist/es2019/index.js +31 -8
  132. package/dist/es2019/is-different-identifier.js +9 -0
  133. package/dist/es2019/is-external-image-identifier.js +3 -0
  134. package/dist/es2019/is-file-identifier.js +3 -0
  135. package/dist/es2019/models/artifacts.js +1 -1
  136. package/dist/es2019/models/errors/BaseMediaClientError.js +23 -0
  137. package/dist/es2019/models/errors/CommonMediaClientError.js +13 -0
  138. package/dist/es2019/models/errors/fromCommonMediaClientError.js +20 -0
  139. package/dist/es2019/models/errors/getMediaClientErrorReason.js +4 -0
  140. package/dist/es2019/models/errors/helpers.js +10 -6
  141. package/dist/es2019/models/errors/index.js +27 -72
  142. package/dist/es2019/models/errors/isCommonMediaClientError.js +11 -0
  143. package/dist/es2019/models/errors/isMediaClientError.js +3 -0
  144. package/dist/es2019/models/errors/toCommonMediaClientError.js +8 -0
  145. package/dist/es2019/models/file-state.js +46 -79
  146. package/dist/es2019/models/has-artifacts.js +1 -0
  147. package/dist/es2019/models/is-error-file-state.js +1 -0
  148. package/dist/es2019/models/is-final-file-state.js +1 -0
  149. package/dist/es2019/models/is-image-representation-ready.js +10 -0
  150. package/dist/es2019/models/is-non-error-final-file-state.js +1 -0
  151. package/dist/es2019/models/is-not-found-media-item-details.js +3 -0
  152. package/dist/es2019/models/is-previewable-file-state.js +2 -0
  153. package/dist/es2019/models/is-previewable-type.js +4 -0
  154. package/dist/es2019/models/is-processed-file-state.js +1 -0
  155. package/dist/es2019/models/is-processing-file-state.js +1 -0
  156. package/dist/es2019/models/is-uploading-file-state.js +1 -0
  157. package/dist/es2019/models/map-media-file-to-file-state.js +53 -0
  158. package/dist/es2019/models/map-media-item-to-file-state.js +9 -0
  159. package/dist/es2019/models/media.js +12 -8
  160. package/dist/es2019/uploader/{error.js → UploaderError.js} +1 -4
  161. package/dist/es2019/uploader/index.js +3 -3
  162. package/dist/es2019/uploader/isUploaderError.js +4 -0
  163. package/dist/es2019/utils/addFileAttrsToUrl.js +19 -0
  164. package/dist/es2019/utils/createBatchLoadingFunc.js +74 -0
  165. package/dist/es2019/utils/createFileDataLoader.js +1 -122
  166. package/dist/es2019/utils/createFileDataloader-2.js +8 -0
  167. package/dist/es2019/utils/getAttrsFromUrl.js +35 -0
  168. package/dist/es2019/utils/getItemsFromKeys.js +43 -0
  169. package/dist/es2019/utils/isCDNEnabled.js +9 -0
  170. package/dist/es2019/utils/isMediaBlobUrl.js +4 -0
  171. package/dist/es2019/utils/isPathBasedEnabled.js +7 -0
  172. package/dist/es2019/utils/mapRetryUrlToPathBasedUrl.js +17 -0
  173. package/dist/es2019/utils/mapToMediaCdnUrl.js +32 -0
  174. package/dist/es2019/utils/mapToPathBasedUrl.js +25 -0
  175. package/dist/es2019/utils/mediaCdn.js +1 -37
  176. package/dist/es2019/utils/mediaSubscribable/createMediaSubscribable.js +5 -0
  177. package/dist/es2019/utils/mediaSubscribable/fromObservable.js +7 -4
  178. package/dist/es2019/utils/mobileUpload/{error.js → MobileUploadError.js} +1 -4
  179. package/dist/es2019/utils/mobileUpload/{helpers.js → createMobileDownloadFileStream.js} +3 -11
  180. package/dist/es2019/utils/mobileUpload/createMobileFileStateSubject.js +8 -0
  181. package/dist/es2019/utils/mobileUpload/isMobileUploadError.js +4 -0
  182. package/dist/es2019/utils/mobileUpload/stateMachine/createMobileUploadService.js +4 -0
  183. package/dist/es2019/utils/mobileUpload/stateMachine/{index.js → createMobileUploadStateMachine.js} +7 -10
  184. package/dist/es2019/utils/mobileUpload/stateMachine/states/uploading.js +1 -1
  185. package/dist/es2019/utils/objectToQueryString.js +9 -0
  186. package/dist/es2019/utils/overrideMediaTypeIfUnknown.js +1 -1
  187. package/dist/es2019/utils/pathBasedUrl.js +1 -45
  188. package/dist/es2019/utils/polling/PollingError.js +21 -0
  189. package/dist/es2019/utils/polling/errors.js +9 -24
  190. package/dist/es2019/utils/polling/index.js +10 -2
  191. package/dist/es2019/utils/polling/isPollingError.js +4 -0
  192. package/dist/es2019/utils/rejectTimeout.js +3 -0
  193. package/dist/es2019/utils/request/RequestError.js +39 -0
  194. package/dist/es2019/utils/request/cloneRequestError.js +12 -0
  195. package/dist/es2019/utils/request/createMapResponseToBlob.js +15 -0
  196. package/dist/es2019/utils/request/createMapResponseToJson.js +15 -0
  197. package/dist/es2019/utils/request/createProcessFetchResponse.js +10 -0
  198. package/dist/es2019/utils/request/createRequestErrorFromResponse.js +14 -0
  199. package/dist/es2019/utils/request/createRequestErrorReason.js +24 -0
  200. package/dist/es2019/utils/request/createUrl.js +17 -0
  201. package/dist/es2019/utils/request/defaultShouldRetryError.js +6 -0
  202. package/dist/es2019/utils/request/errors.js +9 -42
  203. package/dist/es2019/utils/request/extendHeaders.js +18 -0
  204. package/dist/es2019/utils/request/extendTraceContext.js +5 -0
  205. package/dist/es2019/utils/request/extractMediaHeaders.js +11 -0
  206. package/dist/es2019/utils/request/fetchRetry.js +54 -0
  207. package/dist/es2019/utils/request/getStatusCode.js +5 -0
  208. package/dist/es2019/utils/request/helpers.js +73 -215
  209. package/dist/es2019/utils/request/index.js +25 -4
  210. package/dist/es2019/utils/request/isAbortedRequestError.js +3 -0
  211. package/dist/es2019/utils/request/isFetchNetworkError.js +4 -0
  212. package/dist/es2019/utils/request/isRateLimitedError.js +5 -0
  213. package/dist/es2019/utils/request/isRequestError.js +4 -0
  214. package/dist/es2019/utils/request/mapAuthToRequestHeaders.js +16 -0
  215. package/dist/es2019/utils/request/waitPromise.js +3 -0
  216. package/dist/es2019/utils/resolveTimeout.js +3 -0
  217. package/dist/es2019/utils/url.js +18 -65
  218. package/dist/esm/client/file-fetcher/FileFetcherError.js +47 -0
  219. package/dist/esm/client/file-fetcher/error.js +9 -50
  220. package/dist/esm/client/file-fetcher/index.js +32 -17
  221. package/dist/esm/client/file-fetcher/isFileFetcherError.js +4 -0
  222. package/dist/esm/client/media-client.js +1 -1
  223. package/dist/esm/client/media-store/MediaStore.js +35 -58
  224. package/dist/esm/client/media-store/MediaStoreError.js +29 -0
  225. package/dist/esm/client/media-store/cdnFeatureFlag.js +8 -0
  226. package/dist/esm/client/media-store/decodeJwtToken.js +3 -0
  227. package/dist/esm/client/media-store/error.js +9 -32
  228. package/dist/esm/client/media-store/extendImageParams.js +16 -0
  229. package/dist/esm/client/media-store/getMediaEnvironment.js +5 -0
  230. package/dist/esm/client/media-store/getMediaRegion.js +5 -0
  231. package/dist/esm/client/media-store/getValueFromSessionStorage.js +4 -0
  232. package/dist/esm/client/media-store/isMediaStoreError.js +4 -0
  233. package/dist/esm/client/media-store/jsonHeaders.js +4 -0
  234. package/dist/esm/client/media-store/resolveAuth.js +3 -9
  235. package/dist/esm/client/media-store/resolveInitialAuth.js +7 -0
  236. package/dist/esm/client/media-store/setKeyValueInSessionStorage.js +13 -0
  237. package/dist/esm/client/mobile-upload.js +5 -2
  238. package/dist/esm/identifier.js +14 -14
  239. package/dist/esm/index.js +31 -8
  240. package/dist/esm/is-different-identifier.js +9 -0
  241. package/dist/esm/is-external-image-identifier.js +3 -0
  242. package/dist/esm/is-file-identifier.js +3 -0
  243. package/dist/esm/models/artifacts.js +1 -1
  244. package/dist/esm/models/errors/BaseMediaClientError.js +36 -0
  245. package/dist/esm/models/errors/CommonMediaClientError.js +25 -0
  246. package/dist/esm/models/errors/fromCommonMediaClientError.js +21 -0
  247. package/dist/esm/models/errors/getMediaClientErrorReason.js +4 -0
  248. package/dist/esm/models/errors/helpers.js +10 -6
  249. package/dist/esm/models/errors/index.js +27 -91
  250. package/dist/esm/models/errors/isCommonMediaClientError.js +11 -0
  251. package/dist/esm/models/errors/isMediaClientError.js +3 -0
  252. package/dist/esm/models/errors/toCommonMediaClientError.js +8 -0
  253. package/dist/esm/models/file-state.js +46 -93
  254. package/dist/esm/models/has-artifacts.js +3 -0
  255. package/dist/esm/models/is-error-file-state.js +3 -0
  256. package/dist/esm/models/is-final-file-state.js +3 -0
  257. package/dist/esm/models/is-image-representation-ready.js +10 -0
  258. package/dist/esm/models/is-non-error-final-file-state.js +3 -0
  259. package/dist/esm/models/is-not-found-media-item-details.js +3 -0
  260. package/dist/esm/models/is-previewable-file-state.js +4 -0
  261. package/dist/esm/models/is-previewable-type.js +4 -0
  262. package/dist/esm/models/is-processed-file-state.js +3 -0
  263. package/dist/esm/models/is-processing-file-state.js +3 -0
  264. package/dist/esm/models/is-uploading-file-state.js +3 -0
  265. package/dist/esm/models/map-media-file-to-file-state.js +52 -0
  266. package/dist/esm/models/map-media-item-to-file-state.js +11 -0
  267. package/dist/esm/models/media.js +12 -8
  268. package/dist/esm/uploader/{error.js → UploaderError.js} +2 -5
  269. package/dist/esm/uploader/index.js +3 -3
  270. package/dist/esm/uploader/isUploaderError.js +4 -0
  271. package/dist/esm/utils/addFileAttrsToUrl.js +17 -0
  272. package/dist/esm/utils/createBatchLoadingFunc.js +121 -0
  273. package/dist/esm/utils/createFileDataLoader.js +1 -166
  274. package/dist/esm/utils/createFileDataloader-2.js +8 -0
  275. package/dist/esm/utils/getAttrsFromUrl.js +35 -0
  276. package/dist/esm/utils/getItemsFromKeys.js +43 -0
  277. package/dist/esm/utils/isCDNEnabled.js +9 -0
  278. package/dist/esm/utils/isMediaBlobUrl.js +4 -0
  279. package/dist/esm/utils/isPathBasedEnabled.js +7 -0
  280. package/dist/esm/utils/mapRetryUrlToPathBasedUrl.js +17 -0
  281. package/dist/esm/utils/mapToMediaCdnUrl.js +32 -0
  282. package/dist/esm/utils/mapToPathBasedUrl.js +25 -0
  283. package/dist/esm/utils/mediaCdn.js +1 -37
  284. package/dist/esm/utils/mediaSubscribable/createMediaSubscribable.js +5 -0
  285. package/dist/esm/utils/mediaSubscribable/fromObservable.js +7 -4
  286. package/dist/esm/utils/mobileUpload/{error.js → MobileUploadError.js} +2 -5
  287. package/dist/esm/utils/mobileUpload/{helpers.js → createMobileDownloadFileStream.js} +3 -13
  288. package/dist/esm/utils/mobileUpload/createMobileFileStateSubject.js +10 -0
  289. package/dist/esm/utils/mobileUpload/isMobileUploadError.js +4 -0
  290. package/dist/esm/utils/mobileUpload/stateMachine/createMobileUploadService.js +4 -0
  291. package/dist/esm/utils/mobileUpload/stateMachine/{index.js → createMobileUploadStateMachine.js} +7 -10
  292. package/dist/esm/utils/mobileUpload/stateMachine/states/uploading.js +1 -1
  293. package/dist/esm/utils/objectToQueryString.js +11 -0
  294. package/dist/esm/utils/overrideMediaTypeIfUnknown.js +1 -1
  295. package/dist/esm/utils/pathBasedUrl.js +1 -45
  296. package/dist/esm/utils/polling/PollingError.js +29 -0
  297. package/dist/esm/utils/polling/errors.js +9 -32
  298. package/dist/esm/utils/polling/index.js +10 -2
  299. package/dist/esm/utils/polling/isPollingError.js +4 -0
  300. package/dist/esm/utils/rejectTimeout.js +5 -0
  301. package/dist/esm/utils/request/RequestError.js +49 -0
  302. package/dist/esm/utils/request/cloneRequestError.js +10 -0
  303. package/dist/esm/utils/request/createMapResponseToBlob.js +36 -0
  304. package/dist/esm/utils/request/createMapResponseToJson.js +36 -0
  305. package/dist/esm/utils/request/createProcessFetchResponse.js +10 -0
  306. package/dist/esm/utils/request/createRequestErrorFromResponse.js +13 -0
  307. package/dist/esm/utils/request/createRequestErrorReason.js +24 -0
  308. package/dist/esm/utils/request/createUrl.js +24 -0
  309. package/dist/esm/utils/request/defaultShouldRetryError.js +6 -0
  310. package/dist/esm/utils/request/errors.js +9 -52
  311. package/dist/esm/utils/request/extendHeaders.js +14 -0
  312. package/dist/esm/utils/request/extendTraceContext.js +9 -0
  313. package/dist/esm/utils/request/extractMediaHeaders.js +9 -0
  314. package/dist/esm/utils/request/fetchRetry.js +113 -0
  315. package/dist/esm/utils/request/getStatusCode.js +5 -0
  316. package/dist/esm/utils/request/helpers.js +73 -295
  317. package/dist/esm/utils/request/index.js +25 -4
  318. package/dist/esm/utils/request/isAbortedRequestError.js +3 -0
  319. package/dist/esm/utils/request/isFetchNetworkError.js +4 -0
  320. package/dist/esm/utils/request/isRateLimitedError.js +5 -0
  321. package/dist/esm/utils/request/isRequestError.js +4 -0
  322. package/dist/esm/utils/request/mapAuthToRequestHeaders.js +16 -0
  323. package/dist/esm/utils/request/waitPromise.js +5 -0
  324. package/dist/esm/utils/{setTimeoutPromise.js → resolveTimeout.js} +0 -5
  325. package/dist/esm/utils/url.js +18 -65
  326. package/dist/types/client/file-fetcher/FileFetcherError.d.ts +32 -0
  327. package/dist/types/client/file-fetcher/error.d.ts +9 -33
  328. package/dist/types/client/file-fetcher/index.d.ts +15 -7
  329. package/dist/types/client/file-fetcher/isFileFetcherError.d.ts +2 -0
  330. package/dist/types/client/media-client.d.ts +4 -3
  331. package/dist/types/client/media-store/MediaStore.d.ts +18 -6
  332. package/dist/types/client/media-store/MediaStoreError.d.ts +14 -0
  333. package/dist/types/client/media-store/cdnFeatureFlag.d.ts +1 -0
  334. package/dist/types/client/media-store/decodeJwtToken.d.ts +3 -0
  335. package/dist/types/client/media-store/error.d.ts +9 -15
  336. package/dist/types/client/media-store/extendImageParams.d.ts +2 -0
  337. package/dist/types/client/media-store/getMediaEnvironment.d.ts +1 -0
  338. package/dist/types/client/media-store/getMediaRegion.d.ts +1 -0
  339. package/dist/types/client/media-store/getValueFromSessionStorage.d.ts +1 -0
  340. package/dist/types/client/media-store/isMediaStoreError.d.ts +2 -0
  341. package/dist/types/client/media-store/jsonHeaders.d.ts +1 -0
  342. package/dist/types/client/media-store/resolveAuth.d.ts +0 -1
  343. package/dist/types/client/media-store/resolveInitialAuth.d.ts +2 -0
  344. package/dist/types/client/media-store/setKeyValueInSessionStorage.d.ts +1 -0
  345. package/dist/types/client/mobile-upload.d.ts +1 -1
  346. package/dist/types/identifier.d.ts +12 -3
  347. package/dist/types/index.d.ts +34 -10
  348. package/dist/types/is-different-identifier.d.ts +2 -0
  349. package/dist/types/is-external-image-identifier.d.ts +2 -0
  350. package/dist/types/is-file-identifier.d.ts +2 -0
  351. package/dist/types/models/errors/BaseMediaClientError.d.ts +11 -0
  352. package/dist/types/models/errors/CommonMediaClientError.d.ts +7 -0
  353. package/dist/types/models/errors/fromCommonMediaClientError.d.ts +4 -0
  354. package/dist/types/models/errors/getMediaClientErrorReason.d.ts +2 -0
  355. package/dist/types/models/errors/helpers.d.ts +8 -5
  356. package/dist/types/models/errors/index.d.ts +26 -21
  357. package/dist/types/models/errors/isCommonMediaClientError.d.ts +3 -0
  358. package/dist/types/models/errors/isMediaClientError.d.ts +4 -0
  359. package/dist/types/models/errors/toCommonMediaClientError.d.ts +4 -0
  360. package/dist/types/models/file-state.d.ts +45 -16
  361. package/dist/types/models/has-artifacts.d.ts +4 -0
  362. package/dist/types/models/is-error-file-state.d.ts +2 -0
  363. package/dist/types/models/is-final-file-state.d.ts +2 -0
  364. package/dist/types/models/is-image-representation-ready.d.ts +2 -0
  365. package/dist/types/models/is-non-error-final-file-state.d.ts +2 -0
  366. package/dist/types/models/is-not-found-media-item-details.d.ts +2 -0
  367. package/dist/types/models/is-previewable-file-state.d.ts +3 -0
  368. package/dist/types/models/is-previewable-type.d.ts +2 -0
  369. package/dist/types/models/is-processed-file-state.d.ts +2 -0
  370. package/dist/types/models/is-processing-file-state.d.ts +2 -0
  371. package/dist/types/models/is-uploading-file-state.d.ts +2 -0
  372. package/dist/types/models/map-media-file-to-file-state.d.ts +4 -0
  373. package/dist/types/models/map-media-item-to-file-state.d.ts +3 -0
  374. package/dist/types/models/media.d.ts +8 -2
  375. package/dist/types/uploader/{error.d.ts → UploaderError.d.ts} +12 -13
  376. package/dist/types/uploader/index.d.ts +1 -1
  377. package/dist/types/uploader/isUploaderError.d.ts +2 -0
  378. package/dist/types/utils/addFileAttrsToUrl.d.ts +2 -0
  379. package/dist/types/utils/createBatchLoadingFunc.d.ts +11 -0
  380. package/dist/types/utils/createCopyIntentRegisterationBatcher.d.ts +1 -1
  381. package/dist/types/utils/createFileDataLoader.d.ts +0 -14
  382. package/dist/types/utils/createFileDataloader-2.d.ts +4 -0
  383. package/dist/types/utils/getAttrsFromUrl.d.ts +2 -0
  384. package/dist/types/utils/getItemsFromKeys.d.ts +3 -0
  385. package/dist/types/utils/imageResizeModeToFileImageMode.d.ts +1 -1
  386. package/dist/types/utils/isCDNEnabled.d.ts +1 -0
  387. package/dist/types/utils/isMediaBlobUrl.d.ts +1 -0
  388. package/dist/types/utils/isPathBasedEnabled.d.ts +1 -0
  389. package/dist/types/utils/mapRetryUrlToPathBasedUrl.d.ts +1 -0
  390. package/dist/types/utils/mapToMediaCdnUrl.d.ts +1 -0
  391. package/dist/types/utils/mapToPathBasedUrl.d.ts +1 -0
  392. package/dist/types/utils/mediaCdn.d.ts +1 -2
  393. package/dist/types/utils/mediaSubscribable/createMediaSubscribable.d.ts +3 -0
  394. package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +4 -1
  395. package/dist/types/utils/mobileUpload/{error.d.ts → MobileUploadError.d.ts} +15 -16
  396. package/dist/types/utils/mobileUpload/createMobileDownloadFileStream.d.ts +5 -0
  397. package/dist/types/utils/mobileUpload/{helpers.d.ts → createMobileFileStateSubject.d.ts} +0 -3
  398. package/dist/types/utils/mobileUpload/isMobileUploadError.d.ts +2 -0
  399. package/dist/types/utils/mobileUpload/stateMachine/createMobileUploadService.d.ts +3 -0
  400. package/dist/types/utils/mobileUpload/stateMachine/{index.d.ts → createMobileUploadStateMachine.d.ts} +2 -3
  401. package/dist/types/utils/objectToQueryString.d.ts +3 -0
  402. package/dist/types/utils/pathBasedUrl.d.ts +1 -3
  403. package/dist/types/utils/polling/PollingError.d.ts +10 -0
  404. package/dist/types/utils/polling/errors.d.ts +8 -11
  405. package/dist/types/utils/polling/index.d.ts +8 -1
  406. package/dist/types/utils/polling/isPollingError.d.ts +2 -0
  407. package/dist/types/utils/{setTimeoutPromise.d.ts → rejectTimeout.d.ts} +0 -1
  408. package/dist/types/utils/request/RequestError.d.ts +21 -0
  409. package/dist/types/utils/request/cloneRequestError.d.ts +3 -0
  410. package/dist/types/utils/request/createMapResponseToBlob.d.ts +2 -0
  411. package/dist/types/utils/request/createMapResponseToJson.d.ts +2 -0
  412. package/dist/types/utils/request/createProcessFetchResponse.d.ts +2 -0
  413. package/dist/types/utils/request/createRequestErrorFromResponse.d.ts +3 -0
  414. package/dist/types/utils/request/createRequestErrorReason.d.ts +2 -0
  415. package/dist/types/utils/request/createUrl.d.ts +2 -0
  416. package/dist/types/utils/request/defaultShouldRetryError.d.ts +1 -0
  417. package/dist/types/utils/request/errors.d.ts +8 -22
  418. package/dist/types/utils/request/extendHeaders.d.ts +4 -0
  419. package/dist/types/utils/request/extendTraceContext.d.ts +2 -0
  420. package/dist/types/utils/request/extractMediaHeaders.d.ts +4 -0
  421. package/dist/types/utils/request/fetchRetry.d.ts +2 -0
  422. package/dist/types/utils/request/getStatusCode.d.ts +1 -0
  423. package/dist/types/utils/request/helpers.d.ts +73 -24
  424. package/dist/types/utils/request/index.d.ts +16 -2
  425. package/dist/types/utils/request/isAbortedRequestError.d.ts +1 -0
  426. package/dist/types/utils/request/isFetchNetworkError.d.ts +1 -0
  427. package/dist/types/utils/request/isRateLimitedError.d.ts +1 -0
  428. package/dist/types/utils/request/isRequestError.d.ts +2 -0
  429. package/dist/types/utils/request/mapAuthToRequestHeaders.d.ts +3 -0
  430. package/dist/types/utils/request/waitPromise.d.ts +1 -0
  431. package/dist/types/utils/resolveTimeout.d.ts +1 -0
  432. package/dist/types/utils/url.d.ts +17 -6
  433. package/example-helpers/CardsWrapper.tsx +15 -0
  434. package/example-helpers/FileInput.tsx +20 -0
  435. package/example-helpers/FileStateWrapper.tsx +15 -0
  436. package/example-helpers/FileWrapper.tsx +22 -0
  437. package/example-helpers/Header.tsx +15 -0
  438. package/example-helpers/ImagePreview.tsx +18 -0
  439. package/example-helpers/MetadataWrapper.tsx +15 -0
  440. package/example-helpers/PreviewWrapper.tsx +15 -0
  441. package/example-helpers/Response.tsx +15 -0
  442. package/example-helpers/Row.tsx +15 -0
  443. package/example-helpers/UploadTouchWrapper.tsx +15 -0
  444. package/example-helpers/Wrapper.tsx +15 -0
  445. package/package.json +2 -2
  446. package/dist/cjs/client/media-store/index.js +0 -37
  447. package/dist/cjs/utils/mediaSubscribable/index.js +0 -25
  448. package/dist/cjs/utils/mobileUpload/index.js +0 -45
  449. package/dist/es2019/client/media-store/index.js +0 -2
  450. package/dist/es2019/utils/mediaSubscribable/index.js +0 -2
  451. package/dist/es2019/utils/mobileUpload/index.js +0 -4
  452. package/dist/es2019/utils/setTimeoutPromise.js +0 -6
  453. package/dist/esm/client/media-store/index.js +0 -2
  454. package/dist/esm/utils/mediaSubscribable/index.js +0 -2
  455. package/dist/esm/utils/mobileUpload/index.js +0 -4
  456. package/dist/types/client/media-store/index.d.ts +0 -4
  457. package/dist/types/utils/mediaSubscribable/index.d.ts +0 -3
  458. package/dist/types/utils/mobileUpload/index.d.ts +0 -5
  459. package/example-helpers/stylesWrapper.tsx +0 -98
@@ -1,16 +1,20 @@
1
+ /* eslint-disable @repo/internal/deprecations/deprecation-ticket-required -- VOLTC-139 tracks removal of these deprecated re-export shims. */
2
+
1
3
  // Warning! You can't add new media file processing status!
2
4
  // See packages/media/media-core/src/__tests__/cache-backward-compatibility.spec.ts
3
5
 
4
- export const isPreviewableType = type => {
5
- const defaultPreviewableTypes = ['audio', 'video', 'image', 'doc'];
6
- return defaultPreviewableTypes.indexOf(type) > -1;
7
- };
8
- export const isNotFoundMediaItemDetails = itemDetails => {
9
- return 'type' in itemDetails && itemDetails.type === 'not-found';
10
- };
11
6
  export let DATA_UNIT = /*#__PURE__*/function (DATA_UNIT) {
12
7
  DATA_UNIT[DATA_UNIT["MB"] = 1048576] = "MB";
13
8
  DATA_UNIT[DATA_UNIT["GB"] = 1073741824] = "GB";
14
9
  DATA_UNIT[DATA_UNIT["TB"] = 1099511627776] = "TB";
15
10
  return DATA_UNIT;
16
- }({});
11
+ }({});
12
+
13
+ /**
14
+ * @deprecated Use `import { isPreviewableType } from '@atlaskit/media-client'` instead.
15
+ */
16
+ export { isPreviewableType } from './is-previewable-type';
17
+ /**
18
+ * @deprecated Use `import { isNotFoundMediaItemDetails } from '@atlaskit/media-client/media'` instead.
19
+ */
20
+ export { isNotFoundMediaItemDetails } from './is-not-found-media-item-details';
@@ -1,4 +1,4 @@
1
- import { BaseMediaClientError } from '../models/errors';
1
+ import { BaseMediaClientError } from '../models/errors/BaseMediaClientError';
2
2
  export class UploaderError extends BaseMediaClientError {
3
3
  // Legacy Attribute. Should be removed
4
4
 
@@ -25,7 +25,4 @@ export class UploaderError extends BaseMediaClientError {
25
25
  occurrenceKey
26
26
  };
27
27
  }
28
- }
29
- export function isUploaderError(err) {
30
- return err instanceof UploaderError;
31
28
  }
@@ -1,9 +1,9 @@
1
- import { chunkinator } from '@atlaskit/chunkinator';
2
1
  import { from } from 'rxjs/observable/from';
3
2
  import { concatMap } from 'rxjs/operators/concatMap';
4
- import { createHasher } from '../utils/hashing/hasherCreator';
5
- import { UploaderError } from './error';
3
+ import { chunkinator } from '@atlaskit/chunkinator';
6
4
  import { CHUNK_SIZE, PROCESSING_BATCH_SIZE } from '../constants';
5
+ import { createHasher } from '../utils/hashing/hasherCreator';
6
+ import { UploaderError } from './UploaderError';
7
7
  import { calculateChunkSize, fileSizeError } from './calculateChunkSize';
8
8
 
9
9
  // TODO: Allow to pass multiple files
@@ -0,0 +1,4 @@
1
+ import { UploaderError } from './UploaderError';
2
+ export function isUploaderError(err) {
3
+ return err instanceof UploaderError;
4
+ }
@@ -0,0 +1,19 @@
1
+ import { objectToQueryString } from './objectToQueryString';
2
+ import { mediaBlobUrlIdentifier } from './url';
3
+ export const addFileAttrsToUrl = (url, fileAttrs) => {
4
+ const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
5
+ if (isSafari) {
6
+ return url;
7
+ }
8
+ const mediaIdentifierAttr = {
9
+ [mediaBlobUrlIdentifier]: 'true'
10
+ };
11
+ const mergedAttrs = {
12
+ ...mediaIdentifierAttr,
13
+ ...fileAttrs
14
+ };
15
+ const queryAttrs = objectToQueryString(mergedAttrs);
16
+
17
+ // we can't use '?' separator for blob url params
18
+ return `${url}#${queryAttrs}`;
19
+ };
@@ -0,0 +1,74 @@
1
+ import { getRandomTelemetryId } from '@atlaskit/media-common';
2
+ import { getItemsFromKeys } from './getItemsFromKeys';
3
+
4
+ /**
5
+ * Returns a function that, given Array<DataloaderKey>, resolves to an array of same length containing either DataloaderResult or Error.
6
+ * Such contract is formalised by Dataloader 1.0, @see https://github.com/graphql/dataloader
7
+ *
8
+ * If an Error is resolved in the results, it must be at same position then their corresponding key:
9
+ * - Dataloader will re-throw that Error when accessing/loading that particular key
10
+ *
11
+ * @param mediaStore instance of MediaStore
12
+ */
13
+ export function createBatchLoadingFunc(mediaStore) {
14
+ return async keys => {
15
+ const nonCollectionName = '__media-single-file-collection__';
16
+ const includeHashByCollection = keys.reduce((acc, key) => {
17
+ const collectionName = key.collectionName || nonCollectionName;
18
+ if (key.includeHashForDuplicateFiles) {
19
+ acc[collectionName] = key.includeHashForDuplicateFiles;
20
+ }
21
+ return acc;
22
+ }, {});
23
+ const fileIdsByCollection = keys.reduce((acc, key) => {
24
+ const collectionName = key.collectionName || nonCollectionName;
25
+ const fileIds = acc[collectionName] || [];
26
+
27
+ // de-duplicate ids in collection
28
+ if (fileIds.indexOf(key.id) === -1) {
29
+ fileIds.push(key.id);
30
+ }
31
+ acc[collectionName] = fileIds;
32
+ return acc;
33
+ }, {});
34
+ const items = [];
35
+ await Promise.all(Object.keys(fileIdsByCollection).map(async collectionNameKey => {
36
+ const metadataTraceContext = {
37
+ traceId: getRandomTelemetryId(),
38
+ spanId: getRandomTelemetryId()
39
+ };
40
+ const fileIds = fileIdsByCollection[collectionNameKey];
41
+ const includeHashForDuplicateFiles = includeHashByCollection[collectionNameKey];
42
+ const collectionName = collectionNameKey === nonCollectionName ? undefined : collectionNameKey;
43
+ try {
44
+ const response = await mediaStore.getItems(fileIds, collectionName, metadataTraceContext, includeHashForDuplicateFiles);
45
+ const itemsWithMetadataTraceContext = response.data.items.map(item => ({
46
+ ...item,
47
+ metadataTraceContext
48
+ }));
49
+ items.push(...itemsWithMetadataTraceContext);
50
+
51
+ // add EmptyResponseFileItem for each file ID not included in /items response
52
+ const itemsIds = itemsWithMetadataTraceContext.map(item => item.id);
53
+ const fileIdsNotFound = fileIds.filter(id => !itemsIds.includes(id));
54
+ fileIdsNotFound.forEach(fileId => {
55
+ items.push({
56
+ id: fileId,
57
+ collection: collectionName,
58
+ type: 'not-found',
59
+ metadataTraceContext
60
+ });
61
+ });
62
+ } catch (error) {
63
+ fileIds.forEach(fileId => {
64
+ items.push({
65
+ id: fileId,
66
+ collection: collectionName,
67
+ error: error
68
+ });
69
+ });
70
+ }
71
+ }));
72
+ return getItemsFromKeys(keys, items);
73
+ };
74
+ }
@@ -1,122 +1 @@
1
- import Dataloader from 'dataloader';
2
- import { getRandomTelemetryId } from '@atlaskit/media-common';
3
- export const MAX_BATCH_SIZE = 100;
4
- const isBatchLoadingErrorResult = result => {
5
- return result.error instanceof Error;
6
- };
7
- const isResponseFileItem = fileItem => {
8
- return 'details' in fileItem;
9
- };
10
- const makeCacheKey = (id, collection) => collection ? `${id}-${collection}` : id;
11
- export const getItemsFromKeys = (dataloaderKeys, fileItems) => {
12
- const itemsByKey = fileItems.reduce((prev, fileItem) => {
13
- const {
14
- id,
15
- collection
16
- } = fileItem;
17
- const key = makeCacheKey(id, collection);
18
- if (isBatchLoadingErrorResult(fileItem)) {
19
- prev[key] = fileItem.error;
20
- } else if (isResponseFileItem(fileItem)) {
21
- prev[key] = {
22
- ...fileItem.details,
23
- metadataTraceContext: fileItem.metadataTraceContext
24
- };
25
- } else {
26
- prev[key] = {
27
- id,
28
- collection,
29
- type: 'not-found',
30
- metadataTraceContext: fileItem.metadataTraceContext
31
- };
32
- }
33
- return prev;
34
- }, {});
35
- return dataloaderKeys.map(dataloaderKey => {
36
- const {
37
- id,
38
- collectionName
39
- } = dataloaderKey;
40
- const key = makeCacheKey(id, collectionName);
41
- return itemsByKey[key] || {
42
- id,
43
- type: 'not-found'
44
- };
45
- });
46
- };
47
- /**
48
- * Returns a function that, given Array<DataloaderKey>, resolves to an array of same length containing either DataloaderResult or Error.
49
- * Such contract is formalised by Dataloader 1.0, @see https://github.com/graphql/dataloader
50
- *
51
- * If an Error is resolved in the results, it must be at same position then their corresponding key:
52
- * - Dataloader will re-throw that Error when accessing/loading that particular key
53
- *
54
- * @param mediaStore instance of MediaStore
55
- */
56
- export function createBatchLoadingFunc(mediaStore) {
57
- return async keys => {
58
- const nonCollectionName = '__media-single-file-collection__';
59
- const includeHashByCollection = keys.reduce((acc, key) => {
60
- const collectionName = key.collectionName || nonCollectionName;
61
- if (key.includeHashForDuplicateFiles) {
62
- acc[collectionName] = key.includeHashForDuplicateFiles;
63
- }
64
- return acc;
65
- }, {});
66
- const fileIdsByCollection = keys.reduce((acc, key) => {
67
- const collectionName = key.collectionName || nonCollectionName;
68
- const fileIds = acc[collectionName] || [];
69
-
70
- // de-duplicate ids in collection
71
- if (fileIds.indexOf(key.id) === -1) {
72
- fileIds.push(key.id);
73
- }
74
- acc[collectionName] = fileIds;
75
- return acc;
76
- }, {});
77
- const items = [];
78
- await Promise.all(Object.keys(fileIdsByCollection).map(async collectionNameKey => {
79
- const metadataTraceContext = {
80
- traceId: getRandomTelemetryId(),
81
- spanId: getRandomTelemetryId()
82
- };
83
- const fileIds = fileIdsByCollection[collectionNameKey];
84
- const includeHashForDuplicateFiles = includeHashByCollection[collectionNameKey];
85
- const collectionName = collectionNameKey === nonCollectionName ? undefined : collectionNameKey;
86
- try {
87
- const response = await mediaStore.getItems(fileIds, collectionName, metadataTraceContext, includeHashForDuplicateFiles);
88
- const itemsWithMetadataTraceContext = response.data.items.map(item => ({
89
- ...item,
90
- metadataTraceContext
91
- }));
92
- items.push(...itemsWithMetadataTraceContext);
93
-
94
- // add EmptyResponseFileItem for each file ID not included in /items response
95
- const itemsIds = itemsWithMetadataTraceContext.map(item => item.id);
96
- const fileIdsNotFound = fileIds.filter(id => !itemsIds.includes(id));
97
- fileIdsNotFound.forEach(fileId => {
98
- items.push({
99
- id: fileId,
100
- collection: collectionName,
101
- type: 'not-found',
102
- metadataTraceContext
103
- });
104
- });
105
- } catch (error) {
106
- fileIds.forEach(fileId => {
107
- items.push({
108
- id: fileId,
109
- collection: collectionName,
110
- error: error
111
- });
112
- });
113
- }
114
- }));
115
- return getItemsFromKeys(keys, items);
116
- };
117
- }
118
- export function createFileDataloader(mediaStore) {
119
- return new Dataloader(createBatchLoadingFunc(mediaStore), {
120
- maxBatchSize: MAX_BATCH_SIZE
121
- });
122
- }
1
+ export const MAX_BATCH_SIZE = 100;
@@ -0,0 +1,8 @@
1
+ import Dataloader from 'dataloader';
2
+ import { createBatchLoadingFunc } from './createBatchLoadingFunc';
3
+ import { MAX_BATCH_SIZE } from './createFileDataLoader';
4
+ export function createFileDataloader(mediaStore) {
5
+ return new Dataloader(createBatchLoadingFunc(mediaStore), {
6
+ maxBatchSize: MAX_BATCH_SIZE
7
+ });
8
+ }
@@ -0,0 +1,35 @@
1
+ const getNumberFromParams = (params, name) => {
2
+ const value = params.get(name);
3
+ return typeof value === 'string' && !isNaN(parseInt(value)) ? parseInt(value) : undefined;
4
+ };
5
+ const getStringFromParams = (params, name) => {
6
+ const value = params.get(name);
7
+ if (!value) {
8
+ return;
9
+ }
10
+ return decodeURIComponent(value);
11
+ };
12
+ export const getAttrsFromUrl = blobUrl => {
13
+ const url = new URL(blobUrl);
14
+ const hash = url.hash.replace('#', '');
15
+ const params = new URLSearchParams(hash);
16
+ const id = params.get('id');
17
+ const contextId = params.get('contextId');
18
+ const clientId = params.get('clientId');
19
+ // check if we have the required params (clientId is optional for backwards compatibility)
20
+ if (!id || !contextId) {
21
+ return;
22
+ }
23
+ return {
24
+ id,
25
+ contextId,
26
+ clientId: clientId || undefined,
27
+ collection: getStringFromParams(params, 'collection'),
28
+ alt: getStringFromParams(params, 'alt'),
29
+ height: getNumberFromParams(params, 'height'),
30
+ width: getNumberFromParams(params, 'width'),
31
+ size: getNumberFromParams(params, 'size'),
32
+ name: getStringFromParams(params, 'name'),
33
+ mimeType: getStringFromParams(params, 'mimeType')
34
+ };
35
+ };
@@ -0,0 +1,43 @@
1
+ const isBatchLoadingErrorResult = result => {
2
+ return result.error instanceof Error;
3
+ };
4
+ const isResponseFileItem = fileItem => {
5
+ return 'details' in fileItem;
6
+ };
7
+ const makeCacheKey = (id, collection) => collection ? `${id}-${collection}` : id;
8
+ export const getItemsFromKeys = (dataloaderKeys, fileItems) => {
9
+ const itemsByKey = fileItems.reduce((prev, fileItem) => {
10
+ const {
11
+ id,
12
+ collection
13
+ } = fileItem;
14
+ const key = makeCacheKey(id, collection);
15
+ if (isBatchLoadingErrorResult(fileItem)) {
16
+ prev[key] = fileItem.error;
17
+ } else if (isResponseFileItem(fileItem)) {
18
+ prev[key] = {
19
+ ...fileItem.details,
20
+ metadataTraceContext: fileItem.metadataTraceContext
21
+ };
22
+ } else {
23
+ prev[key] = {
24
+ id,
25
+ collection,
26
+ type: 'not-found',
27
+ metadataTraceContext: fileItem.metadataTraceContext
28
+ };
29
+ }
30
+ return prev;
31
+ }, {});
32
+ return dataloaderKeys.map(dataloaderKey => {
33
+ const {
34
+ id,
35
+ collectionName
36
+ } = dataloaderKey;
37
+ const key = makeCacheKey(id, collectionName);
38
+ return itemsByKey[key] || {
39
+ id,
40
+ type: 'not-found'
41
+ };
42
+ });
43
+ };
@@ -0,0 +1,9 @@
1
+ import { isGoogleCloudPlatform } from '@atlaskit/atlassian-context/cloud-provider';
2
+ import { isIsolatedCloud } from '@atlaskit/atlassian-context/is-isolated-cloud';
3
+ import { isGCPtenant as isGCPtenantInStaging } from '@atlaskit/media-common/mediaEnvUtils';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
5
+ import { isCommercial } from './isCommercial';
6
+ import { isPathBasedEnabled } from './isPathBasedEnabled';
7
+ export function isCDNEnabled() {
8
+ return isCommercial() && !isIsolatedCloud() && !(isGoogleCloudPlatform() || isGCPtenantInStaging()) && fg('platform_media_cdn_delivery') && !isPathBasedEnabled();
9
+ }
@@ -0,0 +1,4 @@
1
+ import { mediaBlobUrlIdentifier } from './url';
2
+ export const isMediaBlobUrl = url => {
3
+ return url.indexOf(`${mediaBlobUrlIdentifier}=true`) > -1;
4
+ };
@@ -0,0 +1,7 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+ import getDocument from './getDocument';
3
+ export function isPathBasedEnabled() {
4
+ var _getDocument, _getDocument$location;
5
+ const isLocalhost = ((_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : (_getDocument$location = _getDocument.location) === null || _getDocument$location === void 0 ? void 0 : _getDocument$location.hostname) === 'localhost';
6
+ return fg('platform_media_path_based_route') && !isLocalhost;
7
+ }
@@ -0,0 +1,17 @@
1
+ import getDocument from './getDocument';
2
+ import { mediaApiPathPrefix } from './pathBasedUrl';
3
+ export function mapRetryUrlToPathBasedUrl(url) {
4
+ var _getDocument$location, _getDocument;
5
+ const parsedUrl = new URL(url);
6
+ parsedUrl.host = (_getDocument$location = (_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.location.host) !== null && _getDocument$location !== void 0 ? _getDocument$location : '';
7
+
8
+ // remove CDN from the URL for retry if it exists
9
+ const pathname = parsedUrl.pathname;
10
+ if (pathname.endsWith('/cdn')) {
11
+ parsedUrl.pathname = pathname.replace('/cdn', '');
12
+ }
13
+ if (!parsedUrl.pathname.startsWith(mediaApiPathPrefix)) {
14
+ parsedUrl.pathname = `${mediaApiPathPrefix}${parsedUrl.pathname}`;
15
+ }
16
+ return parsedUrl;
17
+ }
@@ -0,0 +1,32 @@
1
+ import { isGoogleCloudPlatform } from '@atlaskit/atlassian-context/cloud-provider';
2
+ import { isGCPtenant as isGCPtenantInStaging } from '@atlaskit/media-common/mediaEnvUtils';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
4
+ import { isCDNEnabled } from './isCDNEnabled';
5
+ import { MEDIA_CDN_MAP, MEDIA_TOKEN_LENGTH_LIMIT } from './mediaCdn';
6
+ export function mapToMediaCdnUrl(url, token) {
7
+ var _token$length;
8
+ const tokenLength = (_token$length = token === null || token === void 0 ? void 0 : token.length) !== null && _token$length !== void 0 ? _token$length : 0;
9
+ if (!isCDNEnabled() || tokenLength > MEDIA_TOKEN_LENGTH_LIMIT) {
10
+ return url;
11
+ }
12
+ const isGcpTenant = isGoogleCloudPlatform() || isGCPtenantInStaging();
13
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
14
+ if (!isGcpTenant && fg('platform_media_cdn_delivery') && fg('platform_media_cdn_single_host')) {
15
+ try {
16
+ const parsedUrl = new URL(url);
17
+ const cdnHost = MEDIA_CDN_MAP[parsedUrl.host];
18
+
19
+ // If no mapping is found, return the original URL
20
+ if (!cdnHost) {
21
+ return url;
22
+ }
23
+
24
+ // Replace the host with the CDN host in the original URL
25
+ parsedUrl.host = cdnHost;
26
+ return parsedUrl.toString();
27
+ } catch (error) {
28
+ return url;
29
+ }
30
+ }
31
+ return url;
32
+ }
@@ -0,0 +1,25 @@
1
+ import getDocument from './getDocument';
2
+ import { isPathBasedEnabled } from './isPathBasedEnabled';
3
+ import { mediaApiPathPrefix } from './pathBasedUrl';
4
+ function getRelativeUrl(absoluteUrl) {
5
+ const url = new URL(absoluteUrl);
6
+ return `${url.pathname}${url.search}${url.hash}`;
7
+ }
8
+ export function mapToPathBasedUrl(url) {
9
+ if (isPathBasedEnabled()) {
10
+ var _getDocument;
11
+ const parsedUrl = new URL(url);
12
+ if (!parsedUrl.pathname.startsWith(mediaApiPathPrefix)) {
13
+ parsedUrl.pathname = `${mediaApiPathPrefix}${parsedUrl.pathname}`;
14
+ }
15
+ const location = (_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.location;
16
+
17
+ // in this case we are most likely in SSR / a non browser environment so just return a relative URL
18
+ if (!location) {
19
+ return getRelativeUrl(parsedUrl.toString());
20
+ }
21
+ parsedUrl.host = location.host;
22
+ return parsedUrl.toString();
23
+ }
24
+ return url;
25
+ }
@@ -1,9 +1,3 @@
1
- import { fg } from '@atlaskit/platform-feature-flags';
2
- import { isCommercial } from './isCommercial';
3
- import { isIsolatedCloud } from '@atlaskit/atlassian-context/is-isolated-cloud';
4
- import { isGoogleCloudPlatform } from '@atlaskit/atlassian-context/cloud-provider';
5
- import { isGCPtenant as isGCPtenantInStaging } from '@atlaskit/media-common/mediaEnvUtils';
6
- import { isPathBasedEnabled } from './pathBasedUrl';
7
1
  export const MEDIA_CDN_MAP = {
8
2
  'api.media.atlassian.com': 'media-cdn.atlassian.com',
9
3
  'media.staging.atl-paas.net': 'media-cdn.stg.atlassian.com'
@@ -12,34 +6,4 @@ export const MEDIA_CDN_MAP = {
12
6
  // Cloudfront has a hard limit of 8,192 bytes
13
7
  // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
14
8
  // Assuming other parts of the URL make up a max of ~1000 (in reality it's lower), the token can be ~7000
15
- const MEDIA_TOKEN_LENGTH_LIMIT = 7000;
16
- export function isCDNEnabled() {
17
- return isCommercial() && !isIsolatedCloud() && !(isGoogleCloudPlatform() || isGCPtenantInStaging()) && fg('platform_media_cdn_delivery') && !isPathBasedEnabled();
18
- }
19
- export function mapToMediaCdnUrl(url, token) {
20
- var _token$length;
21
- const tokenLength = (_token$length = token === null || token === void 0 ? void 0 : token.length) !== null && _token$length !== void 0 ? _token$length : 0;
22
- if (!isCDNEnabled() || tokenLength > MEDIA_TOKEN_LENGTH_LIMIT) {
23
- return url;
24
- }
25
- const isGcpTenant = isGoogleCloudPlatform() || isGCPtenantInStaging();
26
- // eslint-disable-next-line @atlaskit/platform/no-preconditioning
27
- if (!isGcpTenant && fg('platform_media_cdn_delivery') && fg('platform_media_cdn_single_host')) {
28
- try {
29
- const parsedUrl = new URL(url);
30
- const cdnHost = MEDIA_CDN_MAP[parsedUrl.host];
31
-
32
- // If no mapping is found, return the original URL
33
- if (!cdnHost) {
34
- return url;
35
- }
36
-
37
- // Replace the host with the CDN host in the original URL
38
- parsedUrl.host = cdnHost;
39
- return parsedUrl.toString();
40
- } catch (error) {
41
- return url;
42
- }
43
- }
44
- return url;
45
- }
9
+ export const MEDIA_TOKEN_LENGTH_LIMIT = 7000;
@@ -0,0 +1,5 @@
1
+ import { createMediaSubject } from '../createMediaSubject';
2
+ import { fromObservable } from './fromObservable';
3
+ export function createMediaSubscribable(item) {
4
+ return fromObservable(createMediaSubject(item));
5
+ }
@@ -1,4 +1,5 @@
1
- import { createMediaSubject } from '../createMediaSubject';
1
+ /* eslint-disable @repo/internal/deprecations/deprecation-ticket-required -- VOLTC-139 tracks removal of these deprecated re-export shims. */
2
+
2
3
  export function fromObservable(observable) {
3
4
  return {
4
5
  subscribe: observer => {
@@ -14,6 +15,8 @@ export function fromObservable(observable) {
14
15
  }
15
16
  };
16
17
  }
17
- export function createMediaSubscribable(item) {
18
- return fromObservable(createMediaSubject(item));
19
- }
18
+
19
+ /**
20
+ * @deprecated Use `import { createMediaSubscribable } from '@atlaskit/media-client'` instead.
21
+ */
22
+ export { createMediaSubscribable } from './createMediaSubscribable';
@@ -1,4 +1,4 @@
1
- import { BaseMediaClientError } from '../../models/errors';
1
+ import { BaseMediaClientError } from '../../models/errors/BaseMediaClientError';
2
2
  export class MobileUploadError extends BaseMediaClientError {
3
3
  // Legacy Attribute. Should be removed
4
4
 
@@ -29,7 +29,4 @@ export class MobileUploadError extends BaseMediaClientError {
29
29
  }
30
30
  };
31
31
  }
32
- }
33
- export function isMobileUploadError(err) {
34
- return err instanceof MobileUploadError;
35
32
  }
@@ -1,17 +1,9 @@
1
- import { ReplaySubject } from 'rxjs/ReplaySubject';
2
- import { from } from 'rxjs/observable/from';
3
- import { map } from 'rxjs/operators/map';
4
- import { mapMediaItemToFileState } from '../../models/file-state';
1
+ import { isNotFoundMediaItemDetails } from '../../models/is-not-found-media-item-details';
2
+ import { mapMediaItemToFileState } from '../../models/map-media-item-to-file-state';
5
3
  import { createMediaSubject } from '../createMediaSubject';
6
4
  import { isEmptyFile } from '../detectEmptyFile';
7
5
  import { PollingFunction } from '../polling';
8
- import { MobileUploadError } from './error';
9
- import { isNotFoundMediaItemDetails } from '../../models/media';
10
- export const createMobileFileStateSubject = service => {
11
- const subject = new ReplaySubject(1);
12
- from(service.start()).pipe(map(state => state.context.currentFileState)).subscribe(subject);
13
- return subject;
14
- };
6
+ import { MobileUploadError } from './MobileUploadError';
15
7
  export const createMobileDownloadFileStream = (dataloader, id, collectionName, occurrenceKey) => {
16
8
  const subject = createMediaSubject();
17
9
  const poll = new PollingFunction();
@@ -0,0 +1,8 @@
1
+ import { from } from 'rxjs/observable/from';
2
+ import { map } from 'rxjs/operators/map';
3
+ import { ReplaySubject } from 'rxjs/ReplaySubject';
4
+ export const createMobileFileStateSubject = service => {
5
+ const subject = new ReplaySubject(1);
6
+ from(service.start()).pipe(map(state => state.context.currentFileState)).subscribe(subject);
7
+ return subject;
8
+ };
@@ -0,0 +1,4 @@
1
+ import { MobileUploadError } from './MobileUploadError';
2
+ export function isMobileUploadError(err) {
3
+ return err instanceof MobileUploadError;
4
+ }
@@ -0,0 +1,4 @@
1
+ import { interpret } from 'xstate';
2
+ export function createMobileUploadService(machine) {
3
+ return interpret(machine);
4
+ }
@@ -1,13 +1,13 @@
1
1
  import { map } from 'rxjs/operators/map';
2
- import { createMachine, interpret } from 'xstate';
3
- import { isProcessingFileState } from '../../../models/file-state';
2
+ import { createMachine } from 'xstate';
3
+ import { isProcessingFileState } from '../../../models/is-processing-file-state';
4
4
  import { shouldFetchRemoteFileStates } from '../../shouldFetchRemoteFileStates';
5
- import { createMobileDownloadFileStream } from '../helpers';
6
- import { machineUploadingState } from './states/uploading';
7
- import { machineProcessingState } from './states/processing';
5
+ import { createMobileDownloadFileStream } from '../createMobileDownloadFileStream';
6
+ import { machineErrorState } from './states/error';
8
7
  import { machineProcessedState } from './states/processed';
8
+ import { machineProcessingState } from './states/processing';
9
9
  import { machineProcessingFailedState } from './states/processingFailed';
10
- import { machineErrorState } from './states/error';
10
+ import { machineUploadingState } from './states/uploading';
11
11
  export const createMobileUploadStateMachine = (dataloader, initialState, collectionName) => createMachine({
12
12
  // Initial state
13
13
  initial: initialState.status,
@@ -44,7 +44,4 @@ export const createMobileUploadStateMachine = (dataloader, initialState, collect
44
44
  fileState
45
45
  })))
46
46
  }
47
- });
48
- export function createMobileUploadService(machine) {
49
- return interpret(machine);
50
- }
47
+ });
@@ -1,5 +1,5 @@
1
1
  import { assign } from 'xstate';
2
- import { isUploadingFileState } from '../../../../models/file-state';
2
+ import { isUploadingFileState } from '../../../../models/is-uploading-file-state';
3
3
  export const machineUploadingState = {
4
4
  // Events
5
5
  on: {
@@ -0,0 +1,9 @@
1
+ export const objectToQueryString = json => {
2
+ return Object.keys(json).filter(attrName => typeof json[attrName] !== 'undefined' && json[attrName] !== null).map(key => {
3
+ const value = json[key];
4
+ if (typeof value === 'undefined' || value === null) {
5
+ return;
6
+ }
7
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value.toString())}`;
8
+ }).join('&');
9
+ };