diff --git a/README.md b/README.md
index 052ed8f..61b5131 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/package.json b/package.json
index a99ef34..6e08d7b 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 abstract and simplify complex and repetitive development tasks behind a very simple REST API",
- "version": "16.0.0-rc.2",
+ "version": "16.0.0-rc.3",
"license": "BSD-3-Clause",
"main": "dist/cjs/sdk.js",
"exports": {
diff --git a/src/client.ts b/src/client.ts
index bd07a32..98cc19f 100644
--- a/src/client.ts
+++ b/src/client.ts
@@ -1,5 +1,4 @@
import { Models } from './models';
-import { Service } from './service';
/**
* Payload type representing a key-value pair with string keys and any values.
@@ -48,7 +47,7 @@ type RealtimeRequest = {
/**
* Realtime event response structure with generic payload type.
*/
-export type RealtimeResponseEvent = {
+type RealtimeResponseEvent = {
/**
* List of event names associated with the response.
*/
@@ -215,7 +214,7 @@ type Realtime = {
/**
* Type representing upload progress information.
*/
-export type UploadProgress = {
+type UploadProgress = {
/**
* Identifier for the upload progress.
*/
@@ -284,6 +283,8 @@ class AppwriteException extends Error {
* Client that handles requests to Appwrite
*/
class Client {
+ static CHUNK_SIZE = 1024 * 1024 * 5;
+
/**
* Holds configuration such as project.
*/
@@ -295,7 +296,6 @@ class Client {
locale: '',
session: '',
};
-
/**
* Custom headers for API requests.
*/
@@ -303,7 +303,7 @@ class Client {
'x-sdk-name': 'Web',
'x-sdk-platform': 'client',
'x-sdk-language': 'web',
- 'x-sdk-version': '16.0.0-rc.2',
+ 'x-sdk-version': '16.0.0-rc.3',
'X-Appwrite-Response-Format': '1.6.0',
};
@@ -350,7 +350,6 @@ class Client {
this.config.project = value;
return this;
}
-
/**
* Set JWT
*
@@ -365,7 +364,6 @@ class Client {
this.config.jwt = value;
return this;
}
-
/**
* Set Locale
*
@@ -378,7 +376,6 @@ class Client {
this.config.locale = value;
return this;
}
-
/**
* Set Session
*
@@ -394,7 +391,6 @@ class Client {
return this;
}
-
private realtime: Realtime = {
socket: undefined,
timeout: undefined,
@@ -578,40 +574,18 @@ class Client {
}
}
- /**
- * Call API endpoint with the specified method, URL, headers, and parameters.
- *
- * @param {string} method - HTTP method (e.g., 'GET', 'POST', 'PUT', 'DELETE').
- * @param {URL} url - The URL of the API endpoint.
- * @param {Headers} headers - Custom headers for the API request.
- * @param {Payload} params - Request parameters.
- * @returns {Promise} - A promise that resolves with the response data.
- *
- * @typedef {Object} Payload - Request payload data.
- * @property {string} key - The key.
- * @property {string} value - The value.
- */
- async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise {
+ prepareRequest(method: string, url: URL, headers: Headers = {}, params: Payload = {}): { uri: string, options: RequestInit } {
method = method.toUpperCase();
-
headers = Object.assign({}, this.headers, headers);
let options: RequestInit = {
method,
headers,
- credentials: 'include'
};
- if (typeof window !== 'undefined' && window.localStorage) {
- const cookieFallback = window.localStorage.getItem('cookieFallback');
- if (cookieFallback) {
- headers['X-Fallback-Cookies'] = cookieFallback;
- }
- }
-
if (method === 'GET') {
- for (const [key, value] of Object.entries(Service.flatten(params))) {
+ for (const [key, value] of Object.entries(Client.flatten(params))) {
url.searchParams.append(key, value);
}
} else {
@@ -621,15 +595,17 @@ class Client {
break;
case 'multipart/form-data':
- let formData = new FormData();
-
- for (const key in params) {
- if (Array.isArray(params[key])) {
- params[key].forEach((value: any) => {
- formData.append(key + '[]', value);
- })
+ const formData = new FormData();
+
+ for (const [key, value] of Object.entries(params)) {
+ if (value instanceof File) {
+ formData.append(key, value, value.name);
+ } else if (Array.isArray(value)) {
+ for (const nestedValue of value) {
+ formData.append(`${key}[]`, nestedValue);
+ }
} else {
- formData.append(key, params[key]);
+ formData.append(key, value);
}
}
@@ -639,45 +615,121 @@ class Client {
}
}
- try {
- let data = null;
- const response = await fetch(url.toString(), options);
+ return { uri: url.toString(), options };
+ }
+
+ async chunkedUpload(method: string, url: URL, headers: Headers = {}, originalPayload: Payload = {}, onProgress: (progress: UploadProgress) => void) {
+ const file = Object.values(originalPayload).find((value) => value instanceof File);
+
+ if (file.size <= Client.CHUNK_SIZE) {
+ return await this.call(method, url, headers, originalPayload);
+ }
+
+ let start = 0;
+ let response = null;
- const warnings = response.headers.get('x-appwrite-warning');
- if (warnings) {
- warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning));
+ while (start < file.size) {
+ let end = start + Client.CHUNK_SIZE; // Prepare end for the next chunk
+ if (end >= file.size) {
+ end = file.size; // Adjust for the last chunk to include the last byte
}
- if (response.headers.get('content-type')?.includes('application/json')) {
- data = await response.json();
- } else {
- data = {
- message: await response.text()
- };
+ headers['content-range'] = `bytes ${start}-${end-1}/${file.size}`;
+ const chunk = file.slice(start, end);
+
+ let payload = { ...originalPayload, file: new File([chunk], file.name)};
+
+ response = await this.call(method, url, headers, payload);
+
+ if (onProgress && typeof onProgress === 'function') {
+ onProgress({
+ $id: response.$id,
+ progress: Math.round((end / file.size) * 100),
+ sizeUploaded: end,
+ chunksTotal: Math.ceil(file.size / Client.CHUNK_SIZE),
+ chunksUploaded: Math.ceil(end / Client.CHUNK_SIZE)
+ });
}
- if (400 <= response.status) {
- throw new AppwriteException(data?.message, response.status, data?.type, data);
+ if (response && response.$id) {
+ headers['x-appwrite-id'] = response.$id;
}
- const cookieFallback = response.headers.get('X-Fallback-Cookies');
+ start = end;
+ }
- if (typeof window !== 'undefined' && window.localStorage && cookieFallback) {
- window.console.warn('Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.');
- window.localStorage.setItem('cookieFallback', cookieFallback);
- }
+ return response;
+ }
+
+ async redirect(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise {
+ const { uri, options } = this.prepareRequest(method, url, headers, params);
+
+ const response = await fetch(uri, {
+ ...options,
+ redirect: 'manual'
+ });
+
+ if (response.status !== 301 && response.status !== 302) {
+ throw new AppwriteException('Invalid redirect', response.status);
+ }
+
+ return response.headers.get('location') || '';
+ }
+
+ async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise {
+ const { uri, options } = this.prepareRequest(method, url, headers, params);
+
+ let data: any = null;
+
+ const response = await fetch(uri, options);
+
+ const warnings = response.headers.get('x-appwrite-warning');
+ if (warnings) {
+ warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning));
+ }
- return data;
- } catch (e) {
- if (e instanceof AppwriteException) {
- throw e;
+ if (response.headers.get('content-type')?.includes('application/json')) {
+ data = await response.json();
+ } else if (responseType === 'arrayBuffer') {
+ data = await response.arrayBuffer();
+ } else {
+ data = {
+ message: await response.text()
+ };
+ }
+
+ if (400 <= response.status) {
+ throw new AppwriteException(data?.message, response.status, data?.type, data);
+ }
+
+ const cookieFallback = response.headers.get('X-Fallback-Cookies');
+
+ if (typeof window !== 'undefined' && window.localStorage && cookieFallback) {
+ window.console.warn('Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.');
+ window.localStorage.setItem('cookieFallback', cookieFallback);
+ }
+
+ return data;
+ }
+
+ static flatten(data: Payload, prefix = ''): Payload {
+ let output: Payload = {};
+
+ for (const [key, value] of Object.entries(data)) {
+ let finalKey = prefix ? prefix + '[' + key +']' : key;
+ if (Array.isArray(value)) {
+ output = { ...output, ...Client.flatten(value, finalKey) };
+ } else {
+ output[finalKey] = value;
}
- throw new AppwriteException((e).message);
}
+
+ return output;
}
}
export { Client, AppwriteException };
export { Query } from './query';
-export type { Models, Payload };
+export type { Models, Payload, UploadProgress };
+export type { RealtimeResponseEvent };
export type { QueryTypes, QueryTypesList } from './query';
diff --git a/src/services/account.ts b/src/services/account.ts
index b9fa27d..3a4717b 100644
--- a/src/services/account.ts
+++ b/src/services/account.ts
@@ -1,17 +1,15 @@
-import { Service } from '../service';
-import { AppwriteException, Client } from '../client';
+import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
-import type { UploadProgress, Payload } from '../client';
import { AuthenticatorType } from '../enums/authenticator-type';
import { AuthenticationFactor } from '../enums/authentication-factor';
import { OAuthProvider } from '../enums/o-auth-provider';
-export class Account extends Service {
+export class Account {
+ client: Client;
- constructor(client: Client)
- {
- super(client);
- }
+ constructor(client: Client) {
+ this.client = client;
+ }
/**
* Get account
@@ -19,117 +17,113 @@ export class Account extends Service {
* Get the currently logged in user.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async get(): Promise> {
const apiPath = '/account';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create account
*
- * Use this endpoint to allow a new user to register a new account in your
- * project. After the user registration completes successfully, you can use
- * the
- * [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification)
- * route to start verifying the user email address. To allow the new user to
- * login to their new account, you need to create a new [account
- * session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession).
+ * Use this endpoint to allow a new user to register a new account in your project. After the user registration completes successfully, you can use the [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) route to start verifying the user email address. To allow the new user to login to their new account, you need to create a new [account session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession).
*
* @param {string} userId
* @param {string} email
* @param {string} password
* @param {string} name
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async create(userId: string, email: string, password: string, name?: string): Promise> {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof email === 'undefined') {
throw new AppwriteException('Missing required parameter: "email"');
}
-
if (typeof password === 'undefined') {
throw new AppwriteException('Missing required parameter: "password"');
}
-
const apiPath = '/account';
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof email !== 'undefined') {
payload['email'] = email;
}
-
if (typeof password !== 'undefined') {
payload['password'] = password;
}
-
if (typeof name !== 'undefined') {
payload['name'] = name;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update email
*
- * Update currently logged in user account email address. After changing user
- * address, the user confirmation status will get reset. A new confirmation
- * email is not sent automatically however you can use the send confirmation
- * email endpoint again to send the confirmation email. For security measures,
- * user password is required to complete this request.
- * This endpoint can also be used to convert an anonymous account to a normal
- * one, by passing an email address and a new password.
- *
+ * Update currently logged in user account email address. After changing user address, the user confirmation status will get reset. A new confirmation email is not sent automatically however you can use the send confirmation email endpoint again to send the confirmation email. For security measures, user password is required to complete this request.
+This endpoint can also be used to convert an anonymous account to a normal one, by passing an email address and a new password.
+
*
* @param {string} email
* @param {string} password
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async updateEmail(email: string, password: string): Promise> {
if (typeof email === 'undefined') {
throw new AppwriteException('Missing required parameter: "email"');
}
-
if (typeof password === 'undefined') {
throw new AppwriteException('Missing required parameter: "password"');
}
-
const apiPath = '/account/email';
const payload: Payload = {};
-
if (typeof email !== 'undefined') {
payload['email'] = email;
}
-
if (typeof password !== 'undefined') {
payload['password'] = password;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* List Identities
*
@@ -137,22 +131,27 @@ export class Account extends Service {
*
* @param {string[]} queries
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listIdentities(queries?: string[]): Promise {
const apiPath = '/account/identities';
const payload: Payload = {};
-
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Delete identity
*
@@ -160,68 +159,79 @@ export class Account extends Service {
*
* @param {string} identityId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async deleteIdentity(identityId: string): Promise<{}> {
if (typeof identityId === 'undefined') {
throw new AppwriteException('Missing required parameter: "identityId"');
}
-
const apiPath = '/account/identities/{identityId}'.replace('{identityId}', identityId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('delete', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'delete',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create JWT
*
- * Use this endpoint to create a JSON Web Token. You can use the resulting JWT
- * to authenticate on behalf of the current user when working with the
- * Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes
- * from its creation and will be invalid if the user will logout in that time
- * frame.
+ * Use this endpoint to create a JSON Web Token. You can use the resulting JWT to authenticate on behalf of the current user when working with the Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes from its creation and will be invalid if the user will logout in that time frame.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createJWT(): Promise {
const apiPath = '/account/jwts';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* List logs
*
- * Get the list of latest security activity logs for the currently logged in
- * user. Each log returns user IP address, location and date and time of log.
+ * Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log.
*
* @param {string[]} queries
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listLogs(queries?: string[]): Promise {
const apiPath = '/account/logs';
const payload: Payload = {};
-
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update MFA
*
@@ -229,86 +239,93 @@ export class Account extends Service {
*
* @param {boolean} mfa
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async updateMFA(mfa: boolean): Promise> {
if (typeof mfa === 'undefined') {
throw new AppwriteException('Missing required parameter: "mfa"');
}
-
const apiPath = '/account/mfa';
const payload: Payload = {};
-
if (typeof mfa !== 'undefined') {
payload['mfa'] = mfa;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create Authenticator
*
- * Add an authenticator app to be used as an MFA factor. Verify the
- * authenticator using the [verify
- * authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator)
- * method.
+ * Add an authenticator app to be used as an MFA factor. Verify the authenticator using the [verify authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) method.
*
* @param {AuthenticatorType} type
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createMfaAuthenticator(type: AuthenticatorType): Promise {
if (typeof type === 'undefined') {
throw new AppwriteException('Missing required parameter: "type"');
}
-
const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Verify Authenticator
*
- * Verify an authenticator app after adding it using the [add
- * authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator)
- * method.
+ * Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.
*
* @param {AuthenticatorType} type
* @param {string} otp
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async updateMfaAuthenticator(type: AuthenticatorType, otp: string): Promise> {
if (typeof type === 'undefined') {
throw new AppwriteException('Missing required parameter: "type"');
}
-
if (typeof otp === 'undefined') {
throw new AppwriteException('Missing required parameter: "otp"');
}
-
const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
const payload: Payload = {};
-
if (typeof otp !== 'undefined') {
payload['otp'] = otp;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Delete Authenticator
*
@@ -316,173 +333,192 @@ export class Account extends Service {
*
* @param {AuthenticatorType} type
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async deleteMfaAuthenticator(type: AuthenticatorType): Promise<{}> {
if (typeof type === 'undefined') {
throw new AppwriteException('Missing required parameter: "type"');
}
-
const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('delete', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'delete',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create MFA Challenge
*
- * Begin the process of MFA verification after sign-in. Finish the flow with
- * [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge)
- * method.
+ * Begin the process of MFA verification after sign-in. Finish the flow with [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) method.
*
* @param {AuthenticationFactor} factor
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createMfaChallenge(factor: AuthenticationFactor): Promise {
if (typeof factor === 'undefined') {
throw new AppwriteException('Missing required parameter: "factor"');
}
-
const apiPath = '/account/mfa/challenge';
const payload: Payload = {};
-
if (typeof factor !== 'undefined') {
payload['factor'] = factor;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create MFA Challenge (confirmation)
*
- * Complete the MFA challenge by providing the one-time password. Finish the
- * process of MFA verification by providing the one-time password. To begin
- * the flow, use
- * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge)
- * method.
+ * Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
* @param {string} challengeId
* @param {string} otp
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async updateMfaChallenge(challengeId: string, otp: string): Promise<{}> {
if (typeof challengeId === 'undefined') {
throw new AppwriteException('Missing required parameter: "challengeId"');
}
-
if (typeof otp === 'undefined') {
throw new AppwriteException('Missing required parameter: "otp"');
}
-
const apiPath = '/account/mfa/challenge';
const payload: Payload = {};
-
if (typeof challengeId !== 'undefined') {
payload['challengeId'] = challengeId;
}
-
if (typeof otp !== 'undefined') {
payload['otp'] = otp;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* List Factors
*
* List the factors available on the account to be used as a MFA challange.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listMfaFactors(): Promise {
const apiPath = '/account/mfa/factors';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Get MFA Recovery Codes
*
- * Get recovery codes that can be used as backup for MFA flow. Before getting
- * codes, they must be generated using
- * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes)
- * method. An OTP challenge is required to read recovery codes.
+ * Get recovery codes that can be used as backup for MFA flow. Before getting codes, they must be generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to read recovery codes.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async getMfaRecoveryCodes(): Promise {
const apiPath = '/account/mfa/recovery-codes';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create MFA Recovery Codes
*
- * Generate recovery codes as backup for MFA flow. It's recommended to
- * generate and show then immediately after user successfully adds their
- * authehticator. Recovery codes can be used as a MFA verification type in
- * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge)
- * method.
+ * Generate recovery codes as backup for MFA flow. It's recommended to generate and show then immediately after user successfully adds their authehticator. Recovery codes can be used as a MFA verification type in [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createMfaRecoveryCodes(): Promise {
const apiPath = '/account/mfa/recovery-codes';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Regenerate MFA Recovery Codes
*
- * Regenerate recovery codes that can be used as backup for MFA flow. Before
- * regenerating codes, they must be first generated using
- * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes)
- * method. An OTP challenge is required to regenreate recovery codes.
+ * Regenerate recovery codes that can be used as backup for MFA flow. Before regenerating codes, they must be first generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to regenreate recovery codes.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updateMfaRecoveryCodes(): Promise {
const apiPath = '/account/mfa/recovery-codes';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update name
*
@@ -490,618 +526,626 @@ export class Account extends Service {
*
* @param {string} name
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async updateName(name: string): Promise> {
if (typeof name === 'undefined') {
throw new AppwriteException('Missing required parameter: "name"');
}
-
const apiPath = '/account/name';
const payload: Payload = {};
-
if (typeof name !== 'undefined') {
payload['name'] = name;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update password
*
- * Update currently logged in user password. For validation, user is required
- * to pass in the new password, and the old password. For users created with
- * OAuth, Team Invites and Magic URL, oldPassword is optional.
+ * Update currently logged in user password. For validation, user is required to pass in the new password, and the old password. For users created with OAuth, Team Invites and Magic URL, oldPassword is optional.
*
* @param {string} password
* @param {string} oldPassword
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async updatePassword(password: string, oldPassword?: string): Promise> {
if (typeof password === 'undefined') {
throw new AppwriteException('Missing required parameter: "password"');
}
-
const apiPath = '/account/password';
const payload: Payload = {};
-
if (typeof password !== 'undefined') {
payload['password'] = password;
}
-
if (typeof oldPassword !== 'undefined') {
payload['oldPassword'] = oldPassword;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update phone
*
- * Update the currently logged in user's phone number. After updating the
- * phone number, the phone verification status will be reset. A confirmation
- * SMS is not sent automatically, however you can use the [POST
- * /account/verification/phone](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification)
- * endpoint to send a confirmation SMS.
+ * Update the currently logged in user's phone number. After updating the phone number, the phone verification status will be reset. A confirmation SMS is not sent automatically, however you can use the [POST /account/verification/phone](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) endpoint to send a confirmation SMS.
*
* @param {string} phone
* @param {string} password
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async updatePhone(phone: string, password: string): Promise> {
if (typeof phone === 'undefined') {
throw new AppwriteException('Missing required parameter: "phone"');
}
-
if (typeof password === 'undefined') {
throw new AppwriteException('Missing required parameter: "password"');
}
-
const apiPath = '/account/phone';
const payload: Payload = {};
-
if (typeof phone !== 'undefined') {
payload['phone'] = phone;
}
-
if (typeof password !== 'undefined') {
payload['password'] = password;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Get account preferences
*
* Get the preferences as a key-value object for the currently logged in user.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async getPrefs(): Promise {
const apiPath = '/account/prefs';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update preferences
*
- * Update currently logged in user account preferences. The object you pass is
- * stored as is, and replaces any previous value. The maximum allowed prefs
- * size is 64kB and throws error if exceeded.
+ * Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 64kB and throws error if exceeded.
*
* @param {Partial} prefs
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async updatePrefs(prefs: Partial): Promise> {
if (typeof prefs === 'undefined') {
throw new AppwriteException('Missing required parameter: "prefs"');
}
-
const apiPath = '/account/prefs';
const payload: Payload = {};
-
if (typeof prefs !== 'undefined') {
payload['prefs'] = prefs;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create password recovery
*
- * Sends the user an email with a temporary secret key for password reset.
- * When the user clicks the confirmation link he is redirected back to your
- * app password reset URL with the secret key and email address values
- * attached to the URL query string. Use the query string params to submit a
- * request to the [PUT
- * /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery)
- * endpoint to complete the process. The verification link sent to the user's
- * email address is valid for 1 hour.
+ * Sends the user an email with a temporary secret key for password reset. When the user clicks the confirmation link he is redirected back to your app password reset URL with the secret key and email address values attached to the URL query string. Use the query string params to submit a request to the [PUT /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) endpoint to complete the process. The verification link sent to the user's email address is valid for 1 hour.
*
* @param {string} email
* @param {string} url
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createRecovery(email: string, url: string): Promise {
if (typeof email === 'undefined') {
throw new AppwriteException('Missing required parameter: "email"');
}
-
if (typeof url === 'undefined') {
throw new AppwriteException('Missing required parameter: "url"');
}
-
const apiPath = '/account/recovery';
const payload: Payload = {};
-
if (typeof email !== 'undefined') {
payload['email'] = email;
}
-
if (typeof url !== 'undefined') {
payload['url'] = url;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create password recovery (confirmation)
*
- * Use this endpoint to complete the user account password reset. Both the
- * **userId** and **secret** arguments will be passed as query parameters to
- * the redirect URL you have provided when sending your request to the [POST
- * /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery)
- * endpoint.
- *
- * Please note that in order to avoid a [Redirect
- * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
- * the only valid redirect URLs are the ones from domains you have set when
- * adding your platforms in the console interface.
+ * Use this endpoint to complete the user account password reset. Both the **userId** and **secret** arguments will be passed as query parameters to the redirect URL you have provided when sending your request to the [POST /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) endpoint.
+
+Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.
*
* @param {string} userId
* @param {string} secret
* @param {string} password
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updateRecovery(userId: string, secret: string, password: string): Promise {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof secret === 'undefined') {
throw new AppwriteException('Missing required parameter: "secret"');
}
-
if (typeof password === 'undefined') {
throw new AppwriteException('Missing required parameter: "password"');
}
-
const apiPath = '/account/recovery';
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof secret !== 'undefined') {
payload['secret'] = secret;
}
-
if (typeof password !== 'undefined') {
payload['password'] = password;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* List sessions
*
- * Get the list of active sessions across different devices for the currently
- * logged in user.
+ * Get the list of active sessions across different devices for the currently logged in user.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listSessions(): Promise {
const apiPath = '/account/sessions';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Delete sessions
*
- * Delete all sessions from the user account and remove any sessions cookies
- * from the end client.
+ * Delete all sessions from the user account and remove any sessions cookies from the end client.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async deleteSessions(): Promise<{}> {
const apiPath = '/account/sessions';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('delete', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'delete',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create anonymous session
*
- * Use this endpoint to allow a new user to register an anonymous account in
- * your project. This route will also create a new session for the user. To
- * allow the new user to convert an anonymous account to a normal account, you
- * need to update its [email and
- * password](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail)
- * or create an [OAuth2
- * session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session).
+ * Use this endpoint to allow a new user to register an anonymous account in your project. This route will also create a new session for the user. To allow the new user to convert an anonymous account to a normal account, you need to update its [email and password](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) or create an [OAuth2 session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session).
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createAnonymousSession(): Promise {
const apiPath = '/account/sessions/anonymous';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create email password session
*
- * Allow the user to login into their account by providing a valid email and
- * password combination. This route will create a new session for the user.
- *
- * A user is limited to 10 active sessions at a time by default. [Learn more
- * about session
- * limits](https://appwrite.io/docs/authentication-security#limits).
+ * Allow the user to login into their account by providing a valid email and password combination. This route will create a new session for the user.
+
+A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).
*
* @param {string} email
* @param {string} password
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createEmailPasswordSession(email: string, password: string): Promise {
if (typeof email === 'undefined') {
throw new AppwriteException('Missing required parameter: "email"');
}
-
if (typeof password === 'undefined') {
throw new AppwriteException('Missing required parameter: "password"');
}
-
const apiPath = '/account/sessions/email';
const payload: Payload = {};
-
if (typeof email !== 'undefined') {
payload['email'] = email;
}
-
if (typeof password !== 'undefined') {
payload['password'] = password;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update magic URL session
*
- * Use this endpoint to create a session from token. Provide the **userId**
- * and **secret** parameters from the successful response of authentication
- * flows initiated by token creation. For example, magic URL and phone login.
+ * Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.
*
* @param {string} userId
* @param {string} secret
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updateMagicURLSession(userId: string, secret: string): Promise {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof secret === 'undefined') {
throw new AppwriteException('Missing required parameter: "secret"');
}
-
const apiPath = '/account/sessions/magic-url';
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof secret !== 'undefined') {
payload['secret'] = secret;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create OAuth2 session
*
- * Allow the user to login to their account using the OAuth2 provider of their
- * choice. Each OAuth2 provider should be enabled from the Appwrite console
- * first. Use the success and failure arguments to provide a redirect URL's
- * back to your app when login is completed.
- *
- * If there is already an active session, the new session will be attached to
- * the logged-in account. If there are no active sessions, the server will
- * attempt to look for a user with the same email address as the email
- * received from the OAuth2 provider and attach the new session to the
- * existing user. If no matching user is found - the server will create a new
- * user.
- *
- * A user is limited to 10 active sessions at a time by default. [Learn more
- * about session
- * limits](https://appwrite.io/docs/authentication-security#limits).
- *
+ * Allow the user to login to their account using the OAuth2 provider of their choice. Each OAuth2 provider should be enabled from the Appwrite console first. Use the success and failure arguments to provide a redirect URL's back to your app when login is completed.
+
+If there is already an active session, the new session will be attached to the logged-in account. If there are no active sessions, the server will attempt to look for a user with the same email address as the email received from the OAuth2 provider and attach the new session to the existing user. If no matching user is found - the server will create a new user.
+
+A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).
+
*
* @param {OAuthProvider} provider
* @param {string} success
* @param {string} failure
* @param {string[]} scopes
* @throws {AppwriteException}
- * @returns {void|string}
- */
- createOAuth2Session(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): void | URL {
+ * @returns {Promise}
+ */
+ async createOAuth2Session(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): Promise {
if (typeof provider === 'undefined') {
throw new AppwriteException('Missing required parameter: "provider"');
}
-
const apiPath = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider);
const payload: Payload = {};
-
if (typeof success !== 'undefined') {
payload['success'] = success;
}
-
if (typeof failure !== 'undefined') {
payload['failure'] = failure;
}
-
if (typeof scopes !== 'undefined') {
payload['scopes'] = scopes;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
-
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
- uri.searchParams.append(key, value);
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
}
- if (typeof window !== 'undefined' && window?.location) {
- window.location.href = uri.toString();
- } else {
- return uri;
+
+ const location = await this.client.redirect(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ if (typeof window !== 'undefined') {
+ window.location.href = location;
}
+ return location.toString();
}
-
/**
* Update phone session
*
- * Use this endpoint to create a session from token. Provide the **userId**
- * and **secret** parameters from the successful response of authentication
- * flows initiated by token creation. For example, magic URL and phone login.
+ * Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.
*
* @param {string} userId
* @param {string} secret
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updatePhoneSession(userId: string, secret: string): Promise {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof secret === 'undefined') {
throw new AppwriteException('Missing required parameter: "secret"');
}
-
const apiPath = '/account/sessions/phone';
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof secret !== 'undefined') {
payload['secret'] = secret;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create session
*
- * Use this endpoint to create a session from token. Provide the **userId**
- * and **secret** parameters from the successful response of authentication
- * flows initiated by token creation. For example, magic URL and phone login.
+ * Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.
*
* @param {string} userId
* @param {string} secret
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createSession(userId: string, secret: string): Promise {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof secret === 'undefined') {
throw new AppwriteException('Missing required parameter: "secret"');
}
-
const apiPath = '/account/sessions/token';
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof secret !== 'undefined') {
payload['secret'] = secret;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Get session
*
- * Use this endpoint to get a logged in user's session using a Session ID.
- * Inputting 'current' will return the current session being used.
+ * Use this endpoint to get a logged in user's session using a Session ID. Inputting 'current' will return the current session being used.
*
* @param {string} sessionId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async getSession(sessionId: string): Promise {
if (typeof sessionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "sessionId"');
}
-
const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update session
*
- * Use this endpoint to extend a session's length. Extending a session is
- * useful when session expiry is short. If the session was created using an
- * OAuth provider, this endpoint refreshes the access token from the provider.
+ * Use this endpoint to extend a session's length. Extending a session is useful when session expiry is short. If the session was created using an OAuth provider, this endpoint refreshes the access token from the provider.
*
* @param {string} sessionId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updateSession(sessionId: string): Promise {
if (typeof sessionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "sessionId"');
}
-
const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Delete session
*
- * Logout the user. Use 'current' as the session ID to logout on this device,
- * use a session ID to logout on another device. If you're looking to logout
- * the user on all devices, use [Delete
- * Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions)
- * instead.
+ * Logout the user. Use 'current' as the session ID to logout on this device, use a session ID to logout on another device. If you're looking to logout the user on all devices, use [Delete Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) instead.
*
* @param {string} sessionId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async deleteSession(sessionId: string): Promise<{}> {
if (typeof sessionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "sessionId"');
}
-
const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('delete', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'delete',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update status
*
- * Block the currently logged in user account. Behind the scene, the user
- * record is not deleted but permanently blocked from any access. To
- * completely delete a user, use the Users API instead.
+ * Block the currently logged in user account. Behind the scene, the user record is not deleted but permanently blocked from any access. To completely delete a user, use the Users API instead.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async updateStatus(): Promise> {
const apiPath = '/account/status';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create push target
*
@@ -1110,38 +1154,39 @@ export class Account extends Service {
* @param {string} identifier
* @param {string} providerId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createPushTarget(targetId: string, identifier: string, providerId?: string): Promise {
if (typeof targetId === 'undefined') {
throw new AppwriteException('Missing required parameter: "targetId"');
}
-
if (typeof identifier === 'undefined') {
throw new AppwriteException('Missing required parameter: "identifier"');
}
-
const apiPath = '/account/targets/push';
const payload: Payload = {};
-
if (typeof targetId !== 'undefined') {
payload['targetId'] = targetId;
}
-
if (typeof identifier !== 'undefined') {
payload['identifier'] = identifier;
}
-
if (typeof providerId !== 'undefined') {
payload['providerId'] = providerId;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update push target
*
@@ -1149,408 +1194,373 @@ export class Account extends Service {
* @param {string} targetId
* @param {string} identifier
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updatePushTarget(targetId: string, identifier: string): Promise {
if (typeof targetId === 'undefined') {
throw new AppwriteException('Missing required parameter: "targetId"');
}
-
if (typeof identifier === 'undefined') {
throw new AppwriteException('Missing required parameter: "identifier"');
}
-
const apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', targetId);
const payload: Payload = {};
-
if (typeof identifier !== 'undefined') {
payload['identifier'] = identifier;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Delete push target
*
*
* @param {string} targetId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async deletePushTarget(targetId: string): Promise<{}> {
if (typeof targetId === 'undefined') {
throw new AppwriteException('Missing required parameter: "targetId"');
}
-
const apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', targetId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('delete', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'delete',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create email token (OTP)
*
- * Sends the user an email with a secret key for creating a session. If the
- * provided user ID has not be registered, a new user will be created. Use the
- * returned user ID and secret and submit a request to the [POST
- * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
- * endpoint to complete the login process. The secret sent to the user's email
- * is valid for 15 minutes.
- *
- * A user is limited to 10 active sessions at a time by default. [Learn more
- * about session
- * limits](https://appwrite.io/docs/authentication-security#limits).
+ * Sends the user an email with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The secret sent to the user's email is valid for 15 minutes.
+
+A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).
*
* @param {string} userId
* @param {string} email
* @param {boolean} phrase
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createEmailToken(userId: string, email: string, phrase?: boolean): Promise {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof email === 'undefined') {
throw new AppwriteException('Missing required parameter: "email"');
}
-
const apiPath = '/account/tokens/email';
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof email !== 'undefined') {
payload['email'] = email;
}
-
if (typeof phrase !== 'undefined') {
payload['phrase'] = phrase;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create magic URL token
*
- * Sends the user an email with a secret key for creating a session. If the
- * provided user ID has not been registered, a new user will be created. When
- * the user clicks the link in the email, the user is redirected back to the
- * URL you provided with the secret key and userId values attached to the URL
- * query string. Use the query string parameters to submit a request to the
- * [POST
- * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
- * endpoint to complete the login process. The link sent to the user's email
- * address is valid for 1 hour. If you are on a mobile device you can leave
- * the URL parameter empty, so that the login completion will be handled by
- * your Appwrite instance by default.
- *
- * A user is limited to 10 active sessions at a time by default. [Learn more
- * about session
- * limits](https://appwrite.io/docs/authentication-security#limits).
- *
+ * Sends the user an email with a secret key for creating a session. If the provided user ID has not been registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default.
+
+A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).
+
*
* @param {string} userId
* @param {string} email
* @param {string} url
* @param {boolean} phrase
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createMagicURLToken(userId: string, email: string, url?: string, phrase?: boolean): Promise {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof email === 'undefined') {
throw new AppwriteException('Missing required parameter: "email"');
}
-
const apiPath = '/account/tokens/magic-url';
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof email !== 'undefined') {
payload['email'] = email;
}
-
if (typeof url !== 'undefined') {
payload['url'] = url;
}
-
if (typeof phrase !== 'undefined') {
payload['phrase'] = phrase;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create OAuth2 token
*
- * Allow the user to login to their account using the OAuth2 provider of their
- * choice. Each OAuth2 provider should be enabled from the Appwrite console
- * first. Use the success and failure arguments to provide a redirect URL's
- * back to your app when login is completed.
- *
- * If authentication succeeds, `userId` and `secret` of a token will be
- * appended to the success URL as query parameters. These can be used to
- * create a new session using the [Create
- * session](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
- * endpoint.
- *
- * A user is limited to 10 active sessions at a time by default. [Learn more
- * about session
- * limits](https://appwrite.io/docs/authentication-security#limits).
+ * Allow the user to login to their account using the OAuth2 provider of their choice. Each OAuth2 provider should be enabled from the Appwrite console first. Use the success and failure arguments to provide a redirect URL's back to your app when login is completed.
+
+If authentication succeeds, `userId` and `secret` of a token will be appended to the success URL as query parameters. These can be used to create a new session using the [Create session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint.
+
+A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).
*
* @param {OAuthProvider} provider
* @param {string} success
* @param {string} failure
* @param {string[]} scopes
* @throws {AppwriteException}
- * @returns {void|string}
- */
- createOAuth2Token(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): void | URL {
+ * @returns {Promise}
+ */
+ async createOAuth2Token(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): Promise {
if (typeof provider === 'undefined') {
throw new AppwriteException('Missing required parameter: "provider"');
}
-
const apiPath = '/account/tokens/oauth2/{provider}'.replace('{provider}', provider);
const payload: Payload = {};
-
if (typeof success !== 'undefined') {
payload['success'] = success;
}
-
if (typeof failure !== 'undefined') {
payload['failure'] = failure;
}
-
if (typeof scopes !== 'undefined') {
payload['scopes'] = scopes;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
-
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
- uri.searchParams.append(key, value);
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
}
- if (typeof window !== 'undefined' && window?.location) {
- window.location.href = uri.toString();
- } else {
- return uri;
+
+ const location = await this.client.redirect(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ if (typeof window !== 'undefined') {
+ window.location.href = location;
}
+ return location.toString();
}
-
/**
* Create phone token
*
- * Sends the user an SMS with a secret key for creating a session. If the
- * provided user ID has not be registered, a new user will be created. Use the
- * returned user ID and secret and submit a request to the [POST
- * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
- * endpoint to complete the login process. The secret sent to the user's phone
- * is valid for 15 minutes.
- *
- * A user is limited to 10 active sessions at a time by default. [Learn more
- * about session
- * limits](https://appwrite.io/docs/authentication-security#limits).
+ * Sends the user an SMS with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes.
+
+A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).
*
* @param {string} userId
* @param {string} phone
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createPhoneToken(userId: string, phone: string): Promise {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof phone === 'undefined') {
throw new AppwriteException('Missing required parameter: "phone"');
}
-
const apiPath = '/account/tokens/phone';
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof phone !== 'undefined') {
payload['phone'] = phone;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create email verification
*
- * Use this endpoint to send a verification message to your user email address
- * to confirm they are the valid owners of that address. Both the **userId**
- * and **secret** arguments will be passed as query parameters to the URL you
- * have provided to be attached to the verification email. The provided URL
- * should redirect the user back to your app and allow you to complete the
- * verification process by verifying both the **userId** and **secret**
- * parameters. Learn more about how to [complete the verification
- * process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification).
- * The verification link sent to the user's email address is valid for 7 days.
- *
- * Please note that in order to avoid a [Redirect
- * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md),
- * the only valid redirect URLs are the ones from domains you have set when
- * adding your platforms in the console interface.
- *
+ * Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). The verification link sent to the user's email address is valid for 7 days.
+
+Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.
+
*
* @param {string} url
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createVerification(url: string): Promise {
if (typeof url === 'undefined') {
throw new AppwriteException('Missing required parameter: "url"');
}
-
const apiPath = '/account/verification';
const payload: Payload = {};
-
if (typeof url !== 'undefined') {
payload['url'] = url;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create email verification (confirmation)
*
- * Use this endpoint to complete the user email verification process. Use both
- * the **userId** and **secret** parameters that were attached to your app URL
- * to verify the user email ownership. If confirmed this route will return a
- * 200 status code.
+ * Use this endpoint to complete the user email verification process. Use both the **userId** and **secret** parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.
*
* @param {string} userId
* @param {string} secret
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updateVerification(userId: string, secret: string): Promise {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof secret === 'undefined') {
throw new AppwriteException('Missing required parameter: "secret"');
}
-
const apiPath = '/account/verification';
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof secret !== 'undefined') {
payload['secret'] = secret;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create phone verification
*
- * Use this endpoint to send a verification SMS to the currently logged in
- * user. This endpoint is meant for use after updating a user's phone number
- * using the
- * [accountUpdatePhone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone)
- * endpoint. Learn more about how to [complete the verification
- * process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification).
- * The verification code sent to the user's phone number is valid for 15
- * minutes.
+ * Use this endpoint to send a verification SMS to the currently logged in user. This endpoint is meant for use after updating a user's phone number using the [accountUpdatePhone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) endpoint. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). The verification code sent to the user's phone number is valid for 15 minutes.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createPhoneVerification(): Promise {
const apiPath = '/account/verification/phone';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update phone verification (confirmation)
*
- * Use this endpoint to complete the user phone verification process. Use the
- * **userId** and **secret** that were sent to your user's phone number to
- * verify the user email ownership. If confirmed this route will return a 200
- * status code.
+ * Use this endpoint to complete the user phone verification process. Use the **userId** and **secret** that were sent to your user's phone number to verify the user email ownership. If confirmed this route will return a 200 status code.
*
* @param {string} userId
* @param {string} secret
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updatePhoneVerification(userId: string, secret: string): Promise {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof secret === 'undefined') {
throw new AppwriteException('Missing required parameter: "secret"');
}
-
const apiPath = '/account/verification/phone';
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof secret !== 'undefined') {
payload['secret'] = secret;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-};
+}
diff --git a/src/services/avatars.ts b/src/services/avatars.ts
index 6c775fc..ab76ccb 100644
--- a/src/services/avatars.ts
+++ b/src/services/avatars.ts
@@ -1,357 +1,314 @@
-import { Service } from '../service';
-import { AppwriteException, Client } from '../client';
+import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
-import type { UploadProgress, Payload } from '../client';
import { Browser } from '../enums/browser';
import { CreditCard } from '../enums/credit-card';
import { Flag } from '../enums/flag';
-export class Avatars extends Service {
+export class Avatars {
+ client: Client;
- constructor(client: Client)
- {
- super(client);
- }
+ constructor(client: Client) {
+ this.client = client;
+ }
/**
* Get browser icon
*
- * You can use this endpoint to show different browser icons to your users.
- * The code argument receives the browser code as it appears in your user [GET
- * /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions)
- * endpoint. Use width, height and quality arguments to change the output
- * settings.
- *
- * When one dimension is specified and the other is 0, the image is scaled
- * with preserved aspect ratio. If both dimensions are 0, the API provides an
- * image at source quality. If dimensions are not specified, the default size
- * of image returned is 100x100px.
+ * You can use this endpoint to show different browser icons to your users. The code argument receives the browser code as it appears in your user [GET /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) endpoint. Use width, height and quality arguments to change the output settings.
+
+When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px.
*
* @param {Browser} code
* @param {number} width
* @param {number} height
* @param {number} quality
* @throws {AppwriteException}
- * @returns {URL}
- */
- getBrowser(code: Browser, width?: number, height?: number, quality?: number): URL {
+ * @returns {string}
+ */
+ getBrowser(code: Browser, width?: number, height?: number, quality?: number): string {
if (typeof code === 'undefined') {
throw new AppwriteException('Missing required parameter: "code"');
}
-
const apiPath = '/avatars/browsers/{code}'.replace('{code}', code);
const payload: Payload = {};
-
if (typeof width !== 'undefined') {
payload['width'] = width;
}
-
if (typeof height !== 'undefined') {
payload['height'] = height;
}
-
if (typeof quality !== 'undefined') {
payload['quality'] = quality;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
+
+ payload['project'] = this.client.config.project;
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
- }
+ return uri.toString();
+ }
/**
* Get credit card icon
*
- * The credit card endpoint will return you the icon of the credit card
- * provider you need. Use width, height and quality arguments to change the
- * output settings.
- *
- * When one dimension is specified and the other is 0, the image is scaled
- * with preserved aspect ratio. If both dimensions are 0, the API provides an
- * image at source quality. If dimensions are not specified, the default size
- * of image returned is 100x100px.
- *
+ * The credit card endpoint will return you the icon of the credit card provider you need. Use width, height and quality arguments to change the output settings.
+
+When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px.
+
*
* @param {CreditCard} code
* @param {number} width
* @param {number} height
* @param {number} quality
* @throws {AppwriteException}
- * @returns {URL}
- */
- getCreditCard(code: CreditCard, width?: number, height?: number, quality?: number): URL {
+ * @returns {string}
+ */
+ getCreditCard(code: CreditCard, width?: number, height?: number, quality?: number): string {
if (typeof code === 'undefined') {
throw new AppwriteException('Missing required parameter: "code"');
}
-
const apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code);
const payload: Payload = {};
-
if (typeof width !== 'undefined') {
payload['width'] = width;
}
-
if (typeof height !== 'undefined') {
payload['height'] = height;
}
-
if (typeof quality !== 'undefined') {
payload['quality'] = quality;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
+
+ payload['project'] = this.client.config.project;
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
- }
+ return uri.toString();
+ }
/**
* Get favicon
*
- * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote
- * website URL.
- *
- * This endpoint does not follow HTTP redirects.
+ * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote website URL.
+
+This endpoint does not follow HTTP redirects.
*
* @param {string} url
* @throws {AppwriteException}
- * @returns {URL}
- */
- getFavicon(url: string): URL {
+ * @returns {string}
+ */
+ getFavicon(url: string): string {
if (typeof url === 'undefined') {
throw new AppwriteException('Missing required parameter: "url"');
}
-
const apiPath = '/avatars/favicon';
const payload: Payload = {};
-
if (typeof url !== 'undefined') {
payload['url'] = url;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
+
+ payload['project'] = this.client.config.project;
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
- }
+ return uri.toString();
+ }
/**
* Get country flag
*
- * You can use this endpoint to show different country flags icons to your
- * users. The code argument receives the 2 letter country code. Use width,
- * height and quality arguments to change the output settings. Country codes
- * follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard.
- *
- * When one dimension is specified and the other is 0, the image is scaled
- * with preserved aspect ratio. If both dimensions are 0, the API provides an
- * image at source quality. If dimensions are not specified, the default size
- * of image returned is 100x100px.
- *
+ * You can use this endpoint to show different country flags icons to your users. The code argument receives the 2 letter country code. Use width, height and quality arguments to change the output settings. Country codes follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard.
+
+When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px.
+
*
* @param {Flag} code
* @param {number} width
* @param {number} height
* @param {number} quality
* @throws {AppwriteException}
- * @returns {URL}
- */
- getFlag(code: Flag, width?: number, height?: number, quality?: number): URL {
+ * @returns {string}
+ */
+ getFlag(code: Flag, width?: number, height?: number, quality?: number): string {
if (typeof code === 'undefined') {
throw new AppwriteException('Missing required parameter: "code"');
}
-
const apiPath = '/avatars/flags/{code}'.replace('{code}', code);
const payload: Payload = {};
-
if (typeof width !== 'undefined') {
payload['width'] = width;
}
-
if (typeof height !== 'undefined') {
payload['height'] = height;
}
-
if (typeof quality !== 'undefined') {
payload['quality'] = quality;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
+
+ payload['project'] = this.client.config.project;
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
- }
+ return uri.toString();
+ }
/**
* Get image from URL
*
- * Use this endpoint to fetch a remote image URL and crop it to any image size
- * you want. This endpoint is very useful if you need to crop and display
- * remote images in your app or in case you want to make sure a 3rd party
- * image is properly served using a TLS protocol.
- *
- * When one dimension is specified and the other is 0, the image is scaled
- * with preserved aspect ratio. If both dimensions are 0, the API provides an
- * image at source quality. If dimensions are not specified, the default size
- * of image returned is 400x400px.
- *
- * This endpoint does not follow HTTP redirects.
+ * Use this endpoint to fetch a remote image URL and crop it to any image size you want. This endpoint is very useful if you need to crop and display remote images in your app or in case you want to make sure a 3rd party image is properly served using a TLS protocol.
+
+When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 400x400px.
+
+This endpoint does not follow HTTP redirects.
*
* @param {string} url
* @param {number} width
* @param {number} height
* @throws {AppwriteException}
- * @returns {URL}
- */
- getImage(url: string, width?: number, height?: number): URL {
+ * @returns {string}
+ */
+ getImage(url: string, width?: number, height?: number): string {
if (typeof url === 'undefined') {
throw new AppwriteException('Missing required parameter: "url"');
}
-
const apiPath = '/avatars/image';
const payload: Payload = {};
-
if (typeof url !== 'undefined') {
payload['url'] = url;
}
-
if (typeof width !== 'undefined') {
payload['width'] = width;
}
-
if (typeof height !== 'undefined') {
payload['height'] = height;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
+
+ payload['project'] = this.client.config.project;
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
- }
+ return uri.toString();
+ }
/**
* Get user initials
*
- * Use this endpoint to show your user initials avatar icon on your website or
- * app. By default, this route will try to print your logged-in user name or
- * email initials. You can also overwrite the user name if you pass the 'name'
- * parameter. If no name is given and no user is logged, an empty avatar will
- * be returned.
- *
- * You can use the color and background params to change the avatar colors. By
- * default, a random theme will be selected. The random theme will persist for
- * the user's initials when reloading the same theme will always return for
- * the same initials.
- *
- * When one dimension is specified and the other is 0, the image is scaled
- * with preserved aspect ratio. If both dimensions are 0, the API provides an
- * image at source quality. If dimensions are not specified, the default size
- * of image returned is 100x100px.
- *
+ * Use this endpoint to show your user initials avatar icon on your website or app. By default, this route will try to print your logged-in user name or email initials. You can also overwrite the user name if you pass the 'name' parameter. If no name is given and no user is logged, an empty avatar will be returned.
+
+You can use the color and background params to change the avatar colors. By default, a random theme will be selected. The random theme will persist for the user's initials when reloading the same theme will always return for the same initials.
+
+When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px.
+
*
* @param {string} name
* @param {number} width
* @param {number} height
* @param {string} background
* @throws {AppwriteException}
- * @returns {URL}
- */
- getInitials(name?: string, width?: number, height?: number, background?: string): URL {
+ * @returns {string}
+ */
+ getInitials(name?: string, width?: number, height?: number, background?: string): string {
const apiPath = '/avatars/initials';
const payload: Payload = {};
-
if (typeof name !== 'undefined') {
payload['name'] = name;
}
-
if (typeof width !== 'undefined') {
payload['width'] = width;
}
-
if (typeof height !== 'undefined') {
payload['height'] = height;
}
-
if (typeof background !== 'undefined') {
payload['background'] = background;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ payload['project'] = this.client.config.project;
+
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
- }
+ return uri.toString();
+ }
/**
* Get QR code
*
- * Converts a given plain text to a QR code image. You can use the query
- * parameters to change the size and style of the resulting image.
- *
+ * Converts a given plain text to a QR code image. You can use the query parameters to change the size and style of the resulting image.
+
*
* @param {string} text
* @param {number} size
* @param {number} margin
* @param {boolean} download
* @throws {AppwriteException}
- * @returns {URL}
- */
- getQR(text: string, size?: number, margin?: number, download?: boolean): URL {
+ * @returns {string}
+ */
+ getQR(text: string, size?: number, margin?: number, download?: boolean): string {
if (typeof text === 'undefined') {
throw new AppwriteException('Missing required parameter: "text"');
}
-
const apiPath = '/avatars/qr';
const payload: Payload = {};
-
if (typeof text !== 'undefined') {
payload['text'] = text;
}
-
if (typeof size !== 'undefined') {
payload['size'] = size;
}
-
if (typeof margin !== 'undefined') {
payload['margin'] = margin;
}
-
if (typeof download !== 'undefined') {
payload['download'] = download;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ payload['project'] = this.client.config.project;
+
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
+
+ return uri.toString();
}
-};
+}
diff --git a/src/services/databases.ts b/src/services/databases.ts
index d2bbfa1..cf8c34b 100644
--- a/src/services/databases.ts
+++ b/src/services/databases.ts
@@ -1,56 +1,53 @@
-import { Service } from '../service';
-import { AppwriteException, Client } from '../client';
+import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
-import type { UploadProgress, Payload } from '../client';
-export class Databases extends Service {
+export class Databases {
+ client: Client;
- constructor(client: Client)
- {
- super(client);
- }
+ constructor(client: Client) {
+ this.client = client;
+ }
/**
* List documents
*
- * Get a list of all the user's documents in a given collection. You can use
- * the query params to filter your results.
+ * Get a list of all the user's documents in a given collection. You can use the query params to filter your results.
*
* @param {string} databaseId
* @param {string} collectionId
* @param {string[]} queries
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise> {
if (typeof databaseId === 'undefined') {
throw new AppwriteException('Missing required parameter: "databaseId"');
}
-
if (typeof collectionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "collectionId"');
}
-
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId);
const payload: Payload = {};
-
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create document
*
- * Create a new 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.
+ * Create a new 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
@@ -58,90 +55,89 @@ export class Databases extends Service {
* @param {Omit} data
* @param {string[]} permissions
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createDocument(databaseId: string, collectionId: string, documentId: string, data: Omit, 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'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId);
const payload: Payload = {};
-
if (typeof documentId !== 'undefined') {
payload['documentId'] = documentId;
}
-
if (typeof data !== 'undefined') {
payload['data'] = data;
}
-
if (typeof permissions !== 'undefined') {
payload['permissions'] = permissions;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Get document
*
- * Get a document by its unique ID. This endpoint response returns a JSON
- * object with the document data.
+ * Get a document by its unique ID. This endpoint response returns a JSON object with the document data.
*
* @param {string} databaseId
* @param {string} collectionId
* @param {string} documentId
* @param {string[]} queries
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async getDocument(databaseId: string, collectionId: string, documentId: string, queries?: 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"');
}
-
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId);
const payload: Payload = {};
-
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update document
*
- * Update a document by its unique ID. Using the patch method you can pass
- * only specific fields that will get updated.
+ * Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated.
*
* @param {string} databaseId
* @param {string} collectionId
@@ -149,38 +145,39 @@ export class Databases extends Service {
* @param {Partial>} data
* @param {string[]} permissions
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updateDocument(databaseId: string, collectionId: string, documentId: string, data?: Partial>, 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"');
}
-
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);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Delete document
*
@@ -190,27 +187,31 @@ export class Databases extends Service {
* @param {string} collectionId
* @param {string} documentId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async deleteDocument(databaseId: string, collectionId: string, documentId: 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"');
}
-
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('delete', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'delete',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-};
+}
diff --git a/src/services/functions.ts b/src/services/functions.ts
index 9ee52ed..02330d4 100644
--- a/src/services/functions.ts
+++ b/src/services/functions.ts
@@ -1,155 +1,155 @@
-import { Service } from '../service';
-import { AppwriteException, Client } from '../client';
+import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
-import type { UploadProgress, Payload } from '../client';
import { ExecutionMethod } from '../enums/execution-method';
-export class Functions extends Service {
+export class Functions {
+ client: Client;
- constructor(client: Client)
- {
- super(client);
- }
+ constructor(client: Client) {
+ this.client = client;
+ }
/**
* List function templates
*
- * List available function templates. You can use template details in
- * [createFunction](/docs/references/cloud/server-nodejs/functions#create)
- * method.
+ * List available function templates. You can use template details in [createFunction](/docs/references/cloud/server-nodejs/functions#create) method.
*
* @param {string[]} runtimes
* @param {string[]} useCases
* @param {number} limit
* @param {number} offset
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listTemplates(runtimes?: string[], useCases?: string[], limit?: number, offset?: number): Promise {
const apiPath = '/functions/templates';
const payload: Payload = {};
-
if (typeof runtimes !== 'undefined') {
payload['runtimes'] = runtimes;
}
-
if (typeof useCases !== 'undefined') {
payload['useCases'] = useCases;
}
-
if (typeof limit !== 'undefined') {
payload['limit'] = limit;
}
-
if (typeof offset !== 'undefined') {
payload['offset'] = offset;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Get function template
*
- * Get a function template using ID. You can use template details in
- * [createFunction](/docs/references/cloud/server-nodejs/functions#create)
- * method.
+ * Get a function template using ID. You can use template details in [createFunction](/docs/references/cloud/server-nodejs/functions#create) method.
*
* @param {string} templateId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async getTemplate(templateId: string): Promise {
if (typeof templateId === 'undefined') {
throw new AppwriteException('Missing required parameter: "templateId"');
}
-
const apiPath = '/functions/templates/{templateId}'.replace('{templateId}', templateId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Download deployment
*
- * Get a Deployment's contents by its unique ID. This endpoint supports range
- * requests for partial or streaming file download.
+ * Get a Deployment's contents by its unique ID. This endpoint supports range requests for partial or streaming file download.
*
* @param {string} functionId
* @param {string} deploymentId
* @throws {AppwriteException}
- * @returns {URL}
- */
- getDeploymentDownload(functionId: string, deploymentId: string): URL {
+ * @returns {string}
+ */
+ getDeploymentDownload(functionId: string, deploymentId: string): string {
if (typeof functionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "functionId"');
}
-
if (typeof deploymentId === 'undefined') {
throw new AppwriteException('Missing required parameter: "deploymentId"');
}
-
const apiPath = '/functions/{functionId}/deployments/{deploymentId}/download'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
+
+ payload['project'] = this.client.config.project;
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
- }
+ return uri.toString();
+ }
/**
* List executions
*
- * Get a list of all the current user function execution logs. You can use the
- * query params to filter your results.
+ * Get a list of all the current user function execution logs. You can use the query params to filter your results.
*
* @param {string} functionId
* @param {string[]} queries
* @param {string} search
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listExecutions(functionId: string, queries?: string[], search?: string): Promise {
if (typeof functionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "functionId"');
}
-
const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
const payload: Payload = {};
-
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
-
if (typeof search !== 'undefined') {
payload['search'] = search;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create execution
*
- * Trigger a function execution. The returned object will return you the
- * current execution status. You can ping the `Get Execution` endpoint to get
- * updates on the current execution status. Once this endpoint is called, your
- * function execution process will start asynchronously.
+ * Trigger a function execution. The returned object will return you the current execution status. You can ping the `Get Execution` endpoint to get updates on the current execution status. Once this endpoint is called, your function execution process will start asynchronously.
*
* @param {string} functionId
* @param {string} body
@@ -159,43 +159,46 @@ export class Functions extends Service {
* @param {object} headers
* @param {string} scheduledAt
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: ExecutionMethod, headers?: object, scheduledAt?: string, onProgress = (progress: UploadProgress) => {}): Promise {
if (typeof functionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "functionId"');
}
-
const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
const payload: Payload = {};
-
if (typeof body !== 'undefined') {
payload['body'] = body;
}
-
if (typeof async !== 'undefined') {
payload['async'] = async;
}
-
if (typeof xpath !== 'undefined') {
payload['path'] = xpath;
}
-
if (typeof method !== 'undefined') {
payload['method'] = method;
}
-
if (typeof headers !== 'undefined') {
payload['headers'] = headers;
}
-
if (typeof scheduledAt !== 'undefined') {
payload['scheduledAt'] = scheduledAt;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- }
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'multipart/form-data',
+ }
+
+ return await this.client.chunkedUpload(
+ 'post',
+ uri,
+ apiHeaders,
+ payload,
+ onProgress
+ );
+ }
/**
* Get execution
*
@@ -204,23 +207,28 @@ export class Functions extends Service {
* @param {string} functionId
* @param {string} executionId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async getExecution(functionId: string, executionId: string): Promise {
if (typeof functionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "functionId"');
}
-
if (typeof executionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "executionId"');
}
-
const apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-};
+}
diff --git a/src/services/graphql.ts b/src/services/graphql.ts
index ca03efb..b68e7b5 100644
--- a/src/services/graphql.ts
+++ b/src/services/graphql.ts
@@ -1,14 +1,12 @@
-import { Service } from '../service';
-import { AppwriteException, Client } from '../client';
+import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
-import type { UploadProgress, Payload } from '../client';
-export class Graphql extends Service {
+export class Graphql {
+ client: Client;
- constructor(client: Client)
- {
- super(client);
- }
+ constructor(client: Client) {
+ this.client = client;
+ }
/**
* GraphQL endpoint
@@ -17,27 +15,31 @@ export class Graphql extends Service {
*
* @param {object} query
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async query(query: object): Promise<{}> {
if (typeof query === 'undefined') {
throw new AppwriteException('Missing required parameter: "query"');
}
-
const apiPath = '/graphql';
const payload: Payload = {};
-
if (typeof query !== 'undefined') {
payload['query'] = query;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'x-sdk-graphql': 'true',
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* GraphQL endpoint
*
@@ -45,24 +47,29 @@ export class Graphql extends Service {
*
* @param {object} query
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async mutation(query: object): Promise<{}> {
if (typeof query === 'undefined') {
throw new AppwriteException('Missing required parameter: "query"');
}
-
const apiPath = '/graphql/mutation';
const payload: Payload = {};
-
if (typeof query !== 'undefined') {
payload['query'] = query;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'x-sdk-graphql': 'true',
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-};
+}
diff --git a/src/services/locale.ts b/src/services/locale.ts
index d70b5ed..d1c94b7 100644
--- a/src/services/locale.ts
+++ b/src/services/locale.ts
@@ -1,169 +1,205 @@
-import { Service } from '../service';
-import { AppwriteException, Client } from '../client';
+import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
-import type { UploadProgress, Payload } from '../client';
-export class Locale extends Service {
+export class Locale {
+ client: Client;
- constructor(client: Client)
- {
- super(client);
- }
+ constructor(client: Client) {
+ this.client = client;
+ }
/**
* Get user locale
*
- * Get the current user location based on IP. Returns an object with user
- * country code, country name, continent name, continent code, ip address and
- * suggested currency. You can use the locale header to get the data in a
- * supported language.
- *
- * ([IP Geolocation by DB-IP](https://db-ip.com))
+ * Get the current user location based on IP. Returns an object with user country code, country name, continent name, continent code, ip address and suggested currency. You can use the locale header to get the data in a supported language.
+
+([IP Geolocation by DB-IP](https://db-ip.com))
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async get(): Promise {
const apiPath = '/locale';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-
/**
* List Locale Codes
*
- * List of all locale codes in [ISO
- * 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
+ * List of all locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listCodes(): Promise {
const apiPath = '/locale/codes';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-
/**
* List continents
*
- * List of all continents. You can use the locale header to get the data in a
- * supported language.
+ * List of all continents. You can use the locale header to get the data in a supported language.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listContinents(): Promise {
const apiPath = '/locale/continents';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-
/**
* List countries
*
- * List of all countries. You can use the locale header to get the data in a
- * supported language.
+ * List of all countries. You can use the locale header to get the data in a supported language.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listCountries(): Promise {
const apiPath = '/locale/countries';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-
/**
* List EU countries
*
- * List of all countries that are currently members of the EU. You can use the
- * locale header to get the data in a supported language.
+ * List of all countries that are currently members of the EU. You can use the locale header to get the data in a supported language.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listCountriesEU(): Promise {
const apiPath = '/locale/countries/eu';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-
/**
* List countries phone codes
*
- * List of all countries phone codes. You can use the locale header to get the
- * data in a supported language.
+ * List of all countries phone codes. You can use the locale header to get the data in a supported language.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listCountriesPhones(): Promise {
const apiPath = '/locale/countries/phones';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-
/**
* List currencies
*
- * List of all currencies, including currency symbol, name, plural, and
- * decimal digits for all major and minor currencies. You can use the locale
- * header to get the data in a supported language.
+ * List of all currencies, including currency symbol, name, plural, and decimal digits for all major and minor currencies. You can use the locale header to get the data in a supported language.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listCurrencies(): Promise {
const apiPath = '/locale/currencies';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-
/**
* List languages
*
- * List of all languages classified by ISO 639-1 including 2-letter code, name
- * in English, and name in the respective language.
+ * List of all languages classified by ISO 639-1 including 2-letter code, name in English, and name in the respective language.
*
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listLanguages(): Promise {
const apiPath = '/locale/languages';
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-};
+}
diff --git a/src/services/messaging.ts b/src/services/messaging.ts
index 16920b2..a38b4e5 100644
--- a/src/services/messaging.ts
+++ b/src/services/messaging.ts
@@ -1,14 +1,12 @@
-import { Service } from '../service';
-import { AppwriteException, Client } from '../client';
+import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
-import type { UploadProgress, Payload } from '../client';
-export class Messaging extends Service {
+export class Messaging {
+ client: Client;
- constructor(client: Client)
- {
- super(client);
- }
+ constructor(client: Client) {
+ this.client = client;
+ }
/**
* Create subscriber
@@ -19,38 +17,39 @@ export class Messaging extends Service {
* @param {string} subscriberId
* @param {string} targetId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createSubscriber(topicId: string, subscriberId: string, targetId: string): Promise {
if (typeof topicId === 'undefined') {
throw new AppwriteException('Missing required parameter: "topicId"');
}
-
if (typeof subscriberId === 'undefined') {
throw new AppwriteException('Missing required parameter: "subscriberId"');
}
-
if (typeof targetId === 'undefined') {
throw new AppwriteException('Missing required parameter: "targetId"');
}
-
const apiPath = '/messaging/topics/{topicId}/subscribers'.replace('{topicId}', topicId);
const payload: Payload = {};
-
if (typeof subscriberId !== 'undefined') {
payload['subscriberId'] = subscriberId;
}
-
if (typeof targetId !== 'undefined') {
payload['targetId'] = targetId;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Delete subscriber
*
@@ -59,23 +58,28 @@ export class Messaging extends Service {
* @param {string} topicId
* @param {string} subscriberId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async deleteSubscriber(topicId: string, subscriberId: string): Promise<{}> {
if (typeof topicId === 'undefined') {
throw new AppwriteException('Missing required parameter: "topicId"');
}
-
if (typeof subscriberId === 'undefined') {
throw new AppwriteException('Missing required parameter: "subscriberId"');
}
-
const apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replace('{topicId}', topicId).replace('{subscriberId}', subscriberId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('delete', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'delete',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-};
+}
diff --git a/src/services/storage.ts b/src/services/storage.ts
index 83a51b1..0862be3 100644
--- a/src/services/storage.ts
+++ b/src/services/storage.ts
@@ -1,301 +1,246 @@
-import { Service } from '../service';
-import { AppwriteException, Client } from '../client';
+import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
-import type { UploadProgress, Payload } from '../client';
import { ImageGravity } from '../enums/image-gravity';
import { ImageFormat } from '../enums/image-format';
-export class Storage extends Service {
+export class Storage {
+ client: Client;
- constructor(client: Client)
- {
- super(client);
- }
+ constructor(client: Client) {
+ this.client = client;
+ }
/**
* List files
*
- * Get a list of all the user files. You can use the query params to filter
- * your results.
+ * Get a list of all the user files. You can use the query params to filter your results.
*
* @param {string} bucketId
* @param {string[]} queries
* @param {string} search
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listFiles(bucketId: string, queries?: string[], search?: string): Promise {
if (typeof bucketId === 'undefined') {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
-
const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
const payload: Payload = {};
-
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
-
if (typeof search !== 'undefined') {
payload['search'] = search;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create file
*
- * Create a new file. Before using this route, you should create a new bucket
- * resource using either a [server
- * integration](https://appwrite.io/docs/server/storage#storageCreateBucket)
- * API or directly from your Appwrite console.
- *
- * Larger files should be uploaded using multiple requests with the
- * [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range)
- * header to send a partial request with a maximum supported chunk of `5MB`.
- * The `content-range` header values should always be in bytes.
- *
- * When the first request is sent, the server will return the **File** object,
- * and the subsequent part request must include the file's **id** in
- * `x-appwrite-id` header to allow the server to know that the partial upload
- * is for the existing file and not for a new one.
- *
- * If you're creating a new file using one of the Appwrite SDKs, all the
- * chunking logic will be managed by the SDK internally.
- *
+ * Create a new file. Before using this route, you should create a new bucket resource using either a [server integration](https://appwrite.io/docs/server/storage#storageCreateBucket) API or directly from your Appwrite console.
+
+Larger files should be uploaded using multiple requests with the [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) header to send a partial request with a maximum supported chunk of `5MB`. The `content-range` header values should always be in bytes.
+
+When the first request is sent, the server will return the **File** object, and the subsequent part request must include the file's **id** in `x-appwrite-id` header to allow the server to know that the partial upload is for the existing file and not for a new one.
+
+If you're creating a new file using one of the Appwrite SDKs, all the chunking logic will be managed by the SDK internally.
+
*
* @param {string} bucketId
* @param {string} fileId
* @param {File} file
* @param {string[]} permissions
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createFile(bucketId: string, fileId: string, file: File, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise {
if (typeof bucketId === 'undefined') {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
-
if (typeof fileId === 'undefined') {
throw new AppwriteException('Missing required parameter: "fileId"');
}
-
if (typeof file === 'undefined') {
throw new AppwriteException('Missing required parameter: "file"');
}
-
const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
const payload: Payload = {};
-
if (typeof fileId !== 'undefined') {
payload['fileId'] = fileId;
}
-
if (typeof file !== 'undefined') {
payload['file'] = file;
}
-
if (typeof permissions !== 'undefined') {
payload['permissions'] = permissions;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- if(!(file instanceof File)) {
- throw new AppwriteException('Parameter "file" has to be a File.');
- }
-
- const size = file.size;
-
- if (size <= Service.CHUNK_SIZE) {
- return await this.client.call('post', uri, {
- 'content-type': 'multipart/form-data',
- }, payload);
- }
-
const apiHeaders: { [header: string]: string } = {
'content-type': 'multipart/form-data',
}
- let offset = 0;
- let response = undefined;
- if(fileId != 'unique()') {
- try {
- response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), apiHeaders);
- offset = response.chunksUploaded * Service.CHUNK_SIZE;
- } catch(e) {
- }
- }
-
- while (offset < size) {
- let end = Math.min(offset + Service.CHUNK_SIZE - 1, size - 1);
-
- apiHeaders['content-range'] = 'bytes ' + offset + '-' + end + '/' + size;
- if (response && response.$id) {
- apiHeaders['x-appwrite-id'] = response.$id;
- }
-
- const chunk = file.slice(offset, end + 1);
- payload['file'] = new File([chunk], file.name);
- response = await this.client.call('post', uri, apiHeaders, payload);
-
- if (onProgress) {
- onProgress({
- $id: response.$id,
- progress: (offset / size) * 100,
- sizeUploaded: offset,
- chunksTotal: response.chunksTotal,
- chunksUploaded: response.chunksUploaded
- });
- }
- offset += Service.CHUNK_SIZE;
- }
- return response;
+ return await this.client.chunkedUpload(
+ 'post',
+ uri,
+ apiHeaders,
+ payload,
+ onProgress
+ );
}
-
/**
* Get file
*
- * Get a file by its unique ID. This endpoint response returns a JSON object
- * with the file metadata.
+ * Get a file by its unique ID. This endpoint response returns a JSON object with the file metadata.
*
* @param {string} bucketId
* @param {string} fileId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async getFile(bucketId: string, fileId: string): Promise {
if (typeof bucketId === 'undefined') {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
-
if (typeof fileId === 'undefined') {
throw new AppwriteException('Missing required parameter: "fileId"');
}
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update file
*
- * Update a file by its unique ID. Only users with write permissions have
- * access to update this resource.
+ * Update a file by its unique ID. Only users with write permissions have access to update this resource.
*
* @param {string} bucketId
* @param {string} fileId
* @param {string} name
* @param {string[]} permissions
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updateFile(bucketId: string, fileId: string, name?: string, permissions?: string[]): Promise {
if (typeof bucketId === 'undefined') {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
-
if (typeof fileId === 'undefined') {
throw new AppwriteException('Missing required parameter: "fileId"');
}
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
const payload: Payload = {};
-
if (typeof name !== 'undefined') {
payload['name'] = name;
}
-
if (typeof permissions !== 'undefined') {
payload['permissions'] = permissions;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Delete File
*
- * Delete a file by its unique ID. Only users with write permissions have
- * access to delete this resource.
+ * Delete a file by its unique ID. Only users with write permissions have access to delete this resource.
*
* @param {string} bucketId
* @param {string} fileId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async deleteFile(bucketId: string, fileId: string): Promise<{}> {
if (typeof bucketId === 'undefined') {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
-
if (typeof fileId === 'undefined') {
throw new AppwriteException('Missing required parameter: "fileId"');
}
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('delete', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'delete',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Get file for download
*
- * Get a file content by its unique ID. The endpoint response return with a
- * 'Content-Disposition: attachment' header that tells the browser to start
- * downloading the file to user downloads directory.
+ * Get a file content by its unique ID. The endpoint response return with a 'Content-Disposition: attachment' header that tells the browser to start downloading the file to user downloads directory.
*
* @param {string} bucketId
* @param {string} fileId
* @throws {AppwriteException}
- * @returns {URL}
- */
- getFileDownload(bucketId: string, fileId: string): URL {
+ * @returns {string}
+ */
+ getFileDownload(bucketId: string, fileId: string): string {
if (typeof bucketId === 'undefined') {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
-
if (typeof fileId === 'undefined') {
throw new AppwriteException('Missing required parameter: "fileId"');
}
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
+
+ payload['project'] = this.client.config.project;
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
- }
+ return uri.toString();
+ }
/**
* Get file preview
*
- * Get a file preview image. Currently, this method supports preview for image
- * files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
- * and spreadsheets, will return the file icon image. You can also pass query
- * string arguments for cutting and resizing your preview image. Preview is
- * supported only for image files smaller than 10MB.
+ * Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. Preview is supported only for image files smaller than 10MB.
*
* @param {string} bucketId
* @param {string} fileId
@@ -311,105 +256,95 @@ export class Storage extends Service {
* @param {string} background
* @param {ImageFormat} output
* @throws {AppwriteException}
- * @returns {URL}
- */
- getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat): URL {
+ * @returns {string}
+ */
+ getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat): string {
if (typeof bucketId === 'undefined') {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
-
if (typeof fileId === 'undefined') {
throw new AppwriteException('Missing required parameter: "fileId"');
}
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
const payload: Payload = {};
-
if (typeof width !== 'undefined') {
payload['width'] = width;
}
-
if (typeof height !== 'undefined') {
payload['height'] = height;
}
-
if (typeof gravity !== 'undefined') {
payload['gravity'] = gravity;
}
-
if (typeof quality !== 'undefined') {
payload['quality'] = quality;
}
-
if (typeof borderWidth !== 'undefined') {
payload['borderWidth'] = borderWidth;
}
-
if (typeof borderColor !== 'undefined') {
payload['borderColor'] = borderColor;
}
-
if (typeof borderRadius !== 'undefined') {
payload['borderRadius'] = borderRadius;
}
-
if (typeof opacity !== 'undefined') {
payload['opacity'] = opacity;
}
-
if (typeof rotation !== 'undefined') {
payload['rotation'] = rotation;
}
-
if (typeof background !== 'undefined') {
payload['background'] = background;
}
-
if (typeof output !== 'undefined') {
payload['output'] = output;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
+
+ payload['project'] = this.client.config.project;
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
- }
+ return uri.toString();
+ }
/**
* Get file for view
*
- * Get a file content by its unique ID. This endpoint is similar to the
- * download method but returns with no 'Content-Disposition: attachment'
- * header.
+ * Get a file content by its unique ID. This endpoint is similar to the download method but returns with no 'Content-Disposition: attachment' header.
*
* @param {string} bucketId
* @param {string} fileId
* @throws {AppwriteException}
- * @returns {URL}
- */
- getFileView(bucketId: string, fileId: string): URL {
+ * @returns {string}
+ */
+ getFileView(bucketId: string, fileId: string): string {
if (typeof bucketId === 'undefined') {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
-
if (typeof fileId === 'undefined') {
throw new AppwriteException('Missing required parameter: "fileId"');
}
-
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- payload['project'] = this.client.config.project;
+ const apiHeaders: { [header: string]: string } = {
+ 'content-type': 'application/json',
+ }
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
+ payload['project'] = this.client.config.project;
+
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
uri.searchParams.append(key, value);
}
- return uri;
+
+ return uri.toString();
}
-};
+}
diff --git a/src/services/teams.ts b/src/services/teams.ts
index 4c47f3d..b24e955 100644
--- a/src/services/teams.ts
+++ b/src/services/teams.ts
@@ -1,87 +1,87 @@
-import { Service } from '../service';
-import { AppwriteException, Client } from '../client';
+import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
-import type { UploadProgress, Payload } from '../client';
-export class Teams extends Service {
+export class Teams {
+ client: Client;
- constructor(client: Client)
- {
- super(client);
- }
+ constructor(client: Client) {
+ this.client = client;
+ }
/**
* List teams
*
- * Get a list of all the teams in which the current user is a member. You can
- * use the parameters to filter your results.
+ * Get a list of all the teams in which the current user is a member. You can use the parameters to filter your results.
*
* @param {string[]} queries
* @param {string} search
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async list(queries?: string[], search?: string): Promise> {
const apiPath = '/teams';
const payload: Payload = {};
-
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
-
if (typeof search !== 'undefined') {
payload['search'] = search;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create team
*
- * Create a new team. The user who creates the team will automatically be
- * assigned as the owner of the team. Only the users with the owner role can
- * invite new members, add new owners and delete or update the team.
+ * Create a new team. The user who creates the team will automatically be assigned as the owner of the team. Only the users with the owner role can invite new members, add new owners and delete or update the team.
*
* @param {string} teamId
* @param {string} name
* @param {string[]} roles
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async create(teamId: string, name: string, roles?: string[]): Promise> {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
if (typeof name === 'undefined') {
throw new AppwriteException('Missing required parameter: "name"');
}
-
const apiPath = '/teams';
const payload: Payload = {};
-
if (typeof teamId !== 'undefined') {
payload['teamId'] = teamId;
}
-
if (typeof name !== 'undefined') {
payload['name'] = name;
}
-
if (typeof roles !== 'undefined') {
payload['roles'] = roles;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Get team
*
@@ -89,136 +89,137 @@ export class Teams extends Service {
*
* @param {string} teamId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async get(teamId: string): Promise> {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update name
*
- * Update the team's name by its unique ID.
+ * Update the team's name by its unique ID.
*
* @param {string} teamId
* @param {string} name
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise>}
+ */
async updateName(teamId: string, name: string): Promise> {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
if (typeof name === 'undefined') {
throw new AppwriteException('Missing required parameter: "name"');
}
-
const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId);
const payload: Payload = {};
-
if (typeof name !== 'undefined') {
payload['name'] = name;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Delete team
*
- * Delete a team using its ID. Only team members with the owner role can
- * delete the team.
+ * Delete a team using its ID. Only team members with the owner role can delete the team.
*
* @param {string} teamId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async delete(teamId: string): Promise<{}> {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('delete', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'delete',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* List team memberships
*
- * Use this endpoint to list a team's members using the team's ID. All team
- * members have read access to this endpoint.
+ * Use this endpoint to list a team's members using the team's ID. All team members have read access to this endpoint.
*
* @param {string} teamId
* @param {string[]} queries
* @param {string} search
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async listMemberships(teamId: string, queries?: string[], search?: string): Promise {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId);
const payload: Payload = {};
-
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
-
if (typeof search !== 'undefined') {
payload['search'] = search;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Create team membership
*
- * Invite a new member to join your team. Provide an ID for existing users, or
- * invite unregistered users using an email or phone number. If initiated from
- * a Client SDK, Appwrite will send an email or sms with a link to join the
- * team to the invited user, and an account will be created for them if one
- * doesn't exist. If initiated from a Server SDK, the new member will be added
- * automatically to the team.
- *
- * You only need to provide one of a user ID, email, or phone number. Appwrite
- * will prioritize accepting the user ID > email > phone number if you provide
- * more than one of these parameters.
- *
- * Use the `url` parameter to redirect the user from the invitation email to
- * your app. After the user is redirected, use the [Update Team Membership
- * Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus)
- * endpoint to allow the user to accept the invitation to the team.
- *
- * Please note that to avoid a [Redirect
- * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
- * Appwrite will accept the only redirect URLs under the domains you have
- * added as a platform on the Appwrite Console.
- *
+ * Invite a new member to join your team. Provide an ID for existing users, or invite unregistered users using an email or phone number. If initiated from a Client SDK, Appwrite will send an email or sms with a link to join the team to the invited user, and an account will be created for them if one doesn't exist. If initiated from a Server SDK, the new member will be added automatically to the team.
+
+You only need to provide one of a user ID, email, or phone number. Appwrite will prioritize accepting the user ID > email > phone number if you provide more than one of these parameters.
+
+Use the `url` parameter to redirect the user from the invitation email to your app. After the user is redirected, use the [Update Team Membership Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) endpoint to allow the user to accept the invitation to the team.
+
+Please note that to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) Appwrite will accept the only redirect URLs under the domains you have added as a platform on the Appwrite Console.
+
*
* @param {string} teamId
* @param {string[]} roles
@@ -228,257 +229,262 @@ export class Teams extends Service {
* @param {string} url
* @param {string} name
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async createMembership(teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
if (typeof roles === 'undefined') {
throw new AppwriteException('Missing required parameter: "roles"');
}
-
const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId);
const payload: Payload = {};
-
if (typeof email !== 'undefined') {
payload['email'] = email;
}
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof phone !== 'undefined') {
payload['phone'] = phone;
}
-
if (typeof roles !== 'undefined') {
payload['roles'] = roles;
}
-
if (typeof url !== 'undefined') {
payload['url'] = url;
}
-
if (typeof name !== 'undefined') {
payload['name'] = name;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('post', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'post',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Get team membership
*
- * Get a team member by the membership unique id. All team members have read
- * access for this resource.
+ * Get a team member by the membership unique id. All team members have read access for this resource.
*
* @param {string} teamId
* @param {string} membershipId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async getMembership(teamId: string, membershipId: string): Promise {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
if (typeof membershipId === 'undefined') {
throw new AppwriteException('Missing required parameter: "membershipId"');
}
-
const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update membership
*
- * Modify the roles of a team member. Only team members with the owner role
- * have access to this endpoint. Learn more about [roles and
- * permissions](https://appwrite.io/docs/permissions).
- *
+ * Modify the roles of a team member. Only team members with the owner role have access to this endpoint. Learn more about [roles and permissions](https://appwrite.io/docs/permissions).
+
*
* @param {string} teamId
* @param {string} membershipId
* @param {string[]} roles
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updateMembership(teamId: string, membershipId: string, roles: string[]): Promise {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
if (typeof membershipId === 'undefined') {
throw new AppwriteException('Missing required parameter: "membershipId"');
}
-
if (typeof roles === 'undefined') {
throw new AppwriteException('Missing required parameter: "roles"');
}
-
const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
const payload: Payload = {};
-
if (typeof roles !== 'undefined') {
payload['roles'] = roles;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Delete team membership
*
- * This endpoint allows a user to leave a team or for a team owner to delete
- * the membership of any other team member. You can also use this endpoint to
- * delete a user membership even if it is not accepted.
+ * This endpoint allows a user to leave a team or for a team owner to delete the membership of any other team member. You can also use this endpoint to delete a user membership even if it is not accepted.
*
* @param {string} teamId
* @param {string} membershipId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise<{}>}
+ */
async deleteMembership(teamId: string, membershipId: string): Promise<{}> {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
if (typeof membershipId === 'undefined') {
throw new AppwriteException('Missing required parameter: "membershipId"');
}
-
const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('delete', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'delete',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update team membership status
*
- * Use this endpoint to allow a user to accept an invitation to join a team
- * after being redirected back to your app from the invitation email received
- * by the user.
- *
- * If the request is successful, a session for the user is automatically
- * created.
- *
+ * Use this endpoint to allow a user to accept an invitation to join a team after being redirected back to your app from the invitation email received by the user.
+
+If the request is successful, a session for the user is automatically created.
+
*
* @param {string} teamId
* @param {string} membershipId
* @param {string} userId
* @param {string} secret
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updateMembershipStatus(teamId: string, membershipId: string, userId: string, secret: string): Promise {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
if (typeof membershipId === 'undefined') {
throw new AppwriteException('Missing required parameter: "membershipId"');
}
-
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
-
if (typeof secret === 'undefined') {
throw new AppwriteException('Missing required parameter: "secret"');
}
-
const apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
const payload: Payload = {};
-
if (typeof userId !== 'undefined') {
payload['userId'] = userId;
}
-
if (typeof secret !== 'undefined') {
payload['secret'] = secret;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('patch', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'patch',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Get team preferences
*
- * Get the team's shared preferences by its unique ID. If a preference doesn't
- * need to be shared by all team members, prefer storing them in [user
- * preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs).
+ * Get the team's shared preferences by its unique ID. If a preference doesn't need to be shared by all team members, prefer storing them in [user preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs).
*
* @param {string} teamId
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async getPrefs(teamId: string): Promise {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId);
const payload: Payload = {};
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('get', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
- }
+ }
+ return await this.client.call(
+ 'get',
+ uri,
+ apiHeaders,
+ payload
+ );
+ }
/**
* Update preferences
*
- * Update the team's preferences by its unique ID. The object you pass is
- * stored as is and replaces any previous value. The maximum allowed prefs
- * size is 64kB and throws an error if exceeded.
+ * Update the team's preferences by its unique ID. The object you pass is stored as is and replaces any previous value. The maximum allowed prefs size is 64kB and throws an error if exceeded.
*
* @param {string} teamId
* @param {object} prefs
* @throws {AppwriteException}
- * @returns {Promise}
- */
+ * @returns {Promise}
+ */
async updatePrefs(teamId: string, prefs: object): Promise {
if (typeof teamId === 'undefined') {
throw new AppwriteException('Missing required parameter: "teamId"');
}
-
if (typeof prefs === 'undefined') {
throw new AppwriteException('Missing required parameter: "prefs"');
}
-
const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId);
const payload: Payload = {};
-
if (typeof prefs !== 'undefined') {
payload['prefs'] = prefs;
}
-
const uri = new URL(this.client.config.endpoint + apiPath);
- return await this.client.call('put', uri, {
+
+ const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
- }, payload);
+ }
+
+ return await this.client.call(
+ 'put',
+ uri,
+ apiHeaders,
+ payload
+ );
}
-};
+}