Skip to content

fix: pong response & chunked upload #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors.
Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export class Client {
endpoint: string = 'https://cloud.appwrite.io/v1';
headers: Payload = {
'content-type': '',
'user-agent' : `AppwriteDenoSDK/12.2.0 (${Deno.build.os}; ${Deno.build.arch})`,
'user-agent' : `AppwriteDenoSDK/13.0.0 (${Deno.build.os}; ${Deno.build.arch})`,
'x-sdk-name': 'Deno',
'x-sdk-platform': 'server',
'x-sdk-language': 'deno',
'x-sdk-version': '12.2.0',
'x-sdk-version': '13.0.0',
'X-Appwrite-Response-Format':'1.6.0',
};

Expand Down
1 change: 1 addition & 0 deletions src/enums/image-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export enum ImageFormat {
Gif = 'gif',
Png = 'png',
Webp = 'webp',
Heic = 'heic',
Avif = 'avif',
}
4 changes: 2 additions & 2 deletions src/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export class Account extends Service {
* @throws {AppwriteException}
* @returns {Promise}
*/
async updateMfaChallenge(challengeId: string, otp: string): Promise<Response> {
async updateMfaChallenge(challengeId: string, otp: string): Promise<Models.Session> {
if (typeof challengeId === 'undefined') {
throw new AppwriteException('Missing required parameter: "challengeId"');
}
Expand Down Expand Up @@ -1529,4 +1529,4 @@ export class Account extends Service {
'json'
);
}
}
}
2 changes: 1 addition & 1 deletion src/services/avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,4 @@ export class Avatars extends Service {
'arraybuffer'
);
}
}
}
2 changes: 1 addition & 1 deletion src/services/databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2149,4 +2149,4 @@ export class Databases extends Service {
'json'
);
}
}
}
18 changes: 15 additions & 3 deletions src/services/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ export class Functions extends Service {
}

const size = code.size;

const apiHeaders: { [header: string]: string } = {
'content-type': 'multipart/form-data',
};
Expand Down Expand Up @@ -501,7 +501,7 @@ export class Functions extends Service {
}

let uploadableChunkTrimmed: Uint8Array;

if(currentPosition + 1 >= Client.CHUNK_SIZE) {
uploadableChunkTrimmed = uploadableChunk;
} else {
Expand Down Expand Up @@ -658,6 +658,12 @@ export class Functions extends Service {
/**
* Rebuild deployment
*
* Create a new build for an existing function deployment. This endpoint
* allows you to rebuild a deployment with the updated function configuration,
* including its entrypoint and build commands if they have been modified The
* build process will be queued and executed asynchronously. The original
* deployment's code will be preserved and used for the new build.
*
* @param {string} functionId
* @param {string} deploymentId
* @param {string} buildId
Expand Down Expand Up @@ -692,6 +698,12 @@ export class Functions extends Service {
/**
* Cancel deployment
*
* Cancel an ongoing function deployment build. If the build is already in
* progress, it will be stopped and marked as canceled. If the build hasn't
* started yet, it will be marked as canceled without executing. You cannot
* cancel builds that have already completed (status 'ready') or failed. The
* response includes the final build status and details.
*
* @param {string} functionId
* @param {string} deploymentId
* @throws {AppwriteException}
Expand Down Expand Up @@ -1088,4 +1100,4 @@ export class Functions extends Service {
'json'
);
}
}
}
2 changes: 1 addition & 1 deletion src/services/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ export class Graphql extends Service {
'json'
);
}
}
}
2 changes: 1 addition & 1 deletion src/services/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,4 @@ export class Health extends Service {
'json'
);
}
}
}
2 changes: 1 addition & 1 deletion src/services/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,4 @@ export class Locale extends Service {
'json'
);
}
}
}
4 changes: 2 additions & 2 deletions src/services/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export class Messaging extends Service {
/**
* Update SMS
*
* Update an email message by its unique ID.
* Update an SMS message by its unique ID.
*
*
* @param {string} messageId
Expand Down Expand Up @@ -2260,4 +2260,4 @@ export class Messaging extends Service {
'json'
);
}
}
}
24 changes: 11 additions & 13 deletions src/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export class Storage extends Service {
}

const size = file.size;

const apiHeaders: { [header: string]: string } = {
'content-type': 'multipart/form-data',
};
Expand All @@ -353,16 +353,14 @@ export class Storage extends Service {

let chunksUploaded = 0;

if(fileId != 'unique()') {
try {
response = await this.client.call(
'get',
apiPath + '/' + fileId,
apiHeaders
);
chunksUploaded = response.chunksUploaded;
} catch(e) {
}
try {
response = await this.client.call(
'get',
apiPath + '/' + fileId,
apiHeaders
);
chunksUploaded = response.chunksUploaded;
} catch(e) {
}

let currentChunk = 1;
Expand All @@ -386,7 +384,7 @@ export class Storage extends Service {
}

let uploadableChunkTrimmed: Uint8Array;

if(currentPosition + 1 >= Client.CHUNK_SIZE) {
uploadableChunkTrimmed = uploadableChunk;
} else {
Expand Down Expand Up @@ -708,4 +706,4 @@ export class Storage extends Service {
'arraybuffer'
);
}
}
}
2 changes: 1 addition & 1 deletion src/services/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,4 @@ export class Teams extends Service {
'json'
);
}
}
}
4 changes: 2 additions & 2 deletions src/services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ export class Users extends Service {
* @throws {AppwriteException}
* @returns {Promise}
*/
async deleteMfaAuthenticator<Preferences extends Models.Preferences>(userId: string, type: AuthenticatorType): Promise<Models.User<Preferences>> {
async deleteMfaAuthenticator(userId: string, type: AuthenticatorType): Promise<Response> {
if (typeof userId === 'undefined') {
throw new AppwriteException('Missing required parameter: "userId"');
}
Expand Down Expand Up @@ -1647,4 +1647,4 @@ export class Users extends Service {
'json'
);
}
}
}
36 changes: 32 additions & 4 deletions test/services/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,45 @@ describe('Account service', () => {


test('test method updateMfaChallenge()', async () => {
const data = '';
const data = {
'\$id': '5e5ea5c16897e',
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
'userId': '5e5bb8c16897e',
'expire': '2020-10-15T06:38:00.000+00:00',
'provider': 'email',
'providerUid': 'user@example.com',
'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3',
'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00',
'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3',
'ip': '127.0.0.1',
'osCode': 'Mac',
'osName': 'Mac',
'osVersion': 'Mac',
'clientType': 'browser',
'clientCode': 'CM',
'clientName': 'Chrome Mobile iOS',
'clientVersion': '84.0',
'clientEngine': 'WebKit',
'clientEngineVersion': '605.1.15',
'deviceName': 'smartphone',
'deviceBrand': 'Google',
'deviceModel': 'Nexus 5',
'countryCode': 'US',
'countryName': 'United States',
'current': true,
'factors': [],
'secret': '5e5bb8c16897e',
'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',};

const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data)))
const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data)));

const response = await account.updateMfaChallenge(
'<CHALLENGE_ID>',
'<OTP>',
);

const text = await response.text();
assertEquals(text, data);
assertEquals(response, data);
stubbedFetch.restore();
});

Expand Down
23 changes: 4 additions & 19 deletions test/services/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,32 +505,17 @@ describe('Users service', () => {


test('test method deleteMfaAuthenticator()', async () => {
const data = {
'\$id': '5e5ea5c16897e',
'\$createdAt': '2020-10-15T06:38:00.000+00:00',
'\$updatedAt': '2020-10-15T06:38:00.000+00:00',
'name': 'John Doe',
'registration': '2020-10-15T06:38:00.000+00:00',
'status': true,
'labels': [],
'passwordUpdate': '2020-10-15T06:38:00.000+00:00',
'email': 'john@appwrite.io',
'phone': '+4930901820',
'emailVerification': true,
'phoneVerification': true,
'mfa': true,
'prefs': {},
'targets': [],
'accessedAt': '2020-10-15T06:38:00.000+00:00',};
const data = '';

const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(Response.json(data)));
const stubbedFetch = stub(globalThis, 'fetch', () => Promise.resolve(new Response(data)))

const response = await users.deleteMfaAuthenticator(
'<USER_ID>',
'totp',
);

assertEquals(response, data);
const text = await response.text();
assertEquals(text, data);
stubbedFetch.restore();
});

Expand Down