@frigear-nu/shifts 0.1.0 → 0.1.2

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/module.d.mts CHANGED
@@ -197,8 +197,8 @@ type ShiftScheduleDto = {
197
197
  autoNoShow: boolean;
198
198
  autoNoShowMinutes: number;
199
199
  /**
200
- * Whether the server has a station key (`NUXT_SHIFTS_STATION_KEY`). Without one, `station` check-in and station
201
- * screens answer 501 `not_configured`, whatever `checkIn.modes` says. A fact of the deployment, the same on every schedule.
200
+ * Whether the server has a station key (`NUXT_SHIFTS_STATION_KEY`, else one derived from `NUXT_APP_SECRET`). Without
201
+ * one, `station` check-in and station screens answer 501 `not_configured`, whatever `checkIn.modes` says. A fact of the deployment, the same on every schedule.
202
202
  */
203
203
  stationKeyConfigured: boolean;
204
204
  publishedAt: string | null;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frigear-nu/shifts",
3
3
  "configKey": "shifts",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.4",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { defineNuxtModule, createResolver, hasNuxtModule, addServerImportsDir, addServerPlugin, addImports, addComponentsDir } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, hasNuxtModule, addServerImportsDir, addNitroPlugin, addImports, addComponentsDir } from '@nuxt/kit';
2
2
  import { registerModule, registerTailwindSource, registerLocales, resolveDashboardHubPath, isPathUnder, resolvePagePath, registerDatabaseTable, addModuleRoutes, inlineModuleRuntime, addModulePages, addPageRedirects } from '@frigear-nu/module-kit/utils';
3
3
  import { extendMaps, defineMapLayer } from '@frigear-nu/maps/utils';
4
4
  import { OPERATIONS_VENUE_SURFACE } from '@frigear-nu/operations/utils';
@@ -156,8 +156,8 @@ const module$1 = defineNuxtModule({
156
156
  ], { base: "/api/admin/shifts" });
157
157
  addServerImportsDir(resolver.resolve("./runtime/server/utils"));
158
158
  inlineModuleRuntime(nuxt, resolver);
159
- addServerPlugin(resolver.resolve("./runtime/server/plugins/teams"));
160
- addServerPlugin(resolver.resolve("./runtime/server/plugins/station-key"));
159
+ addNitroPlugin(resolver.resolve("./runtime/server/plugins/teams"));
160
+ addNitroPlugin(resolver.resolve("./runtime/server/plugins/station-key"));
161
161
  nuxt.hook("notify:email:templates", (sources) => sources.push({ dir: resolver.resolve("./runtime/emails") }));
162
162
  const tasks = [
163
163
  {
@@ -32,7 +32,7 @@ const stationInUse = computed(() => modes.value.includes("station") || overrides
32
32
  const modeItemsFor = (selected) => [
33
33
  {
34
34
  label: t("checkIn.modes.station", "Station"),
35
- description: stationReady.value ? t("checkIn.modes.stationHelp", "Volunteers scan the rotating QR code of a station of their team.") : t("checkIn.modes.stationNeedsKey", "Needs a station key on the server (NUXT_SHIFTS_STATION_KEY)."),
35
+ description: stationReady.value ? t("checkIn.modes.stationHelp", "Volunteers scan the rotating QR code of a station of their team.") : t("checkIn.modes.stationNeedsKey", "Needs NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY) on the server."),
36
36
  value: "station",
37
37
  disabled: !stationReady.value && !selected.includes("station")
38
38
  },
@@ -92,7 +92,7 @@ const columns = computed(() => [
92
92
  :color="stationInUse ? 'warning' : 'neutral'"
93
93
  variant="subtle"
94
94
  :title="t('checkIn.stationKeyMissing', 'Station check-in needs a station key')"
95
- :description="stationInUse ? t('checkIn.stationKeyMissingInUse', 'Station check-in is on, but the server has no NUXT_SHIFTS_STATION_KEY: volunteers cannot check in by station and station screens do not open. Set the key, or turn the mode off. The other modes work.') : t('checkIn.stationKeyMissingHint', 'Set NUXT_SHIFTS_STATION_KEY on the server to use station check-in and station screens. The other modes work without it.')"
95
+ :description="stationInUse ? t('checkIn.stationKeyMissingInUse', 'Station check-in is on, but the server has neither NUXT_APP_SECRET nor NUXT_SHIFTS_STATION_KEY: volunteers cannot check in by station and station screens do not open. Set NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY), or turn the mode off. The other modes work.') : t('checkIn.stationKeyMissingHint', 'Set NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY) on the server to use station check-in and station screens. The other modes work without it.')"
96
96
  />
97
97
  <SectionCard
98
98
  :title="t('checkIn.title', 'How volunteers check in')"
@@ -266,7 +266,7 @@
266
266
  "locationHelp": "Frivillige trykker \"Jeg er her\", og appen sender deres placering. Den kan forfalskes af en, der vil.",
267
267
  "station": "Station",
268
268
  "stationHelp": "Frivillige scanner den skiftende QR-kode på en af holdets stationer.",
269
- "stationNeedsKey": "Kræver en stationsnøgle på serveren (NUXT_SHIFTS_STATION_KEY)."
269
+ "stationNeedsKey": "Kræver NUXT_APP_SECRET (eller NUXT_SHIFTS_STATION_KEY) på serveren."
270
270
  },
271
271
  "modesHint": "Ud over at en leder scanner passet.",
272
272
  "modesLabel": "Måder at tjekke ind",
@@ -279,8 +279,8 @@
279
279
  "saved": "Gemte tjek ind for {name}",
280
280
  "scanStation": "Scan stationens kode",
281
281
  "stationKeyMissing": "Tjek ind ved station kræver en stationsnøgle",
282
- "stationKeyMissingHint": "Sæt NUXT_SHIFTS_STATION_KEY på serveren for at bruge tjek ind ved station og stationsskærme. De andre tilstande virker uden den.",
283
- "stationKeyMissingInUse": "Tjek ind ved station er slået til, men serveren har ingen NUXT_SHIFTS_STATION_KEY: frivillige kan ikke tjekke ind ved en station, og stationsskærme åbner ikke. Sæt nøglen, eller slå tilstanden fra. De andre tilstande virker.",
282
+ "stationKeyMissingHint": "Sæt NUXT_APP_SECRET (eller NUXT_SHIFTS_STATION_KEY) på serveren for at bruge tjek ind ved station og stationsskærme. De andre tilstande virker uden den.",
283
+ "stationKeyMissingInUse": "Tjek ind ved station er slået til, men serveren har hverken NUXT_APP_SECRET eller NUXT_SHIFTS_STATION_KEY: frivillige kan ikke tjekke ind ved en station, og stationsskærme åbner ikke. Sæt NUXT_APP_SECRET (eller NUXT_SHIFTS_STATION_KEY), eller slå tilstanden fra. De andre tilstande virker.",
284
284
  "stopScanning": "Stop scanning",
285
285
  "title": "Sådan tjekker frivillige ind"
286
286
  },
@@ -266,7 +266,7 @@
266
266
  "locationHelp": "Volunteers tap \"I'm here\" and the app sends their position. A determined person can fake it.",
267
267
  "station": "Station",
268
268
  "stationHelp": "Volunteers scan the rotating QR code of a station of their team.",
269
- "stationNeedsKey": "Needs a station key on the server (NUXT_SHIFTS_STATION_KEY)."
269
+ "stationNeedsKey": "Needs NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY) on the server."
270
270
  },
271
271
  "modesHint": "Besides a lead scanning the pass.",
272
272
  "modesLabel": "Check-in modes",
@@ -279,8 +279,8 @@
279
279
  "saved": "Saved the check-in of {name}",
280
280
  "scanStation": "Scan the station code",
281
281
  "stationKeyMissing": "Station check-in needs a station key",
282
- "stationKeyMissingHint": "Set NUXT_SHIFTS_STATION_KEY on the server to use station check-in and station screens. The other modes work without it.",
283
- "stationKeyMissingInUse": "Station check-in is on, but the server has no NUXT_SHIFTS_STATION_KEY: volunteers cannot check in by station and station screens do not open. Set the key, or turn the mode off. The other modes work.",
282
+ "stationKeyMissingHint": "Set NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY) on the server to use station check-in and station screens. The other modes work without it.",
283
+ "stationKeyMissingInUse": "Station check-in is on, but the server has neither NUXT_APP_SECRET nor NUXT_SHIFTS_STATION_KEY: volunteers cannot check in by station and station screens do not open. Set NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY), or turn the mode off. The other modes work.",
284
284
  "stopScanning": "Stop scanning",
285
285
  "title": "How volunteers check in"
286
286
  },
@@ -1,7 +1,17 @@
1
1
  import type { H3Event } from 'h3';
2
- /** `shifts.stationKey` (`NUXT_SHIFTS_STATION_KEY`), trimmed; empty when unset or too short. Station check-in has no other secret. */
3
- export declare function shiftsStationSecret(event?: H3Event): string;
4
- /** Whether `shifts.stationKey` (`NUXT_SHIFTS_STATION_KEY`) is set (and long enough), so station check-in and station screens work. */
2
+ /**
3
+ * The secret station tokens are signed with: `shifts.stationKey` (`NUXT_SHIFTS_STATION_KEY`), else one derived from
4
+ * `appSecret` (`NUXT_APP_SECRET`); empty when neither is set, or when the station key is set but too short.
5
+ */
6
+ export declare function shiftsStationSecret(event?: H3Event): Promise<string>;
7
+ /**
8
+ * Whether station check-in and station screens work: `shifts.stationKey` (`NUXT_SHIFTS_STATION_KEY`) is set and long
9
+ * enough, or it is unset and `appSecret` (`NUXT_APP_SECRET`) is.
10
+ */
5
11
  export declare function shiftsStationKeyConfigured(event?: H3Event): boolean;
6
- /** 501 `not_configured` unless `shifts.stationKey` (`NUXT_SHIFTS_STATION_KEY`) is set and at least 32 characters. */
12
+ /** The 501 `not_configured` of station check-in without a station secret. */
13
+ export declare function shiftsStationKeyMissing(): import("h3").H3Error<{
14
+ code: string;
15
+ }>;
16
+ /** 501 `not_configured` unless {@link shiftsStationKeyConfigured}. */
7
17
  export declare function shiftsRequireStationKey(event?: H3Event): void;
@@ -1,22 +1,37 @@
1
1
  import { notConfigured } from "@frigear-nu/module-kit/server";
2
+ import { APP_SECRET_MIN_LENGTH, resolveSecret } from "@frigear-nu/module-kit/secret";
2
3
  import { shiftsStationKeyIssue } from "../../utils/station-key.js";
4
+ const STATION_SECRET_PURPOSE = "@frigear-nu/shifts:station";
3
5
  let reported;
4
- export function shiftsStationSecret(event) {
6
+ function ownStationKey(event) {
5
7
  const config = useRuntimeConfig(event);
6
8
  const secret = config.shifts?.stationKey;
7
9
  const issue = shiftsStationKeyIssue(secret);
8
10
  if (issue) {
9
11
  if (reported !== issue) console.error(issue);
10
12
  reported = issue;
11
- return "";
13
+ return { key: "", invalid: true };
12
14
  }
13
- return typeof secret === "string" ? secret.trim() : "";
15
+ return { key: typeof secret === "string" ? secret.trim() : "", invalid: false };
16
+ }
17
+ function appSecretSet(event) {
18
+ const root = useRuntimeConfig(event).appSecret;
19
+ return typeof root === "string" && root.length >= APP_SECRET_MIN_LENGTH;
20
+ }
21
+ export async function shiftsStationSecret(event) {
22
+ const own = ownStationKey(event);
23
+ if (own.invalid) return "";
24
+ if (!own.key && !appSecretSet(event)) return "";
25
+ return resolveSecret(STATION_SECRET_PURPOSE, own.key);
14
26
  }
15
27
  export function shiftsStationKeyConfigured(event) {
16
- return shiftsStationSecret(event) !== "";
28
+ const own = ownStationKey(event);
29
+ if (own.invalid) return false;
30
+ return own.key !== "" || appSecretSet(event);
31
+ }
32
+ export function shiftsStationKeyMissing() {
33
+ return notConfigured("Station check-in is not set up: set NUXT_APP_SECRET (or NUXT_SHIFTS_STATION_KEY, at least 32 characters) on the server.");
17
34
  }
18
35
  export function shiftsRequireStationKey(event) {
19
- if (!shiftsStationKeyConfigured(event)) {
20
- throw notConfigured("Station check-in is not set up: the server has no station key of at least 32 characters (NUXT_SHIFTS_STATION_KEY).");
21
- }
36
+ if (!shiftsStationKeyConfigured(event)) throw shiftsStationKeyMissing();
22
37
  }
@@ -7,12 +7,13 @@ import { newId } from "../../utils/index.js";
7
7
  import { STATION_ROTATE_SECONDS, parseStationToken, stationTokenPayload, stationWindow, stationWindowAccepted } from "../../utils/checkin.js";
8
8
  import { toShiftStationDto } from "./shifts-dto.js";
9
9
  import { shiftsOperationTeamOr400 } from "./shifts-core.js";
10
- import { shiftsRequireStationKey, shiftsStationSecret } from "./shifts-station-key.js";
10
+ import { shiftsRequireStationKey, shiftsStationKeyMissing, shiftsStationSecret } from "./shifts-station-key.js";
11
11
  const encoder = new TextEncoder();
12
12
  const stationKeys = /* @__PURE__ */ new Map();
13
- function shiftsStationKey(event) {
13
+ async function shiftsStationKey(event) {
14
14
  shiftsRequireStationKey(event);
15
- const secret = shiftsStationSecret(event);
15
+ const secret = await shiftsStationSecret(event);
16
+ if (!secret) throw shiftsStationKeyMissing();
16
17
  let key = stationKeys.get(secret);
17
18
  if (!key) {
18
19
  key = deriveHkdfKey(secret, { salt: "@frigear-nu/shifts", info: "shift_station_tokens" }, { name: "HMAC", hash: "SHA-256", length: 256 }, ["sign", "verify"]);
@@ -1,8 +1,9 @@
1
1
  /** The shortest station key shifts accepts: station codes are signed with a key derived from it. */
2
2
  export declare const SHIFTS_STATION_KEY_MIN_LENGTH = 32;
3
3
  /**
4
- * Why `value` cannot be the station key, or `undefined` when it can. An empty key is allowed (station check-in is then
5
- * off); a set key must be at least {@link SHIFTS_STATION_KEY_MIN_LENGTH} characters once trimmed.
4
+ * Why `value` cannot be the station key, or `undefined` when it can. An empty key is allowed (a key derived from
5
+ * `NUXT_APP_SECRET` stands in, else station check-in is off); a set key must be at least
6
+ * {@link SHIFTS_STATION_KEY_MIN_LENGTH} characters once trimmed.
6
7
  */
7
8
  export declare function shiftsStationKeyIssue(value: unknown): string | undefined;
8
9
  /** Throws the {@link shiftsStationKeyIssue} of `value`, if any. */
@@ -4,7 +4,7 @@ export function shiftsStationKeyIssue(value) {
4
4
  if (typeof value !== "string") return "[shifts] NUXT_SHIFTS_STATION_KEY (`shifts.stationKey`) must be a string.";
5
5
  const length = value.trim().length;
6
6
  if (length === 0 || length >= SHIFTS_STATION_KEY_MIN_LENGTH) return void 0;
7
- return `[shifts] NUXT_SHIFTS_STATION_KEY (\`shifts.stationKey\`) is ${length} characters long; it must be at least ${SHIFTS_STATION_KEY_MIN_LENGTH}. Use a long random value of its own, such as the output of \`openssl rand -base64 32\`, or leave it empty to turn station check-in off.`;
7
+ return `[shifts] NUXT_SHIFTS_STATION_KEY (\`shifts.stationKey\`) is ${length} characters long; it must be at least ${SHIFTS_STATION_KEY_MIN_LENGTH}. Use a long random value of its own, such as the output of \`openssl rand -base64 32\`, or leave it empty to derive one from NUXT_APP_SECRET.`;
8
8
  }
9
9
  export function assertShiftsStationKey(value) {
10
10
  const issue = shiftsStationKeyIssue(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frigear-nu/shifts",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Shifts for the frigear ecosystem: schedules, shift roles, assignment, swaps, QR check-in and who is on shift now, per operation, built on crew and teams.",
5
5
  "homepage": "https://docs.frigear.dev/modules/volunteering/shifts",
6
6
  "repository": {
@@ -35,15 +35,15 @@
35
35
  "playground"
36
36
  ],
37
37
  "dependencies": {
38
- "@frigear-nu/auth": "^0.6.4",
39
- "@frigear-nu/crew": "^0.1.0",
40
- "@frigear-nu/maps": "^0.0.1",
41
- "@frigear-nu/module-kit": "^1.3.8",
42
- "@frigear-nu/notify": "^0.2.6",
43
- "@frigear-nu/operations": "^0.1.0",
44
- "@frigear-nu/teams": "^0.1.0",
45
- "@frigear-nu/ui": "^0.2.8",
46
- "@frigear-nu/users": "^3.1.2",
38
+ "@frigear-nu/auth": "^0.6.6",
39
+ "@frigear-nu/crew": "^0.1.2",
40
+ "@frigear-nu/maps": "^0.0.2",
41
+ "@frigear-nu/module-kit": "^1.3.10",
42
+ "@frigear-nu/notify": "^0.2.7",
43
+ "@frigear-nu/operations": "^0.1.1",
44
+ "@frigear-nu/teams": "^0.1.2",
45
+ "@frigear-nu/ui": "^0.2.9",
46
+ "@frigear-nu/users": "^3.1.4",
47
47
  "@libsql/client": "^0.18.0",
48
48
  "@nuxt/kit": "^4.6.4",
49
49
  "@vueuse/core": "^15.0.0",
@@ -55,12 +55,12 @@
55
55
  "zod": "^4.6.7"
56
56
  },
57
57
  "peerDependencies": {
58
- "@frigear-nu/admin": "^0.5.1",
59
- "@frigear-nu/dashboard": "^0.1.0",
60
- "@frigear-nu/email-templates": "^0.1.2",
61
- "@frigear-nu/menu": "^0.4.0",
62
- "@frigear-nu/mobile": "^0.6.2",
63
- "@frigear-nu/widget": "^0.4.1",
58
+ "@frigear-nu/admin": "^0.5.2",
59
+ "@frigear-nu/dashboard": "^0.1.2",
60
+ "@frigear-nu/email-templates": "^0.1.4",
61
+ "@frigear-nu/menu": "^0.4.1",
62
+ "@frigear-nu/mobile": "^0.6.3",
63
+ "@frigear-nu/widget": "^0.4.2",
64
64
  "@nuxt/ui": "^4.12.0",
65
65
  "@nuxthub/core": "^0.10.12"
66
66
  },
@@ -88,15 +88,15 @@
88
88
  }
89
89
  },
90
90
  "devDependencies": {
91
- "@frigear-nu/admin": "^0.5.1",
92
- "@frigear-nu/dashboard": "^0.1.0",
93
- "@frigear-nu/email-templates": "^0.1.2",
94
- "@frigear-nu/forms": "^0.5.1",
95
- "@frigear-nu/menu": "^0.4.0",
96
- "@frigear-nu/mobile": "^0.6.2",
97
- "@frigear-nu/preferences": "^0.3.2",
98
- "@frigear-nu/push": "^0.1.0",
99
- "@frigear-nu/widget": "^0.4.1",
91
+ "@frigear-nu/admin": "^0.5.2",
92
+ "@frigear-nu/dashboard": "^0.1.2",
93
+ "@frigear-nu/email-templates": "^0.1.4",
94
+ "@frigear-nu/forms": "^0.5.3",
95
+ "@frigear-nu/menu": "^0.4.1",
96
+ "@frigear-nu/mobile": "^0.6.3",
97
+ "@frigear-nu/preferences": "^0.3.4",
98
+ "@frigear-nu/push": "^0.1.2",
99
+ "@frigear-nu/widget": "^0.4.2",
100
100
  "@nuxt/devtools": "^4.2.0",
101
101
  "@nuxt/eslint-config": "^1.17.0",
102
102
  "@nuxt/module-builder": "^1.0.4",