main page
This commit is contained in:
442
node_modules/appwrite/src/client.ts
generated
vendored
Normal file
442
node_modules/appwrite/src/client.ts
generated
vendored
Normal file
@@ -0,0 +1,442 @@
|
||||
import 'isomorphic-form-data';
|
||||
import { fetch } from 'cross-fetch';
|
||||
import { Models } from './models';
|
||||
import { Service } from './service';
|
||||
|
||||
type Payload = {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
type Headers = {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
type RealtimeResponse = {
|
||||
type: 'error' | 'event' | 'connected' | 'response';
|
||||
data: RealtimeResponseAuthenticated | RealtimeResponseConnected | RealtimeResponseError | RealtimeResponseEvent<unknown>;
|
||||
}
|
||||
|
||||
type RealtimeRequest = {
|
||||
type: 'authentication';
|
||||
data: RealtimeRequestAuthenticate;
|
||||
}
|
||||
|
||||
export type RealtimeResponseEvent<T extends unknown> = {
|
||||
events: string[];
|
||||
channels: string[];
|
||||
timestamp: number;
|
||||
payload: T;
|
||||
}
|
||||
|
||||
type RealtimeResponseError = {
|
||||
code: number;
|
||||
message: string;
|
||||
}
|
||||
|
||||
type RealtimeResponseConnected = {
|
||||
channels: string[];
|
||||
user?: object;
|
||||
}
|
||||
|
||||
type RealtimeResponseAuthenticated = {
|
||||
to: string;
|
||||
success: boolean;
|
||||
user: object;
|
||||
}
|
||||
|
||||
type RealtimeRequestAuthenticate = {
|
||||
session: string;
|
||||
}
|
||||
|
||||
type Realtime = {
|
||||
socket?: WebSocket;
|
||||
timeout?: number;
|
||||
url?: string;
|
||||
lastMessage?: RealtimeResponse;
|
||||
channels: Set<string>;
|
||||
subscriptions: Map<number, {
|
||||
channels: string[];
|
||||
callback: (payload: RealtimeResponseEvent<any>) => void
|
||||
}>;
|
||||
subscriptionsCounter: number;
|
||||
reconnect: boolean;
|
||||
reconnectAttempts: number;
|
||||
getTimeout: () => number;
|
||||
connect: () => void;
|
||||
createSocket: () => void;
|
||||
cleanUp: (channels: string[]) => void;
|
||||
onMessage: (event: MessageEvent) => void;
|
||||
}
|
||||
|
||||
export type UploadProgress = {
|
||||
$id: string;
|
||||
progress: number;
|
||||
sizeUploaded: number;
|
||||
chunksTotal: number;
|
||||
chunksUploaded: number;
|
||||
}
|
||||
|
||||
class AppwriteException extends Error {
|
||||
code: number;
|
||||
response: string;
|
||||
type: string;
|
||||
constructor(message: string, code: number = 0, type: string = '', response: string = '') {
|
||||
super(message);
|
||||
this.name = 'AppwriteException';
|
||||
this.message = message;
|
||||
this.code = code;
|
||||
this.type = type;
|
||||
this.response = response;
|
||||
}
|
||||
}
|
||||
|
||||
class Client {
|
||||
config = {
|
||||
endpoint: 'https://HOSTNAME/v1',
|
||||
endpointRealtime: '',
|
||||
project: '',
|
||||
jwt: '',
|
||||
locale: '',
|
||||
};
|
||||
headers: Headers = {
|
||||
'x-sdk-name': 'Web',
|
||||
'x-sdk-platform': 'client',
|
||||
'x-sdk-language': 'web',
|
||||
'x-sdk-version': '13.0.2',
|
||||
'X-Appwrite-Response-Format': '1.4.0',
|
||||
};
|
||||
|
||||
/**
|
||||
* Set Endpoint
|
||||
*
|
||||
* Your project endpoint
|
||||
*
|
||||
* @param {string} endpoint
|
||||
*
|
||||
* @returns {this}
|
||||
*/
|
||||
setEndpoint(endpoint: string): this {
|
||||
this.config.endpoint = endpoint;
|
||||
this.config.endpointRealtime = this.config.endpointRealtime || this.config.endpoint.replace('https://', 'wss://').replace('http://', 'ws://');
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Realtime Endpoint
|
||||
*
|
||||
* @param {string} endpointRealtime
|
||||
*
|
||||
* @returns {this}
|
||||
*/
|
||||
setEndpointRealtime(endpointRealtime: string): this {
|
||||
this.config.endpointRealtime = endpointRealtime;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Project
|
||||
*
|
||||
* Your project ID
|
||||
*
|
||||
* @param value string
|
||||
*
|
||||
* @return {this}
|
||||
*/
|
||||
setProject(value: string): this {
|
||||
this.headers['X-Appwrite-Project'] = value;
|
||||
this.config.project = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set JWT
|
||||
*
|
||||
* Your secret JSON Web Token
|
||||
*
|
||||
* @param value string
|
||||
*
|
||||
* @return {this}
|
||||
*/
|
||||
setJWT(value: string): this {
|
||||
this.headers['X-Appwrite-JWT'] = value;
|
||||
this.config.jwt = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Locale
|
||||
*
|
||||
* @param value string
|
||||
*
|
||||
* @return {this}
|
||||
*/
|
||||
setLocale(value: string): this {
|
||||
this.headers['X-Appwrite-Locale'] = value;
|
||||
this.config.locale = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
private realtime: Realtime = {
|
||||
socket: undefined,
|
||||
timeout: undefined,
|
||||
url: '',
|
||||
channels: new Set(),
|
||||
subscriptions: new Map(),
|
||||
subscriptionsCounter: 0,
|
||||
reconnect: true,
|
||||
reconnectAttempts: 0,
|
||||
lastMessage: undefined,
|
||||
connect: () => {
|
||||
clearTimeout(this.realtime.timeout);
|
||||
this.realtime.timeout = window?.setTimeout(() => {
|
||||
this.realtime.createSocket();
|
||||
}, 50);
|
||||
},
|
||||
getTimeout: () => {
|
||||
switch (true) {
|
||||
case this.realtime.reconnectAttempts < 5:
|
||||
return 1000;
|
||||
case this.realtime.reconnectAttempts < 15:
|
||||
return 5000;
|
||||
case this.realtime.reconnectAttempts < 100:
|
||||
return 10_000;
|
||||
default:
|
||||
return 60_000;
|
||||
}
|
||||
},
|
||||
createSocket: () => {
|
||||
if (this.realtime.channels.size < 1) return;
|
||||
|
||||
const channels = new URLSearchParams();
|
||||
channels.set('project', this.config.project);
|
||||
this.realtime.channels.forEach(channel => {
|
||||
channels.append('channels[]', channel);
|
||||
});
|
||||
|
||||
const url = this.config.endpointRealtime + '/realtime?' + channels.toString();
|
||||
|
||||
if (
|
||||
url !== this.realtime.url || // Check if URL is present
|
||||
!this.realtime.socket || // Check if WebSocket has not been created
|
||||
this.realtime.socket?.readyState > WebSocket.OPEN // Check if WebSocket is CLOSING (3) or CLOSED (4)
|
||||
) {
|
||||
if (
|
||||
this.realtime.socket &&
|
||||
this.realtime.socket?.readyState < WebSocket.CLOSING // Close WebSocket if it is CONNECTING (0) or OPEN (1)
|
||||
) {
|
||||
this.realtime.reconnect = false;
|
||||
this.realtime.socket.close();
|
||||
}
|
||||
|
||||
this.realtime.url = url;
|
||||
this.realtime.socket = new WebSocket(url);
|
||||
this.realtime.socket.addEventListener('message', this.realtime.onMessage);
|
||||
this.realtime.socket.addEventListener('open', _event => {
|
||||
this.realtime.reconnectAttempts = 0;
|
||||
});
|
||||
this.realtime.socket.addEventListener('close', event => {
|
||||
if (
|
||||
!this.realtime.reconnect ||
|
||||
(
|
||||
this.realtime?.lastMessage?.type === 'error' && // Check if last message was of type error
|
||||
(<RealtimeResponseError>this.realtime?.lastMessage.data).code === 1008 // Check for policy violation 1008
|
||||
)
|
||||
) {
|
||||
this.realtime.reconnect = true;
|
||||
return;
|
||||
}
|
||||
|
||||
const timeout = this.realtime.getTimeout();
|
||||
console.error(`Realtime got disconnected. Reconnect will be attempted in ${timeout / 1000} seconds.`, event.reason);
|
||||
|
||||
setTimeout(() => {
|
||||
this.realtime.reconnectAttempts++;
|
||||
this.realtime.createSocket();
|
||||
}, timeout);
|
||||
})
|
||||
}
|
||||
},
|
||||
onMessage: (event) => {
|
||||
try {
|
||||
const message: RealtimeResponse = JSON.parse(event.data);
|
||||
this.realtime.lastMessage = message;
|
||||
switch (message.type) {
|
||||
case 'connected':
|
||||
const cookie = JSON.parse(window.localStorage.getItem('cookieFallback') ?? '{}');
|
||||
const session = cookie?.[`a_session_${this.config.project}`];
|
||||
const messageData = <RealtimeResponseConnected>message.data;
|
||||
|
||||
if (session && !messageData.user) {
|
||||
this.realtime.socket?.send(JSON.stringify(<RealtimeRequest>{
|
||||
type: 'authentication',
|
||||
data: {
|
||||
session
|
||||
}
|
||||
}));
|
||||
}
|
||||
break;
|
||||
case 'event':
|
||||
let data = <RealtimeResponseEvent<unknown>>message.data;
|
||||
if (data?.channels) {
|
||||
const isSubscribed = data.channels.some(channel => this.realtime.channels.has(channel));
|
||||
if (!isSubscribed) return;
|
||||
this.realtime.subscriptions.forEach(subscription => {
|
||||
if (data.channels.some(channel => subscription.channels.includes(channel))) {
|
||||
setTimeout(() => subscription.callback(data));
|
||||
}
|
||||
})
|
||||
}
|
||||
break;
|
||||
case 'error':
|
||||
throw message.data;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
cleanUp: channels => {
|
||||
this.realtime.channels.forEach(channel => {
|
||||
if (channels.includes(channel)) {
|
||||
let found = Array.from(this.realtime.subscriptions).some(([_key, subscription] )=> {
|
||||
return subscription.channels.includes(channel);
|
||||
})
|
||||
|
||||
if (!found) {
|
||||
this.realtime.channels.delete(channel);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribes to Appwrite events and passes you the payload in realtime.
|
||||
*
|
||||
* @param {string|string[]} channels
|
||||
* Channel to subscribe - pass a single channel as a string or multiple with an array of strings.
|
||||
*
|
||||
* Possible channels are:
|
||||
* - account
|
||||
* - collections
|
||||
* - collections.[ID]
|
||||
* - collections.[ID].documents
|
||||
* - documents
|
||||
* - documents.[ID]
|
||||
* - files
|
||||
* - files.[ID]
|
||||
* - executions
|
||||
* - executions.[ID]
|
||||
* - functions.[ID]
|
||||
* - teams
|
||||
* - teams.[ID]
|
||||
* - memberships
|
||||
* - memberships.[ID]
|
||||
* @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update.
|
||||
* @returns {() => void} Unsubscribes from events.
|
||||
*/
|
||||
subscribe<T extends unknown>(channels: string | string[], callback: (payload: RealtimeResponseEvent<T>) => void): () => void {
|
||||
let channelArray = typeof channels === 'string' ? [channels] : channels;
|
||||
channelArray.forEach(channel => this.realtime.channels.add(channel));
|
||||
|
||||
const counter = this.realtime.subscriptionsCounter++;
|
||||
this.realtime.subscriptions.set(counter, {
|
||||
channels: channelArray,
|
||||
callback
|
||||
});
|
||||
|
||||
this.realtime.connect();
|
||||
|
||||
return () => {
|
||||
this.realtime.subscriptions.delete(counter);
|
||||
this.realtime.cleanUp(channelArray);
|
||||
this.realtime.connect();
|
||||
}
|
||||
}
|
||||
|
||||
async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<any> {
|
||||
method = method.toUpperCase();
|
||||
|
||||
|
||||
headers = Object.assign({}, this.headers, headers);
|
||||
|
||||
let options: RequestInit = {
|
||||
method,
|
||||
headers,
|
||||
credentials: 'include'
|
||||
};
|
||||
|
||||
if (typeof window !== 'undefined' && window.localStorage) {
|
||||
headers['X-Fallback-Cookies'] = window.localStorage.getItem('cookieFallback') ?? '';
|
||||
}
|
||||
|
||||
if (method === 'GET') {
|
||||
for (const [key, value] of Object.entries(Service.flatten(params))) {
|
||||
url.searchParams.append(key, value);
|
||||
}
|
||||
} else {
|
||||
switch (headers['content-type']) {
|
||||
case 'application/json':
|
||||
options.body = JSON.stringify(params);
|
||||
break;
|
||||
|
||||
case 'multipart/form-data':
|
||||
let formData = new FormData();
|
||||
|
||||
for (const key in params) {
|
||||
if (Array.isArray(params[key])) {
|
||||
params[key].forEach((value: any) => {
|
||||
formData.append(key + '[]', value);
|
||||
})
|
||||
} else {
|
||||
formData.append(key, params[key]);
|
||||
}
|
||||
}
|
||||
|
||||
options.body = formData;
|
||||
delete headers['content-type'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
let data = null;
|
||||
const response = await fetch(url.toString(), options);
|
||||
|
||||
if (response.headers.get('content-type')?.includes('application/json')) {
|
||||
data = await response.json();
|
||||
} else {
|
||||
data = {
|
||||
message: await response.text()
|
||||
};
|
||||
}
|
||||
|
||||
if (400 <= response.status) {
|
||||
throw new AppwriteException(data?.message, response.status, data?.type, data);
|
||||
}
|
||||
|
||||
const cookieFallback = response.headers.get('X-Fallback-Cookies');
|
||||
|
||||
if (typeof window !== 'undefined' && window.localStorage && cookieFallback) {
|
||||
window.console.warn('Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.');
|
||||
window.localStorage.setItem('cookieFallback', cookieFallback);
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (e) {
|
||||
if (e instanceof AppwriteException) {
|
||||
throw e;
|
||||
}
|
||||
throw new AppwriteException((<Error>e).message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { Client, AppwriteException };
|
||||
export { Query } from './query';
|
||||
export type { Models, Payload };
|
||||
export type { QueryTypes, QueryTypesList } from './query';
|
||||
9
node_modules/appwrite/src/id.ts
generated
vendored
Normal file
9
node_modules/appwrite/src/id.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export class ID {
|
||||
public static custom(id: string): string {
|
||||
return id
|
||||
}
|
||||
|
||||
public static unique(): string {
|
||||
return 'unique()'
|
||||
}
|
||||
}
|
||||
14
node_modules/appwrite/src/index.ts
generated
vendored
Normal file
14
node_modules/appwrite/src/index.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
export { Client, Query, AppwriteException } from './client';
|
||||
export { Account } from './services/account';
|
||||
export { Avatars } from './services/avatars';
|
||||
export { Databases } from './services/databases';
|
||||
export { Functions } from './services/functions';
|
||||
export { Graphql } from './services/graphql';
|
||||
export { Locale } from './services/locale';
|
||||
export { Storage } from './services/storage';
|
||||
export { Teams } from './services/teams';
|
||||
export type { Models, Payload, RealtimeResponseEvent, UploadProgress } from './client';
|
||||
export type { QueryTypes, QueryTypesList } from './query';
|
||||
export { Permission } from './permission';
|
||||
export { Role } from './role';
|
||||
export { ID } from './id';
|
||||
1021
node_modules/appwrite/src/models.ts
generated
vendored
Normal file
1021
node_modules/appwrite/src/models.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
22
node_modules/appwrite/src/permission.ts
generated
vendored
Normal file
22
node_modules/appwrite/src/permission.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export class Permission {
|
||||
|
||||
static read = (role: string): string => {
|
||||
return `read("${role}")`
|
||||
}
|
||||
|
||||
static write = (role: string): string => {
|
||||
return `write("${role}")`
|
||||
}
|
||||
|
||||
static create = (role: string): string => {
|
||||
return `create("${role}")`
|
||||
}
|
||||
|
||||
static update = (role: string): string => {
|
||||
return `update("${role}")`
|
||||
}
|
||||
|
||||
static delete = (role: string): string => {
|
||||
return `delete("${role}")`
|
||||
}
|
||||
}
|
||||
74
node_modules/appwrite/src/query.ts
generated
vendored
Normal file
74
node_modules/appwrite/src/query.ts
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
type QueryTypesSingle = string | number | boolean;
|
||||
export type QueryTypesList = string[] | number[] | boolean[];
|
||||
export type QueryTypes = QueryTypesSingle | QueryTypesList;
|
||||
|
||||
export class Query {
|
||||
static equal = (attribute: string, value: QueryTypes): string =>
|
||||
Query.addQuery(attribute, "equal", value);
|
||||
|
||||
static notEqual = (attribute: string, value: QueryTypes): string =>
|
||||
Query.addQuery(attribute, "notEqual", value);
|
||||
|
||||
static lessThan = (attribute: string, value: QueryTypes): string =>
|
||||
Query.addQuery(attribute, "lessThan", value);
|
||||
|
||||
static lessThanEqual = (attribute: string, value: QueryTypes): string =>
|
||||
Query.addQuery(attribute, "lessThanEqual", value);
|
||||
|
||||
static greaterThan = (attribute: string, value: QueryTypes): string =>
|
||||
Query.addQuery(attribute, "greaterThan", value);
|
||||
|
||||
static greaterThanEqual = (attribute: string, value: QueryTypes): string =>
|
||||
Query.addQuery(attribute, "greaterThanEqual", value);
|
||||
|
||||
static isNull = (attribute: string): string =>
|
||||
`isNull("${attribute}")`;
|
||||
|
||||
static isNotNull = (attribute: string): string =>
|
||||
`isNotNull("${attribute}")`;
|
||||
|
||||
static between = (attribute: string, start: string|number, end: string|number): string =>
|
||||
`between("${attribute}", ${Query.parseValues(start)}, ${Query.parseValues(end)})`;
|
||||
|
||||
static startsWith = (attribute: string, value: string): string =>
|
||||
Query.addQuery(attribute, "startsWith", value);
|
||||
|
||||
static endsWith = (attribute: string, value: string): string =>
|
||||
Query.addQuery(attribute, "endsWith", value);
|
||||
|
||||
static select = (attributes: string[]): string =>
|
||||
`select([${attributes.map((attr: string) => `"${attr}"`).join(",")}])`;
|
||||
|
||||
static search = (attribute: string, value: string): string =>
|
||||
Query.addQuery(attribute, "search", value);
|
||||
|
||||
static orderDesc = (attribute: string): string =>
|
||||
`orderDesc("${attribute}")`;
|
||||
|
||||
static orderAsc = (attribute: string): string =>
|
||||
`orderAsc("${attribute}")`;
|
||||
|
||||
static cursorAfter = (documentId: string): string =>
|
||||
`cursorAfter("${documentId}")`;
|
||||
|
||||
static cursorBefore = (documentId: string): string =>
|
||||
`cursorBefore("${documentId}")`;
|
||||
|
||||
static limit = (limit: number): string =>
|
||||
`limit(${limit})`;
|
||||
|
||||
static offset = (offset: number): string =>
|
||||
`offset(${offset})`;
|
||||
|
||||
private static addQuery = (attribute: string, method: string, value: QueryTypes): string =>
|
||||
value instanceof Array
|
||||
? `${method}("${attribute}", [${value
|
||||
.map((v: QueryTypesSingle) => Query.parseValues(v))
|
||||
.join(",")}])`
|
||||
: `${method}("${attribute}", [${Query.parseValues(value)}])`;
|
||||
|
||||
private static parseValues = (value: QueryTypes): string =>
|
||||
typeof value === "string" || value instanceof String
|
||||
? `"${value}"`
|
||||
: `${value}`;
|
||||
}
|
||||
100
node_modules/appwrite/src/role.ts
generated
vendored
Normal file
100
node_modules/appwrite/src/role.ts
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Helper class to generate role strings for `Permission`.
|
||||
*/
|
||||
export class Role {
|
||||
|
||||
/**
|
||||
* Grants access to anyone.
|
||||
*
|
||||
* This includes authenticated and unauthenticated users.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
public static any(): string {
|
||||
return 'any'
|
||||
}
|
||||
|
||||
/**
|
||||
* Grants access to a specific user by user ID.
|
||||
*
|
||||
* You can optionally pass verified or unverified for
|
||||
* `status` to target specific types of users.
|
||||
*
|
||||
* @param {string} id
|
||||
* @param {string} status
|
||||
* @returns {string}
|
||||
*/
|
||||
public static user(id: string, status: string = ''): string {
|
||||
if (status === '') {
|
||||
return `user:${id}`
|
||||
}
|
||||
return `user:${id}/${status}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Grants access to any authenticated or anonymous user.
|
||||
*
|
||||
* You can optionally pass verified or unverified for
|
||||
* `status` to target specific types of users.
|
||||
*
|
||||
* @param {string} status
|
||||
* @returns {string}
|
||||
*/
|
||||
public static users(status: string = ''): string {
|
||||
if (status === '') {
|
||||
return 'users'
|
||||
}
|
||||
return `users/${status}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Grants access to any guest user without a session.
|
||||
*
|
||||
* Authenticated users don't have access to this role.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
public static guests(): string {
|
||||
return 'guests'
|
||||
}
|
||||
|
||||
/**
|
||||
* Grants access to a team by team ID.
|
||||
*
|
||||
* You can optionally pass a role for `role` to target
|
||||
* team members with the specified role.
|
||||
*
|
||||
* @param {string} id
|
||||
* @param {string} role
|
||||
* @returns {string}
|
||||
*/
|
||||
public static team(id: string, role: string = ''): string {
|
||||
if (role === '') {
|
||||
return `team:${id}`
|
||||
}
|
||||
return `team:${id}/${role}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Grants access to a specific member of a team.
|
||||
*
|
||||
* When the member is removed from the team, they will
|
||||
* no longer have access.
|
||||
*
|
||||
* @param {string} id
|
||||
* @returns {string}
|
||||
*/
|
||||
public static member(id: string): string {
|
||||
return `member:${id}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Grants access to a user with the specified label.
|
||||
*
|
||||
* @param {string} name
|
||||
* @returns {string}
|
||||
*/
|
||||
public static label(name: string): string {
|
||||
return `label:${name}`
|
||||
}
|
||||
}
|
||||
30
node_modules/appwrite/src/service.ts
generated
vendored
Normal file
30
node_modules/appwrite/src/service.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Client } from './client';
|
||||
import type { Payload } from './client';
|
||||
|
||||
export class Service {
|
||||
static CHUNK_SIZE = 5*1024*1024; // 5MB
|
||||
|
||||
client: Client;
|
||||
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
static flatten(data: Payload, prefix = ''): Payload {
|
||||
let output: Payload = {};
|
||||
|
||||
for (const key in data) {
|
||||
let value = data[key];
|
||||
let finalKey = prefix ? `${prefix}[${key}]` : key;
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
output = Object.assign(output, this.flatten(value, finalKey));
|
||||
}
|
||||
else {
|
||||
output[finalKey] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
1066
node_modules/appwrite/src/services/account.ts
generated
vendored
Normal file
1066
node_modules/appwrite/src/services/account.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
352
node_modules/appwrite/src/services/avatars.ts
generated
vendored
Normal file
352
node_modules/appwrite/src/services/avatars.ts
generated
vendored
Normal file
@@ -0,0 +1,352 @@
|
||||
import { Service } from '../service';
|
||||
import { AppwriteException, Client } from '../client';
|
||||
import type { Models } from '../models';
|
||||
import type { UploadProgress, Payload } from '../client';
|
||||
|
||||
export class Avatars extends Service {
|
||||
|
||||
constructor(client: Client)
|
||||
{
|
||||
super(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get browser icon
|
||||
*
|
||||
* You can use this endpoint to show different browser icons to your users.
|
||||
* The code argument receives the browser code as it appears in your user [GET
|
||||
* /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions)
|
||||
* endpoint. Use width, height and quality arguments to change the output
|
||||
* settings.
|
||||
*
|
||||
* When one dimension is specified and the other is 0, the image is scaled
|
||||
* with preserved aspect ratio. If both dimensions are 0, the API provides an
|
||||
* image at source quality. If dimensions are not specified, the default size
|
||||
* of image returned is 100x100px.
|
||||
*
|
||||
* @param {string} code
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @param {number} quality
|
||||
* @throws {AppwriteException}
|
||||
* @returns {URL}
|
||||
*/
|
||||
getBrowser(code: string, width?: number, height?: number, quality?: number): URL {
|
||||
if (typeof code === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "code"');
|
||||
}
|
||||
|
||||
const apiPath = '/avatars/browsers/{code}'.replace('{code}', code);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof width !== 'undefined') {
|
||||
payload['width'] = width;
|
||||
}
|
||||
|
||||
if (typeof height !== 'undefined') {
|
||||
payload['height'] = height;
|
||||
}
|
||||
|
||||
if (typeof quality !== 'undefined') {
|
||||
payload['quality'] = quality;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
payload['project'] = this.client.config.project;
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
||||
uri.searchParams.append(key, value);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credit card icon
|
||||
*
|
||||
* The credit card endpoint will return you the icon of the credit card
|
||||
* provider you need. Use width, height and quality arguments to change the
|
||||
* output settings.
|
||||
*
|
||||
* When one dimension is specified and the other is 0, the image is scaled
|
||||
* with preserved aspect ratio. If both dimensions are 0, the API provides an
|
||||
* image at source quality. If dimensions are not specified, the default size
|
||||
* of image returned is 100x100px.
|
||||
*
|
||||
*
|
||||
* @param {string} code
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @param {number} quality
|
||||
* @throws {AppwriteException}
|
||||
* @returns {URL}
|
||||
*/
|
||||
getCreditCard(code: string, width?: number, height?: number, quality?: number): URL {
|
||||
if (typeof code === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "code"');
|
||||
}
|
||||
|
||||
const apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof width !== 'undefined') {
|
||||
payload['width'] = width;
|
||||
}
|
||||
|
||||
if (typeof height !== 'undefined') {
|
||||
payload['height'] = height;
|
||||
}
|
||||
|
||||
if (typeof quality !== 'undefined') {
|
||||
payload['quality'] = quality;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
payload['project'] = this.client.config.project;
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
||||
uri.searchParams.append(key, value);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get favicon
|
||||
*
|
||||
* Use this endpoint to fetch the favorite icon (AKA favicon) of any remote
|
||||
* website URL.
|
||||
*
|
||||
*
|
||||
* @param {string} url
|
||||
* @throws {AppwriteException}
|
||||
* @returns {URL}
|
||||
*/
|
||||
getFavicon(url: string): URL {
|
||||
if (typeof url === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "url"');
|
||||
}
|
||||
|
||||
const apiPath = '/avatars/favicon';
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof url !== 'undefined') {
|
||||
payload['url'] = url;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
payload['project'] = this.client.config.project;
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
||||
uri.searchParams.append(key, value);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get country flag
|
||||
*
|
||||
* You can use this endpoint to show different country flags icons to your
|
||||
* users. The code argument receives the 2 letter country code. Use width,
|
||||
* height and quality arguments to change the output settings. Country codes
|
||||
* follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard.
|
||||
*
|
||||
* When one dimension is specified and the other is 0, the image is scaled
|
||||
* with preserved aspect ratio. If both dimensions are 0, the API provides an
|
||||
* image at source quality. If dimensions are not specified, the default size
|
||||
* of image returned is 100x100px.
|
||||
*
|
||||
*
|
||||
* @param {string} code
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @param {number} quality
|
||||
* @throws {AppwriteException}
|
||||
* @returns {URL}
|
||||
*/
|
||||
getFlag(code: string, width?: number, height?: number, quality?: number): URL {
|
||||
if (typeof code === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "code"');
|
||||
}
|
||||
|
||||
const apiPath = '/avatars/flags/{code}'.replace('{code}', code);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof width !== 'undefined') {
|
||||
payload['width'] = width;
|
||||
}
|
||||
|
||||
if (typeof height !== 'undefined') {
|
||||
payload['height'] = height;
|
||||
}
|
||||
|
||||
if (typeof quality !== 'undefined') {
|
||||
payload['quality'] = quality;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
payload['project'] = this.client.config.project;
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
||||
uri.searchParams.append(key, value);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image from URL
|
||||
*
|
||||
* Use this endpoint to fetch a remote image URL and crop it to any image size
|
||||
* you want. This endpoint is very useful if you need to crop and display
|
||||
* remote images in your app or in case you want to make sure a 3rd party
|
||||
* image is properly served using a TLS protocol.
|
||||
*
|
||||
* When one dimension is specified and the other is 0, the image is scaled
|
||||
* with preserved aspect ratio. If both dimensions are 0, the API provides an
|
||||
* image at source quality. If dimensions are not specified, the default size
|
||||
* of image returned is 400x400px.
|
||||
*
|
||||
*
|
||||
* @param {string} url
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @throws {AppwriteException}
|
||||
* @returns {URL}
|
||||
*/
|
||||
getImage(url: string, width?: number, height?: number): URL {
|
||||
if (typeof url === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "url"');
|
||||
}
|
||||
|
||||
const apiPath = '/avatars/image';
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof url !== 'undefined') {
|
||||
payload['url'] = url;
|
||||
}
|
||||
|
||||
if (typeof width !== 'undefined') {
|
||||
payload['width'] = width;
|
||||
}
|
||||
|
||||
if (typeof height !== 'undefined') {
|
||||
payload['height'] = height;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
payload['project'] = this.client.config.project;
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
||||
uri.searchParams.append(key, value);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user initials
|
||||
*
|
||||
* Use this endpoint to show your user initials avatar icon on your website or
|
||||
* app. By default, this route will try to print your logged-in user name or
|
||||
* email initials. You can also overwrite the user name if you pass the 'name'
|
||||
* parameter. If no name is given and no user is logged, an empty avatar will
|
||||
* be returned.
|
||||
*
|
||||
* You can use the color and background params to change the avatar colors. By
|
||||
* default, a random theme will be selected. The random theme will persist for
|
||||
* the user's initials when reloading the same theme will always return for
|
||||
* the same initials.
|
||||
*
|
||||
* When one dimension is specified and the other is 0, the image is scaled
|
||||
* with preserved aspect ratio. If both dimensions are 0, the API provides an
|
||||
* image at source quality. If dimensions are not specified, the default size
|
||||
* of image returned is 100x100px.
|
||||
*
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @param {string} background
|
||||
* @throws {AppwriteException}
|
||||
* @returns {URL}
|
||||
*/
|
||||
getInitials(name?: string, width?: number, height?: number, background?: string): URL {
|
||||
const apiPath = '/avatars/initials';
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof name !== 'undefined') {
|
||||
payload['name'] = name;
|
||||
}
|
||||
|
||||
if (typeof width !== 'undefined') {
|
||||
payload['width'] = width;
|
||||
}
|
||||
|
||||
if (typeof height !== 'undefined') {
|
||||
payload['height'] = height;
|
||||
}
|
||||
|
||||
if (typeof background !== 'undefined') {
|
||||
payload['background'] = background;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
payload['project'] = this.client.config.project;
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
||||
uri.searchParams.append(key, value);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get QR code
|
||||
*
|
||||
* Converts a given plain text to a QR code image. You can use the query
|
||||
* parameters to change the size and style of the resulting image.
|
||||
*
|
||||
*
|
||||
* @param {string} text
|
||||
* @param {number} size
|
||||
* @param {number} margin
|
||||
* @param {boolean} download
|
||||
* @throws {AppwriteException}
|
||||
* @returns {URL}
|
||||
*/
|
||||
getQR(text: string, size?: number, margin?: number, download?: boolean): URL {
|
||||
if (typeof text === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "text"');
|
||||
}
|
||||
|
||||
const apiPath = '/avatars/qr';
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof text !== 'undefined') {
|
||||
payload['text'] = text;
|
||||
}
|
||||
|
||||
if (typeof size !== 'undefined') {
|
||||
payload['size'] = size;
|
||||
}
|
||||
|
||||
if (typeof margin !== 'undefined') {
|
||||
payload['margin'] = margin;
|
||||
}
|
||||
|
||||
if (typeof download !== 'undefined') {
|
||||
payload['download'] = download;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
payload['project'] = this.client.config.project;
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
||||
uri.searchParams.append(key, value);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
};
|
||||
216
node_modules/appwrite/src/services/databases.ts
generated
vendored
Normal file
216
node_modules/appwrite/src/services/databases.ts
generated
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
import { Service } from '../service';
|
||||
import { AppwriteException, Client } from '../client';
|
||||
import type { Models } from '../models';
|
||||
import type { UploadProgress, Payload } from '../client';
|
||||
|
||||
export class Databases extends Service {
|
||||
|
||||
constructor(client: Client)
|
||||
{
|
||||
super(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* List documents
|
||||
*
|
||||
* Get a list of all the user's documents in a given collection. You can use
|
||||
* the query params to filter your results.
|
||||
*
|
||||
* @param {string} databaseId
|
||||
* @param {string} collectionId
|
||||
* @param {string[]} queries
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listDocuments<Document extends Models.Document>(databaseId: string, collectionId: string, queries?: string[]): Promise<Models.DocumentList<Document>> {
|
||||
if (typeof databaseId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "databaseId"');
|
||||
}
|
||||
|
||||
if (typeof collectionId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "collectionId"');
|
||||
}
|
||||
|
||||
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof queries !== 'undefined') {
|
||||
payload['queries'] = queries;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create document
|
||||
*
|
||||
* Create a new Document. Before using this route, you should create a new
|
||||
* collection resource using either a [server
|
||||
* integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
|
||||
* API or directly from your database console.
|
||||
*
|
||||
* @param {string} databaseId
|
||||
* @param {string} collectionId
|
||||
* @param {string} documentId
|
||||
* @param {Omit<Document, keyof Models.Document>} data
|
||||
* @param {string[]} permissions
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async createDocument<Document extends Models.Document>(databaseId: string, collectionId: string, documentId: string, data: Omit<Document, keyof Models.Document>, permissions?: string[]): Promise<Document> {
|
||||
if (typeof databaseId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "databaseId"');
|
||||
}
|
||||
|
||||
if (typeof collectionId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "collectionId"');
|
||||
}
|
||||
|
||||
if (typeof documentId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "documentId"');
|
||||
}
|
||||
|
||||
if (typeof data === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "data"');
|
||||
}
|
||||
|
||||
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof documentId !== 'undefined') {
|
||||
payload['documentId'] = documentId;
|
||||
}
|
||||
|
||||
if (typeof data !== 'undefined') {
|
||||
payload['data'] = data;
|
||||
}
|
||||
|
||||
if (typeof permissions !== 'undefined') {
|
||||
payload['permissions'] = permissions;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('post', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get document
|
||||
*
|
||||
* Get a document by its unique ID. This endpoint response returns a JSON
|
||||
* object with the document data.
|
||||
*
|
||||
* @param {string} databaseId
|
||||
* @param {string} collectionId
|
||||
* @param {string} documentId
|
||||
* @param {string[]} queries
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async getDocument<Document extends Models.Document>(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise<Document> {
|
||||
if (typeof databaseId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "databaseId"');
|
||||
}
|
||||
|
||||
if (typeof collectionId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "collectionId"');
|
||||
}
|
||||
|
||||
if (typeof documentId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "documentId"');
|
||||
}
|
||||
|
||||
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof queries !== 'undefined') {
|
||||
payload['queries'] = queries;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update document
|
||||
*
|
||||
* Update a document by its unique ID. Using the patch method you can pass
|
||||
* only specific fields that will get updated.
|
||||
*
|
||||
* @param {string} databaseId
|
||||
* @param {string} collectionId
|
||||
* @param {string} documentId
|
||||
* @param {Partial<Omit<Document, keyof Models.Document>>} data
|
||||
* @param {string[]} permissions
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async updateDocument<Document extends Models.Document>(databaseId: string, collectionId: string, documentId: string, data?: Partial<Omit<Document, keyof Models.Document>>, permissions?: string[]): Promise<Document> {
|
||||
if (typeof databaseId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "databaseId"');
|
||||
}
|
||||
|
||||
if (typeof collectionId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "collectionId"');
|
||||
}
|
||||
|
||||
if (typeof documentId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "documentId"');
|
||||
}
|
||||
|
||||
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof data !== 'undefined') {
|
||||
payload['data'] = data;
|
||||
}
|
||||
|
||||
if (typeof permissions !== 'undefined') {
|
||||
payload['permissions'] = permissions;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('patch', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete document
|
||||
*
|
||||
* Delete a document by its unique ID.
|
||||
*
|
||||
* @param {string} databaseId
|
||||
* @param {string} collectionId
|
||||
* @param {string} documentId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise<{}> {
|
||||
if (typeof databaseId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "databaseId"');
|
||||
}
|
||||
|
||||
if (typeof collectionId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "collectionId"');
|
||||
}
|
||||
|
||||
if (typeof documentId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "documentId"');
|
||||
}
|
||||
|
||||
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('delete', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
};
|
||||
125
node_modules/appwrite/src/services/functions.ts
generated
vendored
Normal file
125
node_modules/appwrite/src/services/functions.ts
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
import { Service } from '../service';
|
||||
import { AppwriteException, Client } from '../client';
|
||||
import type { Models } from '../models';
|
||||
import type { UploadProgress, Payload } from '../client';
|
||||
|
||||
export class Functions extends Service {
|
||||
|
||||
constructor(client: Client)
|
||||
{
|
||||
super(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* List executions
|
||||
*
|
||||
* Get a list of all the current user function execution logs. You can use the
|
||||
* query params to filter your results.
|
||||
*
|
||||
* @param {string} functionId
|
||||
* @param {string[]} queries
|
||||
* @param {string} search
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listExecutions(functionId: string, queries?: string[], search?: string): Promise<Models.ExecutionList> {
|
||||
if (typeof functionId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "functionId"');
|
||||
}
|
||||
|
||||
const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof queries !== 'undefined') {
|
||||
payload['queries'] = queries;
|
||||
}
|
||||
|
||||
if (typeof search !== 'undefined') {
|
||||
payload['search'] = search;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create execution
|
||||
*
|
||||
* Trigger a function execution. The returned object will return you the
|
||||
* current execution status. You can ping the `Get Execution` endpoint to get
|
||||
* updates on the current execution status. Once this endpoint is called, your
|
||||
* function execution process will start asynchronously.
|
||||
*
|
||||
* @param {string} functionId
|
||||
* @param {string} body
|
||||
* @param {boolean} async
|
||||
* @param {string} xpath
|
||||
* @param {string} method
|
||||
* @param {object} headers
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: string, headers?: object): Promise<Models.Execution> {
|
||||
if (typeof functionId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "functionId"');
|
||||
}
|
||||
|
||||
const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof body !== 'undefined') {
|
||||
payload['body'] = body;
|
||||
}
|
||||
|
||||
if (typeof async !== 'undefined') {
|
||||
payload['async'] = async;
|
||||
}
|
||||
|
||||
if (typeof xpath !== 'undefined') {
|
||||
payload['path'] = xpath;
|
||||
}
|
||||
|
||||
if (typeof method !== 'undefined') {
|
||||
payload['method'] = method;
|
||||
}
|
||||
|
||||
if (typeof headers !== 'undefined') {
|
||||
payload['headers'] = headers;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('post', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get execution
|
||||
*
|
||||
* Get a function execution log by its unique ID.
|
||||
*
|
||||
* @param {string} functionId
|
||||
* @param {string} executionId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async getExecution(functionId: string, executionId: string): Promise<Models.Execution> {
|
||||
if (typeof functionId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "functionId"');
|
||||
}
|
||||
|
||||
if (typeof executionId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "executionId"');
|
||||
}
|
||||
|
||||
const apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
};
|
||||
68
node_modules/appwrite/src/services/graphql.ts
generated
vendored
Normal file
68
node_modules/appwrite/src/services/graphql.ts
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import { Service } from '../service';
|
||||
import { AppwriteException, Client } from '../client';
|
||||
import type { Models } from '../models';
|
||||
import type { UploadProgress, Payload } from '../client';
|
||||
|
||||
export class Graphql extends Service {
|
||||
|
||||
constructor(client: Client)
|
||||
{
|
||||
super(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* GraphQL endpoint
|
||||
*
|
||||
* Execute a GraphQL mutation.
|
||||
*
|
||||
* @param {object} query
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async query(query: object): Promise<{}> {
|
||||
if (typeof query === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "query"');
|
||||
}
|
||||
|
||||
const apiPath = '/graphql';
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof query !== 'undefined') {
|
||||
payload['query'] = query;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('post', uri, {
|
||||
'x-sdk-graphql': 'true',
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* GraphQL endpoint
|
||||
*
|
||||
* Execute a GraphQL mutation.
|
||||
*
|
||||
* @param {object} query
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async mutation(query: object): Promise<{}> {
|
||||
if (typeof query === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "query"');
|
||||
}
|
||||
|
||||
const apiPath = '/graphql/mutation';
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof query !== 'undefined') {
|
||||
payload['query'] = query;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('post', uri, {
|
||||
'x-sdk-graphql': 'true',
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
};
|
||||
169
node_modules/appwrite/src/services/locale.ts
generated
vendored
Normal file
169
node_modules/appwrite/src/services/locale.ts
generated
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
import { Service } from '../service';
|
||||
import { AppwriteException, Client } from '../client';
|
||||
import type { Models } from '../models';
|
||||
import type { UploadProgress, Payload } from '../client';
|
||||
|
||||
export class Locale extends Service {
|
||||
|
||||
constructor(client: Client)
|
||||
{
|
||||
super(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user locale
|
||||
*
|
||||
* Get the current user location based on IP. Returns an object with user
|
||||
* country code, country name, continent name, continent code, ip address and
|
||||
* suggested currency. You can use the locale header to get the data in a
|
||||
* supported language.
|
||||
*
|
||||
* ([IP Geolocation by DB-IP](https://db-ip.com))
|
||||
*
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async get(): Promise<Models.Locale> {
|
||||
const apiPath = '/locale';
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* List Locale Codes
|
||||
*
|
||||
* List of all locale codes in [ISO
|
||||
* 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
|
||||
*
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listCodes(): Promise<Models.LocaleCodeList> {
|
||||
const apiPath = '/locale/codes';
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* List continents
|
||||
*
|
||||
* List of all continents. You can use the locale header to get the data in a
|
||||
* supported language.
|
||||
*
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listContinents(): Promise<Models.ContinentList> {
|
||||
const apiPath = '/locale/continents';
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* List countries
|
||||
*
|
||||
* List of all countries. You can use the locale header to get the data in a
|
||||
* supported language.
|
||||
*
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listCountries(): Promise<Models.CountryList> {
|
||||
const apiPath = '/locale/countries';
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* List EU countries
|
||||
*
|
||||
* List of all countries that are currently members of the EU. You can use the
|
||||
* locale header to get the data in a supported language.
|
||||
*
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listCountriesEU(): Promise<Models.CountryList> {
|
||||
const apiPath = '/locale/countries/eu';
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* List countries phone codes
|
||||
*
|
||||
* List of all countries phone codes. You can use the locale header to get the
|
||||
* data in a supported language.
|
||||
*
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listCountriesPhones(): Promise<Models.PhoneList> {
|
||||
const apiPath = '/locale/countries/phones';
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* List currencies
|
||||
*
|
||||
* List of all currencies, including currency symbol, name, plural, and
|
||||
* decimal digits for all major and minor currencies. You can use the locale
|
||||
* header to get the data in a supported language.
|
||||
*
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listCurrencies(): Promise<Models.CurrencyList> {
|
||||
const apiPath = '/locale/currencies';
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* List languages
|
||||
*
|
||||
* List of all languages classified by ISO 639-1 including 2-letter code, name
|
||||
* in English, and name in the respective language.
|
||||
*
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listLanguages(): Promise<Models.LanguageList> {
|
||||
const apiPath = '/locale/languages';
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
};
|
||||
413
node_modules/appwrite/src/services/storage.ts
generated
vendored
Normal file
413
node_modules/appwrite/src/services/storage.ts
generated
vendored
Normal file
@@ -0,0 +1,413 @@
|
||||
import { Service } from '../service';
|
||||
import { AppwriteException, Client } from '../client';
|
||||
import type { Models } from '../models';
|
||||
import type { UploadProgress, Payload } from '../client';
|
||||
|
||||
export class Storage extends Service {
|
||||
|
||||
constructor(client: Client)
|
||||
{
|
||||
super(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* List files
|
||||
*
|
||||
* Get a list of all the user files. You can use the query params to filter
|
||||
* your results.
|
||||
*
|
||||
* @param {string} bucketId
|
||||
* @param {string[]} queries
|
||||
* @param {string} search
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listFiles(bucketId: string, queries?: string[], search?: string): Promise<Models.FileList> {
|
||||
if (typeof bucketId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "bucketId"');
|
||||
}
|
||||
|
||||
const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof queries !== 'undefined') {
|
||||
payload['queries'] = queries;
|
||||
}
|
||||
|
||||
if (typeof search !== 'undefined') {
|
||||
payload['search'] = search;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create file
|
||||
*
|
||||
* Create a new file. Before using this route, you should create a new bucket
|
||||
* resource using either a [server
|
||||
* integration](https://appwrite.io/docs/server/storage#storageCreateBucket)
|
||||
* API or directly from your Appwrite console.
|
||||
*
|
||||
* Larger files should be uploaded using multiple requests with the
|
||||
* [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range)
|
||||
* header to send a partial request with a maximum supported chunk of `5MB`.
|
||||
* The `content-range` header values should always be in bytes.
|
||||
*
|
||||
* When the first request is sent, the server will return the **File** object,
|
||||
* and the subsequent part request must include the file's **id** in
|
||||
* `x-appwrite-id` header to allow the server to know that the partial upload
|
||||
* is for the existing file and not for a new one.
|
||||
*
|
||||
* If you're creating a new file using one of the Appwrite SDKs, all the
|
||||
* chunking logic will be managed by the SDK internally.
|
||||
*
|
||||
*
|
||||
* @param {string} bucketId
|
||||
* @param {string} fileId
|
||||
* @param {File} file
|
||||
* @param {string[]} permissions
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async createFile(bucketId: string, fileId: string, file: File, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise<Models.File> {
|
||||
if (typeof bucketId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "bucketId"');
|
||||
}
|
||||
|
||||
if (typeof fileId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "fileId"');
|
||||
}
|
||||
|
||||
if (typeof file === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "file"');
|
||||
}
|
||||
|
||||
const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof fileId !== 'undefined') {
|
||||
payload['fileId'] = fileId;
|
||||
}
|
||||
|
||||
if (typeof file !== 'undefined') {
|
||||
payload['file'] = file;
|
||||
}
|
||||
|
||||
if (typeof permissions !== 'undefined') {
|
||||
payload['permissions'] = permissions;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
|
||||
if(!(file instanceof File)) {
|
||||
throw new AppwriteException('Parameter "file" has to be a File.');
|
||||
}
|
||||
|
||||
const size = file.size;
|
||||
|
||||
if (size <= Service.CHUNK_SIZE) {
|
||||
return await this.client.call('post', uri, {
|
||||
'content-type': 'multipart/form-data',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
const apiHeaders: { [header: string]: string } = {
|
||||
'content-type': 'multipart/form-data',
|
||||
}
|
||||
|
||||
let offset = 0;
|
||||
let response = undefined;
|
||||
if(fileId != 'unique()') {
|
||||
try {
|
||||
response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), apiHeaders);
|
||||
offset = response.chunksUploaded * Service.CHUNK_SIZE;
|
||||
} catch(e) {
|
||||
}
|
||||
}
|
||||
|
||||
while (offset < size) {
|
||||
let end = Math.min(offset + Service.CHUNK_SIZE - 1, size - 1);
|
||||
|
||||
apiHeaders['content-range'] = 'bytes ' + offset + '-' + end + '/' + size;
|
||||
if (response && response.$id) {
|
||||
apiHeaders['x-appwrite-id'] = response.$id;
|
||||
}
|
||||
|
||||
const chunk = file.slice(offset, end + 1);
|
||||
payload['file'] = new File([chunk], file.name);
|
||||
response = await this.client.call('post', uri, apiHeaders, payload);
|
||||
|
||||
if (onProgress) {
|
||||
onProgress({
|
||||
$id: response.$id,
|
||||
progress: (offset / size) * 100,
|
||||
sizeUploaded: offset,
|
||||
chunksTotal: response.chunksTotal,
|
||||
chunksUploaded: response.chunksUploaded
|
||||
});
|
||||
}
|
||||
offset += Service.CHUNK_SIZE;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file
|
||||
*
|
||||
* Get a file by its unique ID. This endpoint response returns a JSON object
|
||||
* with the file metadata.
|
||||
*
|
||||
* @param {string} bucketId
|
||||
* @param {string} fileId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async getFile(bucketId: string, fileId: string): Promise<Models.File> {
|
||||
if (typeof bucketId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "bucketId"');
|
||||
}
|
||||
|
||||
if (typeof fileId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "fileId"');
|
||||
}
|
||||
|
||||
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update file
|
||||
*
|
||||
* Update a file by its unique ID. Only users with write permissions have
|
||||
* access to update this resource.
|
||||
*
|
||||
* @param {string} bucketId
|
||||
* @param {string} fileId
|
||||
* @param {string} name
|
||||
* @param {string[]} permissions
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async updateFile(bucketId: string, fileId: string, name?: string, permissions?: string[]): Promise<Models.File> {
|
||||
if (typeof bucketId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "bucketId"');
|
||||
}
|
||||
|
||||
if (typeof fileId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "fileId"');
|
||||
}
|
||||
|
||||
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof name !== 'undefined') {
|
||||
payload['name'] = name;
|
||||
}
|
||||
|
||||
if (typeof permissions !== 'undefined') {
|
||||
payload['permissions'] = permissions;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('put', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete File
|
||||
*
|
||||
* Delete a file by its unique ID. Only users with write permissions have
|
||||
* access to delete this resource.
|
||||
*
|
||||
* @param {string} bucketId
|
||||
* @param {string} fileId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async deleteFile(bucketId: string, fileId: string): Promise<{}> {
|
||||
if (typeof bucketId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "bucketId"');
|
||||
}
|
||||
|
||||
if (typeof fileId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "fileId"');
|
||||
}
|
||||
|
||||
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('delete', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file for download
|
||||
*
|
||||
* Get a file content by its unique ID. The endpoint response return with a
|
||||
* 'Content-Disposition: attachment' header that tells the browser to start
|
||||
* downloading the file to user downloads directory.
|
||||
*
|
||||
* @param {string} bucketId
|
||||
* @param {string} fileId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {URL}
|
||||
*/
|
||||
getFileDownload(bucketId: string, fileId: string): URL {
|
||||
if (typeof bucketId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "bucketId"');
|
||||
}
|
||||
|
||||
if (typeof fileId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "fileId"');
|
||||
}
|
||||
|
||||
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
payload['project'] = this.client.config.project;
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
||||
uri.searchParams.append(key, value);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file preview
|
||||
*
|
||||
* Get a file preview image. Currently, this method supports preview for image
|
||||
* files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
|
||||
* and spreadsheets, will return the file icon image. You can also pass query
|
||||
* string arguments for cutting and resizing your preview image. Preview is
|
||||
* supported only for image files smaller than 10MB.
|
||||
*
|
||||
* @param {string} bucketId
|
||||
* @param {string} fileId
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @param {string} gravity
|
||||
* @param {number} quality
|
||||
* @param {number} borderWidth
|
||||
* @param {string} borderColor
|
||||
* @param {number} borderRadius
|
||||
* @param {number} opacity
|
||||
* @param {number} rotation
|
||||
* @param {string} background
|
||||
* @param {string} output
|
||||
* @throws {AppwriteException}
|
||||
* @returns {URL}
|
||||
*/
|
||||
getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: string, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: string): URL {
|
||||
if (typeof bucketId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "bucketId"');
|
||||
}
|
||||
|
||||
if (typeof fileId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "fileId"');
|
||||
}
|
||||
|
||||
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof width !== 'undefined') {
|
||||
payload['width'] = width;
|
||||
}
|
||||
|
||||
if (typeof height !== 'undefined') {
|
||||
payload['height'] = height;
|
||||
}
|
||||
|
||||
if (typeof gravity !== 'undefined') {
|
||||
payload['gravity'] = gravity;
|
||||
}
|
||||
|
||||
if (typeof quality !== 'undefined') {
|
||||
payload['quality'] = quality;
|
||||
}
|
||||
|
||||
if (typeof borderWidth !== 'undefined') {
|
||||
payload['borderWidth'] = borderWidth;
|
||||
}
|
||||
|
||||
if (typeof borderColor !== 'undefined') {
|
||||
payload['borderColor'] = borderColor;
|
||||
}
|
||||
|
||||
if (typeof borderRadius !== 'undefined') {
|
||||
payload['borderRadius'] = borderRadius;
|
||||
}
|
||||
|
||||
if (typeof opacity !== 'undefined') {
|
||||
payload['opacity'] = opacity;
|
||||
}
|
||||
|
||||
if (typeof rotation !== 'undefined') {
|
||||
payload['rotation'] = rotation;
|
||||
}
|
||||
|
||||
if (typeof background !== 'undefined') {
|
||||
payload['background'] = background;
|
||||
}
|
||||
|
||||
if (typeof output !== 'undefined') {
|
||||
payload['output'] = output;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
payload['project'] = this.client.config.project;
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
||||
uri.searchParams.append(key, value);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file for view
|
||||
*
|
||||
* Get a file content by its unique ID. This endpoint is similar to the
|
||||
* download method but returns with no 'Content-Disposition: attachment'
|
||||
* header.
|
||||
*
|
||||
* @param {string} bucketId
|
||||
* @param {string} fileId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {URL}
|
||||
*/
|
||||
getFileView(bucketId: string, fileId: string): URL {
|
||||
if (typeof bucketId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "bucketId"');
|
||||
}
|
||||
|
||||
if (typeof fileId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "fileId"');
|
||||
}
|
||||
|
||||
const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
payload['project'] = this.client.config.project;
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(Service.flatten(payload))) {
|
||||
uri.searchParams.append(key, value);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
};
|
||||
484
node_modules/appwrite/src/services/teams.ts
generated
vendored
Normal file
484
node_modules/appwrite/src/services/teams.ts
generated
vendored
Normal file
@@ -0,0 +1,484 @@
|
||||
import { Service } from '../service';
|
||||
import { AppwriteException, Client } from '../client';
|
||||
import type { Models } from '../models';
|
||||
import type { UploadProgress, Payload } from '../client';
|
||||
|
||||
export class Teams extends Service {
|
||||
|
||||
constructor(client: Client)
|
||||
{
|
||||
super(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* List teams
|
||||
*
|
||||
* Get a list of all the teams in which the current user is a member. You can
|
||||
* use the parameters to filter your results.
|
||||
*
|
||||
* @param {string[]} queries
|
||||
* @param {string} search
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async list<Preferences extends Models.Preferences>(queries?: string[], search?: string): Promise<Models.TeamList<Preferences>> {
|
||||
const apiPath = '/teams';
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof queries !== 'undefined') {
|
||||
payload['queries'] = queries;
|
||||
}
|
||||
|
||||
if (typeof search !== 'undefined') {
|
||||
payload['search'] = search;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create team
|
||||
*
|
||||
* Create a new team. The user who creates the team will automatically be
|
||||
* assigned as the owner of the team. Only the users with the owner role can
|
||||
* invite new members, add new owners and delete or update the team.
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @param {string} name
|
||||
* @param {string[]} roles
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async create<Preferences extends Models.Preferences>(teamId: string, name: string, roles?: string[]): Promise<Models.Team<Preferences>> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
if (typeof name === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "name"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams';
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof teamId !== 'undefined') {
|
||||
payload['teamId'] = teamId;
|
||||
}
|
||||
|
||||
if (typeof name !== 'undefined') {
|
||||
payload['name'] = name;
|
||||
}
|
||||
|
||||
if (typeof roles !== 'undefined') {
|
||||
payload['roles'] = roles;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('post', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get team
|
||||
*
|
||||
* Get a team by its ID. All team members have read access for this resource.
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async get<Preferences extends Models.Preferences>(teamId: string): Promise<Models.Team<Preferences>> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update name
|
||||
*
|
||||
* Update the team's name by its unique ID.
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @param {string} name
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async updateName<Preferences extends Models.Preferences>(teamId: string, name: string): Promise<Models.Team<Preferences>> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
if (typeof name === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "name"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof name !== 'undefined') {
|
||||
payload['name'] = name;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('put', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete team
|
||||
*
|
||||
* Delete a team using its ID. Only team members with the owner role can
|
||||
* delete the team.
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async delete(teamId: string): Promise<{}> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('delete', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* List team memberships
|
||||
*
|
||||
* Use this endpoint to list a team's members using the team's ID. All team
|
||||
* members have read access to this endpoint.
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @param {string[]} queries
|
||||
* @param {string} search
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async listMemberships(teamId: string, queries?: string[], search?: string): Promise<Models.MembershipList> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof queries !== 'undefined') {
|
||||
payload['queries'] = queries;
|
||||
}
|
||||
|
||||
if (typeof search !== 'undefined') {
|
||||
payload['search'] = search;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create team membership
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You only need to provide one of a user ID, email, or phone number. Appwrite
|
||||
* will prioritize accepting the user ID > email > phone number if you provide
|
||||
* more than one of these parameters.
|
||||
*
|
||||
* Use the `url` parameter to redirect the user from the invitation email to
|
||||
* your app. After the user is redirected, use the [Update Team Membership
|
||||
* Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus)
|
||||
* endpoint to allow the user to accept the invitation to the team.
|
||||
*
|
||||
* Please note that to avoid a [Redirect
|
||||
* Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
|
||||
* Appwrite will accept the only redirect URLs under the domains you have
|
||||
* added as a platform on the Appwrite Console.
|
||||
*
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @param {string[]} roles
|
||||
* @param {string} email
|
||||
* @param {string} userId
|
||||
* @param {string} phone
|
||||
* @param {string} url
|
||||
* @param {string} name
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async createMembership(teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise<Models.Membership> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
if (typeof roles === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "roles"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof email !== 'undefined') {
|
||||
payload['email'] = email;
|
||||
}
|
||||
|
||||
if (typeof userId !== 'undefined') {
|
||||
payload['userId'] = userId;
|
||||
}
|
||||
|
||||
if (typeof phone !== 'undefined') {
|
||||
payload['phone'] = phone;
|
||||
}
|
||||
|
||||
if (typeof roles !== 'undefined') {
|
||||
payload['roles'] = roles;
|
||||
}
|
||||
|
||||
if (typeof url !== 'undefined') {
|
||||
payload['url'] = url;
|
||||
}
|
||||
|
||||
if (typeof name !== 'undefined') {
|
||||
payload['name'] = name;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('post', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get team membership
|
||||
*
|
||||
* Get a team member by the membership unique id. All team members have read
|
||||
* access for this resource.
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @param {string} membershipId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async getMembership(teamId: string, membershipId: string): Promise<Models.Membership> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
if (typeof membershipId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "membershipId"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update membership
|
||||
*
|
||||
* 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
|
||||
* @param {string} membershipId
|
||||
* @param {string[]} roles
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async updateMembership(teamId: string, membershipId: string, roles: string[]): Promise<Models.Membership> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
if (typeof membershipId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "membershipId"');
|
||||
}
|
||||
|
||||
if (typeof roles === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "roles"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof roles !== 'undefined') {
|
||||
payload['roles'] = roles;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('patch', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete team membership
|
||||
*
|
||||
* This endpoint allows a user to leave a team or for a team owner to delete
|
||||
* the membership of any other team member. You can also use this endpoint to
|
||||
* delete a user membership even if it is not accepted.
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @param {string} membershipId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async deleteMembership(teamId: string, membershipId: string): Promise<{}> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
if (typeof membershipId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "membershipId"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('delete', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update team membership status
|
||||
*
|
||||
* Use this endpoint to allow a user to accept an invitation to join a team
|
||||
* after being redirected back to your app from the invitation email received
|
||||
* by the user.
|
||||
*
|
||||
* If the request is successful, a session for the user is automatically
|
||||
* created.
|
||||
*
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @param {string} membershipId
|
||||
* @param {string} userId
|
||||
* @param {string} secret
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async updateMembershipStatus(teamId: string, membershipId: string, userId: string, secret: string): Promise<Models.Membership> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
if (typeof membershipId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "membershipId"');
|
||||
}
|
||||
|
||||
if (typeof userId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "userId"');
|
||||
}
|
||||
|
||||
if (typeof secret === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "secret"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof userId !== 'undefined') {
|
||||
payload['userId'] = userId;
|
||||
}
|
||||
|
||||
if (typeof secret !== 'undefined') {
|
||||
payload['secret'] = secret;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('patch', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get team preferences
|
||||
*
|
||||
* Get the team's shared preferences by its unique ID. If a preference doesn't
|
||||
* need to be shared by all team members, prefer storing them in [user
|
||||
* preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs).
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async getPrefs<Preferences extends Models.Preferences>(teamId: string): Promise<Preferences> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId);
|
||||
const payload: Payload = {};
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('get', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update preferences
|
||||
*
|
||||
* Update the team's preferences by its unique ID. The object you pass is
|
||||
* stored as is and replaces any previous value. The maximum allowed prefs
|
||||
* size is 64kB and throws an error if exceeded.
|
||||
*
|
||||
* @param {string} teamId
|
||||
* @param {object} prefs
|
||||
* @throws {AppwriteException}
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async updatePrefs<Preferences extends Models.Preferences>(teamId: string, prefs: object): Promise<Preferences> {
|
||||
if (typeof teamId === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "teamId"');
|
||||
}
|
||||
|
||||
if (typeof prefs === 'undefined') {
|
||||
throw new AppwriteException('Missing required parameter: "prefs"');
|
||||
}
|
||||
|
||||
const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId);
|
||||
const payload: Payload = {};
|
||||
|
||||
if (typeof prefs !== 'undefined') {
|
||||
payload['prefs'] = prefs;
|
||||
}
|
||||
|
||||
const uri = new URL(this.client.config.endpoint + apiPath);
|
||||
return await this.client.call('put', uri, {
|
||||
'content-type': 'application/json',
|
||||
}, payload);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user