@vicacha-devs/medusa-plugin-barcode 0.0.0-stage → 0.0.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/.medusa/server/src/admin/index.cjs +3960 -0
- package/.medusa/server/src/admin/index.js +3938 -0
- package/.medusa/server/src/api/admin/barcodes/[barcode]/route.js +43 -0
- package/.medusa/server/src/api/admin/barcodes/batch/route.js +9 -0
- package/.medusa/server/src/api/admin/barcodes/bulk-generate/route.js +9 -0
- package/.medusa/server/src/api/admin/barcodes/cache/route.js +25 -0
- package/.medusa/server/src/api/admin/barcodes/count-sessions/[id]/apply/route.js +13 -0
- package/.medusa/server/src/api/admin/barcodes/count-sessions/[id]/scan/route.js +13 -0
- package/.medusa/server/src/api/admin/barcodes/count-sessions/route.js +27 -0
- package/.medusa/server/src/api/admin/barcodes/create-from-barcode/route.js +9 -0
- package/.medusa/server/src/api/admin/barcodes/lookup/route.js +12 -0
- package/.medusa/server/src/api/admin/barcodes/print/route.js +11 -0
- package/.medusa/server/src/api/admin/barcodes/route.js +27 -0
- package/.medusa/server/src/api/admin/barcodes/scan/route.js +23 -0
- package/.medusa/server/src/api/admin/barcodes/tags/[id]/route.js +28 -0
- package/.medusa/server/src/api/admin/barcodes/tags/route.js +25 -0
- package/.medusa/server/src/api/admin/barcodes/templates/route.js +40 -0
- package/.medusa/server/src/api/admin/plugin/route.js +4 -0
- package/.medusa/server/src/api/admin/variants/barcode/[code]/route.js +28 -0
- package/.medusa/server/src/api/middlewares.js +73 -0
- package/.medusa/server/src/api/store/barcodes/[code]/route.js +28 -0
- package/.medusa/server/src/api/store/barcodes/[code]/verify/route.js +20 -0
- package/.medusa/server/src/api/store/plugin/route.js +4 -0
- package/.medusa/server/src/api/store/variants/barcode/[code]/route.js +28 -0
- package/.medusa/server/src/api/validators.js +173 -0
- package/.medusa/server/src/hooks/index.js +202 -0
- package/.medusa/server/src/index.js +5 -0
- package/.medusa/server/src/jobs/purge-expired-barcode-cache.js +10 -0
- package/.medusa/server/src/modules/barcode/index.js +16 -0
- package/.medusa/server/src/modules/barcode/migrations/Migration20260522000000.js +165 -0
- package/.medusa/server/src/modules/barcode/models/index.js +162 -0
- package/.medusa/server/src/modules/barcode/operations/context.js +2 -0
- package/.medusa/server/src/modules/barcode/operations/data-service.js +10 -0
- package/.medusa/server/src/modules/barcode/operations/generation.js +33 -0
- package/.medusa/server/src/modules/barcode/operations/index.js +9 -0
- package/.medusa/server/src/modules/barcode/operations/labels.js +57 -0
- package/.medusa/server/src/modules/barcode/operations/lookup.js +135 -0
- package/.medusa/server/src/modules/barcode/operations/maintenance.js +37 -0
- package/.medusa/server/src/modules/barcode/operations/stock-count.js +129 -0
- package/.medusa/server/src/modules/barcode/operations/tags.js +298 -0
- package/.medusa/server/src/modules/barcode/providers/index.js +721 -0
- package/.medusa/server/src/modules/barcode/service.js +161 -0
- package/.medusa/server/src/modules/barcode/types.js +21 -0
- package/.medusa/server/src/modules/barcode/utils/barcode-parser.js +399 -0
- package/.medusa/server/src/modules/barcode/utils/label-printer.js +533 -0
- package/.medusa/server/src/modules/barcode/utils/normalize-product.js +443 -0
- package/.medusa/server/src/modules/barcode/utils/security.js +114 -0
- package/.medusa/server/src/modules/barcode/utils/svg-renderer.js +492 -0
- package/.medusa/server/src/rbac.js +130 -0
- package/.medusa/server/src/sdk/index.js +164 -0
- package/.medusa/server/src/subscribers/product-created.js +34 -0
- package/.medusa/server/src/types/index.js +2 -0
- package/.medusa/server/src/ui/index.js +138 -0
- package/.medusa/server/src/workflows/apply-inventory-count.js +68 -0
- package/.medusa/server/src/workflows/batch-barcode-import.js +153 -0
- package/.medusa/server/src/workflows/bulk-generate-variant-barcodes.js +143 -0
- package/.medusa/server/src/workflows/generate-barcode-tag.js +44 -0
- package/.medusa/server/src/workflows/helpers.js +15 -0
- package/.medusa/server/src/workflows/index.js +7 -0
- package/.medusa/server/src/workflows/lookup-and-create-product.js +215 -0
- package/.medusa/server/src/workflows/scan-inventory-count.js +15 -0
- package/LICENSE +21 -0
- package/README.md +844 -2
- package/package.json +129 -3
- package/src/__tests__/barcode.spec.ts +836 -0
- package/src/__tests__/medusa-shim.mjs +331 -0
- package/src/__tests__/register-ts-resolver.mjs +135 -0
- package/src/admin/README.md +134 -0
- package/src/admin/components/barcode-studio-header.tsx +73 -0
- package/src/admin/components/batch-import-section.tsx +99 -0
- package/src/admin/components/dynamic-qr-tag-drawer-form.tsx +230 -0
- package/src/admin/components/dynamic-qr-tag-form.tsx +129 -0
- package/src/admin/components/dynamic-qr-tags-table.tsx +136 -0
- package/src/admin/components/gtin-lookup-section.tsx +155 -0
- package/src/admin/components/index.tsx +14 -0
- package/src/admin/components/label-designer-section.tsx +151 -0
- package/src/admin/components/label-output-section.tsx +63 -0
- package/src/admin/components/overview-cards.tsx +98 -0
- package/src/admin/components/product-barcode-card.tsx +127 -0
- package/src/admin/components/providers-cache-table.tsx +61 -0
- package/src/admin/components/providers-overview-section.tsx +49 -0
- package/src/admin/components/rbac-guard.tsx +153 -0
- package/src/admin/components/stock-take-scanner-section.tsx +116 -0
- package/src/admin/components/stock-take-sessions-section.tsx +109 -0
- package/src/admin/hooks/use-barcode-studio.ts +466 -0
- package/src/admin/hooks/use-product-barcodes.ts +139 -0
- package/src/admin/i18n/README.md +130 -0
- package/src/admin/i18n/index.ts +36 -0
- package/src/admin/i18n/json/ar.json +157 -0
- package/src/admin/i18n/json/de.json +157 -0
- package/src/admin/i18n/json/en.json +157 -0
- package/src/admin/i18n/json/es.json +157 -0
- package/src/admin/i18n/json/fr.json +157 -0
- package/src/admin/i18n/json/it.json +157 -0
- package/src/admin/i18n/json/nl.json +157 -0
- package/src/admin/i18n/json/pl.json +157 -0
- package/src/admin/i18n/json/pt.json +157 -0
- package/src/admin/i18n/json/tr.json +157 -0
- package/src/admin/routes/barcodes/lookup/page.tsx +75 -0
- package/src/admin/routes/barcodes/page.tsx +212 -0
- package/src/admin/routes/barcodes/print/page.tsx +67 -0
- package/src/admin/routes/barcodes/providers/page.tsx +66 -0
- package/src/admin/routes/barcodes/stock-take/page.tsx +74 -0
- package/src/admin/routes/barcodes/tags/@create/page.tsx +56 -0
- package/src/admin/routes/barcodes/tags/page.tsx +72 -0
- package/src/admin/tsconfig.json +20 -0
- package/src/admin/vite-env.d.ts +1 -0
- package/src/admin/widgets/product-barcode-widget.tsx +43 -0
- package/src/api/README.md +117 -0
- package/src/api/admin/barcodes/[barcode]/route.ts +64 -0
- package/src/api/admin/barcodes/batch/route.ts +12 -0
- package/src/api/admin/barcodes/bulk-generate/route.ts +12 -0
- package/src/api/admin/barcodes/cache/route.ts +35 -0
- package/src/api/admin/barcodes/count-sessions/[id]/apply/route.ts +17 -0
- package/src/api/admin/barcodes/count-sessions/[id]/scan/route.ts +17 -0
- package/src/api/admin/barcodes/count-sessions/route.ts +43 -0
- package/src/api/admin/barcodes/create-from-barcode/route.ts +16 -0
- package/src/api/admin/barcodes/lookup/route.ts +19 -0
- package/src/api/admin/barcodes/print/route.ts +18 -0
- package/src/api/admin/barcodes/route.ts +36 -0
- package/src/api/admin/barcodes/scan/route.ts +32 -0
- package/src/api/admin/barcodes/tags/[id]/route.ts +41 -0
- package/src/api/admin/barcodes/tags/route.ts +36 -0
- package/src/api/admin/barcodes/templates/route.ts +51 -0
- package/src/api/admin/plugin/route.ts +5 -0
- package/src/api/admin/variants/barcode/[code]/route.ts +36 -0
- package/src/api/middlewares.ts +91 -0
- package/src/api/store/barcodes/[code]/route.ts +43 -0
- package/src/api/store/barcodes/[code]/verify/route.ts +35 -0
- package/src/api/store/plugin/route.ts +5 -0
- package/src/api/store/variants/barcode/[code]/route.ts +36 -0
- package/src/api/validators.ts +217 -0
- package/src/hooks/index.ts +270 -0
- package/src/index.ts +4 -0
- package/src/jobs/README.md +54 -0
- package/src/jobs/purge-expired-barcode-cache.ts +18 -0
- package/src/links/README.md +44 -0
- package/src/modules/README.md +85 -0
- package/src/modules/barcode/index.ts +18 -0
- package/src/modules/barcode/migrations/Migration20260522000000.ts +225 -0
- package/src/modules/barcode/models/index.ts +168 -0
- package/src/modules/barcode/operations/context.ts +14 -0
- package/src/modules/barcode/operations/data-service.ts +10 -0
- package/src/modules/barcode/operations/generation.ts +57 -0
- package/src/modules/barcode/operations/index.ts +8 -0
- package/src/modules/barcode/operations/labels.ts +90 -0
- package/src/modules/barcode/operations/lookup.ts +202 -0
- package/src/modules/barcode/operations/maintenance.ts +53 -0
- package/src/modules/barcode/operations/stock-count.ts +217 -0
- package/src/modules/barcode/operations/tags.ts +425 -0
- package/src/modules/barcode/providers/index.ts +958 -0
- package/src/modules/barcode/service.ts +243 -0
- package/src/modules/barcode/types.ts +297 -0
- package/src/modules/barcode/utils/barcode-parser.ts +453 -0
- package/src/modules/barcode/utils/label-printer.ts +641 -0
- package/src/modules/barcode/utils/normalize-product.ts +524 -0
- package/src/modules/barcode/utils/security.ts +136 -0
- package/src/modules/barcode/utils/svg-renderer.ts +574 -0
- package/src/providers/README.md +105 -0
- package/src/rbac.ts +144 -0
- package/src/sdk/index.ts +253 -0
- package/src/subscribers/README.md +73 -0
- package/src/subscribers/product-created.ts +45 -0
- package/src/types/index.ts +1 -0
- package/src/types/medusa-ui.d.ts +118 -0
- package/src/ui/index.tsx +311 -0
- package/src/workflows/README.md +56 -0
- package/src/workflows/apply-inventory-count.ts +115 -0
- package/src/workflows/batch-barcode-import.ts +218 -0
- package/src/workflows/bulk-generate-variant-barcodes.ts +214 -0
- package/src/workflows/generate-barcode-tag.ts +85 -0
- package/src/workflows/helpers.ts +21 -0
- package/src/workflows/index.ts +6 -0
- package/src/workflows/lookup-and-create-product.ts +298 -0
- package/src/workflows/scan-inventory-count.ts +45 -0
- package/tsconfig.json +40 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# API Routes
|
|
2
|
+
|
|
3
|
+
File-based REST routes under the `admin` and `store` surfaces, following Medusa v2's `src/api/<surface>/<path>/route.ts` convention.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
api/
|
|
7
|
+
├── validators.ts Zod schemas for all Admin & Store request bodies
|
|
8
|
+
├── middlewares.ts Route-level validateAndTransformBody middleware bindings
|
|
9
|
+
├── admin/
|
|
10
|
+
│ ├── plugin/
|
|
11
|
+
│ │ └── route.ts GET /admin/plugin — plugin health check
|
|
12
|
+
│ └── barcodes/
|
|
13
|
+
│ ├── route.ts GET /admin/barcodes — list linked products & studio overview
|
|
14
|
+
│ ├── lookup/
|
|
15
|
+
│ │ └── route.ts POST /admin/barcodes/lookup — 10-provider GTIN/ISBN lookup
|
|
16
|
+
│ ├── create-from-barcode/
|
|
17
|
+
│ │ └── route.ts POST /admin/barcodes/create-from-barcode — lookup & create product
|
|
18
|
+
│ ├── batch/
|
|
19
|
+
│ │ └── route.ts POST /admin/barcodes/batch — batch import up to 100 barcodes
|
|
20
|
+
│ ├── bulk-generate/
|
|
21
|
+
│ │ └── route.ts POST /admin/barcodes/bulk-generate — assign GS1 EAN-13 to variants
|
|
22
|
+
│ ├── scan/
|
|
23
|
+
│ │ └── route.ts POST /admin/barcodes/scan — quick scan lookup / stock adjust
|
|
24
|
+
│ ├── cache/
|
|
25
|
+
│ │ └── route.ts GET, DELETE /admin/barcodes/cache — inspect or purge cache
|
|
26
|
+
│ ├── [barcode]/
|
|
27
|
+
│ │ └── route.ts GET, DELETE /admin/barcodes/:barcode — inspect or delete barcode
|
|
28
|
+
│ ├── tags/
|
|
29
|
+
│ │ ├── route.ts GET, POST /admin/barcodes/tags — list or create 1D/2D & QR tags
|
|
30
|
+
│ │ └── [id]/
|
|
31
|
+
│ │ └── route.ts GET, PATCH, DELETE /admin/barcodes/tags/:id — manage tag by ID
|
|
32
|
+
│ ├── templates/
|
|
33
|
+
│ │ └── route.ts GET, POST /admin/barcodes/templates — list presets or save template
|
|
34
|
+
│ ├── print/
|
|
35
|
+
│ │ └── route.ts POST /admin/barcodes/print — render HTML+SVG & Zebra ZPL II labels
|
|
36
|
+
│ └── count-sessions/
|
|
37
|
+
│ ├── route.ts GET, POST /admin/barcodes/count-sessions — list or start session
|
|
38
|
+
│ └── [id]/
|
|
39
|
+
│ ├── scan/
|
|
40
|
+
│ │ └── route.ts POST /admin/barcodes/count-sessions/:id/scan — record item scan
|
|
41
|
+
│ └── apply/
|
|
42
|
+
│ └── route.ts POST /admin/barcodes/count-sessions/:id/apply — apply variance
|
|
43
|
+
└── store/
|
|
44
|
+
├── plugin/
|
|
45
|
+
│ └── route.ts GET /store/plugin — storefront plugin status
|
|
46
|
+
└── barcodes/
|
|
47
|
+
└── [code]/
|
|
48
|
+
├── route.ts GET /store/barcodes/:code — resolve scan (?format=json|svg)
|
|
49
|
+
└── verify/
|
|
50
|
+
└── route.ts GET, POST /store/barcodes/:code/verify — verify HMAC-SHA256 seal
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Admin endpoints (`15` barcode routes)
|
|
56
|
+
|
|
57
|
+
| Method(s) | Path | Zod Validator | Workflow / Service Delegate | Description |
|
|
58
|
+
| ------------------------ | ------------------------------------------ | ---------------------------------------- | ---------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
59
|
+
| `GET` | `/admin/barcodes` | — | `BarcodeModuleService` | Lists `BarcodeProduct` links (filterable by `?product_id=`), tags, sessions, cache stats & active providers |
|
|
60
|
+
| `POST` | `/admin/barcodes/lookup` | `LookupBarcodeBodySchema` | `barcodeService.lookupBarcode` | Queries the 10-provider chain (`first-hit` or `deep-merge`) without creating a product |
|
|
61
|
+
| `POST` | `/admin/barcodes/create-from-barcode` | `CreateFromBarcodeBodySchema` | `lookupAndCreateProductWorkflow` | Enriches a barcode and creates a Medusa Product + Variant + `BarcodeProduct` link |
|
|
62
|
+
| `POST` | `/admin/barcodes/batch` | `BatchBarcodeImportBodySchema` | `batchBarcodeImportWorkflow` | Batch-imports up to 100 barcodes into Medusa Products + Variants with rollback compensation |
|
|
63
|
+
| `POST` | `/admin/barcodes/bulk-generate` | `BulkGenerateBarcodesBodySchema` | `bulkGenerateVariantBarcodesWorkflow` | Generates GS1 in-store (`200`–`299`) EAN-13 codes for variants and syncs `barcode`/`ean`/`upc` |
|
|
64
|
+
| `POST` | `/admin/barcodes/scan` | `QuickScanAdjustBodySchema` | `BarcodeModuleService` / `Modules.INVENTORY` | Resolves a scanned barcode and performs optional `lookup`, `increment`, `decrement`, or `set` stock actions |
|
|
65
|
+
| `GET`, `DELETE` | `/admin/barcodes/cache` | — | `barcodeService.purgeExpiredCache` / `clearAllCache` | Lists `barcode_cache` rows or purges expired entries (`?all=true` clears all cache rows) |
|
|
66
|
+
| `GET`, `DELETE` | `/admin/barcodes/:barcode` | — | `BarcodeModuleService` | Returns parsed GS1 metadata, linked `BarcodeProduct`, `BarcodeTag`, and SVG, or deletes mapping/cache |
|
|
67
|
+
| `GET`, `POST` | `/admin/barcodes/tags` | `CreateBarcodeTagBodySchema` (`POST`) | `generateBarcodeTagWorkflow` | Lists `BarcodeTag` rows (`?product_id=`, `?target_id=`) or creates a signed 1D/2D `BarcodeTag` |
|
|
68
|
+
| `GET`, `PATCH`, `DELETE` | `/admin/barcodes/tags/:id` | `UpdateBarcodeTagBodySchema` (`PATCH`) | `BarcodeModuleService` | Retrieves, updates, or deletes a specific `BarcodeTag` by ID |
|
|
69
|
+
| `GET`, `POST` | `/admin/barcodes/templates` | `CreateLabelTemplateBodySchema` (`POST`) | `BarcodeModuleService` | Lists all 7 built-in thermal/A4 presets + custom templates, or creates a custom `BarcodeLabelTemplate` |
|
|
70
|
+
| `POST` | `/admin/barcodes/print` | `PrintLabelsBodySchema` | `barcodeService.printLabels` | Renders print-ready HTML+SVG sheets and raw Zebra ZPL II (`^XA...^XZ`) thermal commands |
|
|
71
|
+
| `GET`, `POST` | `/admin/barcodes/count-sessions` | `CreateCountSessionBodySchema` (`POST`) | `barcodeService.startCountSession` | Lists warehouse stock-take sessions with items, or starts a new `BarcodeCountSession` |
|
|
72
|
+
| `POST` | `/admin/barcodes/count-sessions/:id/scan` | `RecordCountScanBodySchema` | `scanInventoryCountWorkflow` | Records a barcode scan (`delta` or `set_quantity`) inside an active count session |
|
|
73
|
+
| `POST` | `/admin/barcodes/count-sessions/:id/apply` | `ApplyCountSessionBodySchema` | `applyInventoryCountWorkflow` | Completes a count session and reconciles stock variances with `Modules.INVENTORY` |
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Store endpoints (`2` barcode routes)
|
|
78
|
+
|
|
79
|
+
| Method(s) | Path | Zod Validator | Service Delegate | Description |
|
|
80
|
+
| ------------- | ------------------------------ | --------------------------------------- | -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
81
|
+
| `GET` | `/store/barcodes/:code` | — | `barcodeService.resolveStoreScan` | Resolves a barcode/QR scan and increments `scan_count` (`?format=json`), or streams raw `image/svg+xml` (`?format=svg&symbology=ean13`) |
|
|
82
|
+
| `GET`, `POST` | `/store/barcodes/:code/verify` | `VerifyStoreBarcodeBodySchema` (`POST`) | `barcodeService.verifyTagAuthenticity` | Constant-time `HMAC-SHA256` anti-counterfeit verification via `?sig=` query param or JSON body `{ signature }` |
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Validation & middlewares
|
|
87
|
+
|
|
88
|
+
All request body schemas are defined in `src/api/validators.ts` (importing `z` from `@medusajs/framework/zod`) with strict length, numeric, and array bounds (e.g., max 100 barcodes per batch import, max 200 items per label print request).
|
|
89
|
+
|
|
90
|
+
`src/api/middlewares.ts` binds each schema to its route and HTTP method using `defineMiddlewares` and `validateAndTransformBody`:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import {
|
|
94
|
+
defineMiddlewares,
|
|
95
|
+
validateAndTransformBody,
|
|
96
|
+
} from "@medusajs/framework/http"
|
|
97
|
+
import { LookupBarcodeBodySchema } from "./validators"
|
|
98
|
+
|
|
99
|
+
export default defineMiddlewares({
|
|
100
|
+
routes: [
|
|
101
|
+
{
|
|
102
|
+
matcher: "/admin/barcodes/lookup",
|
|
103
|
+
method: ["POST"],
|
|
104
|
+
middlewares: [validateAndTransformBody(LookupBarcodeBodySchema)],
|
|
105
|
+
},
|
|
106
|
+
// ...
|
|
107
|
+
],
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Route file conventions
|
|
114
|
+
|
|
115
|
+
- Each `route.ts` file exports named HTTP verb functions (`GET`, `POST`, `PATCH`, `DELETE`).
|
|
116
|
+
- Route handlers read validated bodies from `req.validatedBody` (falling back to `req.body` if needed), resolve `BARCODE_MODULE` or execute one of the 6 workflows from `src/workflows/index.ts` via `req.scope`, and return structured JSON (or `image/svg+xml` when `?format=svg` is requested on `/store/barcodes/:code`).
|
|
117
|
+
- No domain math, SVG rendering, or external HTTP calls live directly inside route handlers.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type { BarcodeModuleService } from "../../../../modules/barcode/service"
|
|
3
|
+
import { BARCODE_MODULE } from "../../../../modules/barcode/types"
|
|
4
|
+
|
|
5
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const barcodeService = req.scope.resolve(
|
|
7
|
+
BARCODE_MODULE
|
|
8
|
+
) as BarcodeModuleService
|
|
9
|
+
const rawBarcode = req.params.barcode || ""
|
|
10
|
+
const parsed = await barcodeService.parseAndValidateBarcode(rawBarcode)
|
|
11
|
+
|
|
12
|
+
const [products, tags, svg] = await Promise.all([
|
|
13
|
+
barcodeService.listBarcodeProducts(
|
|
14
|
+
{ barcode: parsed.normalized },
|
|
15
|
+
{ take: 1 }
|
|
16
|
+
),
|
|
17
|
+
barcodeService.listBarcodeTags({ code: parsed.normalized }, { take: 1 }),
|
|
18
|
+
barcodeService.renderSvg({
|
|
19
|
+
code: parsed.normalized,
|
|
20
|
+
symbology: parsed.type === "unknown" ? "code128" : parsed.type,
|
|
21
|
+
}),
|
|
22
|
+
])
|
|
23
|
+
|
|
24
|
+
res.json({
|
|
25
|
+
barcode: parsed.normalized,
|
|
26
|
+
parsed,
|
|
27
|
+
barcode_product: products[0] || null,
|
|
28
|
+
tag: tags[0] || null,
|
|
29
|
+
svg,
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function DELETE(req: MedusaRequest, res: MedusaResponse) {
|
|
34
|
+
const barcodeService = req.scope.resolve(
|
|
35
|
+
BARCODE_MODULE
|
|
36
|
+
) as BarcodeModuleService
|
|
37
|
+
const rawBarcode = req.params.barcode || ""
|
|
38
|
+
const parsed = await barcodeService.parseAndValidateBarcode(rawBarcode)
|
|
39
|
+
|
|
40
|
+
const [products, caches] = await Promise.all([
|
|
41
|
+
barcodeService.listBarcodeProducts(
|
|
42
|
+
{ barcode: parsed.normalized },
|
|
43
|
+
{ take: 20 }
|
|
44
|
+
),
|
|
45
|
+
barcodeService.listBarcodeCaches(
|
|
46
|
+
{ barcode: parsed.normalized },
|
|
47
|
+
{ take: 20 }
|
|
48
|
+
),
|
|
49
|
+
])
|
|
50
|
+
|
|
51
|
+
if (products.length > 0) {
|
|
52
|
+
await barcodeService.deleteBarcodeProducts(products.map((p) => p.id))
|
|
53
|
+
}
|
|
54
|
+
if (caches.length > 0) {
|
|
55
|
+
await barcodeService.deleteBarcodeCaches(caches.map((c) => c.id))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
res.json({
|
|
59
|
+
deleted: true,
|
|
60
|
+
barcode: parsed.normalized,
|
|
61
|
+
deleted_products: products.length,
|
|
62
|
+
deleted_caches: caches.length,
|
|
63
|
+
})
|
|
64
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { batchBarcodeImportWorkflow } from "../../../../workflows"
|
|
3
|
+
import type { BatchBarcodeImportBody } from "../../../validators"
|
|
4
|
+
|
|
5
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const body = req.validatedBody as BatchBarcodeImportBody
|
|
7
|
+
const { result } = await batchBarcodeImportWorkflow(req.scope).run({
|
|
8
|
+
input: body,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
res.status(201).json(result)
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { bulkGenerateVariantBarcodesWorkflow } from "../../../../workflows"
|
|
3
|
+
import type { BulkGenerateBarcodesBody } from "../../../validators"
|
|
4
|
+
|
|
5
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const body = req.validatedBody as BulkGenerateBarcodesBody
|
|
7
|
+
const { result } = await bulkGenerateVariantBarcodesWorkflow(req.scope).run({
|
|
8
|
+
input: body,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
res.status(201).json(result)
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type { BarcodeModuleService } from "../../../../modules/barcode/service"
|
|
3
|
+
import { BARCODE_MODULE } from "../../../../modules/barcode/types"
|
|
4
|
+
|
|
5
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const barcodeService = req.scope.resolve(
|
|
7
|
+
BARCODE_MODULE
|
|
8
|
+
) as BarcodeModuleService
|
|
9
|
+
|
|
10
|
+
const caches = await barcodeService.listBarcodeCaches({}, { take: 200 })
|
|
11
|
+
res.json({
|
|
12
|
+
cache_entries: caches,
|
|
13
|
+
count: caches.length,
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function DELETE(req: MedusaRequest, res: MedusaResponse) {
|
|
18
|
+
const barcodeService = req.scope.resolve(
|
|
19
|
+
BARCODE_MODULE
|
|
20
|
+
) as BarcodeModuleService
|
|
21
|
+
|
|
22
|
+
const clearAll = req.query.all === "true"
|
|
23
|
+
if (clearAll) {
|
|
24
|
+
const all = await barcodeService.listBarcodeCaches({}, { take: 1000 })
|
|
25
|
+
const ids = all.map((c) => c.id)
|
|
26
|
+
if (ids.length > 0) {
|
|
27
|
+
await barcodeService.deleteBarcodeCaches(ids)
|
|
28
|
+
}
|
|
29
|
+
res.json({ purged_count: ids.length })
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const result = await barcodeService.purgeExpiredCache()
|
|
34
|
+
res.json(result)
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { applyInventoryCountWorkflow } from "../../../../../../workflows"
|
|
3
|
+
import type { ApplyCountSessionBody } from "../../../../../validators"
|
|
4
|
+
|
|
5
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const sessionId = req.params.id || ""
|
|
7
|
+
const body = (req.validatedBody || {}) as ApplyCountSessionBody
|
|
8
|
+
|
|
9
|
+
const { result } = await applyInventoryCountWorkflow(req.scope).run({
|
|
10
|
+
input: {
|
|
11
|
+
session_id: sessionId,
|
|
12
|
+
location_id: body.location_id,
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
res.json(result)
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { scanInventoryCountWorkflow } from "../../../../../../workflows"
|
|
3
|
+
import type { RecordCountScanBody } from "../../../../../validators"
|
|
4
|
+
|
|
5
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const sessionId = req.params.id || ""
|
|
7
|
+
const body = req.validatedBody as RecordCountScanBody
|
|
8
|
+
|
|
9
|
+
const { result } = await scanInventoryCountWorkflow(req.scope).run({
|
|
10
|
+
input: {
|
|
11
|
+
session_id: sessionId,
|
|
12
|
+
...body,
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
res.json(result)
|
|
17
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type { BarcodeModuleService } from "../../../../modules/barcode/service"
|
|
3
|
+
import { BARCODE_MODULE } from "../../../../modules/barcode/types"
|
|
4
|
+
import type { CreateCountSessionBody } from "../../../validators"
|
|
5
|
+
|
|
6
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
7
|
+
const barcodeService = req.scope.resolve(
|
|
8
|
+
BARCODE_MODULE
|
|
9
|
+
) as BarcodeModuleService
|
|
10
|
+
|
|
11
|
+
const sessions = await barcodeService.listBarcodeCountSessions(
|
|
12
|
+
{},
|
|
13
|
+
{ take: 100 }
|
|
14
|
+
)
|
|
15
|
+
const items = await barcodeService.listBarcodeCountItems({}, { take: 1000 })
|
|
16
|
+
|
|
17
|
+
const itemsBySession = new Map<string, typeof items>()
|
|
18
|
+
for (const item of items) {
|
|
19
|
+
const list = itemsBySession.get(item.session_id) || []
|
|
20
|
+
list.push(item)
|
|
21
|
+
itemsBySession.set(item.session_id, list)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const enriched = sessions.map((session) => ({
|
|
25
|
+
...session,
|
|
26
|
+
items: itemsBySession.get(session.id) || [],
|
|
27
|
+
}))
|
|
28
|
+
|
|
29
|
+
res.json({
|
|
30
|
+
sessions: enriched,
|
|
31
|
+
count: enriched.length,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
36
|
+
const barcodeService = req.scope.resolve(
|
|
37
|
+
BARCODE_MODULE
|
|
38
|
+
) as BarcodeModuleService
|
|
39
|
+
const body = req.validatedBody as CreateCountSessionBody
|
|
40
|
+
|
|
41
|
+
const created = await barcodeService.createStockCountSession(body)
|
|
42
|
+
res.status(201).json(created)
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { lookupAndCreateProductWorkflow } from "../../../../workflows"
|
|
3
|
+
import type { CreateFromBarcodeBody } from "../../../validators"
|
|
4
|
+
|
|
5
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const body = req.validatedBody as CreateFromBarcodeBody
|
|
7
|
+
const { result } = await lookupAndCreateProductWorkflow(req.scope).run({
|
|
8
|
+
input: body as Parameters<
|
|
9
|
+
typeof lookupAndCreateProductWorkflow
|
|
10
|
+
>[0] extends never
|
|
11
|
+
? never
|
|
12
|
+
: any,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
res.status(201).json(result)
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type { BarcodeModuleService } from "../../../../modules/barcode/service"
|
|
3
|
+
import { BARCODE_MODULE } from "../../../../modules/barcode/types"
|
|
4
|
+
import type { LookupBarcodeBody } from "../../../validators"
|
|
5
|
+
|
|
6
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
7
|
+
const barcodeService = req.scope.resolve(
|
|
8
|
+
BARCODE_MODULE
|
|
9
|
+
) as BarcodeModuleService
|
|
10
|
+
const body = req.validatedBody as LookupBarcodeBody
|
|
11
|
+
|
|
12
|
+
const result = await barcodeService.lookupBarcode(body.barcode, {
|
|
13
|
+
skipCache: body.skipCache,
|
|
14
|
+
strategy: body.strategy,
|
|
15
|
+
providers: body.providers,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
res.json(result)
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import type { BarcodeModuleService } from "../../../../modules/barcode/service"
|
|
3
|
+
import { BARCODE_MODULE } from "../../../../modules/barcode/types"
|
|
4
|
+
import type { PrintLabelsBody } from "../../../validators"
|
|
5
|
+
|
|
6
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
7
|
+
const barcodeService = req.scope.resolve(
|
|
8
|
+
BARCODE_MODULE
|
|
9
|
+
) as BarcodeModuleService
|
|
10
|
+
const body = req.validatedBody as PrintLabelsBody
|
|
11
|
+
|
|
12
|
+
const output = await barcodeService.renderLabels({
|
|
13
|
+
template_id: body.template_id,
|
|
14
|
+
items: body.items,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
res.json(output)
|
|
18
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
import type { BarcodeModuleService } from "../../../modules/barcode/service"
|
|
4
|
+
import { BARCODE_MODULE } from "../../../modules/barcode/types"
|
|
5
|
+
|
|
6
|
+
const AdminListBarcodesQuerySchema = z.object({
|
|
7
|
+
product_id: z.string().min(1).max(256).optional(),
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
11
|
+
const parsed = AdminListBarcodesQuerySchema.safeParse(req.query || {})
|
|
12
|
+
if (!parsed.success) {
|
|
13
|
+
return res.status(400).json({
|
|
14
|
+
message: "Invalid query parameters",
|
|
15
|
+
errors: parsed.error.flatten().fieldErrors,
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const barcodeService = req.scope.resolve(
|
|
20
|
+
BARCODE_MODULE
|
|
21
|
+
) as BarcodeModuleService
|
|
22
|
+
|
|
23
|
+
const productId = parsed.data.product_id
|
|
24
|
+
const filter = productId ? { product_id: productId } : {}
|
|
25
|
+
|
|
26
|
+
const [barcodeProducts, overview] = await Promise.all([
|
|
27
|
+
barcodeService.listBarcodeProducts(filter, { take: 200 }),
|
|
28
|
+
barcodeService.getAnalyticsOverview(),
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
res.json({
|
|
32
|
+
barcodes: barcodeProducts,
|
|
33
|
+
count: barcodeProducts.length,
|
|
34
|
+
overview,
|
|
35
|
+
})
|
|
36
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
|
|
3
|
+
import type { BarcodeModuleService } from "../../../../modules/barcode/service"
|
|
4
|
+
import { BARCODE_MODULE } from "../../../../modules/barcode/types"
|
|
5
|
+
import type { QuickScanAdjustBody } from "../../../validators"
|
|
6
|
+
|
|
7
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
8
|
+
const barcodeService = req.scope.resolve(
|
|
9
|
+
BARCODE_MODULE
|
|
10
|
+
) as BarcodeModuleService
|
|
11
|
+
const body = req.validatedBody as QuickScanAdjustBody
|
|
12
|
+
|
|
13
|
+
const resolved = await barcodeService.resolveBarcodeScan(body.barcode, {
|
|
14
|
+
scope: req.scope,
|
|
15
|
+
hydrateVariant: true,
|
|
16
|
+
})
|
|
17
|
+
const action = body.action || "lookup"
|
|
18
|
+
const quantityDelta =
|
|
19
|
+
action === "increment"
|
|
20
|
+
? (body.quantity ?? 1)
|
|
21
|
+
: action === "decrement"
|
|
22
|
+
? -(body.quantity ?? 1)
|
|
23
|
+
: (body.quantity ?? 0)
|
|
24
|
+
|
|
25
|
+
res.json({
|
|
26
|
+
...resolved,
|
|
27
|
+
inventory_action: action,
|
|
28
|
+
quantity_delta: quantityDelta,
|
|
29
|
+
location_id: body.location_id ?? null,
|
|
30
|
+
scanned_at: new Date().toISOString(),
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
|
|
3
|
+
import type { BarcodeModuleService } from "../../../../../modules/barcode/service"
|
|
4
|
+
import { BARCODE_MODULE } from "../../../../../modules/barcode/types"
|
|
5
|
+
import type { UpdateBarcodeTagBody } from "../../../../validators"
|
|
6
|
+
|
|
7
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
8
|
+
const barcodeService = req.scope.resolve(
|
|
9
|
+
BARCODE_MODULE
|
|
10
|
+
) as BarcodeModuleService
|
|
11
|
+
const id = req.params.id || ""
|
|
12
|
+
const rows = await barcodeService.listBarcodeTags({ id }, { take: 1 })
|
|
13
|
+
if (!rows[0]) {
|
|
14
|
+
res.status(404).json({ message: `BarcodeTag ${id} not found` })
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
res.json({ tag: rows[0] })
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function PATCH(req: MedusaRequest, res: MedusaResponse) {
|
|
21
|
+
const barcodeService = req.scope.resolve(
|
|
22
|
+
BARCODE_MODULE
|
|
23
|
+
) as BarcodeModuleService
|
|
24
|
+
const id = req.params.id || ""
|
|
25
|
+
const body = req.validatedBody as UpdateBarcodeTagBody
|
|
26
|
+
|
|
27
|
+
const updated = await barcodeService.updateBarcodeTags({
|
|
28
|
+
id,
|
|
29
|
+
...body,
|
|
30
|
+
})
|
|
31
|
+
res.json({ tag: updated })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function DELETE(req: MedusaRequest, res: MedusaResponse) {
|
|
35
|
+
const barcodeService = req.scope.resolve(
|
|
36
|
+
BARCODE_MODULE
|
|
37
|
+
) as BarcodeModuleService
|
|
38
|
+
const id = req.params.id || ""
|
|
39
|
+
await barcodeService.deleteBarcodeTags([id])
|
|
40
|
+
res.json({ id, object: "barcode_tag", deleted: true })
|
|
41
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
|
|
3
|
+
import type { BarcodeModuleService } from "../../../../modules/barcode/service"
|
|
4
|
+
import { BARCODE_MODULE } from "../../../../modules/barcode/types"
|
|
5
|
+
import { generateBarcodeTagWorkflow } from "../../../../workflows"
|
|
6
|
+
import type { CreateBarcodeTagBody } from "../../../validators"
|
|
7
|
+
|
|
8
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
9
|
+
const barcodeService = req.scope.resolve(
|
|
10
|
+
BARCODE_MODULE
|
|
11
|
+
) as BarcodeModuleService
|
|
12
|
+
|
|
13
|
+
const productId =
|
|
14
|
+
typeof req.query.product_id === "string" ? req.query.product_id : undefined
|
|
15
|
+
const targetId =
|
|
16
|
+
typeof req.query.target_id === "string" ? req.query.target_id : undefined
|
|
17
|
+
|
|
18
|
+
const filter: Record<string, unknown> = {}
|
|
19
|
+
if (productId) filter.product_id = productId
|
|
20
|
+
if (targetId) filter.target_id = targetId
|
|
21
|
+
|
|
22
|
+
const tags = await barcodeService.listBarcodeTags(filter, { take: 200 })
|
|
23
|
+
res.json({
|
|
24
|
+
tags,
|
|
25
|
+
count: tags.length,
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
30
|
+
const body = req.validatedBody as CreateBarcodeTagBody
|
|
31
|
+
const { result } = await generateBarcodeTagWorkflow(req.scope).run({
|
|
32
|
+
input: body,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
res.status(201).json({ tag: result })
|
|
36
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
|
|
3
|
+
import type { BarcodeModuleService } from "../../../../modules/barcode/service"
|
|
4
|
+
import { BARCODE_MODULE } from "../../../../modules/barcode/types"
|
|
5
|
+
import type { CreateLabelTemplateBody } from "../../../validators"
|
|
6
|
+
|
|
7
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
8
|
+
const barcodeService = req.scope.resolve(
|
|
9
|
+
BARCODE_MODULE
|
|
10
|
+
) as BarcodeModuleService
|
|
11
|
+
const templates = await barcodeService.listAllLabelTemplates()
|
|
12
|
+
res.json({
|
|
13
|
+
templates,
|
|
14
|
+
count: templates.length,
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
19
|
+
const barcodeService = req.scope.resolve(
|
|
20
|
+
BARCODE_MODULE
|
|
21
|
+
) as BarcodeModuleService
|
|
22
|
+
const body = req.validatedBody as CreateLabelTemplateBody
|
|
23
|
+
|
|
24
|
+
const created = await barcodeService.createBarcodeLabelTemplates({
|
|
25
|
+
name: body.name,
|
|
26
|
+
preset_id: body.preset_id || "custom",
|
|
27
|
+
layout_type: body.layout_type || "thermal_roll",
|
|
28
|
+
width_mm: body.width_mm,
|
|
29
|
+
height_mm: body.height_mm,
|
|
30
|
+
columns: body.columns ?? 1,
|
|
31
|
+
rows: body.rows ?? 1,
|
|
32
|
+
margin_top_mm: body.margin_top_mm ?? 2,
|
|
33
|
+
margin_left_mm: body.margin_left_mm ?? 2,
|
|
34
|
+
gap_x_mm: body.gap_x_mm ?? 0,
|
|
35
|
+
gap_y_mm: body.gap_y_mm ?? 2,
|
|
36
|
+
symbology: body.symbology || "ean13",
|
|
37
|
+
show_title: body.show_title ?? true,
|
|
38
|
+
show_variant_title: body.show_variant_title ?? true,
|
|
39
|
+
show_sku: body.show_sku ?? true,
|
|
40
|
+
show_price: body.show_price ?? true,
|
|
41
|
+
show_compare_at_price: body.show_compare_at_price ?? true,
|
|
42
|
+
show_brand: body.show_brand ?? false,
|
|
43
|
+
show_qr: body.show_qr ?? false,
|
|
44
|
+
custom_header: body.custom_header ?? null,
|
|
45
|
+
custom_footer: body.custom_footer ?? null,
|
|
46
|
+
dpi: Number(body.dpi || 203),
|
|
47
|
+
is_default: body.is_default ?? false,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
res.status(201).json({ template: created })
|
|
51
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
|
|
3
|
+
import type { BarcodeModuleService } from "../../../../../modules/barcode/service"
|
|
4
|
+
import { BARCODE_MODULE } from "../../../../../modules/barcode/types"
|
|
5
|
+
|
|
6
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
7
|
+
const barcodeService = req.scope.resolve(
|
|
8
|
+
BARCODE_MODULE
|
|
9
|
+
) as BarcodeModuleService
|
|
10
|
+
const code = req.params.code || ""
|
|
11
|
+
|
|
12
|
+
const resolved = await barcodeService.resolveBarcodeScan(code, {
|
|
13
|
+
scope: req.scope,
|
|
14
|
+
hydrateVariant: true,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
if (!resolved.found) {
|
|
18
|
+
res.status(404).json({
|
|
19
|
+
message: `No variant or product found for barcode ${code}`,
|
|
20
|
+
code: resolved.code,
|
|
21
|
+
})
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
res.json({
|
|
26
|
+
code: resolved.code,
|
|
27
|
+
parsed: resolved.parsed,
|
|
28
|
+
found: resolved.found,
|
|
29
|
+
variant_id: resolved.variant_id,
|
|
30
|
+
product_id: resolved.product_id,
|
|
31
|
+
variant: resolved.variant,
|
|
32
|
+
product: resolved.product,
|
|
33
|
+
tag: resolved.tag,
|
|
34
|
+
barcode_product: resolved.barcode_product,
|
|
35
|
+
})
|
|
36
|
+
}
|