react-native-appwrite 0.1.0

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 (109) hide show
  1. package/.github/ISSUE_TEMPLATE/bug.yaml +82 -0
  2. package/.github/ISSUE_TEMPLATE/documentation.yaml +32 -0
  3. package/.github/ISSUE_TEMPLATE/feature.yaml +40 -0
  4. package/.github/workflows/publish.yml +33 -0
  5. package/.gitpod.yml +10 -0
  6. package/CHANGELOG.md +1 -0
  7. package/LICENSE +12 -0
  8. package/README.md +111 -0
  9. package/dist/cjs/sdk.js +3127 -0
  10. package/dist/cjs/sdk.js.map +1 -0
  11. package/dist/esm/sdk.js +3108 -0
  12. package/dist/esm/sdk.js.map +1 -0
  13. package/dist/iife/sdk.js +3126 -0
  14. package/docs/examples/account/create-anonymous-session.md +18 -0
  15. package/docs/examples/account/create-email-session.md +18 -0
  16. package/docs/examples/account/create-j-w-t.md +18 -0
  17. package/docs/examples/account/create-magic-u-r-l-session.md +18 -0
  18. package/docs/examples/account/create-o-auth2session.md +14 -0
  19. package/docs/examples/account/create-phone-session.md +18 -0
  20. package/docs/examples/account/create-phone-verification.md +18 -0
  21. package/docs/examples/account/create-recovery.md +18 -0
  22. package/docs/examples/account/create-verification.md +18 -0
  23. package/docs/examples/account/create.md +18 -0
  24. package/docs/examples/account/delete-identity.md +18 -0
  25. package/docs/examples/account/delete-session.md +18 -0
  26. package/docs/examples/account/delete-sessions.md +18 -0
  27. package/docs/examples/account/get-prefs.md +18 -0
  28. package/docs/examples/account/get-session.md +18 -0
  29. package/docs/examples/account/get.md +18 -0
  30. package/docs/examples/account/list-identities.md +18 -0
  31. package/docs/examples/account/list-logs.md +18 -0
  32. package/docs/examples/account/list-sessions.md +18 -0
  33. package/docs/examples/account/update-email.md +18 -0
  34. package/docs/examples/account/update-magic-u-r-l-session.md +18 -0
  35. package/docs/examples/account/update-name.md +18 -0
  36. package/docs/examples/account/update-password.md +18 -0
  37. package/docs/examples/account/update-phone-session.md +18 -0
  38. package/docs/examples/account/update-phone-verification.md +18 -0
  39. package/docs/examples/account/update-phone.md +18 -0
  40. package/docs/examples/account/update-prefs.md +18 -0
  41. package/docs/examples/account/update-recovery.md +18 -0
  42. package/docs/examples/account/update-session.md +18 -0
  43. package/docs/examples/account/update-status.md +18 -0
  44. package/docs/examples/account/update-verification.md +18 -0
  45. package/docs/examples/avatars/get-browser.md +14 -0
  46. package/docs/examples/avatars/get-credit-card.md +14 -0
  47. package/docs/examples/avatars/get-favicon.md +14 -0
  48. package/docs/examples/avatars/get-flag.md +14 -0
  49. package/docs/examples/avatars/get-image.md +14 -0
  50. package/docs/examples/avatars/get-initials.md +14 -0
  51. package/docs/examples/avatars/get-q-r.md +14 -0
  52. package/docs/examples/databases/create-document.md +18 -0
  53. package/docs/examples/databases/delete-document.md +18 -0
  54. package/docs/examples/databases/get-document.md +18 -0
  55. package/docs/examples/databases/list-documents.md +18 -0
  56. package/docs/examples/databases/update-document.md +18 -0
  57. package/docs/examples/functions/create-execution.md +18 -0
  58. package/docs/examples/functions/get-execution.md +18 -0
  59. package/docs/examples/functions/list-executions.md +18 -0
  60. package/docs/examples/graphql/mutation.md +18 -0
  61. package/docs/examples/graphql/query.md +18 -0
  62. package/docs/examples/locale/get.md +18 -0
  63. package/docs/examples/locale/list-codes.md +18 -0
  64. package/docs/examples/locale/list-continents.md +18 -0
  65. package/docs/examples/locale/list-countries-e-u.md +18 -0
  66. package/docs/examples/locale/list-countries-phones.md +18 -0
  67. package/docs/examples/locale/list-countries.md +18 -0
  68. package/docs/examples/locale/list-currencies.md +18 -0
  69. package/docs/examples/locale/list-languages.md +18 -0
  70. package/docs/examples/storage/create-file.md +18 -0
  71. package/docs/examples/storage/delete-file.md +18 -0
  72. package/docs/examples/storage/get-file-download.md +14 -0
  73. package/docs/examples/storage/get-file-preview.md +14 -0
  74. package/docs/examples/storage/get-file-view.md +14 -0
  75. package/docs/examples/storage/get-file.md +18 -0
  76. package/docs/examples/storage/list-files.md +18 -0
  77. package/docs/examples/storage/update-file.md +18 -0
  78. package/docs/examples/teams/create-membership.md +18 -0
  79. package/docs/examples/teams/create.md +18 -0
  80. package/docs/examples/teams/delete-membership.md +18 -0
  81. package/docs/examples/teams/delete.md +18 -0
  82. package/docs/examples/teams/get-membership.md +18 -0
  83. package/docs/examples/teams/get-prefs.md +18 -0
  84. package/docs/examples/teams/get.md +18 -0
  85. package/docs/examples/teams/list-memberships.md +18 -0
  86. package/docs/examples/teams/list.md +18 -0
  87. package/docs/examples/teams/update-membership-status.md +18 -0
  88. package/docs/examples/teams/update-membership.md +18 -0
  89. package/docs/examples/teams/update-name.md +18 -0
  90. package/docs/examples/teams/update-prefs.md +18 -0
  91. package/package.json +47 -0
  92. package/rollup.config.js +31 -0
  93. package/src/client.ts +437 -0
  94. package/src/id.ts +9 -0
  95. package/src/index.ts +14 -0
  96. package/src/models.ts +1021 -0
  97. package/src/permission.ts +22 -0
  98. package/src/query.ts +74 -0
  99. package/src/role.ts +100 -0
  100. package/src/service.ts +30 -0
  101. package/src/services/account.ts +1066 -0
  102. package/src/services/avatars.ts +352 -0
  103. package/src/services/databases.ts +216 -0
  104. package/src/services/functions.ts +125 -0
  105. package/src/services/graphql.ts +68 -0
  106. package/src/services/locale.ts +169 -0
  107. package/src/services/storage.ts +411 -0
  108. package/src/services/teams.ts +484 -0
  109. package/tsconfig.json +24 -0
@@ -0,0 +1,22 @@
1
+ export class Permission {
2
+
3
+ static read = (role: string): string => {
4
+ return `read("${role}")`
5
+ }
6
+
7
+ static write = (role: string): string => {
8
+ return `write("${role}")`
9
+ }
10
+
11
+ static create = (role: string): string => {
12
+ return `create("${role}")`
13
+ }
14
+
15
+ static update = (role: string): string => {
16
+ return `update("${role}")`
17
+ }
18
+
19
+ static delete = (role: string): string => {
20
+ return `delete("${role}")`
21
+ }
22
+ }
package/src/query.ts ADDED
@@ -0,0 +1,74 @@
1
+ type QueryTypesSingle = string | number | boolean;
2
+ export type QueryTypesList = string[] | number[] | boolean[];
3
+ export type QueryTypes = QueryTypesSingle | QueryTypesList;
4
+
5
+ export class Query {
6
+ static equal = (attribute: string, value: QueryTypes): string =>
7
+ Query.addQuery(attribute, "equal", value);
8
+
9
+ static notEqual = (attribute: string, value: QueryTypes): string =>
10
+ Query.addQuery(attribute, "notEqual", value);
11
+
12
+ static lessThan = (attribute: string, value: QueryTypes): string =>
13
+ Query.addQuery(attribute, "lessThan", value);
14
+
15
+ static lessThanEqual = (attribute: string, value: QueryTypes): string =>
16
+ Query.addQuery(attribute, "lessThanEqual", value);
17
+
18
+ static greaterThan = (attribute: string, value: QueryTypes): string =>
19
+ Query.addQuery(attribute, "greaterThan", value);
20
+
21
+ static greaterThanEqual = (attribute: string, value: QueryTypes): string =>
22
+ Query.addQuery(attribute, "greaterThanEqual", value);
23
+
24
+ static isNull = (attribute: string): string =>
25
+ `isNull("${attribute}")`;
26
+
27
+ static isNotNull = (attribute: string): string =>
28
+ `isNotNull("${attribute}")`;
29
+
30
+ static between = (attribute: string, start: string|number, end: string|number): string =>
31
+ `between("${attribute}", ${Query.parseValues(start)}, ${Query.parseValues(end)})`;
32
+
33
+ static startsWith = (attribute: string, value: string): string =>
34
+ Query.addQuery(attribute, "startsWith", value);
35
+
36
+ static endsWith = (attribute: string, value: string): string =>
37
+ Query.addQuery(attribute, "endsWith", value);
38
+
39
+ static select = (attributes: string[]): string =>
40
+ `select([${attributes.map((attr: string) => `"${attr}"`).join(",")}])`;
41
+
42
+ static search = (attribute: string, value: string): string =>
43
+ Query.addQuery(attribute, "search", value);
44
+
45
+ static orderDesc = (attribute: string): string =>
46
+ `orderDesc("${attribute}")`;
47
+
48
+ static orderAsc = (attribute: string): string =>
49
+ `orderAsc("${attribute}")`;
50
+
51
+ static cursorAfter = (documentId: string): string =>
52
+ `cursorAfter("${documentId}")`;
53
+
54
+ static cursorBefore = (documentId: string): string =>
55
+ `cursorBefore("${documentId}")`;
56
+
57
+ static limit = (limit: number): string =>
58
+ `limit(${limit})`;
59
+
60
+ static offset = (offset: number): string =>
61
+ `offset(${offset})`;
62
+
63
+ private static addQuery = (attribute: string, method: string, value: QueryTypes): string =>
64
+ value instanceof Array
65
+ ? `${method}("${attribute}", [${value
66
+ .map((v: QueryTypesSingle) => Query.parseValues(v))
67
+ .join(",")}])`
68
+ : `${method}("${attribute}", [${Query.parseValues(value)}])`;
69
+
70
+ private static parseValues = (value: QueryTypes): string =>
71
+ typeof value === "string" || value instanceof String
72
+ ? `"${value}"`
73
+ : `${value}`;
74
+ }
package/src/role.ts ADDED
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Helper class to generate role strings for `Permission`.
3
+ */
4
+ export class Role {
5
+
6
+ /**
7
+ * Grants access to anyone.
8
+ *
9
+ * This includes authenticated and unauthenticated users.
10
+ *
11
+ * @returns {string}
12
+ */
13
+ public static any(): string {
14
+ return 'any'
15
+ }
16
+
17
+ /**
18
+ * Grants access to a specific user by user ID.
19
+ *
20
+ * You can optionally pass verified or unverified for
21
+ * `status` to target specific types of users.
22
+ *
23
+ * @param {string} id
24
+ * @param {string} status
25
+ * @returns {string}
26
+ */
27
+ public static user(id: string, status: string = ''): string {
28
+ if (status === '') {
29
+ return `user:${id}`
30
+ }
31
+ return `user:${id}/${status}`
32
+ }
33
+
34
+ /**
35
+ * Grants access to any authenticated or anonymous user.
36
+ *
37
+ * You can optionally pass verified or unverified for
38
+ * `status` to target specific types of users.
39
+ *
40
+ * @param {string} status
41
+ * @returns {string}
42
+ */
43
+ public static users(status: string = ''): string {
44
+ if (status === '') {
45
+ return 'users'
46
+ }
47
+ return `users/${status}`
48
+ }
49
+
50
+ /**
51
+ * Grants access to any guest user without a session.
52
+ *
53
+ * Authenticated users don't have access to this role.
54
+ *
55
+ * @returns {string}
56
+ */
57
+ public static guests(): string {
58
+ return 'guests'
59
+ }
60
+
61
+ /**
62
+ * Grants access to a team by team ID.
63
+ *
64
+ * You can optionally pass a role for `role` to target
65
+ * team members with the specified role.
66
+ *
67
+ * @param {string} id
68
+ * @param {string} role
69
+ * @returns {string}
70
+ */
71
+ public static team(id: string, role: string = ''): string {
72
+ if (role === '') {
73
+ return `team:${id}`
74
+ }
75
+ return `team:${id}/${role}`
76
+ }
77
+
78
+ /**
79
+ * Grants access to a specific member of a team.
80
+ *
81
+ * When the member is removed from the team, they will
82
+ * no longer have access.
83
+ *
84
+ * @param {string} id
85
+ * @returns {string}
86
+ */
87
+ public static member(id: string): string {
88
+ return `member:${id}`
89
+ }
90
+
91
+ /**
92
+ * Grants access to a user with the specified label.
93
+ *
94
+ * @param {string} name
95
+ * @returns {string}
96
+ */
97
+ public static label(name: string): string {
98
+ return `label:${name}`
99
+ }
100
+ }
package/src/service.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { Client } from './client';
2
+ import type { Payload } from './client';
3
+
4
+ export class Service {
5
+ static CHUNK_SIZE = 5*1024*1024; // 5MB
6
+
7
+ client: Client;
8
+
9
+ constructor(client: Client) {
10
+ this.client = client;
11
+ }
12
+
13
+ static flatten(data: Payload, prefix = ''): Payload {
14
+ let output: Payload = {};
15
+
16
+ for (const key in data) {
17
+ let value = data[key];
18
+ let finalKey = prefix ? `${prefix}[${key}]` : key;
19
+
20
+ if (Array.isArray(value)) {
21
+ output = Object.assign(output, this.flatten(value, finalKey));
22
+ }
23
+ else {
24
+ output[finalKey] = value;
25
+ }
26
+ }
27
+
28
+ return output;
29
+ }
30
+ }