appwrite / sdk-for-node Goto Github PK
View Code? Open in Web Editor NEW[READ-ONLY] Official Appwrite Node.js SDK ๐ข
Home Page: https://appwrite.io
License: BSD 3-Clause "New" or "Revised" License
[READ-ONLY] Official Appwrite Node.js SDK ๐ข
Home Page: https://appwrite.io
License: BSD 3-Clause "New" or "Revised" License
From discord: https://discord.com/channels/564160730845151244/564161373148414012/999227422648053790
I think I found another bug in the node server SDK (7.0.2)
In line 478 of ./lib/services/storage.js we have:
writeStream.on("finish", async () => {
if(currentChunkSize > 0) {
await uploadChunk(true);
}
resolve(response);
});
That is executed on a createFile
operation. If the given bucket ID is wrong, this section will execute regardless and will throw an error at uploadChunk
. However, since it is thrown within an async function, it cannot get caught by the developer's code flow.
I'd suggest to change it as:
writeStream.on("finish", async () => {
try {
if (currentChunkSize > 0) {
await uploadChunk(true);
}
resolve(response);
} catch (e) {
reject(e)
}
});
This way the exception is propagated and can be handled by developer's code
You should add the ability to send Buffer
s using the Storage.createFile
function.
With the latest version we can't Storage.createFile
with anything other than a FS access, but depending on the context sending a raw Buffer is way better than writing to a file and then after sending the same file, also some applications contexts don't have the FS access on nodeJS.
Steps:
update recovery
requestawait account.updateRecovery(userId, secret, password)
The implementation does seem to omit the passwordAgain
field
Given correct userId, secret and qualifying password, the password reset flow should complete without error.
I am getting the following error
{"message":"Param "passwordAgain" is not optional.","code":400,"type":"general_argument_invalid","version":"0.12.141"}
Different version (specify in environment)
Linux
I am using GCP Cloud Run to develop a node js app. The backend sdk of appwrite is v.12.0.0.
Installing the Node SDK, importing the Permission
and/or Role
class and compiling with tsc.
Import Statement
import sdk, {Permission, Role} from 'node-appwrite';
package.json
{
"name": "appwrite-function",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npx tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"node-appwrite": "^8.0.0",
"typescript": "^4.8.3"
}
}
Import the classes.
Raises an error for each of the two classes during Typescript Compilation:
user@host someFolder % npm run build
> [email protected] build
> npx tsc
src/index.ts:1:14 - error TS2305: Module '"node-appwrite"' has no exported member 'Permission'.
1 import sdk, {Permission, Role} from 'node-appwrite';
~~~~~~~~~~
src/index.ts:1:26 - error TS2305: Module '"node-appwrite"' has no exported member 'Role'.
1 import sdk, {Permission, Role} from 'node-appwrite';
~~~~
Found 2 errors in the same file, starting at: src/index.ts:1
The error does not appear, when manually adding these Lines into the index.d.ts
file after line 1719 (into the root namespace of the node-appwrite
module):
export class Permission {
static read(role: string): string;
static write(role: string): string;
static create(role: string): string;
static update(role: string): string;
static delete(role: string): string;
}
export class Role {
static any(): string;
static user(id: string, status?: string): string;
static users(status?: string): string;
static guests(): string;
static team(id, role?: string): string;
static member(id): string;
static status(status: string): string;
}
Different version (specify in environment)
Linux
Appwrite Version: 1.0.1
node-appwrite Version: ^8.0.0
tsc Version: 4.8.3
import sdk from "node-appwrite"; const Query = sdk.Query;
Query class gets imported and can be used in database requests.
Error: Property 'Query' does not exist on type 'typeof import("node-appwrite")'.
Different version (specify in environment)
Linux
Appwrite 0.12
When i try to save a file stream received on my express server using busboy, it ends up failing.
const bb = busboy({headers:req.headers});
bb.on('file', async (name,stream,info) =>{
try {
let response = await api.getStorage().createFile(stream,[],[]);
console.log("file upload response\n" +JSON.stringify(response));
} catch (error) {
console.log("failed to save file. "+error.stack);
}
stream.on('data', (data) => {
console.log(`File [${name}] got ${data.length} bytes`);
}).on('close', () => {
console.log(`File [${name}] done`);
});
})
bb.on('field', (name, val, info) => {
console.log(`Field [${name}]: value: %j`, val);
});
bb.on('close', () => {
console.log(`close called`);
res.writeHead(200, { 'Connection': 'close' });
});
req.pipe(bb);
Error
Error: Request failed with status code 400
at createError (/app/node_modules/axios/lib/core/createError.js:16:15)
at settle (/app/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/app/node_modules/axios/lib/adapters/http.js:269:11)
at IncomingMessage.emit (node:events:377:35)
at endReadableNT (node:internal/streams/readable:1312:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
one should be able to save the stream directly without first saving it on a temporary file
one cannot save the stream
Version 0.10.x
MacOS
No response
Use node-appwrite and compile Typescript to Javascript.
Basically the same problem as #37
Export the missing classes: Blob
, Response
โฏ npm run compile
> compile
> tsc
node_modules/node-appwrite/index.d.ts:1797:27 - error TS2304: Cannot find name 'Blob'.
1797 static fromBlob(blob: Blob, filename: string): InputFile;
~~~~
node_modules/node-appwrite/index.d.ts:2020:31 - error TS2304: Cannot find name 'Response'.
2020 deleteSessions(): Promise<Response>;
~~~~~~~~
node_modules/node-appwrite/index.d.ts:2056:47 - error TS2304: Cannot find name 'Response'.
2056 deleteSession(sessionId: string): Promise<Response>;
~~~~~~~~
.
.
.
Found 20 errors in the same file, starting at: node_modules/node-appwrite/index.d.ts:1797
Different version (specify in environment)
MacOS
node-appwrite: 8.1.0
Would be great to have the same functionality in the node-sdk as in the other sdk's!
Imagine writing a backend-service which should not be exposed to the outer world (webhooks are not working) or the IP is not static or whatever reasons.
The service would just ping out, connect and receive notifications :)
In some async functions, you're using redundant code that makes the execution code slower (I assume that this is also valid for the deno sdk). I didn't new at first that this redundant code could make the execution slower, but I tested it and here is my experience/results.
In some async functions, you're using the following pattern (from /lib/services/account.js):
async get() {
let path = '/account';
let payload = {};
return await this.client.call('get', path, {
'content-type': 'application/json',
}, payload);
}
This pattern contains an unnecessary "async" and "await" notation.
This could be simplified by:
get() {
let path = '/account';
let payload = {};
return this.client.call('get', path, {
'content-type': 'application/json',
}, payload);
}
From this pov, I decided to benchmark the 2 solutions with the following script:
async function measure_async_func(cb) {
const start = performance.now()
await cb()
const stop = performance.now()
const timeInSeconds = (stop - start) / 1000;
const timeRounded = timeInSeconds.toFixed(3)
return timeRounded
}
function printExecutionTime(funcName, executionTime) {
console.log(`Time taken to execute function ${funcName}(): ${executionTime} seconds`)
}
function getNumber() {
return new Promise((resolve, _) => {
resolve(10)
})
}
function getNumber1() {
return getNumber()
}
async function getNumber2() {
return await getNumber()
}
async function getNumbers1(numbersToGenerate) {
for (let i = 0; i < numbersToGenerate; i++) {
await getNumber1()
}
}
async function getNumbers2(numbersToGenerate) {
for (let i = 0; i < numbersToGenerate; i++) {
await getNumber2()
}
}
async function runTests() {
const numbersToGenerate = 10_000_000
const executionTime1 = await measure_async_func(() => getNumbers1(numbersToGenerate))
printExecutionTime("getNumbers1", executionTime1)
const executionTime2 = await measure_async_func(() => getNumbers2(numbersToGenerate))
printExecutionTime("getNumbers2", executionTime2)
const ratio = executionTime2 / executionTime1
console.log(`getNumbers1() is ${ratio} faster than getNumbers2()`)
}
runTests()
The results are (with Node v17.4.0):
Time taken to execute function getNumbers1(): 0.928 seconds
Time taken to execute function getNumbers2(): 1.613 seconds
getNumbers1() is 1.738146551724138 faster than getNumbers2()
I haven't tested with the sdk itself, but with a simple script, the second solution (without "async" and "await" notation) seems 1.74 times faster than the first one. I should have tested with the sdk itself, but I don't really have time for that rn.
I was trying to get the Project ID from the Environment var APPWRITE_FUNCTION_PROJECT_ID
But it returned this:
APPWRITE_FUNCTION_PROJECT_ID=APPWRITE_FUNCTION_PROJECT_ID=613**********
When I would only expect the key itself.
I tried to create a collection inside of a function but instead, of it creating a collection I get this error.
TypeError: Cannot read property 'statusText' of undefined
at Client.call (/usr/local/src/node_modules/node-appwrite/lib/client.js:163:64)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
at async Database.createCollection (/usr/local/src/node_modules/node-appwrite/lib/services/database.js:94:16)
The link where it says "Please see the BSD-3-Clause license" is not working in the README file.
It's throwing a connection time out
Here's the link
In the node-appwrite 7.0.2 package, the property "type" is missing in the AppwriteException type definition in index.d.ts
, but it DOES exist in exception.js
. When coding with typescript it would be great to be able to access it without workarounds as it carries important information for exception handling.
AppwriteException types should be consistent with its implementation
Accessing type
creates an error at compile time.
Different version (specify in environment)
Linux
No response
Add a new function in the Database SDK called findDocument which uses listDocument to get the first returned document with Query.
This feature can be used if you have an id for attitude such as a user_id attribute and don't want it to be the same as the document id.
When I try to upload an image to storage using the Node client the uploaded file has the wrong type.
node-canvas
and save it a buffer: canvas.toBuffer()
InputFile.fromBuffer(buffer, 'name.png')
application/octet-stream
instead of PNGThe buffer should be valid as I am able to save and view the image locally using fs.writeFileSync("name.png", buffer);
I expect that it would store it as a png. From my understanding, it should be grabbing the type from the file name.
Here are some relevant links @stnguyen90 shared on Discord.
Node client:
sdk-for-node/lib/services/storage.js
Line 416 in 0b061a1
It uploads as application/octet-stream
. I've also tried not using the .png
extension but that made no difference.
This is what it shows on the dashboard:
Here you can see the file names. I also attempted saving the base64 image which is the text file you see.
When opening the last file, with the .png
it shows this. You can see where it says PNG at the top.
Version 0.15.x
MacOS
I'm using "node-appwrite": "^7.0.2"
When I request appwrite.account.updatePrefs api I got the error message in docker logs:
[Error] Method: PATCH
[Error] URL: /v1/account/prefs
[Error] Type: Appwrite\Extend\Exception
[Error] Message: [email protected] (role: applications) missing scope (account)
[Error] File: /usr/src/code/app/controllers/general.php
[Error] Line: 365
I am sure that my API key has been set correctly.
appwrite version is: 1.2.1
"appwrite": "^10.2.0",
"node-appwrite": "^8.2.0",
I am sure that I have set the permissions for the API key correctly.
users.read: checked
users.write: checked
Open generated types for Query
static offset(value: number): string;
static offset = (value: number): string;
Different version (specify in environment)
MacOS
Appwrite Version 1.0.1
node-appwrite 8.0.0
I've tried several methods to call upload file but all with no sucess.
I have a Uint8Array that I am trying to upload, I know the file mime type also, but it doesn't appear I can pass that in any way through the SDK.
My current code looks roughly like this:
// setup
const appwriteSdk = require('node-appwrite');
let appwriteClient = new appwriteSdk.Client();
appwriteClient.setEndpoint(process.env.APPWRITE_URL).setProject(process.env.APPWRITE_PROJECT_ID).setKey(process.env.APPWRITE_API_SECRET);
const appwriteStorage = new appwriteSdk.Storage(appwriteClient);
// try to upload file
let contents = new Uint8Array(8); // 8 empty bytes for the example here
appwriteStorage.createFile(Buffer.from(contents), ['*']);
This current code results in the API returning a 400 with:
No file sent
I'm guessing this has something to do with the mimetype and filename not being set for the file field of the body. It starts roughly as follows:
----------------------------237413076769890169368363.
Content-Disposition: form-data; name="file".
Content-Type: application/octet-stream.
Compared to a manual file upload done from the admin console:
------WebKitFormBoundarytM78TqdmJGw2uqNA
Content-Disposition: form-data; name="file"; filename="myfile.webm"
Content-Type: video/webm
What is the proper way to do this file upload? I think I'm going to have to resert to manually calling the REST api until this can be fixed in the SDK.
The documentation for storageCreateFile
seems wrong: https://appwrite.io/docs/server/storage?sdk=nodejs-default#storageCreateFile
For the file
parameter, there is only a string allowed:
sdk-for-node/lib/services/storage.js
Line 334 in 4f021b9
sdk-for-node/lib/services/storage.js
Line 340 in 4f021b9
The code Example and the description are claiming, that I can provide a binary file:
https://appwrite.io/docs/server/storage?sdk=nodejs-default#storageCreateFile
This works but is different from what is in the documentation):
const filename = './tmp/1.jpg';
let promise = storage.createFile(BUCKET_ID, id, filename);
Following the documenttation, this should, but does not work (also is not giving any error, or I might have overseen them):
const file = new File([uin8array], '1.jpg', {type: 'image/jpeg'})
let promise = storage.createFile(BUCKET_ID, id, file);
If I provide different things as file
I get Type Errors, which are telling, that it would work to provide either a String or a Uint8Array. Both does not work:
const url = 'https://sample.com/1.jpg'
const response = await fetch(url)
const image = await response.arrayBuffer();
const uin8array = new Uint8Array(image);
let promise = storage.createFile(BUCKET_ID, id, uin8array);
-> TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received Uint8Array(178056)
const url = 'https://sample.com/1.jpg'
const response = await fetch(url)
const image = await response.arrayBuffer();
const uin8array = new Uint8Array(image);
const imageString = new TextDecoder().decode(uin8array);
let promise = storage.createFile(BUCKET_ID, id, imageString);
->TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received '๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00...'
When using the node sdk, the AppwriteException doesn't have the type property in the interface
It should have the property since it's in the original class
I actually tells that it doesn't exist
Version 0.10.x
MacOS
In local dev
I made a PR for this bug:
#74
When I try to use appwrite in NextJS middleware I get the following error...
[Error: adapter is not a function] {
code: undefined,
type: undefined,
response: undefined
}
My middleware.js file is as per the example on https://appwrite.io/docs/getting-started-for-server with my own server variables of course...
import { Client, Users, ID } from 'node-appwrite'
export function middleware() {
const client = new Client()
client.setEndpoint('https://appwrite.jadeyo.dev/v1').setProject('633***').setKey('0ac***')
const users = new Users(client)
let promise = users.create(ID.unique(), '[email protected]', null, 'password')
promise.then(
function (response) {
console.log(response)
},
function (error) {
console.log(error)
}
)
}
My appwrite server is v:1.0.3.501 hosted on digital ocean using the built in docker image - not customised in any way.
My local machine is Linux running node v18.11.0
My package.json is as follows...
{
"name": "support.jadeyo.xyz",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"appwrite": "^10.1.0",
"next": "12.3.1",
"node-appwrite": "^8.1.0",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@fortawesome/fontawesome-pro": "^6.2.0",
"@fortawesome/fontawesome-svg-core": "^6.2.0",
"@fortawesome/pro-duotone-svg-icons": "^6.2.0",
"@fortawesome/pro-light-svg-icons": "^6.2.0",
"@fortawesome/pro-regular-svg-icons": "^6.2.0",
"@fortawesome/pro-solid-svg-icons": "^6.2.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"autoprefixer": "^10.4.12",
"eslint": "8.25.0",
"eslint-config-next": "12.3.1",
"postcss": "^8.4.18",
"tailwindcss": "^3.2.0"
}
}
Account creation
User account not created and error thrown
Version 0.10.x
Linux
No response
I'm using the latest version of node-appwrite (11.1.0) and have set up some scripts to set up my projects programmatically. Everything works fine besides creating array attributes, when I try this code:
await db.createStringAttribute(databaseId, collectionId, 'media', 10000, false, '', true)
it generates this exception:
Cannot set default value for array attributes
message: 'Cannot set default value for array attributes',
code: 400,
type: 'attribute_default_unsupported',
version: '1.4.13'
And when I try to use any other value instead of empty string for a 'default value' parameter, SDK throws another error saying that only string with size 0 can be used as a parameter.
Attribute is created.
Exception thrown.
Version 0.10.x
Linux
No response
Using node-appwrite sdk version 12.0.0, databases, listDocument function with a query. The problem does not occur on node-appwrite version 11.1.1 with same code.
new Databases(client).listDocuments<Models.Document & Card>(
this.databaseId,
this.collectionId,
[Query.equal('userId', userId)],
);
Same issue in forum from someone else
Should return the list of documents
Query.equals throws an error:
Error: Invalid query: {"method":"equal","attribute":"userId","values":["65ead2450a70959d9de7"]}
Different version (specify in environment)
Windows
appwrite version 1.3.7 on debian server
nestjs local server with node-appwrite 12.0.0
Installing [email protected] leads to npm warning about a low security vulnerability from the undici dependency.
node-appwrite should upgrade the dependency and the warning should not be shown
The warning is shown
Version 0.10.x
Linux
No response
I am new to appwrite environment. I am trying to create a simple sveltekit web app. With user login and logout. In sveltekit ecosystem it is very convenient to store the user session on event.locals. I tried to do so using this code.
export const handle: Handle = async function ({ event, resolve }) {
event.locals.appwrite = awServerClient(); // returns the {appwrite: {auth: sdk.Users, account: sdk.Account}}
event.locals.getSession = async () => {
const session = await event.locals.appwrite.account.getSession('current');
console.log(session);
return session;
};
return await resolve(event);
};
I am getting User (role: guests) missing scope (account) this error. Is there any way to store the user session on server side.
Not sure how to write it properly...
const Appwrite = require('node-appwrite');
const sdk = new Appwrite();
sdk.setProject('');
sdk.setKey('');
I'm getting: TypeError: Appwrite is not a constructor
Just trying this lib and it appears that data is not being fully parsed or docs are not correct.
for instance i tried a simple example as :
const { Client, Database } = require('node-appwrite');
const sdk = new Client();
const db = new Database(sdk);
....
// uid=5d9630017f3ac
// let promise = db.createCollection('CHECK');
let promise = db.createDocument('5d9630017f3ac', JSON.stringify({ name: "Hello" }));
promise.then(
function(response) {
console.log(response);
},
function(error) {
console.log(error);
}
);
And console show error on promise:
Docs tell to use as:
Perhaps schema validation when passing data? Just a thought... What could be wrong in this example?
Regards, and thanks for the hard work :)
When trying to upload a file using a bad API key, an uncaught exception is thrown.
client.setEndpoint(endpoint)
client.setProjectprojectid)
client.setKey(badkey)
const storage = new sdk.Storage(client);
try {
const appFile = await storage.createFile("files",file.name,InputFile.fromPath(directory,file.name))
return true;
}catch (e){
console.log(e);
return false;
}
I should be able to catch the exception my self in my own try/catch block.
try {
const appFile = await storage.createFile("files",file.name,InputFile.fromPath(directory,file.name))
return true;
}catch (e){
console.log(e);
return false;
}
It actually crashes the whole application, and spits out a stack trace.
C:\laragon\www\myfiles\node_modules\.pnpm\node-appwrite@8.1.0\node_modules\node-appwrite\lib\client.js:171
throw new AppwriteException(error.response.data.message, error.response.status, error.response.data.type, error.response.data);
^
AppwriteException [Error]: The current user is not authorized to perform the requested action.
at Client.call (C:\laragon\www\myfiles\node_modules\.pnpm\node-appwrite@8.1.0\node_modules\node-appwrite\lib\client.js:171:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async uploadChunk (C:\laragon\www\myfiles\node_modules\.pnpm\node-appwrite@8.1.0\node_modules\node-appwrite\lib\services\storage.js:371:24)
at async Writable.<anonymous> (C:\laragon\www\myfiles\node_modules\.pnpm\node-appwrite@8.1.0\node_modules\node-appwrite\lib\services\storage.js:433:21) {
code: 401,
type: 'user_unauthorized',
response: {
message: 'The current user is not authorized to perform the requested action.',
code: 401,
type: 'user_unauthorized',
version: '1.1.1'
}
}
Node.js v17.2.0
ELIFECYCLEโ Command failed with exit code 1.
โ
Version 1.1.1
Windows
N/A
On this getDocument method here why does it take queries as filter when documentId is supposed to be unique for every document?
Calling createOAuth2Token
on the server side in Nuxt
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig(event);
const { account } = useAppwriteAdminClient(event);
try {
const redirectUrl = await account.createOAuth2Token(
'github',
`${config.public.api.url}/oauth`,
`${config.public.api.url}/login`,
['user']
);
return redirectUrl;
} catch (error) {
console.log('OAUTH ERROR', error);
}
});
returns oauth
provider information like providerUid
like in the web-sdk
Example response:
Different version (specify in environment)
Linux
No response
GitHub has recently rolled out a public beta for their issue forms feature. This would allow you to create interactive issue templates and validate them ๐คฏ.
Appwrite currently uses the older issue template format. Your task is to create GitHub issue forms for this repository. Please use Appwrite's issue templates as a reference for this PR.
.github/ISSUE_TEMPLATE/bug.yaml
.github/ISSUE_TEMPLATE/documentation.yaml
.github/ISSUE_TEMPLATE/feature.yaml
If you need any help, reach out to us on our Discord server.
Are you ready to work on this issue? ๐ค Let us know, and we will assign it to you ๐
Happy Appwriting!
Prepare a file that is > 10MB (The one I am using is 19MB),
copy and paste the createFile
example codes from Appwrite https://appwrite.io/docs/server/storage?sdk=nodejs-default#storageCreateFile
, then modified the file path to your > 10MB file
storage.createFile(
'unique()',
fs.createReadStream(`./large_file.pdf`)
)
I should be able to createFile
without errors
It throws the following error
(node:4348) UnhandledPromiseRejectionWarning: Error: Request body larger than maxBodyLength limit
at Client.call (/mnt/c/Users/fores/node_modules/node-appwrite/lib/client.js:169:23)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Storage.createFile (/mnt/c/Users/fores/node_modules/node-appwrite/lib/services/storage.js:97:16)
at async run (/mnt/c/Users/fores/Downloads/latte/convert.js:124:20)
Note that no errors are thrown from Appwrite server, the above is from node sdk client
Different version (specify in environment)
Linux
_APP_STORAGE_LIMIT=60000000
(10MB to 60MB or more)After trying to work with this sdk in a typescript based node.js project i found out that this node.js SDK is missing typescript support.
That might happen because its missing the index.d.ts file we have added to the client SDK a few weeks ago.
Call method that returns an error. It will show the response as an object, but TS is typed as a string.
This will show
AppwriteException [Error]: A user with the same email already exists in your project.
at Client.call (/Users/ajonp/web/dubstep-stack/node_modules/node-appwrite/lib/client.js:171:31)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Users.create (/Users/ajonp/web/dubstep-stack/node_modules/node-appwrite/lib/services/users.js:86:16)
at createUser (/Users/ajonp/web/dubstep-stack/app/models/user.server.ts:10:16)
at action5 (/Users/ajonp/web/dubstep-stack/app/routes/join.tsx:73:7)
at Object.callRouteAction (/Users/ajonp/web/dubstep-stack/node_modules/@remix-run/server-runtime/dist/data.js:40:14)
at handleDataRequest (/Users/ajonp/web/dubstep-stack/node_modules/@remix-run/server-runtime/dist/server.js:94:18)
at requestHandler (/Users/ajonp/web/dubstep-stack/node_modules/@remix-run/server-runtime/dist/server.js:34:18)
at /Users/ajonp/web/dubstep-stack/node_modules/@remix-run/express/dist/server.js:39:22 {
code: 409,
type: 'user_already_exists',
response: {
message: 'A user with the same email already exists in your project.',
code: 409,
type: 'user_already_exists',
version: '1.0.1'
}
}
Line 1781 in 6caaeb8
TS should change from
export class AppwriteException extends Error {
public code: number | null;
public response: string | null;
constructor(message: string, code?: number, response?: string);
}
to
export class AppwriteException extends Error {
public code: number | null;
public response: AppwriteExceptionResponse | null;
constructor(message: string, code?: number, response?: string);
}
export type AppwriteExceptionResponse = {
message: string,
code: number,
type: string,
version: number
}
}
catch (error) {
let message = 'Unknown Error'
if (error instanceof AppwriteException) message = error?.response != null ? error.response : message;
return json<ActionData>(
{ errors: { email: `${message} for ${email}` } },
{ status: 400 }
);
}
Causes [object Object]
Version 0.10.x
MacOS
No
I tried the following in my node app
try {
const _response = databases.createDocument(
process.env.APPWRITE_DATABASE_ID,
process.env.APPWRITE_COLLECTION_ID,
uuidv4(),
{
query: query as string,
userId: auth0UserId as string,
},
)
} catch (e) {
console.log(e)
}
It works as expected.
When the appwrite server is not available I expect, that my node server continue running and displays the error in the console.
My node server stops working with:
[2023-05-11T12:44:36.447Z] Error:
at Client.call (/Users/holger/Documents/GitHub/pzh-server/node_modules/node-appwrite/lib/client.js:170:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Databases.createDocument (/Users/holger/Documents/GitHub/pzh-server/node_modules/node-appwrite/lib/services/databases.js:1666:16)
[ERROR] 14:44:36 Error
"node-appwrite": "^9.0.0",
Version 0.10.x
Linux
No response
Hello;
Thanks again for Appwrite; really neat project, with awesome docs too.
So, after introducing SSR capabilities, I was finally getting started on my SvelteKit project, and followed along with how this sdk is the one to use for SSR.
Currently, deploying my project to Cloudflare Pages breaks everything since CF isn't a true node runtime, and doesn't support some modules. I know from the name itself this is a node
sdk, but I was hoping to hear of a solution and/or alternatives in order to have SSR in my app.
There are currently Error: Bundling with esbuild failed with 29 errors
in different files that crash everything. Here is a list of inaccessible modules and file source:
I guess my ask is, do you mind providing support for Cloudflare pages with this SDK, and if it's not possible, do you mind pointing me in the right direction in terms of alternatives for someone trying to use SSR capabilities with Appwrite but deploying on Cloudflare.
Thank you for the consideration. ๐
In my use-case, I really love deploying to Cloudflare because it's very convenient, easy, and free. ๐
Guessing other people feel the same.
node-appwrite
in a new TS project and compile using tsc
with the following tsconfig.json
:{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"moduleResolution": "node",
},
"exclude": ["node_modules", "dist", "__tests__"]
}
node dist/src/index
, with index.ts being the following:import sdk from "node-appwrite";
const client = new sdk.Client();
const client = new node_appwrite_1.default.Client();
^
TypeError: Cannot read property 'Client' of undefined
at Object.<anonymous> (/Users/daniellesage/Github/krypto-backend-ts/dist/index.js:5:44)
I should be able to instantiate a new client.
I get the following error message:
const client = new node_appwrite_1.default.Client();
^
TypeError: Cannot read property 'Client' of undefined
at Object.<anonymous> (/Users/daniellesage/Github/krypto-backend-ts/dist/index.js:5:44)
Version 0.10.x
MacOS
Nothing in particular.
import { Client, Databases, Users } from "node-appwrite";
const client = new Client();
const databases = new Databases(client);
client
.setEndpoint(ENDPOINT)
.setProject(PROJECT_ID)
.setKey(API_KEY);
const {my_attribute} = databases.getDocument(DB_ID, COLLECTION_ID, DOCUMENT_ID);
In this example, my_attribute
shows a TS error saying "Property 'my_attribute' does not exist on type 'Document'"
That's a quickie. I would be happy to help with this
It should adapt to any property I wanna use from the document
Throws a TS error
Different version (specify in environment)
Linux
node-appwrite
v11.1.0
I noticed that the example docs are Markdown files, but the contents are not inside code blocks. As a result the code is missing syntax highlighting, and indentation is broken.
Example:
How it looks currently:
const sdk = require('node-appwrite');
// Init SDK let client = new sdk.Client();
let avatars = new sdk.Avatars(client);
client .setProject('5df5acd0d48c2') // Your project ID .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ;
let promise = avatars.getBrowser('aa');
promise.then(function (response) { console.log(response); }, function (error) { console.log(error); });
With a code block:
const sdk = require('node-appwrite');
// Init SDK
let client = new sdk.Client();
let avatars = new sdk.Avatars(client);
client
.setProject('5df5acd0d48c2') // Your project ID
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;
let promise = avatars.getBrowser('aa');
promise.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});
const document = await databases.createDocument(
import.meta.env.VITE_APPWRITE_EVENTS_DATABASE_ID,
import.meta.env.VITE_APPWRITE_EVENTS_COLLECTION_ID,
ID.unique(),
{
...,
date: new Date().toISOString(),
...
}
);
My Solution: If I remove the Z at end of datetime, document is then correctly created
const document = await databases.createDocument(
import.meta.env.VITE_APPWRITE_EVENTS_DATABASE_ID,
import.meta.env.VITE_APPWRITE_EVENTS_COLLECTION_ID,
ID.unique(),
{
...,
date: new Date(target.date.value).toISOString().slice(0, -1),
...
}
);
New document in collection will be created.
Gives a 500 server error
Version 0.10.x
Linux
No response
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.