discourse-js
Advanced tools
Comparing version 3.0.9 to 3.0.11
@@ -307,34 +307,32 @@ 'use strict'; | ||
var _this = this; | ||
this.get = function () { return __awaiter(_this, void 0, void 0, function () { | ||
this.get = function (inputs) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, discourse.get({ | ||
path: "topics/private-messages/" + discourse._API_USERNAME + ".json", | ||
path: buildQueryString("topics/private-messages/" + discourse._API_USERNAME + ".json", inputs), | ||
})]; | ||
}); | ||
}); }; | ||
this.getGroupMessages = function (_a) { | ||
var group_name = _a.group_name; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_b) { | ||
return [2 /*return*/, discourse.get({ | ||
path: "topics/private-messages-group/" + discourse._API_USERNAME + "/" + group_name + ".json", | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
})]; | ||
}); | ||
this.getGroupMessages = function (_a) { return __awaiter(_this, void 0, void 0, function () { | ||
var group_name = _a.group_name, inputs = __rest(_a, ["group_name"]); | ||
return __generator(this, function (_b) { | ||
return [2 /*return*/, discourse.get({ | ||
path: buildQueryString("topics/private-messages-group/" + discourse._API_USERNAME + "/" + group_name + ".json", inputs), | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
})]; | ||
}); | ||
}; | ||
this.getSentMessages = function () { return __awaiter(_this, void 0, void 0, function () { | ||
}); }; | ||
this.getSentMessages = function (inputs) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, discourse.get({ | ||
path: "topics/private-messages-sent/" + discourse._API_USERNAME + ".json", | ||
path: buildQueryString("topics/private-messages-sent/" + discourse._API_USERNAME + ".json", inputs), | ||
})]; | ||
}); | ||
}); }; | ||
this.getAllMessages = function () { return __awaiter(_this, void 0, void 0, function () { | ||
this.getAllMessages = function (inputs) { return __awaiter(_this, void 0, void 0, function () { | ||
var getMessages, getSentMessages; | ||
return __generator(this, function (_a) { | ||
getMessages = this.get(); | ||
getSentMessages = this.getSentMessages(); | ||
getMessages = this.get(inputs); | ||
getSentMessages = this.getSentMessages(inputs); | ||
return [2 /*return*/, Promise.all([getMessages, getSentMessages])]; | ||
@@ -341,0 +339,0 @@ }); |
@@ -303,34 +303,32 @@ import { camelizeKeys } from 'humps'; | ||
var _this = this; | ||
this.get = function () { return __awaiter(_this, void 0, void 0, function () { | ||
this.get = function (inputs) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, discourse.get({ | ||
path: "topics/private-messages/" + discourse._API_USERNAME + ".json", | ||
path: buildQueryString("topics/private-messages/" + discourse._API_USERNAME + ".json", inputs), | ||
})]; | ||
}); | ||
}); }; | ||
this.getGroupMessages = function (_a) { | ||
var group_name = _a.group_name; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_b) { | ||
return [2 /*return*/, discourse.get({ | ||
path: "topics/private-messages-group/" + discourse._API_USERNAME + "/" + group_name + ".json", | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
})]; | ||
}); | ||
this.getGroupMessages = function (_a) { return __awaiter(_this, void 0, void 0, function () { | ||
var group_name = _a.group_name, inputs = __rest(_a, ["group_name"]); | ||
return __generator(this, function (_b) { | ||
return [2 /*return*/, discourse.get({ | ||
path: buildQueryString("topics/private-messages-group/" + discourse._API_USERNAME + "/" + group_name + ".json", inputs), | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
})]; | ||
}); | ||
}; | ||
this.getSentMessages = function () { return __awaiter(_this, void 0, void 0, function () { | ||
}); }; | ||
this.getSentMessages = function (inputs) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, discourse.get({ | ||
path: "topics/private-messages-sent/" + discourse._API_USERNAME + ".json", | ||
path: buildQueryString("topics/private-messages-sent/" + discourse._API_USERNAME + ".json", inputs), | ||
})]; | ||
}); | ||
}); }; | ||
this.getAllMessages = function () { return __awaiter(_this, void 0, void 0, function () { | ||
this.getAllMessages = function (inputs) { return __awaiter(_this, void 0, void 0, function () { | ||
var getMessages, getSentMessages; | ||
return __generator(this, function (_a) { | ||
getMessages = this.get(); | ||
getSentMessages = this.getSentMessages(); | ||
getMessages = this.get(inputs); | ||
getSentMessages = this.getSentMessages(inputs); | ||
return [2 /*return*/, Promise.all([getMessages, getSentMessages])]; | ||
@@ -337,0 +335,0 @@ }); |
@@ -307,34 +307,32 @@ (function (global, factory) { | ||
var _this = this; | ||
this.get = function () { return __awaiter(_this, void 0, void 0, function () { | ||
this.get = function (inputs) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, discourse.get({ | ||
path: "topics/private-messages/" + discourse._API_USERNAME + ".json", | ||
path: buildQueryString("topics/private-messages/" + discourse._API_USERNAME + ".json", inputs), | ||
})]; | ||
}); | ||
}); }; | ||
this.getGroupMessages = function (_a) { | ||
var group_name = _a.group_name; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_b) { | ||
return [2 /*return*/, discourse.get({ | ||
path: "topics/private-messages-group/" + discourse._API_USERNAME + "/" + group_name + ".json", | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
})]; | ||
}); | ||
this.getGroupMessages = function (_a) { return __awaiter(_this, void 0, void 0, function () { | ||
var group_name = _a.group_name, inputs = __rest(_a, ["group_name"]); | ||
return __generator(this, function (_b) { | ||
return [2 /*return*/, discourse.get({ | ||
path: buildQueryString("topics/private-messages-group/" + discourse._API_USERNAME + "/" + group_name + ".json", inputs), | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
})]; | ||
}); | ||
}; | ||
this.getSentMessages = function () { return __awaiter(_this, void 0, void 0, function () { | ||
}); }; | ||
this.getSentMessages = function (inputs) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, discourse.get({ | ||
path: "topics/private-messages-sent/" + discourse._API_USERNAME + ".json", | ||
path: buildQueryString("topics/private-messages-sent/" + discourse._API_USERNAME + ".json", inputs), | ||
})]; | ||
}); | ||
}); }; | ||
this.getAllMessages = function () { return __awaiter(_this, void 0, void 0, function () { | ||
this.getAllMessages = function (inputs) { return __awaiter(_this, void 0, void 0, function () { | ||
var getMessages, getSentMessages; | ||
return __generator(this, function (_a) { | ||
getMessages = this.get(); | ||
getSentMessages = this.getSentMessages(); | ||
getMessages = this.get(inputs); | ||
getSentMessages = this.getSentMessages(inputs); | ||
return [2 /*return*/, Promise.all([getMessages, getSentMessages])]; | ||
@@ -341,0 +339,0 @@ }); |
@@ -6,3 +6,5 @@ import Discourse from '../index'; | ||
subcat_id?: number; | ||
latest: boolean; | ||
latest?: boolean; | ||
page?: number; | ||
[key: string]: string | number | boolean; | ||
}; | ||
@@ -9,0 +11,0 @@ export interface ICategories { |
import Discourse from '../index'; | ||
import { PrivateMessageList } from '../types/Messages'; | ||
import { Post } from '../types/Posts'; | ||
export declare type MessageParams = { | ||
page?: number; | ||
[key: string]: string | number | boolean; | ||
}; | ||
export interface SendMessageBody { | ||
@@ -5,0 +9,0 @@ topic_id: number; |
@@ -8,3 +8,4 @@ import { CreatePostBody } from './Posts'; | ||
reverse?: boolean; | ||
posts?: any; | ||
page?: number; | ||
posts?: number[]; | ||
username?: string; | ||
@@ -11,0 +12,0 @@ tag?: string; |
export declare const createBody: (params: Record<string, string | number | Blob>) => FormData; | ||
export declare const buildQueryString: (uri: string, params: Record<string, string | number | boolean>) => string; | ||
export declare const buildQueryString: (uri: string, params: Record<string, string | number | boolean | (string | number)[]>) => string; | ||
export declare class ApiError extends Error { | ||
@@ -4,0 +4,0 @@ status: number; |
{ | ||
"name": "discourse-js", | ||
"version": "3.0.9", | ||
"version": "3.0.11", | ||
"description": "A client-side javascript wrapper for the discourse API.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js", |
@@ -8,3 +8,5 @@ import Discourse from '../index'; | ||
subcat_id?: number; | ||
latest: boolean; | ||
latest?: boolean; | ||
page?: number; | ||
[key: string]: string | number | boolean; | ||
}; | ||
@@ -11,0 +13,0 @@ |
import Discourse from '../index'; | ||
import { buildQueryString } from '../utils'; | ||
import { PrivateMessageList } from '../types/Messages'; | ||
import { Post } from '../types/Posts'; | ||
export type MessageParams = { | ||
page?: number; | ||
[key: string]: string | number | boolean; | ||
}; | ||
export interface SendMessageBody { | ||
@@ -20,11 +26,20 @@ topic_id: number; | ||
export default function Messages(discourse: Discourse): void { | ||
this.get = async () => { | ||
this.get = async (inputs: MessageParams) => { | ||
return discourse.get({ | ||
path: `topics/private-messages/${discourse._API_USERNAME}.json`, | ||
path: buildQueryString( | ||
`topics/private-messages/${discourse._API_USERNAME}.json`, | ||
inputs, | ||
), | ||
}); | ||
}; | ||
this.getGroupMessages = async ({ group_name }: { group_name: string }) => { | ||
this.getGroupMessages = async ({ | ||
group_name, | ||
...inputs | ||
}: { group_name: string } & MessageParams) => { | ||
return discourse.get({ | ||
path: `topics/private-messages-group/${discourse._API_USERNAME}/${group_name}.json`, | ||
path: buildQueryString( | ||
`topics/private-messages-group/${discourse._API_USERNAME}/${group_name}.json`, | ||
inputs, | ||
), | ||
headers: { | ||
@@ -36,11 +51,14 @@ Accept: 'application/json', | ||
this.getSentMessages = async () => { | ||
this.getSentMessages = async (inputs: MessageParams) => { | ||
return discourse.get({ | ||
path: `topics/private-messages-sent/${discourse._API_USERNAME}.json`, | ||
path: buildQueryString( | ||
`topics/private-messages-sent/${discourse._API_USERNAME}.json`, | ||
inputs, | ||
), | ||
}); | ||
}; | ||
this.getAllMessages = async () => { | ||
const getMessages = this.get(); | ||
const getSentMessages = this.getSentMessages(); | ||
this.getAllMessages = async (inputs: MessageParams) => { | ||
const getMessages = this.get(inputs); | ||
const getSentMessages = this.getSentMessages(inputs); | ||
@@ -47,0 +65,0 @@ return Promise.all([getMessages, getSentMessages]); |
@@ -17,4 +17,5 @@ import { CreatePostBody } from './Posts'; | ||
reverse?: boolean; | ||
page?: number; | ||
// TODO: Add strict type | ||
posts?: any; | ||
posts?: number[]; | ||
username?: string; | ||
@@ -21,0 +22,0 @@ // By Tag |
@@ -24,3 +24,3 @@ export const createBody = ( | ||
uri: string, | ||
params: Record<string, string | number | boolean>, | ||
params: Record<string, string | number | boolean | (string | number)[]>, | ||
): string => { | ||
@@ -27,0 +27,0 @@ const queryString = Object.keys(params) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
344153
4479