From 144716a6e42e628104bbb3ae956a117cc0afa0ab Mon Sep 17 00:00:00 2001 From: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> Date: Fri, 22 Mar 2024 23:57:06 +0000 Subject: [PATCH] fix(messaging): fix msg91 params --- README.md | 2 +- .../messaging/create-msg91provider.md | 2 +- .../messaging/update-msg91provider.md | 4 +-- src/client.ts | 4 +-- src/id.ts | 29 ++++++++++++++++--- src/services/messaging.ts | 18 ++++++------ 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 6cfb665..f846663 100644 --- a/README.md +++ b/README.md @@ -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.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.5.4-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) diff --git a/docs/examples/messaging/create-msg91provider.md b/docs/examples/messaging/create-msg91provider.md index 4383e23..86dbbf4 100644 --- a/docs/examples/messaging/create-msg91provider.md +++ b/docs/examples/messaging/create-msg91provider.md @@ -10,7 +10,7 @@ const messaging = new Messaging(client); const response = await messaging.createMsg91Provider( '', // providerId '', // name - '+12065550100', // from (optional) + '', // templateId (optional) '', // senderId (optional) '', // authKey (optional) false // enabled (optional) diff --git a/docs/examples/messaging/update-msg91provider.md b/docs/examples/messaging/update-msg91provider.md index 3239b97..c5e222f 100644 --- a/docs/examples/messaging/update-msg91provider.md +++ b/docs/examples/messaging/update-msg91provider.md @@ -11,7 +11,7 @@ const response = await messaging.updateMsg91Provider( '', // providerId '', // name (optional) false, // enabled (optional) + '', // templateId (optional) '', // senderId (optional) - '', // authKey (optional) - '' // from (optional) + '' // authKey (optional) ); diff --git a/src/client.ts b/src/client.ts index 9c0c138..f592dff 100644 --- a/src/client.ts +++ b/src/client.ts @@ -11,11 +11,11 @@ export class Client { endpoint: string = 'https://cloud.appwrite.io/v1'; headers: Payload = { 'content-type': '', - 'user-agent' : `AppwriteDenoSDK/10.0.0 (${Deno.build.os}; ${Deno.build.arch})`, + 'user-agent' : `AppwriteDenoSDK/10.0.1 (${Deno.build.os}; ${Deno.build.arch})`, 'x-sdk-name': 'Deno', 'x-sdk-platform': 'server', 'x-sdk-language': 'deno', - 'x-sdk-version': '10.0.0', + 'x-sdk-version': '10.0.1', 'X-Appwrite-Response-Format':'1.5.0', }; diff --git a/src/id.ts b/src/id.ts index 9577e4b..4556ccb 100644 --- a/src/id.ts +++ b/src/id.ts @@ -1,9 +1,30 @@ export class ID { + // Generate an hex ID based on timestamp + // Recreated from https://www.php.net/manual/en/function.uniqid.php + static #hexTimestamp(): string { + const now = new Date(); + const sec = Math.floor(now.getTime() / 1000); + const msec = now.getMilliseconds(); + + // Convert to hexadecimal + const hexTimestamp = sec.toString(16) + msec.toString(16).padStart(5, '0'); + return hexTimestamp; + } + public static custom(id: string): string { return id } - - public static unique(): string { - return 'unique()' + + // Generate a unique ID with padding to have a longer ID + public static unique(padding: number = 7): string { + const baseId = ID.#hexTimestamp(); + let randomPadding = ''; + + for (let i = 0; i < padding; i++) { + const randomHexDigit = Math.floor(Math.random() * 16).toString(16); + randomPadding += randomHexDigit; + } + + return baseId + randomPadding; } -} \ No newline at end of file +} diff --git a/src/services/messaging.ts b/src/services/messaging.ts index 77e0a59..2bcf0c3 100644 --- a/src/services/messaging.ts +++ b/src/services/messaging.ts @@ -994,14 +994,14 @@ export class Messaging extends Service { * * @param {string} providerId * @param {string} name - * @param {string} from + * @param {string} templateId * @param {string} senderId * @param {string} authKey * @param {boolean} enabled * @throws {AppwriteException} * @returns {Promise} */ - async createMsg91Provider(providerId: string, name: string, from?: string, senderId?: string, authKey?: string, enabled?: boolean): Promise { + async createMsg91Provider(providerId: string, name: string, templateId?: string, senderId?: string, authKey?: string, enabled?: boolean): Promise { if (typeof providerId === 'undefined') { throw new AppwriteException('Missing required parameter: "providerId"'); } @@ -1019,8 +1019,8 @@ export class Messaging extends Service { if (typeof name !== 'undefined') { payload['name'] = name; } - if (typeof from !== 'undefined') { - payload['from'] = from; + if (typeof templateId !== 'undefined') { + payload['templateId'] = templateId; } if (typeof senderId !== 'undefined') { payload['senderId'] = senderId; @@ -1049,13 +1049,13 @@ export class Messaging extends Service { * @param {string} providerId * @param {string} name * @param {boolean} enabled + * @param {string} templateId * @param {string} senderId * @param {string} authKey - * @param {string} from * @throws {AppwriteException} * @returns {Promise} */ - async updateMsg91Provider(providerId: string, name?: string, enabled?: boolean, senderId?: string, authKey?: string, from?: string): Promise { + async updateMsg91Provider(providerId: string, name?: string, enabled?: boolean, templateId?: string, senderId?: string, authKey?: string): Promise { if (typeof providerId === 'undefined') { throw new AppwriteException('Missing required parameter: "providerId"'); } @@ -1069,15 +1069,15 @@ export class Messaging extends Service { if (typeof enabled !== 'undefined') { payload['enabled'] = enabled; } + if (typeof templateId !== 'undefined') { + payload['templateId'] = templateId; + } if (typeof senderId !== 'undefined') { payload['senderId'] = senderId; } if (typeof authKey !== 'undefined') { payload['authKey'] = authKey; } - if (typeof from !== 'undefined') { - payload['from'] = from; - } return await this.client.call( 'patch', apiPath,