node-appwrite
Version:
Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API
149 lines (146 loc) • 4.34 kB
JavaScript
var client = require('../client');
class Tokens {
constructor(client) {
this.client = client;
}
/**
* List all the tokens created for a specific file or bucket. You can use the query params to filter your results.
*
* @param {string} bucketId
* @param {string} fileId
* @param {string[]} queries
* @throws {AppwriteException}
* @returns {Promise<Models.ResourceTokenList>}
*/
list(bucketId, fileId, queries) {
if (typeof bucketId === "undefined") {
throw new client.AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof fileId === "undefined") {
throw new client.AppwriteException('Missing required parameter: "fileId"');
}
const apiPath = "/tokens/buckets/{bucketId}/files/{fileId}".replace("{bucketId}", bucketId).replace("{fileId}", fileId);
const payload = {};
if (typeof queries !== "undefined") {
payload["queries"] = queries;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {};
return this.client.call(
"get",
uri,
apiHeaders,
payload
);
}
/**
* Create a new token. A token is linked to a file. Token can be passed as a header or request get parameter.
*
* @param {string} bucketId
* @param {string} fileId
* @param {string} expire
* @throws {AppwriteException}
* @returns {Promise<Models.ResourceToken>}
*/
createFileToken(bucketId, fileId, expire) {
if (typeof bucketId === "undefined") {
throw new client.AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof fileId === "undefined") {
throw new client.AppwriteException('Missing required parameter: "fileId"');
}
const apiPath = "/tokens/buckets/{bucketId}/files/{fileId}".replace("{bucketId}", bucketId).replace("{fileId}", fileId);
const payload = {};
if (typeof expire !== "undefined") {
payload["expire"] = expire;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {
"content-type": "application/json"
};
return this.client.call(
"post",
uri,
apiHeaders,
payload
);
}
/**
* Get a token by its unique ID.
*
* @param {string} tokenId
* @throws {AppwriteException}
* @returns {Promise<Models.ResourceToken>}
*/
get(tokenId) {
if (typeof tokenId === "undefined") {
throw new client.AppwriteException('Missing required parameter: "tokenId"');
}
const apiPath = "/tokens/{tokenId}".replace("{tokenId}", tokenId);
const payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {};
return this.client.call(
"get",
uri,
apiHeaders,
payload
);
}
/**
* Update a token by its unique ID. Use this endpoint to update a token's expiry date.
*
* @param {string} tokenId
* @param {string} expire
* @throws {AppwriteException}
* @returns {Promise<Models.ResourceToken>}
*/
update(tokenId, expire) {
if (typeof tokenId === "undefined") {
throw new client.AppwriteException('Missing required parameter: "tokenId"');
}
const apiPath = "/tokens/{tokenId}".replace("{tokenId}", tokenId);
const payload = {};
if (typeof expire !== "undefined") {
payload["expire"] = expire;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {
"content-type": "application/json"
};
return this.client.call(
"patch",
uri,
apiHeaders,
payload
);
}
/**
* Delete a token by its unique ID.
*
* @param {string} tokenId
* @throws {AppwriteException}
* @returns {Promise<{}>}
*/
delete(tokenId) {
if (typeof tokenId === "undefined") {
throw new client.AppwriteException('Missing required parameter: "tokenId"');
}
const apiPath = "/tokens/{tokenId}".replace("{tokenId}", tokenId);
const payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {
"content-type": "application/json"
};
return this.client.call(
"delete",
uri,
apiHeaders,
payload
);
}
}
exports.Tokens = Tokens;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=tokens.js.map
;