@haatlabs-core/templates 0.19.0 → 0.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/package.json +3 -3
- package/starter/apps/api/package.json.tmpl +1 -0
- package/starter/apps/api/src/app.module.ts +36 -0
- package/starter/apps/api/src/notifications.int.test.ts +210 -0
- package/starter/apps/api/src/security-sweep.int.test.ts +81 -12
- package/starter/apps/api/src/seed-plans.int.test.ts +8 -1
- package/starter/apps/api/src/seed.ts +16 -3
- package/starter/apps/shopify-app/index.html +2 -0
- package/starter/apps/shopify-app/public/theme-boot.js +6 -0
- package/starter/apps/web/public/notifications-sw.js +47 -0
- package/starter/apps/worker/package.json.tmpl +2 -0
- package/starter/apps/worker/src/handlers/notifications.handler.ts +63 -0
- package/starter/apps/worker/src/runtime.ts +52 -26
- package/starter/dot-env.example +16 -0
- package/starter/packages/config/src/config.test.ts +26 -0
- package/starter/packages/config/src/config.ts +11 -2
- package/starter/packages/contracts/package.json.tmpl +3 -1
- package/starter/packages/contracts/src/notifications.ts +38 -0
- package/starter/packages/database/drizzle/0009_notifications.sql +87 -0
- package/starter/packages/database/drizzle/0010_platform_vendorhaat.sql +5 -0
- package/starter/packages/database/drizzle/meta/0009_snapshot.json +2446 -0
- package/starter/packages/database/drizzle/meta/0010_snapshot.json +2467 -0
- package/starter/packages/database/drizzle/meta/_journal.json +14 -0
- package/starter/packages/database/package.json.tmpl +1 -0
- package/starter/packages/database/src/index.ts +1 -0
- package/starter/packages/database/src/repositories/billing.int.test.ts +5 -4
- package/starter/packages/database/src/repositories/notification.repository.ts +65 -0
- package/starter/packages/database/src/schema/index.ts +1 -0
- package/starter/packages/database/src/schema/notifications.ts +37 -0
- package/starter/packages/database/src/schema-tables.int.test.ts +10 -0
- package/starter/packages/queue/src/topology.test.ts +1 -0
- package/starter/packages/queue/src/topology.ts +3 -0
- package/starter/packages/web-ui/package.json.tmpl +1 -0
- package/starter/packages/web-ui/src/App.test.tsx +140 -6
- package/starter/packages/web-ui/src/App.tsx +129 -27
- package/starter/packages/web-ui/src/api-client.test.ts +204 -1
- package/starter/packages/web-ui/src/api-client.ts +207 -1
- package/starter/packages/web-ui/src/components/Logo.tsx +11 -3
- package/starter/packages/web-ui/src/pages/HomePage.tsx +3 -3
- package/starter/packages/web-ui/src/pages/LoginPage.tsx +3 -1
- package/starter/packages/web-ui/src/pages/NotificationSettingsPage.tsx +24 -0
- package/starter/packages/web-ui/src/pages/NotificationsPage.tsx +19 -0
- package/starter/packages/web-ui/src/styles.css +73 -37
- package/starter/packages/web-ui/src/testing/fake-client.ts +16 -0
|
@@ -57,8 +57,24 @@ import type {
|
|
|
57
57
|
CreateExtensionKeyResponse,
|
|
58
58
|
ExtensionKeyListResponse,
|
|
59
59
|
} from '@haatlabs-core/auth-contracts';
|
|
60
|
+
import {
|
|
61
|
+
NotificationItemSchema,
|
|
62
|
+
NotificationListSchema,
|
|
63
|
+
PreferencesSchema,
|
|
64
|
+
PushKeySchema,
|
|
65
|
+
UnreadSchema,
|
|
66
|
+
pushSubscribed,
|
|
67
|
+
pushSupport,
|
|
68
|
+
subscribeToPush,
|
|
69
|
+
unsubscribeFromPush,
|
|
70
|
+
} from '@haatlabs-core/notifications/browser';
|
|
60
71
|
import { ApiError, OkSchema, createTransport } from '@haatlabs-core/ui/client';
|
|
61
|
-
import type {
|
|
72
|
+
import type {
|
|
73
|
+
CredentialStrategy,
|
|
74
|
+
NotificationStreamEvent,
|
|
75
|
+
NotificationsClient,
|
|
76
|
+
Transport,
|
|
77
|
+
} from '@haatlabs-core/ui/client';
|
|
62
78
|
|
|
63
79
|
export type { CredentialStrategy } from '@haatlabs-core/ui/client';
|
|
64
80
|
|
|
@@ -128,6 +144,11 @@ export interface ApiClient {
|
|
|
128
144
|
listStores(): Promise<StoreListResponse>;
|
|
129
145
|
#@end
|
|
130
146
|
cancelRenewal(): Promise<{ cancelled: true }>;
|
|
147
|
+
/**
|
|
148
|
+
* The caller's notifications: the inbox, the live stream and the preferences, and push on
|
|
149
|
+
* this device (left out of the embedded app, whose frame cannot have push).
|
|
150
|
+
*/
|
|
151
|
+
notifications: NotificationsClient;
|
|
131
152
|
#@if standalone
|
|
132
153
|
/** The example page: images for a product name, from the Haatlabs API. */
|
|
133
154
|
findImages(q: string): Promise<FindImagesResponse>;
|
|
@@ -142,6 +163,187 @@ export interface ApiClient {
|
|
|
142
163
|
#@end
|
|
143
164
|
}
|
|
144
165
|
|
|
166
|
+
const NOTIFICATIONS = '/api/v1/notifications';
|
|
167
|
+
/** How long to wait before the stream is opened again, until the server says otherwise. */
|
|
168
|
+
const DEFAULT_STREAM_RETRY_MS = 10_000;
|
|
169
|
+
|
|
170
|
+
/** A route that answers 204 and no body when it is done; otherwise its error. */
|
|
171
|
+
async function noContent(transport: Transport, response: Response): Promise<void> {
|
|
172
|
+
if (response.ok) return;
|
|
173
|
+
throw transport.failure(await response.json().catch(() => null), response.status);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Resolves after `ms`, or at once when `signal` aborts. */
|
|
177
|
+
const wait = (ms: number, signal: AbortSignal): Promise<void> =>
|
|
178
|
+
new Promise((resolve) => {
|
|
179
|
+
if (signal.aborted) return resolve();
|
|
180
|
+
const done = (): void => {
|
|
181
|
+
clearTimeout(timer);
|
|
182
|
+
signal.removeEventListener('abort', done);
|
|
183
|
+
resolve();
|
|
184
|
+
};
|
|
185
|
+
const timer = setTimeout(done, ms);
|
|
186
|
+
signal.addEventListener('abort', done);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
/** One Server-Sent Events message: what the stream says and, when it says so, how long to wait. */
|
|
190
|
+
function parseEvent(block: string): { event?: NotificationStreamEvent; retryMs?: number } {
|
|
191
|
+
let name = 'message';
|
|
192
|
+
let data = '';
|
|
193
|
+
let retryMs: number | undefined;
|
|
194
|
+
for (const line of block.split('\n')) {
|
|
195
|
+
if (line === '' || line.startsWith(':')) continue;
|
|
196
|
+
const colon = line.indexOf(':');
|
|
197
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
198
|
+
const value = colon === -1 ? '' : line.slice(colon + 1).replace(/^ /, '');
|
|
199
|
+
if (field === 'event') name = value;
|
|
200
|
+
else if (field === 'data') data = data ? `${data}\n${value}` : value;
|
|
201
|
+
else if (field === 'retry' && /^\d+$/.test(value)) retryMs = Number(value);
|
|
202
|
+
}
|
|
203
|
+
if (!data) return { retryMs };
|
|
204
|
+
let payload: unknown;
|
|
205
|
+
try {
|
|
206
|
+
payload = JSON.parse(data);
|
|
207
|
+
} catch {
|
|
208
|
+
return { retryMs };
|
|
209
|
+
}
|
|
210
|
+
if (name === 'unread') {
|
|
211
|
+
const parsed = UnreadSchema.safeParse(payload);
|
|
212
|
+
return { retryMs, event: parsed.success ? { kind: 'unread', ...parsed.data } : undefined };
|
|
213
|
+
}
|
|
214
|
+
if (name === 'notification') {
|
|
215
|
+
const parsed = NotificationItemSchema.safeParse(payload);
|
|
216
|
+
return {
|
|
217
|
+
retryMs,
|
|
218
|
+
event: parsed.success ? { kind: 'notification', item: parsed.data } : undefined,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return { retryMs };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The notification routes. The stream is read with fetch, not EventSource, so that inside
|
|
226
|
+
* the embedded app it carries the session token as every other request does.
|
|
227
|
+
*/
|
|
228
|
+
function notificationsClient(
|
|
229
|
+
transport: Transport,
|
|
230
|
+
options: { credentials: CredentialStrategy; fetch: typeof fetch },
|
|
231
|
+
): NotificationsClient {
|
|
232
|
+
const { call, queryOf } = transport;
|
|
233
|
+
|
|
234
|
+
async function stream(
|
|
235
|
+
signal: AbortSignal,
|
|
236
|
+
onEvent: (event: NotificationStreamEvent) => void,
|
|
237
|
+
): Promise<void> {
|
|
238
|
+
const { credentials } = options;
|
|
239
|
+
const headers: Record<string, string> = { accept: 'text/event-stream' };
|
|
240
|
+
if (credentials.kind === 'bearer') {
|
|
241
|
+
try {
|
|
242
|
+
headers.authorization = `Bearer ${await credentials.getToken()}`;
|
|
243
|
+
} catch (error) {
|
|
244
|
+
const message = error instanceof Error ? error.message : 'No session token';
|
|
245
|
+
throw new ApiError('UNAUTHENTICATED', message, 401);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
let response: Response;
|
|
249
|
+
try {
|
|
250
|
+
response = await options.fetch(`${transport.baseUrl}${NOTIFICATIONS}/stream`, {
|
|
251
|
+
headers,
|
|
252
|
+
credentials: credentials.kind === 'cookie' ? 'include' : 'omit',
|
|
253
|
+
cache: 'no-store',
|
|
254
|
+
signal,
|
|
255
|
+
});
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (signal.aborted) return;
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
260
|
+
if (!response.ok || !response.body) {
|
|
261
|
+
throw transport.failure(await response.json().catch(() => null), response.status);
|
|
262
|
+
}
|
|
263
|
+
let retryMs = DEFAULT_STREAM_RETRY_MS;
|
|
264
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
265
|
+
const stop = (): void => void reader.cancel().catch(() => undefined);
|
|
266
|
+
signal.addEventListener('abort', stop);
|
|
267
|
+
let buffer = '';
|
|
268
|
+
// A '\r' that ends a chunk may be the first half of a '\r\n': held until the next one.
|
|
269
|
+
let held = '';
|
|
270
|
+
try {
|
|
271
|
+
// Aborted while the response was on its way: nothing would fire 'abort' again.
|
|
272
|
+
if (signal.aborted) {
|
|
273
|
+
stop();
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
for (;;) {
|
|
277
|
+
const { done, value } = await reader.read();
|
|
278
|
+
if (done) break;
|
|
279
|
+
let text = held + value;
|
|
280
|
+
held = text.endsWith('\r') ? '\r' : '';
|
|
281
|
+
if (held) text = text.slice(0, -1);
|
|
282
|
+
buffer = (buffer + text).replace(/\r\n?/g, '\n');
|
|
283
|
+
let end = buffer.indexOf('\n\n');
|
|
284
|
+
while (end !== -1) {
|
|
285
|
+
const parsed = parseEvent(buffer.slice(0, end));
|
|
286
|
+
buffer = buffer.slice(end + 2);
|
|
287
|
+
if (parsed.retryMs !== undefined) retryMs = parsed.retryMs;
|
|
288
|
+
if (parsed.event && !signal.aborted) onEvent(parsed.event);
|
|
289
|
+
end = buffer.indexOf('\n\n');
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
} catch (error) {
|
|
293
|
+
if (!signal.aborted) throw error;
|
|
294
|
+
} finally {
|
|
295
|
+
signal.removeEventListener('abort', stop);
|
|
296
|
+
}
|
|
297
|
+
// The server ended the stream: open it again no sooner than it asked.
|
|
298
|
+
await wait(retryMs, signal);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const push: NotificationsClient['push'] = {
|
|
302
|
+
support: () => pushSupport(),
|
|
303
|
+
enable: async () => {
|
|
304
|
+
const { webPush } = await call('GET', `${NOTIFICATIONS}/push/key`, PushKeySchema);
|
|
305
|
+
// Web Push is not set up on this server (no VAPID keys).
|
|
306
|
+
if (!webPush) return 'unsupported';
|
|
307
|
+
return subscribeToPush({
|
|
308
|
+
vapidPublicKey: webPush,
|
|
309
|
+
save: async (body) =>
|
|
310
|
+
noContent(
|
|
311
|
+
transport,
|
|
312
|
+
await transport.send('POST', `${NOTIFICATIONS}/push/subscriptions`, body),
|
|
313
|
+
),
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
isSubscribed: () => pushSubscribed(),
|
|
317
|
+
disable: () =>
|
|
318
|
+
unsubscribeFromPush(async (endpoint) =>
|
|
319
|
+
noContent(
|
|
320
|
+
transport,
|
|
321
|
+
await transport.send('DELETE', `${NOTIFICATIONS}/push/subscriptions`, { endpoint }),
|
|
322
|
+
),
|
|
323
|
+
),
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
list: (q) =>
|
|
328
|
+
call(
|
|
329
|
+
'GET',
|
|
330
|
+
`${NOTIFICATIONS}${queryOf({ unread: q.unread ? 'true' : undefined, cursor: q.cursor })}`,
|
|
331
|
+
NotificationListSchema,
|
|
332
|
+
),
|
|
333
|
+
unreadCount: async () =>
|
|
334
|
+
(await call('GET', `${NOTIFICATIONS}/unread-count`, UnreadSchema)).unread,
|
|
335
|
+
markRead: async (ids) =>
|
|
336
|
+
(await call('POST', `${NOTIFICATIONS}/read`, UnreadSchema, { ids })).unread,
|
|
337
|
+
markAllRead: async () => (await call('POST', `${NOTIFICATIONS}/read-all`, UnreadSchema)).unread,
|
|
338
|
+
stream,
|
|
339
|
+
preferences: () => call('GET', `${NOTIFICATIONS}/preferences`, PreferencesSchema),
|
|
340
|
+
setPreferences: (changes) =>
|
|
341
|
+
call('PUT', `${NOTIFICATIONS}/preferences`, PreferencesSchema, { changes }),
|
|
342
|
+
// The embedded app (a session token, not a cookie) is framed, and a frame cannot have push.
|
|
343
|
+
...(options.credentials.kind === 'cookie' ? { push } : {}),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
145
347
|
export function createApiClient(options: {
|
|
146
348
|
baseUrl?: string;
|
|
147
349
|
credentials: CredentialStrategy;
|
|
@@ -187,6 +389,10 @@ export function createApiClient(options: {
|
|
|
187
389
|
|
|
188
390
|
return {
|
|
189
391
|
admin,
|
|
392
|
+
notifications: notificationsClient(transport, {
|
|
393
|
+
credentials: options.credentials,
|
|
394
|
+
fetch: options.fetch ?? ((...args: Parameters<typeof fetch>) => fetch(...args)),
|
|
395
|
+
}),
|
|
190
396
|
me: async () => remember(await call('GET', '/api/v1/auth/me', MeResponseSchema)),
|
|
191
397
|
requestSignInCode: async (body) =>
|
|
192
398
|
void (await call('POST', '/api/v1/auth/code', OkSchema, body)),
|
|
@@ -16,7 +16,10 @@ const TILES: readonly (readonly [number, number])[] = [
|
|
|
16
16
|
const SIZE = { header: 24, panel: 30 } as const;
|
|
17
17
|
|
|
18
18
|
function Mark(props: { size: number; onDark: boolean; label?: string }): ReactElement {
|
|
19
|
-
|
|
19
|
+
// On the dashboard the mark follows the theme (dark tiles on light, light tiles on dark);
|
|
20
|
+
// on the sign-in panel it is always drawn for the dark ground.
|
|
21
|
+
const tile = props.onDark ? '#FFFFFF' : 'var(--hl-text, #15171C)';
|
|
22
|
+
const centre = props.onDark ? '#8FA6FF' : 'var(--hl-accent, #2447D6)';
|
|
20
23
|
const labelled = props.label
|
|
21
24
|
? { role: 'img', 'aria-label': props.label }
|
|
22
25
|
: { 'aria-hidden': true };
|
|
@@ -30,7 +33,7 @@ function Mark(props: { size: number; onDark: boolean; label?: string }): ReactEl
|
|
|
30
33
|
width={TILE}
|
|
31
34
|
height={TILE}
|
|
32
35
|
rx={2}
|
|
33
|
-
|
|
36
|
+
style={{ fill: tile }}
|
|
34
37
|
/>
|
|
35
38
|
))}
|
|
36
39
|
<rect
|
|
@@ -39,7 +42,7 @@ function Mark(props: { size: number; onDark: boolean; label?: string }): ReactEl
|
|
|
39
42
|
width={TILE}
|
|
40
43
|
height={TILE}
|
|
41
44
|
rx={2}
|
|
42
|
-
|
|
45
|
+
style={{ fill: centre }}
|
|
43
46
|
/>
|
|
44
47
|
</svg>
|
|
45
48
|
);
|
|
@@ -58,6 +61,11 @@ export function Logo(): ReactElement {
|
|
|
58
61
|
);
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
/** The mark alone: the collapsed sidebar's brand. */
|
|
65
|
+
export function LogoMark(): ReactElement {
|
|
66
|
+
return <Mark size={SIZE.panel} onDark={false} />;
|
|
67
|
+
}
|
|
68
|
+
|
|
61
69
|
/** The logo in the app header: a link home. */
|
|
62
70
|
export function LogoLink(): ReactElement {
|
|
63
71
|
return (
|
|
@@ -3,7 +3,7 @@ import type { ReactElement } from 'react';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Where a signed-in user lands. The app's own work begins here: replace this page with
|
|
6
|
-
* the first thing a merchant does, and add a line to the
|
|
6
|
+
* the first thing a merchant does, and add a line to the menu for each page after.
|
|
7
7
|
*/
|
|
8
8
|
export function HomePage({ organizationName }: { organizationName: string }): ReactElement {
|
|
9
9
|
return (
|
|
@@ -11,13 +11,13 @@ export function HomePage({ organizationName }: { organizationName: string }): Re
|
|
|
11
11
|
#@if kindShopify
|
|
12
12
|
<PageHeader
|
|
13
13
|
title="Home"
|
|
14
|
-
subtitle={`Signed in to @@Name@@ as ${organizationName}. Your stores and your plan are in the
|
|
14
|
+
subtitle={`Signed in to @@Name@@ as ${organizationName}. Your stores and your plan are in the menu.`}
|
|
15
15
|
/>
|
|
16
16
|
#@end
|
|
17
17
|
#@if !kindShopify
|
|
18
18
|
<PageHeader
|
|
19
19
|
title="Home"
|
|
20
|
-
subtitle={`Signed in to @@Name@@ as ${organizationName}. Your plan is in the
|
|
20
|
+
subtitle={`Signed in to @@Name@@ as ${organizationName}. Your plan is in the menu.`}
|
|
21
21
|
/>
|
|
22
22
|
#@end
|
|
23
23
|
</main>
|
|
@@ -5,12 +5,14 @@ import { LogoOnDark } from '../components/Logo';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Signing in has no password: a code is sent to the email, and giving it back signs the
|
|
8
|
-
* person in. The form is the platform's; what @@Name@@ is, beside it, is its own.
|
|
8
|
+
* person in. The form is the platform's; what @@Name@@ is, beside it, is its own. On a phone
|
|
9
|
+
* or tablet the panel gives way to a slim row, on the panel's dark ground, with the logo.
|
|
9
10
|
*/
|
|
10
11
|
export function LoginPage({ client }: { client: ApiClient }): ReactElement {
|
|
11
12
|
return (
|
|
12
13
|
<SignIn
|
|
13
14
|
client={client}
|
|
15
|
+
brand={<LogoOnDark />}
|
|
14
16
|
aside={
|
|
15
17
|
<section aria-label="About @@Name@@">
|
|
16
18
|
<LogoOnDark />
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PageHeader } from '@haatlabs-core/ui';
|
|
2
|
+
import { NotificationPreferences } from '@haatlabs-core/ui/client';
|
|
3
|
+
import type { NotificationsClient } from '@haatlabs-core/ui/client';
|
|
4
|
+
import type { ReactElement } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which notifications reach the signed-in person by email and push, and push on this device.
|
|
8
|
+
* Every notification email links here ("Change which emails you get").
|
|
9
|
+
*/
|
|
10
|
+
export function NotificationSettingsPage({
|
|
11
|
+
client,
|
|
12
|
+
}: {
|
|
13
|
+
client: NotificationsClient;
|
|
14
|
+
}): ReactElement {
|
|
15
|
+
return (
|
|
16
|
+
<main className="page">
|
|
17
|
+
<PageHeader
|
|
18
|
+
title="Notification settings"
|
|
19
|
+
subtitle="Everything still reaches your inbox: these choose what also comes by email and push."
|
|
20
|
+
/>
|
|
21
|
+
<NotificationPreferences client={client} />
|
|
22
|
+
</main>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PageHeader } from '@haatlabs-core/ui';
|
|
2
|
+
import { NotificationInbox } from '@haatlabs-core/ui/client';
|
|
3
|
+
import type { NotificationsClient } from '@haatlabs-core/ui/client';
|
|
4
|
+
import type { ReactElement } from 'react';
|
|
5
|
+
import { Link, useNavigate } from 'react-router-dom';
|
|
6
|
+
|
|
7
|
+
/** Everything the signed-in person was notified of, newest first; the bell's "See all". */
|
|
8
|
+
export function NotificationsPage({ client }: { client: NotificationsClient }): ReactElement {
|
|
9
|
+
const navigate = useNavigate();
|
|
10
|
+
return (
|
|
11
|
+
<main className="page">
|
|
12
|
+
<PageHeader
|
|
13
|
+
title="Notifications"
|
|
14
|
+
actions={<Link to="/settings/notifications">Choose what you get</Link>}
|
|
15
|
+
/>
|
|
16
|
+
<NotificationInbox client={client} onOpenItem={(link) => void navigate(link)} />
|
|
17
|
+
</main>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -1121,7 +1121,10 @@ article.candidate ul {
|
|
|
1121
1121
|
border: 0;
|
|
1122
1122
|
background: transparent;
|
|
1123
1123
|
color: var(--ink);
|
|
1124
|
-
|
|
1124
|
+
cursor: pointer;
|
|
1125
|
+
}
|
|
1126
|
+
.auth button.link:hover {
|
|
1127
|
+
color: var(--accent);
|
|
1125
1128
|
}
|
|
1126
1129
|
|
|
1127
1130
|
/* --- Plan comparison --- */
|
|
@@ -1224,19 +1227,12 @@ table.compare tfoot button + button {
|
|
|
1224
1227
|
#@if !kindShopify
|
|
1225
1228
|
* The embedded app sits in its host's own frame, so it follows that frame's look rather
|
|
1226
1229
|
#@end
|
|
1227
|
-
* than the standalone dashboard's: system type at 13px,
|
|
1228
|
-
*
|
|
1229
|
-
* `embedded` class on the
|
|
1230
|
+
* than the standalone dashboard's: system type at 13px, compact controls and plain table
|
|
1231
|
+
* headings. Its colours are still the dashboard theme's tokens (`--hl-*`), so the theme
|
|
1232
|
+
* switch (light, dark or the system's) works here too. App sets the `embedded` class on the
|
|
1233
|
+
* root element.
|
|
1230
1234
|
*/
|
|
1231
1235
|
:root.embedded {
|
|
1232
|
-
--ground: #f1f1f1;
|
|
1233
|
-
--ink: #303030;
|
|
1234
|
-
--ink-soft: #4a4a4a;
|
|
1235
|
-
--muted: #616161;
|
|
1236
|
-
--line: #e3e3e3;
|
|
1237
|
-
--line-soft: #ebebeb;
|
|
1238
|
-
--control-line: #8a8a8a;
|
|
1239
|
-
--accent: #303030;
|
|
1240
1236
|
--high-ink: #0c5132;
|
|
1241
1237
|
--high-ground: #cdfee1;
|
|
1242
1238
|
--review-ink: #5e4200;
|
|
@@ -1251,10 +1247,35 @@ table.compare tfoot button + button {
|
|
|
1251
1247
|
Inter, -apple-system, BlinkMacSystemFont, 'San Francisco', 'Segoe UI', Roboto, 'Helvetica Neue',
|
|
1252
1248
|
sans-serif;
|
|
1253
1249
|
--control: 28px;
|
|
1254
|
-
--card-shadow:
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1250
|
+
--card-shadow: 0 0 0 1px var(--hl-border), 0 1px 2px rgba(0, 0, 0, 0.06);
|
|
1251
|
+
--button-shadow: 0 0 0 1px var(--hl-border) inset;
|
|
1252
|
+
}
|
|
1253
|
+
/* The status chips on the dark theme, chosen or the system's: dark grounds, light ink. */
|
|
1254
|
+
:root.embedded[data-theme="dark"] {
|
|
1255
|
+
--high-ink: #7ee2a8;
|
|
1256
|
+
--high-ground: #143323;
|
|
1257
|
+
--review-ink: #f5c871;
|
|
1258
|
+
--review-ground: #352a10;
|
|
1259
|
+
--neutral-ink: #c9ccd3;
|
|
1260
|
+
--neutral-ground: #2c2f36;
|
|
1261
|
+
--danger-ink: #ff9c8f;
|
|
1262
|
+
--danger-ground: #3f1a16;
|
|
1263
|
+
--info-ink: #9cc8ff;
|
|
1264
|
+
--info-ground: #142a40;
|
|
1265
|
+
}
|
|
1266
|
+
@media (prefers-color-scheme: dark) {
|
|
1267
|
+
:root.embedded:not([data-theme]) {
|
|
1268
|
+
--high-ink: #7ee2a8;
|
|
1269
|
+
--high-ground: #143323;
|
|
1270
|
+
--review-ink: #f5c871;
|
|
1271
|
+
--review-ground: #352a10;
|
|
1272
|
+
--neutral-ink: #c9ccd3;
|
|
1273
|
+
--neutral-ground: #2c2f36;
|
|
1274
|
+
--danger-ink: #ff9c8f;
|
|
1275
|
+
--danger-ground: #3f1a16;
|
|
1276
|
+
--info-ink: #9cc8ff;
|
|
1277
|
+
--info-ground: #142a40;
|
|
1278
|
+
}
|
|
1258
1279
|
}
|
|
1259
1280
|
.embedded body {
|
|
1260
1281
|
font-size: 13px;
|
|
@@ -1294,8 +1315,17 @@ table.compare tfoot button + button {
|
|
|
1294
1315
|
/* The one navigation: quiet tabs above the page. */
|
|
1295
1316
|
#@end
|
|
1296
1317
|
.embedded-nav {
|
|
1318
|
+
display: flex;
|
|
1319
|
+
align-items: center;
|
|
1320
|
+
justify-content: space-between;
|
|
1321
|
+
gap: 8px;
|
|
1297
1322
|
padding: 8px 16px 0;
|
|
1298
1323
|
}
|
|
1324
|
+
/* Below 1024px the tabs give way to the bottom bar: the bell keeps the row's right end, and
|
|
1325
|
+
the page ends above the bar (under "Full width" below). */
|
|
1326
|
+
.embedded-nav .hl-notify {
|
|
1327
|
+
margin-left: auto;
|
|
1328
|
+
}
|
|
1299
1329
|
.embedded-nav .store-nav {
|
|
1300
1330
|
margin: 0;
|
|
1301
1331
|
gap: 4px;
|
|
@@ -1309,10 +1339,12 @@ table.compare tfoot button + button {
|
|
|
1309
1339
|
font-weight: 550;
|
|
1310
1340
|
}
|
|
1311
1341
|
.embedded .store-nav a:hover {
|
|
1312
|
-
background:
|
|
1342
|
+
background: var(--hl-faint);
|
|
1343
|
+
color: var(--hl-text);
|
|
1313
1344
|
}
|
|
1314
1345
|
.embedded .store-nav a[aria-current='page'] {
|
|
1315
|
-
background:
|
|
1346
|
+
background: var(--hl-accent-soft);
|
|
1347
|
+
color: var(--hl-accent-text);
|
|
1316
1348
|
box-shadow: none;
|
|
1317
1349
|
font-weight: 650;
|
|
1318
1350
|
}
|
|
@@ -1330,6 +1362,13 @@ table.compare tfoot button + button {
|
|
|
1330
1362
|
padding: 8px 16px 32px;
|
|
1331
1363
|
gap: 8px;
|
|
1332
1364
|
}
|
|
1365
|
+
@media (max-width: 1023px) {
|
|
1366
|
+
.embedded main,
|
|
1367
|
+
.embedded main.narrow,
|
|
1368
|
+
.embedded main.medium {
|
|
1369
|
+
padding-bottom: calc(56px + 32px + env(safe-area-inset-bottom));
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1333
1372
|
/*
|
|
1334
1373
|
* The page scrolls at the window's edge; a form page's content keeps a readable width,
|
|
1335
1374
|
#@if kindShopify
|
|
@@ -1380,31 +1419,28 @@ table.compare tfoot button + button {
|
|
|
1380
1419
|
}
|
|
1381
1420
|
.embedded button:hover:not(:disabled),
|
|
1382
1421
|
.embedded .button:hover {
|
|
1383
|
-
background:
|
|
1422
|
+
background: var(--hl-faint);
|
|
1384
1423
|
}
|
|
1385
1424
|
.embedded button:disabled {
|
|
1386
|
-
background:
|
|
1425
|
+
background: var(--hl-faint);
|
|
1387
1426
|
box-shadow: none;
|
|
1388
|
-
color:
|
|
1427
|
+
color: var(--hl-muted);
|
|
1389
1428
|
}
|
|
1390
1429
|
.embedded button.primary,
|
|
1391
1430
|
.embedded button[type='submit'] {
|
|
1392
|
-
background:
|
|
1393
|
-
box-shadow:
|
|
1394
|
-
|
|
1395
|
-
0 0 0 1px #303030 inset,
|
|
1396
|
-
0 0.5px 0 1.5px rgba(255, 255, 255, 0.25) inset;
|
|
1397
|
-
color: #ffffff;
|
|
1431
|
+
background: var(--hl-accent);
|
|
1432
|
+
box-shadow: 0 -1px 0 0 rgba(0, 0, 0, 0.25) inset;
|
|
1433
|
+
color: var(--hl-on-accent);
|
|
1398
1434
|
}
|
|
1399
1435
|
.embedded button.primary:hover:not(:disabled),
|
|
1400
1436
|
.embedded button[type='submit']:hover:not(:disabled) {
|
|
1401
|
-
background: #
|
|
1437
|
+
background: color-mix(in srgb, var(--hl-accent) 85%, #000000);
|
|
1402
1438
|
}
|
|
1403
1439
|
.embedded button.primary:disabled,
|
|
1404
1440
|
.embedded button[type='submit']:disabled {
|
|
1405
|
-
background:
|
|
1441
|
+
background: var(--hl-faint);
|
|
1406
1442
|
box-shadow: none;
|
|
1407
|
-
color:
|
|
1443
|
+
color: var(--hl-muted);
|
|
1408
1444
|
}
|
|
1409
1445
|
#@if kindShopify
|
|
1410
1446
|
/* Filters: Shopify's view tabs. */
|
|
@@ -1419,11 +1455,11 @@ table.compare tfoot button + button {
|
|
|
1419
1455
|
font-weight: 550;
|
|
1420
1456
|
}
|
|
1421
1457
|
.embedded button[aria-pressed]:hover {
|
|
1422
|
-
background:
|
|
1458
|
+
background: var(--hl-faint);
|
|
1423
1459
|
}
|
|
1424
1460
|
.embedded button[aria-pressed='true'] {
|
|
1425
|
-
background:
|
|
1426
|
-
color: var(--
|
|
1461
|
+
background: var(--hl-accent-soft);
|
|
1462
|
+
color: var(--hl-accent-text);
|
|
1427
1463
|
font-weight: 650;
|
|
1428
1464
|
}
|
|
1429
1465
|
.embedded input:not([type='radio'], [type='checkbox']),
|
|
@@ -1475,7 +1511,7 @@ table.compare tfoot button + button {
|
|
|
1475
1511
|
}
|
|
1476
1512
|
.embedded thead th {
|
|
1477
1513
|
padding: 8px 12px;
|
|
1478
|
-
background:
|
|
1514
|
+
background: var(--hl-sidebar);
|
|
1479
1515
|
font-size: 12px;
|
|
1480
1516
|
font-weight: 550;
|
|
1481
1517
|
text-transform: none;
|
|
@@ -1488,14 +1524,14 @@ table.compare tfoot button + button {
|
|
|
1488
1524
|
align-items: center;
|
|
1489
1525
|
}
|
|
1490
1526
|
.embedded tbody tr:hover {
|
|
1491
|
-
background:
|
|
1527
|
+
background: var(--hl-faint);
|
|
1492
1528
|
}
|
|
1493
1529
|
.embedded td img {
|
|
1494
1530
|
width: 40px;
|
|
1495
1531
|
height: 40px;
|
|
1496
1532
|
border: 1px solid var(--line);
|
|
1497
1533
|
border-radius: 8px;
|
|
1498
|
-
background:
|
|
1534
|
+
background: var(--hl-surface);
|
|
1499
1535
|
}
|
|
1500
1536
|
.embedded article.candidate {
|
|
1501
1537
|
border: 0;
|
|
@@ -1650,7 +1686,7 @@ table.compare tfoot button + button {
|
|
|
1650
1686
|
overflow: auto;
|
|
1651
1687
|
}
|
|
1652
1688
|
.embedded .board-column {
|
|
1653
|
-
background:
|
|
1689
|
+
background: var(--hl-faint);
|
|
1654
1690
|
}
|
|
1655
1691
|
.embedded .board-column h2 {
|
|
1656
1692
|
font-size: 13px;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ALL_FEATURES_ON } from '@@@name@@/contracts';
|
|
2
2
|
import type { AdminMe, AdminOrganizationList, AdminOverview, MeResponse } from '@@@name@@/contracts';
|
|
3
|
+
import type { NotificationsClient } from '@haatlabs-core/ui/client';
|
|
3
4
|
import { vi } from 'vitest';
|
|
4
5
|
import type { ApiClient } from '../api-client';
|
|
5
6
|
|
|
@@ -14,6 +15,7 @@ export const me: MeResponse = {
|
|
|
14
15
|
via: 'session',
|
|
15
16
|
csrfToken: 'csrf',
|
|
16
17
|
storeOnly: false,
|
|
18
|
+
organizationCount: 1,
|
|
17
19
|
features: ALL_FEATURES_ON,
|
|
18
20
|
};
|
|
19
21
|
|
|
@@ -83,6 +85,19 @@ export const shopStore = {
|
|
|
83
85
|
};
|
|
84
86
|
#@end
|
|
85
87
|
|
|
88
|
+
/** An empty inbox, no stream (the bell polls) and no push. */
|
|
89
|
+
export const fakeNotifications = (
|
|
90
|
+
overrides: Partial<NotificationsClient> = {},
|
|
91
|
+
): NotificationsClient => ({
|
|
92
|
+
list: vi.fn().mockResolvedValue({ items: [], nextCursor: null }),
|
|
93
|
+
unreadCount: vi.fn().mockResolvedValue(0),
|
|
94
|
+
markRead: vi.fn().mockResolvedValue(0),
|
|
95
|
+
markAllRead: vi.fn().mockResolvedValue(0),
|
|
96
|
+
preferences: vi.fn().mockResolvedValue({ events: [] }),
|
|
97
|
+
setPreferences: vi.fn().mockResolvedValue({ events: [] }),
|
|
98
|
+
...overrides,
|
|
99
|
+
});
|
|
100
|
+
|
|
86
101
|
export const fakeClient = (overrides: Partial<ApiClient> = {}): ApiClient => ({
|
|
87
102
|
me: vi.fn().mockResolvedValue(me),
|
|
88
103
|
requestSignInCode: vi.fn().mockResolvedValue(undefined),
|
|
@@ -117,6 +132,7 @@ export const fakeClient = (overrides: Partial<ApiClient> = {}): ApiClient => ({
|
|
|
117
132
|
listPlans: vi.fn().mockResolvedValue({ plans: [], providers: [] }),
|
|
118
133
|
startCheckout: vi.fn().mockResolvedValue({ url: 'https://pay.example/checkout' }),
|
|
119
134
|
cancelRenewal: vi.fn().mockResolvedValue({ cancelled: true }),
|
|
135
|
+
notifications: fakeNotifications(),
|
|
120
136
|
#@if standalone
|
|
121
137
|
findImages: vi.fn().mockResolvedValue({ configured: false, message: 'Set HAATLABS_API_KEY' }),
|
|
122
138
|
#@end
|