@epic-web/workshop-utils 5.20.4 → 5.22.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 +7 -6
- package/dist/esm/db.server.d.ts.map +1 -1
- package/dist/esm/db.server.js +13 -0
- package/dist/esm/db.server.js.map +1 -1
- 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
|
@@ -17,13 +17,13 @@ declare function getEpicVideoInfo({ epicVideoEmbed, accessToken, request, timing
|
|
|
17
17
|
muxPlaybackId: string;
|
|
18
18
|
statusCode: number;
|
|
19
19
|
} | {
|
|
20
|
-
type: "unknown";
|
|
21
20
|
status: "error";
|
|
21
|
+
type: "unknown";
|
|
22
22
|
statusText: string;
|
|
23
23
|
statusCode: number;
|
|
24
24
|
} | {
|
|
25
|
-
type: "region-restricted";
|
|
26
25
|
status: "error";
|
|
26
|
+
type: "region-restricted";
|
|
27
27
|
statusText: string;
|
|
28
28
|
requestCountry: string;
|
|
29
29
|
restrictedCountry: string;
|
|
@@ -143,9 +143,9 @@ declare const UserInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
143
143
|
}>>>;
|
|
144
144
|
}, "strip", z.ZodTypeAny, {
|
|
145
145
|
name: string | null;
|
|
146
|
-
image: string | null;
|
|
147
146
|
id: string;
|
|
148
147
|
email: string;
|
|
148
|
+
image: string | null;
|
|
149
149
|
discordProfile?: {
|
|
150
150
|
nick: string | null;
|
|
151
151
|
user: {
|
|
@@ -157,9 +157,9 @@ declare const UserInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
157
157
|
} | null | undefined;
|
|
158
158
|
}, {
|
|
159
159
|
name: string | null;
|
|
160
|
-
image: string | null;
|
|
161
160
|
id: string;
|
|
162
161
|
email: string;
|
|
162
|
+
image: string | null;
|
|
163
163
|
discordProfile?: {
|
|
164
164
|
nick: string | null;
|
|
165
165
|
user: {
|
|
@@ -173,9 +173,9 @@ declare const UserInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
173
173
|
imageUrlSmall: string | null;
|
|
174
174
|
imageUrlLarge: string | null;
|
|
175
175
|
name: string | null;
|
|
176
|
-
image: string | null;
|
|
177
176
|
id: string;
|
|
178
177
|
email: string;
|
|
178
|
+
image: string | null;
|
|
179
179
|
discordProfile?: {
|
|
180
180
|
nick: string | null;
|
|
181
181
|
user: {
|
|
@@ -187,9 +187,9 @@ declare const UserInfoSchema: z.ZodEffects<z.ZodObject<{
|
|
|
187
187
|
} | null | undefined;
|
|
188
188
|
}, {
|
|
189
189
|
name: string | null;
|
|
190
|
-
image: string | null;
|
|
191
190
|
id: string;
|
|
192
191
|
email: string;
|
|
192
|
+
image: string | null;
|
|
193
193
|
discordProfile?: {
|
|
194
194
|
nick: string | null;
|
|
195
195
|
user: {
|
|
@@ -209,9 +209,9 @@ export declare function getUserInfo({ timings, request, forceFresh, }?: {
|
|
|
209
209
|
imageUrlSmall: string | null;
|
|
210
210
|
imageUrlLarge: string | null;
|
|
211
211
|
name: string | null;
|
|
212
|
-
image: string | null;
|
|
213
212
|
id: string;
|
|
214
213
|
email: string;
|
|
214
|
+
image: string | null;
|
|
215
215
|
discordProfile?: {
|
|
216
216
|
nick: string | null;
|
|
217
217
|
user: {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const NotificationSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
title: z.ZodString;
|
|
5
|
+
message: z.ZodString;
|
|
6
|
+
link: z.ZodOptional<z.ZodString>;
|
|
7
|
+
type: z.ZodEnum<["info", "warning", "danger"]>;
|
|
8
|
+
products: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
9
|
+
host: z.ZodString;
|
|
10
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
host: string;
|
|
13
|
+
slug?: string | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
host: string;
|
|
16
|
+
slug?: string | undefined;
|
|
17
|
+
}>, "many">>;
|
|
18
|
+
expiresAt: z.ZodEffects<z.ZodNullable<z.ZodString>, Date | null, string | null>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
title: string;
|
|
21
|
+
message: string;
|
|
22
|
+
type: "info" | "warning" | "danger";
|
|
23
|
+
id: string;
|
|
24
|
+
expiresAt: Date | null;
|
|
25
|
+
link?: string | undefined;
|
|
26
|
+
products?: {
|
|
27
|
+
host: string;
|
|
28
|
+
slug?: string | undefined;
|
|
29
|
+
}[] | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
title: string;
|
|
32
|
+
message: string;
|
|
33
|
+
type: "info" | "warning" | "danger";
|
|
34
|
+
id: string;
|
|
35
|
+
expiresAt: string | null;
|
|
36
|
+
link?: string | undefined;
|
|
37
|
+
products?: {
|
|
38
|
+
host: string;
|
|
39
|
+
slug?: string | undefined;
|
|
40
|
+
}[] | undefined;
|
|
41
|
+
}>;
|
|
42
|
+
export type Notification = z.infer<typeof NotificationSchema>;
|
|
43
|
+
export declare function getUnmutedNotifications(): Promise<{
|
|
44
|
+
title: string;
|
|
45
|
+
message: string;
|
|
46
|
+
type: "info" | "warning" | "danger";
|
|
47
|
+
id: string;
|
|
48
|
+
expiresAt: Date | null;
|
|
49
|
+
link?: string | undefined;
|
|
50
|
+
products?: {
|
|
51
|
+
host: string;
|
|
52
|
+
slug?: string | undefined;
|
|
53
|
+
}[] | undefined;
|
|
54
|
+
}[]>;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=notifications.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifications.server.d.ts","sourceRoot":"","sources":["../../src/notifications.server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAKvB,QAAA,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBtB,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAsB7D,wBAAsB,uBAAuB;;;;;;;;;;;KAgC5C"}
|
|
@@ -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,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,CA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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.22.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",
|