@haatlabs-core/announcements 0.27.0 → 0.27.2

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.
Files changed (55) hide show
  1. package/dist/audience.d.ts +39 -0
  2. package/dist/audience.js +24 -0
  3. package/dist/audience.js.map +1 -0
  4. package/dist/cjs/audience.d.ts +39 -0
  5. package/dist/cjs/audience.js +44 -0
  6. package/dist/cjs/index.d.ts +3 -1
  7. package/dist/cjs/index.js +3 -0
  8. package/dist/cjs/nest/admin.controller.d.ts +9 -7
  9. package/dist/cjs/nest/admin.controller.js +25 -21
  10. package/dist/cjs/nest/admin.guard.d.ts +8 -0
  11. package/dist/cjs/nest/admin.guard.js +52 -0
  12. package/dist/cjs/nest/context.d.ts +2 -0
  13. package/dist/cjs/nest/context.js +28 -0
  14. package/dist/cjs/nest/index.d.ts +5 -3
  15. package/dist/cjs/nest/index.js +7 -1
  16. package/dist/cjs/nest/options.d.ts +27 -6
  17. package/dist/cjs/nest/options.js +3 -0
  18. package/dist/cjs/nest/status.controller.d.ts +7 -7
  19. package/dist/cjs/nest/status.controller.js +19 -9
  20. package/dist/cjs/nest-auth/index.d.ts +8 -0
  21. package/dist/cjs/nest-auth/index.js +40 -0
  22. package/dist/cjs/notify.d.ts +28 -11
  23. package/dist/cjs/targeting.d.ts +2 -1
  24. package/dist/cjs/targeting.js +1 -1
  25. package/dist/index.d.ts +3 -1
  26. package/dist/index.js +1 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/nest/admin.controller.d.ts +9 -7
  29. package/dist/nest/admin.controller.js +26 -22
  30. package/dist/nest/admin.controller.js.map +1 -1
  31. package/dist/nest/admin.guard.d.ts +8 -0
  32. package/dist/nest/admin.guard.js +27 -0
  33. package/dist/nest/admin.guard.js.map +1 -0
  34. package/dist/nest/context.d.ts +2 -0
  35. package/dist/nest/context.js +4 -0
  36. package/dist/nest/context.js.map +1 -0
  37. package/dist/nest/index.d.ts +5 -3
  38. package/dist/nest/index.js +9 -4
  39. package/dist/nest/index.js.map +1 -1
  40. package/dist/nest/options.d.ts +27 -6
  41. package/dist/nest/options.js +1 -0
  42. package/dist/nest/options.js.map +1 -1
  43. package/dist/nest/status.controller.d.ts +7 -7
  44. package/dist/nest/status.controller.js +20 -10
  45. package/dist/nest/status.controller.js.map +1 -1
  46. package/dist/nest-auth/index.d.ts +8 -0
  47. package/dist/nest-auth/index.js +21 -0
  48. package/dist/nest-auth/index.js.map +1 -0
  49. package/dist/notify.d.ts +28 -11
  50. package/dist/notify.js +0 -6
  51. package/dist/notify.js.map +1 -1
  52. package/dist/targeting.d.ts +2 -1
  53. package/dist/targeting.js +2 -1
  54. package/dist/targeting.js.map +1 -1
  55. package/package.json +26 -11
@@ -0,0 +1,39 @@
1
+ import type { Platform } from './contracts/index.js';
2
+ /**
3
+ * One organization as targeting sees it. `planCode` is null for an app without plans: such
4
+ * an organization sees what is for everyone, and nothing aimed at a plan.
5
+ */
6
+ export interface AudienceOrganization {
7
+ id: string;
8
+ planCode: string | null;
9
+ platforms: Platform[];
10
+ /** ISO-3166 alpha-2, or null when nothing says. */
11
+ country: string | null;
12
+ }
13
+ /**
14
+ * Who announcements can reach: the adapter the app wires. nest-billing's `SystemAudience`
15
+ * is one (plans, platforms, countries); `everyoneAudience` is one for an app without billing.
16
+ */
17
+ export interface Audience {
18
+ /** A signed-in caller's organization, for its alert bar; null when unknown. */
19
+ of(organizationId: string): Promise<AudienceOrganization | null>;
20
+ /** Every organization a notify may reach, by id, a page at a time. */
21
+ page(after: string | null, limit: number): Promise<{
22
+ items: AudienceOrganization[];
23
+ nextAfter: string | null;
24
+ }>;
25
+ /** The user ids of an organization's people. */
26
+ members(organizationId: string): Promise<string[]>;
27
+ }
28
+ /**
29
+ * An audience for an app without plans: every organization is on no plan, platform or
30
+ * country, so it receives what is for everyone. Without `organizations` and `members` it
31
+ * serves the alert bar alone (a notify reaches nobody).
32
+ */
33
+ export declare function everyoneAudience(source?: {
34
+ organizations?(after: string | null, limit: number): Promise<{
35
+ ids: string[];
36
+ nextAfter: string | null;
37
+ }>;
38
+ members?(organizationId: string): Promise<string[]>;
39
+ }): Audience;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * An audience for an app without plans: every organization is on no plan, platform or
3
+ * country, so it receives what is for everyone. Without `organizations` and `members` it
4
+ * serves the alert bar alone (a notify reaches nobody).
5
+ */
6
+ export function everyoneAudience(source = {}) {
7
+ const plain = (id) => ({
8
+ id,
9
+ planCode: null,
10
+ platforms: [],
11
+ country: null,
12
+ });
13
+ return {
14
+ of: async (id) => plain(id),
15
+ page: async (after, limit) => {
16
+ if (!source.organizations)
17
+ return { items: [], nextAfter: null };
18
+ const { ids, nextAfter } = await source.organizations(after, limit);
19
+ return { items: ids.map(plain), nextAfter };
20
+ },
21
+ members: async (id) => (source.members ? source.members(id) : []),
22
+ };
23
+ }
24
+ //# sourceMappingURL=audience.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audience.js","sourceRoot":"","sources":["../src/audience.ts"],"names":[],"mappings":"AA8BA;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAMI,EAAE;IAEN,MAAM,KAAK,GAAG,CAAC,EAAU,EAAwB,EAAE,CAAC,CAAC;QACnD,EAAE;QACF,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IACH,OAAO;QACL,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YAC3B,IAAI,CAAC,MAAM,CAAC,aAAa;gBAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YACjE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YACpE,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;QAC9C,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAClE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { Platform } from './contracts/index.js';
2
+ /**
3
+ * One organization as targeting sees it. `planCode` is null for an app without plans: such
4
+ * an organization sees what is for everyone, and nothing aimed at a plan.
5
+ */
6
+ export interface AudienceOrganization {
7
+ id: string;
8
+ planCode: string | null;
9
+ platforms: Platform[];
10
+ /** ISO-3166 alpha-2, or null when nothing says. */
11
+ country: string | null;
12
+ }
13
+ /**
14
+ * Who announcements can reach: the adapter the app wires. nest-billing's `SystemAudience`
15
+ * is one (plans, platforms, countries); `everyoneAudience` is one for an app without billing.
16
+ */
17
+ export interface Audience {
18
+ /** A signed-in caller's organization, for its alert bar; null when unknown. */
19
+ of(organizationId: string): Promise<AudienceOrganization | null>;
20
+ /** Every organization a notify may reach, by id, a page at a time. */
21
+ page(after: string | null, limit: number): Promise<{
22
+ items: AudienceOrganization[];
23
+ nextAfter: string | null;
24
+ }>;
25
+ /** The user ids of an organization's people. */
26
+ members(organizationId: string): Promise<string[]>;
27
+ }
28
+ /**
29
+ * An audience for an app without plans: every organization is on no plan, platform or
30
+ * country, so it receives what is for everyone. Without `organizations` and `members` it
31
+ * serves the alert bar alone (a notify reaches nobody).
32
+ */
33
+ export declare function everyoneAudience(source?: {
34
+ organizations?(after: string | null, limit: number): Promise<{
35
+ ids: string[];
36
+ nextAfter: string | null;
37
+ }>;
38
+ members?(organizationId: string): Promise<string[]>;
39
+ }): Audience;
@@ -0,0 +1,44 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var audience_exports = {};
19
+ __export(audience_exports, {
20
+ everyoneAudience: () => everyoneAudience
21
+ });
22
+ module.exports = __toCommonJS(audience_exports);
23
+ function everyoneAudience(source = {}) {
24
+ const plain = (id) => ({
25
+ id,
26
+ planCode: null,
27
+ platforms: [],
28
+ country: null
29
+ });
30
+ return {
31
+ of: async (id) => plain(id),
32
+ page: async (after, limit) => {
33
+ if (!source.organizations)
34
+ return { items: [], nextAfter: null };
35
+ const { ids, nextAfter } = await source.organizations(after, limit);
36
+ return { items: ids.map(plain), nextAfter };
37
+ },
38
+ members: async (id) => source.members ? source.members(id) : []
39
+ };
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ everyoneAudience
44
+ });
@@ -1,4 +1,6 @@
1
1
  export * from './contracts/index.js';
2
+ export { everyoneAudience } from './audience.js';
3
+ export type { Audience, AudienceOrganization } from './audience.js';
2
4
  export { ANNOUNCEMENT_ERROR_DEFINITIONS, announcementErrors } from './errors.js';
3
5
  export type { AnnouncementErrorCode } from './errors.js';
4
6
  export { AnnouncementRepository } from './repository.js';
@@ -7,4 +9,4 @@ export { STALE_TTL_SECONDS, STATUS_TTL_SECONDS, StatusCache, statusKeys } from '
7
9
  export { activeMaintenance, matches, statusFor } from './targeting.js';
8
10
  export type { Viewer } from './targeting.js';
9
11
  export { NOTIFY_EVERY_MS, announcementData, announcementEvent, sendDueAnnouncements, startAnnouncementNotify, } from './notify.js';
10
- export type { AnnouncementNotificationData, AnnouncementNotify, AnnouncementNotifyDeps, NotifyAudience, } from './notify.js';
12
+ export type { AnnouncementEventDef, AnnouncementNotificationData, AnnouncementNotify, AnnouncementNotifyDeps, NotifyAudience, } from './notify.js';
package/dist/cjs/index.js CHANGED
@@ -28,6 +28,7 @@ __export(index_exports, {
28
28
  announcementData: () => import_notify.announcementData,
29
29
  announcementErrors: () => import_errors.announcementErrors,
30
30
  announcementEvent: () => import_notify.announcementEvent,
31
+ everyoneAudience: () => import_audience.everyoneAudience,
31
32
  matches: () => import_targeting.matches,
32
33
  sendDueAnnouncements: () => import_notify.sendDueAnnouncements,
33
34
  startAnnouncementNotify: () => import_notify.startAnnouncementNotify,
@@ -36,6 +37,7 @@ __export(index_exports, {
36
37
  });
37
38
  module.exports = __toCommonJS(index_exports);
38
39
  __reExport(index_exports, require("./contracts/index.js"), module.exports);
40
+ var import_audience = require("./audience.js");
39
41
  var import_errors = require("./errors.js");
40
42
  var import_repository = require("./repository.js");
41
43
  var import_status_cache = require("./status-cache.js");
@@ -53,6 +55,7 @@ var import_notify = require("./notify.js");
53
55
  announcementData,
54
56
  announcementErrors,
55
57
  announcementEvent,
58
+ everyoneAudience,
56
59
  matches,
57
60
  sendDueAnnouncements,
58
61
  startAnnouncementNotify,
@@ -1,7 +1,8 @@
1
- import type { AdminPrincipal } from '@haatlabs-core/nest-auth/admin';
1
+ import type { ExecutionContext } from '@nestjs/common';
2
2
  import type { AnnouncementInput, AnnouncementView, MaintenanceInput, MaintenanceView, Page } from '../contracts/index.js';
3
3
  import type { AnnouncementRepository } from '../repository.js';
4
4
  import type { StatusCache } from '../status-cache.js';
5
+ import type { AnnouncementsAuth } from './options.js';
5
6
  /**
6
7
  * Announcements and maintenance, for platform administrators only. Bodies are checked by
7
8
  * the repository, which refuses with codes the admin screen explains. Every write clears
@@ -10,18 +11,19 @@ import type { StatusCache } from '../status-cache.js';
10
11
  export declare class AnnouncementsAdminController {
11
12
  private readonly repo;
12
13
  private readonly cache;
13
- constructor(repo: AnnouncementRepository, cache: StatusCache);
14
+ private readonly auth;
15
+ constructor(repo: AnnouncementRepository, cache: StatusCache, auth: AnnouncementsAuth);
14
16
  list(includeEnded?: string, limit?: string, offset?: string): Promise<Page<AnnouncementView>>;
15
- create(admin: AdminPrincipal, body: AnnouncementInput): Promise<AnnouncementView>;
17
+ create(context: ExecutionContext, body: AnnouncementInput): Promise<AnnouncementView>;
16
18
  /** A full replacement: the screen sends the whole form. */
17
- update(admin: AdminPrincipal, id: string, body: AnnouncementInput): Promise<AnnouncementView>;
18
- cancel(admin: AdminPrincipal, id: string): Promise<{
19
+ update(context: ExecutionContext, id: string, body: AnnouncementInput): Promise<AnnouncementView>;
20
+ cancel(context: ExecutionContext, id: string): Promise<{
19
21
  ok: true;
20
22
  }>;
21
23
  maintenance(limit?: string, offset?: string): Promise<Page<MaintenanceView>>;
22
- schedule(admin: AdminPrincipal, body: MaintenanceInput): Promise<MaintenanceView>;
24
+ schedule(context: ExecutionContext, body: MaintenanceInput): Promise<MaintenanceView>;
23
25
  /** "End now": ends an open window, or cancels a scheduled one. */
24
- end(admin: AdminPrincipal, id: string): Promise<{
26
+ end(context: ExecutionContext, id: string): Promise<{
25
27
  ok: true;
26
28
  }>;
27
29
  }
@@ -21,8 +21,9 @@ __export(admin_controller_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(admin_controller_exports);
23
23
  var import_common = require("@nestjs/common");
24
- var import_nest_auth = require("@haatlabs-core/nest-auth");
25
- var import_admin = require("@haatlabs-core/nest-auth/admin");
24
+ var import_nest_common = require("@haatlabs-core/nest-common");
25
+ var import_admin_guard = require("./admin.guard.js");
26
+ var import_context = require("./context.js");
26
27
  var import_options = require("./options.js");
27
28
  var __decorate = function(decorators, target, key, desc) {
28
29
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -44,9 +45,11 @@ const paging = (limit, offset) => ({
44
45
  let AnnouncementsAdminController = class AnnouncementsAdminController2 {
45
46
  repo;
46
47
  cache;
47
- constructor(repo, cache) {
48
+ auth;
49
+ constructor(repo, cache, auth) {
48
50
  this.repo = repo;
49
51
  this.cache = cache;
52
+ this.auth = auth;
50
53
  }
51
54
  list(includeEnded, limit, offset) {
52
55
  return this.repo.listAnnouncements({
@@ -54,33 +57,33 @@ let AnnouncementsAdminController = class AnnouncementsAdminController2 {
54
57
  ...paging(limit, offset)
55
58
  });
56
59
  }
57
- async create(admin, body) {
58
- const view = await this.repo.createAnnouncement(admin.id, body);
60
+ async create(context, body) {
61
+ const view = await this.repo.createAnnouncement(this.auth.adminIdOf(context), body);
59
62
  await this.cache.invalidate();
60
63
  return view;
61
64
  }
62
65
  /** A full replacement: the screen sends the whole form. */
63
- async update(admin, id, body) {
64
- const view = await this.repo.updateAnnouncement(admin.id, id, body);
66
+ async update(context, id, body) {
67
+ const view = await this.repo.updateAnnouncement(this.auth.adminIdOf(context), id, body);
65
68
  await this.cache.invalidate();
66
69
  return view;
67
70
  }
68
- async cancel(admin, id) {
69
- await this.repo.cancelAnnouncement(admin.id, id);
71
+ async cancel(context, id) {
72
+ await this.repo.cancelAnnouncement(this.auth.adminIdOf(context), id);
70
73
  await this.cache.invalidate();
71
74
  return { ok: true };
72
75
  }
73
76
  maintenance(limit, offset) {
74
77
  return this.repo.listMaintenance(paging(limit, offset));
75
78
  }
76
- async schedule(admin, body) {
77
- const view = await this.repo.scheduleMaintenance(admin.id, body);
79
+ async schedule(context, body) {
80
+ const view = await this.repo.scheduleMaintenance(this.auth.adminIdOf(context), body);
78
81
  await this.cache.invalidate();
79
82
  return view;
80
83
  }
81
84
  /** "End now": ends an open window, or cancels a scheduled one. */
82
- async end(admin, id) {
83
- await this.repo.endMaintenance(admin.id, id);
85
+ async end(context, id) {
86
+ await this.repo.endMaintenance(this.auth.adminIdOf(context), id);
84
87
  await this.cache.invalidate();
85
88
  return { ok: true };
86
89
  }
@@ -93,19 +96,19 @@ __decorate([
93
96
  ], AnnouncementsAdminController.prototype, "list", null);
94
97
  __decorate([
95
98
  (0, import_common.Post)("announcements"),
96
- __param(0, (0, import_admin.CurrentAdmin)()),
99
+ __param(0, (0, import_context.CurrentContext)()),
97
100
  __param(1, (0, import_common.Body)())
98
101
  ], AnnouncementsAdminController.prototype, "create", null);
99
102
  __decorate([
100
103
  (0, import_common.Put)("announcements/:id"),
101
- __param(0, (0, import_admin.CurrentAdmin)()),
104
+ __param(0, (0, import_context.CurrentContext)()),
102
105
  __param(1, (0, import_common.Param)("id", import_common.ParseUUIDPipe)),
103
106
  __param(2, (0, import_common.Body)())
104
107
  ], AnnouncementsAdminController.prototype, "update", null);
105
108
  __decorate([
106
109
  (0, import_common.Post)("announcements/:id/cancel"),
107
110
  (0, import_common.HttpCode)(200),
108
- __param(0, (0, import_admin.CurrentAdmin)()),
111
+ __param(0, (0, import_context.CurrentContext)()),
109
112
  __param(1, (0, import_common.Param)("id", import_common.ParseUUIDPipe))
110
113
  ], AnnouncementsAdminController.prototype, "cancel", null);
111
114
  __decorate([
@@ -115,21 +118,22 @@ __decorate([
115
118
  ], AnnouncementsAdminController.prototype, "maintenance", null);
116
119
  __decorate([
117
120
  (0, import_common.Post)("maintenance"),
118
- __param(0, (0, import_admin.CurrentAdmin)()),
121
+ __param(0, (0, import_context.CurrentContext)()),
119
122
  __param(1, (0, import_common.Body)())
120
123
  ], AnnouncementsAdminController.prototype, "schedule", null);
121
124
  __decorate([
122
125
  (0, import_common.Post)("maintenance/:id/end"),
123
126
  (0, import_common.HttpCode)(200),
124
- __param(0, (0, import_admin.CurrentAdmin)()),
127
+ __param(0, (0, import_context.CurrentContext)()),
125
128
  __param(1, (0, import_common.Param)("id", import_common.ParseUUIDPipe))
126
129
  ], AnnouncementsAdminController.prototype, "end", null);
127
130
  AnnouncementsAdminController = __decorate([
128
- (0, import_nest_auth.Public)(),
131
+ (0, import_nest_common.Public)(),
129
132
  (0, import_common.Controller)("api/v1/admin"),
130
- (0, import_common.UseGuards)(import_admin.AdminGuard),
133
+ (0, import_common.UseGuards)(import_admin_guard.AdminOnly),
131
134
  __param(0, (0, import_common.Inject)(import_options.ANNOUNCEMENT_REPOSITORY)),
132
- __param(1, (0, import_common.Inject)(import_options.STATUS_CACHE))
135
+ __param(1, (0, import_common.Inject)(import_options.STATUS_CACHE)),
136
+ __param(2, (0, import_common.Inject)(import_options.ANNOUNCEMENTS_AUTH))
133
137
  ], AnnouncementsAdminController);
134
138
  // Annotate the CommonJS export names for ESM import in node:
135
139
  0 && (module.exports = {
@@ -0,0 +1,8 @@
1
+ import type { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import type { AnnouncementsAuth } from './options.js';
3
+ /** The administrators' routes: whoever the auth adapter says is one. */
4
+ export declare class AdminOnly implements CanActivate {
5
+ private readonly auth;
6
+ constructor(auth: AnnouncementsAuth);
7
+ canActivate(context: ExecutionContext): boolean | Promise<boolean>;
8
+ }
@@ -0,0 +1,52 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var admin_guard_exports = {};
19
+ __export(admin_guard_exports, {
20
+ AdminOnly: () => AdminOnly
21
+ });
22
+ module.exports = __toCommonJS(admin_guard_exports);
23
+ var import_common = require("@nestjs/common");
24
+ var import_options = require("./options.js");
25
+ var __decorate = function(decorators, target, key, desc) {
26
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
27
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
28
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
29
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
30
+ };
31
+ var __param = function(paramIndex, decorator) {
32
+ return function(target, key) {
33
+ decorator(target, key, paramIndex);
34
+ };
35
+ };
36
+ let AdminOnly = class AdminOnly2 {
37
+ auth;
38
+ constructor(auth) {
39
+ this.auth = auth;
40
+ }
41
+ canActivate(context) {
42
+ return this.auth.isAdmin(context);
43
+ }
44
+ };
45
+ AdminOnly = __decorate([
46
+ (0, import_common.Injectable)(),
47
+ __param(0, (0, import_common.Inject)(import_options.ANNOUNCEMENTS_AUTH))
48
+ ], AdminOnly);
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ AdminOnly
52
+ });
@@ -0,0 +1,2 @@
1
+ /** The request's context itself, for the auth adapter to read who is calling. */
2
+ export declare const CurrentContext: (...dataOrPipes: unknown[]) => ParameterDecorator;
@@ -0,0 +1,28 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var context_exports = {};
19
+ __export(context_exports, {
20
+ CurrentContext: () => CurrentContext
21
+ });
22
+ module.exports = __toCommonJS(context_exports);
23
+ var import_common = require("@nestjs/common");
24
+ const CurrentContext = (0, import_common.createParamDecorator)((_data, context) => context);
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ CurrentContext
28
+ });
@@ -3,11 +3,13 @@ import type { AnnouncementsModuleOptions } from './options.js';
3
3
  /**
4
4
  * Announcements and app-layer maintenance: `GET api/v1/status` (public) and
5
5
  * `GET api/v1/me/status`, the administrators' routes under `api/v1/admin/announcements` and
6
- * `api/v1/admin/maintenance`, and the maintenance gate on every other route. Needs
7
- * nest-auth's `AuthModule` and `AdminAuthModule`, and nest-common's `LOGGER`.
6
+ * `api/v1/admin/maintenance`, and the maintenance gate on every other route. Sign-in comes
7
+ * from the `auth` adapter (`@haatlabs-core/announcements/nest-auth` for the platform's own), who a
8
+ * caller's organization is from the optional `audience`; nest-common's `LOGGER` is needed.
8
9
  */
9
10
  export declare class AnnouncementsModule {
10
11
  static forRoot(options: AnnouncementsModuleOptions): DynamicModule;
11
12
  }
12
13
  export { DEFAULT_EXEMPT_PREFIXES, exemptPrefixesOf, isExempt } from './options.js';
13
- export type { AnnouncementsModuleOptions } from './options.js';
14
+ export type { AnnouncementsAuth, AnnouncementsModuleOptions, Provide } from './options.js';
15
+ export { AdminOnly } from './admin.guard.js';
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var nest_exports = {};
19
19
  __export(nest_exports, {
20
+ AdminOnly: () => import_admin_guard2.AdminOnly,
20
21
  AnnouncementsModule: () => AnnouncementsModule,
21
22
  DEFAULT_EXEMPT_PREFIXES: () => import_options2.DEFAULT_EXEMPT_PREFIXES,
22
23
  exemptPrefixesOf: () => import_options2.exemptPrefixesOf,
@@ -28,9 +29,11 @@ var import_nest_common = require("@haatlabs-core/nest-common");
28
29
  var import_status_cache = require("../status-cache.js");
29
30
  var import_admin_controller = require("./admin.controller.js");
30
31
  var import_maintenance_gate = require("./maintenance-gate.js");
32
+ var import_admin_guard = require("./admin.guard.js");
31
33
  var import_options = require("./options.js");
32
34
  var import_status_controller = require("./status.controller.js");
33
35
  var import_options2 = require("./options.js");
36
+ var import_admin_guard2 = require("./admin.guard.js");
34
37
  var __decorate = function(decorators, target, key, desc) {
35
38
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
36
39
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -55,7 +58,9 @@ let AnnouncementsModule = AnnouncementsModule_1 = class AnnouncementsModule2 {
55
58
  { provide: import_options.ANNOUNCEMENTS_OPTIONS, useValue: resolved },
56
59
  provide(import_options.ANNOUNCEMENT_REPOSITORY, options.repository),
57
60
  provide(import_options.ANNOUNCEMENTS_REDIS, options.redis),
58
- provide(import_options.ANNOUNCEMENTS_AUDIENCE, options.audience),
61
+ provide(import_options.ANNOUNCEMENTS_AUTH, options.auth),
62
+ ...options.audience ? [provide(import_options.ANNOUNCEMENTS_AUDIENCE, options.audience)] : [],
63
+ import_admin_guard.AdminOnly,
59
64
  {
60
65
  provide: import_options.STATUS_CACHE,
61
66
  useFactory: (repo, redis, logger) => new import_status_cache.StatusCache({
@@ -77,6 +82,7 @@ AnnouncementsModule = AnnouncementsModule_1 = __decorate([
77
82
  ], AnnouncementsModule);
78
83
  // Annotate the CommonJS export names for ESM import in node:
79
84
  0 && (module.exports = {
85
+ AdminOnly,
80
86
  AnnouncementsModule,
81
87
  DEFAULT_EXEMPT_PREFIXES,
82
88
  exemptPrefixesOf,
@@ -1,7 +1,24 @@
1
- import type { Provide } from '@haatlabs-core/nest-auth';
2
- import type { AudienceOrganization } from '@haatlabs-core/nest-billing';
1
+ import type { ExecutionContext, InjectionToken } from '@nestjs/common';
3
2
  import type { Redis } from 'ioredis';
3
+ import type { Audience } from '../audience.js';
4
4
  import type { AnnouncementRepository } from '../repository.js';
5
+ /** How a provider is made: a factory and what it is given, as Nest takes one. */
6
+ export interface Provide<T> {
7
+ useFactory: (...deps: any[]) => T | Promise<T>;
8
+ inject?: InjectionToken[];
9
+ }
10
+ /**
11
+ * Sign-in, as this package needs it: the adapter the app wires. `@haatlabs-core/announcements/nest-auth`
12
+ * is the one for the platform's own sign-in.
13
+ */
14
+ export interface AnnouncementsAuth {
15
+ /** Whether the request is a platform administrator's (throw to refuse with a reason). */
16
+ isAdmin(context: ExecutionContext): boolean | Promise<boolean>;
17
+ /** The administrator a request that passed `isAdmin` is from: who wrote it. */
18
+ adminIdOf(context: ExecutionContext): string;
19
+ /** The organization a signed-in caller acts for, or null when signed out. */
20
+ organizationOf(context: ExecutionContext): string | null;
21
+ }
5
22
  export interface AnnouncementsModuleOptions {
6
23
  /** The repository on the system connection. */
7
24
  repository: Provide<AnnouncementRepository>;
@@ -9,10 +26,13 @@ export interface AnnouncementsModuleOptions {
9
26
  redis: Provide<Redis>;
10
27
  /** The app's Redis key prefix. */
11
28
  keyPrefix: string;
12
- /** Who a signed-in caller's organization is, for targeting (nest-billing's `SystemAudience`). */
13
- audience: Provide<{
14
- of(organizationId: string): Promise<AudienceOrganization | null>;
15
- }>;
29
+ /** Who an administrator is, and which organization a caller acts for. */
30
+ auth: Provide<AnnouncementsAuth>;
31
+ /**
32
+ * Who a signed-in caller's organization is, for targeting (nest-billing's `SystemAudience`).
33
+ * Left out: every caller sees what is for everyone, as an app without plans would.
34
+ */
35
+ audience?: Provide<Pick<Audience, 'of'>>;
16
36
  /**
17
37
  * Paths maintenance never blocks besides the package's own (admin, status, webhooks,
18
38
  * health, metrics): Shopify's install, OAuth and billing callbacks, a provider gateway.
@@ -32,6 +52,7 @@ export declare const ANNOUNCEMENT_REPOSITORY: symbol;
32
52
  export declare const ANNOUNCEMENTS_REDIS: symbol;
33
53
  export declare const ANNOUNCEMENTS_AUDIENCE: symbol;
34
54
  export declare const STATUS_CACHE: symbol;
55
+ export declare const ANNOUNCEMENTS_AUTH: symbol;
35
56
  export interface ResolvedAnnouncementsOptions {
36
57
  keyPrefix: string;
37
58
  exemptPrefixes: string[];
@@ -18,6 +18,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
18
18
  var options_exports = {};
19
19
  __export(options_exports, {
20
20
  ANNOUNCEMENTS_AUDIENCE: () => ANNOUNCEMENTS_AUDIENCE,
21
+ ANNOUNCEMENTS_AUTH: () => ANNOUNCEMENTS_AUTH,
21
22
  ANNOUNCEMENTS_OPTIONS: () => ANNOUNCEMENTS_OPTIONS,
22
23
  ANNOUNCEMENTS_REDIS: () => ANNOUNCEMENTS_REDIS,
23
24
  ANNOUNCEMENT_REPOSITORY: () => ANNOUNCEMENT_REPOSITORY,
@@ -47,6 +48,7 @@ const ANNOUNCEMENT_REPOSITORY = token("REPOSITORY");
47
48
  const ANNOUNCEMENTS_REDIS = token("REDIS");
48
49
  const ANNOUNCEMENTS_AUDIENCE = token("AUDIENCE");
49
50
  const STATUS_CACHE = token("STATUS_CACHE");
51
+ const ANNOUNCEMENTS_AUTH = token("AUTH");
50
52
  const isExempt = (url, prefixes) => {
51
53
  const path = url.split("?")[0] ?? url;
52
54
  return prefixes.some((prefix) => path === prefix || path.startsWith(`${prefix}/`));
@@ -54,6 +56,7 @@ const isExempt = (url, prefixes) => {
54
56
  // Annotate the CommonJS export names for ESM import in node:
55
57
  0 && (module.exports = {
56
58
  ANNOUNCEMENTS_AUDIENCE,
59
+ ANNOUNCEMENTS_AUTH,
57
60
  ANNOUNCEMENTS_OPTIONS,
58
61
  ANNOUNCEMENTS_REDIS,
59
62
  ANNOUNCEMENT_REPOSITORY,
@@ -1,9 +1,9 @@
1
- import type { Principal } from '@haatlabs-core/nest-auth';
2
- import type { AudienceOrganization } from '@haatlabs-core/nest-billing';
1
+ import type { ExecutionContext } from '@nestjs/common';
3
2
  import type { Redis } from 'ioredis';
3
+ import type { Audience } from '../audience.js';
4
4
  import type { Status } from '../contracts/index.js';
5
5
  import type { StatusCache } from '../status-cache.js';
6
- import type { ResolvedAnnouncementsOptions } from './options.js';
6
+ import type { AnnouncementsAuth, ResolvedAnnouncementsOptions } from './options.js';
7
7
  /**
8
8
  * What a page shows across the top, and whether the app is down: for a signed-out page (and
9
9
  * the maintenance screen, which polls it to notice the end), the alerts for everyone; for a
@@ -11,14 +11,14 @@ import type { ResolvedAnnouncementsOptions } from './options.js';
11
11
  */
12
12
  export declare class StatusController {
13
13
  private readonly cache;
14
+ private readonly auth;
14
15
  private readonly audience;
15
16
  private readonly redis;
16
17
  private readonly options;
17
- constructor(cache: StatusCache, audience: {
18
- of(id: string): Promise<AudienceOrganization | null>;
19
- }, redis: Redis, options: ResolvedAnnouncementsOptions);
18
+ constructor(cache: StatusCache, auth: AnnouncementsAuth, audience: Pick<Audience, 'of'> | null, redis: Redis, options: ResolvedAnnouncementsOptions);
20
19
  status(): Promise<Status>;
21
- mine(principal: Principal): Promise<Status>;
20
+ /** The caller's own: signed out, or in an app without an audience, what is for everyone. */
21
+ mine(context: ExecutionContext): Promise<Status>;
22
22
  /** The organization as targeting reads it; a failed read is a narrower bar, never cached. */
23
23
  private viewerOf;
24
24
  }