@haatlabs-core/announcements 0.27.1 → 0.28.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.
Files changed (56) hide show
  1. package/README.md +9 -1
  2. package/dist/audience.d.ts +39 -0
  3. package/dist/audience.js +24 -0
  4. package/dist/audience.js.map +1 -0
  5. package/dist/cjs/audience.d.ts +39 -0
  6. package/dist/cjs/audience.js +44 -0
  7. package/dist/cjs/index.d.ts +3 -1
  8. package/dist/cjs/index.js +3 -0
  9. package/dist/cjs/nest/admin.controller.d.ts +9 -7
  10. package/dist/cjs/nest/admin.controller.js +25 -21
  11. package/dist/cjs/nest/admin.guard.d.ts +8 -0
  12. package/dist/cjs/nest/admin.guard.js +52 -0
  13. package/dist/cjs/nest/context.d.ts +2 -0
  14. package/dist/cjs/nest/context.js +28 -0
  15. package/dist/cjs/nest/index.d.ts +5 -3
  16. package/dist/cjs/nest/index.js +7 -1
  17. package/dist/cjs/nest/options.d.ts +27 -6
  18. package/dist/cjs/nest/options.js +3 -0
  19. package/dist/cjs/nest/status.controller.d.ts +7 -7
  20. package/dist/cjs/nest/status.controller.js +19 -9
  21. package/dist/cjs/nest-auth/index.d.ts +8 -0
  22. package/dist/cjs/nest-auth/index.js +40 -0
  23. package/dist/cjs/notify.d.ts +28 -11
  24. package/dist/cjs/targeting.d.ts +2 -1
  25. package/dist/cjs/targeting.js +1 -1
  26. package/dist/index.d.ts +3 -1
  27. package/dist/index.js +1 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/nest/admin.controller.d.ts +9 -7
  30. package/dist/nest/admin.controller.js +26 -22
  31. package/dist/nest/admin.controller.js.map +1 -1
  32. package/dist/nest/admin.guard.d.ts +8 -0
  33. package/dist/nest/admin.guard.js +27 -0
  34. package/dist/nest/admin.guard.js.map +1 -0
  35. package/dist/nest/context.d.ts +2 -0
  36. package/dist/nest/context.js +4 -0
  37. package/dist/nest/context.js.map +1 -0
  38. package/dist/nest/index.d.ts +5 -3
  39. package/dist/nest/index.js +9 -4
  40. package/dist/nest/index.js.map +1 -1
  41. package/dist/nest/options.d.ts +27 -6
  42. package/dist/nest/options.js +1 -0
  43. package/dist/nest/options.js.map +1 -1
  44. package/dist/nest/status.controller.d.ts +7 -7
  45. package/dist/nest/status.controller.js +20 -10
  46. package/dist/nest/status.controller.js.map +1 -1
  47. package/dist/nest-auth/index.d.ts +8 -0
  48. package/dist/nest-auth/index.js +21 -0
  49. package/dist/nest-auth/index.js.map +1 -0
  50. package/dist/notify.d.ts +28 -11
  51. package/dist/notify.js +0 -6
  52. package/dist/notify.js.map +1 -1
  53. package/dist/targeting.d.ts +2 -1
  54. package/dist/targeting.js +2 -1
  55. package/dist/targeting.js.map +1 -1
  56. package/package.json +26 -11
@@ -21,9 +21,10 @@ __export(status_controller_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(status_controller_exports);
23
23
  var import_common = require("@nestjs/common");
24
- var import_nest_auth = require("@haatlabs-core/nest-auth");
24
+ var import_nest_common = require("@haatlabs-core/nest-common");
25
25
  var import_targeting = require("../targeting.js");
26
26
  var import_options = require("./options.js");
27
+ var import_context = require("./context.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;
29
30
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -38,11 +39,13 @@ var __param = function(paramIndex, decorator) {
38
39
  const VIEWER_SECONDS = 300;
39
40
  let StatusController = class StatusController2 {
40
41
  cache;
42
+ auth;
41
43
  audience;
42
44
  redis;
43
45
  options;
44
- constructor(cache, audience, redis, options) {
46
+ constructor(cache, auth, audience, redis, options) {
45
47
  this.cache = cache;
48
+ this.auth = auth;
46
49
  this.audience = audience;
47
50
  this.redis = redis;
48
51
  this.options = options;
@@ -50,15 +53,19 @@ let StatusController = class StatusController2 {
50
53
  async status() {
51
54
  return (0, import_targeting.statusFor)(await this.cache.get(), null, /* @__PURE__ */ new Date());
52
55
  }
53
- async mine(principal) {
56
+ /** The caller's own: signed out, or in an app without an audience, what is for everyone. */
57
+ async mine(context) {
58
+ const organizationId = this.auth.organizationOf(context);
54
59
  const [status, viewer] = await Promise.all([
55
60
  this.cache.get(),
56
- this.viewerOf(principal.organizationId)
61
+ organizationId ? this.viewerOf(organizationId) : Promise.resolve(null)
57
62
  ]);
58
63
  return (0, import_targeting.statusFor)(status, viewer, /* @__PURE__ */ new Date());
59
64
  }
60
65
  /** The organization as targeting reads it; a failed read is a narrower bar, never cached. */
61
66
  async viewerOf(organizationId) {
67
+ if (!this.audience)
68
+ return null;
62
69
  const key = `${this.options.keyPrefix}:announcements:viewer:${organizationId}`;
63
70
  const kept = await this.redis.get(key).catch(() => null);
64
71
  if (kept !== null)
@@ -74,21 +81,24 @@ let StatusController = class StatusController2 {
74
81
  }
75
82
  };
76
83
  __decorate([
77
- (0, import_nest_auth.Public)(),
84
+ (0, import_nest_common.Public)(),
78
85
  (0, import_common.Get)("status"),
79
86
  (0, import_common.Header)("Cache-Control", "no-store")
80
87
  ], StatusController.prototype, "status", null);
81
88
  __decorate([
89
+ (0, import_nest_common.OptionalAuth)(),
82
90
  (0, import_common.Get)("me/status"),
83
91
  (0, import_common.Header)("Cache-Control", "no-store"),
84
- __param(0, (0, import_nest_auth.CurrentPrincipal)())
92
+ __param(0, (0, import_context.CurrentContext)())
85
93
  ], StatusController.prototype, "mine", null);
86
94
  StatusController = __decorate([
87
95
  (0, import_common.Controller)("api/v1"),
88
96
  __param(0, (0, import_common.Inject)(import_options.STATUS_CACHE)),
89
- __param(1, (0, import_common.Inject)(import_options.ANNOUNCEMENTS_AUDIENCE)),
90
- __param(2, (0, import_common.Inject)(import_options.ANNOUNCEMENTS_REDIS)),
91
- __param(3, (0, import_common.Inject)(import_options.ANNOUNCEMENTS_OPTIONS))
97
+ __param(1, (0, import_common.Inject)(import_options.ANNOUNCEMENTS_AUTH)),
98
+ __param(2, (0, import_common.Optional)()),
99
+ __param(2, (0, import_common.Inject)(import_options.ANNOUNCEMENTS_AUDIENCE)),
100
+ __param(3, (0, import_common.Inject)(import_options.ANNOUNCEMENTS_REDIS)),
101
+ __param(4, (0, import_common.Inject)(import_options.ANNOUNCEMENTS_OPTIONS))
92
102
  ], StatusController);
93
103
  // Annotate the CommonJS export names for ESM import in node:
94
104
  0 && (module.exports = {
@@ -0,0 +1,8 @@
1
+ import type { AnnouncementsAuth, Provide } from '../nest/options.js';
2
+ /**
3
+ * The auth adapter for the platform's own sign-in (@haatlabs-core/nest-auth): administrators are
4
+ * `AdminAuthModule`'s, and a caller's organization is the principal `AuthModule` signed in.
5
+ *
6
+ * AnnouncementsModule.forRoot({ auth: nestAuthAdapter, … })
7
+ */
8
+ export declare const nestAuthAdapter: Provide<AnnouncementsAuth>;
@@ -0,0 +1,40 @@
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 nest_auth_exports = {};
19
+ __export(nest_auth_exports, {
20
+ nestAuthAdapter: () => nestAuthAdapter
21
+ });
22
+ module.exports = __toCommonJS(nest_auth_exports);
23
+ var import_admin = require("@haatlabs-core/nest-auth/admin");
24
+ const nestAuthAdapter = {
25
+ useFactory: (guard) => ({
26
+ isAdmin: (context) => guard.canActivate(context),
27
+ adminIdOf: (context) => {
28
+ const admin = context.switchToHttp().getRequest().admin;
29
+ if (!admin)
30
+ throw new Error("nestAuthAdapter: no administrator on a route AdminGuard let through");
31
+ return admin.id;
32
+ },
33
+ organizationOf: (context) => context.switchToHttp().getRequest().principal?.organizationId ?? null
34
+ }),
35
+ inject: [import_admin.AdminGuard]
36
+ };
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ nestAuthAdapter
40
+ });
@@ -1,20 +1,13 @@
1
- import type { NotificationEventDef } from '@haatlabs-core/notifications';
2
- import type { AudienceOrganization } from '@haatlabs-core/nest-billing';
3
1
  import type { Redis } from 'ioredis';
2
+ import type { Audience } from './audience.js';
4
3
  import type { AnnouncementView } from './contracts/index.js';
5
4
  import type { AnnouncementRepository } from './repository.js';
6
5
  /** How often a worker looks for announcements whose notify is due: they go within this of their start. */
7
6
  export declare const NOTIFY_EVERY_MS = 30000;
8
7
  /** Announcements one pass takes; the next pass takes the rest. Bounds how long a pass runs. */
9
8
  export declare const NOTIFY_PER_PASS = 10;
10
- /** Who an announcement can reach (nest-billing's `SystemAudience`). */
11
- export interface NotifyAudience {
12
- page(after: string | null, limit: number): Promise<{
13
- items: AudienceOrganization[];
14
- nextAfter: string | null;
15
- }>;
16
- members(organizationId: string): Promise<string[]>;
17
- }
9
+ /** Who an announcement can reach: an `Audience`'s pages and people. */
10
+ export type NotifyAudience = Pick<Audience, 'page' | 'members'>;
18
11
  /**
19
12
  * The app's side: notify these people of one organization, on these channels besides the
20
13
  * inbox, through its notifier — `event: 'announcement'`, `dedupeKey: announcement.id`,
@@ -68,6 +61,30 @@ export interface AnnouncementNotificationData {
68
61
  * narrow what they allow. Its link is the app's root: an announcement's own link is outside
69
62
  * the app, and is shown in the alert bar.
70
63
  */
71
- export declare const announcementEvent: NotificationEventDef<AnnouncementNotificationData>;
64
+ /**
65
+ * A notification event's shape, as a registry such as @haatlabs-core/notifications'
66
+ * `defineNotificationEvents` takes one: written out here, so this package needs no
67
+ * notifications package to give an app its event.
68
+ */
69
+ export interface AnnouncementEventDef {
70
+ label: string;
71
+ group: string;
72
+ audiences: string[];
73
+ defaults: {
74
+ email: boolean;
75
+ push: boolean;
76
+ };
77
+ render(data: AnnouncementNotificationData): {
78
+ title: string;
79
+ body: string;
80
+ link: string | null;
81
+ };
82
+ email(data: AnnouncementNotificationData): {
83
+ subject: string;
84
+ heading: string;
85
+ paragraphs: string[];
86
+ };
87
+ }
88
+ export declare const announcementEvent: AnnouncementEventDef;
72
89
  /** The data `announcementEvent` renders, from an announcement. */
73
90
  export declare const announcementData: (view: AnnouncementView) => AnnouncementNotificationData;
@@ -2,7 +2,8 @@ import type { MaintenanceInfo, Platform, Segments, Status } from './contracts/in
2
2
  import type { CurrentStatus } from './repository.js';
3
3
  /** Who is looking, as targeting reads them; null is a signed-out viewer. */
4
4
  export interface Viewer {
5
- planCode: string;
5
+ /** Null for an app without plans. */
6
+ planCode: string | null;
6
7
  platforms: readonly Platform[];
7
8
  country: string | null;
8
9
  }
@@ -23,7 +23,7 @@ __export(targeting_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(targeting_exports);
25
25
  function matches(segments, viewer) {
26
- if (segments.plans.length > 0 && (!viewer || !segments.plans.includes(viewer.planCode))) {
26
+ if (segments.plans.length > 0 && (!viewer || viewer.planCode === null || !segments.plans.includes(viewer.planCode))) {
27
27
  return false;
28
28
  }
29
29
  if (segments.platforms.length > 0 && (!viewer || !segments.platforms.some((p) => viewer.platforms.includes(p)))) {
package/dist/index.d.ts CHANGED
@@ -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/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './contracts/index.js';
2
+ export { everyoneAudience } from './audience.js';
2
3
  export { ANNOUNCEMENT_ERROR_DEFINITIONS, announcementErrors } from './errors.js';
3
4
  export { AnnouncementRepository } from './repository.js';
4
5
  export { STALE_TTL_SECONDS, STATUS_TTL_SECONDS, StatusCache, statusKeys } from './status-cache.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,aAAa,CAAC"}
@@ -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
  }
@@ -8,9 +8,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
10
  import { Body, Controller, Get, HttpCode, Inject, Param, ParseUUIDPipe, Post, Put, Query, UseGuards, } from '@nestjs/common';
11
- import { Public } from '@haatlabs-core/nest-auth';
12
- import { AdminGuard, CurrentAdmin } from '@haatlabs-core/nest-auth/admin';
13
- import { ANNOUNCEMENT_REPOSITORY, STATUS_CACHE } from './options.js';
11
+ import { Public } from '@haatlabs-core/nest-common';
12
+ import { AdminOnly } from './admin.guard.js';
13
+ import { CurrentContext } from './context.js';
14
+ import { ANNOUNCEMENTS_AUTH, ANNOUNCEMENT_REPOSITORY, STATUS_CACHE } from './options.js';
14
15
  const PAGE_DEFAULT = 50;
15
16
  const PAGE_MAX = 100;
16
17
  const paging = (limit, offset) => ({
@@ -22,13 +23,15 @@ const paging = (limit, offset) => ({
22
23
  * the repository, which refuses with codes the admin screen explains. Every write clears
23
24
  * the cached status, so this app shows it at once and the others within seconds.
24
25
  */
25
- // Public to the merchants' guard: administrators are AdminGuard's, not a merchant session.
26
+ // Public to the app's own guard: administrators are the auth adapter's to recognise.
26
27
  let AnnouncementsAdminController = class AnnouncementsAdminController {
27
28
  repo;
28
29
  cache;
29
- constructor(repo, cache) {
30
+ auth;
31
+ constructor(repo, cache, auth) {
30
32
  this.repo = repo;
31
33
  this.cache = cache;
34
+ this.auth = auth;
32
35
  }
33
36
  list(includeEnded, limit, offset) {
34
37
  return this.repo.listAnnouncements({
@@ -36,33 +39,33 @@ let AnnouncementsAdminController = class AnnouncementsAdminController {
36
39
  ...paging(limit, offset),
37
40
  });
38
41
  }
39
- async create(admin, body) {
40
- const view = await this.repo.createAnnouncement(admin.id, body);
42
+ async create(context, body) {
43
+ const view = await this.repo.createAnnouncement(this.auth.adminIdOf(context), body);
41
44
  await this.cache.invalidate();
42
45
  return view;
43
46
  }
44
47
  /** A full replacement: the screen sends the whole form. */
45
- async update(admin, id, body) {
46
- const view = await this.repo.updateAnnouncement(admin.id, id, body);
48
+ async update(context, id, body) {
49
+ const view = await this.repo.updateAnnouncement(this.auth.adminIdOf(context), id, body);
47
50
  await this.cache.invalidate();
48
51
  return view;
49
52
  }
50
- async cancel(admin, id) {
51
- await this.repo.cancelAnnouncement(admin.id, id);
53
+ async cancel(context, id) {
54
+ await this.repo.cancelAnnouncement(this.auth.adminIdOf(context), id);
52
55
  await this.cache.invalidate();
53
56
  return { ok: true };
54
57
  }
55
58
  maintenance(limit, offset) {
56
59
  return this.repo.listMaintenance(paging(limit, offset));
57
60
  }
58
- async schedule(admin, body) {
59
- const view = await this.repo.scheduleMaintenance(admin.id, body);
61
+ async schedule(context, body) {
62
+ const view = await this.repo.scheduleMaintenance(this.auth.adminIdOf(context), body);
60
63
  await this.cache.invalidate();
61
64
  return view;
62
65
  }
63
66
  /** "End now": ends an open window, or cancels a scheduled one. */
64
- async end(admin, id) {
65
- await this.repo.endMaintenance(admin.id, id);
67
+ async end(context, id) {
68
+ await this.repo.endMaintenance(this.auth.adminIdOf(context), id);
66
69
  await this.cache.invalidate();
67
70
  return { ok: true };
68
71
  }
@@ -75,19 +78,19 @@ __decorate([
75
78
  ], AnnouncementsAdminController.prototype, "list", null);
76
79
  __decorate([
77
80
  Post('announcements'),
78
- __param(0, CurrentAdmin()),
81
+ __param(0, CurrentContext()),
79
82
  __param(1, Body())
80
83
  ], AnnouncementsAdminController.prototype, "create", null);
81
84
  __decorate([
82
85
  Put('announcements/:id'),
83
- __param(0, CurrentAdmin()),
86
+ __param(0, CurrentContext()),
84
87
  __param(1, Param('id', ParseUUIDPipe)),
85
88
  __param(2, Body())
86
89
  ], AnnouncementsAdminController.prototype, "update", null);
87
90
  __decorate([
88
91
  Post('announcements/:id/cancel'),
89
92
  HttpCode(200),
90
- __param(0, CurrentAdmin()),
93
+ __param(0, CurrentContext()),
91
94
  __param(1, Param('id', ParseUUIDPipe))
92
95
  ], AnnouncementsAdminController.prototype, "cancel", null);
93
96
  __decorate([
@@ -97,21 +100,22 @@ __decorate([
97
100
  ], AnnouncementsAdminController.prototype, "maintenance", null);
98
101
  __decorate([
99
102
  Post('maintenance'),
100
- __param(0, CurrentAdmin()),
103
+ __param(0, CurrentContext()),
101
104
  __param(1, Body())
102
105
  ], AnnouncementsAdminController.prototype, "schedule", null);
103
106
  __decorate([
104
107
  Post('maintenance/:id/end'),
105
108
  HttpCode(200),
106
- __param(0, CurrentAdmin()),
109
+ __param(0, CurrentContext()),
107
110
  __param(1, Param('id', ParseUUIDPipe))
108
111
  ], AnnouncementsAdminController.prototype, "end", null);
109
112
  AnnouncementsAdminController = __decorate([
110
113
  Public(),
111
114
  Controller('api/v1/admin'),
112
- UseGuards(AdminGuard),
115
+ UseGuards(AdminOnly),
113
116
  __param(0, Inject(ANNOUNCEMENT_REPOSITORY)),
114
- __param(1, Inject(STATUS_CACHE))
117
+ __param(1, Inject(STATUS_CACHE)),
118
+ __param(2, Inject(ANNOUNCEMENTS_AUTH))
115
119
  ], AnnouncementsAdminController);
116
120
  export { AnnouncementsAdminController };
117
121
  //# sourceMappingURL=admin.controller.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"admin.controller.js","sourceRoot":"","sources":["../../src/nest/admin.controller.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,IAAI,EACJ,U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AAA;0DAK5B;AAGD;IADC,GAAG,CAAC,aAAa,CAAC;IAEhB,WAAA,KAAK,CAAC,OAAO,CAAC,CAAA;IACd,WAAA,KAAK,CAAC,QAAQ,CAAC,CAAA;+DAGjB;AAGK;IADL,IAAI,CAAC,aAAa,CAAC;IAEjB,WAAA,cAAc,EAAE,CAAA;IAChB,WAAA,IAAI,EAAE,CAAA;4DAKR;AAKK;IAFL,IAAI,CAAC,qBAAqB,CAAC;IAC3B,QAAQ,CAAC,GAAG,CAAC;IAEX,WAAA,cAAc,EAAE,CAAA;IAChB,WAAA,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;uDAK5B;AAhFU,4BAA4B;IAHxC,MAAM,EAAE;IACR,UAAU,CAAC,cAAc,CAAC;IAC1B,SAAS,CAAC,SAAS,CAAC;IAGhB,WAAA,MAAM,CAAC,uBAAuB,CAAC,CAAA;IAC/B,WAAA,MAAM,CAAC,YAAY,CAAC,CAAA;IACpB,WAAA,MAAM,CAAC,kBAAkB,CAAC,CAAA;GAJlB,4BAA4B,CAiFxC"}
@@ -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,27 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Injectable } from '@nestjs/common';
11
+ import { ANNOUNCEMENTS_AUTH } from './options.js';
12
+ /** The administrators' routes: whoever the auth adapter says is one. */
13
+ let AdminOnly = class AdminOnly {
14
+ auth;
15
+ constructor(auth) {
16
+ this.auth = auth;
17
+ }
18
+ canActivate(context) {
19
+ return this.auth.isAdmin(context);
20
+ }
21
+ };
22
+ AdminOnly = __decorate([
23
+ Injectable(),
24
+ __param(0, Inject(ANNOUNCEMENTS_AUTH))
25
+ ], AdminOnly);
26
+ export { AdminOnly };
27
+ //# sourceMappingURL=admin.guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.guard.js","sourceRoot":"","sources":["../../src/nest/admin.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,wEAAwE;AAEjE,IAAM,SAAS,GAAf,MAAM,SAAS;IACqC;IAAzD,YAAyD,IAAuB;QAAvB,SAAI,GAAJ,IAAI,CAAmB;IAAG,CAAC;IAEpF,WAAW,CAAC,OAAyB;QACnC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACF,CAAA;AANY,SAAS;IADrB,UAAU,EAAE;IAEE,WAAA,MAAM,CAAC,kBAAkB,CAAC,CAAA;GAD5B,SAAS,CAMrB"}
@@ -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,4 @@
1
+ import { createParamDecorator } from '@nestjs/common';
2
+ /** The request's context itself, for the auth adapter to read who is calling. */
3
+ export const CurrentContext = createParamDecorator((_data, context) => context);
4
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/nest/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGtD,iFAAiF;AACjF,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAChD,CAAC,KAAc,EAAE,OAAyB,EAAoB,EAAE,CAAC,OAAO,CACzE,CAAC"}
@@ -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';
@@ -10,7 +10,8 @@ import { LOGGER } from '@haatlabs-core/nest-common';
10
10
  import { StatusCache } from '../status-cache.js';
11
11
  import { AnnouncementsAdminController } from './admin.controller.js';
12
12
  import { MaintenanceGate } from './maintenance-gate.js';
13
- import { ANNOUNCEMENTS_AUDIENCE, ANNOUNCEMENTS_OPTIONS, ANNOUNCEMENTS_REDIS, ANNOUNCEMENT_REPOSITORY, STATUS_CACHE, exemptPrefixesOf, } from './options.js';
13
+ import { AdminOnly } from './admin.guard.js';
14
+ import { ANNOUNCEMENTS_AUDIENCE, ANNOUNCEMENTS_AUTH, ANNOUNCEMENTS_OPTIONS, ANNOUNCEMENTS_REDIS, ANNOUNCEMENT_REPOSITORY, STATUS_CACHE, exemptPrefixesOf, } from './options.js';
14
15
  import { StatusController } from './status.controller.js';
15
16
  const provide = (token, source) => ({
16
17
  provide: token,
@@ -20,8 +21,9 @@ const provide = (token, source) => ({
20
21
  /**
21
22
  * Announcements and app-layer maintenance: `GET api/v1/status` (public) and
22
23
  * `GET api/v1/me/status`, the administrators' routes under `api/v1/admin/announcements` and
23
- * `api/v1/admin/maintenance`, and the maintenance gate on every other route. Needs
24
- * nest-auth's `AuthModule` and `AdminAuthModule`, and nest-common's `LOGGER`.
24
+ * `api/v1/admin/maintenance`, and the maintenance gate on every other route. Sign-in comes
25
+ * from the `auth` adapter (`@haatlabs-core/announcements/nest-auth` for the platform's own), who a
26
+ * caller's organization is from the optional `audience`; nest-common's `LOGGER` is needed.
25
27
  */
26
28
  let AnnouncementsModule = AnnouncementsModule_1 = class AnnouncementsModule {
27
29
  static forRoot(options) {
@@ -35,7 +37,9 @@ let AnnouncementsModule = AnnouncementsModule_1 = class AnnouncementsModule {
35
37
  { provide: ANNOUNCEMENTS_OPTIONS, useValue: resolved },
36
38
  provide(ANNOUNCEMENT_REPOSITORY, options.repository),
37
39
  provide(ANNOUNCEMENTS_REDIS, options.redis),
38
- provide(ANNOUNCEMENTS_AUDIENCE, options.audience),
40
+ provide(ANNOUNCEMENTS_AUTH, options.auth),
41
+ ...(options.audience ? [provide(ANNOUNCEMENTS_AUDIENCE, options.audience)] : []),
42
+ AdminOnly,
39
43
  {
40
44
  provide: STATUS_CACHE,
41
45
  useFactory: (repo, redis, logger) => new StatusCache({
@@ -57,4 +61,5 @@ AnnouncementsModule = AnnouncementsModule_1 = __decorate([
57
61
  ], AnnouncementsModule);
58
62
  export { AnnouncementsModule };
59
63
  export { DEFAULT_EXEMPT_PREFIXES, exemptPrefixesOf, isExempt } from './options.js';
64
+ export { AdminOnly } from './admin.guard.js';
60
65
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nest/index.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,MAAM,OAAO,GAAG,CAAI,KAAa,EAAE,MAAkB,EAAY,EAAE,CAAC,CAAC;IACnE,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,MAAM,CAAC,UAAU;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;CAC5B,CAAC,CAAC;AAEH;;;;;GAKG;AAEI,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAC9B,MAAM,CAAC,OAAO,CAAC,OAAmC;QAChD,MAAM,QAAQ,GAAiC;YAC7C,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,cAAc,EAAE,gBAAgB,CAAC,OAAO,CAAC,cAAc,CAAC;SACzD,CAAC;QACF,OAAO;YACL,MAAM,EAAE,qBAAmB;YAC3B,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,QAAQ,EAAE;gBACtD,OAAO,CAAC,uBAAuB,EAAE,OAAO,CAAC,UAAU,CAAC;gBACp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mBAAmB,EAAE,MAAM,CAAC;iBAC/D;gBACD,eAAe;aAChB;YACD,WAAW,EAAE,CAAC,gBAAgB,EAAE,4BAA4B,CAAC;SAC9D,CAAC;IACJ,CAAC;CACF,CAAA;AAnCY,mBAAmB;IAD/B,MAAM,CAAC,EAAE,CAAC;GACE,mBAAmB,CAmC/B;;AAED,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEnF,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC"}
@@ -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[];
@@ -26,6 +26,7 @@ export const ANNOUNCEMENT_REPOSITORY = token('REPOSITORY');
26
26
  export const ANNOUNCEMENTS_REDIS = token('REDIS');
27
27
  export const ANNOUNCEMENTS_AUDIENCE = token('AUDIENCE');
28
28
  export const STATUS_CACHE = token('STATUS_CACHE');
29
+ export const ANNOUNCEMENTS_AUTH = token('AUTH');
29
30
  /**
30
31
  * Whether maintenance leaves this request alone: a prefix matches whole path segments only,
31
32
  * the query is ignored, and nothing is decoded (an encoded path is never exempt: it fails
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/nest/options.ts"],"names":[],"mappings":"AAqBA;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,eAAe;IACf,gBAAgB;IAChB,mBAAmB;IACnB,kBAAkB;IAClB,sBAAsB;IACtB,iCAAiC;IACjC,SAAS;IACT,UAAU;CACX,CAAC;AAEF,sFAAsF;AACtF,MAAM,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