Skip to content

Commit

Permalink
Merge pull request #77 from appwrite/dev
Browse files Browse the repository at this point in the history
Fix msg91 params
  • Loading branch information
christyjacob4 committed Mar 24, 2024
2 parents b1039ac + 2ebdcfe commit ba665ec
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Appwrite Node.js SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-node.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)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/messaging/create-msg91provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const messaging = new sdk.Messaging(client);
const result = await messaging.createMsg91Provider(
'<PROVIDER_ID>', // providerId
'<NAME>', // name
'+12065550100', // from (optional)
'<TEMPLATE_ID>', // templateId (optional)
'<SENDER_ID>', // senderId (optional)
'<AUTH_KEY>', // authKey (optional)
false // enabled (optional)
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/messaging/update-msg91provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const result = await messaging.updateMsg91Provider(
'<PROVIDER_ID>', // providerId
'<NAME>', // name (optional)
false, // enabled (optional)
'<TEMPLATE_ID>', // templateId (optional)
'<SENDER_ID>', // senderId (optional)
'<AUTH_KEY>', // authKey (optional)
'<FROM>' // from (optional)
'<AUTH_KEY>' // authKey (optional)
);
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4926,14 +4926,14 @@ declare module "node-appwrite" {
*
* @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}
*/
createMsg91Provider(providerId: string, name: string, from?: string, senderId?: string, authKey?: string, enabled?: boolean): Promise<Models.Provider>;
createMsg91Provider(providerId: string, name: string, templateId?: string, senderId?: string, authKey?: string, enabled?: boolean): Promise<Models.Provider>;
/**
* Update Msg91 provider
*
Expand All @@ -4942,13 +4942,13 @@ declare module "node-appwrite" {
* @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}
*/
updateMsg91Provider(providerId: string, name?: string, enabled?: boolean, senderId?: string, authKey?: string, from?: string): Promise<Models.Provider>;
updateMsg91Provider(providerId: string, name?: string, enabled?: boolean, templateId?: string, senderId?: string, authKey?: string): Promise<Models.Provider>;
/**
* Create Sendgrid provider
*
Expand Down
4 changes: 2 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Client {
this.headers = {
'accept-encoding': '*',
'content-type': '',
'user-agent' : `AppwriteNodeJSSDK/12.0.0 (${os.type()}; ${os.version()}; ${os.arch()})`,
'user-agent' : `AppwriteNodeJSSDK/12.0.1 (${os.type()}; ${os.version()}; ${os.arch()})`,
'x-sdk-name': 'Node.js',
'x-sdk-platform': 'server',
'x-sdk-language': 'nodejs',
'x-sdk-version': '12.0.0',
'x-sdk-version': '12.0.1',
'X-Appwrite-Response-Format' : '1.5.0',
};
this.selfSigned = false;
Expand Down
24 changes: 22 additions & 2 deletions lib/id.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
class ID {
// Generate an hex ID based on timestamp
// Recreated from https://www.php.net/manual/en/function.uniqid.php
static #hexTimestamp = () => {
const now = new Date();
const sec = Math.floor(now.getTime() / 1000);
const msec = now.getMilliseconds();

static unique = () => {
return 'unique()'
// Convert to hexadecimal
const hexTimestamp = sec.toString(16) + msec.toString(16).padStart(5, '0');
return hexTimestamp;
}

// Generate a unique ID with padding to have a longer ID
static unique = (padding = 7) => {
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;
}

static custom = (id) => {
Expand Down
20 changes: 10 additions & 10 deletions lib/services/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,14 +1005,14 @@ 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, name, from, senderId, authKey, enabled) {
async createMsg91Provider(providerId, name, templateId, senderId, authKey, enabled) {
const apiPath = '/messaging/providers/msg91';
let payload = {};
if (typeof providerId === 'undefined') {
Expand All @@ -1032,8 +1032,8 @@ class Messaging extends Service {
payload['name'] = name;
}

if (typeof from !== 'undefined') {
payload['from'] = from;
if (typeof templateId !== 'undefined') {
payload['templateId'] = templateId;
}

if (typeof senderId !== 'undefined') {
Expand Down Expand Up @@ -1061,13 +1061,13 @@ 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, name, enabled, senderId, authKey, from) {
async updateMsg91Provider(providerId, name, enabled, templateId, senderId, authKey) {
const apiPath = '/messaging/providers/msg91/{providerId}'.replace('{providerId}', providerId);
let payload = {};
if (typeof providerId === 'undefined') {
Expand All @@ -1083,6 +1083,10 @@ class Messaging extends Service {
payload['enabled'] = enabled;
}

if (typeof templateId !== 'undefined') {
payload['templateId'] = templateId;
}

if (typeof senderId !== 'undefined') {
payload['senderId'] = senderId;
}
Expand All @@ -1091,10 +1095,6 @@ class Messaging extends Service {
payload['authKey'] = authKey;
}

if (typeof from !== 'undefined') {
payload['from'] = from;
}

return await this.client.call('patch', apiPath, {
'content-type': 'application/json',
}, payload);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "node-appwrite",
"homepage": "https://appwrite.io/support",
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
"version": "12.0.0",
"version": "12.0.1",
"license": "BSD-3-Clause",
"main": "./index.js",
"types": "./index.d.ts",
Expand Down

0 comments on commit ba665ec

Please sign in to comment.