Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update idUtils.ts to allow integer IDs #28

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/cma-client-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "@datocms/cma-client-browser",
"version": "3.3.3",
"description": "Browser client for DatoCMS REST Content Management API",
"keywords": [
"datocms",
"client"
],
"keywords": ["datocms", "client"],
"author": "Stefano Verna <[email protected]>",
"homepage": "https://github.com/datocms/js-rest-api-clients/tree/main/packages/cma-client-browser#readme",
"license": "MIT",
Expand All @@ -16,10 +13,7 @@
"lib": "dist",
"test": "__tests__"
},
"files": [
"dist",
"src"
],
"files": ["dist", "src"],
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 2 additions & 8 deletions packages/cma-client-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "@datocms/cma-client-node",
"version": "3.3.3",
"description": "NodeJS client for DatoCMS REST Content Management API",
"keywords": [
"datocms",
"client"
],
"keywords": ["datocms", "client"],
"author": "Stefano Verna <[email protected]>",
"homepage": "https://github.com/datocms/js-rest-api-clients/tree/main/packages/cma-client-node#readme",
"license": "MIT",
Expand All @@ -16,10 +13,7 @@
"lib": "dist",
"test": "__tests__"
},
"files": [
"dist",
"src"
],
"files": ["dist", "src"],
"publishConfig": {
"access": "public"
},
Expand Down
11 changes: 2 additions & 9 deletions packages/cma-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "@datocms/cma-client",
"version": "3.3.3",
"description": "JS client for DatoCMS REST Content Management API",
"keywords": [
"datocms",
"client"
],
"keywords": ["datocms", "client"],
"author": "Stefano Verna <[email protected]>",
"homepage": "https://github.com/datocms/js-rest-api-clients/tree/main/packages/cma-client#readme",
"license": "MIT",
Expand All @@ -17,11 +14,7 @@
"lib": "dist",
"test": "__tests__"
},
"files": [
"dist",
"src",
"resources.json"
],
"files": ["dist", "src", "resources.json"],
"publishConfig": {
"access": "public"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/cma-client/src/idUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ function fromUrlSafeBase64toUint8Array(urlSafeBase64: string): Uint8Array {
}

export function isValidId(id: string) {
// For backward compatibility, first check to see if this is an older-style integer ID formerly used by Dato
if (/^\d+$/.test(id)) {
const intId = BigInt(id);
const maxDatoIntegerId = 281474976710655; // Max 6-byte/48-bit unsigned int
return intId <= maxDatoIntegerId;
}

const bytes = fromUrlSafeBase64toUint8Array(id);

// UUIDs are 16 bytes
Expand Down
11 changes: 2 additions & 9 deletions packages/dashboard-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "@datocms/dashboard-client",
"version": "3.3.3",
"description": "JS client for DatoCMS REST Content Management API",
"keywords": [
"datocms",
"client"
],
"keywords": ["datocms", "client"],
"author": "Stefano Verna <[email protected]>",
"homepage": "https://github.com/datocms/js-rest-api-clients/tree/main/packages/cma-client#readme",
"license": "MIT",
Expand All @@ -17,11 +14,7 @@
"lib": "dist",
"test": "__tests__"
},
"files": [
"dist",
"src",
"resources.json"
],
"files": ["dist", "src", "resources.json"],
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 2 additions & 8 deletions packages/rest-api-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "@datocms/rest-api-events",
"version": "3.3.3",
"description": "Utilities to receive real-time events from DatoCMS REST APIs",
"keywords": [
"datocms",
"client"
],
"keywords": ["datocms", "client"],
"author": "Stefano Verna <[email protected]>",
"homepage": "https://github.com/datocms/js-rest-api-clients/tree/main/packages/rest-api-events#readme",
"license": "MIT",
Expand All @@ -17,10 +14,7 @@
"lib": "dist",
"test": "__tests__"
},
"files": [
"dist",
"src"
],
"files": ["dist", "src"],
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 2 additions & 8 deletions packages/rest-client-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "@datocms/rest-client-utils",
"version": "3.3.3",
"description": "Utilities for DatoCMS REST API clients",
"keywords": [
"datocms",
"client"
],
"keywords": ["datocms", "client"],
"author": "Stefano Verna <[email protected]>",
"homepage": "https://github.com/datocms/js-rest-api-clients/tree/main/packages/rest-client-utils#readme",
"license": "MIT",
Expand All @@ -17,10 +14,7 @@
"lib": "dist",
"test": "__tests__"
},
"files": [
"dist",
"src"
],
"files": ["dist", "src"],
"publishConfig": {
"access": "public"
},
Expand Down
Loading