@haatlabs-core/announcements 0.0.0-stage → 0.27.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/LICENSE +201 -0
- package/README.md +101 -2
- package/dist/cjs/contracts/index.d.ts +1 -0
- package/dist/cjs/contracts/index.js +21 -0
- package/dist/cjs/errors.d.ts +84 -0
- package/dist/cjs/errors.js +53 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.js +62 -0
- package/dist/cjs/nest/admin.controller.d.ts +27 -0
- package/dist/cjs/nest/admin.controller.js +137 -0
- package/dist/cjs/nest/index.d.ts +13 -0
- package/dist/cjs/nest/index.js +84 -0
- package/dist/cjs/nest/maintenance-gate.d.ts +20 -0
- package/dist/cjs/nest/maintenance-gate.js +74 -0
- package/dist/cjs/nest/options.d.ts +44 -0
- package/dist/cjs/nest/options.js +64 -0
- package/dist/cjs/nest/status.controller.d.ts +24 -0
- package/dist/cjs/nest/status.controller.js +96 -0
- package/dist/cjs/notify.d.ts +73 -0
- package/dist/cjs/notify.js +132 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/repository.d.ts +75 -0
- package/dist/cjs/repository.js +241 -0
- package/dist/cjs/status-cache.d.ts +59 -0
- package/dist/cjs/status-cache.js +137 -0
- package/dist/cjs/targeting.d.ts +21 -0
- package/dist/cjs/targeting.js +58 -0
- package/dist/cjs/validate.d.ts +30 -0
- package/dist/cjs/validate.js +117 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +3 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/errors.d.ts +84 -0
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/nest/admin.controller.d.ts +27 -0
- package/dist/nest/admin.controller.js +117 -0
- package/dist/nest/admin.controller.js.map +1 -0
- package/dist/nest/index.d.ts +13 -0
- package/dist/nest/index.js +60 -0
- package/dist/nest/index.js.map +1 -0
- package/dist/nest/maintenance-gate.d.ts +20 -0
- package/dist/nest/maintenance-gate.js +57 -0
- package/dist/nest/maintenance-gate.js.map +1 -0
- package/dist/nest/options.d.ts +44 -0
- package/dist/nest/options.js +38 -0
- package/dist/nest/options.js.map +1 -0
- package/dist/nest/status.controller.d.ts +24 -0
- package/dist/nest/status.controller.js +81 -0
- package/dist/nest/status.controller.js.map +1 -0
- package/dist/notify.d.ts +73 -0
- package/dist/notify.js +133 -0
- package/dist/notify.js.map +1 -0
- package/dist/repository.d.ts +75 -0
- package/dist/repository.js +273 -0
- package/dist/repository.js.map +1 -0
- package/dist/status-cache.d.ts +59 -0
- package/dist/status-cache.js +139 -0
- package/dist/status-cache.js.map +1 -0
- package/dist/targeting.d.ts +21 -0
- package/dist/targeting.js +43 -0
- package/dist/targeting.js.map +1 -0
- package/dist/validate.d.ts +30 -0
- package/dist/validate.js +102 -0
- package/dist/validate.js.map +1 -0
- package/package.json +106 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Haatlabs
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,102 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @haatlabs-core/announcements
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Announcements (the alert bar across every surface of an app, optionally notified) and app-layer
|
|
4
|
+
maintenance (every surface but admin answers 503 while a window is open), for NestJS apps on the
|
|
5
|
+
Haatlabs platform. Written in each app's own admin by platform administrators; per app.
|
|
6
|
+
|
|
7
|
+
## Wiring an app
|
|
8
|
+
|
|
9
|
+
1. **Tables.** Build them from `@haatlabs-core/db-core` and generate the migration, as the starter
|
|
10
|
+
does in `packages/database/src/schema/announcements.ts` (plus `organizations.country` /
|
|
11
|
+
`country_source` and `notifications.allowed_channels`, which come with the same release):
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
export const announcements = pgTable('announcements', announcementColumns(), (t) =>
|
|
15
|
+
announcementIndexes(t),
|
|
16
|
+
);
|
|
17
|
+
export const maintenanceWindows = pgTable(
|
|
18
|
+
'maintenance_windows',
|
|
19
|
+
maintenanceWindowColumns(),
|
|
20
|
+
(t) => maintenanceWindowIndexes(t),
|
|
21
|
+
);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Grant nothing to the runtime role: the package reads and writes them on the system connection.
|
|
25
|
+
|
|
26
|
+
2. **Module.** Import it beside `AuthModule` and `AdminAuthModule`:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
AnnouncementsModule.forRoot({
|
|
30
|
+
repository: {
|
|
31
|
+
useFactory: (db: DatabaseHandle) =>
|
|
32
|
+
new AnnouncementRepository(db.db, { announcements, maintenanceWindows }),
|
|
33
|
+
inject: [SYSTEM_DB],
|
|
34
|
+
},
|
|
35
|
+
redis: { useFactory: (redis: Redis) => redis, inject: [REDIS] },
|
|
36
|
+
keyPrefix: 'catalogpix',
|
|
37
|
+
audience: {
|
|
38
|
+
useFactory: (db: DatabaseHandle) =>
|
|
39
|
+
new SystemAudience(
|
|
40
|
+
db.db,
|
|
41
|
+
{ ...billingTables, memberships, shopifyInstallations },
|
|
42
|
+
catalog,
|
|
43
|
+
),
|
|
44
|
+
inject: [SYSTEM_DB],
|
|
45
|
+
},
|
|
46
|
+
// The app's own machine-to-machine routes, besides the defaults (admin, status,
|
|
47
|
+
// webhooks, Shopify install/OAuth, Shopify charge confirmation, health, metrics):
|
|
48
|
+
exemptPrefixes: ['/api/v1/vendor/oauth'],
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
This serves `GET /api/v1/status` (public), `GET /api/v1/me/status`, the admin routes under
|
|
53
|
+
`/api/v1/admin/announcements` and `/api/v1/admin/maintenance`, and installs the maintenance
|
|
54
|
+
gate (a Fastify preHandler hook: after CORS, before the guards; an HTTP app only). Check any
|
|
55
|
+
app-specific machine route (a provider gateway, an OAuth door of its own) is in `exemptPrefixes`.
|
|
56
|
+
|
|
57
|
+
3. **Notify loop**, in the worker, and the event in the app's registry:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const events = defineNotificationEvents({ ...appEvents, announcement: announcementEvent });
|
|
61
|
+
|
|
62
|
+
startAnnouncementNotify({
|
|
63
|
+
repository,
|
|
64
|
+
audience,
|
|
65
|
+
redis,
|
|
66
|
+
keyPrefix,
|
|
67
|
+
logger,
|
|
68
|
+
notify: ({ organizationId, userIds, announcement, channels }) =>
|
|
69
|
+
withTenant(app.db, { organizationId }, (tx) =>
|
|
70
|
+
notifier.notify(tx, {
|
|
71
|
+
organizationId,
|
|
72
|
+
event: 'announcement',
|
|
73
|
+
recipients: userIds.map((id) => ({ type: 'user', id })),
|
|
74
|
+
data: announcementData(announcement),
|
|
75
|
+
dedupeKey: announcement.id,
|
|
76
|
+
channels,
|
|
77
|
+
}),
|
|
78
|
+
),
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Every 30 s one worker takes up to 10 due announcements, claims each, and notifies the people
|
|
83
|
+
of every organization it is for. A failure gives the claim back; the dedupe key stops anyone
|
|
84
|
+
being told twice.
|
|
85
|
+
|
|
86
|
+
4. **Dashboard, embed, admin** (`@haatlabs-core/ui`):
|
|
87
|
+
- `createTransport({ …, onMaintenance })` — a maintenance 503 calls it and fails the request
|
|
88
|
+
with code `MAINTENANCE`; show `<MaintenanceScreen>` until its `retry` (the status) clears.
|
|
89
|
+
- `useStatusPoll(read, { maintenance })` and `<AppShell banner={<AlertBar alerts={…} />}>`.
|
|
90
|
+
- Admin: `<AnnouncementsPage client={announcementsAdminClient(transport)} plans={…} />`,
|
|
91
|
+
`<MaintenancePage>` and `<MaintenanceOnBanner>` in the admin shell's `banner`.
|
|
92
|
+
|
|
93
|
+
5. **Extensions** (`@haatlabs-core/extension-ui`): wrap the panel in `<StatusNotices read={…}>`.
|
|
94
|
+
|
|
95
|
+
## The 503 body
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{ "maintenance": { "layer": "app", "message": "Upgrading", "until": "2026-11-26T18:00:00.000Z" } }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The same body comes from the edge's infra switch (`layer: "infra"`). `maintenance.schema.json`
|
|
102
|
+
is its JSON Schema; the infra repository keeps a copy and checks its own body against it.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@haatlabs-core/announcements-contracts';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var contracts_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(contracts_exports);
|
|
17
|
+
__reExport(contracts_exports, require("@haatlabs-core/announcements-contracts"), module.exports);
|
|
18
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
19
|
+
0 && (module.exports = {
|
|
20
|
+
...require("@haatlabs-core/announcements-contracts")
|
|
21
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** What the package refuses with: each code answered with its own HTTP status. */
|
|
2
|
+
export declare const ANNOUNCEMENT_ERROR_DEFINITIONS: {
|
|
3
|
+
readonly ANNOUNCEMENT_NOT_FOUND: {
|
|
4
|
+
readonly httpStatus: 404;
|
|
5
|
+
readonly transient: false;
|
|
6
|
+
};
|
|
7
|
+
readonly MAINTENANCE_NOT_FOUND: {
|
|
8
|
+
readonly httpStatus: 404;
|
|
9
|
+
readonly transient: false;
|
|
10
|
+
};
|
|
11
|
+
readonly MAINTENANCE_OVERLAP: {
|
|
12
|
+
readonly httpStatus: 409;
|
|
13
|
+
readonly transient: false;
|
|
14
|
+
};
|
|
15
|
+
readonly INVALID_SCHEDULE: {
|
|
16
|
+
readonly httpStatus: 400;
|
|
17
|
+
readonly transient: false;
|
|
18
|
+
};
|
|
19
|
+
readonly INVALID_LINK: {
|
|
20
|
+
readonly httpStatus: 400;
|
|
21
|
+
readonly transient: false;
|
|
22
|
+
};
|
|
23
|
+
readonly INVALID_SEGMENT: {
|
|
24
|
+
readonly httpStatus: 400;
|
|
25
|
+
readonly transient: false;
|
|
26
|
+
};
|
|
27
|
+
readonly INVALID_TEXT: {
|
|
28
|
+
readonly httpStatus: 400;
|
|
29
|
+
readonly transient: false;
|
|
30
|
+
};
|
|
31
|
+
readonly INVALID_HEADS_UP: {
|
|
32
|
+
readonly httpStatus: 400;
|
|
33
|
+
readonly transient: false;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare const announcementErrors: {
|
|
37
|
+
codes: {
|
|
38
|
+
readonly ANNOUNCEMENT_NOT_FOUND: "ANNOUNCEMENT_NOT_FOUND";
|
|
39
|
+
readonly MAINTENANCE_NOT_FOUND: "MAINTENANCE_NOT_FOUND";
|
|
40
|
+
readonly MAINTENANCE_OVERLAP: "MAINTENANCE_OVERLAP";
|
|
41
|
+
readonly INVALID_SCHEDULE: "INVALID_SCHEDULE";
|
|
42
|
+
readonly INVALID_LINK: "INVALID_LINK";
|
|
43
|
+
readonly INVALID_SEGMENT: "INVALID_SEGMENT";
|
|
44
|
+
readonly INVALID_TEXT: "INVALID_TEXT";
|
|
45
|
+
readonly INVALID_HEADS_UP: "INVALID_HEADS_UP";
|
|
46
|
+
};
|
|
47
|
+
definitions: {
|
|
48
|
+
readonly ANNOUNCEMENT_NOT_FOUND: {
|
|
49
|
+
readonly httpStatus: 404;
|
|
50
|
+
readonly transient: false;
|
|
51
|
+
};
|
|
52
|
+
readonly MAINTENANCE_NOT_FOUND: {
|
|
53
|
+
readonly httpStatus: 404;
|
|
54
|
+
readonly transient: false;
|
|
55
|
+
};
|
|
56
|
+
readonly MAINTENANCE_OVERLAP: {
|
|
57
|
+
readonly httpStatus: 409;
|
|
58
|
+
readonly transient: false;
|
|
59
|
+
};
|
|
60
|
+
readonly INVALID_SCHEDULE: {
|
|
61
|
+
readonly httpStatus: 400;
|
|
62
|
+
readonly transient: false;
|
|
63
|
+
};
|
|
64
|
+
readonly INVALID_LINK: {
|
|
65
|
+
readonly httpStatus: 400;
|
|
66
|
+
readonly transient: false;
|
|
67
|
+
};
|
|
68
|
+
readonly INVALID_SEGMENT: {
|
|
69
|
+
readonly httpStatus: 400;
|
|
70
|
+
readonly transient: false;
|
|
71
|
+
};
|
|
72
|
+
readonly INVALID_TEXT: {
|
|
73
|
+
readonly httpStatus: 400;
|
|
74
|
+
readonly transient: false;
|
|
75
|
+
};
|
|
76
|
+
readonly INVALID_HEADS_UP: {
|
|
77
|
+
readonly httpStatus: 400;
|
|
78
|
+
readonly transient: false;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
create: (code: "ANNOUNCEMENT_NOT_FOUND" | "MAINTENANCE_NOT_FOUND" | "MAINTENANCE_OVERLAP" | "INVALID_SCHEDULE" | "INVALID_LINK" | "INVALID_SEGMENT" | "INVALID_TEXT" | "INVALID_HEADS_UP", message: string, options?: import("@haatlabs-core/errors").AppErrorOptions) => import("@haatlabs-core/errors").AppError<"ANNOUNCEMENT_NOT_FOUND" | "MAINTENANCE_NOT_FOUND" | "MAINTENANCE_OVERLAP" | "INVALID_SCHEDULE" | "INVALID_LINK" | "INVALID_SEGMENT" | "INVALID_TEXT" | "INVALID_HEADS_UP">;
|
|
82
|
+
};
|
|
83
|
+
export type AnnouncementErrorCode = keyof typeof ANNOUNCEMENT_ERROR_DEFINITIONS;
|
|
84
|
+
export declare const refuse: (code: AnnouncementErrorCode) => import("@haatlabs-core/errors").AppError<"ANNOUNCEMENT_NOT_FOUND" | "MAINTENANCE_NOT_FOUND" | "MAINTENANCE_OVERLAP" | "INVALID_SCHEDULE" | "INVALID_LINK" | "INVALID_SEGMENT" | "INVALID_TEXT" | "INVALID_HEADS_UP">;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 errors_exports = {};
|
|
19
|
+
__export(errors_exports, {
|
|
20
|
+
ANNOUNCEMENT_ERROR_DEFINITIONS: () => ANNOUNCEMENT_ERROR_DEFINITIONS,
|
|
21
|
+
announcementErrors: () => announcementErrors,
|
|
22
|
+
refuse: () => refuse
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(errors_exports);
|
|
25
|
+
var import_errors = require("@haatlabs-core/errors");
|
|
26
|
+
const ANNOUNCEMENT_ERROR_DEFINITIONS = {
|
|
27
|
+
ANNOUNCEMENT_NOT_FOUND: { httpStatus: 404, transient: false },
|
|
28
|
+
MAINTENANCE_NOT_FOUND: { httpStatus: 404, transient: false },
|
|
29
|
+
MAINTENANCE_OVERLAP: { httpStatus: 409, transient: false },
|
|
30
|
+
INVALID_SCHEDULE: { httpStatus: 400, transient: false },
|
|
31
|
+
INVALID_LINK: { httpStatus: 400, transient: false },
|
|
32
|
+
INVALID_SEGMENT: { httpStatus: 400, transient: false },
|
|
33
|
+
INVALID_TEXT: { httpStatus: 400, transient: false },
|
|
34
|
+
INVALID_HEADS_UP: { httpStatus: 400, transient: false }
|
|
35
|
+
};
|
|
36
|
+
const announcementErrors = (0, import_errors.domainErrors)(ANNOUNCEMENT_ERROR_DEFINITIONS);
|
|
37
|
+
const MESSAGES = {
|
|
38
|
+
ANNOUNCEMENT_NOT_FOUND: "This announcement does not exist, or was cancelled.",
|
|
39
|
+
MAINTENANCE_NOT_FOUND: "This maintenance window does not exist.",
|
|
40
|
+
MAINTENANCE_OVERLAP: "Another maintenance window covers some of that time.",
|
|
41
|
+
INVALID_SCHEDULE: "The end must be after the start, and not already past.",
|
|
42
|
+
INVALID_LINK: "The link must start with https://",
|
|
43
|
+
INVALID_SEGMENT: "Check the plans, platforms and countries (two-letter codes).",
|
|
44
|
+
INVALID_TEXT: "A title (up to 120 characters) and a message (up to 1000) are both needed; link text is at most 60.",
|
|
45
|
+
INVALID_HEADS_UP: "Warn between 0 and 10080 minutes (a week) ahead, in whole minutes."
|
|
46
|
+
};
|
|
47
|
+
const refuse = (code) => announcementErrors.create(code, MESSAGES[code]);
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
ANNOUNCEMENT_ERROR_DEFINITIONS,
|
|
51
|
+
announcementErrors,
|
|
52
|
+
refuse
|
|
53
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './contracts/index.js';
|
|
2
|
+
export { ANNOUNCEMENT_ERROR_DEFINITIONS, announcementErrors } from './errors.js';
|
|
3
|
+
export type { AnnouncementErrorCode } from './errors.js';
|
|
4
|
+
export { AnnouncementRepository } from './repository.js';
|
|
5
|
+
export type { AnnouncementTables, CurrentStatus, TargetedAlert } from './repository.js';
|
|
6
|
+
export { STALE_TTL_SECONDS, STATUS_TTL_SECONDS, StatusCache, statusKeys } from './status-cache.js';
|
|
7
|
+
export { activeMaintenance, matches, statusFor } from './targeting.js';
|
|
8
|
+
export type { Viewer } from './targeting.js';
|
|
9
|
+
export { NOTIFY_EVERY_MS, announcementData, announcementEvent, sendDueAnnouncements, startAnnouncementNotify, } from './notify.js';
|
|
10
|
+
export type { AnnouncementNotificationData, AnnouncementNotify, AnnouncementNotifyDeps, NotifyAudience, } from './notify.js';
|
|
@@ -0,0 +1,62 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
ANNOUNCEMENT_ERROR_DEFINITIONS: () => import_errors.ANNOUNCEMENT_ERROR_DEFINITIONS,
|
|
22
|
+
AnnouncementRepository: () => import_repository.AnnouncementRepository,
|
|
23
|
+
NOTIFY_EVERY_MS: () => import_notify.NOTIFY_EVERY_MS,
|
|
24
|
+
STALE_TTL_SECONDS: () => import_status_cache.STALE_TTL_SECONDS,
|
|
25
|
+
STATUS_TTL_SECONDS: () => import_status_cache.STATUS_TTL_SECONDS,
|
|
26
|
+
StatusCache: () => import_status_cache.StatusCache,
|
|
27
|
+
activeMaintenance: () => import_targeting.activeMaintenance,
|
|
28
|
+
announcementData: () => import_notify.announcementData,
|
|
29
|
+
announcementErrors: () => import_errors.announcementErrors,
|
|
30
|
+
announcementEvent: () => import_notify.announcementEvent,
|
|
31
|
+
matches: () => import_targeting.matches,
|
|
32
|
+
sendDueAnnouncements: () => import_notify.sendDueAnnouncements,
|
|
33
|
+
startAnnouncementNotify: () => import_notify.startAnnouncementNotify,
|
|
34
|
+
statusFor: () => import_targeting.statusFor,
|
|
35
|
+
statusKeys: () => import_status_cache.statusKeys
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
__reExport(index_exports, require("./contracts/index.js"), module.exports);
|
|
39
|
+
var import_errors = require("./errors.js");
|
|
40
|
+
var import_repository = require("./repository.js");
|
|
41
|
+
var import_status_cache = require("./status-cache.js");
|
|
42
|
+
var import_targeting = require("./targeting.js");
|
|
43
|
+
var import_notify = require("./notify.js");
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
ANNOUNCEMENT_ERROR_DEFINITIONS,
|
|
47
|
+
AnnouncementRepository,
|
|
48
|
+
NOTIFY_EVERY_MS,
|
|
49
|
+
STALE_TTL_SECONDS,
|
|
50
|
+
STATUS_TTL_SECONDS,
|
|
51
|
+
StatusCache,
|
|
52
|
+
activeMaintenance,
|
|
53
|
+
announcementData,
|
|
54
|
+
announcementErrors,
|
|
55
|
+
announcementEvent,
|
|
56
|
+
matches,
|
|
57
|
+
sendDueAnnouncements,
|
|
58
|
+
startAnnouncementNotify,
|
|
59
|
+
statusFor,
|
|
60
|
+
statusKeys,
|
|
61
|
+
...require("./contracts/index.js")
|
|
62
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AdminPrincipal } from '@haatlabs-core/nest-auth/admin';
|
|
2
|
+
import type { AnnouncementInput, AnnouncementView, MaintenanceInput, MaintenanceView, Page } from '../contracts/index.js';
|
|
3
|
+
import type { AnnouncementRepository } from '../repository.js';
|
|
4
|
+
import type { StatusCache } from '../status-cache.js';
|
|
5
|
+
/**
|
|
6
|
+
* Announcements and maintenance, for platform administrators only. Bodies are checked by
|
|
7
|
+
* the repository, which refuses with codes the admin screen explains. Every write clears
|
|
8
|
+
* the cached status, so this app shows it at once and the others within seconds.
|
|
9
|
+
*/
|
|
10
|
+
export declare class AnnouncementsAdminController {
|
|
11
|
+
private readonly repo;
|
|
12
|
+
private readonly cache;
|
|
13
|
+
constructor(repo: AnnouncementRepository, cache: StatusCache);
|
|
14
|
+
list(includeEnded?: string, limit?: string, offset?: string): Promise<Page<AnnouncementView>>;
|
|
15
|
+
create(admin: AdminPrincipal, body: AnnouncementInput): Promise<AnnouncementView>;
|
|
16
|
+
/** 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
|
+
ok: true;
|
|
20
|
+
}>;
|
|
21
|
+
maintenance(limit?: string, offset?: string): Promise<Page<MaintenanceView>>;
|
|
22
|
+
schedule(admin: AdminPrincipal, body: MaintenanceInput): Promise<MaintenanceView>;
|
|
23
|
+
/** "End now": ends an open window, or cancels a scheduled one. */
|
|
24
|
+
end(admin: AdminPrincipal, id: string): Promise<{
|
|
25
|
+
ok: true;
|
|
26
|
+
}>;
|
|
27
|
+
}
|