Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
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@3.1.0"></script>
<script src="https://cdn.jsdelivr.net/npm/@appwrite.io/console@4.0.0"></script>
```


Expand Down
3 changes: 2 additions & 1 deletion docs/examples/databases/list-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const result = await databases.listDocuments({
collectionId: '<COLLECTION_ID>',
queries: [], // optional
transactionId: '<TRANSACTION_ID>', // optional
total: false // optional
total: false, // optional
ttl: 0 // optional
});

console.log(result);
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/domains/create-purchase.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const domains = new Domains(client);

const result = await domains.createPurchase({
domain: '',
teamId: '<TEAM_ID>',
organizationId: '<ORGANIZATION_ID>',
firstName: '<FIRST_NAME>',
lastName: '<LAST_NAME>',
email: 'email@example.com',
Expand Down
18 changes: 18 additions & 0 deletions docs/examples/domains/create-transfer-in.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```javascript
import { Client, Domains } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const domains = new Domains(client);

const result = await domains.createTransferIn({
domain: '',
organizationId: '<ORGANIZATION_ID>',
authCode: '<AUTH_CODE>',
paymentMethodId: '<PAYMENT_METHOD_ID>'
});

console.log(result);
```
16 changes: 16 additions & 0 deletions docs/examples/domains/create-transfer-out.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```javascript
import { Client, Domains } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const domains = new Domains(client);

const result = await domains.createTransferOut({
domainId: '<DOMAIN_ID>',
organizationId: '<ORGANIZATION_ID>'
});

console.log(result);
```
15 changes: 15 additions & 0 deletions docs/examples/domains/get-transfer-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```javascript
import { Client, Domains } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const domains = new Domains(client);

const result = await domains.getTransferStatus({
domainId: '<DOMAIN_ID>'
});

console.log(result);
```
16 changes: 16 additions & 0 deletions docs/examples/health/get-console-pausing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```javascript
import { Client, Health } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const health = new Health(client);

const result = await health.getConsolePausing({
threshold: null, // optional
inactivityDays: null // optional
});

console.log(result);
```
4 changes: 2 additions & 2 deletions docs/examples/migrations/create-appwrite-migration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, AppwriteMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.createAppwriteMigration({
resources: [Resources.User],
resources: [AppwriteMigrationResource.User],
endpoint: 'https://example.com',
projectId: '<PROJECT_ID>',
apiKey: '<API_KEY>'
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/create-firebase-migration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, FirebaseMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.createFirebaseMigration({
resources: [Resources.User],
resources: [FirebaseMigrationResource.User],
serviceAccount: '<SERVICE_ACCOUNT>'
});

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/create-n-host-migration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, NHostMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.createNHostMigration({
resources: [Resources.User],
resources: [NHostMigrationResource.User],
subdomain: '<SUBDOMAIN>',
region: '<REGION>',
adminSecret: '<ADMIN_SECRET>',
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/create-supabase-migration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, SupabaseMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.createSupabaseMigration({
resources: [Resources.User],
resources: [SupabaseMigrationResource.User],
endpoint: 'https://example.com',
apiKey: '<API_KEY>',
databaseHost: '<DATABASE_HOST>',
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/get-appwrite-report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, AppwriteMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.getAppwriteReport({
resources: [Resources.User],
resources: [AppwriteMigrationResource.User],
endpoint: 'https://example.com',
projectID: '<PROJECT_ID>',
key: '<KEY>'
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/get-firebase-report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, FirebaseMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.getFirebaseReport({
resources: [Resources.User],
resources: [FirebaseMigrationResource.User],
serviceAccount: '<SERVICE_ACCOUNT>'
});

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/get-n-host-report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, NHostMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.getNHostReport({
resources: [Resources.User],
resources: [NHostMigrationResource.User],
subdomain: '<SUBDOMAIN>',
region: '<REGION>',
adminSecret: '<ADMIN_SECRET>',
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/migrations/get-supabase-report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import { Client, Migrations, Resources } from "@appwrite.io/console";
import { Client, Migrations, SupabaseMigrationResource } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
Expand All @@ -8,7 +8,7 @@ const client = new Client()
const migrations = new Migrations(client);

const result = await migrations.getSupabaseReport({
resources: [Resources.User],
resources: [SupabaseMigrationResource.User],
endpoint: 'https://example.com',
apiKey: '<API_KEY>',
databaseHost: '<DATABASE_HOST>',
Expand Down
15 changes: 15 additions & 0 deletions docs/examples/projects/update-console-access.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```javascript
import { Client, Projects } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const projects = new Projects(client);

const result = await projects.updateConsoleAccess({
projectId: '<PROJECT_ID>'
});

console.log(result);
```
16 changes: 16 additions & 0 deletions docs/examples/projects/update-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```javascript
import { Client, Projects, Status } from "@appwrite.io/console";

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID

const projects = new Projects(client);

const result = await projects.updateStatus({
projectId: '<PROJECT_ID>',
status: Status.Active
});

console.log(result);
```
4 changes: 2 additions & 2 deletions docs/examples/sites/create-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const sites = new Sites(client);
const result = await sites.createDeployment({
siteId: '<SITE_ID>',
code: document.getElementById('uploader').files[0],
activate: false,
installCommand: '<INSTALL_COMMAND>', // optional
buildCommand: '<BUILD_COMMAND>', // optional
outputDirectory: '<OUTPUT_DIRECTORY>' // optional
outputDirectory: '<OUTPUT_DIRECTORY>', // optional
activate: false // optional
});

console.log(result);
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/tablesdb/list-rows.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const result = await tablesDB.listRows({
tableId: '<TABLE_ID>',
queries: [], // optional
transactionId: '<TRANSACTION_ID>', // optional
total: false // optional
total: false, // optional
ttl: 0 // optional
});

console.log(result);
Expand Down
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 abstracts and simplifies complex and repetitive development tasks behind a very simple REST API",
"version": "3.1.0",
"version": "4.0.0",
"license": "BSD-3-Clause",
"main": "dist/cjs/sdk.js",
"exports": {
Expand Down
34 changes: 19 additions & 15 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ interface Resolved { _res: any }
type Actionable = Document | Row | File | Team | Membership;

function normalize(id: string): string {
const trimmed = id.trim();
return trimmed === "" ? "*" : trimmed;
if (id === undefined || id === null) {
throw new Error("Channel ID is required");
}
const trimmed = String(id).trim();
if (trimmed === "") {
throw new Error("Channel ID is required");
}
return trimmed;
}

export class Channel<T> {
Expand All @@ -44,9 +50,8 @@ export class Channel<T> {

// --- DATABASE ROUTE ---
// Only available on Channel<Database>
collection(this: Channel<Database>, id?: string): Channel<Collection> {
// Default: wildcard collection ID
return this.next<Collection>("collections", id ?? "*");
collection(this: Channel<Database>, id: string): Channel<Collection> {
return this.next<Collection>("collections", id);
}

// Only available on Channel<Collection>
Expand All @@ -56,9 +61,8 @@ export class Channel<T> {
}

// --- TABLESDB ROUTE ---
table(this: Channel<TablesDB>, id?: string): Channel<Table> {
// Default: wildcard table ID
return this.next<Table>("tables", id ?? "*");
table(this: Channel<TablesDB>, id: string): Channel<Table> {
return this.next<Table>("tables", id);
}

row(this: Channel<Table>, id?: string): Channel<Row> {
Expand Down Expand Up @@ -91,31 +95,31 @@ export class Channel<T> {
}

// --- ROOT FACTORIES ---
static database(id: string = "*") {
static database(id: string) {
return new Channel<Database>(["databases", normalize(id)]);
}

static execution(id: string = "*") {
static execution(id: string) {
return new Channel<Execution>(["executions", normalize(id)]);
}

static tablesdb(id: string = "*") {
static tablesdb(id: string) {
return new Channel<TablesDB>(["tablesdb", normalize(id)]);
}

static bucket(id: string = "*") {
static bucket(id: string) {
return new Channel<Bucket>(["buckets", normalize(id)]);
}

static function(id: string = "*") {
static function(id: string) {
return new Channel<Func>(["functions", normalize(id)]);
}

static team(id: string = "*") {
static team(id: string) {
return new Channel<Team>(["teams", normalize(id)]);
}

static membership(id: string = "*") {
static membership(id: string) {
return new Channel<Membership>(["memberships", normalize(id)]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class Client {
'x-sdk-name': 'Console',
'x-sdk-platform': 'console',
'x-sdk-language': 'web',
'x-sdk-version': '3.1.0',
'x-sdk-version': '4.0.0',
'X-Appwrite-Response-Format': '1.8.0',
};

Expand Down
Loading