diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e18617..9e6898b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,68 @@ # Change Log +## 17.1.0 + +* Add `upsertDocument` method +* Add `dart-3.8` and `flutter-3.32` runtimes +* Add `gif` image format +* Update bulk operation methods to reflect warning message +* Fix file parameter handling in chunked upload method + ## 17.0.0 -* Add `<REGION>` to doc examples due to the new multi region endpoints +* Add `REGION` to doc examples due to the new multi region endpoints * Add doc examples and methods for bulk api transactions: `createDocuments`, `deleteDocuments` etc. * Add doc examples, class and methods for new `Sites` service * Add doc examples, class and methods for new `Tokens` service -* Add enums for `BuildRuntime `, `Adapter`, `Framework`, `DeploymentDownloadType` and `VCSDeploymentType` +* Add enums for `BuildRuntime`, `Adapter`, `Framework`, `DeploymentDownloadType` and `VCSDeploymentType` * Updates enum for `runtimes` with Pythonml312, Dart219, Flutter327 and Flutter329 * Add `token` param to `getFilePreview` and `getFileView` for File tokens usage * Add `queries` and `search` params to `listMemberships` method -* Removes `search` param from `listExecutions` method \ No newline at end of file +* Removes `search` param from `listExecutions` method + +## 16.0.0 + +* Fix: remove content-type from GET requests +* Update (breaking): min and max params are now optional in `updateFloatAttribute` and `updateIntegerAttribute` methods (changes their positioning in method definition) + +## 15.0.1 + +* Remove titles from all function descriptions +* Fix typing for collection "attribute" key +* Remove unnecessary awaits and asyncs +* Ensure `AppwriteException` response is always string + +## 15.0.0 + +* Fix: pong response & chunked upload + +## 14.2.0 + +* Add new push message parameters + +## 14.1.0 + +* Support updating attribute name and size + +## 14.0.0 + +* Support for Appwrite 1.6 +* Add `key` attribute to `Runtime` response model. +* Add `buildSize` attribute to `Deployments` response model +* Add `scheduledAt` attribute to `Executions` response model +* Add `scopes` attribute to `Functions` response model +* Add `specifications` attribute to `Functions` response model +* Add new response model for `Specifications` +* Add new response model for `Builds` +* Add `createJWT()` : Enables creating a JWT using the `userId` +* Add `listSpecifications()`: Enables listing available runtime specifications +* Add `deleteExecution()` : Enables deleting executions +* Add `updateDeploymentBuild()`: Enables cancelling a deployment +* Add `scheduledAt` parameter to `createExecution()`: Enables creating a delayed execution +* Breaking changes + * Remove `otp` parameter from `deleteMFAAuthenticator`. + * Add `scopes` parameter for create/update function. + * Rename `templateBranch` to `templateVersion` in `createFunction()`. + * Rename `downloadDeployment()` to `getDeploymentDownload()` + +> You can find the new syntax for breaking changes in the [Appwrite API references](https://appwrite.io/docs/references). Select version `1.6.x`. \ No newline at end of file diff --git a/README.md b/README.md index 687a2dc..fe7f3dc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Appwrite Node.js SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-node.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.7.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) diff --git a/docs/examples/databases/upsert-document.md b/docs/examples/databases/upsert-document.md new file mode 100644 index 0000000..fcc62d6 --- /dev/null +++ b/docs/examples/databases/upsert-document.md @@ -0,0 +1,16 @@ +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setSession(''); // The user session to authenticate with + +const databases = new sdk.Databases(client); + +const result = await databases.upsertDocument( + '', // databaseId + '', // collectionId + '', // documentId + {}, // data + ["read("any")"] // permissions (optional) +); diff --git a/docs/examples/databases/upsert-documents.md b/docs/examples/databases/upsert-documents.md index 5b47956..425b7ba 100644 --- a/docs/examples/databases/upsert-documents.md +++ b/docs/examples/databases/upsert-documents.md @@ -10,5 +10,5 @@ const databases = new sdk.Databases(client); const result = await databases.upsertDocuments( '', // databaseId '', // collectionId - [] // documents (optional) + [] // documents ); diff --git a/package.json b/package.json index 1c8ed63..ca074ab 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "node-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "17.0.0", + "version": "17.1.0", "license": "BSD-3-Clause", "main": "dist/index.js", "type": "commonjs", diff --git a/src/client.ts b/src/client.ts index 3682e15..19025c7 100644 --- a/src/client.ts +++ b/src/client.ts @@ -33,7 +33,7 @@ class AppwriteException extends Error { } function getUserAgent() { - let ua = 'AppwriteNodeJSSDK/17.0.0'; + let ua = 'AppwriteNodeJSSDK/17.1.0'; // `process` is a global in Node.js, but not fully available in all runtimes. const platform: string[] = []; @@ -82,7 +82,7 @@ class Client { 'x-sdk-name': 'Node.js', 'x-sdk-platform': 'server', 'x-sdk-language': 'nodejs', - 'x-sdk-version': '17.0.0', + 'x-sdk-version': '17.1.0', 'user-agent' : getUserAgent(), 'X-Appwrite-Response-Format': '1.7.0', }; @@ -266,9 +266,9 @@ class Client { } async chunkedUpload(method: string, url: URL, headers: Headers = {}, originalPayload: Payload = {}, onProgress: (progress: UploadProgress) => void) { - const file = Object.values(originalPayload).find((value) => value instanceof File); + const [fileParam, file] = Object.entries(originalPayload).find(([_, value]) => value instanceof File) ?? []; - if (!file) { + if (!file || !fileParam) { throw new Error('File not found in payload'); } @@ -288,7 +288,8 @@ class Client { headers['content-range'] = `bytes ${start}-${end-1}/${file.size}`; const chunk = file.slice(start, end); - let payload = { ...originalPayload, file: new File([chunk], file.name)}; + let payload = { ...originalPayload }; + payload[fileParam] = new File([chunk], file.name); response = await this.call(method, url, headers, payload); diff --git a/src/enums/build-runtime.ts b/src/enums/build-runtime.ts index a2180ef..9468229 100644 --- a/src/enums/build-runtime.ts +++ b/src/enums/build-runtime.ts @@ -36,6 +36,7 @@ export enum BuildRuntime { Dart31 = 'dart-3.1', Dart33 = 'dart-3.3', Dart35 = 'dart-3.5', + Dart38 = 'dart-3.8', Dotnet60 = 'dotnet-6.0', Dotnet70 = 'dotnet-7.0', Dotnet80 = 'dotnet-8.0', @@ -62,4 +63,5 @@ export enum BuildRuntime { Flutter324 = 'flutter-3.24', Flutter327 = 'flutter-3.27', Flutter329 = 'flutter-3.29', + Flutter332 = 'flutter-3.32', } \ No newline at end of file diff --git a/src/enums/image-format.ts b/src/enums/image-format.ts index 5aad5f0..758fad7 100644 --- a/src/enums/image-format.ts +++ b/src/enums/image-format.ts @@ -5,4 +5,5 @@ export enum ImageFormat { Webp = 'webp', Heic = 'heic', Avif = 'avif', + Gif = 'gif', } \ No newline at end of file diff --git a/src/enums/runtime.ts b/src/enums/runtime.ts index 3955557..6ea5c33 100644 --- a/src/enums/runtime.ts +++ b/src/enums/runtime.ts @@ -36,6 +36,7 @@ export enum Runtime { Dart31 = 'dart-3.1', Dart33 = 'dart-3.3', Dart35 = 'dart-3.5', + Dart38 = 'dart-3.8', Dotnet60 = 'dotnet-6.0', Dotnet70 = 'dotnet-7.0', Dotnet80 = 'dotnet-8.0', @@ -62,4 +63,5 @@ export enum Runtime { Flutter324 = 'flutter-3.24', Flutter327 = 'flutter-3.27', Flutter329 = 'flutter-3.29', + Flutter332 = 'flutter-3.32', } \ No newline at end of file diff --git a/src/services/databases.ts b/src/services/databases.ts index 80d1a6a..4d2f434 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -1660,7 +1660,9 @@ export class Databases { ); } /** - * Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions. + +Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. * * @param {string} databaseId * @param {string} collectionId @@ -1697,8 +1699,9 @@ export class Databases { ); } /** - * Create or update Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions. +Create or update Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. * * @param {string} databaseId * @param {string} collectionId @@ -1706,13 +1709,16 @@ export class Databases { * @throws {AppwriteException} * @returns {Promise>} */ - upsertDocuments(databaseId: string, collectionId: string, documents?: object[]): Promise> { + upsertDocuments(databaseId: string, collectionId: string, documents: object[]): Promise> { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } + if (typeof documents === 'undefined') { + throw new AppwriteException('Missing required parameter: "documents"'); + } const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); const payload: Payload = {}; if (typeof documents !== 'undefined') { @@ -1732,7 +1738,9 @@ export class Databases { ); } /** - * Update all documents that match your queries, if no queries are submitted then all documents are updated. You can pass only specific fields to be updated. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions. + +Update all documents that match your queries, if no queries are submitted then all documents are updated. You can pass only specific fields to be updated. * * @param {string} databaseId * @param {string} collectionId @@ -1770,7 +1778,9 @@ export class Databases { ); } /** - * Bulk delete documents using queries, if no queries are passed then all documents are deleted. + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions. + +Bulk delete documents using queries, if no queries are passed then all documents are deleted. * * @param {string} databaseId * @param {string} collectionId @@ -1840,6 +1850,53 @@ export class Databases { payload, ); } + /** + * **WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions. + +Create or update a Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. + * + * @param {string} databaseId + * @param {string} collectionId + * @param {string} documentId + * @param {object} data + * @param {string[]} permissions + * @throws {AppwriteException} + * @returns {Promise} + */ + upsertDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "collectionId"'); + } + if (typeof documentId === 'undefined') { + throw new AppwriteException('Missing required parameter: "documentId"'); + } + if (typeof data === 'undefined') { + throw new AppwriteException('Missing required parameter: "data"'); + } + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + const payload: Payload = {}; + if (typeof data !== 'undefined') { + payload['data'] = data; + } + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + return this.client.call( + 'put', + uri, + apiHeaders, + payload, + ); + } /** * Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated. * diff --git a/src/services/tokens.ts b/src/services/tokens.ts index 81804ca..61326ac 100644 --- a/src/services/tokens.ts +++ b/src/services/tokens.ts @@ -42,7 +42,7 @@ export class Tokens { ); } /** - * Create a new token. A token is linked to a file. Token can be passed as a header or request get parameter. + * Create a new token. A token is linked to a file. Token can be passed as a request URL search parameter. * * @param {string} bucketId * @param {string} fileId