diff --git a/LICENSE b/LICENSE index 5479bb8..c1602fc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors. +Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index 21da491..575083b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Appwrite Console SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-console.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.6.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.6.1-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) @@ -33,7 +33,7 @@ import { Client, Account } from "@appwrite.io/console"; To install with a CDN (content delivery network) add the following scripts to the bottom of your tag, but before you use any Appwrite services: ```html - + ``` diff --git a/docs/examples/migrations/delete-firebase-auth.md b/docs/examples/account/get-coupon.md similarity index 52% rename from docs/examples/migrations/delete-firebase-auth.md rename to docs/examples/account/get-coupon.md index 8c7683b..356b018 100644 --- a/docs/examples/migrations/delete-firebase-auth.md +++ b/docs/examples/account/get-coupon.md @@ -1,11 +1,13 @@ -import { Client, Migrations } from "@appwrite.io/console"; +import { Client, Account } from "@appwrite.io/console"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID -const migrations = new Migrations(client); +const account = new Account(client); -const result = await migrations.deleteFirebaseAuth(); +const result = await account.getCoupon( + '' // couponId +); console.log(result); diff --git a/docs/examples/account/update-payment-method.md b/docs/examples/account/update-payment-method.md index 2b68c3c..4a6e312 100644 --- a/docs/examples/account/update-payment-method.md +++ b/docs/examples/account/update-payment-method.md @@ -9,7 +9,7 @@ const account = new Account(client); const result = await account.updatePaymentMethod( '', // paymentMethodId 1, // expiryMonth - 2024 // expiryYear + 2025 // expiryYear ); console.log(result); diff --git a/docs/examples/console/create-program-membership.md b/docs/examples/console/create-program-membership.md new file mode 100644 index 0000000..032fce9 --- /dev/null +++ b/docs/examples/console/create-program-membership.md @@ -0,0 +1,13 @@ +import { Client, Console } from "@appwrite.io/console"; + +const client = new Client() + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +const console = new Console(client); + +const result = await console.createProgramMembership( + '' // programId +); + +console.log(result); diff --git a/docs/examples/migrations/create-firebase-o-auth-migration.md b/docs/examples/migrations/create-firebase-o-auth-migration.md deleted file mode 100644 index bf57d42..0000000 --- a/docs/examples/migrations/create-firebase-o-auth-migration.md +++ /dev/null @@ -1,14 +0,0 @@ -import { Client, Migrations } from "@appwrite.io/console"; - -const client = new Client() - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID - -const migrations = new Migrations(client); - -const result = await migrations.createFirebaseOAuthMigration( - [], // resources - '' // projectId -); - -console.log(result); diff --git a/docs/examples/migrations/get-firebase-report-o-auth.md b/docs/examples/migrations/get-firebase-report-o-auth.md deleted file mode 100644 index 055ddfb..0000000 --- a/docs/examples/migrations/get-firebase-report-o-auth.md +++ /dev/null @@ -1,14 +0,0 @@ -import { Client, Migrations } from "@appwrite.io/console"; - -const client = new Client() - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID - -const migrations = new Migrations(client); - -const result = await migrations.getFirebaseReportOAuth( - [], // resources - '' // projectId -); - -console.log(result); diff --git a/docs/examples/migrations/list-firebase-projects.md b/docs/examples/migrations/list-firebase-projects.md deleted file mode 100644 index 833c05f..0000000 --- a/docs/examples/migrations/list-firebase-projects.md +++ /dev/null @@ -1,11 +0,0 @@ -import { Client, Migrations } from "@appwrite.io/console"; - -const client = new Client() - .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject(''); // Your project ID - -const migrations = new Migrations(client); - -const result = await migrations.listFirebaseProjects(); - -console.log(result); diff --git a/package.json b/package.json index 2325ca4..f3966e0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@appwrite.io/console", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "1.4.4", + "version": "1.4.6", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/client.ts b/src/client.ts index da0378f..6166a2d 100644 --- a/src/client.ts +++ b/src/client.ts @@ -19,9 +19,9 @@ type Headers = { */ type RealtimeResponse = { /** - * Type of the response: 'error', 'event', 'connected', or 'response'. + * Type of the response: 'error', 'event', 'connected', 'pong', or 'response'. */ - type: 'error' | 'event' | 'connected' | 'response'; + type: 'error' | 'event' | 'connected' | 'response' | 'pong'; /** * Data associated with the response based on the response type. @@ -129,6 +129,8 @@ type RealtimeRequestAuthenticate = { session: string; } +type TimeoutHandle = ReturnType | number; + /** * Realtime interface representing the structure of a realtime communication object. */ @@ -139,9 +141,14 @@ type Realtime = { socket?: WebSocket; /** - * Timeout duration for communication operations. + * Timeout for reconnect operations. */ - timeout?: number; + timeout?: TimeoutHandle; + + /** + * Heartbeat interval for the realtime connection. + */ + heartbeat?: TimeoutHandle; /** * URL for establishing the WebSocket connection. @@ -196,6 +203,11 @@ type Realtime = { */ createSocket: () => void; + /** + * Function to create a new heartbeat interval. + */ + createHeartbeat: () => void; + /** * Function to clean up resources associated with specified channels. * @@ -304,7 +316,7 @@ class Client { 'x-sdk-name': 'Console', 'x-sdk-platform': 'console', 'x-sdk-language': 'web', - 'x-sdk-version': '1.4.4', + 'x-sdk-version': '1.4.6', 'X-Appwrite-Response-Format': '1.6.0', }; @@ -407,6 +419,7 @@ class Client { private realtime: Realtime = { socket: undefined, timeout: undefined, + heartbeat: undefined, url: '', channels: new Set(), subscriptions: new Map(), @@ -432,6 +445,17 @@ class Client { return 60_000; } }, + createHeartbeat: () => { + if (this.realtime.heartbeat) { + clearTimeout(this.realtime.heartbeat); + } + + this.realtime.heartbeat = window?.setInterval(() => { + this.realtime.socket?.send(JSON.stringify({ + type: 'ping' + })); + }, 20_000); + }, createSocket: () => { if (this.realtime.channels.size < 1) { this.realtime.reconnect = false; @@ -465,6 +489,7 @@ class Client { this.realtime.socket.addEventListener('message', this.realtime.onMessage); this.realtime.socket.addEventListener('open', _event => { this.realtime.reconnectAttempts = 0; + this.realtime.createHeartbeat(); }); this.realtime.socket.addEventListener('close', event => { if ( diff --git a/src/enums/runtime.ts b/src/enums/runtime.ts index c2b5474..a97f627 100644 --- a/src/enums/runtime.ts +++ b/src/enums/runtime.ts @@ -54,4 +54,5 @@ export enum Runtime { Bun11 = 'bun-1.1', Go123 = 'go-1.23', Static1 = 'static-1', + Flutter324 = 'flutter-3.24', } \ No newline at end of file diff --git a/src/models.ts b/src/models.ts index c5debb4..fca92fb 100644 --- a/src/models.ts +++ b/src/models.ts @@ -496,19 +496,6 @@ export namespace Models { */ migrations: Migration[]; } - /** - * Migrations Firebase Projects List - */ - export type FirebaseProjectList = { - /** - * Total number of projects documents that matched your query. - */ - total: number; - /** - * List of projects. - */ - projects: FirebaseProject[]; - } /** * Specifications List */ @@ -1941,7 +1928,7 @@ export namespace Models { */ events: string[]; /** - * Function execution schedult in CRON format. + * Function execution schedule in CRON format. */ schedule: string; /** @@ -3110,7 +3097,7 @@ export namespace Models { /** * Resource ID. */ - resourceId: string; + resourceId?: string; /** * Resource name. */ @@ -3119,6 +3106,10 @@ export namespace Models { * The value of this metric at the timestamp. */ value: number; + /** + * The estimated value of this metric at the end of the period. + */ + estimate?: number; } /** * UsageDatabases @@ -3556,6 +3547,18 @@ export namespace Models { * Aggregated breakdown in totals of functions storage size (in bytes). */ functionsStorageBreakdown: MetricBreakdown[]; + /** + * Total aggregated number of phone auth. + */ + authPhoneTotal: number; + /** + * Estimated total aggregated cost of phone auth. + */ + authPhoneEstimate: number; + /** + * Aggregated breakdown in totals of phone auth by country. + */ + authPhoneCountryBreakdown: MetricBreakdown[]; } /** * Headers @@ -4086,19 +4089,6 @@ export namespace Models { */ version: string; } - /** - * MigrationFirebaseProject - */ - export type FirebaseProject = { - /** - * Project ID. - */ - projectId: string; - /** - * Project display name. - */ - displayName: string; - } /** * AdditionalResource */ @@ -4319,6 +4309,10 @@ export namespace Models { * Plan name */ name: string; + /** + * Plan order + */ + order: number; /** * Price */ @@ -4411,6 +4405,26 @@ export namespace Models { * Can user change the plan themselves */ selfService: boolean; + /** + * Does plan enable premium support + */ + premiumSupport: boolean; + /** + * Does plan support budget cap + */ + budgeting: boolean; + /** + * Does plan support mock numbers + */ + supportsMockNumbers: boolean; + /** + * Does plan support backup policies. + */ + backupsEnabled: boolean; + /** + * How many policies does plan support + */ + backupPolicies: number; } /** * Campaign @@ -4692,7 +4706,7 @@ export namespace Models { /** * Project budget limit */ - budgetAlerts: string[]; + budgetAlerts: number[]; /** * Billing plan selected. Can be one of `tier-0`, `tier-1` or `tier-2`. */ @@ -5068,6 +5082,14 @@ export namespace Models { * Aggregated stats for total storage. */ storageTotal: number; + /** + * Aggregated stats for total phone authentication SMS. + */ + authPhoneTotal: number; + /** + * Aggregated stats for estimated phone authentication SMS cost. + */ + authPhoneEstimate: number; /** * Aggregated stats for each projects. */ @@ -5105,6 +5127,14 @@ export namespace Models { * Aggregated stats for number of documents. */ storage: number; + /** + * Aggregated stats for phone authentication. + */ + authPhoneTotal: number; + /** + * Aggregated stats for phone authentication estimated cost. + */ + authPhoneEstimate: number; } /** * Aggregation team list diff --git a/src/services/account.ts b/src/services/account.ts index bdfa576..6d0f141 100644 --- a/src/services/account.ts +++ b/src/services/account.ts @@ -320,6 +320,34 @@ export class Account { payload ); } + /** + * Get coupon details + * + * + * @param {string} couponId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getCoupon(couponId: string): Promise { + if (typeof couponId === 'undefined') { + throw new AppwriteException('Missing required parameter: "couponId"'); + } + const apiPath = '/account/coupons/{couponId}'.replace('{couponId}', couponId); + const payload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + + return await this.client.call( + 'get', + uri, + apiHeaders, + payload + ); + } /** * Update email * @@ -1817,7 +1845,7 @@ A user is limited to 10 active sessions at a time by default. [Learn more about /** * Create magic URL token * - * Sends the user an email with a secret key for creating a session. If the provided user ID has not been registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default. + * Sends the user an email with a secret key for creating a session. If the provided user ID has not been registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). diff --git a/src/services/console.ts b/src/services/console.ts index eeb728f..b362a78 100644 --- a/src/services/console.ts +++ b/src/services/console.ts @@ -89,6 +89,34 @@ export class Console { payload ); } + /** + * Create program membership + * + * + * @param {string} programId + * @throws {AppwriteException} + * @returns {Promise<{}>} + */ + async createProgramMembership(programId: string): Promise<{}> { + if (typeof programId === 'undefined') { + throw new AppwriteException('Missing required parameter: "programId"'); + } + const apiPath = '/console/programs/{programId}/memberships'.replace('{programId}', programId); + const payload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + + return await this.client.call( + 'post', + uri, + apiHeaders, + payload + ); + } /** * Get Regions * diff --git a/src/services/migrations.ts b/src/services/migrations.ts index 69e5aff..b8331b8 100644 --- a/src/services/migrations.ts +++ b/src/services/migrations.ts @@ -146,7 +146,7 @@ export class Migrations { ); } /** - * Migrate Firebase data (Service Account) + * Migrate Firebase data * * * @param {string[]} resources @@ -183,92 +183,6 @@ export class Migrations { payload ); } - /** - * Revoke Appwrite's authorization to access Firebase projects - * - * - * @throws {AppwriteException} - * @returns {Promise<{}>} - */ - async deleteFirebaseAuth(): Promise<{}> { - const apiPath = '/migrations/firebase/deauthorize'; - const payload: Payload = {}; - const uri = new URL(this.client.config.endpoint + apiPath); - - const apiHeaders: { [header: string]: string } = { - 'content-type': 'application/json', - } - - - return await this.client.call( - 'get', - uri, - apiHeaders, - payload - ); - } - /** - * Migrate Firebase data (OAuth) - * - * - * @param {string[]} resources - * @param {string} projectId - * @throws {AppwriteException} - * @returns {Promise} - */ - async createFirebaseOAuthMigration(resources: string[], projectId: string): Promise { - if (typeof resources === 'undefined') { - throw new AppwriteException('Missing required parameter: "resources"'); - } - if (typeof projectId === 'undefined') { - throw new AppwriteException('Missing required parameter: "projectId"'); - } - const apiPath = '/migrations/firebase/oauth'; - const payload: Payload = {}; - if (typeof resources !== 'undefined') { - payload['resources'] = resources; - } - if (typeof projectId !== 'undefined') { - payload['projectId'] = projectId; - } - const uri = new URL(this.client.config.endpoint + apiPath); - - const apiHeaders: { [header: string]: string } = { - 'content-type': 'application/json', - } - - - return await this.client.call( - 'post', - uri, - apiHeaders, - payload - ); - } - /** - * List Firebase projects - * - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async listFirebaseProjects(): Promise { - const apiPath = '/migrations/firebase/projects'; - const payload: Payload = {}; - const uri = new URL(this.client.config.endpoint + apiPath); - - const apiHeaders: { [header: string]: string } = { - 'content-type': 'application/json', - } - - - return await this.client.call( - 'get', - uri, - apiHeaders, - payload - ); - } /** * Generate a report on Firebase data * @@ -300,44 +214,6 @@ export class Migrations { } - return await this.client.call( - 'get', - uri, - apiHeaders, - payload - ); - } - /** - * Generate a report on Firebase data using OAuth - * - * - * @param {string[]} resources - * @param {string} projectId - * @throws {AppwriteException} - * @returns {Promise} - */ - async getFirebaseReportOAuth(resources: string[], projectId: string): Promise { - if (typeof resources === 'undefined') { - throw new AppwriteException('Missing required parameter: "resources"'); - } - if (typeof projectId === 'undefined') { - throw new AppwriteException('Missing required parameter: "projectId"'); - } - const apiPath = '/migrations/firebase/report/oauth'; - const payload: Payload = {}; - if (typeof resources !== 'undefined') { - payload['resources'] = resources; - } - if (typeof projectId !== 'undefined') { - payload['projectId'] = projectId; - } - const uri = new URL(this.client.config.endpoint + apiPath); - - const apiHeaders: { [header: string]: string } = { - 'content-type': 'application/json', - } - - return await this.client.call( 'get', uri, diff --git a/src/services/organizations.ts b/src/services/organizations.ts index cd46739..79ad9a7 100644 --- a/src/services/organizations.ts +++ b/src/services/organizations.ts @@ -165,9 +165,9 @@ export class Organizations { * @param {string} organizationId * @param {string} aggregationId * @throws {AppwriteException} - * @returns {Promise} + * @returns {Promise} */ - async getAggregation(organizationId: string, aggregationId: string): Promise { + async getAggregation(organizationId: string, aggregationId: string): Promise { if (typeof organizationId === 'undefined') { throw new AppwriteException('Missing required parameter: "organizationId"'); } @@ -523,7 +523,7 @@ export class Organizations { ); } /** - * View invoice in PDF + * Download invoice in PDF * * * @param {string} organizationId