Skip to content

Commit 7c865f9

Browse files
committed
Add new push message parameters
1 parent 255c672 commit 7c865f9

37 files changed

+1100
-1187
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Appwrite Deno SDK
22

33
![License](https://img.shields.io/github/license/appwrite/sdk-for-deno.svg?style=flat-square)
4-
![Version](https://img.shields.io/badge/api%20version-1.6.0-blue.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-1.6.1-blue.svg?style=flat-square)
55
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

docs/examples/databases/update-string-attribute.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ const response = await databases.updateStringAttribute(
1313
'', // key
1414
false, // required
1515
'<DEFAULT>', // default
16-
null, // size (optional)
16+
1, // size (optional)
1717
'' // newKey (optional)
1818
);

docs/examples/functions/create-deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const functions = new Functions(client);
99

1010
const response = await functions.createDeployment(
1111
'<FUNCTION_ID>', // functionId
12-
Payload.fromFile('/path/to/file.png'), // code
12+
InputFile.fromPath('/path/to/file.png', 'file.png'), // code
1313
false, // activate
1414
'<ENTRYPOINT>', // entrypoint (optional)
1515
'<COMMANDS>' // commands (optional)

docs/examples/functions/create-execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const functions = new Functions(client);
99

1010
const response = await functions.createExecution(
1111
'<FUNCTION_ID>', // functionId
12-
Payload.fromJson({ x: "y" }), // body (optional)
12+
'<BODY>', // body (optional)
1313
false, // async (optional)
1414
'<PATH>', // path (optional)
1515
ExecutionMethod.GET, // method (optional)

docs/examples/messaging/create-push.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts";
1+
import { Client, Messaging, MessagePriority } from "https://deno.land/x/appwrite/mod.ts";
22

33
const client = new Client()
44
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
@@ -9,8 +9,8 @@ const messaging = new Messaging(client);
99

1010
const response = await messaging.createPush(
1111
'<MESSAGE_ID>', // messageId
12-
'<TITLE>', // title
13-
'<BODY>', // body
12+
'<TITLE>', // title (optional)
13+
'<BODY>', // body (optional)
1414
[], // topics (optional)
1515
[], // users (optional)
1616
[], // targets (optional)
@@ -21,7 +21,10 @@ const response = await messaging.createPush(
2121
'<SOUND>', // sound (optional)
2222
'<COLOR>', // color (optional)
2323
'<TAG>', // tag (optional)
24-
'<BADGE>', // badge (optional)
24+
null, // badge (optional)
2525
false, // draft (optional)
26-
'' // scheduledAt (optional)
26+
'', // scheduledAt (optional)
27+
false, // contentAvailable (optional)
28+
false, // critical (optional)
29+
MessagePriority.Normal // priority (optional)
2730
);

docs/examples/messaging/update-push.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, Messaging } from "https://deno.land/x/appwrite/mod.ts";
1+
import { Client, Messaging, MessagePriority } from "https://deno.land/x/appwrite/mod.ts";
22

33
const client = new Client()
44
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
@@ -23,5 +23,8 @@ const response = await messaging.updatePush(
2323
'<TAG>', // tag (optional)
2424
null, // badge (optional)
2525
false, // draft (optional)
26-
'' // scheduledAt (optional)
26+
'', // scheduledAt (optional)
27+
false, // contentAvailable (optional)
28+
false, // critical (optional)
29+
MessagePriority.Normal // priority (optional)
2730
);

docs/examples/storage/create-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ const storage = new Storage(client);
1010
const response = await storage.createFile(
1111
'<BUCKET_ID>', // bucketId
1212
'<FILE_ID>', // fileId
13-
Payload.fromFile('/path/to/file.png'), // file
13+
InputFile.fromPath('/path/to/file.png', 'file.png'), // file
1414
["read("any")"] // permissions (optional)
1515
);

mod.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Query } from "./src/query.ts";
33
import { Permission } from "./src/permission.ts";
44
import { Role } from "./src/role.ts";
55
import { ID } from "./src/id.ts";
6-
import { Payload } from "./src/payload.ts";
6+
import { InputFile } from "./src/inputFile.ts";
77
import { AppwriteException } from "./src/exception.ts";
88
import { Account } from "./src/services/account.ts";
99
import { Avatars } from "./src/services/avatars.ts";
@@ -28,6 +28,7 @@ import { IndexType } from "./src/enums/index-type.ts";
2828
import { Runtime } from "./src/enums/runtime.ts";
2929
import { ExecutionMethod } from "./src/enums/execution-method.ts";
3030
import { Name } from "./src/enums/name.ts";
31+
import { MessagePriority } from "./src/enums/message-priority.ts";
3132
import { SmtpEncryption } from "./src/enums/smtp-encryption.ts";
3233
import { Compression } from "./src/enums/compression.ts";
3334
import { ImageGravity } from "./src/enums/image-gravity.ts";
@@ -41,7 +42,7 @@ export {
4142
Permission,
4243
Role,
4344
ID,
44-
Payload,
45+
InputFile,
4546
AppwriteException,
4647
Account,
4748
Avatars,
@@ -66,6 +67,7 @@ export {
6667
Runtime,
6768
ExecutionMethod,
6869
Name,
70+
MessagePriority,
6971
SmtpEncryption,
7072
Compression,
7173
ImageGravity,

src/client.ts

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { AppwriteException } from './exception.ts';
2-
import { Payload } from './payload.ts';
3-
import { getBoundary, parse as parseMultipart } from './multipart.ts';
42

5-
export interface Params {
3+
export interface Payload {
64
[key: string]: any;
75
}
86

@@ -11,13 +9,13 @@ export class Client {
119
static DENO_READ_CHUNK_SIZE = 16384; // 16kb; refference: https://github.com/denoland/deno/discussions/9906
1210

1311
endpoint: string = 'https://cloud.appwrite.io/v1';
14-
headers: Params = {
12+
headers: Payload = {
1513
'content-type': '',
16-
'user-agent' : `AppwriteDenoSDK/13.0.0 (${Deno.build.os}; ${Deno.build.arch})`,
14+
'user-agent' : `AppwriteDenoSDK/12.2.0 (${Deno.build.os}; ${Deno.build.arch})`,
1715
'x-sdk-name': 'Deno',
1816
'x-sdk-platform': 'server',
1917
'x-sdk-language': 'deno',
20-
'x-sdk-version': '13.0.0',
18+
'x-sdk-version': '12.2.0',
2119
'X-Appwrite-Response-Format':'1.6.0',
2220
};
2321

@@ -130,7 +128,7 @@ export class Client {
130128
return this;
131129
}
132130

133-
async call(method: string, path: string = "", headers: Params = {}, params: Params = {}, responseType: string = "json") {
131+
async call(method: string, path: string = "", headers: Payload = {}, params: Payload = {}, responseType: string = "json") {
134132
headers = {...this.headers, ...headers};
135133
const url = new URL(this.endpoint + path);
136134

@@ -194,40 +192,6 @@ export class Client {
194192
return response.headers.get("location");
195193
}
196194

197-
if (response.headers.get('content-type')?.includes('multipart/form-data')) {
198-
const boundary = getBoundary(
199-
response.headers.get("content-type") || ""
200-
);
201-
202-
const body = new Uint8Array(await response.arrayBuffer());
203-
const parts = parseMultipart(body, boundary);
204-
const partsObject: { [key: string]: any } = {};
205-
206-
for (const part of parts) {
207-
if (!part.name) {
208-
continue;
209-
}
210-
if (part.name === "responseBody") {
211-
partsObject[part.name] = Payload.fromBinary(part.data, part.filename);
212-
} else if (part.name === "responseStatusCode") {
213-
partsObject[part.name] = parseInt(part.data.toString());
214-
} else if (part.name === "duration") {
215-
partsObject[part.name] = parseFloat(part.data.toString());
216-
} else if (part.type === 'application/json') {
217-
try {
218-
partsObject[part.name] = JSON.parse(part.data.toString());
219-
} catch (e) {
220-
throw new Error(`Error parsing JSON for part ${part.name}: ${e instanceof Error ? e.message : 'Unknown error'}`);
221-
}
222-
} else {
223-
partsObject[part.name] = new TextDecoder().decode(part.data);
224-
}
225-
}
226-
227-
const data = partsObject;
228-
return data;
229-
}
230-
231195
const text = await response.text();
232196
let json = undefined;
233197
try {
@@ -238,8 +202,8 @@ export class Client {
238202
return json;
239203
}
240204

241-
static flatten(data: Params, prefix = ''): Params {
242-
let output: Params = {};
205+
static flatten(data: Payload, prefix = ''): Payload {
206+
let output: Payload = {};
243207

244208
for (const [key, value] of Object.entries(data)) {
245209
let finalKey = prefix ? prefix + '[' + key +']' : key;

src/enums/message-priority.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum MessagePriority {
2+
Normal = 'normal',
3+
High = 'high',
4+
}

0 commit comments

Comments
 (0)