@epic-web/workshop-utils 5.20.4 → 5.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/apps.server.d.ts +448 -448
- package/dist/esm/cache.server.d.ts +159 -120
- package/dist/esm/cache.server.d.ts.map +1 -1
- package/dist/esm/cache.server.js +1 -0
- package/dist/esm/cache.server.js.map +1 -1
- package/dist/esm/config.server.d.ts +68 -14
- package/dist/esm/config.server.d.ts.map +1 -1
- package/dist/esm/config.server.js +11 -0
- package/dist/esm/config.server.js.map +1 -1
- package/dist/esm/db.server.d.ts +6 -6
- package/dist/esm/env.server.d.ts +3 -3
- package/dist/esm/epic-api.server.d.ts +7 -7
- package/dist/esm/notifications.server.d.ts +56 -0
- package/dist/esm/notifications.server.d.ts.map +1 -0
- package/dist/esm/notifications.server.js +65 -0
- package/dist/esm/notifications.server.js.map +1 -0
- package/package.json +9 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import json5 from 'json5';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { cachified, notificationsCache } from './cache.server.js';
|
|
4
|
+
import { getWorkshopConfig } from './config.server.js';
|
|
5
|
+
import { getMutedNotifications } from './db.server.js';
|
|
6
|
+
const NotificationSchema = z.object({
|
|
7
|
+
id: z.string(),
|
|
8
|
+
title: z.string(),
|
|
9
|
+
message: z.string(),
|
|
10
|
+
link: z.string().optional(),
|
|
11
|
+
type: z.enum(['info', 'warning', 'danger']),
|
|
12
|
+
products: z
|
|
13
|
+
.array(z.object({
|
|
14
|
+
host: z.string(),
|
|
15
|
+
slug: z.string().optional(),
|
|
16
|
+
}))
|
|
17
|
+
.optional(),
|
|
18
|
+
expiresAt: z
|
|
19
|
+
.string()
|
|
20
|
+
.nullable()
|
|
21
|
+
.transform((val) => (val ? new Date(val) : null)),
|
|
22
|
+
});
|
|
23
|
+
async function getRemoteNotifications() {
|
|
24
|
+
return cachified({
|
|
25
|
+
key: 'notifications',
|
|
26
|
+
cache: notificationsCache,
|
|
27
|
+
ttl: 1000 * 60 * 60 * 6,
|
|
28
|
+
swr: 1000 * 60 * 60 * 24,
|
|
29
|
+
offlineFallbackValue: [],
|
|
30
|
+
async getFreshValue() {
|
|
31
|
+
const URL = 'https://gist.github.com/kentcdodds/c3aaa5141f591cdbb0e6bfcacd361f39';
|
|
32
|
+
const filename = 'notifications.json5';
|
|
33
|
+
const response = await fetch(`${URL}/raw/${filename}`);
|
|
34
|
+
const text = await response.text();
|
|
35
|
+
const json = json5.parse(text);
|
|
36
|
+
return NotificationSchema.array().parse(json);
|
|
37
|
+
},
|
|
38
|
+
}).catch(() => []);
|
|
39
|
+
}
|
|
40
|
+
export async function getUnmutedNotifications() {
|
|
41
|
+
if (ENV.EPICSHOP_DEPLOYED)
|
|
42
|
+
return [];
|
|
43
|
+
const remoteNotifications = await getRemoteNotifications();
|
|
44
|
+
const config = getWorkshopConfig();
|
|
45
|
+
const notificationsToShow = remoteNotifications
|
|
46
|
+
.filter((n) => {
|
|
47
|
+
if (n.expiresAt && n.expiresAt < new Date()) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
})
|
|
52
|
+
.filter((n) => {
|
|
53
|
+
if (!n.products)
|
|
54
|
+
return true;
|
|
55
|
+
return n.products.some((p) => {
|
|
56
|
+
return (p.host === config.product.host &&
|
|
57
|
+
(p.slug ? p.slug === config.product.slug : true));
|
|
58
|
+
});
|
|
59
|
+
})
|
|
60
|
+
.concat(config.notifications);
|
|
61
|
+
const muted = await getMutedNotifications();
|
|
62
|
+
const visibleNotifications = notificationsToShow.filter((n) => !muted.includes(n.id));
|
|
63
|
+
return visibleNotifications;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=notifications.server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifications.server.js","sourceRoot":"","sources":["../../src/notifications.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,M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,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAChD,CAAA;QACF,CAAC,CAAC,CAAA;IACH,CAAC,CAAC;SACD,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;IAE9B,MAAM,KAAK,GAAG,MAAM,qBAAqB,EAAE,CAAA;IAE3C,MAAM,oBAAoB,GAAG,mBAAmB,CAAC,MAAM,CACtD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAC5B,CAAA;IAED,OAAO,oBAAoB,CAAA;AAC5B,CAAC","sourcesContent":["import json5 from 'json5'\nimport { z } from 'zod'\nimport { cachified, notificationsCache } from './cache.server.js'\nimport { getWorkshopConfig } from './config.server.js'\nimport { getMutedNotifications } from './db.server.js'\n\nconst NotificationSchema = z.object({\n\tid: z.string(),\n\ttitle: z.string(),\n\tmessage: z.string(),\n\tlink: z.string().optional(),\n\ttype: z.enum(['info', 'warning', 'danger']),\n\tproducts: z\n\t\t.array(\n\t\t\tz.object({\n\t\t\t\thost: z.string(),\n\t\t\t\tslug: z.string().optional(),\n\t\t\t}),\n\t\t)\n\t\t.optional(),\n\texpiresAt: z\n\t\t.string()\n\t\t.nullable()\n\t\t.transform((val) => (val ? new Date(val) : null)),\n})\n\nexport type Notification = z.infer<typeof NotificationSchema>\n\nasync function getRemoteNotifications() {\n\treturn cachified({\n\t\tkey: 'notifications',\n\t\tcache: notificationsCache,\n\t\tttl: 1000 * 60 * 60 * 6,\n\t\tswr: 1000 * 60 * 60 * 24,\n\t\tofflineFallbackValue: [],\n\t\tasync getFreshValue() {\n\t\t\tconst URL =\n\t\t\t\t'https://gist.github.com/kentcdodds/c3aaa5141f591cdbb0e6bfcacd361f39'\n\t\t\tconst filename = 'notifications.json5'\n\t\t\tconst response = await fetch(`${URL}/raw/${filename}`)\n\t\t\tconst text = await response.text()\n\t\t\tconst json = json5.parse(text)\n\n\t\t\treturn NotificationSchema.array().parse(json)\n\t\t},\n\t}).catch(() => [])\n}\n\nexport async function getUnmutedNotifications() {\n\tif (ENV.EPICSHOP_DEPLOYED) return []\n\n\tconst remoteNotifications = await getRemoteNotifications()\n\n\tconst config = getWorkshopConfig()\n\n\tconst notificationsToShow = remoteNotifications\n\t\t.filter((n) => {\n\t\t\tif (n.expiresAt && n.expiresAt < new Date()) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\t.filter((n) => {\n\t\t\tif (!n.products) return true\n\t\t\treturn n.products.some((p) => {\n\t\t\t\treturn (\n\t\t\t\t\tp.host === config.product.host &&\n\t\t\t\t\t(p.slug ? p.slug === config.product.slug : true)\n\t\t\t\t)\n\t\t\t})\n\t\t})\n\t\t.concat(config.notifications)\n\n\tconst muted = await getMutedNotifications()\n\n\tconst visibleNotifications = notificationsToShow.filter(\n\t\t(n) => !muted.includes(n.id),\n\t)\n\n\treturn visibleNotifications\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epic-web/workshop-utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.21.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"./git.server": "./src/git.server.ts",
|
|
27
27
|
"./iframe-sync": "./src/iframe-sync.ts",
|
|
28
28
|
"./playwright.server": "./src/playwright.server.ts",
|
|
29
|
+
"./notifications.server": "./src/notifications.server.ts",
|
|
29
30
|
"./process-manager.server": "./src/process-manager.server.ts",
|
|
30
31
|
"./test": "./src/test.ts",
|
|
31
32
|
"./utils.server": "./src/utils.server.ts",
|
|
@@ -118,6 +119,12 @@
|
|
|
118
119
|
"default": "./dist/esm/playwright.server.js"
|
|
119
120
|
}
|
|
120
121
|
},
|
|
122
|
+
"./notifications.server": {
|
|
123
|
+
"import": {
|
|
124
|
+
"types": "./dist/esm/notifications.server.d.ts",
|
|
125
|
+
"default": "./dist/esm/notifications.server.js"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
121
128
|
"./process-manager.server": {
|
|
122
129
|
"import": {
|
|
123
130
|
"types": "./dist/esm/process-manager.server.d.ts",
|
|
@@ -181,6 +188,7 @@
|
|
|
181
188
|
"fs-extra": "^11.2.0",
|
|
182
189
|
"globby": "^14.0.2",
|
|
183
190
|
"ignore": "^5.3.2",
|
|
191
|
+
"json5": "^2.2.3",
|
|
184
192
|
"lru-cache": "^11.0.1",
|
|
185
193
|
"md5-hex": "^5.0.0",
|
|
186
194
|
"mdast-util-mdx-jsx": "^3.1.3",
|