@notidotbot/noti-api-client 1.9.63 → 1.9.64

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.
@@ -0,0 +1,108 @@
1
+ import { CancelOutWebResponses } from '../types';
2
+ import { WebDataManager } from '../core/manager';
3
+ import type { SiteAnnouncementSeverity } from './announcements';
4
+ /**
5
+ * Site announcements - the developers' side. Every method is developer-only (403 otherwise) and NOT behind the
6
+ * `siteAnnouncements` flag, so announcements can be drafted before launch. Every write refreshes what the
7
+ * site shows.
8
+ *
9
+ * Publishing with `postToDiscord` posts it to the site-updates Discord webhook ONCE (only if the server has one
10
+ * configured); `postedToDiscordAt` says when.
11
+ */
12
+ export declare class APIAdminAnnouncements {
13
+ private web;
14
+ constructor(web: WebDataManager);
15
+ /** Every announcement, drafts and ended ones included, newest first. */
16
+ listAdminAnnouncements({ auth }: AdminAnnouncementsFunctionsInput['listAdminAnnouncements']): Promise<import("../types").WebResponse<{
17
+ announcements: AdminSiteAnnouncement[];
18
+ }>>;
19
+ /**
20
+ * Create an announcement. Rules checked on the server: in the feed, as a banner, or both; `linkUrl` and
21
+ * `linkLabel` together; `endsAt` after `startsAt`.
22
+ */
23
+ createAnnouncement({ auth, announcement }: AdminAnnouncementsFunctionsInput['createAnnouncement']): Promise<import("../types").WebResponse<AdminSiteAnnouncement>>;
24
+ /** Edit an announcement; send only what changes. The same rules apply to the result. */
25
+ updateAnnouncement({ auth, announcementId, announcement }: AdminAnnouncementsFunctionsInput['updateAnnouncement']): Promise<import("../types").WebResponse<AdminSiteAnnouncement>>;
26
+ /** Delete an announcement with its dismissals. */
27
+ deleteAnnouncement({ auth, announcementId }: AdminAnnouncementsFunctionsInput['deleteAnnouncement']): Promise<import("../types").WebResponse<{
28
+ announcementId: string;
29
+ }>>;
30
+ }
31
+ export type AdminAnnouncementsFunctionsInput = {
32
+ 'listAdminAnnouncements': {
33
+ auth: string;
34
+ };
35
+ 'createAnnouncement': {
36
+ auth: string;
37
+ announcement: SiteAnnouncementCreateInput;
38
+ };
39
+ 'updateAnnouncement': {
40
+ auth: string;
41
+ announcementId: string;
42
+ announcement: SiteAnnouncementUpdateInput;
43
+ };
44
+ 'deleteAnnouncement': {
45
+ auth: string;
46
+ announcementId: string;
47
+ };
48
+ };
49
+ export type AdminAnnouncementsGetReturnTypes = {
50
+ 'listAdminAnnouncementsRaw': Awaited<ReturnType<APIAdminAnnouncements['listAdminAnnouncements']>>;
51
+ 'listAdminAnnouncementsSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAdminAnnouncements['listAdminAnnouncements']>>>;
52
+ 'createAnnouncementRaw': Awaited<ReturnType<APIAdminAnnouncements['createAnnouncement']>>;
53
+ 'createAnnouncementSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAdminAnnouncements['createAnnouncement']>>>;
54
+ 'updateAnnouncementRaw': Awaited<ReturnType<APIAdminAnnouncements['updateAnnouncement']>>;
55
+ 'updateAnnouncementSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAdminAnnouncements['updateAnnouncement']>>>;
56
+ 'deleteAnnouncementRaw': Awaited<ReturnType<APIAdminAnnouncements['deleteAnnouncement']>>;
57
+ 'deleteAnnouncementSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAdminAnnouncements['deleteAnnouncement']>>>;
58
+ };
59
+ /** The developers' view of an announcement: every field, dates as ISO. */
60
+ export type AdminSiteAnnouncement = {
61
+ announcementId: string;
62
+ title: string;
63
+ body: string;
64
+ severity: SiteAnnouncementSeverity;
65
+ linkUrl: string | null;
66
+ linkLabel: string | null;
67
+ showInFeed: boolean;
68
+ showAsBanner: boolean;
69
+ dismissible: boolean;
70
+ pinned: boolean;
71
+ isPublished: boolean;
72
+ /** Published and inside its window right now. */
73
+ isActive: boolean;
74
+ startsAt: string | null;
75
+ endsAt: string | null;
76
+ postToDiscord: boolean;
77
+ postedToDiscordAt: string | null;
78
+ createdBy: string;
79
+ createdAt: string;
80
+ updatedAt: string;
81
+ };
82
+ /** Mirrors `SiteAnnouncementCreateSchema` in Noti-v3's `src/json/zod/site.zod.ts`. Defaults are the server's. */
83
+ export type SiteAnnouncementCreateInput = {
84
+ title: string;
85
+ /** Markdown. */
86
+ body: string;
87
+ /** Default `info`. */
88
+ severity?: SiteAnnouncementSeverity;
89
+ /** http(s) only; goes with `linkLabel`. */
90
+ linkUrl?: string | null;
91
+ linkLabel?: string | null;
92
+ /** Default true. */
93
+ showInFeed?: boolean;
94
+ /** Default false. */
95
+ showAsBanner?: boolean;
96
+ /** Default true. */
97
+ dismissible?: boolean;
98
+ /** Default false. */
99
+ pinned?: boolean;
100
+ /** Default false (draft). */
101
+ isPublished?: boolean;
102
+ startsAt?: Date | string | null;
103
+ endsAt?: Date | string | null;
104
+ /** Default false. */
105
+ postToDiscord?: boolean;
106
+ };
107
+ /** Mirrors `SiteAnnouncementUpdateSchema` in Noti-v3. */
108
+ export type SiteAnnouncementUpdateInput = Partial<SiteAnnouncementCreateInput>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APIAdminAnnouncements = void 0;
4
+ // Data.
5
+ /**
6
+ * Site announcements - the developers' side. Every method is developer-only (403 otherwise) and NOT behind the
7
+ * `siteAnnouncements` flag, so announcements can be drafted before launch. Every write refreshes what the
8
+ * site shows.
9
+ *
10
+ * Publishing with `postToDiscord` posts it to the site-updates Discord webhook ONCE (only if the server has one
11
+ * configured); `postedToDiscordAt` says when.
12
+ */
13
+ class APIAdminAnnouncements {
14
+ web;
15
+ constructor(web) {
16
+ this.web = web;
17
+ }
18
+ /** Every announcement, drafts and ended ones included, newest first. */
19
+ async listAdminAnnouncements({ auth }) {
20
+ return await this.web.request({
21
+ method: 'GET', auth,
22
+ endpoint: this.web.qp('/admin/announcements'),
23
+ });
24
+ }
25
+ /**
26
+ * Create an announcement. Rules checked on the server: in the feed, as a banner, or both; `linkUrl` and
27
+ * `linkLabel` together; `endsAt` after `startsAt`.
28
+ */
29
+ async createAnnouncement({ auth, announcement }) {
30
+ return await this.web.request({
31
+ method: 'POST', auth,
32
+ endpoint: this.web.qp('/admin/announcements'),
33
+ body: announcement,
34
+ });
35
+ }
36
+ /** Edit an announcement; send only what changes. The same rules apply to the result. */
37
+ async updateAnnouncement({ auth, announcementId, announcement }) {
38
+ return await this.web.request({
39
+ method: 'PATCH', auth,
40
+ endpoint: this.web.qp('/admin/announcements/' + announcementId),
41
+ body: announcement,
42
+ });
43
+ }
44
+ /** Delete an announcement with its dismissals. */
45
+ async deleteAnnouncement({ auth, announcementId }) {
46
+ return await this.web.request({
47
+ method: 'DELETE', auth,
48
+ endpoint: this.web.qp('/admin/announcements/' + announcementId),
49
+ });
50
+ }
51
+ }
52
+ exports.APIAdminAnnouncements = APIAdminAnnouncements;
@@ -0,0 +1,111 @@
1
+ import { CancelOutWebResponses } from '../types';
2
+ import { WebDataManager } from '../core/manager';
3
+ import type { SitePoll, SitePollResults, SitePollResultsVisibility } from './polls';
4
+ /**
5
+ * Site polls - the developers' side. Every method is developer-only (403 otherwise) and NOT behind the
6
+ * `sitePolls` flag, so polls can be drafted before launch.
7
+ *
8
+ * Publishing with `postToDiscord` posts the poll to the site-updates Discord webhook ONCE (only if the
9
+ * server has one configured); `postedToDiscordAt` says when. Unpublishing and publishing again never posts twice.
10
+ */
11
+ export declare class APIAdminPolls {
12
+ private web;
13
+ constructor(web: WebDataManager);
14
+ /** Every poll, drafts included, newest first, with full counts. */
15
+ listAdminPolls({ auth }: AdminPollsFunctionsInput['listAdminPolls']): Promise<import("../types").WebResponse<{
16
+ polls: AdminSitePoll[];
17
+ }>>;
18
+ /** Create a poll with 2 to 20 options. `maxChoices` cannot exceed the option count; `closesAt` must follow `opensAt`. */
19
+ createPoll({ auth, poll }: AdminPollsFunctionsInput['createPoll']): Promise<import("../types").WebResponse<AdminSitePoll>>;
20
+ /**
21
+ * Edit a poll; send only what changes. `options` REPLACES the list: send an existing option's `optionId`
22
+ * to keep it (and its votes). Removing an option that has votes is
23
+ * `{ status: 409, error: { code: 'option_has_votes', optionIds } }` unless `force: true`, which deletes them.
24
+ */
25
+ updatePoll({ auth, pollId, poll }: AdminPollsFunctionsInput['updatePoll']): Promise<import("../types").WebResponse<AdminSitePoll>>;
26
+ /** Delete a poll with its options and votes. */
27
+ deletePoll({ auth, pollId }: AdminPollsFunctionsInput['deletePoll']): Promise<import("../types").WebResponse<{
28
+ pollId: string;
29
+ }>>;
30
+ /** Full counts, whatever the poll's `resultsVisibility`. */
31
+ getPollResults({ auth, pollId }: AdminPollsFunctionsInput['getPollResults']): Promise<import("../types").WebResponse<SitePollResults>>;
32
+ }
33
+ export type AdminPollsFunctionsInput = {
34
+ 'listAdminPolls': {
35
+ auth: string;
36
+ };
37
+ 'createPoll': {
38
+ auth: string;
39
+ poll: SitePollCreateInput;
40
+ };
41
+ 'updatePoll': {
42
+ auth: string;
43
+ pollId: string;
44
+ poll: SitePollUpdateInput;
45
+ };
46
+ 'deletePoll': {
47
+ auth: string;
48
+ pollId: string;
49
+ };
50
+ 'getPollResults': {
51
+ auth: string;
52
+ pollId: string;
53
+ };
54
+ };
55
+ export type AdminPollsGetReturnTypes = {
56
+ 'listAdminPollsRaw': Awaited<ReturnType<APIAdminPolls['listAdminPolls']>>;
57
+ 'listAdminPollsSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAdminPolls['listAdminPolls']>>>;
58
+ 'createPollRaw': Awaited<ReturnType<APIAdminPolls['createPoll']>>;
59
+ 'createPollSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAdminPolls['createPoll']>>>;
60
+ 'updatePollRaw': Awaited<ReturnType<APIAdminPolls['updatePoll']>>;
61
+ 'updatePollSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAdminPolls['updatePoll']>>>;
62
+ 'deletePollRaw': Awaited<ReturnType<APIAdminPolls['deletePoll']>>;
63
+ 'deletePollSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAdminPolls['deletePoll']>>>;
64
+ 'getPollResultsRaw': Awaited<ReturnType<APIAdminPolls['getPollResults']>>;
65
+ 'getPollResultsSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAdminPolls['getPollResults']>>>;
66
+ };
67
+ /** The developers' view of a poll: the public poll plus everything the public never sees. */
68
+ export type AdminSitePoll = SitePoll & {
69
+ isPublished: boolean;
70
+ postToDiscord: boolean;
71
+ /** ISO; null until it has been posted. */
72
+ postedToDiscordAt: string | null;
73
+ /** Discord id of the developer who made it. */
74
+ createdBy: string;
75
+ /** ISO. */
76
+ createdAt: string;
77
+ /** ISO. */
78
+ updatedAt: string;
79
+ results: SitePollResults;
80
+ };
81
+ /** Mirrors `SitePollCreateSchema` in Noti-v3's `src/json/zod/site.zod.ts`. Defaults are the server's. */
82
+ export type SitePollCreateInput = {
83
+ title: string;
84
+ description?: string | null;
85
+ /** Default 1 (single choice). */
86
+ maxChoices?: number;
87
+ /** Default false. */
88
+ allowVoteChange?: boolean;
89
+ /** Default `afterVote`. */
90
+ resultsVisibility?: SitePollResultsVisibility;
91
+ /** Default false (draft). */
92
+ isPublished?: boolean;
93
+ opensAt?: Date | string | null;
94
+ closesAt?: Date | string | null;
95
+ /** Default false. */
96
+ postToDiscord?: boolean;
97
+ options: Array<{
98
+ label: string;
99
+ description?: string | null;
100
+ }>;
101
+ };
102
+ /** Mirrors `SitePollUpdateSchema` in Noti-v3. */
103
+ export type SitePollUpdateInput = Partial<Omit<SitePollCreateInput, 'options'>> & {
104
+ options?: Array<{
105
+ optionId?: string;
106
+ label: string;
107
+ description?: string | null;
108
+ }>;
109
+ /** Allow removing options that have votes (their votes are deleted). */
110
+ force?: boolean;
111
+ };
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APIAdminPolls = void 0;
4
+ // Data.
5
+ /**
6
+ * Site polls - the developers' side. Every method is developer-only (403 otherwise) and NOT behind the
7
+ * `sitePolls` flag, so polls can be drafted before launch.
8
+ *
9
+ * Publishing with `postToDiscord` posts the poll to the site-updates Discord webhook ONCE (only if the
10
+ * server has one configured); `postedToDiscordAt` says when. Unpublishing and publishing again never posts twice.
11
+ */
12
+ class APIAdminPolls {
13
+ web;
14
+ constructor(web) {
15
+ this.web = web;
16
+ }
17
+ /** Every poll, drafts included, newest first, with full counts. */
18
+ async listAdminPolls({ auth }) {
19
+ return await this.web.request({
20
+ method: 'GET', auth,
21
+ endpoint: this.web.qp('/admin/polls'),
22
+ });
23
+ }
24
+ /** Create a poll with 2 to 20 options. `maxChoices` cannot exceed the option count; `closesAt` must follow `opensAt`. */
25
+ async createPoll({ auth, poll }) {
26
+ return await this.web.request({
27
+ method: 'POST', auth,
28
+ endpoint: this.web.qp('/admin/polls'),
29
+ body: poll,
30
+ });
31
+ }
32
+ /**
33
+ * Edit a poll; send only what changes. `options` REPLACES the list: send an existing option's `optionId`
34
+ * to keep it (and its votes). Removing an option that has votes is
35
+ * `{ status: 409, error: { code: 'option_has_votes', optionIds } }` unless `force: true`, which deletes them.
36
+ */
37
+ async updatePoll({ auth, pollId, poll }) {
38
+ return await this.web.request({
39
+ method: 'PATCH', auth,
40
+ endpoint: this.web.qp('/admin/polls/' + pollId),
41
+ body: poll,
42
+ });
43
+ }
44
+ /** Delete a poll with its options and votes. */
45
+ async deletePoll({ auth, pollId }) {
46
+ return await this.web.request({
47
+ method: 'DELETE', auth,
48
+ endpoint: this.web.qp('/admin/polls/' + pollId),
49
+ });
50
+ }
51
+ /** Full counts, whatever the poll's `resultsVisibility`. */
52
+ async getPollResults({ auth, pollId }) {
53
+ return await this.web.request({
54
+ method: 'GET', auth,
55
+ endpoint: this.web.qp('/admin/polls/' + pollId + '/results'),
56
+ });
57
+ }
58
+ }
59
+ exports.APIAdminPolls = APIAdminPolls;
@@ -0,0 +1,68 @@
1
+ import { CancelOutWebResponses } from '../types';
2
+ import { WebDataManager } from '../core/manager';
3
+ /**
4
+ * Site announcements - developer-posted announcements the dashboard shows, in a feed and/or as a banner.
5
+ *
6
+ * `listAnnouncements` needs no session; the rest need a logged-in user (`auth`). Behind the
7
+ * `siteAnnouncements` launch flag: while it is hidden for the caller the lists are EMPTY (not 403) and a
8
+ * dismissal 404s.
9
+ *
10
+ * Only announcements showing NOW are returned: published, and inside their start/end window. One
11
+ * announcement can be in both `feed` and `banners`. Pinned first, then newest. `body` is markdown.
12
+ */
13
+ export declare class APIAnnouncements {
14
+ private web;
15
+ constructor(web: WebDataManager);
16
+ /** What is showing now: `{ feed, banners }`. No session. */
17
+ listAnnouncements(): Promise<import("../types").WebResponse<SiteAnnouncementList>>;
18
+ /** The showing, dismissible announcements the logged-in user has dismissed - hide those banners. */
19
+ getAnnouncementDismissals({ auth }: AnnouncementsFunctionsInput['getAnnouncementDismissals']): Promise<import("../types").WebResponse<{
20
+ dismissedIds: string[];
21
+ }>>;
22
+ /**
23
+ * Dismiss a banner for the logged-in user (remembered across devices). Dismissing twice is fine.
24
+ * `{ status: 400, error: { code: 'not_dismissible' } }` when it cannot be dismissed; 30/minute.
25
+ */
26
+ createAnnouncementDismissal({ auth, announcementId }: AnnouncementsFunctionsInput['createAnnouncementDismissal']): Promise<import("../types").WebResponse<{
27
+ announcementId: string;
28
+ dismissed: true;
29
+ }>>;
30
+ }
31
+ export type AnnouncementsFunctionsInput = {
32
+ 'getAnnouncementDismissals': {
33
+ auth: string;
34
+ };
35
+ 'createAnnouncementDismissal': {
36
+ auth: string;
37
+ announcementId: string;
38
+ };
39
+ };
40
+ export type AnnouncementsGetReturnTypes = {
41
+ 'listAnnouncementsRaw': Awaited<ReturnType<APIAnnouncements['listAnnouncements']>>;
42
+ 'listAnnouncementsSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAnnouncements['listAnnouncements']>>>;
43
+ 'getAnnouncementDismissalsRaw': Awaited<ReturnType<APIAnnouncements['getAnnouncementDismissals']>>;
44
+ 'getAnnouncementDismissalsSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAnnouncements['getAnnouncementDismissals']>>>;
45
+ 'createAnnouncementDismissalRaw': Awaited<ReturnType<APIAnnouncements['createAnnouncementDismissal']>>;
46
+ 'createAnnouncementDismissalSuccess': CancelOutWebResponses<Awaited<ReturnType<APIAnnouncements['createAnnouncementDismissal']>>>;
47
+ };
48
+ export type SiteAnnouncementSeverity = 'info' | 'success' | 'warning' | 'critical';
49
+ /** One announcement as the site shows it. Mirrors `SiteAnnouncementCard` in Noti-v3. */
50
+ export type SiteAnnouncement = {
51
+ announcementId: string;
52
+ title: string;
53
+ /** Markdown. */
54
+ body: string;
55
+ severity: SiteAnnouncementSeverity;
56
+ linkUrl: string | null;
57
+ linkLabel: string | null;
58
+ dismissible: boolean;
59
+ pinned: boolean;
60
+ /** ISO. */
61
+ startsAt: string | null;
62
+ /** ISO. */
63
+ endsAt: string | null;
64
+ };
65
+ export type SiteAnnouncementList = {
66
+ feed: SiteAnnouncement[];
67
+ banners: SiteAnnouncement[];
68
+ };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APIAnnouncements = void 0;
4
+ // Data.
5
+ /**
6
+ * Site announcements - developer-posted announcements the dashboard shows, in a feed and/or as a banner.
7
+ *
8
+ * `listAnnouncements` needs no session; the rest need a logged-in user (`auth`). Behind the
9
+ * `siteAnnouncements` launch flag: while it is hidden for the caller the lists are EMPTY (not 403) and a
10
+ * dismissal 404s.
11
+ *
12
+ * Only announcements showing NOW are returned: published, and inside their start/end window. One
13
+ * announcement can be in both `feed` and `banners`. Pinned first, then newest. `body` is markdown.
14
+ */
15
+ class APIAnnouncements {
16
+ web;
17
+ constructor(web) {
18
+ this.web = web;
19
+ }
20
+ /** What is showing now: `{ feed, banners }`. No session. */
21
+ async listAnnouncements() {
22
+ return await this.web.request({
23
+ method: 'GET',
24
+ endpoint: this.web.qp('/public/announcements'),
25
+ });
26
+ }
27
+ /** The showing, dismissible announcements the logged-in user has dismissed - hide those banners. */
28
+ async getAnnouncementDismissals({ auth }) {
29
+ return await this.web.request({
30
+ method: 'GET', auth,
31
+ endpoint: this.web.qp('/public/announcements/@me'),
32
+ });
33
+ }
34
+ /**
35
+ * Dismiss a banner for the logged-in user (remembered across devices). Dismissing twice is fine.
36
+ * `{ status: 400, error: { code: 'not_dismissible' } }` when it cannot be dismissed; 30/minute.
37
+ */
38
+ async createAnnouncementDismissal({ auth, announcementId }) {
39
+ return await this.web.request({
40
+ method: 'PUT', auth,
41
+ endpoint: this.web.qp('/public/announcements/' + announcementId + '/dismissals/@me'),
42
+ });
43
+ }
44
+ }
45
+ exports.APIAnnouncements = APIAnnouncements;