@7365admin1/layer-common 4.153.0 → 4.154.1
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/CHANGELOG.md +16 -4
- package/components/VehicleQrStickerDialog.vue +14 -1
- package/package.json +1 -1
- package/plugins/API.ts +8 -1
- package/utils/shared-get.ts +54 -0
- package/utils/vehicle-qr-design.ts +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @iservice365/layer-common
|
|
2
2
|
|
|
3
|
+
## 4.154.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b2d43ad: Vehicle QR stickers: the serial number (No. 1, 2, 3 ...) now prints on the sticker by default; a serial choice the person picked in this browser still wins.
|
|
8
|
+
|
|
9
|
+
## 4.154.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 5d7a51b: Speed: identical GET requests already on their way share one answer instead of being sent again (a page load asked for the same site, user and membership twice). Nothing is kept once the answer arrives; writes and special requests are never shared.
|
|
14
|
+
|
|
3
15
|
## 4.153.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -3596,11 +3608,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
|
|
|
3596
3608
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
3597
3609
|
own rule from two endpoints the console already calls, unprojected:
|
|
3598
3610
|
|
|
3599
|
-
|
|
3600
|
-
|
|
3611
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
3612
|
+
GET /api/roles/id/:role that membership's role document
|
|
3601
3613
|
|
|
3602
|
-
|
|
3603
|
-
|
|
3614
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
3615
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
3604
3616
|
|
|
3605
3617
|
`role.default` is the marker because it is the only property of a platform
|
|
3606
3618
|
staff role no API caller can set - `role.controller.ts` validates create and
|
|
@@ -268,6 +268,7 @@ import {
|
|
|
268
268
|
TEXT_OPTIONS,
|
|
269
269
|
frameOptionsFor,
|
|
270
270
|
normalizeDesign,
|
|
271
|
+
rememberedDesign,
|
|
271
272
|
sizeOptionsFor,
|
|
272
273
|
stickerFaceSvg,
|
|
273
274
|
type StickerDesign,
|
|
@@ -320,9 +321,11 @@ const siteName = ref("");
|
|
|
320
321
|
// The last design chosen in this browser. Storage can be blocked (private
|
|
321
322
|
// window): then it is simply the standard look each time.
|
|
322
323
|
const DESIGN_KEY = "vehicleQrStickerDesign";
|
|
324
|
+
// The serial choice is kept on its own, only when the person picks it.
|
|
325
|
+
const SERIAL_KEY = "vehicleQrStickerSerial";
|
|
323
326
|
function loadDesign(): StickerDesign {
|
|
324
327
|
try {
|
|
325
|
-
return
|
|
328
|
+
return rememberedDesign(JSON.parse(localStorage.getItem(DESIGN_KEY) || "null"), localStorage.getItem(SERIAL_KEY));
|
|
326
329
|
} catch {
|
|
327
330
|
return { ...DEFAULT_STICKER_DESIGN };
|
|
328
331
|
}
|
|
@@ -335,6 +338,16 @@ watch(design, (d) => {
|
|
|
335
338
|
/* not saved - nothing else to do */
|
|
336
339
|
}
|
|
337
340
|
});
|
|
341
|
+
watch(
|
|
342
|
+
() => design.serial,
|
|
343
|
+
(s) => {
|
|
344
|
+
try {
|
|
345
|
+
localStorage.setItem(SERIAL_KEY, s);
|
|
346
|
+
} catch {
|
|
347
|
+
/* not saved - nothing else to do */
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
);
|
|
338
351
|
function resetDesign() {
|
|
339
352
|
Object.assign(design, DEFAULT_STICKER_DESIGN);
|
|
340
353
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.
|
|
5
|
+
"version": "4.154.1",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
package/plugins/API.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isPermissionRefusal } from "../utils/permission-refusal";
|
|
2
2
|
import { accessSuspendedMessage, SIGNIN_NOTICE_COOKIE } from "../utils/access-suspended";
|
|
3
3
|
import { apiPath, clientLog } from "../utils/client-log";
|
|
4
|
+
import { shareIdenticalGets } from "../utils/shared-get";
|
|
4
5
|
|
|
5
6
|
// Expected answers, not failures: the session lapsed, no permission, nothing there.
|
|
6
7
|
const UNLOGGED_REFUSALS = new Set([401, 403, 404]);
|
|
@@ -89,10 +90,16 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
89
90
|
},
|
|
90
91
|
});
|
|
91
92
|
|
|
93
|
+
// Identical GETs already on their way share one answer (utils/shared-get.ts).
|
|
94
|
+
// Browser only; nothing is kept once the answer arrives.
|
|
95
|
+
const shared = import.meta.client
|
|
96
|
+
? (Object.assign(shareIdenticalGets(api as any), { raw: api.raw, native: api.native, create: api.create }) as unknown as typeof api)
|
|
97
|
+
: api;
|
|
98
|
+
|
|
92
99
|
// Expose to useNuxtApp().$api
|
|
93
100
|
return {
|
|
94
101
|
provide: {
|
|
95
|
-
api,
|
|
102
|
+
api: shared,
|
|
96
103
|
},
|
|
97
104
|
};
|
|
98
105
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPEED (owner 2026-10-29, "every click is slow"): a page load fired the same
|
|
3
|
+
* GET several times at once - the site, the user and the membership each twice
|
|
4
|
+
* on the PM dashboard - because separate components each ask for them. While
|
|
5
|
+
* one identical GET is already on its way, a second caller now shares that
|
|
6
|
+
* answer instead of sending another request.
|
|
7
|
+
*
|
|
8
|
+
* Nothing is kept: the moment the answer arrives the request is forgotten, so
|
|
9
|
+
* the next click always asks the server again (no stale data). Only plain GETs
|
|
10
|
+
* qualify - no body, no custom headers, no abort signal, no special response
|
|
11
|
+
* type. A caller that joins gets its own copy, so one screen changing the
|
|
12
|
+
* object cannot change another's.
|
|
13
|
+
*/
|
|
14
|
+
export type Fetcher = (request: any, options?: any) => Promise<any>;
|
|
15
|
+
|
|
16
|
+
export function shareIdenticalGets(fetcher: Fetcher): Fetcher {
|
|
17
|
+
const inflight = new Map<string, Promise<any>>();
|
|
18
|
+
return (request: any, options: any = {}) => {
|
|
19
|
+
const key = sharedGetKey(request, options);
|
|
20
|
+
if (!key) return fetcher(request, options);
|
|
21
|
+
const pending = inflight.get(key);
|
|
22
|
+
if (pending) return pending.then(ownCopy);
|
|
23
|
+
const first = fetcher(request, options);
|
|
24
|
+
inflight.set(key, first);
|
|
25
|
+
const forget = () => {
|
|
26
|
+
if (inflight.get(key) === first) inflight.delete(key);
|
|
27
|
+
};
|
|
28
|
+
first.then(forget, forget);
|
|
29
|
+
return first;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The identity of a shareable GET, or "" when this request must go on its own. */
|
|
34
|
+
export function sharedGetKey(request: any, options: any = {}): string {
|
|
35
|
+
if (typeof request !== "string") return "";
|
|
36
|
+
const method = String(options?.method ?? "GET").toUpperCase();
|
|
37
|
+
if (method !== "GET") return "";
|
|
38
|
+
if (options?.body !== undefined || options?.headers || options?.signal || options?.responseType) return "";
|
|
39
|
+
const rest = Object.keys(options ?? {}).filter((k) => !["method", "query", "params"].includes(k));
|
|
40
|
+
if (rest.length) return "";
|
|
41
|
+
try {
|
|
42
|
+
return JSON.stringify([request, options?.query ?? null, options?.params ?? null]);
|
|
43
|
+
} catch {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function ownCopy<T>(value: T): T {
|
|
49
|
+
try {
|
|
50
|
+
return structuredClone(value);
|
|
51
|
+
} catch {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -175,7 +175,7 @@ export const DEFAULT_STICKER_DESIGN: StickerDesign = {
|
|
|
175
175
|
label: "app",
|
|
176
176
|
text: "below",
|
|
177
177
|
cutLines: true,
|
|
178
|
-
serial: "
|
|
178
|
+
serial: "sticker",
|
|
179
179
|
};
|
|
180
180
|
|
|
181
181
|
/** A saved or typed-in design with anything unknown replaced by the default. */
|
|
@@ -198,10 +198,20 @@ export function normalizeDesign(raw: unknown): StickerDesign {
|
|
|
198
198
|
label: pick(r.label, LABEL_OPTIONS, d.label),
|
|
199
199
|
text: pick(r.text, TEXT_OPTIONS, d.text),
|
|
200
200
|
cutLines: typeof r.cutLines === "boolean" ? r.cutLines : true,
|
|
201
|
-
serial: pick(r.serial, SERIAL_OPTIONS,
|
|
201
|
+
serial: pick(r.serial, SERIAL_OPTIONS, d.serial),
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* The design remembered in this browser. The whole design is saved on every
|
|
207
|
+
* change, so a saved serial of "off" may only be the old default; the serial
|
|
208
|
+
* choice counts only when it was saved on its own (the person picked it).
|
|
209
|
+
*/
|
|
210
|
+
export function rememberedDesign(saved: unknown, savedSerial: unknown): StickerDesign {
|
|
211
|
+
const r = saved && typeof saved === "object" ? (saved as Record<string, unknown>) : {};
|
|
212
|
+
return normalizeDesign({ ...r, serial: savedSerial });
|
|
213
|
+
}
|
|
214
|
+
|
|
205
215
|
export function stickerTheme(id: string): StickerTheme {
|
|
206
216
|
return STICKER_THEMES.find((t) => t.id === id) ?? STICKER_THEMES[0];
|
|
207
217
|
}
|