@pro-acc/pos-core 0.0.2 → 0.0.4
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/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Pro-Acc POS/Restoran ortak Nuxt 4 katmanı. UI uygulaması ve veritabanı bu paketten bağımsızdır; tüketici kendi Prisma istemcisini, server/service sınıflarını ve API plugin'ini sağlar.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
pnpm add @pro-acc/ui@0.0.2 @pro-acc/pos-core@0.0.
|
|
6
|
+
pnpm add @pro-acc/ui@0.0.2 @pro-acc/pos-core@0.0.3
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
POS/Restoran Nuxt yapılandırması extends: ["@pro-acc/pos-core"] kullanır. Bu katman @pro-acc/ui modülünü pos:true ile kaydeder. Paylaşılan route'lar hizmetleri tüketici kökü üzerinden (~~/server/service) çağırır; uygulama override davranışı korunur.
|
|
@@ -14,25 +14,31 @@ export function readRequestKey(
|
|
|
14
14
|
)
|
|
15
15
|
return;
|
|
16
16
|
if (String(options.method || "GET").toUpperCase() !== "GET") return;
|
|
17
|
-
|
|
17
|
+
// UFO; Date, iç nesne ve undefined dizi elemanını farklı kodlar. Bunlar paylaşılmaz.
|
|
18
|
+
const scalar = (value: any) =>
|
|
19
|
+
value === null ||
|
|
20
|
+
["string", "boolean"].includes(typeof value) ||
|
|
21
|
+
(typeof value === "number" && Number.isFinite(value));
|
|
18
22
|
const normalize = (value: any): any => {
|
|
19
|
-
if (value
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
if (value == null) return value;
|
|
24
|
+
if (
|
|
25
|
+
typeof value !== "object" ||
|
|
26
|
+
Array.isArray(value) ||
|
|
27
|
+
Object.getPrototypeOf(value) !== Object.prototype
|
|
28
|
+
)
|
|
29
|
+
throw new Error("Özel sorgu");
|
|
30
|
+
return Object.fromEntries(
|
|
31
|
+
Object.keys(value)
|
|
32
|
+
.sort()
|
|
33
|
+
.map((key) => {
|
|
34
|
+
const item = value[key];
|
|
35
|
+
if (Array.isArray(item)) {
|
|
36
|
+
for (let i = 0; i < item.length; i++)
|
|
37
|
+
if (!Object.hasOwn(item, i) || !scalar(item[i])) throw new Error("Karmaşık dizi");
|
|
38
|
+
} else if (item !== undefined && !scalar(item)) throw new Error("Karmaşık sorgu alanı");
|
|
39
|
+
return [key, item];
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
36
42
|
};
|
|
37
43
|
try {
|
|
38
44
|
return JSON.stringify([resource, normalize(options.query), normalize(options.params)]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pro-acc/pos-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Pro-Acc POS/Restoran ortak Nuxt sayfa, API, servis ve güvenlik katmanı",
|
|
5
5
|
"homepage": "https://github.com/olcan123/pro-acc-packages/tree/main/packages/pos-core#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -203,5 +203,8 @@
|
|
|
203
203
|
},
|
|
204
204
|
"engines": {
|
|
205
205
|
"node": ">=22"
|
|
206
|
+
},
|
|
207
|
+
"devDependencies": {
|
|
208
|
+
"@types/node": "25.0.9"
|
|
206
209
|
}
|
|
207
210
|
}
|
|
@@ -20,7 +20,7 @@ export default defineEventHandler(async (event) => {
|
|
|
20
20
|
|
|
21
21
|
const parsed = schema.safeParse(await readBody(event));
|
|
22
22
|
if (!parsed.success) {
|
|
23
|
-
throw createError({ statusCode: 400, statusMessage: parsed.error.errors[0]
|
|
23
|
+
throw createError({ statusCode: 400, statusMessage: parsed.error.errors[0]?.message ?? "validation_error" });
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
return posAuthService.changePassword(payload.email, parsed.data.currentPassword, parsed.data.newPassword);
|
|
@@ -17,7 +17,7 @@ const loginLimiter = createRateLimiter({ max: 5, blockMs: 10 * 60 * 1000 });
|
|
|
17
17
|
export default defineEventHandler(async (event) => {
|
|
18
18
|
const parsed = schema.safeParse(await readBody(event));
|
|
19
19
|
if (!parsed.success) {
|
|
20
|
-
throw createError({ statusCode: 400, statusMessage: parsed.error.errors[0]
|
|
20
|
+
throw createError({ statusCode: 400, statusMessage: parsed.error.errors[0]?.message ?? "validation_error" });
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const rateKey = event.node?.req?.socket?.remoteAddress || "unknown";
|
|
@@ -96,7 +96,7 @@ export class SyncService {
|
|
|
96
96
|
const terminals = await localDb.client.bankTerminal.findMany();
|
|
97
97
|
const paymentCtx = {
|
|
98
98
|
cashGlAccountId: settings.cashGlAccountId,
|
|
99
|
-
terminalGlById: new Map(terminals.map((t: any) => [t.id, t.glAccountId])),
|
|
99
|
+
terminalGlById: new Map<string, number>(terminals.map((t: any) => [t.id, t.glAccountId])),
|
|
100
100
|
};
|
|
101
101
|
const payments = groupPaymentsForMain(session.orders.flatMap((o: any) => o.payments), paymentCtx);
|
|
102
102
|
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
// crudHandlers.ts — Tekrar kullanılabilir CRUD route handler factory'leri.
|
|
2
2
|
// Standart CRUD uçlarındaki id/body doğrulama + 404/FK yönetimini tek yerde toplar.
|
|
3
3
|
import type { H3Event } from "h3";
|
|
4
|
-
import type { ZodSchema } from "zod";
|
|
4
|
+
import type { ZodSchema, ZodTypeDef } from "zod";
|
|
5
|
+
|
|
6
|
+
// Router girdisi metin olabilir; dönüşümden sonra id'nin sayı olması yeterlidir.
|
|
7
|
+
type IdSchema = ZodSchema<{ id: number }, ZodTypeDef, unknown>;
|
|
5
8
|
|
|
6
9
|
/** Router param `id`'yi zod ile doğrular; geçersizse 400. */
|
|
7
|
-
function parseId(event: H3Event, idSchema:
|
|
10
|
+
function parseId(event: H3Event, idSchema: IdSchema): number {
|
|
8
11
|
const r = idSchema.safeParse({ id: getRouterParam(event, "id") });
|
|
9
12
|
if (!r.success) {
|
|
10
|
-
throw createError({ statusCode: 400, statusMessage: r.error.errors[0]
|
|
13
|
+
throw createError({ statusCode: 400, statusMessage: r.error.errors[0]?.message ?? "v_invalid_id" });
|
|
11
14
|
}
|
|
12
15
|
return r.data.id;
|
|
13
16
|
}
|
|
@@ -18,7 +21,7 @@ function parseBody<T>(body: unknown, schema: ZodSchema<T>): T {
|
|
|
18
21
|
if (!r.success) {
|
|
19
22
|
throw createError({
|
|
20
23
|
statusCode: 400,
|
|
21
|
-
statusMessage: r.error.errors[0]
|
|
24
|
+
statusMessage: r.error.errors[0]?.message ?? "validation_error",
|
|
22
25
|
data: r.error.errors,
|
|
23
26
|
});
|
|
24
27
|
}
|
|
@@ -27,7 +30,7 @@ function parseBody<T>(body: unknown, schema: ZodSchema<T>): T {
|
|
|
27
30
|
|
|
28
31
|
interface GetByIdOpts {
|
|
29
32
|
service: Record<string, any>;
|
|
30
|
-
idSchema:
|
|
33
|
+
idSchema: IdSchema;
|
|
31
34
|
findMethod?: string;
|
|
32
35
|
notFoundMessage: string;
|
|
33
36
|
}
|
|
@@ -54,7 +57,7 @@ export const makeCreateHandler = (opts: CreateOpts) =>
|
|
|
54
57
|
|
|
55
58
|
interface UpdateOpts {
|
|
56
59
|
service: Record<string, any>;
|
|
57
|
-
idSchema:
|
|
60
|
+
idSchema: IdSchema;
|
|
58
61
|
schema: ZodSchema<any>;
|
|
59
62
|
updateMethod?: string;
|
|
60
63
|
}
|
|
@@ -68,7 +71,7 @@ export const makeUpdateHandler = (opts: UpdateOpts) =>
|
|
|
68
71
|
|
|
69
72
|
interface DeleteOpts {
|
|
70
73
|
service: Record<string, any>;
|
|
71
|
-
idSchema:
|
|
74
|
+
idSchema: IdSchema;
|
|
72
75
|
deleteMethod?: string;
|
|
73
76
|
inUseMessage?: string;
|
|
74
77
|
inUseCode?: string;
|