@7365admin1/layer-common 3.1.4-staging.53 → 3.2.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.
@@ -11,10 +11,6 @@ interface USBDevice {
11
11
  close(): Promise<void>;
12
12
  selectConfiguration(configurationValue: number): Promise<void>;
13
13
  claimInterface(interfaceNumber: number): Promise<void>;
14
- selectAlternateInterface(
15
- interfaceNumber: number,
16
- alternateSetting: number,
17
- ): Promise<void>;
18
14
  releaseInterface(interfaceNumber: number): Promise<void>;
19
15
  transferOut(
20
16
  endpointNumber: number,
@@ -23,27 +19,14 @@ interface USBDevice {
23
19
  configuration: {
24
20
  interfaces: Array<{
25
21
  interfaceNumber: number;
26
- alternate: USBAlternateInterface;
27
22
  alternates: Array<{
28
- alternateSetting: number;
29
- interfaceClass: number;
30
23
  endpoints: Array<{
31
24
  endpointNumber: number;
32
25
  direction: "in" | "out";
33
26
  }>;
34
27
  }>;
35
28
  }>;
36
- } | null;
37
- configurations: Array<{ configurationValue: number }>;
38
- }
39
-
40
- interface USBAlternateInterface {
41
- alternateSetting: number;
42
- interfaceClass: number;
43
- endpoints: Array<{
44
- endpointNumber: number;
45
- direction: "in" | "out";
46
- }>;
29
+ };
47
30
  }
48
31
 
49
32
  interface USBOutTransferResult {
@@ -56,86 +39,13 @@ declare global {
56
39
  usb: {
57
40
  getDevices(): Promise<USBDevice[]>;
58
41
  requestDevice(options: {
59
- filters: Array<{
60
- vendorId?: number;
61
- productId?: number;
62
- classCode?: number;
63
- }>;
42
+ filters: Array<{ vendorId?: number; productId?: number }>;
64
43
  }): Promise<USBDevice>;
65
44
  };
66
45
  }
67
46
  }
68
47
 
69
48
  export default function useWebUsb() {
70
- const printerConnections = new WeakMap<
71
- USBDevice,
72
- { interfaceNumber: number; endpointNumber: number }
73
- >();
74
-
75
- const protectedInterfaceClasses = new Set([0x01, 0x03, 0x08, 0x0b, 0x0e, 0x10, 0xe0]);
76
-
77
- function getErrorMessage(error: unknown, fallback: string) {
78
- return error instanceof Error && error.message ? error.message : fallback;
79
- }
80
-
81
- function findPrinterInterface(device: USBDevice) {
82
- const candidates = (device.configuration?.interfaces || []).flatMap((usbInterface) =>
83
- usbInterface.alternates.flatMap((alternate) => {
84
- const outputEndpoint = alternate.endpoints.find((endpoint) => endpoint.direction === "out");
85
- if (!outputEndpoint || protectedInterfaceClasses.has(alternate.interfaceClass)) return [];
86
-
87
- return [{
88
- interfaceNumber: usbInterface.interfaceNumber,
89
- alternateSetting: alternate.alternateSetting,
90
- activeAlternateSetting: usbInterface.alternate.alternateSetting,
91
- interfaceClass: alternate.interfaceClass,
92
- endpointNumber: outputEndpoint.endpointNumber,
93
- }];
94
- }),
95
- );
96
-
97
- candidates.sort((left, right) => {
98
- const priority = (interfaceClass: number) => interfaceClass === 0x07 ? 0 : interfaceClass === 0xff ? 1 : 2;
99
- return priority(left.interfaceClass) - priority(right.interfaceClass);
100
- });
101
-
102
- return candidates[0] || null;
103
- }
104
-
105
- async function preparePrinterDevice(device: USBDevice) {
106
- await device.open();
107
- if (!device.configuration) {
108
- await device.selectConfiguration(device.configurations[0]?.configurationValue || 1);
109
- }
110
-
111
- const printerInterface = findPrinterInterface(device);
112
- if (!printerInterface) {
113
- throw new Error(
114
- "The selected USB device is not a compatible printer. Select the receipt printer instead of a Bluetooth, camera, keyboard, or other system device.",
115
- );
116
- }
117
-
118
- await device.claimInterface(printerInterface.interfaceNumber);
119
- if (printerInterface.alternateSetting !== printerInterface.activeAlternateSetting) {
120
- await device.selectAlternateInterface(
121
- printerInterface.interfaceNumber,
122
- printerInterface.alternateSetting,
123
- );
124
- }
125
-
126
- printerConnections.set(device, {
127
- interfaceNumber: printerInterface.interfaceNumber,
128
- endpointNumber: printerInterface.endpointNumber,
129
- });
130
- return device;
131
- }
132
-
133
- function getPrinterConnection(device: USBDevice) {
134
- const connection = printerConnections.get(device);
135
- if (!connection) throw new Error("Printer interface is not connected");
136
- return connection;
137
- }
138
-
139
49
  const isWebUsbSupported = computed(() => {
140
50
  return typeof navigator !== "undefined" && "usb" in navigator;
141
51
  });
@@ -165,9 +75,7 @@ export default function useWebUsb() {
165
75
  throw new Error("Web USB is not supported in this browser");
166
76
  }
167
77
  try {
168
- const device = await navigator.usb.requestDevice({
169
- filters: [{ classCode: 0x07 }, { classCode: 0xff }],
170
- });
78
+ const device = await navigator.usb.requestDevice({ filters: [] });
171
79
  return {
172
80
  vendorId: device.vendorId,
173
81
  productId: device.productId,
@@ -176,12 +84,12 @@ export default function useWebUsb() {
176
84
  serialNumber: device.serialNumber || "Unknown",
177
85
  deviceId: `${device.vendorId}:${device.productId}`,
178
86
  };
179
- } catch (error: unknown) {
180
- if (error instanceof DOMException && error.name === "NotFoundError") {
87
+ } catch (error: any) {
88
+ if (error.name === "NotFoundError") {
181
89
  throw new Error("No device selected");
182
90
  }
183
91
  console.error("Error requesting USB device:", error);
184
- throw new Error(getErrorMessage(error, "Failed to access USB printer"));
92
+ throw new Error("Failed to access USB device");
185
93
  }
186
94
  };
187
95
 
@@ -202,17 +110,14 @@ export default function useWebUsb() {
202
110
  });
203
111
  }
204
112
  console.log("[WebUSB] Opening device:", device.vendorId, device.productId);
205
- await preparePrinterDevice(device);
113
+ await device.open();
114
+ await device.selectConfiguration(1);
115
+ await device.claimInterface(0);
206
116
  console.log("[WebUSB] Device opened and interface claimed.");
207
117
  return device;
208
- } catch (error: unknown) {
118
+ } catch (error) {
209
119
  console.error("Error connecting to USB device:", error);
210
- try {
211
- await device?.close();
212
- } catch (closeError) {
213
- console.error("Error closing rejected USB device:", closeError);
214
- }
215
- throw new Error(getErrorMessage(error, "Failed to connect to USB printer"));
120
+ throw new Error("Failed to connect to USB device");
216
121
  }
217
122
  };
218
123
 
@@ -268,20 +173,15 @@ export default function useWebUsb() {
268
173
  ? "Connection and print test successful"
269
174
  : "Connection successful but print test failed",
270
175
  };
271
- } catch (error: unknown) {
176
+ } catch (error: any) {
272
177
  return {
273
178
  success: false,
274
- error: getErrorMessage(error, "Failed to connect to USB printer"),
179
+ error: error.message,
275
180
  message: "Connection failed",
276
181
  };
277
182
  } finally {
278
183
  if (device) {
279
184
  try {
280
- const connection = printerConnections.get(device);
281
- if (connection) {
282
- await device.releaseInterface(connection.interfaceNumber);
283
- printerConnections.delete(device);
284
- }
285
185
  await device.close();
286
186
  } catch (closeError) {
287
187
  console.error("Error closing device:", closeError);
@@ -305,16 +205,21 @@ export default function useWebUsb() {
305
205
  ];
306
206
 
307
207
  const testData = new Uint8Array(testCommands);
308
- const { endpointNumber } = getPrinterConnection(device);
309
- await device.transferOut(endpointNumber, testData);
208
+ const usbInterface = device.configuration.interfaces[0];
209
+ const alternate = usbInterface.alternates[0];
210
+ const outputEndpoint = alternate.endpoints.find(
211
+ (ep: any) => ep.direction === "out",
212
+ );
213
+
214
+ if (!outputEndpoint) {
215
+ throw new Error("No output endpoint found");
216
+ }
217
+
218
+ await device.transferOut(outputEndpoint.endpointNumber, testData);
310
219
  return { success: true, message: "Test print sent successfully" };
311
- } catch (error: unknown) {
220
+ } catch (error: any) {
312
221
  console.error("Test print error:", error);
313
- return {
314
- success: false,
315
- error: getErrorMessage(error, "Test print failed"),
316
- message: "Test print failed",
317
- };
222
+ return { success: false, error: error.message, message: "Test print failed" };
318
223
  }
319
224
  };
320
225
 
@@ -449,8 +354,13 @@ export default function useWebUsb() {
449
354
  ) => {
450
355
  try {
451
356
  console.log("[WebUSB] printQrCode start — doorLevel:", doorLevel, "liftLevel:", liftLevel, "company:", companyName, "address:", address);
452
- const { endpointNumber } = getPrinterConnection(device);
453
- console.log("[WebUSB] Using endpoint:", endpointNumber);
357
+ const usbInterface = device.configuration.interfaces[0];
358
+ const alternate = usbInterface.alternates[0];
359
+ const outputEndpoint = alternate.endpoints.find(
360
+ (ep: any) => ep.direction === "out",
361
+ );
362
+ if (!outputEndpoint) throw new Error("No output endpoint found");
363
+ console.log("[WebUSB] Using endpoint:", outputEndpoint.endpointNumber);
454
364
 
455
365
  const canvas = await createReceiptLayout(
456
366
  urlImage,
@@ -465,17 +375,17 @@ export default function useWebUsb() {
465
375
  const rasterData = canvasToRaster(canvas);
466
376
  console.log("[WebUSB] Raster data size:", rasterData.byteLength, "bytes");
467
377
 
468
- await device.transferOut(endpointNumber, rasterData.buffer);
378
+ await device.transferOut(outputEndpoint.endpointNumber, rasterData.buffer);
469
379
  console.log("[WebUSB] Raster data sent.");
470
380
 
471
381
  const CUT = new Uint8Array([0x1d, 0x56, 0x41, 0x10]);
472
- await device.transferOut(endpointNumber, CUT.buffer);
382
+ await device.transferOut(outputEndpoint.endpointNumber, CUT.buffer);
473
383
  console.log("[WebUSB] Cut command sent.");
474
384
 
475
385
  return { success: true, message: "QR print sent successfully" };
476
- } catch (error: unknown) {
386
+ } catch (error: any) {
477
387
  console.error("[WebUSB] printQrCode error:", error);
478
- return { success: false, error: getErrorMessage(error, "Unable to print QR code") };
388
+ return { success: false, error: error.message };
479
389
  }
480
390
  };
481
391
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "3.1.4-staging.53",
5
+ "version": "3.2.0",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "publishConfig": {
@@ -40,7 +40,6 @@
40
40
  "qrcode": "^1.5.4",
41
41
  "qrcode.vue": "^3.4.1",
42
42
  "sass": "^1.80.6",
43
- "sip.js": "0.21.2",
44
43
  "socket.io-client": "^4.8.3",
45
44
  "vue-draggable-next": "^2.3.0",
46
45
  "vue3-signature": "^0.2.4",
@@ -0,0 +1,23 @@
1
+ <template>
2
+ <v-container fluid>
3
+ <HidEnabledGate
4
+ :site="siteId"
5
+ :org="orgId"
6
+ message="Enable HID as a service for this site before mapping identities."
7
+ >
8
+ <HidIdentityMapping :site="siteId" :org="orgId" />
9
+ </HidEnabledGate>
10
+ </v-container>
11
+ </template>
12
+
13
+ <script setup lang="ts">
14
+ definePageMeta({
15
+ layout: "default",
16
+ middleware: ["01-auth", "02-org"],
17
+ memberOnly: true,
18
+ });
19
+
20
+ const route = useRoute();
21
+ const siteId = computed(() => String(route.params.site ?? ""));
22
+ const orgId = computed(() => String(route.params.org ?? ""));
23
+ </script>
@@ -12,40 +12,75 @@ export default defineNuxtPlugin(() => {
12
12
 
13
13
  const { userAppRole, id, orgNature } = useLocalSetup();
14
14
 
15
- router.beforeEach(async (to) => {
15
+ router.afterEach(async (to) => {
16
16
  const isMember = to.meta?.memberOnly;
17
17
 
18
18
  if (!isMember) return;
19
19
 
20
20
  const APP = useRuntimeConfig().public.APP;
21
- const org =
22
- (to.params.org as string) || (to.params.organization as string) || "";
21
+ const org = computed(
22
+ () =>
23
+ (to.params.org as string) || (to.params.organization as string) || ""
24
+ );
23
25
 
24
- if (!hexSchema.safeParse(org).success) {
25
- return { name: "require-organization-membership" };
26
+ console.log('[secure-member-plugin', 'org', org.value)
27
+
28
+ if (!hexSchema.safeParse(org.value).success) {
29
+ return router.replace({ name: "require-organization-membership" });
26
30
  }
27
31
 
28
- const userId = useCookie("user").value ?? "";
29
- if (!userId) return { name: "index" };
32
+ const userId = computed(() => useCookie("user").value ?? "");
33
+
34
+ const { data: userMemberData, error: userMemberError } =
35
+ await useLazyAsyncData(
36
+ "plugin-get-member-by-id-" + userId.value + "-" + APP + "-" + org.value,
37
+ () => getByUserType(userId.value, APP, org.value),
38
+ { watch: [userId] }
39
+ );
40
+
41
+ watchEffect(() => {
42
+ if (userMemberError.value) {
43
+ console.log('running-secure-member-redirect-plugin')
44
+ navigateTo(
45
+ {
46
+ name: "index",
47
+ },
48
+ { replace: true }
49
+ );
50
+ }
51
+ });
52
+
53
+ const roleId = ref("roleId");
30
54
 
31
- try {
32
- const userMemberData = await getByUserType(userId, APP, org);
33
- id.value = userMemberData.org ?? "";
55
+ watchEffect(() => {
56
+ if (userMemberData.value) {
57
+ id.value = userMemberData.value.org ?? "";
58
+ roleId.value = userMemberData.value.role ?? "roleId";
59
+ }
60
+ });
34
61
 
35
- const [orgResult, roleResult] = await Promise.allSettled([
36
- getById(org),
37
- userMemberData.role ? getRoleById(userMemberData.role) : null,
38
- ]);
62
+ const { data: getOrgByIdReq } = await useLazyAsyncData(
63
+ "plugin-get-org-by-id-" + org.value,
64
+ () => getById(org.value),
65
+ { watch: [org] }
66
+ );
39
67
 
40
- if (orgResult.status === "fulfilled" && orgResult.value) {
41
- orgNature.value = orgResult.value.nature ?? "";
68
+ watchEffect(() => {
69
+ if (getOrgByIdReq.value) {
70
+ orgNature.value = getOrgByIdReq.value.nature ?? "";
42
71
  }
72
+ });
43
73
 
44
- if (roleResult.status === "fulfilled" && roleResult.value) {
45
- userAppRole.value = roleResult.value;
74
+ const { data: getRoleByIdReq } = await useLazyAsyncData(
75
+ "plugin-get-role-by-id-" + roleId.value,
76
+ () => getRoleById(roleId.value),
77
+ { watch: [roleId] }
78
+ );
79
+
80
+ watchEffect(() => {
81
+ if (getRoleByIdReq.value) {
82
+ userAppRole.value = getRoleByIdReq.value;
46
83
  }
47
- } catch (error) {
48
- return { name: "index" };
49
- }
84
+ });
50
85
  });
51
86
  });
package/types/site.d.ts CHANGED
@@ -1,70 +1,5 @@
1
1
  declare type TSiteCreate = Pick<TSite, "name" | "description" | "orgId">;
2
2
 
3
- declare type THidQrCodeFormat = "0" | "1" | "2";
4
-
5
- declare type THidPermissionCategory =
6
- | "resident"
7
- | "property_management"
8
- | "service_provider";
9
-
10
- declare type THidPermissionAssignment = {
11
- subjectId: string;
12
- category: THidPermissionCategory;
13
- name: string;
14
- subtitle?: string;
15
- intercom: boolean;
16
- };
17
-
18
- declare type THidSitePermissions = {
19
- site: string;
20
- assignments: THidPermissionAssignment[];
21
- counts: {
22
- resident: number;
23
- propertyManagement: number;
24
- serviceProvider: number;
25
- intercom: number;
26
- };
27
- };
28
-
29
- declare type THidPermissionCandidate = THidPermissionAssignment & {
30
- selected: boolean;
31
- };
32
-
33
- declare type THidQrCodePassConfig = {
34
- enabled: boolean;
35
- onlineMode?: boolean;
36
- readerId: string;
37
- qrFormat: THidQrCodeFormat;
38
- identificationMethods?: {
39
- facial: boolean;
40
- card: boolean;
41
- qrCode: boolean;
42
- idPassword: boolean;
43
- pin: boolean;
44
- bluetooth: boolean;
45
- };
46
- printer: {
47
- vendorId: string;
48
- productId: string;
49
- };
50
- template: {
51
- header: string;
52
- subtext: string;
53
- };
54
- validityMinutes: number | null;
55
- updatedAt?: string;
56
- };
57
-
58
- declare type TSiteMetadata = {
59
- block?: number;
60
- guardPosts?: number;
61
- gracePeriod?: number;
62
- incidentCounter?: number;
63
- incidentLogo?: string;
64
- services?: Record<string, unknown>[];
65
- hidQrCodePass?: THidQrCodePassConfig;
66
- };
67
-
68
3
 
69
4
  declare type TSite = {
70
5
  _id?: string;
@@ -0,0 +1,51 @@
1
+ export type PlanStatus = "active" | "deactive";
2
+
3
+ export type PlanType = "free_bundle" | "paid_bundle" | "custom_apps";
4
+
5
+ export type BillingCycle = "monthly" | "annually";
6
+
7
+ export interface AppOption {
8
+ id: string;
9
+ name: string;
10
+ monthlyPrice: number;
11
+ yearlyPrice: number;
12
+ }
13
+
14
+ export interface SubscriptionPlan {
15
+ id: string;
16
+ name: string;
17
+ description?: string;
18
+ maxSeats: number;
19
+ planType: PlanType;
20
+ billingCycle: BillingCycle | null;
21
+ price: number | null;
22
+ applicationIds: string[];
23
+ status: PlanStatus;
24
+ }
25
+
26
+ export interface PlanFormState {
27
+ name: string;
28
+ description: string;
29
+ maxSeats: number;
30
+ planType: PlanType;
31
+ billingCycle: BillingCycle | null;
32
+ bundleApps: string[];
33
+ bundlePrice: number | null;
34
+ customApps: string[];
35
+ }
36
+
37
+ export const PLAN_TYPE_LABEL: Record<PlanType, string> = {
38
+ free_bundle: "Free (Bundle)",
39
+ paid_bundle: "Paid (Bundle)",
40
+ custom_apps: "Paid (Custom Apps)",
41
+ };
42
+
43
+ // Mock catalogue of applications that can be bundled into a plan.
44
+ // Replace with data fetched from your backend.
45
+ export const AVAILABLE_APPLICATIONS: AppOption[] = [
46
+ { id: "crm", name: "CRM", monthlyPrice: 49, yearlyPrice: 490 },
47
+ { id: "hrm", name: "HRM", monthlyPrice: 39, yearlyPrice: 390 },
48
+ { id: "accounting", name: "Accounting", monthlyPrice: 59, yearlyPrice: 590 },
49
+ { id: "inventory", name: "Inventory", monthlyPrice: 45, yearlyPrice: 450 },
50
+ { id: "pos", name: "POS", monthlyPrice: 69, yearlyPrice: 690 },
51
+ ];