Skip to content

Commit

Permalink
Merge pull request #20 from appwrite/dev
Browse files Browse the repository at this point in the history
fix: minor bugs
  • Loading branch information
stnguyen90 authored May 29, 2024
2 parents 63b9538 + 44fc066 commit fe476d7
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Appwrite Deno SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-deno.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.5.4-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.5.7-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/messaging/update-email.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ const response = await messaging.updateEmail(
false, // html (optional)
[], // cc (optional)
[], // bcc (optional)
'' // scheduledAt (optional)
'', // scheduledAt (optional)
[] // attachments (optional)
);
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/10.0.1 (${Deno.build.os}; ${Deno.build.arch})`,
'user-agent' : `AppwriteDenoSDK/11.0.0 (${Deno.build.os}; ${Deno.build.arch})`,
'x-sdk-name': 'Deno',
'x-sdk-platform': 'server',
'x-sdk-language': 'deno',
'x-sdk-version': '10.0.1',
'x-sdk-version': '11.0.0',
'X-Appwrite-Response-Format':'1.5.0',
};

Expand Down
2 changes: 1 addition & 1 deletion src/enums/credit-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export enum CreditCard {
AmericanExpress = 'amex',
Argencard = 'argencard',
Cabal = 'cabal',
Consosud = 'censosud',
Cencosud = 'cencosud',
DinersClub = 'diners',
Discover = 'discover',
Elo = 'elo',
Expand Down
1 change: 1 addition & 0 deletions src/enums/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export enum Flag {
Palau = 'pw',
PapuaNewGuinea = 'pg',
Poland = 'pl',
FrenchPolynesia = 'pf',
NorthKorea = 'kp',
Portugal = 'pt',
Paraguay = 'py',
Expand Down
1 change: 0 additions & 1 deletion src/enums/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ export enum Name {
V1Builds = 'v1-builds',
V1Messaging = 'v1-messaging',
V1Migrations = 'v1-migrations',
Hamsterv1 = 'hamsterv1',
}
4 changes: 4 additions & 0 deletions src/enums/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export enum Runtime {
Python310 = 'python-3.10',
Python311 = 'python-3.11',
Python312 = 'python-3.12',
PythonMl311 = 'python-ml-3.11',
Deno121 = 'deno-1.21',
Deno124 = 'deno-1.24',
Deno135 = 'deno-1.35',
Deno140 = 'deno-1.40',
Dart215 = 'dart-2.15',
Dart216 = 'dart-2.16',
Expand Down
14 changes: 11 additions & 3 deletions src/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,10 @@ export namespace Models {
* Session creation date in ISO 8601 format.
*/
$createdAt: string;
/**
* Session update date in ISO 8601 format.
*/
$updatedAt: string;
/**
* User ID.
*/
Expand Down Expand Up @@ -2174,17 +2178,21 @@ export namespace Models {
*/
export type MfaFactors = {
/**
* TOTP
* Can TOTP be used for MFA challenge for this account.
*/
totp: boolean;
/**
* Phone
* Can phone (SMS) be used for MFA challenge for this account.
*/
phone: boolean;
/**
* Email
* Can email be used for MFA challenge for this account.
*/
email: boolean;
/**
* Can recovery code be used for MFA challenge for this account.
*/
recoveryCode: boolean;
}
/**
* Provider
Expand Down
8 changes: 4 additions & 4 deletions src/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class Account extends Service {
*
* Add an authenticator app to be used as an MFA factor. Verify the
* authenticator using the [verify
* authenticator](/docs/references/cloud/client-web/account#verifyAuthenticator)
* authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator)
* method.
*
* @param {AuthenticatorType} type
Expand Down Expand Up @@ -319,8 +319,8 @@ export class Account extends Service {
* Verify Authenticator
*
* Verify an authenticator app after adding it using the [add
* authenticator](/docs/references/cloud/client-web/account#addAuthenticator)
* method.
* authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator)
* method. add
*
* @param {AuthenticatorType} type
* @param {string} otp
Expand Down Expand Up @@ -362,7 +362,7 @@ export class Account extends Service {
* @throws {AppwriteException}
* @returns {Promise}
*/
async deleteMfaAuthenticator<Preferences extends Models.Preferences>(type: AuthenticatorType, otp: string): Promise<Models.User<Preferences>> {
async deleteMfaAuthenticator(type: AuthenticatorType, otp: string): Promise<Response> {
if (typeof type === 'undefined') {
throw new AppwriteException('Missing required parameter: "type"');
}
Expand Down
6 changes: 5 additions & 1 deletion src/services/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ export class Messaging extends Service {
* @param {string[]} cc
* @param {string[]} bcc
* @param {string} scheduledAt
* @param {string[]} attachments
* @throws {AppwriteException}
* @returns {Promise}
*/
async updateEmail(messageId: string, topics?: string[], users?: string[], targets?: string[], subject?: string, content?: string, draft?: boolean, html?: boolean, cc?: string[], bcc?: string[], scheduledAt?: string): Promise<Models.Message> {
async updateEmail(messageId: string, topics?: string[], users?: string[], targets?: string[], subject?: string, content?: string, draft?: boolean, html?: boolean, cc?: string[], bcc?: string[], scheduledAt?: string, attachments?: string[]): Promise<Models.Message> {
if (typeof messageId === 'undefined') {
throw new AppwriteException('Missing required parameter: "messageId"');
}
Expand Down Expand Up @@ -194,6 +195,9 @@ export class Messaging extends Service {
if (typeof scheduledAt !== 'undefined') {
payload['scheduledAt'] = scheduledAt;
}
if (typeof attachments !== 'undefined') {
payload['attachments'] = attachments;
}
return await this.client.call(
'patch',
apiPath,
Expand Down
8 changes: 4 additions & 4 deletions src/services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1504,11 +1504,11 @@ export class Users extends Service {
/**
* Create token
*
* Returns a token with a secret key for creating a session. If the provided
* user ID has not be registered, a new user will be created. Use the returned
* user ID and secret and submit a request to the [PUT
* /account/sessions/custom](https://appwrite.io/docs/references/cloud/client-web/account#updateCustomSession)
* Returns a token with a secret key for creating a session. Use the user ID
* and secret and submit a request to the [PUT
* /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
* endpoint to complete the login process.
*
*
* @param {string} userId
* @param {number} length
Expand Down
33 changes: 13 additions & 20 deletions test/services/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,32 +241,17 @@ describe('Account 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': '[email protected]',
'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 account.deleteMfaAuthenticator(
'totp',
'<OTP>',
);

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

Expand Down Expand Up @@ -309,7 +294,8 @@ describe('Account service', () => {
const data = {
'totp': true,
'phone': true,
'email': true,};
'email': true,
'recoveryCode': true,};

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

Expand Down Expand Up @@ -573,6 +559,7 @@ describe('Account service', () => {
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',
Expand Down Expand Up @@ -614,6 +601,7 @@ describe('Account service', () => {
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',
Expand Down Expand Up @@ -657,6 +645,7 @@ describe('Account service', () => {
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',
Expand Down Expand Up @@ -700,6 +689,7 @@ describe('Account service', () => {
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',
Expand Down Expand Up @@ -743,6 +733,7 @@ describe('Account service', () => {
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',
Expand Down Expand Up @@ -786,6 +777,7 @@ describe('Account service', () => {
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',
Expand Down Expand Up @@ -828,6 +820,7 @@ describe('Account service', () => {
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',
Expand Down
4 changes: 3 additions & 1 deletion test/services/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ describe('Users service', () => {
const data = {
'totp': true,
'phone': true,
'email': true,};
'email': true,
'recoveryCode': true,};

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

Expand Down Expand Up @@ -724,6 +725,7 @@ describe('Users service', () => {
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',
Expand Down

0 comments on commit fe476d7

Please sign in to comment.