Skip to content

Commit

Permalink
Merge branch 'master' into fix/dont-use-private-class-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut authored Oct 18, 2023
2 parents a84faf3 + 7dab64a commit 1c81b61
Show file tree
Hide file tree
Showing 24 changed files with 139 additions and 104 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [6.6.1](https://github.com/uploadcare/uploadcare-js-api-clients/compare/v6.6.0...v6.6.1) (2023-05-01)

### Bug Fixes

* **upload-client**: do not use buffer for browser-like bundles to prevent polyfilling by cdn ([#484](https://github.com/uploadcare/uploadcare-js-api-clients/pull/484))

# [6.6.0](https://github.com/uploadcare/uploadcare-js-api-clients/compare/v6.5.1...v6.6.0) (2023-05-01)


Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@uploadcare/api-clients",
"private": true,
"type": "module",
"version": "6.6.0",
"version": "6.6.1",
"license": "MIT",
"workspaces": [
"packages/api-client-utils",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uploadcare/api-client-utils",
"version": "6.6.0",
"version": "6.6.1",
"type": "module",
"main": "./dist/cjs/index.browser.cjs",
"module": "./dist/esm/index.browser.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client-utils/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '6.6.0'
export default '6.6.1'
4 changes: 2 additions & 2 deletions packages/rest-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uploadcare/rest-client",
"version": "6.6.0",
"version": "6.6.1",
"description": "Library for work with Uploadcare Rest API",
"type": "module",
"main": "./dist/cjs/index.node.cjs",
Expand Down Expand Up @@ -56,7 +56,7 @@
"devDependencies": {
"@types/blueimp-md5": "^2.18.0",
"@types/node-fetch": "^2.6.2",
"@uploadcare/upload-client": "^6.6.0",
"@uploadcare/upload-client": "^6.6.1",
"ts-node": "^10.8.1"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/rest-client/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '6.6.0'
export default '6.6.1'
2 changes: 1 addition & 1 deletion packages/signed-uploads/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uploadcare/signed-uploads",
"version": "6.6.0",
"version": "6.6.1",
"description": "Library for work with Uploadcare Signed Uploads",
"type": "module",
"main": "./dist/cjs/index.node.cjs",
Expand Down
12 changes: 11 additions & 1 deletion packages/upload-client/mock-server/controllers/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,17 @@ const index = (ctx) => {
})
}

ctx.body = find(json, 'info')
const response = find(json, 'info') as (typeof json)['info']
response.files = files.map((file) => {
const uuid = file.split('/')[0]
const effects = file.split('/-/')[1] ?? ''
return {
...response.files[0],
uuid,
default_effects: effects.replace(/^-\//, '')
}
})
ctx.body = response
}

/**
Expand Down
29 changes: 2 additions & 27 deletions packages/upload-client/mock-server/data/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,8 @@ export default {
datetime_original: '2018-08-20T08:59:50',
dpi: [72, 72]
},
mime_type: 'image/jpeg'
},
{
is_stored: false,
done: 2667636,
file_id: 'd3275f8b-686d-4980-916a-53a1fc17450b',
total: 2667636,
size: 2667636,
uuid: 'd3275f8b-686d-4980-916a-53a1fc17450b',
is_image: true,
filename: 'newFileName.jpg',
video_info: null,
is_ready: true,
original_filename: 'newFileName.jpg',
image_info: {
orientation: 6,
format: 'JPEG',
height: 4032,
width: 3024,
geo_location: {
latitude: 55.62013611111111,
longitude: 37.66299166666666
},
datetime_original: '2018-08-20T08:59:50',
dpi: [72, 72]
},
mime_type: 'image/jpeg'
mime_type: 'image/jpeg',
default_effects: ''
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions packages/upload-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uploadcare/upload-client",
"version": "6.6.0",
"version": "6.6.1",
"description": "Library for work with Uploadcare Upload API",
"type": "module",
"module": "./dist/esm/index.node.mjs",
Expand Down Expand Up @@ -90,7 +90,7 @@
"koa-body": "5.0.0",
"mock-socket": "9.0.3",
"start-server-and-test": "1.14.0",
"@uploadcare/api-client-utils": "^6.6.0",
"@uploadcare/api-client-utils": "^6.6.1",
"chalk": "^4.1.2"
},
"dependencies": {
Expand Down
7 changes: 6 additions & 1 deletion packages/upload-client/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ export type FileInfo = {
metadata?: Metadata
}

export type GroupFileInfo = FileInfo & {
defaultEffects: string
}

export type GroupInfo = {
datetimeCreated: string
datetimeStored: string | null
filesCount: string
cdnUrl: string
files: FileInfo[]
// An array may contain null values if a file has been removed.
files: (GroupFileInfo | null)[]
url: string
id: GroupId
}
Expand Down
1 change: 1 addition & 0 deletions packages/upload-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export {
FileInfo,
GroupId,
GroupInfo,
GroupFileInfo,
Token,
Url,
Uuid,
Expand Down
14 changes: 12 additions & 2 deletions packages/upload-client/src/tools/UploadcareFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileInfo, Uuid } from '../api/types'
import { FileInfo, GroupFileInfo, Uuid } from '../api/types'
import {
ContentInfo,
ImageInfo,
Expand All @@ -8,6 +8,11 @@ import {
import getUrl from './getUrl'
import defaultSettings from '../defaultSettings'

function isGroupFileInfo(
fileInfo: FileInfo | GroupFileInfo
): fileInfo is GroupFileInfo {
return 'defaultEffects' in fileInfo
}
export class UploadcareFile {
readonly uuid: Uuid
readonly name: null | string = null
Expand All @@ -23,9 +28,10 @@ export class UploadcareFile {
readonly contentInfo: null | ContentInfo = null
readonly metadata: null | Metadata = null
readonly s3Bucket: null | string = null
readonly defaultEffects: null | string = null

constructor(
fileInfo: FileInfo,
fileInfo: FileInfo | GroupFileInfo,
{
baseCDN = defaultSettings.baseCDN,
fileName
Expand Down Expand Up @@ -57,5 +63,9 @@ export class UploadcareFile {
this.metadata = fileInfo.metadata || null
this.s3Bucket = s3Bucket || null
this.s3Url = s3Url

if (isGroupFileInfo(fileInfo)) {
this.defaultEffects = fileInfo.defaultEffects
}
}
}
24 changes: 17 additions & 7 deletions packages/upload-client/src/tools/UploadcareGroup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GroupId, GroupInfo } from '../api/types'
import { GroupFileInfo, GroupId, GroupInfo } from '../api/types'
import defaultSettings from '../defaultSettings'
import { UploadcareFile } from './UploadcareFile'

export class UploadcareGroup {
Expand All @@ -12,19 +13,28 @@ export class UploadcareGroup {
readonly createdAt: string
readonly storedAt: string | null = null

constructor(groupInfo: GroupInfo, files: UploadcareFile[]) {
constructor(
groupInfo: GroupInfo,
{
baseCDN = defaultSettings.baseCDN
}: {
baseCDN?: string
} = {}
) {
this.uuid = groupInfo.id
this.filesCount = groupInfo.filesCount
this.totalSize = Object.values(groupInfo.files).reduce(
const groupFiles = groupInfo.files.filter(Boolean) as GroupFileInfo[]
this.totalSize = Object.values(groupFiles).reduce(
(acc, file) => acc + file.size,
0
)
this.isStored = !!groupInfo.datetimeStored
this.isImage = !!Object.values(groupInfo.files).filter(
(file) => file.isImage
).length
this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
.length
this.cdnUrl = groupInfo.cdnUrl
this.files = files
this.files = groupFiles.map(
(fileInfo) => new UploadcareFile(fileInfo, { baseCDN })
)
this.createdAt = groupInfo.datetimeCreated
this.storedAt = groupInfo.datetimeStored
}
Expand Down
1 change: 1 addition & 0 deletions packages/upload-client/src/tools/isBuffer.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isBuffer = (data: unknown): data is Buffer => false
2 changes: 2 additions & 0 deletions packages/upload-client/src/tools/isBuffer.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const isBuffer = (data: unknown): data is Buffer =>
data instanceof Buffer
1 change: 1 addition & 0 deletions packages/upload-client/src/tools/isBuffer.react-native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isBuffer = (data: unknown): data is Buffer => false
9 changes: 4 additions & 5 deletions packages/upload-client/src/tools/isFileData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { SupportedFileInput, ReactNativeAsset } from '../types'
import { ReactNativeAsset, SupportedFileInput } from '../types'
import { isBuffer } from './isBuffer.node'

export { isBuffer }

export const isBlob = (data: unknown): data is Blob => {
return typeof Blob !== 'undefined' && data instanceof Blob
Expand All @@ -8,10 +11,6 @@ export const isFile = (data: unknown): data is File => {
return typeof File !== 'undefined' && data instanceof File
}

export const isBuffer = (data: unknown): data is Buffer => {
return typeof Buffer !== 'undefined' && data instanceof Buffer
}

export const isReactNativeAsset = (data: unknown): data is ReactNativeAsset => {
return (
!!data &&
Expand Down
Loading

0 comments on commit 1c81b61

Please sign in to comment.