Skip to content

Commit

Permalink
Merge pull request #32 from appwrite/dev
Browse files Browse the repository at this point in the history
feat: add authPhone to organisation and project uage
  • Loading branch information
christyjacob4 authored Jan 10, 2025
2 parents 2ee8ea8 + d31574a commit 9876f42
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 210 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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 <body> tag, but before you use any Appwrite services:

```html
<script src="https://cdn.jsdelivr.net/npm/@appwrite.io/console@1.4.4"></script>
<script src="https://cdn.jsdelivr.net/npm/@appwrite.io/console@1.4.6"></script>
```


Expand Down
Original file line number Diff line number Diff line change
@@ -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>'); // Your project ID

const migrations = new Migrations(client);
const account = new Account(client);

const result = await migrations.deleteFirebaseAuth();
const result = await account.getCoupon(
'<COUPON_ID>' // couponId
);

console.log(result);
2 changes: 1 addition & 1 deletion docs/examples/account/update-payment-method.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const account = new Account(client);
const result = await account.updatePaymentMethod(
'<PAYMENT_METHOD_ID>', // paymentMethodId
1, // expiryMonth
2024 // expiryYear
2025 // expiryYear
);

console.log(result);
13 changes: 13 additions & 0 deletions docs/examples/console/create-program-membership.md
Original file line number Diff line number Diff line change
@@ -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>'); // Your project ID

const console = new Console(client);

const result = await console.createProgramMembership(
'<PROGRAM_ID>' // programId
);

console.log(result);
14 changes: 0 additions & 14 deletions docs/examples/migrations/create-firebase-o-auth-migration.md

This file was deleted.

14 changes: 0 additions & 14 deletions docs/examples/migrations/get-firebase-report-o-auth.md

This file was deleted.

11 changes: 0 additions & 11 deletions docs/examples/migrations/list-firebase-projects.md

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
35 changes: 30 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -129,6 +129,8 @@ type RealtimeRequestAuthenticate = {
session: string;
}

type TimeoutHandle = ReturnType<typeof setTimeout> | number;

/**
* Realtime interface representing the structure of a realtime communication object.
*/
Expand All @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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',
};

Expand Down Expand Up @@ -407,6 +419,7 @@ class Client {
private realtime: Realtime = {
socket: undefined,
timeout: undefined,
heartbeat: undefined,
url: '',
channels: new Set(),
subscriptions: new Map(),
Expand All @@ -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;
Expand Down Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions src/enums/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ export enum Runtime {
Bun11 = 'bun-1.1',
Go123 = 'go-1.23',
Static1 = 'static-1',
Flutter324 = 'flutter-3.24',
}
88 changes: 59 additions & 29 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -1941,7 +1928,7 @@ export namespace Models {
*/
events: string[];
/**
* Function execution schedult in CRON format.
* Function execution schedule in CRON format.
*/
schedule: string;
/**
Expand Down Expand Up @@ -3110,7 +3097,7 @@ export namespace Models {
/**
* Resource ID.
*/
resourceId: string;
resourceId?: string;
/**
* Resource name.
*/
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -4086,19 +4089,6 @@ export namespace Models {
*/
version: string;
}
/**
* MigrationFirebaseProject
*/
export type FirebaseProject = {
/**
* Project ID.
*/
projectId: string;
/**
* Project display name.
*/
displayName: string;
}
/**
* AdditionalResource
*/
Expand Down Expand Up @@ -4319,6 +4309,10 @@ export namespace Models {
* Plan name
*/
name: string;
/**
* Plan order
*/
order: number;
/**
* Price
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9876f42

Please sign in to comment.