@appwrite.io/console 2.0.0 → 2.1.1

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 (49) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/sdk.js +81 -15
  4. package/dist/cjs/sdk.js.map +1 -1
  5. package/dist/esm/sdk.js +77 -15
  6. package/dist/esm/sdk.js.map +1 -1
  7. package/dist/iife/sdk.js +3838 -15
  8. package/docs/examples/account/update-payment-method.md +1 -1
  9. package/docs/examples/projects/update-labels.md +14 -0
  10. package/package.json +7 -1
  11. package/rollup.config.js +40 -24
  12. package/src/client.ts +49 -10
  13. package/src/models.ts +432 -424
  14. package/src/query.ts +14 -11
  15. package/src/services/account.ts +20 -20
  16. package/src/services/avatars.ts +117 -117
  17. package/src/services/backups.ts +18 -18
  18. package/src/services/console.ts +24 -24
  19. package/src/services/databases.ts +119 -119
  20. package/src/services/domains.ts +204 -204
  21. package/src/services/functions.ts +30 -30
  22. package/src/services/health.ts +146 -146
  23. package/src/services/messaging.ts +54 -54
  24. package/src/services/migrations.ts +36 -36
  25. package/src/services/organizations.ts +42 -42
  26. package/src/services/projects.ts +146 -83
  27. package/src/services/sites.ts +30 -30
  28. package/src/services/storage.ts +49 -49
  29. package/src/services/tables-db.ts +119 -119
  30. package/src/services/users.ts +39 -39
  31. package/types/client.d.ts +27 -1
  32. package/types/models.d.ts +432 -424
  33. package/types/query.d.ts +8 -8
  34. package/types/services/account.d.ts +11 -11
  35. package/types/services/avatars.d.ts +82 -82
  36. package/types/services/backups.d.ts +8 -8
  37. package/types/services/console.d.ts +14 -14
  38. package/types/services/databases.d.ts +70 -70
  39. package/types/services/domains.d.ts +104 -104
  40. package/types/services/functions.d.ts +15 -15
  41. package/types/services/health.d.ts +72 -72
  42. package/types/services/messaging.d.ts +24 -24
  43. package/types/services/migrations.d.ts +16 -16
  44. package/types/services/organizations.d.ts +22 -22
  45. package/types/services/projects.d.ts +60 -38
  46. package/types/services/sites.d.ts +15 -15
  47. package/types/services/storage.d.ts +34 -34
  48. package/types/services/tables-db.d.ts +70 -70
  49. package/types/services/users.d.ts +24 -24
@@ -9,7 +9,7 @@ const account = new Account(client);
9
9
  const result = await account.updatePaymentMethod({
10
10
  paymentMethodId: '<PAYMENT_METHOD_ID>',
11
11
  expiryMonth: 1,
12
- expiryYear: 2025,
12
+ expiryYear: 2026,
13
13
  state: '<STATE>' // optional
14
14
  });
15
15
 
@@ -0,0 +1,14 @@
1
+ import { Client, Projects } 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 projects = new Projects(client);
8
+
9
+ const result = await projects.updateLabels({
10
+ projectId: '<PROJECT_ID>',
11
+ labels: []
12
+ });
13
+
14
+ console.log(result);
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.0.0",
5
+ "version": "2.1.1",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "dist/cjs/sdk.js",
8
8
  "exports": {
@@ -24,8 +24,14 @@
24
24
  "build:types": "tsc --declaration --emitDeclarationOnly --outDir types",
25
25
  "build:libs": "rollup -c"
26
26
  },
27
+ "dependencies": {
28
+ "json-bigint": "1.0.0"
29
+ },
27
30
  "devDependencies": {
31
+ "@rollup/plugin-commonjs": "22.0.0",
32
+ "@rollup/plugin-node-resolve": "13.3.0",
28
33
  "@rollup/plugin-typescript": "8.3.2",
34
+ "@types/json-bigint": "1.0.4",
29
35
  "playwright": "1.56.1",
30
36
  "rollup": "2.79.2",
31
37
  "serve-handler": "6.1.0",
package/rollup.config.js CHANGED
@@ -1,27 +1,43 @@
1
1
  import pkg from "./package.json";
2
2
  import typescript from "@rollup/plugin-typescript";
3
+ import resolve from "@rollup/plugin-node-resolve";
4
+ import commonjs from "@rollup/plugin-commonjs";
3
5
 
4
- export default {
5
- external: Object.keys(pkg.dependencies ?? {}),
6
- input: "src/index.ts",
7
- plugins: [typescript()],
8
- output: [
9
- {
10
- format: "cjs",
11
- file: pkg.main,
12
- esModule: false,
13
- sourcemap: true,
14
- },
15
- {
16
- format: "es",
17
- file: pkg.module,
18
- sourcemap: true,
19
- },
20
- {
21
- format: "iife",
22
- file: pkg.jsdelivr,
23
- name: "Appwrite",
24
- extend: true,
25
- },
26
- ],
27
- };
6
+ const external = Object.keys(pkg.dependencies ?? {});
7
+
8
+ export default [
9
+ {
10
+ input: "src/index.ts",
11
+ external,
12
+ plugins: [typescript()],
13
+ output: [
14
+ {
15
+ format: "cjs",
16
+ file: pkg.main,
17
+ esModule: false,
18
+ sourcemap: true,
19
+ },
20
+ {
21
+ format: "es",
22
+ file: pkg.module,
23
+ sourcemap: true,
24
+ },
25
+ ],
26
+ },
27
+ {
28
+ input: "src/index.ts",
29
+ plugins: [
30
+ resolve({ browser: true }),
31
+ commonjs(),
32
+ typescript()
33
+ ],
34
+ output: [
35
+ {
36
+ format: "iife",
37
+ file: pkg.jsdelivr,
38
+ name: "Appwrite",
39
+ extend: true,
40
+ },
41
+ ],
42
+ }
43
+ ];
package/src/client.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { Models } from './models';
2
+ import JSONbigModule from 'json-bigint';
3
+ const JSONbig = JSONbigModule({ useNativeBigInt: true });
2
4
 
3
5
  /**
4
6
  * Payload type representing a key-value pair with string keys and any values.
@@ -303,7 +305,15 @@ class Client {
303
305
  config: {
304
306
  endpoint: string;
305
307
  endpointRealtime: string;
306
- [key: string]: string | undefined;
308
+ project: string;
309
+ key: string;
310
+ jwt: string;
311
+ locale: string;
312
+ mode: string;
313
+ cookie: string;
314
+ platform: string;
315
+ selfSigned: boolean;
316
+ session?: string;
307
317
  } = {
308
318
  endpoint: 'https://cloud.appwrite.io/v1',
309
319
  endpointRealtime: '',
@@ -312,7 +322,10 @@ class Client {
312
322
  jwt: '',
313
323
  locale: '',
314
324
  mode: '',
325
+ cookie: '',
315
326
  platform: '',
327
+ selfSigned: false,
328
+ session: undefined,
316
329
  };
317
330
  /**
318
331
  * Custom headers for API requests.
@@ -321,7 +334,7 @@ class Client {
321
334
  'x-sdk-name': 'Console',
322
335
  'x-sdk-platform': 'console',
323
336
  'x-sdk-language': 'web',
324
- 'x-sdk-version': '2.0.0',
337
+ 'x-sdk-version': '2.1.1',
325
338
  'X-Appwrite-Response-Format': '1.8.0',
326
339
  };
327
340
 
@@ -369,6 +382,18 @@ class Client {
369
382
  return this;
370
383
  }
371
384
 
385
+ /**
386
+ * Set self-signed
387
+ *
388
+ * @param {boolean} selfSigned
389
+ *
390
+ * @returns {this}
391
+ */
392
+ setSelfSigned(selfSigned: boolean): this {
393
+ this.config.selfSigned = selfSigned;
394
+ return this;
395
+ }
396
+
372
397
  /**
373
398
  * Set Project
374
399
  *
@@ -435,6 +460,20 @@ class Client {
435
460
  this.config.mode = value;
436
461
  return this;
437
462
  }
463
+ /**
464
+ * Set Cookie
465
+ *
466
+ * The user cookie to authenticate with
467
+ *
468
+ * @param value string
469
+ *
470
+ * @return {this}
471
+ */
472
+ setCookie(value: string): this {
473
+ this.headers['Cookie'] = value;
474
+ this.config.cookie = value;
475
+ return this;
476
+ }
438
477
  /**
439
478
  * Set Platform
440
479
  *
@@ -485,7 +524,7 @@ class Client {
485
524
  }
486
525
 
487
526
  this.realtime.heartbeat = window?.setInterval(() => {
488
- this.realtime.socket?.send(JSON.stringify({
527
+ this.realtime.socket?.send(JSONbig.stringify({
489
528
  type: 'ping'
490
529
  }));
491
530
  }, 20_000);
@@ -499,7 +538,7 @@ class Client {
499
538
 
500
539
  const channels = new URLSearchParams();
501
540
  if (this.config.project) {
502
- channels.set('project', this.config.project);
541
+ channels.set('project', this.config.project as string);
503
542
  }
504
543
  this.realtime.channels.forEach(channel => {
505
544
  channels.append('channels[]', channel);
@@ -551,19 +590,19 @@ class Client {
551
590
  },
552
591
  onMessage: (event) => {
553
592
  try {
554
- const message: RealtimeResponse = JSON.parse(event.data);
593
+ const message: RealtimeResponse = JSONbig.parse(event.data);
555
594
  this.realtime.lastMessage = message;
556
595
  switch (message.type) {
557
596
  case 'connected':
558
597
  let session = this.config.session;
559
598
  if (!session) {
560
- const cookie = JSON.parse(window.localStorage.getItem('cookieFallback') ?? '{}');
599
+ const cookie = JSONbig.parse(window.localStorage.getItem('cookieFallback') ?? '{}');
561
600
  session = cookie?.[`a_session_${this.config.project}`];
562
601
  }
563
602
 
564
603
  const messageData = <RealtimeResponseConnected>message.data;
565
604
  if (session && !messageData.user) {
566
- this.realtime.socket?.send(JSON.stringify(<RealtimeRequest>{
605
+ this.realtime.socket?.send(JSONbig.stringify(<RealtimeRequest>{
567
606
  type: 'authentication',
568
607
  data: {
569
608
  session
@@ -684,7 +723,7 @@ class Client {
684
723
  } else {
685
724
  switch (headers['content-type']) {
686
725
  case 'application/json':
687
- options.body = JSON.stringify(params);
726
+ options.body = JSONbig.stringify(params);
688
727
  break;
689
728
 
690
729
  case 'multipart/form-data':
@@ -786,7 +825,7 @@ class Client {
786
825
  }
787
826
 
788
827
  if (response.headers.get('content-type')?.includes('application/json')) {
789
- data = await response.json();
828
+ data = JSONbig.parse(await response.text());
790
829
  } else if (responseType === 'arrayBuffer') {
791
830
  data = await response.arrayBuffer();
792
831
  } else {
@@ -798,7 +837,7 @@ class Client {
798
837
  if (400 <= response.status) {
799
838
  let responseText = '';
800
839
  if (response.headers.get('content-type')?.includes('application/json') || responseType === 'arrayBuffer') {
801
- responseText = JSON.stringify(data);
840
+ responseText = JSONbig.stringify(data);
802
841
  } else {
803
842
  responseText = data?.message;
804
843
  }