@appwrite.io/console 2.1.1 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/sdk.js +311 -17
  4. package/dist/cjs/sdk.js.map +1 -1
  5. package/dist/esm/sdk.js +310 -18
  6. package/dist/esm/sdk.js.map +1 -1
  7. package/dist/iife/sdk.js +344 -70
  8. package/docs/examples/domains/list-suggestions.md +18 -0
  9. package/docs/examples/health/get-queue-audits.md +13 -0
  10. package/docs/examples/organizations/create.md +2 -2
  11. package/docs/examples/organizations/estimation-create-organization.md +2 -2
  12. package/docs/examples/organizations/estimation-update-plan.md +2 -2
  13. package/docs/examples/organizations/update-plan.md +2 -2
  14. package/package.json +3 -2
  15. package/src/channel.ts +134 -0
  16. package/src/client.ts +79 -9
  17. package/src/enums/billing-plan.ts +17 -0
  18. package/src/enums/filter-type.ts +4 -0
  19. package/src/enums/name.ts +1 -0
  20. package/src/enums/o-auth-provider.ts +0 -2
  21. package/src/index.ts +3 -0
  22. package/src/models.ts +437 -375
  23. package/src/query.ts +42 -0
  24. package/src/services/account.ts +20 -20
  25. package/src/services/avatars.ts +117 -117
  26. package/src/services/backups.ts +18 -18
  27. package/src/services/console.ts +24 -24
  28. package/src/services/databases.ts +89 -89
  29. package/src/services/domains.ts +295 -204
  30. package/src/services/functions.ts +30 -30
  31. package/src/services/health.ts +201 -152
  32. package/src/services/messaging.ts +54 -54
  33. package/src/services/migrations.ts +36 -36
  34. package/src/services/organizations.ts +67 -66
  35. package/src/services/projects.ts +81 -81
  36. package/src/services/realtime.ts +35 -12
  37. package/src/services/sites.ts +30 -30
  38. package/src/services/storage.ts +45 -45
  39. package/src/services/tables-db.ts +89 -89
  40. package/src/services/users.ts +39 -39
  41. package/types/channel.d.ts +71 -0
  42. package/types/client.d.ts +11 -3
  43. package/types/enums/billing-plan.d.ts +17 -0
  44. package/types/enums/filter-type.d.ts +4 -0
  45. package/types/enums/name.d.ts +1 -0
  46. package/types/enums/o-auth-provider.d.ts +0 -2
  47. package/types/index.d.ts +3 -0
  48. package/types/models.d.ts +434 -375
  49. package/types/query.d.ts +30 -0
  50. package/types/services/account.d.ts +11 -11
  51. package/types/services/avatars.d.ts +82 -82
  52. package/types/services/backups.d.ts +8 -8
  53. package/types/services/console.d.ts +14 -14
  54. package/types/services/databases.d.ts +50 -50
  55. package/types/services/domains.d.ts +139 -104
  56. package/types/services/functions.d.ts +15 -15
  57. package/types/services/health.d.ts +95 -78
  58. package/types/services/messaging.d.ts +24 -24
  59. package/types/services/migrations.d.ts +16 -16
  60. package/types/services/organizations.d.ts +37 -36
  61. package/types/services/projects.d.ts +36 -36
  62. package/types/services/realtime.d.ts +17 -8
  63. package/types/services/sites.d.ts +15 -15
  64. package/types/services/storage.d.ts +30 -30
  65. package/types/services/tables-db.d.ts +50 -50
  66. package/types/services/users.d.ts +24 -24
@@ -0,0 +1,18 @@
1
+ import { Client, Domains, FilterType } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const domains = new Domains(client);
8
+
9
+ const result = await domains.listSuggestions({
10
+ query: '<QUERY>',
11
+ tlds: [], // optional
12
+ limit: null, // optional
13
+ filterType: FilterType.Premium, // optional
14
+ priceMax: null, // optional
15
+ priceMin: null // optional
16
+ });
17
+
18
+ console.log(result);
@@ -0,0 +1,13 @@
1
+ import { Client, Health } from "@appwrite.io/console";
2
+
3
+ const client = new Client()
4
+ .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5
+ .setProject('<YOUR_PROJECT_ID>'); // Your project ID
6
+
7
+ const health = new Health(client);
8
+
9
+ const result = await health.getQueueAudits({
10
+ threshold: null // optional
11
+ });
12
+
13
+ console.log(result);
@@ -1,4 +1,4 @@
1
- import { Client, Organizations, Platform } from "@appwrite.io/console";
1
+ import { Client, Organizations, BillingPlan, Platform } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -9,7 +9,7 @@ const organizations = new Organizations(client);
9
9
  const result = await organizations.create({
10
10
  organizationId: '<ORGANIZATION_ID>',
11
11
  name: '<NAME>',
12
- billingPlan: 'tier-0',
12
+ billingPlan: BillingPlan.Tier0,
13
13
  paymentMethodId: '<PAYMENT_METHOD_ID>', // optional
14
14
  billingAddressId: '<BILLING_ADDRESS_ID>', // optional
15
15
  invites: [], // optional
@@ -1,4 +1,4 @@
1
- import { Client, Organizations, Platform } from "@appwrite.io/console";
1
+ import { Client, Organizations, BillingPlan, Platform } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -7,7 +7,7 @@ const client = new Client()
7
7
  const organizations = new Organizations(client);
8
8
 
9
9
  const result = await organizations.estimationCreateOrganization({
10
- billingPlan: 'tier-0',
10
+ billingPlan: BillingPlan.Tier0,
11
11
  paymentMethodId: '<PAYMENT_METHOD_ID>', // optional
12
12
  invites: [], // optional
13
13
  couponId: '<COUPON_ID>', // optional
@@ -1,4 +1,4 @@
1
- import { Client, Organizations } from "@appwrite.io/console";
1
+ import { Client, Organizations, BillingPlan } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -8,7 +8,7 @@ const organizations = new Organizations(client);
8
8
 
9
9
  const result = await organizations.estimationUpdatePlan({
10
10
  organizationId: '<ORGANIZATION_ID>',
11
- billingPlan: 'tier-0',
11
+ billingPlan: BillingPlan.Tier0,
12
12
  invites: [], // optional
13
13
  couponId: '<COUPON_ID>' // optional
14
14
  });
@@ -1,4 +1,4 @@
1
- import { Client, Organizations } from "@appwrite.io/console";
1
+ import { Client, Organizations, BillingPlan } from "@appwrite.io/console";
2
2
 
3
3
  const client = new Client()
4
4
  .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
@@ -8,7 +8,7 @@ const organizations = new Organizations(client);
8
8
 
9
9
  const result = await organizations.updatePlan({
10
10
  organizationId: '<ORGANIZATION_ID>',
11
- billingPlan: 'tier-0',
11
+ billingPlan: BillingPlan.Tier0,
12
12
  paymentMethodId: '<PAYMENT_METHOD_ID>', // optional
13
13
  billingAddressId: '<BILLING_ADDRESS_ID>', // optional
14
14
  invites: [], // optional
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@appwrite.io/console",
3
3
  "homepage": "https://appwrite.io/support",
4
4
  "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",
5
- "version": "2.1.1",
5
+ "version": "2.1.3",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "dist/cjs/sdk.js",
8
8
  "exports": {
@@ -25,7 +25,8 @@
25
25
  "build:libs": "rollup -c"
26
26
  },
27
27
  "dependencies": {
28
- "json-bigint": "1.0.0"
28
+ "json-bigint": "1.0.0",
29
+ "bignumber.js": "9.0.0"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@rollup/plugin-commonjs": "22.0.0",
package/src/channel.ts ADDED
@@ -0,0 +1,134 @@
1
+ interface Root {}
2
+ interface Database { _db: any }
3
+ interface Collection { _coll: any }
4
+ interface Document { _doc: any }
5
+ interface TablesDB { _tdb: any }
6
+ interface Table { _tbl: any }
7
+ interface Row { _row: any }
8
+ interface Bucket { _bkt: any }
9
+ interface File { _file: any }
10
+ interface Func { _fn: any }
11
+ interface Execution { _exec: any }
12
+ interface Team { _team: any }
13
+ interface Membership { _mem: any }
14
+ interface Resolved { _res: any }
15
+
16
+ type Actionable = Document | Row | File | Execution | Team | Membership;
17
+
18
+ function normalize(id: string): string {
19
+ const trimmed = id.trim();
20
+ return trimmed === "" ? "*" : trimmed;
21
+ }
22
+
23
+ export class Channel<T> {
24
+ declare _type: T;
25
+
26
+ private constructor(private readonly segments: string[]) {}
27
+
28
+ private next<N>(segment: string, id: string = "*"): Channel<N> {
29
+ return new Channel<N>([...this.segments, segment, normalize(id)]) as any;
30
+ }
31
+
32
+ private resolve(action: string): Channel<Resolved> {
33
+ return new Channel<Resolved>([...this.segments, action]) as any;
34
+ }
35
+
36
+ toString(): string {
37
+ return this.segments.join(".");
38
+ }
39
+
40
+ // --- DATABASE ROUTE ---
41
+ // Only available on Channel<Database>
42
+ collection(this: Channel<Database>, id: string = "*"): Channel<Collection> {
43
+ return this.next<Collection>("collections", id);
44
+ }
45
+
46
+ // Only available on Channel<Collection>
47
+ document(this: Channel<Collection>, id: string = "*"): Channel<Document> {
48
+ return this.next<Document>("documents", id);
49
+ }
50
+
51
+ // --- TABLESDB ROUTE ---
52
+ table(this: Channel<TablesDB>, id: string = "*"): Channel<Table> {
53
+ return this.next<Table>("tables", id);
54
+ }
55
+
56
+ row(this: Channel<Table>, id: string = "*"): Channel<Row> {
57
+ return this.next<Row>("rows", id);
58
+ }
59
+
60
+ // --- BUCKET ROUTE ---
61
+ file(this: Channel<Bucket>, id: string = "*"): Channel<File> {
62
+ return this.next<File>("files", id);
63
+ }
64
+
65
+ // --- FUNCTION ROUTE ---
66
+ execution(this: Channel<Func>, id: string = "*"): Channel<Execution> {
67
+ return this.next<Execution>("executions", id);
68
+ }
69
+
70
+ // --- TERMINAL ACTIONS ---
71
+ // Restricted to the Actionable union
72
+ create(this: Channel<Actionable>): Channel<Resolved> {
73
+ return this.resolve("create");
74
+ }
75
+
76
+ update(this: Channel<Actionable>): Channel<Resolved> {
77
+ return this.resolve("update");
78
+ }
79
+
80
+ delete(this: Channel<Actionable>): Channel<Resolved> {
81
+ return this.resolve("delete");
82
+ }
83
+
84
+ // --- ROOT FACTORIES ---
85
+ static database(id: string = "*") {
86
+ return new Channel<Database>(["databases", normalize(id)]);
87
+ }
88
+
89
+ static tablesdb(id: string = "*") {
90
+ return new Channel<TablesDB>(["tablesdb", normalize(id)]);
91
+ }
92
+
93
+ static bucket(id: string = "*") {
94
+ return new Channel<Bucket>(["buckets", normalize(id)]);
95
+ }
96
+
97
+ static function(id: string = "*") {
98
+ return new Channel<Func>(["functions", normalize(id)]);
99
+ }
100
+
101
+ static team(id: string = "*") {
102
+ return new Channel<Team>(["teams", normalize(id)]);
103
+ }
104
+
105
+ static membership(id: string = "*") {
106
+ return new Channel<Membership>(["memberships", normalize(id)]);
107
+ }
108
+
109
+ static account(userId: string = ""): string {
110
+ const id = normalize(userId);
111
+ return id === "*" ? "account" : `account.${id}`;
112
+ }
113
+
114
+ // Global events
115
+ static get documents(): string {
116
+ return "documents";
117
+ }
118
+
119
+ static get rows(): string {
120
+ return "rows";
121
+ }
122
+
123
+ static get files(): string {
124
+ return "files";
125
+ }
126
+
127
+ static get executions(): string {
128
+ return "executions";
129
+ }
130
+ }
131
+
132
+ // Export types for backward compatibility with realtime
133
+ export type ActionableChannel = Channel<Document> | Channel<Row> | Channel<File> | Channel<Execution> | Channel<Team> | Channel<Membership>;
134
+ export type ResolvedChannel = Channel<Resolved>;
package/src/client.ts CHANGED
@@ -1,6 +1,57 @@
1
1
  import { Models } from './models';
2
+ import { Channel, ActionableChannel, ResolvedChannel } from './channel';
2
3
  import JSONbigModule from 'json-bigint';
3
- const JSONbig = JSONbigModule({ useNativeBigInt: true });
4
+ import BigNumber from 'bignumber.js';
5
+ const JSONbigParser = JSONbigModule({ storeAsString: false });
6
+ const JSONbigSerializer = JSONbigModule({ useNativeBigInt: true });
7
+
8
+ /**
9
+ * Converts BigNumber objects from json-bigint to native types.
10
+ * - Integer BigNumbers → BigInt (if unsafe) or number (if safe)
11
+ * - Float BigNumbers → number
12
+ * - Strings remain strings (never converted to BigNumber by json-bigint)
13
+ */
14
+ const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
15
+ const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
16
+
17
+ function convertBigNumbers(value: any): any {
18
+ if (value === null || value === undefined) return value;
19
+
20
+ if (Array.isArray(value)) {
21
+ return value.map(convertBigNumbers);
22
+ }
23
+
24
+ if (BigNumber.isBigNumber(value)) {
25
+ if (value.isInteger()) {
26
+ const str = value.toFixed();
27
+ const bi = BigInt(str);
28
+
29
+ if (bi >= MIN_SAFE && bi <= MAX_SAFE) {
30
+ return Number(str);
31
+ }
32
+
33
+ return bi;
34
+ }
35
+
36
+ // float
37
+ return value.toNumber();
38
+ }
39
+
40
+ if (typeof value === 'object') {
41
+ const result: any = {};
42
+ for (const [k, v] of Object.entries(value)) {
43
+ result[k] = convertBigNumbers(v);
44
+ }
45
+ return result;
46
+ }
47
+
48
+ return value;
49
+ }
50
+
51
+ const JSONbig = {
52
+ parse: (text: string) => convertBigNumbers(JSONbigParser.parse(text)),
53
+ stringify: JSONbigSerializer.stringify
54
+ };
4
55
 
5
56
  /**
6
57
  * Payload type representing a key-value pair with string keys and any values.
@@ -334,7 +385,7 @@ class Client {
334
385
  'x-sdk-name': 'Console',
335
386
  'x-sdk-platform': 'console',
336
387
  'x-sdk-language': 'web',
337
- 'x-sdk-version': '2.1.1',
388
+ 'x-sdk-version': '2.1.3',
338
389
  'X-Appwrite-Response-Format': '1.8.0',
339
390
  };
340
391
 
@@ -654,8 +705,8 @@ class Client {
654
705
  * @deprecated Use the Realtime service instead.
655
706
  * @see Realtime
656
707
  *
657
- * @param {string|string[]} channels
658
- * Channel to subscribe - pass a single channel as a string or multiple with an array of strings.
708
+ * @param {string|string[]|Channel<any>|ActionableChannel|ResolvedChannel|(Channel<any>|ActionableChannel|ResolvedChannel)[]} channels
709
+ * Channel to subscribe - pass a single channel as a string or Channel builder instance, or multiple with an array.
659
710
  *
660
711
  * Possible channels are:
661
712
  * - account
@@ -673,16 +724,35 @@ class Client {
673
724
  * - teams.[ID]
674
725
  * - memberships
675
726
  * - memberships.[ID]
727
+ *
728
+ * You can also use Channel builders:
729
+ * - Channel.database('db').collection('col').document('doc').create()
730
+ * - Channel.bucket('bucket').file('file').update()
731
+ * - Channel.function('func').execution('exec').delete()
732
+ * - Channel.team('team').create()
733
+ * - Channel.membership('membership').update()
676
734
  * @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update.
677
735
  * @returns {() => void} Unsubscribes from events.
678
736
  */
679
- subscribe<T extends unknown>(channels: string | string[], callback: (payload: RealtimeResponseEvent<T>) => void): () => void {
680
- let channelArray = typeof channels === 'string' ? [channels] : channels;
681
- channelArray.forEach(channel => this.realtime.channels.add(channel));
737
+ subscribe<T extends unknown>(channels: string | string[] | Channel<any> | ActionableChannel | ResolvedChannel | (Channel<any> | ActionableChannel | ResolvedChannel)[], callback: (payload: RealtimeResponseEvent<T>) => void): () => void {
738
+ const channelArray = Array.isArray(channels) ? channels : [channels];
739
+ // Convert Channel instances to strings
740
+ const channelStrings = channelArray.map(ch => {
741
+ if (typeof ch === 'string') {
742
+ return ch;
743
+ }
744
+ // All Channel instances have toString() method
745
+ if (ch && typeof (ch as Channel<any>).toString === 'function') {
746
+ return (ch as Channel<any>).toString();
747
+ }
748
+ // Fallback to generic string conversion
749
+ return String(ch);
750
+ });
751
+ channelStrings.forEach(channel => this.realtime.channels.add(channel));
682
752
 
683
753
  const counter = this.realtime.subscriptionsCounter++;
684
754
  this.realtime.subscriptions.set(counter, {
685
- channels: channelArray,
755
+ channels: channelStrings,
686
756
  callback
687
757
  });
688
758
 
@@ -690,7 +760,7 @@ class Client {
690
760
 
691
761
  return () => {
692
762
  this.realtime.subscriptions.delete(counter);
693
- this.realtime.cleanUp(channelArray);
763
+ this.realtime.cleanUp(channelStrings);
694
764
  this.realtime.connect();
695
765
  }
696
766
  }
@@ -0,0 +1,17 @@
1
+ export enum BillingPlan {
2
+ Tier0 = 'tier-0',
3
+ Tier1 = 'tier-1',
4
+ Tier2 = 'tier-2',
5
+ Imaginetier0 = 'imagine-tier-0',
6
+ Imaginetier1 = 'imagine-tier-1',
7
+ Imaginetier150 = 'imagine-tier-1-50',
8
+ Imaginetier1100 = 'imagine-tier-1-100',
9
+ Imaginetier1200 = 'imagine-tier-1-200',
10
+ Imaginetier1290 = 'imagine-tier-1-290',
11
+ Imaginetier1480 = 'imagine-tier-1-480',
12
+ Imaginetier1700 = 'imagine-tier-1-700',
13
+ Imaginetier1900 = 'imagine-tier-1-900',
14
+ Imaginetier11100 = 'imagine-tier-1-1100',
15
+ Imaginetier11650 = 'imagine-tier-1-1650',
16
+ Imaginetier12200 = 'imagine-tier-1-2200',
17
+ }
@@ -0,0 +1,4 @@
1
+ export enum FilterType {
2
+ Premium = 'premium',
3
+ Suggestion = 'suggestion',
4
+ }
package/src/enums/name.ts CHANGED
@@ -9,6 +9,7 @@ export enum Name {
9
9
  V1webhooks = 'v1-webhooks',
10
10
  V1certificates = 'v1-certificates',
11
11
  V1builds = 'v1-builds',
12
+ V1screenshots = 'v1-screenshots',
12
13
  V1messaging = 'v1-messaging',
13
14
  V1migrations = 'v1-migrations',
14
15
  }
@@ -38,8 +38,6 @@ export enum OAuthProvider {
38
38
  Yandex = 'yandex',
39
39
  Zoho = 'zoho',
40
40
  Zoom = 'zoom',
41
- Mock = 'mock',
42
- Mockunverified = 'mock-unverified',
43
41
  GithubImagine = 'githubImagine',
44
42
  GoogleImagine = 'googleImagine',
45
43
  }
package/src/index.ts CHANGED
@@ -36,6 +36,7 @@ export type { QueryTypes, QueryTypesList } from './query';
36
36
  export { Permission } from './permission';
37
37
  export { Role } from './role';
38
38
  export { ID } from './id';
39
+ export { Channel } from './channel';
39
40
  export { Operator, Condition } from './operator';
40
41
  export { AuthenticatorType } from './enums/authenticator-type';
41
42
  export { AuthenticationFactor } from './enums/authentication-factor';
@@ -52,6 +53,7 @@ export { UsageRange } from './enums/usage-range';
52
53
  export { RelationshipType } from './enums/relationship-type';
53
54
  export { RelationMutate } from './enums/relation-mutate';
54
55
  export { IndexType } from './enums/index-type';
56
+ export { FilterType } from './enums/filter-type';
55
57
  export { Runtime } from './enums/runtime';
56
58
  export { TemplateReferenceType } from './enums/template-reference-type';
57
59
  export { VCSReferenceType } from './enums/vcs-reference-type';
@@ -60,6 +62,7 @@ export { ExecutionMethod } from './enums/execution-method';
60
62
  export { Name } from './enums/name';
61
63
  export { MessagePriority } from './enums/message-priority';
62
64
  export { SmtpEncryption } from './enums/smtp-encryption';
65
+ export { BillingPlan } from './enums/billing-plan';
63
66
  export { ProjectUsageRange } from './enums/project-usage-range';
64
67
  export { Region } from './enums/region';
65
68
  export { Api } from './enums/api';