@oblax/comments 0.0.0-stage → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bans.d.ts +29 -0
- package/dist/bans.d.ts.map +1 -0
- package/dist/bans.js +42 -0
- package/dist/bans.js.map +1 -0
- package/dist/comment-types.d.ts +32 -0
- package/dist/comment-types.d.ts.map +1 -0
- package/dist/comment-types.js +43 -0
- package/dist/comment-types.js.map +1 -0
- package/dist/comments-module.d.ts +64 -0
- package/dist/comments-module.d.ts.map +1 -0
- package/dist/comments-module.js +116 -0
- package/dist/comments-module.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/moderation.d.ts +47 -0
- package/dist/moderation.d.ts.map +1 -0
- package/dist/moderation.js +71 -0
- package/dist/moderation.js.map +1 -0
- package/dist/threads.d.ts +64 -0
- package/dist/threads.d.ts.map +1 -0
- package/dist/threads.js +131 -0
- package/dist/threads.js.map +1 -0
- package/dist/types.d.ts +439 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +48 -3
- package/README.md +0 -3
package/dist/bans.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { Ban, CommentsList, CreateBanParams, IdParams, ListQuery } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Bans users from posting, on one comment type or project-wide.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* await oblax.comments.bans.create({
|
|
9
|
+
* commentId: 'comment-id',
|
|
10
|
+
* type: 'product-reviews',
|
|
11
|
+
* reason: 'spam',
|
|
12
|
+
* removeComments: true,
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class BansSubmodule {
|
|
17
|
+
private readonly ctx;
|
|
18
|
+
constructor(ctx: OblaxContext);
|
|
19
|
+
/**
|
|
20
|
+
* The bans on the types the user moderates, and project-wide ones. Filter
|
|
21
|
+
* on `type_id`, `user_id`, `comment_id`.
|
|
22
|
+
*/
|
|
23
|
+
list(params?: ListQuery): Promise<CommentsList<Ban>>;
|
|
24
|
+
/** Bans a user, or a comment's author; optionally removes their comments in the background. */
|
|
25
|
+
create(params: CreateBanParams): Promise<Ban>;
|
|
26
|
+
/** Lifts a ban. */
|
|
27
|
+
lift(params: IdParams): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=bans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bans.d.ts","sourceRoot":"","sources":["../src/bans.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEzF;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY;IAE9C;;;OAGG;IACG,IAAI,CAAC,MAAM,GAAE,SAAc,GAAG,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IAI9D,+FAA+F;IACzF,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC;IAWnD,mBAAmB;IACb,IAAI,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAG5C"}
|
package/dist/bans.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { listPairs, buildQuery as query, pathSegment as seg } from '@oblax/core';
|
|
2
|
+
/**
|
|
3
|
+
* Bans users from posting, on one comment type or project-wide.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* await oblax.comments.bans.create({
|
|
8
|
+
* commentId: 'comment-id',
|
|
9
|
+
* type: 'product-reviews',
|
|
10
|
+
* reason: 'spam',
|
|
11
|
+
* removeComments: true,
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export class BansSubmodule {
|
|
16
|
+
constructor(ctx) {
|
|
17
|
+
this.ctx = ctx;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The bans on the types the user moderates, and project-wide ones. Filter
|
|
21
|
+
* on `type_id`, `user_id`, `comment_id`.
|
|
22
|
+
*/
|
|
23
|
+
async list(params = {}) {
|
|
24
|
+
return this.ctx.http.get(`/comments/bans${query({}, listPairs(params))}`);
|
|
25
|
+
}
|
|
26
|
+
/** Bans a user, or a comment's author; optionally removes their comments in the background. */
|
|
27
|
+
async create(params) {
|
|
28
|
+
return this.ctx.http.post('/comments/bans', {
|
|
29
|
+
user_id: params.userId,
|
|
30
|
+
comment_id: params.commentId,
|
|
31
|
+
type: params.type,
|
|
32
|
+
reason: params.reason,
|
|
33
|
+
expires_at: params.expiresAt,
|
|
34
|
+
remove_comments: params.removeComments,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** Lifts a ban. */
|
|
38
|
+
async lift(params) {
|
|
39
|
+
return this.ctx.http.delete(`/comments/bans/${seg(params.id)}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=bans.js.map
|
package/dist/bans.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bans.js","sourceRoot":"","sources":["../src/bans.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,IAAI,KAAK,EAAE,WAAW,IAAI,GAAG,EAAE,MAAM,aAAa,CAAA;AAGhF;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,aAAa;IACxB,YAA6B,GAAiB;QAAjB,QAAG,GAAH,GAAG,CAAc;IAAG,CAAC;IAElD;;;OAGG;IACH,KAAK,CAAC,IAAI,CAAC,SAAoB,EAAE;QAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAoB,iBAAiB,KAAK,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAA;IAC9F,CAAC;IAED,+FAA+F;IAC/F,KAAK,CAAC,MAAM,CAAC,MAAuB;QAClC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAM,gBAAgB,EAAE;YAC/C,OAAO,EAAU,MAAM,CAAC,MAAM;YAC9B,UAAU,EAAO,MAAM,CAAC,SAAS;YACjC,IAAI,EAAa,MAAM,CAAC,IAAI;YAC5B,MAAM,EAAW,MAAM,CAAC,MAAM;YAC9B,UAAU,EAAO,MAAM,CAAC,SAAS;YACjC,eAAe,EAAE,MAAM,CAAC,cAAc;SACvC,CAAC,CAAA;IACJ,CAAC;IAED,mBAAmB;IACnB,KAAK,CAAC,IAAI,CAAC,MAAgB;QACzB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAO,kBAAkB,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;IACvE,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { CommentType, CommentsList, CreateCommentTypeParams, IdParams, UpdateCommentTypeParams } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Manages comment types: how a kind of discussion behaves (mode, nesting,
|
|
5
|
+
* voting, anonymity, moderation, permissions). Settings use the API's own
|
|
6
|
+
* snake_case names, so a type read from the API can be edited and sent back.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const reviews = await oblax.comments.types.create({
|
|
11
|
+
* code: 'product-reviews',
|
|
12
|
+
* name: 'Product reviews',
|
|
13
|
+
* mode: 'reviews',
|
|
14
|
+
* threads: 'client',
|
|
15
|
+
* initial_status: 'pending',
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* await oblax.comments.types.update({ id: reviews.id, voting: 'up' })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class CommentTypesSubmodule {
|
|
22
|
+
private readonly ctx;
|
|
23
|
+
constructor(ctx: OblaxContext);
|
|
24
|
+
list(): Promise<CommentsList<CommentType>>;
|
|
25
|
+
get(params: IdParams): Promise<CommentType>;
|
|
26
|
+
/** Creates a type; settings left out take the defaults of a plain discussion. */
|
|
27
|
+
create(params: CreateCommentTypeParams): Promise<CommentType>;
|
|
28
|
+
/** Updates a type; settings left out keep their values. The code can't change. */
|
|
29
|
+
update(params: UpdateCommentTypeParams): Promise<void>;
|
|
30
|
+
delete(params: IdParams): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=comment-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-types.d.ts","sourceRoot":"","sources":["../src/comment-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,QAAQ,EACR,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,qBAAqB;IACpB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY;IAExC,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAI1C,GAAG,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;IAIjD,iFAAiF;IAC3E,MAAM,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,WAAW,CAAC;IAInE,kFAAkF;IAC5E,MAAM,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtD,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9C"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { pathSegment as seg } from '@oblax/core';
|
|
2
|
+
/**
|
|
3
|
+
* Manages comment types: how a kind of discussion behaves (mode, nesting,
|
|
4
|
+
* voting, anonymity, moderation, permissions). Settings use the API's own
|
|
5
|
+
* snake_case names, so a type read from the API can be edited and sent back.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const reviews = await oblax.comments.types.create({
|
|
10
|
+
* code: 'product-reviews',
|
|
11
|
+
* name: 'Product reviews',
|
|
12
|
+
* mode: 'reviews',
|
|
13
|
+
* threads: 'client',
|
|
14
|
+
* initial_status: 'pending',
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* await oblax.comments.types.update({ id: reviews.id, voting: 'up' })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export class CommentTypesSubmodule {
|
|
21
|
+
constructor(ctx) {
|
|
22
|
+
this.ctx = ctx;
|
|
23
|
+
}
|
|
24
|
+
async list() {
|
|
25
|
+
return this.ctx.http.get('/comments/types');
|
|
26
|
+
}
|
|
27
|
+
async get(params) {
|
|
28
|
+
return this.ctx.http.get(`/comments/types/${seg(params.id)}`);
|
|
29
|
+
}
|
|
30
|
+
/** Creates a type; settings left out take the defaults of a plain discussion. */
|
|
31
|
+
async create(params) {
|
|
32
|
+
return this.ctx.http.post('/comments/types', params);
|
|
33
|
+
}
|
|
34
|
+
/** Updates a type; settings left out keep their values. The code can't change. */
|
|
35
|
+
async update(params) {
|
|
36
|
+
const { id, ...settings } = params;
|
|
37
|
+
return this.ctx.http.put(`/comments/types/${seg(id)}`, settings);
|
|
38
|
+
}
|
|
39
|
+
async delete(params) {
|
|
40
|
+
return this.ctx.http.delete(`/comments/types/${seg(params.id)}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=comment-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-types.js","sourceRoot":"","sources":["../src/comment-types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,GAAG,EAAE,MAAM,aAAa,CAAA;AAShD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,qBAAqB;IAChC,YAA6B,GAAiB;QAAjB,QAAG,GAAH,GAAG,CAAc;IAAG,CAAC;IAElD,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAA4B,iBAAiB,CAAC,CAAA;IACxE,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,MAAgB;QACxB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAc,mBAAmB,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;IAC5E,CAAC;IAED,iFAAiF;IACjF,KAAK,CAAC,MAAM,CAAC,MAA+B;QAC1C,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAc,iBAAiB,EAAE,MAAM,CAAC,CAAA;IACnE,CAAC;IAED,kFAAkF;IAClF,KAAK,CAAC,MAAM,CAAC,MAA+B;QAC1C,MAAM,EAAE,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAA;QAClC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAO,mBAAmB,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;IACxE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAgB;QAC3B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAO,mBAAmB,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;IACxE,CAAC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import { CommentTypesSubmodule } from './comment-types.js';
|
|
3
|
+
import { ThreadsSubmodule } from './threads.js';
|
|
4
|
+
import { ModerationSubmodule } from './moderation.js';
|
|
5
|
+
import { BansSubmodule } from './bans.js';
|
|
6
|
+
import type { AttachmentLink, AttachmentParams, Comment, CommentPage, CommentsConfig, CommentsList, CreateCommentParams, IdParams, ListCommentsParams, ListRepliesParams, ReactParams, Report, ReportCommentParams, UpdateCommentParams, VoteParams } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* The Comments module.
|
|
9
|
+
*
|
|
10
|
+
* Comments, votes, reactions and reports are on the module itself; the rest
|
|
11
|
+
* is in sub-modules:
|
|
12
|
+
*
|
|
13
|
+
* - `types` — comment types: how a kind of discussion behaves.
|
|
14
|
+
* - `threads` — a subject's discussion: create, stats, state, subscriptions, members.
|
|
15
|
+
* - `moderation` — approve, remove, pin, accept...; the queue and the log.
|
|
16
|
+
* - `bans` — ban users on a type or project-wide.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const thread = await oblax.comments.threads.create({
|
|
21
|
+
* type: 'blog', subjectType: 'post', subjectId: 'post-1',
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* const comment = await oblax.comments.create({ threadId: thread.id, body: 'Nice post!' })
|
|
25
|
+
* await oblax.comments.create({ threadId: thread.id, parentId: comment.id, body: 'Agreed' })
|
|
26
|
+
*
|
|
27
|
+
* const page = await oblax.comments.list({ threadId: thread.id, sort: 'best' })
|
|
28
|
+
* await oblax.comments.vote({ id: page.data[0].id, value: 1 })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class CommentsModule {
|
|
32
|
+
private readonly ctx;
|
|
33
|
+
readonly types: CommentTypesSubmodule;
|
|
34
|
+
readonly threads: ThreadsSubmodule;
|
|
35
|
+
readonly moderation: ModerationSubmodule;
|
|
36
|
+
readonly bans: BansSubmodule;
|
|
37
|
+
constructor(ctx: OblaxContext, _config: CommentsConfig);
|
|
38
|
+
/** Returns a page of the thread's top-level comments. */
|
|
39
|
+
list(params: ListCommentsParams): Promise<CommentPage>;
|
|
40
|
+
/** Returns a page of a comment's direct replies. */
|
|
41
|
+
listReplies(params: ListRepliesParams): Promise<CommentPage>;
|
|
42
|
+
get(params: IdParams): Promise<Comment>;
|
|
43
|
+
/** Posts a comment in the thread, or a reply with `parentId`. */
|
|
44
|
+
create(params: CreateCommentParams): Promise<Comment>;
|
|
45
|
+
/** Edits the user's own comment. */
|
|
46
|
+
update(params: UpdateCommentParams): Promise<void>;
|
|
47
|
+
/** Deletes the user's own comment. */
|
|
48
|
+
delete(params: IdParams): Promise<void>;
|
|
49
|
+
/** Sets the user's vote: `1` or `-1`. */
|
|
50
|
+
vote(params: VoteParams): Promise<Comment>;
|
|
51
|
+
/** Removes the user's vote. */
|
|
52
|
+
unvote(params: IdParams): Promise<Comment>;
|
|
53
|
+
/** Adds the user's reaction (one of the type's `reactions`). */
|
|
54
|
+
react(params: ReactParams): Promise<Comment>;
|
|
55
|
+
/** Takes the user's reaction back. */
|
|
56
|
+
unreact(params: ReactParams): Promise<Comment>;
|
|
57
|
+
/** Returns a short-lived download link to one of a comment's files. */
|
|
58
|
+
getAttachmentLink(params: AttachmentParams): Promise<AttachmentLink>;
|
|
59
|
+
/** Reports a comment the user sees. */
|
|
60
|
+
report(params: ReportCommentParams): Promise<Report>;
|
|
61
|
+
/** Returns a comment's reports. Moderators only. */
|
|
62
|
+
listReports(params: IdParams): Promise<CommentsList<Report>>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=comments-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments-module.d.ts","sourceRoot":"","sources":["../src/comments-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,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Q,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,yCAAyC;IACnC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAIhD,+BAA+B;IACzB,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAIhD,gEAAgE;IAC1D,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAMlD,sCAAsC;IAChC,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAMpD,uEAAuE;IACjE,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC;IAM1E,uCAAuC;IACjC,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;IAO1D,oDAAoD;IAC9C,WAAW,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;CAGnE"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { buildQuery as query, pathSegment as seg } from '@oblax/core';
|
|
2
|
+
import { CommentTypesSubmodule } from './comment-types.js';
|
|
3
|
+
import { ThreadsSubmodule } from './threads.js';
|
|
4
|
+
import { ModerationSubmodule } from './moderation.js';
|
|
5
|
+
import { BansSubmodule } from './bans.js';
|
|
6
|
+
/**
|
|
7
|
+
* The Comments module.
|
|
8
|
+
*
|
|
9
|
+
* Comments, votes, reactions and reports are on the module itself; the rest
|
|
10
|
+
* is in sub-modules:
|
|
11
|
+
*
|
|
12
|
+
* - `types` — comment types: how a kind of discussion behaves.
|
|
13
|
+
* - `threads` — a subject's discussion: create, stats, state, subscriptions, members.
|
|
14
|
+
* - `moderation` — approve, remove, pin, accept...; the queue and the log.
|
|
15
|
+
* - `bans` — ban users on a type or project-wide.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const thread = await oblax.comments.threads.create({
|
|
20
|
+
* type: 'blog', subjectType: 'post', subjectId: 'post-1',
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* const comment = await oblax.comments.create({ threadId: thread.id, body: 'Nice post!' })
|
|
24
|
+
* await oblax.comments.create({ threadId: thread.id, parentId: comment.id, body: 'Agreed' })
|
|
25
|
+
*
|
|
26
|
+
* const page = await oblax.comments.list({ threadId: thread.id, sort: 'best' })
|
|
27
|
+
* await oblax.comments.vote({ id: page.data[0].id, value: 1 })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class CommentsModule {
|
|
31
|
+
constructor(ctx, _config) {
|
|
32
|
+
this.ctx = ctx;
|
|
33
|
+
this.types = new CommentTypesSubmodule(ctx);
|
|
34
|
+
this.threads = new ThreadsSubmodule(ctx);
|
|
35
|
+
this.moderation = new ModerationSubmodule(ctx);
|
|
36
|
+
this.bans = new BansSubmodule(ctx);
|
|
37
|
+
}
|
|
38
|
+
// ─── Comments ──────────────────────────────────────────────────────────────
|
|
39
|
+
/** Returns a page of the thread's top-level comments. */
|
|
40
|
+
async list(params) {
|
|
41
|
+
// 0 means the default page size: the API takes positive limits only
|
|
42
|
+
const qs = query({ sort: params.sort, cursor: params.cursor, limit: params.limit || undefined });
|
|
43
|
+
return this.ctx.http.get(`/comments/threads/${seg(params.threadId)}/comments${qs}`);
|
|
44
|
+
}
|
|
45
|
+
/** Returns a page of a comment's direct replies. */
|
|
46
|
+
async listReplies(params) {
|
|
47
|
+
const qs = query({ sort: params.sort, cursor: params.cursor, limit: params.limit || undefined });
|
|
48
|
+
return this.ctx.http.get(`/comments/${seg(params.id)}/replies${qs}`);
|
|
49
|
+
}
|
|
50
|
+
async get(params) {
|
|
51
|
+
return this.ctx.http.get(`/comments/${seg(params.id)}`);
|
|
52
|
+
}
|
|
53
|
+
/** Posts a comment in the thread, or a reply with `parentId`. */
|
|
54
|
+
async create(params) {
|
|
55
|
+
return this.ctx.http.post(`/comments/threads/${seg(params.threadId)}/comments`, {
|
|
56
|
+
body: params.body,
|
|
57
|
+
parent_id: params.parentId,
|
|
58
|
+
visibility: params.visibility,
|
|
59
|
+
anonymous: params.anonymous,
|
|
60
|
+
attributes: params.attributes,
|
|
61
|
+
language: params.language,
|
|
62
|
+
rating: params.rating,
|
|
63
|
+
anchor: params.anchor,
|
|
64
|
+
attachments: params.attachments,
|
|
65
|
+
guest_name: params.guestName,
|
|
66
|
+
guest_email: params.guestEmail,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Edits the user's own comment. */
|
|
70
|
+
async update(params) {
|
|
71
|
+
return this.ctx.http.put(`/comments/${seg(params.id)}`, {
|
|
72
|
+
body: params.body,
|
|
73
|
+
attributes: params.attributes,
|
|
74
|
+
language: params.language,
|
|
75
|
+
rating: params.rating,
|
|
76
|
+
anchor: params.anchor,
|
|
77
|
+
attachments: params.attachments,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** Deletes the user's own comment. */
|
|
81
|
+
async delete(params) {
|
|
82
|
+
return this.ctx.http.delete(`/comments/${seg(params.id)}`);
|
|
83
|
+
}
|
|
84
|
+
/** Sets the user's vote: `1` or `-1`. */
|
|
85
|
+
async vote(params) {
|
|
86
|
+
return this.ctx.http.put(`/comments/${seg(params.id)}/vote`, { value: params.value });
|
|
87
|
+
}
|
|
88
|
+
/** Removes the user's vote. */
|
|
89
|
+
async unvote(params) {
|
|
90
|
+
return this.ctx.http.delete(`/comments/${seg(params.id)}/vote`);
|
|
91
|
+
}
|
|
92
|
+
/** Adds the user's reaction (one of the type's `reactions`). */
|
|
93
|
+
async react(params) {
|
|
94
|
+
return this.ctx.http.put(`/comments/${seg(params.id)}/reactions/${seg(params.emoji)}`);
|
|
95
|
+
}
|
|
96
|
+
/** Takes the user's reaction back. */
|
|
97
|
+
async unreact(params) {
|
|
98
|
+
return this.ctx.http.delete(`/comments/${seg(params.id)}/reactions/${seg(params.emoji)}`);
|
|
99
|
+
}
|
|
100
|
+
/** Returns a short-lived download link to one of a comment's files. */
|
|
101
|
+
async getAttachmentLink(params) {
|
|
102
|
+
return this.ctx.http.get(`/comments/${seg(params.id)}/attachments/${seg(params.fileId)}`);
|
|
103
|
+
}
|
|
104
|
+
/** Reports a comment the user sees. */
|
|
105
|
+
async report(params) {
|
|
106
|
+
return this.ctx.http.post(`/comments/${seg(params.id)}/reports`, {
|
|
107
|
+
reason: params.reason,
|
|
108
|
+
note: params.note,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Returns a comment's reports. Moderators only. */
|
|
112
|
+
async listReports(params) {
|
|
113
|
+
return this.ctx.http.get(`/comments/${seg(params.id)}/reports`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=comments-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments-module.js","sourceRoot":"","sources":["../src/comments-module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,WAAW,IAAI,GAAG,EAAE,MAAM,aAAa,CAAA;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAmBzC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,cAAc;IAMzB,YAA6B,GAAiB,EAAE,OAAuB;QAA1C,QAAG,GAAH,GAAG,CAAc;QAC5C,IAAI,CAAC,KAAK,GAAQ,IAAI,qBAAqB,CAAC,GAAG,CAAC,CAAA;QAChD,IAAI,CAAC,OAAO,GAAM,IAAI,gBAAgB,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,mBAAmB,CAAC,GAAG,CAAC,CAAA;QA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AAC,GAAG,CAAuB,aAAa,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAA;IACvF,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { OblaxModulePlugin } from '@oblax/core';
|
|
2
|
+
import { CommentsModule } from './comments-module.js';
|
|
3
|
+
import type { CommentsConfig } from './types.js';
|
|
4
|
+
export { CommentsModule } from './comments-module.js';
|
|
5
|
+
export { CommentTypesSubmodule } from './comment-types.js';
|
|
6
|
+
export { ThreadsSubmodule } from './threads.js';
|
|
7
|
+
export { ModerationSubmodule } from './moderation.js';
|
|
8
|
+
export { BansSubmodule } from './bans.js';
|
|
9
|
+
export type { CommentsConfig, CommentsRecord, CommentsList, JsonObject, FilterOp, ListFilter, ListQuery, AttributeRule, IdParams, ReasonParams, CommentMode, CommentSort, CommentPermissions, AttachmentLimits, CommentType, CommentTypeSettings, CreateCommentTypeParams, UpdateCommentTypeParams, ThreadState, ThreadAudience, Thread, ListThreadsParams, CreateThreadParams, UpdateThreadSubjectParams, ThreadStatsParams, ThreadStats, SetThreadStateParams, SubscribeParams, MarkReadParams, ThreadMember, ListMembersParams, MemberPage, SetMemberParams, RemoveMemberParams, PostActivityParams, CommentStatus, CommentVisibility, CommentAttachment, Mention, Comment, CommentPage, ListCommentsParams, ListRepliesParams, CreateCommentParams, UpdateCommentParams, VoteParams, ReactParams, AttachmentParams, AttachmentLink, Report, ReportCommentParams, ModlogEntry, Ban, CreateBanParams, } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Comments module factory.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { Oblax } from '@oblax/core'
|
|
16
|
+
* import { PlatformBrowser } from '@oblax/platform-browser'
|
|
17
|
+
* import { Comments } from '@oblax/comments'
|
|
18
|
+
*
|
|
19
|
+
* const oblax = new Oblax({
|
|
20
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
21
|
+
* clientId: 'my-web-app',
|
|
22
|
+
* modules: [PlatformBrowser(), Comments()],
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* const thread = await oblax.comments.threads.create({
|
|
26
|
+
* type: 'blog', subjectType: 'post', subjectId: 'post-1',
|
|
27
|
+
* })
|
|
28
|
+
* await oblax.comments.create({ threadId: thread.id, body: 'First!' })
|
|
29
|
+
* const page = await oblax.comments.list({ threadId: thread.id })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function Comments(config?: CommentsConfig): OblaxModulePlugin<'comments', CommentsModule>;
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzC,YAAY,EACV,cAAc,EACd,cAAc,EACd,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,WAAW,EACX,cAAc,EACd,MAAM,EACN,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,OAAO,EACP,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,MAAM,EACN,mBAAmB,EACnB,WAAW,EACX,GAAG,EACH,eAAe,GAChB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,GAAE,cAAmB,GAAG,iBAAiB,CAAC,UAAU,EAAE,cAAc,CAAC,CAOnG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CommentsModule } from './comments-module.js';
|
|
2
|
+
export { CommentsModule } from './comments-module.js';
|
|
3
|
+
export { CommentTypesSubmodule } from './comment-types.js';
|
|
4
|
+
export { ThreadsSubmodule } from './threads.js';
|
|
5
|
+
export { ModerationSubmodule } from './moderation.js';
|
|
6
|
+
export { BansSubmodule } from './bans.js';
|
|
7
|
+
/**
|
|
8
|
+
* Comments module factory.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { Oblax } from '@oblax/core'
|
|
13
|
+
* import { PlatformBrowser } from '@oblax/platform-browser'
|
|
14
|
+
* import { Comments } from '@oblax/comments'
|
|
15
|
+
*
|
|
16
|
+
* const oblax = new Oblax({
|
|
17
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
18
|
+
* clientId: 'my-web-app',
|
|
19
|
+
* modules: [PlatformBrowser(), Comments()],
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* const thread = await oblax.comments.threads.create({
|
|
23
|
+
* type: 'blog', subjectType: 'post', subjectId: 'post-1',
|
|
24
|
+
* })
|
|
25
|
+
* await oblax.comments.create({ threadId: thread.id, body: 'First!' })
|
|
26
|
+
* const page = await oblax.comments.list({ threadId: thread.id })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function Comments(config = {}) {
|
|
30
|
+
return {
|
|
31
|
+
name: 'comments',
|
|
32
|
+
create(ctx) {
|
|
33
|
+
return new CommentsModule(ctx, config);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AA2DzC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAyB,EAAE;IAClD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,MAAM,CAAC,GAAiB;YACtB,OAAO,IAAI,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACxC,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { Comment, CommentsList, ListQuery, ModlogEntry, ReasonParams } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Moderation: decisions on single comments, the queue of comments waiting
|
|
5
|
+
* for one, and the moderation log. The backend decides who may act:
|
|
6
|
+
* moderators, the subject owner where the type allows it, or system callers.
|
|
7
|
+
* Each action takes an optional reason, recorded in the log.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const { data } = await oblax.comments.moderation.queue({
|
|
12
|
+
* order: { field: 'open_reports', direction: 'desc' },
|
|
13
|
+
* })
|
|
14
|
+
* await oblax.comments.moderation.approve({ id: data[0].id })
|
|
15
|
+
* await oblax.comments.moderation.spam({ id: 'comment-id', reason: 'link farm' })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class ModerationSubmodule {
|
|
19
|
+
private readonly ctx;
|
|
20
|
+
constructor(ctx: OblaxContext);
|
|
21
|
+
private act;
|
|
22
|
+
/** Publishes a pending comment, or one hidden by reports. */
|
|
23
|
+
approve(params: ReasonParams): Promise<Comment>;
|
|
24
|
+
/** Takes a comment down; its author sees it with the reason. */
|
|
25
|
+
remove(params: ReasonParams): Promise<Comment>;
|
|
26
|
+
/** Publishes a removed, hidden or spam comment again. */
|
|
27
|
+
restore(params: ReasonParams): Promise<Comment>;
|
|
28
|
+
/** Takes a comment down as spam, without telling its author. */
|
|
29
|
+
spam(params: ReasonParams): Promise<Comment>;
|
|
30
|
+
/** Pins a top-level comment on its thread. */
|
|
31
|
+
pin(params: ReasonParams): Promise<Comment>;
|
|
32
|
+
unpin(params: ReasonParams): Promise<Comment>;
|
|
33
|
+
/** Accepts an answer as its Q&A thread's accepted answer, in place of the one before. */
|
|
34
|
+
accept(params: ReasonParams): Promise<Comment>;
|
|
35
|
+
unaccept(params: ReasonParams): Promise<Comment>;
|
|
36
|
+
/**
|
|
37
|
+
* Comments waiting for a decision on the types the user moderates. Filter
|
|
38
|
+
* on `type_id`, `thread_id`, `status`; `count` is the total across pages.
|
|
39
|
+
*/
|
|
40
|
+
queue(params?: ListQuery): Promise<CommentsList<Comment>>;
|
|
41
|
+
/**
|
|
42
|
+
* The moderation log of the types the user moderates. Filter on
|
|
43
|
+
* `thread_id`, `target_id`, `action`, `actor_id`.
|
|
44
|
+
*/
|
|
45
|
+
log(params?: ListQuery): Promise<CommentsList<ModlogEntry>>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=moderation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moderation.d.ts","sourceRoot":"","sources":["../src/moderation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE7F;;;;;;;;;;;;;;GAcG;AACH,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY;IAE9C,OAAO,CAAC,GAAG;IAMX,6DAA6D;IAC7D,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAI/C,gEAAgE;IAChE,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAI9C,yDAAyD;IACzD,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAI/C,gEAAgE;IAChE,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAI5C,8CAA8C;IAC9C,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3C,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAI7C,yFAAyF;IACzF,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAI9C,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAIhD;;;OAGG;IACG,KAAK,CAAC,MAAM,GAAE,SAAc,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAMnE;;;OAGG;IACG,GAAG,CAAC,MAAM,GAAE,SAAc,GAAG,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;CAKtE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { listPairs, buildQuery as query, pathSegment as seg } from '@oblax/core';
|
|
2
|
+
/**
|
|
3
|
+
* Moderation: decisions on single comments, the queue of comments waiting
|
|
4
|
+
* for one, and the moderation log. The backend decides who may act:
|
|
5
|
+
* moderators, the subject owner where the type allows it, or system callers.
|
|
6
|
+
* Each action takes an optional reason, recorded in the log.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const { data } = await oblax.comments.moderation.queue({
|
|
11
|
+
* order: { field: 'open_reports', direction: 'desc' },
|
|
12
|
+
* })
|
|
13
|
+
* await oblax.comments.moderation.approve({ id: data[0].id })
|
|
14
|
+
* await oblax.comments.moderation.spam({ id: 'comment-id', reason: 'link farm' })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export class ModerationSubmodule {
|
|
18
|
+
constructor(ctx) {
|
|
19
|
+
this.ctx = ctx;
|
|
20
|
+
}
|
|
21
|
+
act(action, params) {
|
|
22
|
+
return this.ctx.http.post(`/comments/${seg(params.id)}:${action}`, {
|
|
23
|
+
reason: params.reason,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Publishes a pending comment, or one hidden by reports. */
|
|
27
|
+
approve(params) {
|
|
28
|
+
return this.act('approve', params);
|
|
29
|
+
}
|
|
30
|
+
/** Takes a comment down; its author sees it with the reason. */
|
|
31
|
+
remove(params) {
|
|
32
|
+
return this.act('remove', params);
|
|
33
|
+
}
|
|
34
|
+
/** Publishes a removed, hidden or spam comment again. */
|
|
35
|
+
restore(params) {
|
|
36
|
+
return this.act('restore', params);
|
|
37
|
+
}
|
|
38
|
+
/** Takes a comment down as spam, without telling its author. */
|
|
39
|
+
spam(params) {
|
|
40
|
+
return this.act('spam', params);
|
|
41
|
+
}
|
|
42
|
+
/** Pins a top-level comment on its thread. */
|
|
43
|
+
pin(params) {
|
|
44
|
+
return this.act('pin', params);
|
|
45
|
+
}
|
|
46
|
+
unpin(params) {
|
|
47
|
+
return this.act('unpin', params);
|
|
48
|
+
}
|
|
49
|
+
/** Accepts an answer as its Q&A thread's accepted answer, in place of the one before. */
|
|
50
|
+
accept(params) {
|
|
51
|
+
return this.act('accept', params);
|
|
52
|
+
}
|
|
53
|
+
unaccept(params) {
|
|
54
|
+
return this.act('unaccept', params);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Comments waiting for a decision on the types the user moderates. Filter
|
|
58
|
+
* on `type_id`, `thread_id`, `status`; `count` is the total across pages.
|
|
59
|
+
*/
|
|
60
|
+
async queue(params = {}) {
|
|
61
|
+
return this.ctx.http.get(`/comments/moderation/queue${query({}, listPairs(params))}`);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The moderation log of the types the user moderates. Filter on
|
|
65
|
+
* `thread_id`, `target_id`, `action`, `actor_id`.
|
|
66
|
+
*/
|
|
67
|
+
async log(params = {}) {
|
|
68
|
+
return this.ctx.http.get(`/comments/modlog${query({}, listPairs(params))}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=moderation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moderation.js","sourceRoot":"","sources":["../src/moderation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,IAAI,KAAK,EAAE,WAAW,IAAI,GAAG,EAAE,MAAM,aAAa,CAAA;AAGhF;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,mBAAmB;IAC9B,YAA6B,GAAiB;QAAjB,QAAG,GAAH,GAAG,CAAc;IAAG,CAAC;IAE1C,GAAG,CAAC,MAAc,EAAE,MAAoB;QAC9C,OAAO,IAAI,C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AAE,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAC5D,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAG,CAAC,SAAoB,EAAE;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CACtB,mBAAmB,KAAK,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAClD,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { Comment, CommentsList, CreateThreadParams, IdParams, ListMembersParams, ListThreadsParams, MarkReadParams, MemberPage, PostActivityParams, ReasonParams, RemoveMemberParams, SetMemberParams, SetThreadStateParams, SubscribeParams, Thread, ThreadMember, ThreadStats, ThreadStatsParams, UpdateThreadSubjectParams } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Manages threads: the discussion attached to a subject (a product, an
|
|
5
|
+
* article, a document) for one comment type.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const thread = await oblax.comments.threads.create({
|
|
10
|
+
* type: 'product-reviews',
|
|
11
|
+
* subjectType: 'product',
|
|
12
|
+
* subjectId: 'sku-123',
|
|
13
|
+
* title: 'Blue mug',
|
|
14
|
+
* url: '/products/blue-mug',
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* // Comment counts for a product grid
|
|
18
|
+
* const { data } = await oblax.comments.threads.stats({
|
|
19
|
+
* type: 'product-reviews',
|
|
20
|
+
* subjectType: 'product',
|
|
21
|
+
* subjectIds: ['sku-123', 'sku-456'],
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* await oblax.comments.threads.subscribe({ id: thread.id, mode: 'follow' })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class ThreadsSubmodule {
|
|
28
|
+
private readonly ctx;
|
|
29
|
+
constructor(ctx: OblaxContext);
|
|
30
|
+
/** Returns the subject's threads, of every comment type, that the user can read. */
|
|
31
|
+
listBySubject(params: ListThreadsParams): Promise<CommentsList<Thread>>;
|
|
32
|
+
get(params: IdParams): Promise<Thread>;
|
|
33
|
+
/**
|
|
34
|
+
* Makes the subject's thread, or returns the existing one. App admins
|
|
35
|
+
* create (or update) a thread of any type; other users create one of a
|
|
36
|
+
* `client` type and become its subject owner.
|
|
37
|
+
*/
|
|
38
|
+
create(params: CreateThreadParams): Promise<Thread>;
|
|
39
|
+
/** Returns the counters of one type's threads on up to 100 subjects. */
|
|
40
|
+
stats(params: ThreadStatsParams): Promise<CommentsList<ThreadStats>>;
|
|
41
|
+
/** Replaces the thread's subject snapshot (title, url, owner, extra). App admins only. */
|
|
42
|
+
updateSubject(params: UpdateThreadSubjectParams): Promise<void>;
|
|
43
|
+
/** Opens, locks, archives or hides a thread. Moderators only. */
|
|
44
|
+
setState(params: SetThreadStateParams): Promise<void>;
|
|
45
|
+
/** Marks an annotations thread resolved. Moderators and the subject owner. */
|
|
46
|
+
resolve(params: ReasonParams): Promise<Thread>;
|
|
47
|
+
/** Marks a resolved annotations thread not resolved any more. */
|
|
48
|
+
unresolve(params: ReasonParams): Promise<Thread>;
|
|
49
|
+
/** Follows or mutes the thread for the signed-in user. */
|
|
50
|
+
subscribe(params: SubscribeParams): Promise<Thread>;
|
|
51
|
+
/** Takes the user's follow or mute off the thread. */
|
|
52
|
+
unsubscribe(params: IdParams): Promise<Thread>;
|
|
53
|
+
/** Moves the user's read marker to a comment, or to the thread's last comment. */
|
|
54
|
+
markRead(params: MarkReadParams): Promise<Thread>;
|
|
55
|
+
/** Lists the thread's members. App admins only. */
|
|
56
|
+
listMembers(params: ListMembersParams): Promise<MemberPage>;
|
|
57
|
+
/** Puts a user on the thread's member list, or updates them. App admins only. */
|
|
58
|
+
setMember(params: SetMemberParams): Promise<ThreadMember>;
|
|
59
|
+
/** Takes a user off the thread's member list. App admins only. */
|
|
60
|
+
removeMember(params: RemoveMemberParams): Promise<void>;
|
|
61
|
+
/** Posts an activity entry (kind `system`, no author) on the thread. App admins only. */
|
|
62
|
+
postActivity(params: PostActivityParams): Promise<Comment>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=threads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threads.d.ts","sourceRoot":"","sources":["../src/threads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,MAAM,EACN,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY;IAE9C,oFAAoF;IAC9E,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAKvE,GAAG,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAI5C;;;;OAIG;IACG,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAczD,wEAAwE;IAClE,KAAK,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAQ1E,0FAA0F;IACpF,aAAa,CAAC,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IASrE,iEAAiE;IAC3D,QAAQ,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAA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