diff --git a/CHANGELOG.md b/CHANGELOG.md index 737ef947..d111ee5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change log +## 0.21.0 + +* Add `queries` parameter to `client.subscribe()` for filtering Realtime events +* Fix `Roles` enum removed from Teams service; `roles` parameter now accepts `string[]` +* Fix parameter detection in overloaded methods to check for optional params (Account, Avatars, Graphql) + ## 0.20.0 * Add array-based enum parameters (e.g., `permissions: BrowserPermission[]`). diff --git a/README.md b/README.md index ee5c4eb5..5452c01f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![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) -**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).** +**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).** Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the React Native SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index 41c726c7..824c129c 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -1,5 +1,5 @@ ```javascript -import { Client, Teams, Roles } from "react-native-appwrite"; +import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -9,7 +9,7 @@ const teams = new Teams(client); const result = await teams.createMembership({ teamId: '', - roles: [Roles.Admin], + roles: [], email: 'email@example.com', // optional userId: '', // optional phone: '+12065550100', // optional diff --git a/docs/examples/teams/update-membership.md b/docs/examples/teams/update-membership.md index a5109fcb..0f00f5ee 100644 --- a/docs/examples/teams/update-membership.md +++ b/docs/examples/teams/update-membership.md @@ -1,5 +1,5 @@ ```javascript -import { Client, Teams, Roles } from "react-native-appwrite"; +import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -10,7 +10,7 @@ const teams = new Teams(client); const result = await teams.updateMembership({ teamId: '', membershipId: '', - roles: [Roles.Admin] + roles: [] }); console.log(result); diff --git a/package.json b/package.json index f82bf3b5..ab9b6cc1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-appwrite", "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": "0.20.0", + "version": "0.21.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { diff --git a/src/channel.ts b/src/channel.ts index 1d68ded7..9e5dc479 100644 --- a/src/channel.ts +++ b/src/channel.ts @@ -13,7 +13,7 @@ interface Team { _team: any } interface Membership { _mem: any } interface Resolved { _res: any } -type Actionable = Document | Row | File | Execution | Team | Membership; +type Actionable = Document | Row | File | Team | Membership; function normalize(id: string): string { const trimmed = id.trim(); @@ -62,11 +62,6 @@ export class Channel { return this.next("files", id); } - // --- FUNCTION ROUTE --- - execution(this: Channel, id: string = "*"): Channel { - return this.next("executions", id); - } - // --- TERMINAL ACTIONS --- // Restricted to the Actionable union create(this: Channel): Channel { @@ -98,6 +93,10 @@ export class Channel { return new Channel(["functions", normalize(id)]); } + static execution(id: string = "*") { + return new Channel(["executions", normalize(id)]); + } + static team(id: string = "*") { return new Channel(["teams", normalize(id)]); } @@ -106,9 +105,8 @@ export class Channel { return new Channel(["memberships", normalize(id)]); } - static account(userId: string = ""): string { - const id = normalize(userId); - return id === "*" ? "account" : `account.${id}`; + static account(): string { + return "account"; } // Global events diff --git a/src/client.ts b/src/client.ts index a1c6632f..387d35e3 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,6 +1,7 @@ import { Models } from './models'; import { Service } from './service'; import { Platform } from 'react-native'; +import { Query } from './query'; import JSONbigModule from 'json-bigint'; import BigNumber from 'bignumber.js'; const JSONbigParser = JSONbigModule({ storeAsString: false }); @@ -90,8 +91,10 @@ type Realtime = { url?: string; lastMessage?: RealtimeResponse; channels: Set; + queries: Set; subscriptions: Map) => void }>; subscriptionsCounter: number; @@ -101,7 +104,7 @@ type Realtime = { connect: () => void; createSocket: () => void; createHeartbeat: () => void; - cleanUp: (channels: string[]) => void; + cleanUp: (channels: string[], queries: string[]) => void; onMessage: (event: MessageEvent) => void; } @@ -142,7 +145,7 @@ class Client { 'x-sdk-name': 'React Native', 'x-sdk-platform': 'client', 'x-sdk-language': 'reactnative', - 'x-sdk-version': '0.20.0', + 'x-sdk-version': '0.21.0', 'X-Appwrite-Response-Format': '1.8.0', }; @@ -284,6 +287,7 @@ class Client { heartbeat: undefined, url: '', channels: new Set(), + queries: new Set(), subscriptions: new Map(), subscriptionsCounter: 0, reconnect: true, @@ -330,6 +334,9 @@ class Client { this.realtime.channels.forEach(channel => { channels.append('channels[]', channel); }); + this.realtime.queries.forEach(query => { + channels.append('queries[]', query); + }); const url = this.config.endpointRealtime + '/realtime?' + channels.toString(); @@ -408,7 +415,7 @@ class Client { console.error(e); } }, - cleanUp: channels => { + cleanUp: (channels, queries) => { this.realtime.channels.forEach(channel => { if (channels.includes(channel)) { let found = Array.from(this.realtime.subscriptions).some(([_key, subscription] )=> { @@ -420,6 +427,18 @@ class Client { } } }) + + this.realtime.queries.forEach(query => { + if (queries.includes(query)) { + let found = Array.from(this.realtime.subscriptions).some(([_key, subscription]) => { + return subscription.queries?.includes(query); + }) + + if (!found) { + this.realtime.queries.delete(query); + } + } + }) } } @@ -448,13 +467,21 @@ class Client { * @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update. * @returns {() => void} Unsubscribes from events. */ - subscribe(channels: string | string[], callback: (payload: RealtimeResponseEvent) => void): () => void { + subscribe( + channels: string | string[], + callback: (payload: RealtimeResponseEvent) => void, + queries: (string | Query)[] = [] + ): () => void { let channelArray = typeof channels === 'string' ? [channels] : channels; channelArray.forEach(channel => this.realtime.channels.add(channel)); + const queryStrings = (queries ?? []).map(q => typeof q === 'string' ? q : q.toString()); + queryStrings.forEach(query => this.realtime.queries.add(query)); + const counter = this.realtime.subscriptionsCounter++; this.realtime.subscriptions.set(counter, { channels: channelArray, + queries: queryStrings, callback }); @@ -462,7 +489,7 @@ class Client { return () => { this.realtime.subscriptions.delete(counter); - this.realtime.cleanUp(channelArray); + this.realtime.cleanUp(channelArray, queryStrings); this.realtime.connect(); } } diff --git a/src/enums/o-auth-provider.ts b/src/enums/o-auth-provider.ts index 3382e3bf..66833dfe 100644 --- a/src/enums/o-auth-provider.ts +++ b/src/enums/o-auth-provider.ts @@ -38,4 +38,6 @@ export enum OAuthProvider { Yandex = 'yandex', Zoho = 'zoho', Zoom = 'zoom', + GithubImagine = 'githubImagine', + GoogleImagine = 'googleImagine', } \ No newline at end of file diff --git a/src/enums/roles.ts b/src/enums/roles.ts deleted file mode 100644 index f548f935..00000000 --- a/src/enums/roles.ts +++ /dev/null @@ -1,5 +0,0 @@ -export enum Roles { - Admin = 'admin', - Developer = 'developer', - Owner = 'owner', -} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 50baa582..f6d51fd5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,6 +29,5 @@ export { BrowserPermission } from './enums/browser-permission'; export { ImageFormat } from './enums/image-format'; export { ExecutionMethod } from './enums/execution-method'; export { ImageGravity } from './enums/image-gravity'; -export { Roles } from './enums/roles'; export { ExecutionTrigger } from './enums/execution-trigger'; export { ExecutionStatus } from './enums/execution-status'; diff --git a/src/services/account.ts b/src/services/account.ts index cee6e8b5..4c523326 100644 --- a/src/services/account.ts +++ b/src/services/account.ts @@ -447,7 +447,7 @@ export class Account extends Service { ): Promise { let params: { type: AuthenticatorType }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'type' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { type: AuthenticatorType }; } else { params = { @@ -492,7 +492,7 @@ export class Account extends Service { ): Promise { let params: { type: AuthenticatorType }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'type' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { type: AuthenticatorType }; } else { params = { @@ -541,7 +541,7 @@ export class Account extends Service { ): Promise> { let params: { type: AuthenticatorType, otp: string }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'type' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst || 'otp' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { type: AuthenticatorType, otp: string }; } else { params = { @@ -599,7 +599,7 @@ export class Account extends Service { ): Promise> { let params: { type: AuthenticatorType, otp: string }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'type' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst || 'otp' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { type: AuthenticatorType, otp: string }; } else { params = { @@ -655,7 +655,7 @@ export class Account extends Service { ): Promise<{}> { let params: { type: AuthenticatorType }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'type' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { type: AuthenticatorType }; } else { params = { @@ -700,7 +700,7 @@ export class Account extends Service { ): Promise<{}> { let params: { type: AuthenticatorType }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'type' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('type' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { type: AuthenticatorType }; } else { params = { @@ -746,7 +746,7 @@ export class Account extends Service { ): Promise { let params: { factor: AuthenticationFactor }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'factor' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('factor' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { factor: AuthenticationFactor }; } else { params = { @@ -795,7 +795,7 @@ export class Account extends Service { ): Promise { let params: { factor: AuthenticationFactor }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'factor' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('factor' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { factor: AuthenticationFactor }; } else { params = { @@ -1281,7 +1281,7 @@ export class Account extends Service { ): Promise> { let params: { prefs: Partial }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'prefs' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('prefs' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { prefs: Partial }; } else { params = { @@ -1632,7 +1632,7 @@ export class Account extends Service { * A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). * * - * @param {OAuthProvider} params.provider - OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom. + * @param {OAuthProvider} params.provider - OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom, githubImagine, googleImagine. * @param {string} params.success - URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string} params.failure - URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string[]} params.scopes - A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. @@ -1648,7 +1648,7 @@ export class Account extends Service { * A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). * * - * @param {OAuthProvider} provider - OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom. + * @param {OAuthProvider} provider - OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom, githubImagine, googleImagine. * @param {string} success - URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string} failure - URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string[]} scopes - A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. @@ -1663,7 +1663,7 @@ export class Account extends Service { ): void | URL { let params: { provider: OAuthProvider, success?: string, failure?: string, scopes?: string[] }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'provider' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('provider' in paramsOrFirst || 'success' in paramsOrFirst || 'failure' in paramsOrFirst || 'scopes' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { provider: OAuthProvider, success?: string, failure?: string, scopes?: string[] }; } else { params = { @@ -2323,7 +2323,7 @@ export class Account extends Service { * * A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). * - * @param {OAuthProvider} params.provider - OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom. + * @param {OAuthProvider} params.provider - OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom, githubImagine, googleImagine. * @param {string} params.success - URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string} params.failure - URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string[]} params.scopes - A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. @@ -2338,7 +2338,7 @@ export class Account extends Service { * * A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). * - * @param {OAuthProvider} provider - OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom. + * @param {OAuthProvider} provider - OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom, githubImagine, googleImagine. * @param {string} success - URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string} failure - URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @param {string[]} scopes - A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes. Maximum of 100 scopes are allowed, each 4096 characters long. @@ -2353,7 +2353,7 @@ export class Account extends Service { ): void | URL { let params: { provider: OAuthProvider, success?: string, failure?: string, scopes?: string[] }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'provider' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('provider' in paramsOrFirst || 'success' in paramsOrFirst || 'failure' in paramsOrFirst || 'scopes' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { provider: OAuthProvider, success?: string, failure?: string, scopes?: string[] }; } else { params = { diff --git a/src/services/avatars.ts b/src/services/avatars.ts index e7f475ce..e216f092 100644 --- a/src/services/avatars.ts +++ b/src/services/avatars.ts @@ -53,7 +53,7 @@ export class Avatars extends Service { ): Promise { let params: { code: Browser, width?: number, height?: number, quality?: number }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'code' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('code' in paramsOrFirst || 'width' in paramsOrFirst || 'height' in paramsOrFirst || 'quality' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { code: Browser, width?: number, height?: number, quality?: number }; } else { params = { @@ -134,7 +134,7 @@ export class Avatars extends Service { ): Promise { let params: { code: CreditCard, width?: number, height?: number, quality?: number }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'code' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('code' in paramsOrFirst || 'width' in paramsOrFirst || 'height' in paramsOrFirst || 'quality' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { code: CreditCard, width?: number, height?: number, quality?: number }; } else { params = { @@ -273,7 +273,7 @@ export class Avatars extends Service { ): Promise { let params: { code: Flag, width?: number, height?: number, quality?: number }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'code' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('code' in paramsOrFirst || 'width' in paramsOrFirst || 'height' in paramsOrFirst || 'quality' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { code: Flag, width?: number, height?: number, quality?: number }; } else { params = { diff --git a/src/services/graphql.ts b/src/services/graphql.ts index 4d67b695..1c3bdba7 100644 --- a/src/services/graphql.ts +++ b/src/services/graphql.ts @@ -35,7 +35,7 @@ export class Graphql extends Service { ): Promise<{}> { let params: { query: object }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'query' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('query' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { query: object }; } else { params = { @@ -85,7 +85,7 @@ export class Graphql extends Service { ): Promise<{}> { let params: { query: object }; - if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'query' in paramsOrFirst)) { + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && ('query' in paramsOrFirst))) { params = (paramsOrFirst || {}) as { query: object }; } else { params = { diff --git a/src/services/teams.ts b/src/services/teams.ts index 19a462b6..ae8c4ea4 100644 --- a/src/services/teams.ts +++ b/src/services/teams.ts @@ -5,7 +5,6 @@ import type { UploadProgress, Payload } from '../client'; import * as FileSystem from 'expo-file-system'; import { Platform } from 'react-native'; -import { Roles } from '../enums/roles'; export class Teams extends Service { @@ -372,7 +371,7 @@ export class Teams extends Service { * * * @param {string} params.teamId - Team ID. - * @param {Roles[]} params.roles - Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. + * @param {string[]} params.roles - Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. * @param {string} params.email - Email of the new team member. * @param {string} params.userId - ID of the user to be added to a team. * @param {string} params.phone - Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. @@ -381,7 +380,7 @@ export class Teams extends Service { * @throws {AppwriteException} * @returns {Promise} */ - createMembership(params: { teamId: string, roles: Roles[], email?: string, userId?: string, phone?: string, url?: string, name?: string }): Promise; + createMembership(params: { teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string }): Promise; /** * Invite a new member to join your team. Provide an ID for existing users, or invite unregistered users using an email or phone number. If initiated from a Client SDK, Appwrite will send an email or sms with a link to join the team to the invited user, and an account will be created for them if one doesn't exist. If initiated from a Server SDK, the new member will be added automatically to the team. * @@ -393,7 +392,7 @@ export class Teams extends Service { * * * @param {string} teamId - Team ID. - * @param {Roles[]} roles - Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. + * @param {string[]} roles - Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. * @param {string} email - Email of the new team member. * @param {string} userId - ID of the user to be added to a team. * @param {string} phone - Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. @@ -403,19 +402,19 @@ export class Teams extends Service { * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - createMembership(teamId: string, roles: Roles[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise; + createMembership(teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise; createMembership( - paramsOrFirst: { teamId: string, roles: Roles[], email?: string, userId?: string, phone?: string, url?: string, name?: string } | string, - ...rest: [(Roles[])?, (string)?, (string)?, (string)?, (string)?, (string)?] + paramsOrFirst: { teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string } | string, + ...rest: [(string[])?, (string)?, (string)?, (string)?, (string)?, (string)?] ): Promise { - let params: { teamId: string, roles: Roles[], email?: string, userId?: string, phone?: string, url?: string, name?: string }; + let params: { teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { teamId: string, roles: Roles[], email?: string, userId?: string, phone?: string, url?: string, name?: string }; + params = (paramsOrFirst || {}) as { teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string }; } else { params = { teamId: paramsOrFirst as string, - roles: rest[0] as Roles[], + roles: rest[0] as string[], email: rest[1] as string, userId: rest[2] as string, phone: rest[3] as string, @@ -532,36 +531,36 @@ export class Teams extends Service { * * @param {string} params.teamId - Team ID. * @param {string} params.membershipId - Membership ID. - * @param {Roles[]} params.roles - An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. + * @param {string[]} params.roles - An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. * @throws {AppwriteException} * @returns {Promise} */ - updateMembership(params: { teamId: string, membershipId: string, roles: Roles[] }): Promise; + updateMembership(params: { teamId: string, membershipId: string, roles: string[] }): Promise; /** * Modify the roles of a team member. Only team members with the owner role have access to this endpoint. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). * * * @param {string} teamId - Team ID. * @param {string} membershipId - Membership ID. - * @param {Roles[]} roles - An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. + * @param {string[]} roles - An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. * @throws {AppwriteException} * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - updateMembership(teamId: string, membershipId: string, roles: Roles[]): Promise; + updateMembership(teamId: string, membershipId: string, roles: string[]): Promise; updateMembership( - paramsOrFirst: { teamId: string, membershipId: string, roles: Roles[] } | string, - ...rest: [(string)?, (Roles[])?] + paramsOrFirst: { teamId: string, membershipId: string, roles: string[] } | string, + ...rest: [(string)?, (string[])?] ): Promise { - let params: { teamId: string, membershipId: string, roles: Roles[] }; + let params: { teamId: string, membershipId: string, roles: string[] }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { teamId: string, membershipId: string, roles: Roles[] }; + params = (paramsOrFirst || {}) as { teamId: string, membershipId: string, roles: string[] }; } else { params = { teamId: paramsOrFirst as string, membershipId: rest[0] as string, - roles: rest[1] as Roles[] + roles: rest[1] as string[] }; }