diff --git a/CHANGELOG.md b/CHANGELOG.md index fe57112..dac266e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 26.1.0 + +* Added: Realtime connections now send the configured JWT for authentication. +* Added: Forwarded `impersonateUserId` on `avatars` and `storage` file requests. +* Fixed: URL-encode path parameters across all services. +* Fixed: `ping` now sends an `Accept: application/json` header. + ## 26.0.0 * Breaking: Renamed `Theme` enum to `BrowserTheme`, changing `avatars.getScreenshot()` `theme` param type. diff --git a/README.md b/README.md index 8044285..4516100 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ import { Client, Account } from "appwrite"; To install with a CDN (content delivery network) add the following scripts to the bottom of your tag, but before you use any Appwrite services: ```html - + ``` diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md index a78197c..1fb3971 100644 --- a/docs/examples/account/create.md +++ b/docs/examples/account/create.md @@ -10,7 +10,7 @@ const account = new Account(client); const result = await account.create({ userId: '', email: 'email@example.com', - password: '', + password: 'password', name: '' // optional }); diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md index 3f87ddc..9918b1d 100644 --- a/docs/examples/account/update-password.md +++ b/docs/examples/account/update-password.md @@ -8,8 +8,8 @@ const client = new Client() const account = new Account(client); const result = await account.updatePassword({ - password: '', - oldPassword: '' // optional + password: 'password', + oldPassword: 'password' // optional }); console.log(result); diff --git a/docs/examples/account/update-recovery.md b/docs/examples/account/update-recovery.md index e08d48c..52da3fb 100644 --- a/docs/examples/account/update-recovery.md +++ b/docs/examples/account/update-recovery.md @@ -10,7 +10,7 @@ const account = new Account(client); const result = await account.updateRecovery({ userId: '', secret: '', - password: '' + password: 'password' }); console.log(result); diff --git a/package-lock.json b/package-lock.json index a3aa13e..2d9dfd0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "appwrite", - "version": "26.0.0", + "version": "26.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "appwrite", - "version": "26.0.0", + "version": "26.1.0", "license": "BSD-3-Clause", "dependencies": { "json-bigint": "1.0.0" diff --git a/package.json b/package.json index b3307c1..432f949 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API", - "version": "26.0.0", + "version": "26.1.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index 15a0357..2ad9169 100644 --- a/src/client.ts +++ b/src/client.ts @@ -382,7 +382,7 @@ class Client { 'x-sdk-name': 'Web', 'x-sdk-platform': 'client', 'x-sdk-language': 'web', - 'x-sdk-version': '26.0.0', + 'x-sdk-version': '26.1.0', 'X-Appwrite-Response-Format': '1.9.5', }; @@ -526,7 +526,7 @@ class Client { /** * Set ImpersonateUserId * - * Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + * Impersonate a user by ID * * @param value string * @@ -540,7 +540,7 @@ class Client { /** * Set ImpersonateUserEmail * - * Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + * Impersonate a user by email * * @param value string * @@ -554,7 +554,7 @@ class Client { /** * Set ImpersonateUserPhone * - * Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + * Impersonate a user by phone * * @param value string * @@ -615,7 +615,11 @@ class Client { const encodedProject = encodeURIComponent((this.config.project as string) ?? ''); // URL carries only the project; channels/queries are sent via subscribe message. - const queryParams = 'project=' + encodedProject; + let queryParams = 'project=' + encodedProject; + + if (this.config.jwt) { + queryParams += '&jwt=' + encodeURIComponent(this.config.jwt as string); + } const url = this.config.endpointRealtime + '/realtime?' + queryParams; @@ -1044,6 +1048,7 @@ class Client { async ping(): Promise { return this.call('GET', new URL(this.config.endpoint + '/ping'), { 'X-Appwrite-Project': this.config.project, + 'accept': 'application/json', }); } diff --git a/src/services/account.ts b/src/services/account.ts index 896931c..9122ef4 100644 --- a/src/services/account.ts +++ b/src/services/account.ts @@ -292,7 +292,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "identityId"'); } - const apiPath = '/account/identities/{identityId}'.replace('{identityId}', identityId); + const apiPath = '/account/identities/{identityId}'.replace('{identityId}', encodeURIComponent(String(identityId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -518,7 +518,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "type"'); } - const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); + const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', encodeURIComponent(String(type))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -572,7 +572,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "type"'); } - const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); + const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', encodeURIComponent(String(type))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -635,7 +635,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "otp"'); } - const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); + const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', encodeURIComponent(String(type))); const payload: Payload = {}; if (typeof otp !== 'undefined') { payload['otp'] = otp; @@ -700,7 +700,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "otp"'); } - const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); + const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', encodeURIComponent(String(type))); const payload: Payload = {}; if (typeof otp !== 'undefined') { payload['otp'] = otp; @@ -758,7 +758,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "type"'); } - const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); + const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', encodeURIComponent(String(type))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -811,7 +811,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "type"'); } - const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); + const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', encodeURIComponent(String(type))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -1986,7 +1986,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "provider"'); } - const apiPath = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider); + const apiPath = '/account/sessions/oauth2/{provider}'.replace('{provider}', encodeURIComponent(String(provider))); const payload: Payload = {}; if (typeof success !== 'undefined') { payload['success'] = success; @@ -2191,7 +2191,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "sessionId"'); } - const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); + const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', encodeURIComponent(String(sessionId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -2244,7 +2244,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "sessionId"'); } - const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); + const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', encodeURIComponent(String(sessionId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -2298,7 +2298,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "sessionId"'); } - const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); + const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', encodeURIComponent(String(sessionId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -2460,7 +2460,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "identifier"'); } - const apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', targetId); + const apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', encodeURIComponent(String(targetId))); const payload: Payload = {}; if (typeof identifier !== 'undefined') { payload['identifier'] = identifier; @@ -2517,7 +2517,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "targetId"'); } - const apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', targetId); + const apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', encodeURIComponent(String(targetId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -2760,7 +2760,7 @@ export class Account { throw new AppwriteException('Missing required parameter: "provider"'); } - const apiPath = '/account/tokens/oauth2/{provider}'.replace('{provider}', provider); + const apiPath = '/account/tokens/oauth2/{provider}'.replace('{provider}', encodeURIComponent(String(provider))); const payload: Payload = {}; if (typeof success !== 'undefined') { payload['success'] = success; diff --git a/src/services/avatars.ts b/src/services/avatars.ts index 9089390..151d112 100644 --- a/src/services/avatars.ts +++ b/src/services/avatars.ts @@ -70,7 +70,7 @@ export class Avatars { throw new AppwriteException('Missing required parameter: "code"'); } - const apiPath = '/avatars/browsers/{code}'.replace('{code}', code); + const apiPath = '/avatars/browsers/{code}'.replace('{code}', encodeURIComponent(String(code))); const payload: Payload = {}; if (typeof width !== 'undefined') { payload['width'] = width; @@ -89,6 +89,7 @@ export class Avatars { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); @@ -152,7 +153,7 @@ export class Avatars { throw new AppwriteException('Missing required parameter: "code"'); } - const apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code); + const apiPath = '/avatars/credit-cards/{code}'.replace('{code}', encodeURIComponent(String(code))); const payload: Payload = {}; if (typeof width !== 'undefined') { payload['width'] = width; @@ -171,6 +172,7 @@ export class Avatars { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); @@ -232,6 +234,7 @@ export class Avatars { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); @@ -295,7 +298,7 @@ export class Avatars { throw new AppwriteException('Missing required parameter: "code"'); } - const apiPath = '/avatars/flags/{code}'.replace('{code}', code); + const apiPath = '/avatars/flags/{code}'.replace('{code}', encodeURIComponent(String(code))); const payload: Payload = {}; if (typeof width !== 'undefined') { payload['width'] = width; @@ -314,6 +317,7 @@ export class Avatars { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); @@ -394,6 +398,7 @@ export class Avatars { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); @@ -480,6 +485,7 @@ export class Avatars { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); @@ -561,6 +567,7 @@ export class Avatars { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); @@ -760,6 +767,7 @@ export class Avatars { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); diff --git a/src/services/databases.ts b/src/services/databases.ts index 7421d14..6a5a781 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -16,6 +16,7 @@ export class Databases { * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). * @throws {AppwriteException} * @returns {Promise} + * @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.listTransactions` instead. */ listTransactions(params?: { queries?: string[] }): Promise; /** @@ -69,6 +70,7 @@ export class Databases { * @param {number} params.ttl - Seconds before the transaction expires. * @throws {AppwriteException} * @returns {Promise} + * @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.createTransaction` instead. */ createTransaction(params?: { ttl?: number }): Promise; /** @@ -123,6 +125,7 @@ export class Databases { * @param {string} params.transactionId - Transaction ID. * @throws {AppwriteException} * @returns {Promise} + * @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.getTransaction` instead. */ getTransaction(params: { transactionId: string }): Promise; /** @@ -153,7 +156,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "transactionId"'); } - const apiPath = '/databases/transactions/{transactionId}'.replace('{transactionId}', transactionId); + const apiPath = '/databases/transactions/{transactionId}'.replace('{transactionId}', encodeURIComponent(String(transactionId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -178,6 +181,7 @@ export class Databases { * @param {boolean} params.rollback - Rollback transaction? * @throws {AppwriteException} * @returns {Promise} + * @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.updateTransaction` instead. */ updateTransaction(params: { transactionId: string, commit?: boolean, rollback?: boolean }): Promise; /** @@ -215,7 +219,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "transactionId"'); } - const apiPath = '/databases/transactions/{transactionId}'.replace('{transactionId}', transactionId); + const apiPath = '/databases/transactions/{transactionId}'.replace('{transactionId}', encodeURIComponent(String(transactionId))); const payload: Payload = {}; if (typeof commit !== 'undefined') { payload['commit'] = commit; @@ -245,6 +249,7 @@ export class Databases { * @param {string} params.transactionId - Transaction ID. * @throws {AppwriteException} * @returns {Promise<{}>} + * @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.deleteTransaction` instead. */ deleteTransaction(params: { transactionId: string }): Promise<{}>; /** @@ -275,7 +280,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "transactionId"'); } - const apiPath = '/databases/transactions/{transactionId}'.replace('{transactionId}', transactionId); + const apiPath = '/databases/transactions/{transactionId}'.replace('{transactionId}', encodeURIComponent(String(transactionId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -299,6 +304,7 @@ export class Databases { * @param {object[]} params.operations - Array of staged operations. * @throws {AppwriteException} * @returns {Promise} + * @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.createOperations` instead. */ createOperations(params: { transactionId: string, operations?: object[] }): Promise; /** @@ -333,7 +339,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "transactionId"'); } - const apiPath = '/databases/transactions/{transactionId}/operations'.replace('{transactionId}', transactionId); + const apiPath = '/databases/transactions/{transactionId}/operations'.replace('{transactionId}', encodeURIComponent(String(transactionId))); const payload: Payload = {}; if (typeof operations !== 'undefined') { payload['operations'] = operations; @@ -415,7 +421,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "collectionId"'); } - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{collectionId}', encodeURIComponent(String(collectionId))); const payload: Payload = {}; if (typeof queries !== 'undefined') { payload['queries'] = queries; @@ -511,7 +517,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "data"'); } - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{collectionId}', encodeURIComponent(String(collectionId))); const payload: Payload = {}; if (typeof documentId !== 'undefined') { payload['documentId'] = documentId; @@ -601,7 +607,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "documentId"'); } - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{collectionId}', encodeURIComponent(String(collectionId))).replace('{documentId}', encodeURIComponent(String(documentId))); const payload: Payload = {}; if (typeof queries !== 'undefined') { payload['queries'] = queries; @@ -688,7 +694,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "documentId"'); } - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{collectionId}', encodeURIComponent(String(collectionId))).replace('{documentId}', encodeURIComponent(String(documentId))); const payload: Payload = {}; if (typeof data !== 'undefined') { payload['data'] = data; @@ -779,7 +785,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "documentId"'); } - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{collectionId}', encodeURIComponent(String(collectionId))).replace('{documentId}', encodeURIComponent(String(documentId))); const payload: Payload = {}; if (typeof data !== 'undefined') { payload['data'] = data; @@ -862,7 +868,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "documentId"'); } - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{collectionId}', encodeURIComponent(String(collectionId))).replace('{documentId}', encodeURIComponent(String(documentId))); const payload: Payload = {}; if (typeof transactionId !== 'undefined') { payload['transactionId'] = transactionId; @@ -953,7 +959,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "attribute"'); } - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute); + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{collectionId}', encodeURIComponent(String(collectionId))).replace('{documentId}', encodeURIComponent(String(documentId))).replace('{attribute}', encodeURIComponent(String(attribute))); const payload: Payload = {}; if (typeof value !== 'undefined') { payload['value'] = value; @@ -1051,7 +1057,7 @@ export class Databases { throw new AppwriteException('Missing required parameter: "attribute"'); } - const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute); + const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{collectionId}', encodeURIComponent(String(collectionId))).replace('{documentId}', encodeURIComponent(String(documentId))).replace('{attribute}', encodeURIComponent(String(attribute))); const payload: Payload = {}; if (typeof value !== 'undefined') { payload['value'] = value; diff --git a/src/services/functions.ts b/src/services/functions.ts index 14864b7..ba9cae1 100644 --- a/src/services/functions.ts +++ b/src/services/functions.ts @@ -56,7 +56,7 @@ export class Functions { throw new AppwriteException('Missing required parameter: "functionId"'); } - const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId); + const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', encodeURIComponent(String(functionId))); const payload: Payload = {}; if (typeof queries !== 'undefined') { payload['queries'] = queries; @@ -140,7 +140,7 @@ export class Functions { throw new AppwriteException('Missing required parameter: "functionId"'); } - const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId); + const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', encodeURIComponent(String(functionId))); const payload: Payload = {}; if (typeof body !== 'undefined') { payload['body'] = body; @@ -220,7 +220,7 @@ export class Functions { throw new AppwriteException('Missing required parameter: "executionId"'); } - const apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); + const apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', encodeURIComponent(String(functionId))).replace('{executionId}', encodeURIComponent(String(executionId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); diff --git a/src/services/messaging.ts b/src/services/messaging.ts index 8b3ef81..0ad9b7f 100644 --- a/src/services/messaging.ts +++ b/src/services/messaging.ts @@ -61,7 +61,7 @@ export class Messaging { throw new AppwriteException('Missing required parameter: "targetId"'); } - const apiPath = '/messaging/topics/{topicId}/subscribers'.replace('{topicId}', topicId); + const apiPath = '/messaging/topics/{topicId}/subscribers'.replace('{topicId}', encodeURIComponent(String(topicId))); const payload: Payload = {}; if (typeof subscriberId !== 'undefined') { payload['subscriberId'] = subscriberId; @@ -129,7 +129,7 @@ export class Messaging { throw new AppwriteException('Missing required parameter: "subscriberId"'); } - const apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replace('{topicId}', topicId).replace('{subscriberId}', subscriberId); + const apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replace('{topicId}', encodeURIComponent(String(topicId))).replace('{subscriberId}', encodeURIComponent(String(subscriberId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); diff --git a/src/services/presences.ts b/src/services/presences.ts index 4667820..254cba6 100644 --- a/src/services/presences.ts +++ b/src/services/presences.ts @@ -118,7 +118,7 @@ export class Presences { throw new AppwriteException('Missing required parameter: "presenceId"'); } - const apiPath = '/presences/{presenceId}'.replace('{presenceId}', presenceId); + const apiPath = '/presences/{presenceId}'.replace('{presenceId}', encodeURIComponent(String(presenceId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -193,7 +193,7 @@ export class Presences { throw new AppwriteException('Missing required parameter: "status"'); } - const apiPath = '/presences/{presenceId}'.replace('{presenceId}', presenceId); + const apiPath = '/presences/{presenceId}'.replace('{presenceId}', encodeURIComponent(String(presenceId))); const payload: Payload = {}; if (typeof status !== 'undefined') { payload['status'] = status; @@ -282,7 +282,7 @@ export class Presences { throw new AppwriteException('Missing required parameter: "presenceId"'); } - const apiPath = '/presences/{presenceId}'.replace('{presenceId}', presenceId); + const apiPath = '/presences/{presenceId}'.replace('{presenceId}', encodeURIComponent(String(presenceId))); const payload: Payload = {}; if (typeof status !== 'undefined') { payload['status'] = status; @@ -353,7 +353,7 @@ export class Presences { throw new AppwriteException('Missing required parameter: "presenceId"'); } - const apiPath = '/presences/{presenceId}'.replace('{presenceId}', presenceId); + const apiPath = '/presences/{presenceId}'.replace('{presenceId}', encodeURIComponent(String(presenceId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); diff --git a/src/services/realtime.ts b/src/services/realtime.ts index 7aebdaa..ebd4131 100644 --- a/src/services/realtime.ts +++ b/src/services/realtime.ts @@ -205,7 +205,12 @@ export class Realtime { } // URL carries only the project; channels/queries are sent via the subscribe message. - const queryParams = `project=${projectId}`; + let queryParams = `project=${projectId}`; + + const jwt = this.client.config.jwt; + if (jwt) { + queryParams += `&jwt=${encodeURIComponent(jwt)}`; + } const endpoint = this.client.config.endpointRealtime !== '' diff --git a/src/services/storage.ts b/src/services/storage.ts index 485f59d..0e4c093 100644 --- a/src/services/storage.ts +++ b/src/services/storage.ts @@ -61,7 +61,7 @@ export class Storage { throw new AppwriteException('Missing required parameter: "bucketId"'); } - const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); + const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', encodeURIComponent(String(bucketId))); const payload: Payload = {}; if (typeof queries !== 'undefined') { payload['queries'] = queries; @@ -159,7 +159,7 @@ export class Storage { throw new AppwriteException('Missing required parameter: "file"'); } - const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); + const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', encodeURIComponent(String(bucketId))); const payload: Payload = {}; if (typeof fileId !== 'undefined') { payload['fileId'] = fileId; @@ -231,7 +231,7 @@ export class Storage { throw new AppwriteException('Missing required parameter: "fileId"'); } - const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', encodeURIComponent(String(bucketId))).replace('{fileId}', encodeURIComponent(String(fileId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -300,7 +300,7 @@ export class Storage { throw new AppwriteException('Missing required parameter: "fileId"'); } - const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', encodeURIComponent(String(bucketId))).replace('{fileId}', encodeURIComponent(String(fileId))); const payload: Payload = {}; if (typeof name !== 'undefined') { payload['name'] = name; @@ -368,7 +368,7 @@ export class Storage { throw new AppwriteException('Missing required parameter: "fileId"'); } - const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', encodeURIComponent(String(bucketId))).replace('{fileId}', encodeURIComponent(String(fileId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -433,7 +433,7 @@ export class Storage { throw new AppwriteException('Missing required parameter: "fileId"'); } - const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', encodeURIComponent(String(bucketId))).replace('{fileId}', encodeURIComponent(String(fileId))); const payload: Payload = {}; if (typeof token !== 'undefined') { payload['token'] = token; @@ -446,6 +446,7 @@ export class Storage { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); @@ -546,7 +547,7 @@ export class Storage { throw new AppwriteException('Missing required parameter: "fileId"'); } - const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', encodeURIComponent(String(bucketId))).replace('{fileId}', encodeURIComponent(String(fileId))); const payload: Payload = {}; if (typeof width !== 'undefined') { payload['width'] = width; @@ -592,6 +593,7 @@ export class Storage { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); @@ -648,7 +650,7 @@ export class Storage { throw new AppwriteException('Missing required parameter: "fileId"'); } - const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', encodeURIComponent(String(bucketId))).replace('{fileId}', encodeURIComponent(String(fileId))); const payload: Payload = {}; if (typeof token !== 'undefined') { payload['token'] = token; @@ -661,6 +663,7 @@ export class Storage { } payload['project'] = this.client.config.project; + payload['impersonateuserid'] = this.client.config.impersonateuserid; for (const [key, value] of Object.entries(Service.flatten(payload))) { uri.searchParams.append(key, value); diff --git a/src/services/tables-db.ts b/src/services/tables-db.ts index 06a034a..f765685 100644 --- a/src/services/tables-db.ts +++ b/src/services/tables-db.ts @@ -153,7 +153,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "transactionId"'); } - const apiPath = '/tablesdb/transactions/{transactionId}'.replace('{transactionId}', transactionId); + const apiPath = '/tablesdb/transactions/{transactionId}'.replace('{transactionId}', encodeURIComponent(String(transactionId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -215,7 +215,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "transactionId"'); } - const apiPath = '/tablesdb/transactions/{transactionId}'.replace('{transactionId}', transactionId); + const apiPath = '/tablesdb/transactions/{transactionId}'.replace('{transactionId}', encodeURIComponent(String(transactionId))); const payload: Payload = {}; if (typeof commit !== 'undefined') { payload['commit'] = commit; @@ -275,7 +275,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "transactionId"'); } - const apiPath = '/tablesdb/transactions/{transactionId}'.replace('{transactionId}', transactionId); + const apiPath = '/tablesdb/transactions/{transactionId}'.replace('{transactionId}', encodeURIComponent(String(transactionId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -333,7 +333,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "transactionId"'); } - const apiPath = '/tablesdb/transactions/{transactionId}/operations'.replace('{transactionId}', transactionId); + const apiPath = '/tablesdb/transactions/{transactionId}/operations'.replace('{transactionId}', encodeURIComponent(String(transactionId))); const payload: Payload = {}; if (typeof operations !== 'undefined') { payload['operations'] = operations; @@ -414,7 +414,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "tableId"'); } - const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows'.replace('{databaseId}', databaseId).replace('{tableId}', tableId); + const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{tableId}', encodeURIComponent(String(tableId))); const payload: Payload = {}; if (typeof queries !== 'undefined') { payload['queries'] = queries; @@ -509,7 +509,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "data"'); } - const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows'.replace('{databaseId}', databaseId).replace('{tableId}', tableId); + const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{tableId}', encodeURIComponent(String(tableId))); const payload: Payload = {}; if (typeof rowId !== 'undefined') { payload['rowId'] = rowId; @@ -598,7 +598,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "rowId"'); } - const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); + const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{tableId}', encodeURIComponent(String(tableId))).replace('{rowId}', encodeURIComponent(String(rowId))); const payload: Payload = {}; if (typeof queries !== 'undefined') { payload['queries'] = queries; @@ -684,7 +684,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "rowId"'); } - const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); + const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{tableId}', encodeURIComponent(String(tableId))).replace('{rowId}', encodeURIComponent(String(rowId))); const payload: Payload = {}; if (typeof data !== 'undefined') { payload['data'] = data; @@ -774,7 +774,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "rowId"'); } - const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); + const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{tableId}', encodeURIComponent(String(tableId))).replace('{rowId}', encodeURIComponent(String(rowId))); const payload: Payload = {}; if (typeof data !== 'undefined') { payload['data'] = data; @@ -856,7 +856,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "rowId"'); } - const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId); + const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{tableId}', encodeURIComponent(String(tableId))).replace('{rowId}', encodeURIComponent(String(rowId))); const payload: Payload = {}; if (typeof transactionId !== 'undefined') { payload['transactionId'] = transactionId; @@ -946,7 +946,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "column"'); } - const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}/{column}/decrement'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId).replace('{column}', column); + const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}/{column}/decrement'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{tableId}', encodeURIComponent(String(tableId))).replace('{rowId}', encodeURIComponent(String(rowId))).replace('{column}', encodeURIComponent(String(column))); const payload: Payload = {}; if (typeof value !== 'undefined') { payload['value'] = value; @@ -1043,7 +1043,7 @@ export class TablesDB { throw new AppwriteException('Missing required parameter: "column"'); } - const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}/{column}/increment'.replace('{databaseId}', databaseId).replace('{tableId}', tableId).replace('{rowId}', rowId).replace('{column}', column); + const apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}/{column}/increment'.replace('{databaseId}', encodeURIComponent(String(databaseId))).replace('{tableId}', encodeURIComponent(String(tableId))).replace('{rowId}', encodeURIComponent(String(rowId))).replace('{column}', encodeURIComponent(String(column))); const payload: Payload = {}; if (typeof value !== 'undefined') { payload['value'] = value; diff --git a/src/services/teams.ts b/src/services/teams.ts index 7d16945..3e15637 100644 --- a/src/services/teams.ts +++ b/src/services/teams.ts @@ -189,7 +189,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "teamId"'); } - const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); + const apiPath = '/teams/{teamId}'.replace('{teamId}', encodeURIComponent(String(teamId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -250,7 +250,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "name"'); } - const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); + const apiPath = '/teams/{teamId}'.replace('{teamId}', encodeURIComponent(String(teamId))); const payload: Payload = {}; if (typeof name !== 'undefined') { payload['name'] = name; @@ -307,7 +307,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "teamId"'); } - const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); + const apiPath = '/teams/{teamId}'.replace('{teamId}', encodeURIComponent(String(teamId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -373,7 +373,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "teamId"'); } - const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); + const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', encodeURIComponent(String(teamId))); const payload: Payload = {}; if (typeof queries !== 'undefined') { payload['queries'] = queries; @@ -477,7 +477,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "roles"'); } - const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); + const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', encodeURIComponent(String(teamId))); const payload: Payload = {}; if (typeof email !== 'undefined') { payload['email'] = email; @@ -557,7 +557,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "membershipId"'); } - const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', encodeURIComponent(String(teamId))).replace('{membershipId}', encodeURIComponent(String(membershipId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -627,7 +627,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "roles"'); } - const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', encodeURIComponent(String(teamId))).replace('{membershipId}', encodeURIComponent(String(membershipId))); const payload: Payload = {}; if (typeof roles !== 'undefined') { payload['roles'] = roles; @@ -692,7 +692,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "membershipId"'); } - const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', encodeURIComponent(String(teamId))).replace('{membershipId}', encodeURIComponent(String(membershipId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -773,7 +773,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "secret"'); } - const apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + const apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', encodeURIComponent(String(teamId))).replace('{membershipId}', encodeURIComponent(String(membershipId))); const payload: Payload = {}; if (typeof userId !== 'undefined') { payload['userId'] = userId; @@ -833,7 +833,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "teamId"'); } - const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); + const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', encodeURIComponent(String(teamId))); const payload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); @@ -894,7 +894,7 @@ export class Teams { throw new AppwriteException('Missing required parameter: "prefs"'); } - const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); + const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', encodeURIComponent(String(teamId))); const payload: Payload = {}; if (typeof prefs !== 'undefined') { payload['prefs'] = prefs;