From 8afc90c9b650265aa1b602487d2eda06632ff8f2 Mon Sep 17 00:00:00 2001 From: Stefano Verna Date: Wed, 30 Oct 2024 13:06:01 +0100 Subject: [PATCH] Fix uploadTracks.create() --- lerna.json | 2 +- packages/cma-client-browser/package.json | 8 +++---- .../cma-client-node/__tests__/upload.test.ts | 18 +++++++++++++++- packages/cma-client-node/package-lock.json | 2 +- packages/cma-client-node/package.json | 10 ++++----- packages/cma-client/package-lock.json | 2 +- packages/cma-client/package.json | 8 +++---- .../cma-client/src/generated/SchemaTypes.ts | 16 +++++++------- packages/dashboard-client/package.json | 6 +++--- packages/rest-api-events/package-lock.json | 2 +- packages/rest-api-events/package.json | 8 +++---- packages/rest-client-utils/LICENSE.md | 21 +++++++++++++++++++ packages/rest-client-utils/package-lock.json | 2 +- packages/rest-client-utils/package.json | 4 ++-- packages/rest-client-utils/src/serialize.ts | 10 +++++++-- 15 files changed, 81 insertions(+), 38 deletions(-) create mode 100644 packages/rest-client-utils/LICENSE.md diff --git a/lerna.json b/lerna.json index 2fedab4e..4c5cc595 100644 --- a/lerna.json +++ b/lerna.json @@ -2,5 +2,5 @@ "packages": [ "packages/*" ], - "version": "3.3.13" + "version": "3.3.14" } diff --git a/packages/cma-client-browser/package.json b/packages/cma-client-browser/package.json index 653a7df6..49f27abf 100644 --- a/packages/cma-client-browser/package.json +++ b/packages/cma-client-browser/package.json @@ -1,6 +1,6 @@ { "name": "@datocms/cma-client-browser", - "version": "3.3.13", + "version": "3.3.14", "description": "Browser client for DatoCMS REST Content Management API", "keywords": [ "datocms", @@ -28,8 +28,8 @@ "url": "git+https://github.com/datocms/js-rest-api-clients.git" }, "dependencies": { - "@datocms/cma-client": "^3.3.12", - "@datocms/rest-client-utils": "^3.3.10" + "@datocms/cma-client": "^3.3.14", + "@datocms/rest-client-utils": "^3.3.14" }, "scripts": { "build": "tsc && tsc --project ./tsconfig.esnext.json && ts-node ./esbuild.ts", @@ -38,5 +38,5 @@ "bugs": { "url": "https://github.com/datocms/js-rest-api-clients/issues" }, - "gitHead": "504a80c1a8c628acf6defc5c7ce9c58e777f9ecd" + "gitHead": "ac4164968026ba62a2841d31d2b60c31eadb2cc8" } diff --git a/packages/cma-client-node/__tests__/upload.test.ts b/packages/cma-client-node/__tests__/upload.test.ts index b1651601..4a363003 100644 --- a/packages/cma-client-node/__tests__/upload.test.ts +++ b/packages/cma-client-node/__tests__/upload.test.ts @@ -1,5 +1,5 @@ import { generateNewCmaClient } from '../../../jest-helpers/generateNewCmaClient'; -import { generateId } from '../../cma-client/src'; +import { ApiError, generateId } from '../../cma-client/src'; describe('upload', () => { it.concurrent('upload local file', async () => { @@ -10,6 +10,22 @@ describe('upload', () => { }); expect(upload.path.endsWith('text.txt')).toBeTruthy(); + + try { + await client.uploadTracks.create(upload, { + url_or_upload_request_id: upload.url, + type: 'subtitles', + language_code: 'it-IT', + }); + } catch (e) { + if (!(e instanceof ApiError)) { + throw e; + } + + if (!e.findError('NOT_A_VIDEO')) { + throw e; + } + } }); it.concurrent('upload remote file', async () => { diff --git a/packages/cma-client-node/package-lock.json b/packages/cma-client-node/package-lock.json index efe37400..638d6d92 100644 --- a/packages/cma-client-node/package-lock.json +++ b/packages/cma-client-node/package-lock.json @@ -1,6 +1,6 @@ { "name": "@datocms/cma-client-node", - "version": "3.3.12", + "version": "3.3.14", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/packages/cma-client-node/package.json b/packages/cma-client-node/package.json index 84ff19c1..8116db7f 100644 --- a/packages/cma-client-node/package.json +++ b/packages/cma-client-node/package.json @@ -1,6 +1,6 @@ { "name": "@datocms/cma-client-node", - "version": "3.3.12", + "version": "3.3.14", "description": "NodeJS client for DatoCMS REST Content Management API", "keywords": [ "datocms", @@ -28,14 +28,14 @@ "url": "git+https://github.com/datocms/js-rest-api-clients.git" }, "dependencies": { - "@datocms/cma-client": "^3.3.12", - "@datocms/rest-client-utils": "^3.3.10", + "@datocms/cma-client": "^3.3.14", + "@datocms/rest-client-utils": "^3.3.14", "got": "^11.8.5", "mime-types": "^2.1.35", "tmp-promise": "^3.0.3" }, "devDependencies": { - "@datocms/dashboard-client": "^3.3.11", + "@datocms/dashboard-client": "^3.3.14", "@types/mime-types": "^2.1.1", "@types/tmp": "^0.2.3", "datocms-structured-text-utils": "^2.0.4", @@ -49,5 +49,5 @@ "bugs": { "url": "https://github.com/datocms/js-rest-api-clients/issues" }, - "gitHead": "504a80c1a8c628acf6defc5c7ce9c58e777f9ecd" + "gitHead": "ac4164968026ba62a2841d31d2b60c31eadb2cc8" } diff --git a/packages/cma-client/package-lock.json b/packages/cma-client/package-lock.json index 9db2af1f..ae6d8eb0 100644 --- a/packages/cma-client/package-lock.json +++ b/packages/cma-client/package-lock.json @@ -1,6 +1,6 @@ { "name": "@datocms/cma-client", - "version": "3.3.12", + "version": "3.3.14", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/packages/cma-client/package.json b/packages/cma-client/package.json index 14bfddb6..4052f754 100644 --- a/packages/cma-client/package.json +++ b/packages/cma-client/package.json @@ -1,6 +1,6 @@ { "name": "@datocms/cma-client", - "version": "3.3.12", + "version": "3.3.14", "description": "JS client for DatoCMS REST Content Management API", "keywords": [ "datocms", @@ -37,12 +37,12 @@ "url": "https://github.com/datocms/js-rest-api-clients/issues" }, "dependencies": { - "@datocms/rest-client-utils": "^3.3.10", + "@datocms/rest-client-utils": "^3.3.14", "uuid": "^9.0.1" }, "devDependencies": { - "@datocms/dashboard-client": "^3.3.11", + "@datocms/dashboard-client": "^3.3.14", "@types/uuid": "^9.0.7" }, - "gitHead": "504a80c1a8c628acf6defc5c7ce9c58e777f9ecd" + "gitHead": "ac4164968026ba62a2841d31d2b60c31eadb2cc8" } diff --git a/packages/cma-client/src/generated/SchemaTypes.ts b/packages/cma-client/src/generated/SchemaTypes.ts index 1e1687c2..e65e67d1 100644 --- a/packages/cma-client/src/generated/SchemaTypes.ts +++ b/packages/cma-client/src/generated/SchemaTypes.ts @@ -7150,7 +7150,7 @@ export type ItemRelationships = { data: ItemTypeData; }; /** - * The entity (account/collaborator/access token/sso user) who created the record. It must be an object with `type` (e.g. 'account') and `id` properties. + * The entity (account/collaborator/access token/sso user) who created the record */ creator?: { data: @@ -7252,7 +7252,7 @@ export type ItemValidateExistingSchema = { data: ItemTypeData; }; /** - * The entity (account/collaborator/access token/sso user) who created the record. It must be an object with `type` (e.g. 'account') and `id` properties. + * The entity (account/collaborator/access token/sso user) who created the record */ creator?: { data: @@ -7287,7 +7287,7 @@ export type ItemValidateNewSchema = { data: ItemTypeData; }; /** - * The entity (account/collaborator/access token/sso user) who created the record. It must be an object with `type` (e.g. 'account') and `id` properties. + * The entity (account/collaborator/access token/sso user) who created the record */ creator?: { data: @@ -7368,7 +7368,7 @@ export type ItemCreateSchema = { data: ItemTypeData; }; /** - * The entity (account/collaborator/access token/sso user) who created the record. It must be an object with `type` (e.g. 'account') and `id` properties. + * The entity (account/collaborator/access token/sso user) who created the record */ creator?: { data: @@ -7483,7 +7483,7 @@ export type ItemUpdateSchema = { data: ItemTypeData; }; /** - * The entity (account/collaborator/access token/sso user) who created the record. It must be an object with `type` (e.g. 'account') and `id` properties. + * The entity (account/collaborator/access token/sso user) who created the record */ creator?: { data: @@ -7862,7 +7862,7 @@ export type ItemVersionRelationships = { data: ItemData; }; /** - * The entity (account/collaborator/access token/sso user) who made this change to the record. It must be an object with `type` (e.g. 'account') and `id` properties. + * The entity (account/collaborator/access token/sso user) who made this change to the record */ editor: { data: @@ -8387,7 +8387,7 @@ export type UploadRelationships = { data: UploadCollectionData | null; }; /** - * The entity (account/collaborator/access token) who created the asset. It must be an object with `type` (e.g. 'account') and `id` properties. + * The entity (account/collaborator/access token) who created the asset */ creator: { data: @@ -8608,7 +8608,7 @@ export type UploadUpdateSchema = { }; relationships?: { /** - * The entity (account/collaborator/access token) who created the asset. It must be an object with `type` (e.g. 'account') and `id` properties. + * The entity (account/collaborator/access token) who created the asset */ creator?: { data: diff --git a/packages/dashboard-client/package.json b/packages/dashboard-client/package.json index 9764bfc6..92495a56 100644 --- a/packages/dashboard-client/package.json +++ b/packages/dashboard-client/package.json @@ -1,6 +1,6 @@ { "name": "@datocms/dashboard-client", - "version": "3.3.11", + "version": "3.3.14", "description": "JS client for DatoCMS REST Content Management API", "keywords": [ "datocms", @@ -37,7 +37,7 @@ "url": "https://github.com/datocms/js-rest-api-clients/issues" }, "dependencies": { - "@datocms/rest-client-utils": "^3.3.10" + "@datocms/rest-client-utils": "^3.3.14" }, - "gitHead": "504a80c1a8c628acf6defc5c7ce9c58e777f9ecd" + "gitHead": "ac4164968026ba62a2841d31d2b60c31eadb2cc8" } diff --git a/packages/rest-api-events/package-lock.json b/packages/rest-api-events/package-lock.json index 5bb39c84..64b08682 100644 --- a/packages/rest-api-events/package-lock.json +++ b/packages/rest-api-events/package-lock.json @@ -1,6 +1,6 @@ { "name": "@datocms/rest-api-events", - "version": "3.3.12", + "version": "3.3.14", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/packages/rest-api-events/package.json b/packages/rest-api-events/package.json index ba73acb0..38521501 100644 --- a/packages/rest-api-events/package.json +++ b/packages/rest-api-events/package.json @@ -1,6 +1,6 @@ { "name": "@datocms/rest-api-events", - "version": "3.3.12", + "version": "3.3.14", "description": "Utilities to receive real-time events from DatoCMS REST APIs", "keywords": [ "datocms", @@ -39,8 +39,8 @@ "pusher-js": "^7.0.6" }, "devDependencies": { - "@datocms/cma-client": "^3.3.12", - "@datocms/dashboard-client": "^3.3.11" + "@datocms/cma-client": "^3.3.14", + "@datocms/dashboard-client": "^3.3.14" }, - "gitHead": "504a80c1a8c628acf6defc5c7ce9c58e777f9ecd" + "gitHead": "ac4164968026ba62a2841d31d2b60c31eadb2cc8" } diff --git a/packages/rest-client-utils/LICENSE.md b/packages/rest-client-utils/LICENSE.md new file mode 100644 index 00000000..e84ea5ac --- /dev/null +++ b/packages/rest-client-utils/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Dato SRL + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/rest-client-utils/package-lock.json b/packages/rest-client-utils/package-lock.json index f2edb582..827719d4 100644 --- a/packages/rest-client-utils/package-lock.json +++ b/packages/rest-client-utils/package-lock.json @@ -1,6 +1,6 @@ { "name": "@datocms/rest-client-utils", - "version": "3.3.10", + "version": "3.3.14", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/packages/rest-client-utils/package.json b/packages/rest-client-utils/package.json index fd39fbbf..f9c136b9 100644 --- a/packages/rest-client-utils/package.json +++ b/packages/rest-client-utils/package.json @@ -1,6 +1,6 @@ { "name": "@datocms/rest-client-utils", - "version": "3.3.10", + "version": "3.3.14", "description": "Utilities for DatoCMS REST API clients", "keywords": [ "datocms", @@ -38,7 +38,7 @@ "dependencies": { "async-scheduler": "^1.4.4" }, - "gitHead": "e802f075911ad9d1c6b861b084edb8f44499a40f", + "gitHead": "ac4164968026ba62a2841d31d2b60c31eadb2cc8", "devDependencies": { "@types/qs": "^6.9.7" } diff --git a/packages/rest-client-utils/src/serialize.ts b/packages/rest-client-utils/src/serialize.ts index 1c0f478f..474760ff 100644 --- a/packages/rest-client-utils/src/serialize.ts +++ b/packages/rest-client-utils/src/serialize.ts @@ -49,7 +49,7 @@ export function serializeRequestBody( } as unknown as T; } - const { id, meta, ...otherProperties } = body as any; + const { id, type: typeInBody, meta, ...otherProperties } = body as any; const attributes: Record = {}; const relationships: Record = {}; @@ -111,12 +111,18 @@ export function serializeRequestBody( } } } + + // 'type' key present in data is always ignored.. + // UNLESS the entity has a `type` attribute + if (options.attributes.includes('type')) { + attributes.type = typeInBody; + } } return { data: { ...(id || options.id ? { id: id || options.id } : {}), - type: options.type, // If a body.type is passed in, it should go in data.attributes. Only options.type should be here at the root. + type: options.type, ...(Object.keys(attributes).length > 0 ? { attributes } : {}), ...(Object.keys(relationships).length > 0 ? { relationships } : {}), ...(meta ? { meta } : {}),