diff --git a/CHANGELOG.md b/CHANGELOG.md index c6c7bcb3..d78aef15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,49 +1,31 @@ # Change log -## 1.2.0-rc.4 - -* Fixed: `host()` resolves with the live connection state instead of always `null` -* Fixed: `onConnection(false)` fires when a retired or background connection closes -* Fixed: notification taps are recorded after launching the app, so tap-opened screens land on top -* Fixed: `host()` reports `false` when there was nothing to subscribe instead of a spurious open - -## 1.2.0-rc.3 - -* Added: `getInitialNotification()`, `onNotificationOpened()`, and the `PushNotificationOpened` type (topic + data) -* Added: live push connection open/close events surfaced via `onOpen`/`onClose` -* Fixed: notification taps delivered reliably once, via a `PushTaps` queue -* Fixed: foreground notifications de-duplicated per title -* Updated: `resume` leaves a live Push host's connection untouched - -## 1.2.0-rc.2 - -* Added: `Push.getInitialNotification()` returns the notification whose tap launched the app -* Added: `Push.onNotificationOpened(callback)` fires on each notification tap -* Added: `Push.backgroundStatus()` reports Android exact-alarm, battery, and foreground-service state -* Added: `Push.requestExactAlarms()` and `Push.requestIgnoreBatteryOptimizations()` helpers -* Added: `SubscribeOptions.notifyInForeground` to post notifications while the app is visible -* Added: `PushBackgroundStatus` and `PushNotificationOpened` exported types -* Fixed: reliable Android background wake-ups via a periodic watchdog and alternating jobs -* Fixed: `resume` keeps subscriptions only for the same signed-in user -* Fixed: notification images are size-capped to prevent out-of-memory crashes - -## 1.2.0-rc.1 +## 2.0.0 +* Breaking: `Teams.createMembership` takes `membershipId` after `roles`; positional callers must update +* Added: `Account.listPasskeys`, `createPasskey`, `getPasskey`, `updatePasskey` and `deletePasskey` +* Added: `Account.updatePasskeyVerification` to finish registering a passkey +* Added: `Account.createPasskeyToken` and `Account.updatePasskeyToken` for passkey sign-in +* Added: `Passkey`, `PasskeyList`, `PasskeyChallenge` and `TokenSecret` models +* Added: `Push` service for MQTT realtime push with Android background delivery +* Added: `Topic` builder, `Client.setPushEndpoint()` and `Client.setPushClientId()` * Added: background push notifications render the server `notification` title, body, and image -* Added: Android shows notification images (BigPictureStyle) and long bodies (BigTextStyle) -* Added: the SDK requests Android 13+ `POST_NOTIFICATIONS` itself on first background subscribe -* Added: notification `data` now carries `topic` and `payload` -* Fixed: a server-sent title dedupes to one notification per topic instead of one per subscription - -## 1.2.0-rc.0 - +* Added: `getInitialNotification()`, `onNotificationOpened()` and the `PushNotificationOpened` type +* Added: `onOpen`/`onClose` events for live push connections +* Added: `Push.backgroundStatus()`, `requestExactAlarms()` and `requestIgnoreBatteryOptimizations()` for Android +* Added: `SubscribeOptions.notifyInForeground` to post notifications while the app is visible +* Added: the SDK requests Android 13+ `POST_NOTIFICATIONS` on first background subscribe +* Added: `Analytics` service with `createEvent` * Added: `Apps` service to manage OAuth2 apps, keys, secrets, and installations * Added: `Oauth2` service for authorization, consent, device, PAR, and token flows -* Added: `Push` service for MQTT realtime push with Android background delivery -* Added: `Topic` builder and native TCP modules for push * Added: `Avatars.updatePhoto()` and `Avatars.deletePhoto()` methods * Added: `App`, `Oauth2*`, and `Account` models +* Added: `state` parameter to `Account.createOAuth2Session` and `Account.createOAuth2Token` +* Added: `duration` on `createEmailPasswordSession` and `current` on `deleteSessions` +* Added: `total` parameter to `Account.listSessions`, `Locale` list methods and `listTransactions` * Added: `Webflow` to the `OAuthProvider` enum +* Fixed: response models fill missing fields from spec defaults instead of throwing +* Updated: SDK now targets Appwrite 2.4 (`X-Appwrite-Response-Format: 2.4.0`) * Fixed: cookie session fallback is guarded to Expo web where `localStorage` exists ## 1.1.0 diff --git a/README.md b/README.md index 0ba50f82..ba02d900 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Appwrite React Native SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-react-native.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-2.3.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-2.4.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK targets Appwrite server version 2.3.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-react-native/releases) when APIs differ. +**This SDK targets Appwrite server version 2.4.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-react-native/releases) when APIs differ. Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the React Native SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/docs/examples/account/create-o-auth-2-session.md b/docs/examples/account/create-o-auth-2-session.md index c90edc14..48c50d96 100644 --- a/docs/examples/account/create-o-auth-2-session.md +++ b/docs/examples/account/create-o-auth-2-session.md @@ -12,5 +12,6 @@ account.createOAuth2Session({ success: 'https://example.com', // optional failure: 'https://example.com', // optional scopes: [], // optional + state: '', // optional }); ``` diff --git a/docs/examples/account/create-o-auth-2-token.md b/docs/examples/account/create-o-auth-2-token.md index c043fb78..da5ee9c8 100644 --- a/docs/examples/account/create-o-auth-2-token.md +++ b/docs/examples/account/create-o-auth-2-token.md @@ -12,5 +12,6 @@ account.createOAuth2Token({ success: 'https://example.com', // optional failure: 'https://example.com', // optional scopes: [], // optional + state: '', // optional }); ``` diff --git a/docs/examples/account/create-passkey-token.md b/docs/examples/account/create-passkey-token.md new file mode 100644 index 00000000..5695859f --- /dev/null +++ b/docs/examples/account/create-passkey-token.md @@ -0,0 +1,13 @@ +```javascript +import { Client, Account } from 'react-native-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const account = new Account(client); + +const result = await account.createPasskeyToken(); + +console.log(result); +``` diff --git a/docs/examples/account/create-passkey.md b/docs/examples/account/create-passkey.md new file mode 100644 index 00000000..66968b14 --- /dev/null +++ b/docs/examples/account/create-passkey.md @@ -0,0 +1,16 @@ +```javascript +import { Client, Account } from 'react-native-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const account = new Account(client); + +const result = await account.createPasskey({ + passkeyId: '', // optional + name: '', // optional +}); + +console.log(result); +``` diff --git a/docs/examples/account/delete-passkey.md b/docs/examples/account/delete-passkey.md new file mode 100644 index 00000000..61aec153 --- /dev/null +++ b/docs/examples/account/delete-passkey.md @@ -0,0 +1,15 @@ +```javascript +import { Client, Account } from 'react-native-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const account = new Account(client); + +const result = await account.deletePasskey({ + passkeyId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/account/get-passkey.md b/docs/examples/account/get-passkey.md new file mode 100644 index 00000000..04b7f8fb --- /dev/null +++ b/docs/examples/account/get-passkey.md @@ -0,0 +1,15 @@ +```javascript +import { Client, Account } from 'react-native-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const account = new Account(client); + +const result = await account.getPasskey({ + passkeyId: '', +}); + +console.log(result); +``` diff --git a/docs/examples/account/list-passkeys.md b/docs/examples/account/list-passkeys.md new file mode 100644 index 00000000..f1f68985 --- /dev/null +++ b/docs/examples/account/list-passkeys.md @@ -0,0 +1,16 @@ +```javascript +import { Client, Account } from 'react-native-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const account = new Account(client); + +const result = await account.listPasskeys({ + queries: [], // optional + total: false, // optional +}); + +console.log(result); +``` diff --git a/docs/examples/account/update-passkey-token.md b/docs/examples/account/update-passkey-token.md new file mode 100644 index 00000000..a8e22f7a --- /dev/null +++ b/docs/examples/account/update-passkey-token.md @@ -0,0 +1,16 @@ +```javascript +import { Client, Account } from 'react-native-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const account = new Account(client); + +const result = await account.updatePasskeyToken({ + challengeId: '', + credential: {}, +}); + +console.log(result); +``` diff --git a/docs/examples/account/update-passkey-verification.md b/docs/examples/account/update-passkey-verification.md new file mode 100644 index 00000000..c46c0a63 --- /dev/null +++ b/docs/examples/account/update-passkey-verification.md @@ -0,0 +1,16 @@ +```javascript +import { Client, Account } from 'react-native-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const account = new Account(client); + +const result = await account.updatePasskeyVerification({ + passkeyId: '', + credential: {}, +}); + +console.log(result); +``` diff --git a/docs/examples/account/update-passkey.md b/docs/examples/account/update-passkey.md new file mode 100644 index 00000000..2f925b98 --- /dev/null +++ b/docs/examples/account/update-passkey.md @@ -0,0 +1,16 @@ +```javascript +import { Client, Account } from 'react-native-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const account = new Account(client); + +const result = await account.updatePasskey({ + passkeyId: '', + name: '', +}); + +console.log(result); +``` diff --git a/docs/examples/analytics/create-event.md b/docs/examples/analytics/create-event.md new file mode 100644 index 00000000..eefca061 --- /dev/null +++ b/docs/examples/analytics/create-event.md @@ -0,0 +1,27 @@ +```javascript +import { Client, Analytics } from 'react-native-appwrite'; + +const client = new Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const analytics = new Analytics(client); + +const result = await analytics.createEvent({ + propertyId: '', + name: '', + url: 'https://example.com', + domain: '', // optional + referrer: '', // optional + screenWidth: null, // optional + sessionHash: '', // optional + scrollDepth: 0, // optional + engagementTime: 0, // optional + props: [], // optional + userId: '', // optional + ip: '', // optional + userAgent: '', // optional +}); + +console.log(result); +``` diff --git a/docs/examples/oauth2/authorize-post.md b/docs/examples/oauth2/authorize-post.md index e27aa7e3..f7dd540c 100644 --- a/docs/examples/oauth2/authorize-post.md +++ b/docs/examples/oauth2/authorize-post.md @@ -19,7 +19,7 @@ const result = await oauth2.authorizePost({ prompt: '', // optional maxAge: 0, // optional authorizationDetails: '', // optional - resource: '', // optional + resource: [], // optional audience: '', // optional requestUri: '', // optional }); diff --git a/docs/examples/oauth2/authorize.md b/docs/examples/oauth2/authorize.md index 039dc744..256e9cb6 100644 --- a/docs/examples/oauth2/authorize.md +++ b/docs/examples/oauth2/authorize.md @@ -19,7 +19,7 @@ const result = await oauth2.authorize({ prompt: '', // optional maxAge: 0, // optional authorizationDetails: '', // optional - resource: '', // optional + resource: [], // optional audience: '', // optional requestUri: '', // optional }); diff --git a/docs/examples/oauth2/create-device-authorization.md b/docs/examples/oauth2/create-device-authorization.md index c136011b..1219db51 100644 --- a/docs/examples/oauth2/create-device-authorization.md +++ b/docs/examples/oauth2/create-device-authorization.md @@ -11,7 +11,7 @@ const result = await oauth2.createDeviceAuthorization({ clientId: '', // optional scope: '', // optional authorizationDetails: '', // optional - resource: '', // optional + resource: [], // optional audience: '', // optional }); diff --git a/docs/examples/oauth2/create-par.md b/docs/examples/oauth2/create-par.md index 5d9b5783..425e7a86 100644 --- a/docs/examples/oauth2/create-par.md +++ b/docs/examples/oauth2/create-par.md @@ -19,7 +19,7 @@ const result = await oauth2.createPAR({ prompt: '', // optional maxAge: 0, // optional authorizationDetails: '', // optional - resource: '', // optional + resource: [], // optional audience: '', // optional }); diff --git a/docs/examples/oauth2/create-token.md b/docs/examples/oauth2/create-token.md index 3be9ff4a..567bfb74 100644 --- a/docs/examples/oauth2/create-token.md +++ b/docs/examples/oauth2/create-token.md @@ -16,7 +16,7 @@ const result = await oauth2.createToken({ clientSecret: '', // optional codeVerifier: '', // optional redirectUri: 'https://example.com', // optional - resource: '', // optional + resource: [], // optional audience: '', // optional }); diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index 3c6ee849..e2d206e7 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -10,6 +10,7 @@ const teams = new Teams(client); const result = await teams.createMembership({ teamId: '', roles: ['editor'], + membershipId: '', // optional email: 'email@example.com', // optional userId: '', // optional phone: '+12065550100', // optional diff --git a/package-lock.json b/package-lock.json index 33230e5f..bbf4775e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "react-native-appwrite", - "version": "1.2.0-rc.4", + "version": "2.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "react-native-appwrite", - "version": "1.2.0-rc.4", + "version": "2.0.0", "license": "BSD-3-Clause", "dependencies": { "buffer": "6.0.3", diff --git a/package.json b/package.json index 12b4f76a..b36e9cfc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API", - "version": "1.2.0-rc.4", + "version": "2.0.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index 4bc8575c..2fa4bf31 100644 --- a/src/client.ts +++ b/src/client.ts @@ -45,6 +45,50 @@ export const JSONbig = { stringify: JSONbigSerializer.stringify, }; +type DefaultsShape = string | { items: DefaultsShape }; + +type DefaultsModel = { + defaults?: Record; + properties?: Record; +}; + +type Defaults = { + root: DefaultsShape; + models: Record; +}; + +export function applyDefaults(value: T, tree: Defaults): T { + return fillDefaults(value, tree.root, tree.models) as T; +} + +function fillDefaults( + value: unknown, + shape: DefaultsShape, + models: Record, +): unknown { + if (typeof shape !== 'string') { + if (!Array.isArray(value)) { + return value; + } + const items = shape.items; + return value.map((item) => fillDefaults(item, items, models)); + } + const model = models[shape]; + if (!model || typeof value !== 'object' || value === null) { + return value; + } + if (Array.isArray(value)) { + return value; + } + const result: Record = { ...model.defaults, ...value }; + for (const [key, child] of Object.entries(model.properties ?? {})) { + if (key in result) { + result[key] = fillDefaults(result[key], child, models); + } + } + return result; +} + type Payload = { [key: string]: any; }; @@ -218,8 +262,8 @@ class Client { 'x-sdk-name': 'React Native', 'x-sdk-platform': 'client', 'x-sdk-language': 'reactnative', - 'x-sdk-version': '1.2.0-rc.4', - 'X-Appwrite-Response-Format': '2.3.0', + 'x-sdk-version': '2.0.0', + 'X-Appwrite-Response-Format': '2.4.0', }; /** diff --git a/src/index.ts b/src/index.ts index 579ed73a..a5b728ec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export { Client, AppwriteException } from './client'; export { Account } from './services/account'; +export { Analytics } from './services/analytics'; export { Apps } from './services/apps'; export { Avatars } from './services/avatars'; export { Databases } from './services/databases'; diff --git a/src/models.ts b/src/models.ts index 09b8b39c..f11c898e 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1381,6 +1381,102 @@ export namespace Models { expire: string; }; + /** + * Token Secret + */ + export type TokenSecret = { + /** + * Token ID. + */ + $id: string; + /** + * Token creation date in ISO 8601 format. + */ + $createdAt: string; + /** + * User ID. + */ + userId: string; + /** + * Token secret key. Exchange it for a session with the create session endpoint. + */ + secret: string; + /** + * Token expiration date in ISO 8601 format. + */ + expire: string; + /** + * Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. + */ + phrase: string; + }; + + /** + * Passkey + */ + export type Passkey = { + /** + * Passkey ID. + */ + $id: string; + /** + * Passkey creation date in ISO 8601 format. + */ + $createdAt: string; + /** + * Passkey update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Passkey name. + */ + name: string; + /** + * Most recent sign-in with this passkey in ISO 8601 format. Empty until the passkey is used to sign in. + */ + accessedAt: string; + }; + + /** + * Passkey Challenge + */ + export type PasskeyChallenge = { + /** + * Challenge ID. When signing in, pass it back with the credential to receive a token. + */ + $id: string; + /** + * Challenge creation date in ISO 8601 format. + */ + $createdAt: string; + /** + * ID of the passkey being registered. Empty for sign-in challenges. + */ + passkeyId: string; + /** + * Challenge expiration date in ISO 8601 format. + */ + expire: string; + /** + * WebAuthn options in JSON form. Pass them to `PublicKeyCredential.parseCreationOptionsFromJSON()` when registering, or `PublicKeyCredential.parseRequestOptionsFromJSON()` when signing in. + */ + publicKey: object; + }; + + /** + * Passkeys List + */ + export type PasskeyList = { + /** + * Total number of passkeys that matched your query. + */ + total: number; + /** + * List of passkeys. + */ + passkeys: Passkey[]; + }; + /** * MFA Recovery Codes */ diff --git a/src/services/account.ts b/src/services/account.ts index fb3d545b..60361c99 100644 --- a/src/services/account.ts +++ b/src/services/account.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -25,7 +25,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -34,6 +34,48 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -143,7 +185,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -153,6 +195,48 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -218,7 +302,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -227,6 +311,37 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2ConsentList', + models: { + oauth2ConsentList: { + defaults: { + total: 0, + }, + properties: { + consents: { + items: 'oauth2Consent', + }, + }, + }, + oauth2Consent: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + appId: '', + cimdUrl: '', + scopes: [], + resources: [], + authorizationDetails: '[]', + expire: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -278,7 +393,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -287,6 +402,27 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2Consent', + models: { + oauth2Consent: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + appId: '', + cimdUrl: '', + scopes: [], + resources: [], + authorizationDetails: '[]', + expire: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -427,7 +563,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -436,6 +572,38 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2ConsentTokenList', + models: { + oauth2ConsentTokenList: { + defaults: { + total: 0, + }, + properties: { + tokens: { + items: 'oauth2ConsentToken', + }, + }, + }, + oauth2ConsentToken: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + consentId: '', + userId: '', + appId: '', + cimdUrl: '', + scopes: [], + resources: [], + authorizationDetails: '[]', + expire: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -506,7 +674,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -515,6 +683,28 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2ConsentToken', + models: { + oauth2ConsentToken: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + consentId: '', + userId: '', + appId: '', + cimdUrl: '', + scopes: [], + resources: [], + authorizationDetails: '[]', + expire: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -673,7 +863,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -683,6 +873,48 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -748,7 +980,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -757,6 +989,38 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'identityList', + models: { + identityList: { + defaults: { + total: 0, + }, + properties: { + identities: { + items: 'identity', + }, + }, + }, + identity: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + provider: '', + providerUid: '', + providerEmail: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + providerIdToken: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -865,7 +1129,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -875,6 +1139,18 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'jwt', + models: { + jwt: { + defaults: { + jwt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -931,7 +1207,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -941,6 +1217,48 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -994,7 +1312,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1004,6 +1322,19 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaType', + models: { + mfaType: { + defaults: { + secret: '', + uri: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1056,7 +1387,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1066,6 +1397,19 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaType', + models: { + mfaType: { + defaults: { + secret: '', + uri: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1143,7 +1487,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -1153,6 +1497,48 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1229,7 +1615,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -1239,6 +1625,48 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1416,7 +1844,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1426,6 +1854,21 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaChallenge', + models: { + mfaChallenge: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + expire: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1481,7 +1924,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1491,6 +1934,21 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaChallenge', + models: { + mfaChallenge: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + expire: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1566,7 +2024,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -1576,6 +2034,46 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'session', + models: { + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1650,7 +2148,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -1660,6 +2158,46 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'session', + models: { + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1674,7 +2212,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1683,6 +2221,22 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaFactors', + models: { + mfaFactors: { + defaults: { + totp: false, + phone: false, + email: false, + recoveryCode: false, + custom: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1696,7 +2250,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1705,6 +2259,22 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaFactors', + models: { + mfaFactors: { + defaults: { + totp: false, + phone: false, + email: false, + recoveryCode: false, + custom: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1719,7 +2289,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1728,6 +2298,18 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaRecoveryCodes', + models: { + mfaRecoveryCodes: { + defaults: { + recoveryCodes: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1741,7 +2323,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1750,6 +2332,18 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaRecoveryCodes', + models: { + mfaRecoveryCodes: { + defaults: { + recoveryCodes: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1764,7 +2358,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1774,6 +2368,18 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaRecoveryCodes', + models: { + mfaRecoveryCodes: { + defaults: { + recoveryCodes: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1787,7 +2393,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1797,6 +2403,18 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaRecoveryCodes', + models: { + mfaRecoveryCodes: { + defaults: { + recoveryCodes: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1811,7 +2429,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1821,6 +2439,18 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'mfaRecoveryCodes', + models: { + mfaRecoveryCodes: { + defaults: { + recoveryCodes: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1833,9 +2463,551 @@ export class Account extends Service { const apiPath = '/account/mfa/recovery-codes'; const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + const request = this.client.call( + 'patch', + uri, + { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }, + apiPayload, + ); + const defaults = { + root: 'mfaRecoveryCodes', + models: { + mfaRecoveryCodes: { + defaults: { + recoveryCodes: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Update currently logged in user account name. + * + * @param {string} params.name - User name. Max length: 128 chars. + * @throws {AppwriteException} + * @returns {Promise} + */ + updateName< + Preferences extends Models.Preferences = Models.DefaultPreferences, + >(params: { name: string }): Promise>; + /** + * Update currently logged in user account name. + * + * @param {string} name - User name. Max length: 128 chars. + * @throws {AppwriteException} + * @returns {Promise>} + * @deprecated Use the object parameter style method for a better developer experience. + */ + updateName< + Preferences extends Models.Preferences = Models.DefaultPreferences, + >(name: string): Promise>; + updateName< + Preferences extends Models.Preferences = Models.DefaultPreferences, + >( + paramsOrFirst: { name: string } | string, + ): Promise> { + let params: { name: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { name: string }; + } else { + params = { + name: paramsOrFirst as string, + }; + } + + const name = params.name; + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/account/name'; + const apiPayload: Payload = {}; + + if (typeof name !== 'undefined') { + apiPayload['name'] = name; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + const request = this.client.call( + 'patch', + uri, + { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }, + apiPayload, + ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Get the list of verified passkeys registered by the currently logged in user. + * + * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter and order on the following attributes: $id, $createdAt, $updatedAt, name, accessedAt + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + */ + listPasskeys(params?: { + queries?: string[]; + total?: boolean; + }): Promise; + /** + * Get the list of verified passkeys registered by the currently logged in user. + * + * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter and order on the following attributes: $id, $createdAt, $updatedAt, name, accessedAt + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + listPasskeys( + queries?: string[], + total?: boolean, + ): Promise; + listPasskeys( + paramsOrFirst?: { queries?: string[]; total?: boolean } | string[], + ...rest: [boolean?] + ): Promise { + let params: { queries?: string[]; total?: boolean }; + + if ( + (typeof paramsOrFirst === 'undefined' && rest.length === 0) || + (paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst)) + ) { + params = (paramsOrFirst || {}) as { + queries?: string[]; + total?: boolean; + }; + } else { + params = { + queries: paramsOrFirst as string[], + total: rest[0] as boolean, + }; + } + + const queries = params.queries; + const total = params.total; + + const apiPath = '/account/passkeys'; + const apiPayload: Payload = {}; + + if (typeof queries !== 'undefined') { + apiPayload['queries'] = queries; + } + + if (typeof total !== 'undefined') { + apiPayload['total'] = total; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + const request = this.client.call( + 'get', + uri, + { + 'X-Appwrite-Project': this.client.config.project, + accept: 'application/json', + }, + apiPayload, + ); + const defaults = { + root: 'passkeyList', + models: { + passkeyList: { + defaults: { + total: 0, + }, + properties: { + passkeys: { + items: 'passkey', + }, + }, + }, + passkey: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + accessedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Start registering a passkey for the currently logged in user. The session must have signed in or completed an MFA challenge within the last 10 minutes. Pass the returned `publicKey` options to `navigator.credentials.create()`, then complete the registration with [Update passkey verification](/docs/references/cloud/client-web/account#updatePasskeyVerification). The passkey stays pending until verified, and the challenge expires after 5 minutes. + * + * @param {string} params.passkeyId - Passkey ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param {string} params.name - Passkey name, shown when listing passkeys. Max length: 128 chars. + * @throws {AppwriteException} + * @returns {Promise} + */ + createPasskey(params?: { + passkeyId?: string; + name?: string; + }): Promise; + /** + * Start registering a passkey for the currently logged in user. The session must have signed in or completed an MFA challenge within the last 10 minutes. Pass the returned `publicKey` options to `navigator.credentials.create()`, then complete the registration with [Update passkey verification](/docs/references/cloud/client-web/account#updatePasskeyVerification). The passkey stays pending until verified, and the challenge expires after 5 minutes. + * + * @param {string} passkeyId - Passkey ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param {string} name - Passkey name, shown when listing passkeys. Max length: 128 chars. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + createPasskey( + passkeyId?: string, + name?: string, + ): Promise; + createPasskey( + paramsOrFirst?: { passkeyId?: string; name?: string } | string, + ...rest: [string?] + ): Promise { + let params: { passkeyId?: string; name?: string }; + + if ( + (typeof paramsOrFirst === 'undefined' && rest.length === 0) || + (paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst)) + ) { + params = (paramsOrFirst || {}) as { + passkeyId?: string; + name?: string; + }; + } else { + params = { + passkeyId: paramsOrFirst as string, + name: rest[0] as string, + }; + } + + const passkeyId = params.passkeyId; + const name = params.name; + + const apiPath = '/account/passkeys'; + const apiPayload: Payload = {}; + + if (typeof passkeyId !== 'undefined') { + apiPayload['passkeyId'] = passkeyId; + } + + if (typeof name !== 'undefined') { + apiPayload['name'] = name; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + const request = this.client.call( + 'post', + uri, + { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }, + apiPayload, + ); + const defaults = { + root: 'passkeyChallenge', + models: { + passkeyChallenge: { + defaults: { + $id: '', + $createdAt: '', + passkeyId: '', + expire: '', + publicKey: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Get a verified passkey of the currently logged in user by its unique ID. + * + * @param {string} params.passkeyId - Passkey ID. + * @throws {AppwriteException} + * @returns {Promise} + */ + getPasskey(params: { passkeyId: string }): Promise; + /** + * Get a verified passkey of the currently logged in user by its unique ID. + * + * @param {string} passkeyId - Passkey ID. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + getPasskey(passkeyId: string): Promise; + getPasskey( + paramsOrFirst: { passkeyId: string } | string, + ): Promise { + let params: { passkeyId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { passkeyId: string }; + } else { + params = { + passkeyId: paramsOrFirst as string, + }; + } + + const passkeyId = params.passkeyId; + + if (typeof passkeyId === 'undefined' || passkeyId === '') { + throw new AppwriteException( + 'Missing required parameter: "passkeyId"', + ); + } + + const apiPath = '/account/passkeys/{passkeyId}'.replace( + '{passkeyId}', + encodeURIComponent(String(passkeyId)), + ); + const apiPayload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + apiPath); + const request = this.client.call( + 'get', + uri, + { + 'X-Appwrite-Project': this.client.config.project, + accept: 'application/json', + }, + apiPayload, + ); + const defaults = { + root: 'passkey', + models: { + passkey: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + accessedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Rename a passkey of the currently logged in user. + * + * @param {string} params.passkeyId - Passkey ID. + * @param {string} params.name - Passkey name. Max length: 128 chars. + * @throws {AppwriteException} + * @returns {Promise} + */ + updatePasskey(params: { + passkeyId: string; + name: string; + }): Promise; + /** + * Rename a passkey of the currently logged in user. + * + * @param {string} passkeyId - Passkey ID. + * @param {string} name - Passkey name. Max length: 128 chars. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + updatePasskey(passkeyId: string, name: string): Promise; + updatePasskey( + paramsOrFirst: { passkeyId: string; name: string } | string, + ...rest: [string?] + ): Promise { + let params: { passkeyId: string; name: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + passkeyId: string; + name: string; + }; + } else { + params = { + passkeyId: paramsOrFirst as string, + name: rest[0] as string, + }; + } + + const passkeyId = params.passkeyId; + const name = params.name; + + if (typeof passkeyId === 'undefined' || passkeyId === '') { + throw new AppwriteException( + 'Missing required parameter: "passkeyId"', + ); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + const apiPath = '/account/passkeys/{passkeyId}'.replace( + '{passkeyId}', + encodeURIComponent(String(passkeyId)), + ); + const apiPayload: Payload = {}; + + if (typeof name !== 'undefined') { + apiPayload['name'] = name; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + const request = this.client.call( + 'patch', + uri, + { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }, + apiPayload, + ); + const defaults = { + root: 'passkey', + models: { + passkey: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + accessedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Delete a passkey from the currently logged in user. The passkey can no longer be used to sign in, although it may remain stored on the user's device. The session must have signed in or completed an MFA challenge within the last 10 minutes. + * + * @param {string} params.passkeyId - Passkey ID. + * @throws {AppwriteException} + * @returns {Promise} + */ + deletePasskey(params: { passkeyId: string }): Promise<{}>; + /** + * Delete a passkey from the currently logged in user. The passkey can no longer be used to sign in, although it may remain stored on the user's device. The session must have signed in or completed an MFA challenge within the last 10 minutes. + * + * @param {string} passkeyId - Passkey ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + * @deprecated Use the object parameter style method for a better developer experience. + */ + deletePasskey(passkeyId: string): Promise<{}>; + deletePasskey(paramsOrFirst: { passkeyId: string } | string): Promise<{}> { + let params: { passkeyId: string }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { passkeyId: string }; + } else { + params = { + passkeyId: paramsOrFirst as string, + }; + } + + const passkeyId = params.passkeyId; + + if (typeof passkeyId === 'undefined' || passkeyId === '') { + throw new AppwriteException( + 'Missing required parameter: "passkeyId"', + ); + } + + const apiPath = '/account/passkeys/{passkeyId}'.replace( + '{passkeyId}', + encodeURIComponent(String(passkeyId)), + ); + const apiPayload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); return this.client.call( - 'patch', + 'delete', uri, { 'X-Appwrite-Project': this.client.config.project, @@ -1847,61 +3019,80 @@ export class Account extends Service { } /** - * Update currently logged in user account name. + * Complete a passkey registration started with [Create passkey](/docs/references/cloud/client-web/account#createPasskey). Pass the JSON form of the credential returned by `navigator.credentials.create()`, for example `credential.toJSON()`. Each registration can be verified once; a failed attempt requires starting it again. * - * @param {string} params.name - User name. Max length: 128 chars. + * @param {string} params.passkeyId - Passkey ID. + * @param {object} params.credential - Registration credential returned by the authenticator, in the JSON form produced by `PublicKeyCredential.toJSON()`. * @throws {AppwriteException} * @returns {Promise} */ - updateName< - Preferences extends Models.Preferences = Models.DefaultPreferences, - >(params: { name: string }): Promise>; + updatePasskeyVerification(params: { + passkeyId: string; + credential: object; + }): Promise; /** - * Update currently logged in user account name. + * Complete a passkey registration started with [Create passkey](/docs/references/cloud/client-web/account#createPasskey). Pass the JSON form of the credential returned by `navigator.credentials.create()`, for example `credential.toJSON()`. Each registration can be verified once; a failed attempt requires starting it again. * - * @param {string} name - User name. Max length: 128 chars. + * @param {string} passkeyId - Passkey ID. + * @param {object} credential - Registration credential returned by the authenticator, in the JSON form produced by `PublicKeyCredential.toJSON()`. * @throws {AppwriteException} - * @returns {Promise>} + * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - updateName< - Preferences extends Models.Preferences = Models.DefaultPreferences, - >(name: string): Promise>; - updateName< - Preferences extends Models.Preferences = Models.DefaultPreferences, - >( - paramsOrFirst: { name: string } | string, - ): Promise> { - let params: { name: string }; + updatePasskeyVerification( + passkeyId: string, + credential: object, + ): Promise; + updatePasskeyVerification( + paramsOrFirst: { passkeyId: string; credential: object } | string, + ...rest: [object?] + ): Promise { + let params: { passkeyId: string; credential: object }; if ( paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) ) { - params = (paramsOrFirst || {}) as { name: string }; + params = (paramsOrFirst || {}) as { + passkeyId: string; + credential: object; + }; } else { params = { - name: paramsOrFirst as string, + passkeyId: paramsOrFirst as string, + credential: rest[0] as object, }; } - const name = params.name; + const passkeyId = params.passkeyId; + const credential = params.credential; - if (typeof name === 'undefined') { - throw new AppwriteException('Missing required parameter: "name"'); + if (typeof passkeyId === 'undefined' || passkeyId === '') { + throw new AppwriteException( + 'Missing required parameter: "passkeyId"', + ); } - const apiPath = '/account/name'; + if (typeof credential === 'undefined') { + throw new AppwriteException( + 'Missing required parameter: "credential"', + ); + } + + const apiPath = '/account/passkeys/{passkeyId}/verification'.replace( + '{passkeyId}', + encodeURIComponent(String(passkeyId)), + ); const apiPayload: Payload = {}; - if (typeof name !== 'undefined') { - apiPayload['name'] = name; + if (typeof credential !== 'undefined') { + apiPayload['credential'] = credential; } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( - 'patch', + const request = this.client.call( + 'put', uri, { 'X-Appwrite-Project': this.client.config.project, @@ -1910,6 +3101,22 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'passkey', + models: { + passkey: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + accessedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1986,7 +3193,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1996,6 +3203,48 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -2073,7 +3322,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -2083,6 +3332,48 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -2166,7 +3457,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -2176,6 +3467,48 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -2242,7 +3575,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -2252,6 +3585,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -2346,7 +3696,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -2356,6 +3706,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -2427,7 +3794,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -2437,6 +3804,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -2529,7 +3913,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -2539,6 +3923,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -2586,7 +3987,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -2595,6 +3996,56 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'sessionList', + models: { + sessionList: { + defaults: { + total: 0, + }, + properties: { + sessions: { + items: 'session', + }, + }, + }, + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -2665,7 +4116,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -2675,6 +4126,46 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'session', + models: { + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -2765,7 +4256,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -2775,6 +4266,46 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'session', + models: { + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -2939,7 +4470,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -2949,6 +4480,46 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'session', + models: { + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -3022,7 +4593,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -3032,6 +4603,46 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'session', + models: { + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -3046,6 +4657,7 @@ export class Account extends Service { * @param {string} params.success - URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string} params.failure - URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string[]} params.scopes - A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. + * @param {string} params.state - An opaque value your app generates and keeps, for example in a cookie. It is returned unchanged as the `state` query parameter on the success and failure URLs, so your app can check that the sign-in it receives is one it started. Printable ASCII only (RFC 6749 Appendix A.5). Max length: 256 chars. * @throws {AppwriteException} * @returns {void|string} */ @@ -3054,6 +4666,7 @@ export class Account extends Service { success?: string; failure?: string; scopes?: string[]; + state?: string; }): void | URL; /** * 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. @@ -3067,6 +4680,7 @@ export class Account extends Service { * @param {string} success - URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string} failure - URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string[]} scopes - A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. + * @param {string} state - An opaque value your app generates and keeps, for example in a cookie. It is returned unchanged as the `state` query parameter on the success and failure URLs, so your app can check that the sign-in it receives is one it started. Printable ASCII only (RFC 6749 Appendix A.5). Max length: 256 chars. * @throws {AppwriteException} * @returns {void | URL} * @deprecated Use the object parameter style method for a better developer experience. @@ -3076,6 +4690,7 @@ export class Account extends Service { success?: string, failure?: string, scopes?: string[], + state?: string, ): void | URL; createOAuth2Session( paramsOrFirst: @@ -3084,15 +4699,17 @@ export class Account extends Service { success?: string; failure?: string; scopes?: string[]; + state?: string; } | OAuthProvider, - ...rest: [string?, string?, string[]?] + ...rest: [string?, string?, string[]?, string?] ): void | URL { let params: { provider: OAuthProvider; success?: string; failure?: string; scopes?: string[]; + state?: string; }; if ( @@ -3102,13 +4719,15 @@ export class Account extends Service { ('provider' in paramsOrFirst || 'success' in paramsOrFirst || 'failure' in paramsOrFirst || - 'scopes' in paramsOrFirst) + 'scopes' in paramsOrFirst || + 'state' in paramsOrFirst) ) { params = (paramsOrFirst || {}) as { provider: OAuthProvider; success?: string; failure?: string; scopes?: string[]; + state?: string; }; } else { params = { @@ -3116,6 +4735,7 @@ export class Account extends Service { success: rest[0] as string, failure: rest[1] as string, scopes: rest[2] as string[], + state: rest[3] as string, }; } @@ -3123,6 +4743,7 @@ export class Account extends Service { const success = params.success; const failure = params.failure; const scopes = params.scopes; + const state = params.state; if (typeof provider === 'undefined') { throw new AppwriteException( @@ -3148,6 +4769,10 @@ export class Account extends Service { apiPayload['scopes'] = scopes; } + if (typeof state !== 'undefined') { + apiPayload['state'] = state; + } + const uri = new URL(this.client.config.endpoint + apiPath); apiPayload['project'] = this.client.config.project; @@ -3227,7 +4852,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -3237,6 +4862,46 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'session', + models: { + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -3306,7 +4971,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -3316,6 +4981,46 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'session', + models: { + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -3367,7 +5072,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -3376,6 +5081,46 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'session', + models: { + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -3427,7 +5172,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -3437,6 +5182,46 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'session', + models: { + session: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + expire: '', + provider: '', + providerUid: '', + providerAccessToken: '', + providerAccessTokenExpiry: '', + providerRefreshToken: '', + ip: '', + osCode: '', + osName: '', + osVersion: '', + clientType: '', + clientCode: '', + clientName: '', + clientVersion: '', + clientEngine: '', + clientEngineVersion: '', + deviceName: '', + deviceBrand: '', + deviceModel: '', + countryCode: '', + countryName: '', + current: false, + factors: [], + secret: '', + mfaUpdatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -3511,7 +5296,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -3521,6 +5306,48 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'user', + models: { + user: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + registration: '', + status: true, + labels: [], + passwordUpdate: '', + email: '', + phone: '', + emailVerification: false, + phoneVerification: false, + mfa: false, + accessedAt: '', + }, + properties: { + targets: { + items: 'target', + }, + }, + }, + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -3614,7 +5441,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -3624,6 +5451,25 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'target', + models: { + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -3699,7 +5545,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -3709,6 +5555,25 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'target', + models: { + target: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + userId: '', + providerType: '', + identifier: '', + expired: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -3860,7 +5725,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -3870,6 +5735,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -3977,7 +5859,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -3987,6 +5869,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -4002,6 +5901,7 @@ export class Account extends Service { * @param {string} params.success - URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string} params.failure - URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string[]} params.scopes - A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. + * @param {string} params.state - An opaque value your app generates and keeps, for example in a cookie. It is returned unchanged as the `state` query parameter on the success and failure URLs, so your app can check that the sign-in it receives is one it started. Printable ASCII only (RFC 6749 Appendix A.5). Max length: 256 chars. * @throws {AppwriteException} * @returns {void|string} */ @@ -4010,6 +5910,7 @@ export class Account extends Service { success?: string; failure?: string; scopes?: string[]; + state?: string; }): void | URL; /** * 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. @@ -4024,6 +5925,7 @@ export class Account extends Service { * @param {string} success - URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string} failure - URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string[]} scopes - A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. + * @param {string} state - An opaque value your app generates and keeps, for example in a cookie. It is returned unchanged as the `state` query parameter on the success and failure URLs, so your app can check that the sign-in it receives is one it started. Printable ASCII only (RFC 6749 Appendix A.5). Max length: 256 chars. * @throws {AppwriteException} * @returns {void | URL} * @deprecated Use the object parameter style method for a better developer experience. @@ -4033,6 +5935,7 @@ export class Account extends Service { success?: string, failure?: string, scopes?: string[], + state?: string, ): void | URL; createOAuth2Token( paramsOrFirst: @@ -4041,15 +5944,17 @@ export class Account extends Service { success?: string; failure?: string; scopes?: string[]; + state?: string; } | OAuthProvider, - ...rest: [string?, string?, string[]?] + ...rest: [string?, string?, string[]?, string?] ): void | URL { let params: { provider: OAuthProvider; success?: string; failure?: string; scopes?: string[]; + state?: string; }; if ( @@ -4059,13 +5964,15 @@ export class Account extends Service { ('provider' in paramsOrFirst || 'success' in paramsOrFirst || 'failure' in paramsOrFirst || - 'scopes' in paramsOrFirst) + 'scopes' in paramsOrFirst || + 'state' in paramsOrFirst) ) { params = (paramsOrFirst || {}) as { provider: OAuthProvider; success?: string; failure?: string; scopes?: string[]; + state?: string; }; } else { params = { @@ -4073,6 +5980,7 @@ export class Account extends Service { success: rest[0] as string, failure: rest[1] as string, scopes: rest[2] as string[], + state: rest[3] as string, }; } @@ -4080,6 +5988,7 @@ export class Account extends Service { const success = params.success; const failure = params.failure; const scopes = params.scopes; + const state = params.state; if (typeof provider === 'undefined') { throw new AppwriteException( @@ -4105,6 +6014,10 @@ export class Account extends Service { apiPayload['scopes'] = scopes; } + if (typeof state !== 'undefined') { + apiPayload['state'] = state; + } + const uri = new URL(this.client.config.endpoint + apiPath); apiPayload['project'] = this.client.config.project; @@ -4116,6 +6029,148 @@ export class Account extends Service { return uri; } + /** + * Start signing in with a passkey. No email or user ID is needed: pass the returned `publicKey` options to `navigator.credentials.get()` and the user picks one of their passkeys. Then call [Update passkey token](/docs/references/cloud/client-web/account#updatePasskeyToken) with the credential to receive a token, and exchange it with [Create session](/docs/references/cloud/client-web/account#createSession). The challenge expires after 5 minutes. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + createPasskeyToken(): Promise { + const apiPath = '/account/tokens/passkey'; + const apiPayload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + apiPath); + const request = this.client.call( + 'post', + uri, + { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }, + apiPayload, + ); + const defaults = { + root: 'passkeyChallenge', + models: { + passkeyChallenge: { + defaults: { + $id: '', + $createdAt: '', + passkeyId: '', + expire: '', + publicKey: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + + /** + * Complete a passkey sign-in started with [Create passkey token](/docs/references/cloud/client-web/account#createPasskeyToken). Pass the challenge ID and the JSON form of the credential returned by `navigator.credentials.get()`, for example `credential.toJSON()`. The returned token includes its secret and expires after 1 minute: exchange it for a session with [Create session](/docs/references/cloud/client-web/account#createSession). Passkeys require user verification, so the session also satisfies MFA. Each challenge can only be used once. + * + * @param {string} params.challengeId - Challenge ID returned by createPasskeyToken. + * @param {object} params.credential - Authentication credential returned by the authenticator, in the JSON form produced by `PublicKeyCredential.toJSON()`. + * @throws {AppwriteException} + * @returns {Promise} + */ + updatePasskeyToken(params: { + challengeId: string; + credential: object; + }): Promise; + /** + * Complete a passkey sign-in started with [Create passkey token](/docs/references/cloud/client-web/account#createPasskeyToken). Pass the challenge ID and the JSON form of the credential returned by `navigator.credentials.get()`, for example `credential.toJSON()`. The returned token includes its secret and expires after 1 minute: exchange it for a session with [Create session](/docs/references/cloud/client-web/account#createSession). Passkeys require user verification, so the session also satisfies MFA. Each challenge can only be used once. + * + * @param {string} challengeId - Challenge ID returned by createPasskeyToken. + * @param {object} credential - Authentication credential returned by the authenticator, in the JSON form produced by `PublicKeyCredential.toJSON()`. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + updatePasskeyToken( + challengeId: string, + credential: object, + ): Promise; + updatePasskeyToken( + paramsOrFirst: { challengeId: string; credential: object } | string, + ...rest: [object?] + ): Promise { + let params: { challengeId: string; credential: object }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + challengeId: string; + credential: object; + }; + } else { + params = { + challengeId: paramsOrFirst as string, + credential: rest[0] as object, + }; + } + + const challengeId = params.challengeId; + const credential = params.credential; + + if (typeof challengeId === 'undefined') { + throw new AppwriteException( + 'Missing required parameter: "challengeId"', + ); + } + + if (typeof credential === 'undefined') { + throw new AppwriteException( + 'Missing required parameter: "credential"', + ); + } + + const apiPath = '/account/tokens/passkey'; + const apiPayload: Payload = {}; + + if (typeof challengeId !== 'undefined') { + apiPayload['challengeId'] = challengeId; + } + + if (typeof credential !== 'undefined') { + apiPayload['credential'] = credential; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + const request = this.client.call( + 'put', + uri, + { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }, + apiPayload, + ); + const defaults = { + root: 'tokenSecret', + models: { + tokenSecret: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); + } + /** * 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. * @@ -4184,7 +6239,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -4194,6 +6249,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -4250,7 +6322,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -4260,6 +6332,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -4317,7 +6406,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -4327,6 +6416,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -4399,7 +6505,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -4409,6 +6515,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -4479,7 +6602,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -4489,6 +6612,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -4544,7 +6684,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -4554,6 +6694,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -4628,7 +6785,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -4638,6 +6795,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -4651,7 +6825,7 @@ export class Account extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -4661,6 +6835,23 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -4733,7 +6924,7 @@ export class Account extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -4743,5 +6934,22 @@ export class Account extends Service { }, apiPayload, ); + const defaults = { + root: 'token', + models: { + token: { + defaults: { + $id: '', + $createdAt: '', + userId: '', + secret: '', + expire: '', + phrase: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } } diff --git a/src/services/analytics.ts b/src/services/analytics.ts new file mode 100644 index 00000000..af61d584 --- /dev/null +++ b/src/services/analytics.ts @@ -0,0 +1,260 @@ +import { Service } from '../service'; +import { AppwriteException, Client } from '../client'; +import type { Payload } from '../client'; + +export class Analytics extends Service { + constructor(client: Client) { + super(client); + } + + /** + * Send a tracking event from a browser, native app, or server-side SDK. + * + * @param {string} params.propertyId - Analytics property ID. + * @param {string} params.name - Event name. "pageview" is just a conventional event name; events are not modeled specially. + * @param {string} params.url - Full page URL or screen identifier. + * @param {string} params.domain - Hostname (e.g. example.com). + * @param {string} params.referrer - Referrer URL. + * @param {number} params.screenWidth - Viewport width in CSS pixels. + * @param {string} params.sessionHash - Optional session hash (provided by SDK). + * @param {number} params.scrollDepth - Scroll depth percentage 0-100. + * @param {number} params.engagementTime - Engagement time in seconds, 0-4294967295. + * @param {string[]} params.props - Custom string properties as a flat key=value list (max 32 entries, alternating key,value). + * @param {string} params.userId - Override user ID. Requires API-key auth with analytics.write scope. + * @param {string} params.ip - Override IP address. Requires API-key auth with analytics.write scope. + * @param {string} params.userAgent - Override user agent. Requires API-key auth with analytics.write scope. + * @throws {AppwriteException} + * @returns {Promise} + */ + createEvent(params: { + propertyId: string; + name: string; + url: string; + domain?: string; + referrer?: string; + screenWidth?: number; + sessionHash?: string; + scrollDepth?: number; + engagementTime?: number; + props?: string[]; + userId?: string; + ip?: string; + userAgent?: string; + }): Promise<{}>; + /** + * Send a tracking event from a browser, native app, or server-side SDK. + * + * @param {string} propertyId - Analytics property ID. + * @param {string} name - Event name. "pageview" is just a conventional event name; events are not modeled specially. + * @param {string} url - Full page URL or screen identifier. + * @param {string} domain - Hostname (e.g. example.com). + * @param {string} referrer - Referrer URL. + * @param {number} screenWidth - Viewport width in CSS pixels. + * @param {string} sessionHash - Optional session hash (provided by SDK). + * @param {number} scrollDepth - Scroll depth percentage 0-100. + * @param {number} engagementTime - Engagement time in seconds, 0-4294967295. + * @param {string[]} props - Custom string properties as a flat key=value list (max 32 entries, alternating key,value). + * @param {string} userId - Override user ID. Requires API-key auth with analytics.write scope. + * @param {string} ip - Override IP address. Requires API-key auth with analytics.write scope. + * @param {string} userAgent - Override user agent. Requires API-key auth with analytics.write scope. + * @throws {AppwriteException} + * @returns {Promise<{}>} + * @deprecated Use the object parameter style method for a better developer experience. + */ + createEvent( + propertyId: string, + name: string, + url: string, + domain?: string, + referrer?: string, + screenWidth?: number, + sessionHash?: string, + scrollDepth?: number, + engagementTime?: number, + props?: string[], + userId?: string, + ip?: string, + userAgent?: string, + ): Promise<{}>; + createEvent( + paramsOrFirst: + | { + propertyId: string; + name: string; + url: string; + domain?: string; + referrer?: string; + screenWidth?: number; + sessionHash?: string; + scrollDepth?: number; + engagementTime?: number; + props?: string[]; + userId?: string; + ip?: string; + userAgent?: string; + } + | string, + ...rest: [ + string?, + string?, + string?, + string?, + number?, + string?, + number?, + number?, + string[]?, + string?, + string?, + string?, + ] + ): Promise<{}> { + let params: { + propertyId: string; + name: string; + url: string; + domain?: string; + referrer?: string; + screenWidth?: number; + sessionHash?: string; + scrollDepth?: number; + engagementTime?: number; + props?: string[]; + userId?: string; + ip?: string; + userAgent?: string; + }; + + if ( + paramsOrFirst && + typeof paramsOrFirst === 'object' && + !Array.isArray(paramsOrFirst) + ) { + params = (paramsOrFirst || {}) as { + propertyId: string; + name: string; + url: string; + domain?: string; + referrer?: string; + screenWidth?: number; + sessionHash?: string; + scrollDepth?: number; + engagementTime?: number; + props?: string[]; + userId?: string; + ip?: string; + userAgent?: string; + }; + } else { + params = { + propertyId: paramsOrFirst as string, + name: rest[0] as string, + url: rest[1] as string, + domain: rest[2] as string, + referrer: rest[3] as string, + screenWidth: rest[4] as number, + sessionHash: rest[5] as string, + scrollDepth: rest[6] as number, + engagementTime: rest[7] as number, + props: rest[8] as string[], + userId: rest[9] as string, + ip: rest[10] as string, + userAgent: rest[11] as string, + }; + } + + const propertyId = params.propertyId; + const name = params.name; + const url = params.url; + const domain = params.domain; + const referrer = params.referrer; + const screenWidth = params.screenWidth; + const sessionHash = params.sessionHash; + const scrollDepth = params.scrollDepth; + const engagementTime = params.engagementTime; + const props = params.props; + const userId = params.userId; + const ip = params.ip; + const userAgent = params.userAgent; + + if (typeof propertyId === 'undefined' || propertyId === '') { + throw new AppwriteException( + 'Missing required parameter: "propertyId"', + ); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + if (typeof url === 'undefined') { + throw new AppwriteException('Missing required parameter: "url"'); + } + + const apiPath = '/analytics/properties/{propertyId}/events'.replace( + '{propertyId}', + encodeURIComponent(String(propertyId)), + ); + const apiPayload: Payload = {}; + + if (typeof name !== 'undefined') { + apiPayload['name'] = name; + } + + if (typeof url !== 'undefined') { + apiPayload['url'] = url; + } + + if (typeof domain !== 'undefined') { + apiPayload['domain'] = domain; + } + + if (typeof referrer !== 'undefined') { + apiPayload['referrer'] = referrer; + } + + if (typeof screenWidth !== 'undefined') { + apiPayload['screenWidth'] = screenWidth; + } + + if (typeof sessionHash !== 'undefined') { + apiPayload['sessionHash'] = sessionHash; + } + + if (typeof scrollDepth !== 'undefined') { + apiPayload['scrollDepth'] = scrollDepth; + } + + if (typeof engagementTime !== 'undefined') { + apiPayload['engagementTime'] = engagementTime; + } + + if (typeof props !== 'undefined') { + apiPayload['props'] = props; + } + + if (typeof userId !== 'undefined') { + apiPayload['userId'] = userId; + } + + if (typeof ip !== 'undefined') { + apiPayload['ip'] = ip; + } + + if (typeof userAgent !== 'undefined') { + apiPayload['userAgent'] = userAgent; + } + + const uri = new URL(this.client.config.endpoint + apiPath); + return this.client.call( + 'post', + uri, + { + 'X-Appwrite-Project': this.client.config.project, + 'content-type': 'application/json', + accept: 'application/json', + }, + apiPayload, + ); + } +} diff --git a/src/services/apps.ts b/src/services/apps.ts index 02554ba4..7bc1cb9e 100644 --- a/src/services/apps.ts +++ b/src/services/apps.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -68,7 +68,7 @@ export class Apps extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -77,6 +77,69 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appsList', + models: { + appsList: { + defaults: { + total: 0, + }, + properties: { + apps: { + items: 'app', + }, + }, + }, + app: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + description: '', + clientUri: '', + logoUri: '', + privacyPolicyUrl: '', + termsUrl: '', + contacts: [], + tagline: '', + tags: [], + labels: [], + images: [], + supportUrl: '', + dataDeletionUrl: '', + redirectUris: [], + postLogoutRedirectUris: [], + enabled: true, + type: 'confidential', + deviceFlow: false, + teamId: '', + userId: '', + installationScopes: [], + installationRedirectUrl: '', + }, + properties: { + secrets: { + items: 'appSecret', + }, + }, + }, + appSecret: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -403,7 +466,7 @@ export class Apps extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -413,6 +476,59 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'app', + models: { + app: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + description: '', + clientUri: '', + logoUri: '', + privacyPolicyUrl: '', + termsUrl: '', + contacts: [], + tagline: '', + tags: [], + labels: [], + images: [], + supportUrl: '', + dataDeletionUrl: '', + redirectUris: [], + postLogoutRedirectUris: [], + enabled: true, + type: 'confidential', + deviceFlow: false, + teamId: '', + userId: '', + installationScopes: [], + installationRedirectUrl: '', + }, + properties: { + secrets: { + items: 'appSecret', + }, + }, + }, + appSecret: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -426,7 +542,7 @@ export class Apps extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -435,6 +551,32 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appScopeList', + models: { + appScopeList: { + defaults: { + total: 0, + }, + properties: { + scopes: { + items: 'appScope', + }, + }, + }, + appScope: { + defaults: { + value: '', + description: '', + type: '', + category: '', + deprecated: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -448,7 +590,7 @@ export class Apps extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -457,6 +599,32 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appScopeList', + models: { + appScopeList: { + defaults: { + total: 0, + }, + properties: { + scopes: { + items: 'appScope', + }, + }, + }, + appScope: { + defaults: { + value: '', + description: '', + type: '', + category: '', + deprecated: false, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -504,7 +672,7 @@ export class Apps extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -513,6 +681,59 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'app', + models: { + app: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + description: '', + clientUri: '', + logoUri: '', + privacyPolicyUrl: '', + termsUrl: '', + contacts: [], + tagline: '', + tags: [], + labels: [], + images: [], + supportUrl: '', + dataDeletionUrl: '', + redirectUris: [], + postLogoutRedirectUris: [], + enabled: true, + type: 'confidential', + deviceFlow: false, + teamId: '', + userId: '', + installationScopes: [], + installationRedirectUrl: '', + }, + properties: { + secrets: { + items: 'appSecret', + }, + }, + }, + appSecret: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -846,7 +1067,7 @@ export class Apps extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -856,6 +1077,59 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'app', + models: { + app: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + description: '', + clientUri: '', + logoUri: '', + privacyPolicyUrl: '', + termsUrl: '', + contacts: [], + tagline: '', + tags: [], + labels: [], + images: [], + supportUrl: '', + dataDeletionUrl: '', + redirectUris: [], + postLogoutRedirectUris: [], + enabled: true, + type: 'confidential', + deviceFlow: false, + teamId: '', + userId: '', + installationScopes: [], + installationRedirectUrl: '', + }, + properties: { + secrets: { + items: 'appSecret', + }, + }, + }, + appSecret: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -992,7 +1266,7 @@ export class Apps extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1001,6 +1275,36 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appInstallationList', + models: { + appInstallationList: { + defaults: { + total: 0, + }, + properties: { + installations: { + items: 'appInstallation', + }, + }, + }, + appInstallation: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + teamId: '', + scopes: [], + authorizationDetails: [], + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1072,7 +1376,7 @@ export class Apps extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1081,6 +1385,26 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appInstallation', + models: { + appInstallation: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + teamId: '', + scopes: [], + authorizationDetails: [], + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1230,7 +1554,7 @@ export class Apps extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1240,6 +1564,22 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2Token', + models: { + oauth2Token: { + defaults: { + access_token: '', + token_type: 'Bearer', + expires_in: 0, + refresh_token: '', + scope: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1319,7 +1659,7 @@ export class Apps extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1328,6 +1668,35 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appKeyList', + models: { + appKeyList: { + defaults: { + total: 0, + }, + properties: { + keys: { + items: 'appKey', + }, + }, + }, + appKey: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1377,7 +1746,7 @@ export class Apps extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1387,6 +1756,25 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appKey', + models: { + appKey: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1444,7 +1832,7 @@ export class Apps extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1453,6 +1841,25 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appKey', + models: { + appKey: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1599,7 +2006,7 @@ export class Apps extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1608,6 +2015,35 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appSecretList', + models: { + appSecretList: { + defaults: { + total: 0, + }, + properties: { + secrets: { + items: 'appSecret', + }, + }, + }, + appSecret: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1657,7 +2093,7 @@ export class Apps extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1667,6 +2103,25 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appSecretPlaintext', + models: { + appSecretPlaintext: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1732,7 +2187,7 @@ export class Apps extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1741,6 +2196,25 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'appSecret', + models: { + appSecret: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1875,7 +2349,7 @@ export class Apps extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1885,6 +2359,59 @@ export class Apps extends Service { }, apiPayload, ); + const defaults = { + root: 'app', + models: { + app: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + description: '', + clientUri: '', + logoUri: '', + privacyPolicyUrl: '', + termsUrl: '', + contacts: [], + tagline: '', + tags: [], + labels: [], + images: [], + supportUrl: '', + dataDeletionUrl: '', + redirectUris: [], + postLogoutRedirectUris: [], + enabled: true, + type: 'confidential', + deviceFlow: false, + teamId: '', + userId: '', + installationScopes: [], + installationRedirectUrl: '', + }, + properties: { + secrets: { + items: 'appSecret', + }, + }, + }, + appSecret: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + secret: '', + hint: '', + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** diff --git a/src/services/avatars.ts b/src/services/avatars.ts index e634ce6d..062ed1b6 100644 --- a/src/services/avatars.ts +++ b/src/services/avatars.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { UploadProgress, Payload } from '../client'; import * as FileSystem from 'expo-file-system'; diff --git a/src/services/databases.ts b/src/services/databases.ts index 94d2ad16..faef7447 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -72,7 +72,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -81,6 +81,33 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'transactionList', + models: { + transactionList: { + defaults: { + total: 0, + }, + properties: { + transactions: { + items: 'transaction', + }, + }, + }, + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -129,7 +156,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -139,6 +166,23 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -193,7 +237,7 @@ export class Databases extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -202,6 +246,23 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -289,7 +350,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -299,6 +360,23 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -433,7 +511,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -443,6 +521,23 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -580,7 +675,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -589,6 +684,33 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'documentList', + models: { + documentList: { + defaults: { + total: 0, + }, + properties: { + documents: { + items: 'document', + }, + }, + }, + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -761,7 +883,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -771,6 +893,23 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -901,7 +1040,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -910,6 +1049,23 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1080,7 +1236,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -1090,6 +1246,23 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1260,7 +1433,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1270,6 +1443,23 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1555,7 +1745,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1565,6 +1755,23 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1725,7 +1932,7 @@ export class Databases extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1735,5 +1942,22 @@ export class Databases extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } } diff --git a/src/services/documents-db.ts b/src/services/documents-db.ts index 6f10966e..6efc2e4b 100644 --- a/src/services/documents-db.ts +++ b/src/services/documents-db.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -71,7 +71,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -80,6 +80,33 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transactionList', + models: { + transactionList: { + defaults: { + total: 0, + }, + properties: { + transactions: { + items: 'transaction', + }, + }, + }, + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -127,7 +154,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -137,6 +164,23 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -190,7 +234,7 @@ export class DocumentsDB extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -199,6 +243,23 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -285,7 +346,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -295,6 +356,23 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -427,7 +505,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -437,6 +515,23 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -573,7 +668,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -582,6 +677,33 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'documentList', + models: { + documentList: { + defaults: { + total: 0, + }, + properties: { + documents: { + items: 'document', + }, + }, + }, + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -753,7 +875,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -763,6 +885,23 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -879,7 +1018,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -889,6 +1028,33 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'documentList', + models: { + documentList: { + defaults: { + total: 0, + }, + properties: { + documents: { + items: 'document', + }, + }, + }, + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1018,7 +1184,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1027,6 +1193,23 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1196,7 +1379,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -1206,6 +1389,23 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1375,7 +1575,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1385,6 +1585,23 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1668,7 +1885,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1678,6 +1895,23 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1837,7 +2071,7 @@ export class DocumentsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1847,5 +2081,22 @@ export class DocumentsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } } diff --git a/src/services/functions.ts b/src/services/functions.ts index 230ffe70..54a4b2b7 100644 --- a/src/services/functions.ts +++ b/src/services/functions.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -89,7 +89,7 @@ export class Functions extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -98,6 +98,54 @@ export class Functions extends Service { }, apiPayload, ); + const defaults = { + root: 'executionList', + models: { + executionList: { + defaults: { + total: 0, + }, + properties: { + executions: { + items: 'execution', + }, + }, + }, + execution: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + resourceId: '', + resourceType: 'functions', + deploymentId: '', + requestMethod: '', + requestPath: '', + responseStatusCode: 0, + responseBody: '', + logs: '', + errors: '', + duration: 0, + }, + properties: { + requestHeaders: { + items: 'headers', + }, + responseHeaders: { + items: 'headers', + }, + }, + }, + headers: { + defaults: { + name: '', + value: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -247,7 +295,7 @@ export class Functions extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -257,6 +305,44 @@ export class Functions extends Service { }, apiPayload, ); + const defaults = { + root: 'execution', + models: { + execution: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + resourceId: '', + resourceType: 'functions', + deploymentId: '', + requestMethod: '', + requestPath: '', + responseStatusCode: 0, + responseBody: '', + logs: '', + errors: '', + duration: 0, + }, + properties: { + requestHeaders: { + items: 'headers', + }, + responseHeaders: { + items: 'headers', + }, + }, + }, + headers: { + defaults: { + name: '', + value: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -327,7 +413,7 @@ export class Functions extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -336,5 +422,43 @@ export class Functions extends Service { }, apiPayload, ); + const defaults = { + root: 'execution', + models: { + execution: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + resourceId: '', + resourceType: 'functions', + deploymentId: '', + requestMethod: '', + requestPath: '', + responseStatusCode: 0, + responseBody: '', + logs: '', + errors: '', + duration: 0, + }, + properties: { + requestHeaders: { + items: 'headers', + }, + responseHeaders: { + items: 'headers', + }, + }, + }, + headers: { + defaults: { + name: '', + value: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } } diff --git a/src/services/locale.ts b/src/services/locale.ts index ce9e92b2..6eaeb512 100644 --- a/src/services/locale.ts +++ b/src/services/locale.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { Client } from '../client'; +import { Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -21,7 +21,7 @@ export class Locale extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -30,6 +30,24 @@ export class Locale extends Service { }, apiPayload, ); + const defaults = { + root: 'locale', + models: { + locale: { + defaults: { + ip: '', + countryCode: '', + country: '', + continentCode: '', + continent: '', + eu: false, + currency: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -77,7 +95,7 @@ export class Locale extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -86,6 +104,29 @@ export class Locale extends Service { }, apiPayload, ); + const defaults = { + root: 'localeCodeList', + models: { + localeCodeList: { + defaults: { + total: 0, + }, + properties: { + localeCodes: { + items: 'localeCode', + }, + }, + }, + localeCode: { + defaults: { + code: '', + name: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -133,7 +174,7 @@ export class Locale extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -142,6 +183,29 @@ export class Locale extends Service { }, apiPayload, ); + const defaults = { + root: 'continentList', + models: { + continentList: { + defaults: { + total: 0, + }, + properties: { + continents: { + items: 'continent', + }, + }, + }, + continent: { + defaults: { + name: '', + code: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -189,7 +253,7 @@ export class Locale extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -198,6 +262,29 @@ export class Locale extends Service { }, apiPayload, ); + const defaults = { + root: 'countryList', + models: { + countryList: { + defaults: { + total: 0, + }, + properties: { + countries: { + items: 'country', + }, + }, + }, + country: { + defaults: { + name: '', + code: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -245,7 +332,7 @@ export class Locale extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -254,6 +341,29 @@ export class Locale extends Service { }, apiPayload, ); + const defaults = { + root: 'countryList', + models: { + countryList: { + defaults: { + total: 0, + }, + properties: { + countries: { + items: 'country', + }, + }, + }, + country: { + defaults: { + name: '', + code: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -303,7 +413,7 @@ export class Locale extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -312,6 +422,30 @@ export class Locale extends Service { }, apiPayload, ); + const defaults = { + root: 'phoneList', + models: { + phoneList: { + defaults: { + total: 0, + }, + properties: { + phones: { + items: 'phone', + }, + }, + }, + phone: { + defaults: { + code: '', + countryCode: '', + countryName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -359,7 +493,7 @@ export class Locale extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -368,6 +502,34 @@ export class Locale extends Service { }, apiPayload, ); + const defaults = { + root: 'currencyList', + models: { + currencyList: { + defaults: { + total: 0, + }, + properties: { + currencies: { + items: 'currency', + }, + }, + }, + currency: { + defaults: { + symbol: '', + name: '', + symbolNative: '', + decimalDigits: 0, + rounding: 0, + code: '', + namePlural: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -415,7 +577,7 @@ export class Locale extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -424,5 +586,29 @@ export class Locale extends Service { }, apiPayload, ); + const defaults = { + root: 'languageList', + models: { + languageList: { + defaults: { + total: 0, + }, + properties: { + languages: { + items: 'language', + }, + }, + }, + language: { + defaults: { + name: '', + code: '', + nativeName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } } diff --git a/src/services/messaging.ts b/src/services/messaging.ts index 33e94c19..b1939ddf 100644 --- a/src/services/messaging.ts +++ b/src/services/messaging.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -100,7 +100,7 @@ export class Messaging extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -110,6 +110,25 @@ export class Messaging extends Service { }, apiPayload, ); + const defaults = { + root: 'subscriber', + models: { + subscriber: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + targetId: '', + userId: '', + userName: '', + topicId: '', + providerType: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** diff --git a/src/services/oauth-2.ts b/src/services/oauth-2.ts index 1920bc1a..cbcaf3ad 100644 --- a/src/services/oauth-2.ts +++ b/src/services/oauth-2.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -96,7 +96,7 @@ export class Oauth2 extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -105,6 +105,18 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2Approve', + models: { + oauth2Approve: { + defaults: { + redirectUrl: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -121,7 +133,7 @@ export class Oauth2 extends Service { * @param {string} params.prompt - OIDC prompt parameter for customization of consent screen. Space-separated list of: none, login, consent, select_account. * @param {number} params.maxAge - OIDC max_age paraleter for customization of consent screen. Maximum allowable elapsed time in seconds since the user last authenticated. If exceeded, re-authentication is required. * @param {string} params.authorizationDetails - Rich authorization request. JSON array of objects, each with a `type` and project-defined fields - * @param {string} params.resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. + * @param {string[]} params.resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. * @param {string} params.audience - Compatibility alias for a single OAuth2 resource indicator URI. * @param {string} params.requestUri - OAuth2 authorization request handle returned by the pushed authorization request endpoint. * @throws {AppwriteException} @@ -139,7 +151,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; requestUri?: string; }): Promise; @@ -157,7 +169,7 @@ export class Oauth2 extends Service { * @param {string} prompt - OIDC prompt parameter for customization of consent screen. Space-separated list of: none, login, consent, select_account. * @param {number} maxAge - OIDC max_age paraleter for customization of consent screen. Maximum allowable elapsed time in seconds since the user last authenticated. If exceeded, re-authentication is required. * @param {string} authorizationDetails - Rich authorization request. JSON array of objects, each with a `type` and project-defined fields - * @param {string} resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. + * @param {string[]} resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. * @param {string} audience - Compatibility alias for a single OAuth2 resource indicator URI. * @param {string} requestUri - OAuth2 authorization request handle returned by the pushed authorization request endpoint. * @throws {AppwriteException} @@ -176,7 +188,7 @@ export class Oauth2 extends Service { prompt?: string, maxAge?: number, authorizationDetails?: string, - resource?: string, + resource?: string[], audience?: string, requestUri?: string, ): Promise; @@ -194,7 +206,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; requestUri?: string; } @@ -210,7 +222,7 @@ export class Oauth2 extends Service { string?, number?, string?, - string?, + string[]?, string?, string?, ] @@ -227,7 +239,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; requestUri?: string; }; @@ -250,7 +262,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; requestUri?: string; }; @@ -267,7 +279,7 @@ export class Oauth2 extends Service { prompt: rest[7] as string, maxAge: rest[8] as number, authorizationDetails: rest[9] as string, - resource: rest[10] as string, + resource: rest[10] as string[], audience: rest[11] as string, requestUri: rest[12] as string, }; @@ -351,7 +363,7 @@ export class Oauth2 extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -359,6 +371,19 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2Authorize', + models: { + oauth2Authorize: { + defaults: { + grantId: '', + redirectUrl: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -375,7 +400,7 @@ export class Oauth2 extends Service { * @param {string} params.prompt - OIDC prompt parameter for customization of consent screen. Space-separated list of: none, login, consent, select_account. * @param {number} params.maxAge - OIDC max_age paraleter for customization of consent screen. Maximum allowable elapsed time in seconds since the user last authenticated. If exceeded, re-authentication is required. * @param {string} params.authorizationDetails - Rich authorization request. JSON array of objects, each with a `type` and project-defined fields - * @param {string} params.resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. + * @param {string[]} params.resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. * @param {string} params.audience - Compatibility alias for a single OAuth2 resource indicator URI. * @param {string} params.requestUri - OAuth2 authorization request handle returned by the pushed authorization request endpoint. * @throws {AppwriteException} @@ -393,7 +418,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; requestUri?: string; }): Promise; @@ -411,7 +436,7 @@ export class Oauth2 extends Service { * @param {string} prompt - OIDC prompt parameter for customization of consent screen. Space-separated list of: none, login, consent, select_account. * @param {number} maxAge - OIDC max_age paraleter for customization of consent screen. Maximum allowable elapsed time in seconds since the user last authenticated. If exceeded, re-authentication is required. * @param {string} authorizationDetails - Rich authorization request. JSON array of objects, each with a `type` and project-defined fields - * @param {string} resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. + * @param {string[]} resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. * @param {string} audience - Compatibility alias for a single OAuth2 resource indicator URI. * @param {string} requestUri - OAuth2 authorization request handle returned by the pushed authorization request endpoint. * @throws {AppwriteException} @@ -430,7 +455,7 @@ export class Oauth2 extends Service { prompt?: string, maxAge?: number, authorizationDetails?: string, - resource?: string, + resource?: string[], audience?: string, requestUri?: string, ): Promise; @@ -448,7 +473,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; requestUri?: string; } @@ -464,7 +489,7 @@ export class Oauth2 extends Service { string?, number?, string?, - string?, + string[]?, string?, string?, ] @@ -481,7 +506,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; requestUri?: string; }; @@ -504,7 +529,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; requestUri?: string; }; @@ -521,7 +546,7 @@ export class Oauth2 extends Service { prompt: rest[7] as string, maxAge: rest[8] as number, authorizationDetails: rest[9] as string, - resource: rest[10] as string, + resource: rest[10] as string[], audience: rest[11] as string, requestUri: rest[12] as string, }; @@ -605,7 +630,7 @@ export class Oauth2 extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -614,6 +639,19 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2Authorize', + models: { + oauth2Authorize: { + defaults: { + grantId: '', + redirectUrl: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -622,7 +660,7 @@ export class Oauth2 extends Service { * @param {string} params.clientId - OAuth2 client ID. Either a registered app ID or an HTTPS client ID metadata document URL. * @param {string} params.scope - Space-separated OAuth2 scopes. Can include project scopes, and built-in scopes: `openid`, `email`, `profile`. * @param {string} params.authorizationDetails - Rich authorization request. JSON array of objects, each with a `type` and project-defined fields - * @param {string} params.resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. + * @param {string[]} params.resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. * @param {string} params.audience - Compatibility alias for a single OAuth2 resource indicator URI. * @throws {AppwriteException} * @returns {Promise} @@ -631,7 +669,7 @@ export class Oauth2 extends Service { clientId?: string; scope?: string; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; }): Promise; /** @@ -640,7 +678,7 @@ export class Oauth2 extends Service { * @param {string} clientId - OAuth2 client ID. Either a registered app ID or an HTTPS client ID metadata document URL. * @param {string} scope - Space-separated OAuth2 scopes. Can include project scopes, and built-in scopes: `openid`, `email`, `profile`. * @param {string} authorizationDetails - Rich authorization request. JSON array of objects, each with a `type` and project-defined fields - * @param {string} resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. + * @param {string[]} resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. * @param {string} audience - Compatibility alias for a single OAuth2 resource indicator URI. * @throws {AppwriteException} * @returns {Promise} @@ -650,7 +688,7 @@ export class Oauth2 extends Service { clientId?: string, scope?: string, authorizationDetails?: string, - resource?: string, + resource?: string[], audience?: string, ): Promise; createDeviceAuthorization( @@ -659,17 +697,17 @@ export class Oauth2 extends Service { clientId?: string; scope?: string; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; } | string, - ...rest: [string?, string?, string?, string?] + ...rest: [string?, string?, string[]?, string?] ): Promise { let params: { clientId?: string; scope?: string; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; }; @@ -683,7 +721,7 @@ export class Oauth2 extends Service { clientId?: string; scope?: string; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; }; } else { @@ -691,7 +729,7 @@ export class Oauth2 extends Service { clientId: paramsOrFirst as string, scope: rest[0] as string, authorizationDetails: rest[1] as string, - resource: rest[2] as string, + resource: rest[2] as string[], audience: rest[3] as string, }; } @@ -729,7 +767,7 @@ export class Oauth2 extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -738,6 +776,23 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2DeviceAuthorization', + models: { + oauth2DeviceAuthorization: { + defaults: { + device_code: '', + user_code: '', + verification_uri: '', + verification_uri_complete: '', + expires_in: 0, + interval: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -793,7 +848,7 @@ export class Oauth2 extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -802,6 +857,29 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2Grant', + models: { + oauth2Grant: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + appId: '', + scopes: [], + resources: [], + authorizationDetails: '[]', + prompt: '', + redirectUri: '', + authTime: 0, + expire: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -855,7 +933,7 @@ export class Oauth2 extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -863,6 +941,29 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2Grant', + models: { + oauth2Grant: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + appId: '', + scopes: [], + resources: [], + authorizationDetails: '[]', + prompt: '', + redirectUri: '', + authTime: 0, + expire: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1216,7 +1317,7 @@ export class Oauth2 extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1224,6 +1325,28 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2OrganizationList', + models: { + oauth2OrganizationList: { + defaults: { + total: 0, + }, + properties: { + organizations: { + items: 'oauth2Organization', + }, + }, + }, + oauth2Organization: { + defaults: { + $id: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1240,7 +1363,7 @@ export class Oauth2 extends Service { * @param {string} params.prompt - OIDC prompt parameter for customization of consent screen. Space-separated list of: none, login, consent, select_account. * @param {number} params.maxAge - OIDC max_age parameter for customization of consent screen. * @param {string} params.authorizationDetails - Rich authorization request. JSON array of objects, each with a `type` and project-defined fields - * @param {string} params.resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. + * @param {string[]} params.resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. * @param {string} params.audience - Compatibility alias for a single OAuth2 resource indicator URI. * @throws {AppwriteException} * @returns {Promise} @@ -1257,7 +1380,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; }): Promise; /** @@ -1274,7 +1397,7 @@ export class Oauth2 extends Service { * @param {string} prompt - OIDC prompt parameter for customization of consent screen. Space-separated list of: none, login, consent, select_account. * @param {number} maxAge - OIDC max_age parameter for customization of consent screen. * @param {string} authorizationDetails - Rich authorization request. JSON array of objects, each with a `type` and project-defined fields - * @param {string} resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. + * @param {string[]} resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. * @param {string} audience - Compatibility alias for a single OAuth2 resource indicator URI. * @throws {AppwriteException} * @returns {Promise} @@ -1292,7 +1415,7 @@ export class Oauth2 extends Service { prompt?: string, maxAge?: number, authorizationDetails?: string, - resource?: string, + resource?: string[], audience?: string, ): Promise; createPAR( @@ -1309,7 +1432,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; } | string, @@ -1324,7 +1447,7 @@ export class Oauth2 extends Service { string?, number?, string?, - string?, + string[]?, string?, ] ): Promise { @@ -1340,7 +1463,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; }; @@ -1361,7 +1484,7 @@ export class Oauth2 extends Service { prompt?: string; maxAge?: number; authorizationDetails?: string; - resource?: string; + resource?: string[]; audience?: string; }; } else { @@ -1377,7 +1500,7 @@ export class Oauth2 extends Service { prompt: rest[7] as string, maxAge: rest[8] as number, authorizationDetails: rest[9] as string, - resource: rest[10] as string, + resource: rest[10] as string[], audience: rest[11] as string, }; } @@ -1473,7 +1596,7 @@ export class Oauth2 extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1482,6 +1605,19 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2PAR', + models: { + oauth2PAR: { + defaults: { + request_uri: '', + expires_in: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1562,7 +1698,7 @@ export class Oauth2 extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1570,6 +1706,30 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2ProjectList', + models: { + oauth2ProjectList: { + defaults: { + total: 0, + }, + properties: { + projects: { + items: 'oauth2Project', + }, + }, + }, + oauth2Project: { + defaults: { + $id: '', + region: '', + endpoint: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1625,7 +1785,7 @@ export class Oauth2 extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1634,6 +1794,18 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2Reject', + models: { + oauth2Reject: { + defaults: { + redirectUrl: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1761,7 +1933,7 @@ export class Oauth2 extends Service { * @param {string} params.clientSecret - OAuth2 client secret. Required for confidential apps. * @param {string} params.codeVerifier - PKCE code verifier. Required for public apps. * @param {string} params.redirectUri - Redirect URI. Required for `authorization_code` grant type. - * @param {string} params.resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. + * @param {string[]} params.resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. * @param {string} params.audience - Compatibility alias for a single OAuth2 resource indicator URI. * @throws {AppwriteException} * @returns {Promise} @@ -1775,7 +1947,7 @@ export class Oauth2 extends Service { clientSecret?: string; codeVerifier?: string; redirectUri?: string; - resource?: string; + resource?: string[]; audience?: string; }): Promise; /** @@ -1789,7 +1961,7 @@ export class Oauth2 extends Service { * @param {string} clientSecret - OAuth2 client secret. Required for confidential apps. * @param {string} codeVerifier - PKCE code verifier. Required for public apps. * @param {string} redirectUri - Redirect URI. Required for `authorization_code` grant type. - * @param {string} resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. + * @param {string[]} resource - RFC 8707 resource indicator URI or URI list. Each value must be an absolute URI without a fragment. * @param {string} audience - Compatibility alias for a single OAuth2 resource indicator URI. * @throws {AppwriteException} * @returns {Promise} @@ -1804,7 +1976,7 @@ export class Oauth2 extends Service { clientSecret?: string, codeVerifier?: string, redirectUri?: string, - resource?: string, + resource?: string[], audience?: string, ): Promise; createToken( @@ -1818,7 +1990,7 @@ export class Oauth2 extends Service { clientSecret?: string; codeVerifier?: string; redirectUri?: string; - resource?: string; + resource?: string[]; audience?: string; } | string, @@ -1830,7 +2002,7 @@ export class Oauth2 extends Service { string?, string?, string?, - string?, + string[]?, string?, ] ): Promise { @@ -1843,7 +2015,7 @@ export class Oauth2 extends Service { clientSecret?: string; codeVerifier?: string; redirectUri?: string; - resource?: string; + resource?: string[]; audience?: string; }; @@ -1861,7 +2033,7 @@ export class Oauth2 extends Service { clientSecret?: string; codeVerifier?: string; redirectUri?: string; - resource?: string; + resource?: string[]; audience?: string; }; } else { @@ -1874,7 +2046,7 @@ export class Oauth2 extends Service { clientSecret: rest[4] as string, codeVerifier: rest[5] as string, redirectUri: rest[6] as string, - resource: rest[7] as string, + resource: rest[7] as string[], audience: rest[8] as string, }; } @@ -1943,7 +2115,7 @@ export class Oauth2 extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1952,5 +2124,21 @@ export class Oauth2 extends Service { }, apiPayload, ); + const defaults = { + root: 'oauth2Token', + models: { + oauth2Token: { + defaults: { + access_token: '', + token_type: 'Bearer', + expires_in: 0, + refresh_token: '', + scope: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } } diff --git a/src/services/organization.ts b/src/services/organization.ts index 3542965f..3bf9c9b8 100644 --- a/src/services/organization.ts +++ b/src/services/organization.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -71,7 +71,7 @@ export class Organization extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -80,6 +80,36 @@ export class Organization extends Service { }, apiPayload, ); + const defaults = { + root: 'appInstallationList', + models: { + appInstallationList: { + defaults: { + total: 0, + }, + properties: { + installations: { + items: 'appInstallation', + }, + }, + }, + appInstallation: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + teamId: '', + scopes: [], + authorizationDetails: [], + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -149,7 +179,7 @@ export class Organization extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -159,6 +189,26 @@ export class Organization extends Service { }, apiPayload, ); + const defaults = { + root: 'appInstallation', + models: { + appInstallation: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + teamId: '', + scopes: [], + authorizationDetails: [], + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -212,7 +262,7 @@ export class Organization extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -221,6 +271,26 @@ export class Organization extends Service { }, apiPayload, ); + const defaults = { + root: 'appInstallation', + models: { + appInstallation: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + teamId: '', + scopes: [], + authorizationDetails: [], + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -291,7 +361,7 @@ export class Organization extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -301,6 +371,26 @@ export class Organization extends Service { }, apiPayload, ); + const defaults = { + root: 'appInstallation', + models: { + appInstallation: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + teamId: '', + scopes: [], + authorizationDetails: [], + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** diff --git a/src/services/presences.ts b/src/services/presences.ts index 5fb3a364..883d330b 100644 --- a/src/services/presences.ts +++ b/src/services/presences.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -85,7 +85,7 @@ export class Presences extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -94,6 +94,32 @@ export class Presences extends Service { }, apiPayload, ); + const defaults = { + root: 'presenceList', + models: { + presenceList: { + defaults: { + total: 0, + }, + properties: { + presences: { + items: 'presence', + }, + }, + }, + presence: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + source: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -147,7 +173,7 @@ export class Presences extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -156,6 +182,22 @@ export class Presences extends Service { }, apiPayload, ); + const defaults = { + root: 'presence', + models: { + presence: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + source: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -278,7 +320,7 @@ export class Presences extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -288,6 +330,22 @@ export class Presences extends Service { }, apiPayload, ); + const defaults = { + root: 'presence', + models: { + presence: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + source: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -419,7 +477,7 @@ export class Presences extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -429,6 +487,22 @@ export class Presences extends Service { }, apiPayload, ); + const defaults = { + root: 'presence', + models: { + presence: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + source: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** diff --git a/src/services/storage.ts b/src/services/storage.ts index fdca28a8..c956d2ab 100644 --- a/src/services/storage.ts +++ b/src/services/storage.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { UploadProgress, Payload } from '../client'; import * as FileSystem from 'expo-file-system'; @@ -113,7 +113,7 @@ export class Storage extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -122,6 +122,43 @@ export class Storage extends Service { }, apiPayload, ); + const defaults = { + root: 'fileList', + models: { + fileList: { + defaults: { + total: 0, + }, + properties: { + files: { + items: 'file', + }, + }, + }, + file: { + defaults: { + $id: '', + bucketId: '', + $createdAt: '', + $updatedAt: '', + $permissions: [], + name: '', + folder: '', + key: '', + signature: '', + mimeType: '', + sizeOriginal: 0, + sizeActual: 0, + chunksTotal: 0, + chunksUploaded: 0, + encryption: false, + compression: 'none', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -563,7 +600,7 @@ export class Storage extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -572,6 +609,33 @@ export class Storage extends Service { }, apiPayload, ); + const defaults = { + root: 'file', + models: { + file: { + defaults: { + $id: '', + bucketId: '', + $createdAt: '', + $updatedAt: '', + $permissions: [], + name: '', + folder: '', + key: '', + signature: '', + mimeType: '', + sizeOriginal: 0, + sizeActual: 0, + chunksTotal: 0, + chunksUploaded: 0, + encryption: false, + compression: 'none', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -674,7 +738,7 @@ export class Storage extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -684,6 +748,33 @@ export class Storage extends Service { }, apiPayload, ); + const defaults = { + root: 'file', + models: { + file: { + defaults: { + $id: '', + bucketId: '', + $createdAt: '', + $updatedAt: '', + $permissions: [], + name: '', + folder: '', + key: '', + signature: '', + mimeType: '', + sizeOriginal: 0, + sizeActual: 0, + chunksTotal: 0, + chunksUploaded: 0, + encryption: false, + compression: 'none', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** diff --git a/src/services/tables-db.ts b/src/services/tables-db.ts index ae5d11d1..a41dc9a5 100644 --- a/src/services/tables-db.ts +++ b/src/services/tables-db.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -71,7 +71,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -80,6 +80,33 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transactionList', + models: { + transactionList: { + defaults: { + total: 0, + }, + properties: { + transactions: { + items: 'transaction', + }, + }, + }, + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -127,7 +154,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -137,6 +164,23 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -190,7 +234,7 @@ export class TablesDB extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -199,6 +243,23 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -285,7 +346,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -295,6 +356,23 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -427,7 +505,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -437,6 +515,23 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -567,7 +662,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -576,6 +671,33 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'rowList', + models: { + rowList: { + defaults: { + total: 0, + }, + properties: { + rows: { + items: 'row', + }, + }, + }, + row: { + defaults: { + $id: '', + $sequence: '', + $tableId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -734,7 +856,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -744,6 +866,23 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'row', + models: { + row: { + defaults: { + $id: '', + $sequence: '', + $tableId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -862,7 +1001,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -871,6 +1010,23 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'row', + models: { + row: { + defaults: { + $id: '', + $sequence: '', + $tableId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1025,7 +1181,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -1035,6 +1191,23 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'row', + models: { + row: { + defaults: { + $id: '', + $sequence: '', + $tableId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1189,7 +1362,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1199,6 +1372,23 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'row', + models: { + row: { + defaults: { + $id: '', + $sequence: '', + $tableId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1460,7 +1650,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1470,6 +1660,23 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'row', + models: { + row: { + defaults: { + $id: '', + $sequence: '', + $tableId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1616,7 +1823,7 @@ export class TablesDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1626,5 +1833,22 @@ export class TablesDB extends Service { }, apiPayload, ); + const defaults = { + root: 'row', + models: { + row: { + defaults: { + $id: '', + $sequence: '', + $tableId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } } diff --git a/src/services/teams.ts b/src/services/teams.ts index a4424fcd..caf37d38 100644 --- a/src/services/teams.ts +++ b/src/services/teams.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -85,7 +85,7 @@ export class Teams extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -94,6 +94,32 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'teamList', + models: { + teamList: { + defaults: { + total: 0, + }, + properties: { + teams: { + items: 'team', + }, + }, + }, + team: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + total: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -180,7 +206,7 @@ export class Teams extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -190,6 +216,22 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'team', + models: { + team: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + total: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -243,7 +285,7 @@ export class Teams extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -252,6 +294,22 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'team', + models: { + team: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + total: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -323,7 +381,7 @@ export class Teams extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -333,6 +391,22 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'team', + models: { + team: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + name: '', + total: 0, + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -469,7 +543,7 @@ export class Teams extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -478,6 +552,36 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'appInstallationList', + models: { + appInstallationList: { + defaults: { + total: 0, + }, + properties: { + installations: { + items: 'appInstallation', + }, + }, + }, + appInstallation: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + teamId: '', + scopes: [], + authorizationDetails: [], + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -566,7 +670,7 @@ export class Teams extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -576,6 +680,26 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'appInstallation', + models: { + appInstallation: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + teamId: '', + scopes: [], + authorizationDetails: [], + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -647,7 +771,7 @@ export class Teams extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -656,6 +780,26 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'appInstallation', + models: { + appInstallation: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + teamId: '', + scopes: [], + authorizationDetails: [], + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -748,7 +892,7 @@ export class Teams extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -758,6 +902,26 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'appInstallation', + models: { + appInstallation: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + appId: '', + teamId: '', + scopes: [], + authorizationDetails: [], + createdById: '', + createdByName: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -937,7 +1101,7 @@ export class Teams extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -946,6 +1110,42 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'membershipList', + models: { + membershipList: { + defaults: { + total: 0, + }, + properties: { + memberships: { + items: 'membership', + }, + }, + }, + membership: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + userName: '', + userEmail: '', + userPhone: '', + teamId: '', + teamName: '', + invited: '', + joined: '', + confirm: false, + mfa: false, + userAccessedAt: '', + roles: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -960,6 +1160,7 @@ export class Teams extends Service { * * @param {string} params.teamId - Team ID. * @param {string[]} params.roles - Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 81 characters long. + * @param {string} params.membershipId - Membership ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @param {string} params.email - Email of the new team member. * @param {string} params.userId - ID of the user to be added to a team. * @param {string} params.phone - Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. @@ -971,6 +1172,7 @@ export class Teams extends Service { createMembership(params: { teamId: string; roles: string[]; + membershipId?: string; email?: string; userId?: string; phone?: string; @@ -989,6 +1191,7 @@ export class Teams extends Service { * * @param {string} teamId - Team ID. * @param {string[]} roles - Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 81 characters long. + * @param {string} membershipId - Membership ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @param {string} email - Email of the new team member. * @param {string} userId - ID of the user to be added to a team. * @param {string} phone - Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. @@ -1001,6 +1204,7 @@ export class Teams extends Service { createMembership( teamId: string, roles: string[], + membershipId?: string, email?: string, userId?: string, phone?: string, @@ -1012,6 +1216,7 @@ export class Teams extends Service { | { teamId: string; roles: string[]; + membershipId?: string; email?: string; userId?: string; phone?: string; @@ -1019,11 +1224,20 @@ export class Teams extends Service { name?: string; } | string, - ...rest: [string[]?, string?, string?, string?, string?, string?] + ...rest: [ + string[]?, + string?, + string?, + string?, + string?, + string?, + string?, + ] ): Promise { let params: { teamId: string; roles: string[]; + membershipId?: string; email?: string; userId?: string; phone?: string; @@ -1039,6 +1253,7 @@ export class Teams extends Service { params = (paramsOrFirst || {}) as { teamId: string; roles: string[]; + membershipId?: string; email?: string; userId?: string; phone?: string; @@ -1049,16 +1264,18 @@ export class Teams extends Service { params = { teamId: paramsOrFirst as string, roles: rest[0] as string[], - email: rest[1] as string, - userId: rest[2] as string, - phone: rest[3] as string, - url: rest[4] as string, - name: rest[5] as string, + membershipId: rest[1] as string, + email: rest[2] as string, + userId: rest[3] as string, + phone: rest[4] as string, + url: rest[5] as string, + name: rest[6] as string, }; } const teamId = params.teamId; const roles = params.roles; + const membershipId = params.membershipId; const email = params.email; const userId = params.userId; const phone = params.phone; @@ -1079,6 +1296,10 @@ export class Teams extends Service { ); const apiPayload: Payload = {}; + if (typeof membershipId !== 'undefined') { + apiPayload['membershipId'] = membershipId; + } + if (typeof email !== 'undefined') { apiPayload['email'] = email; } @@ -1104,7 +1325,7 @@ export class Teams extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -1114,6 +1335,32 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'membership', + models: { + membership: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + userName: '', + userEmail: '', + userPhone: '', + teamId: '', + teamName: '', + invited: '', + joined: '', + confirm: false, + mfa: false, + userAccessedAt: '', + roles: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1185,7 +1432,7 @@ export class Teams extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1194,6 +1441,32 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'membership', + models: { + membership: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + userName: '', + userEmail: '', + userPhone: '', + teamId: '', + teamName: '', + invited: '', + joined: '', + confirm: false, + mfa: false, + userAccessedAt: '', + roles: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1283,7 +1556,7 @@ export class Teams extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1293,6 +1566,32 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'membership', + models: { + membership: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + userName: '', + userEmail: '', + userPhone: '', + teamId: '', + teamName: '', + invited: '', + joined: '', + confirm: false, + mfa: false, + userAccessedAt: '', + roles: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1490,7 +1789,7 @@ export class Teams extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1500,6 +1799,32 @@ export class Teams extends Service { }, apiPayload, ); + const defaults = { + root: 'membership', + models: { + membership: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + userId: '', + userName: '', + userEmail: '', + userPhone: '', + teamId: '', + teamName: '', + invited: '', + joined: '', + confirm: false, + mfa: false, + userAccessedAt: '', + roles: [], + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** diff --git a/src/services/vectors-db.ts b/src/services/vectors-db.ts index 710e8b44..1329e910 100644 --- a/src/services/vectors-db.ts +++ b/src/services/vectors-db.ts @@ -1,5 +1,5 @@ import { Service } from '../service'; -import { AppwriteException, Client } from '../client'; +import { AppwriteException, Client, applyDefaults } from '../client'; import type { Models } from '../models'; import type { Payload } from '../client'; @@ -71,7 +71,7 @@ export class VectorsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -80,6 +80,33 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transactionList', + models: { + transactionList: { + defaults: { + total: 0, + }, + properties: { + transactions: { + items: 'transaction', + }, + }, + }, + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -127,7 +154,7 @@ export class VectorsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -137,6 +164,23 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -190,7 +234,7 @@ export class VectorsDB extends Service { const apiPayload: Payload = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -199,6 +243,23 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -285,7 +346,7 @@ export class VectorsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -295,6 +356,23 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -427,7 +505,7 @@ export class VectorsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -437,6 +515,23 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'transaction', + models: { + transaction: { + defaults: { + $id: '', + $createdAt: '', + $updatedAt: '', + status: 'pending', + operations: 0, + expiresAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -573,7 +668,7 @@ export class VectorsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -582,6 +677,33 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'documentList', + models: { + documentList: { + defaults: { + total: 0, + }, + properties: { + documents: { + items: 'document', + }, + }, + }, + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -753,7 +875,7 @@ export class VectorsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -763,6 +885,23 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -901,7 +1040,7 @@ export class VectorsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'post', uri, { @@ -911,6 +1050,33 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'documentList', + models: { + documentList: { + defaults: { + total: 0, + }, + properties: { + documents: { + items: 'document', + }, + }, + }, + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1040,7 +1206,7 @@ export class VectorsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'get', uri, { @@ -1049,6 +1215,23 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1218,7 +1401,7 @@ export class VectorsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'put', uri, { @@ -1228,6 +1411,23 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /** @@ -1397,7 +1597,7 @@ export class VectorsDB extends Service { } const uri = new URL(this.client.config.endpoint + apiPath); - return this.client.call( + const request = this.client.call( 'patch', uri, { @@ -1407,6 +1607,23 @@ export class VectorsDB extends Service { }, apiPayload, ); + const defaults = { + root: 'document', + models: { + document: { + defaults: { + $id: '', + $sequence: '', + $collectionId: '', + $databaseId: '', + $createdAt: '', + $updatedAt: '', + }, + }, + }, + }; + + return request.then((response) => applyDefaults(response, defaults)); } /**