Skip to content
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

Fix msg91 params #19

Merged
merged 1 commit into from
Mar 24, 2024
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 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.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 Messaging(client);
const response = 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 response = 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)
);
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.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',
};

Expand Down
29 changes: 25 additions & 4 deletions src/id.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
18 changes: 9 additions & 9 deletions src/services/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Models.Provider> {
async createMsg91Provider(providerId: string, name: string, templateId?: string, senderId?: string, authKey?: string, enabled?: boolean): Promise<Models.Provider> {
if (typeof providerId === 'undefined') {
throw new AppwriteException('Missing required parameter: "providerId"');
}
Expand All @@ -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;
Expand Down Expand Up @@ -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<Models.Provider> {
async updateMsg91Provider(providerId: string, name?: string, enabled?: boolean, templateId?: string, senderId?: string, authKey?: string): Promise<Models.Provider> {
if (typeof providerId === 'undefined') {
throw new AppwriteException('Missing required parameter: "providerId"');
}
Expand All @@ -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,
Expand Down