Skip to content

Commit

Permalink
Fix uploadTracks.create()
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoverna committed Oct 30, 2024
1 parent a441002 commit 8afc90c
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "3.3.13"
"version": "3.3.14"
}
8 changes: 4 additions & 4 deletions packages/cma-client-browser/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -38,5 +38,5 @@
"bugs": {
"url": "https://github.com/datocms/js-rest-api-clients/issues"
},
"gitHead": "504a80c1a8c628acf6defc5c7ce9c58e777f9ecd"
"gitHead": "ac4164968026ba62a2841d31d2b60c31eadb2cc8"
}
18 changes: 17 additions & 1 deletion packages/cma-client-node/__tests__/upload.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cma-client-node/package-lock.json

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

10 changes: 5 additions & 5 deletions packages/cma-client-node/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -49,5 +49,5 @@
"bugs": {
"url": "https://github.com/datocms/js-rest-api-clients/issues"
},
"gitHead": "504a80c1a8c628acf6defc5c7ce9c58e777f9ecd"
"gitHead": "ac4164968026ba62a2841d31d2b60c31eadb2cc8"
}
2 changes: 1 addition & 1 deletion packages/cma-client/package-lock.json

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

8 changes: 4 additions & 4 deletions packages/cma-client/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
16 changes: 8 additions & 8 deletions packages/cma-client/src/generated/SchemaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions packages/dashboard-client/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion packages/rest-api-events/package-lock.json

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

8 changes: 4 additions & 4 deletions packages/rest-api-events/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
21 changes: 21 additions & 0 deletions packages/rest-client-utils/LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/rest-client-utils/package-lock.json

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

4 changes: 2 additions & 2 deletions packages/rest-client-utils/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"async-scheduler": "^1.4.4"
},
"gitHead": "e802f075911ad9d1c6b861b084edb8f44499a40f",
"gitHead": "ac4164968026ba62a2841d31d2b60c31eadb2cc8",
"devDependencies": {
"@types/qs": "^6.9.7"
}
Expand Down
10 changes: 8 additions & 2 deletions packages/rest-client-utils/src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function serializeRequestBody<T extends { data: unknown } | null>(
} as unknown as T;
}

const { id, meta, ...otherProperties } = body as any;
const { id, type: typeInBody, meta, ...otherProperties } = body as any;

const attributes: Record<string, unknown> = {};
const relationships: Record<string, unknown> = {};
Expand Down Expand Up @@ -111,12 +111,18 @@ export function serializeRequestBody<T extends { data: unknown } | null>(
}
}
}

// '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 } : {}),
Expand Down

0 comments on commit 8afc90c

Please sign in to comment.