@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
package/src/rbac.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Auto-generated RBAC descriptors compatible with @abhi1693/medusa-rbac AccessControlOptions.
|
|
2
|
+
export type RbacPermissionTuple = readonly [
|
|
3
|
+
id: string,
|
|
4
|
+
label: string,
|
|
5
|
+
group: string,
|
|
6
|
+
]
|
|
7
|
+
export type RbacRoutePolicy = {
|
|
8
|
+
method: string
|
|
9
|
+
path: string
|
|
10
|
+
permissions: string[]
|
|
11
|
+
superuser?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const RBAC_PERMISSIONS: readonly RbacPermissionTuple[] = [
|
|
15
|
+
[
|
|
16
|
+
"barcodes.read",
|
|
17
|
+
"Read barcodes, tags, templates & count sessions",
|
|
18
|
+
"Barcodes",
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
"barcodes.write",
|
|
22
|
+
"Manage barcodes, tags, templates, printing & count sessions",
|
|
23
|
+
"Barcodes",
|
|
24
|
+
],
|
|
25
|
+
] as const
|
|
26
|
+
|
|
27
|
+
export const RBAC_ROUTES: RbacRoutePolicy[] = [
|
|
28
|
+
{
|
|
29
|
+
method: "GET",
|
|
30
|
+
path: "/admin/barcodes/:barcode",
|
|
31
|
+
permissions: ["barcodes.read"],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
method: "DELETE",
|
|
35
|
+
path: "/admin/barcodes/:barcode",
|
|
36
|
+
permissions: ["barcodes.write"],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
method: "POST",
|
|
40
|
+
path: "/admin/barcodes/batch",
|
|
41
|
+
permissions: ["barcodes.write"],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
method: "POST",
|
|
45
|
+
path: "/admin/barcodes/bulk-generate",
|
|
46
|
+
permissions: ["barcodes.write"],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
method: "GET",
|
|
50
|
+
path: "/admin/barcodes/cache",
|
|
51
|
+
permissions: ["barcodes.read"],
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
method: "DELETE",
|
|
55
|
+
path: "/admin/barcodes/cache",
|
|
56
|
+
permissions: ["barcodes.write"],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
method: "POST",
|
|
60
|
+
path: "/admin/barcodes/count-sessions/:id/apply",
|
|
61
|
+
permissions: ["barcodes.write"],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
method: "POST",
|
|
65
|
+
path: "/admin/barcodes/count-sessions/:id/scan",
|
|
66
|
+
permissions: ["barcodes.write"],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
method: "GET",
|
|
70
|
+
path: "/admin/barcodes/count-sessions",
|
|
71
|
+
permissions: ["barcodes.read"],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
method: "POST",
|
|
75
|
+
path: "/admin/barcodes/count-sessions",
|
|
76
|
+
permissions: ["barcodes.write"],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
method: "POST",
|
|
80
|
+
path: "/admin/barcodes/create-from-barcode",
|
|
81
|
+
permissions: ["barcodes.write"],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
method: "POST",
|
|
85
|
+
path: "/admin/barcodes/lookup",
|
|
86
|
+
permissions: ["barcodes.write"],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
method: "POST",
|
|
90
|
+
path: "/admin/barcodes/print",
|
|
91
|
+
permissions: ["barcodes.write"],
|
|
92
|
+
},
|
|
93
|
+
{ method: "GET", path: "/admin/barcodes", permissions: ["barcodes.read"] },
|
|
94
|
+
{
|
|
95
|
+
method: "POST",
|
|
96
|
+
path: "/admin/barcodes/scan",
|
|
97
|
+
permissions: ["barcodes.write"],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
method: "GET",
|
|
101
|
+
path: "/admin/barcodes/tags/:id",
|
|
102
|
+
permissions: ["barcodes.read"],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
method: "PATCH",
|
|
106
|
+
path: "/admin/barcodes/tags/:id",
|
|
107
|
+
permissions: ["barcodes.write"],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
method: "DELETE",
|
|
111
|
+
path: "/admin/barcodes/tags/:id",
|
|
112
|
+
permissions: ["barcodes.write"],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
method: "GET",
|
|
116
|
+
path: "/admin/barcodes/tags",
|
|
117
|
+
permissions: ["barcodes.read"],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
method: "POST",
|
|
121
|
+
path: "/admin/barcodes/tags",
|
|
122
|
+
permissions: ["barcodes.write"],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
method: "GET",
|
|
126
|
+
path: "/admin/barcodes/templates",
|
|
127
|
+
permissions: ["barcodes.read"],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
method: "POST",
|
|
131
|
+
path: "/admin/barcodes/templates",
|
|
132
|
+
permissions: ["barcodes.write"],
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
method: "GET",
|
|
136
|
+
path: "/admin/variants/barcode/:code",
|
|
137
|
+
permissions: ["barcodes.read"],
|
|
138
|
+
},
|
|
139
|
+
]
|
|
140
|
+
|
|
141
|
+
export const rbacAccess = {
|
|
142
|
+
permissions: [...RBAC_PERMISSIONS],
|
|
143
|
+
routes: RBAC_ROUTES,
|
|
144
|
+
}
|
package/src/sdk/index.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { MedusaError } from "@medusajs/framework/utils"
|
|
2
|
+
import type {
|
|
3
|
+
ApplyCountSessionBody,
|
|
4
|
+
BatchBarcodeImportBody,
|
|
5
|
+
BulkGenerateBarcodesBody,
|
|
6
|
+
CreateBarcodeTagBody,
|
|
7
|
+
CreateCountSessionBody,
|
|
8
|
+
CreateFromBarcodeBody,
|
|
9
|
+
CreateLabelTemplateBody,
|
|
10
|
+
LookupBarcodeBody,
|
|
11
|
+
PrintLabelsBody,
|
|
12
|
+
QuickScanAdjustBody,
|
|
13
|
+
RecordCountScanBody,
|
|
14
|
+
UpdateBarcodeTagBody,
|
|
15
|
+
} from "../api/validators"
|
|
16
|
+
import type {
|
|
17
|
+
BarcodeLookupChainResult,
|
|
18
|
+
BarcodeSymbology,
|
|
19
|
+
LabelPrintOutput,
|
|
20
|
+
LabelTemplateSpec,
|
|
21
|
+
} from "../modules/barcode/types"
|
|
22
|
+
|
|
23
|
+
export const barcodeQueryKeys = {
|
|
24
|
+
all: ["barcodes"] as const,
|
|
25
|
+
list: (filters?: { product_id?: string }) =>
|
|
26
|
+
filters
|
|
27
|
+
? (["barcodes", "list", filters] as const)
|
|
28
|
+
: (["barcodes", "list"] as const),
|
|
29
|
+
tags: (filters?: { product_id?: string; target_id?: string }) =>
|
|
30
|
+
filters
|
|
31
|
+
? (["barcodes", "tags", filters] as const)
|
|
32
|
+
: (["barcodes", "tags"] as const),
|
|
33
|
+
templates: () => ["barcodes", "templates"] as const,
|
|
34
|
+
countSessions: () => ["barcodes", "count-sessions"] as const,
|
|
35
|
+
cache: () => ["barcodes", "cache"] as const,
|
|
36
|
+
storeScan: (code: string) => ["barcodes", "store", code] as const,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface BarcodeSdkOptions {
|
|
40
|
+
baseUrl?: string
|
|
41
|
+
publishableApiKey?: string
|
|
42
|
+
fetchImpl?: typeof fetch
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function createBarcodeSdk(options?: BarcodeSdkOptions) {
|
|
46
|
+
const baseUrl = (options?.baseUrl ?? "").replace(/\/+$/, "")
|
|
47
|
+
const fetchImpl = options?.fetchImpl ?? globalThis.fetch
|
|
48
|
+
|
|
49
|
+
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
|
50
|
+
const headers: Record<string, string> = {
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
...(options?.publishableApiKey
|
|
53
|
+
? { "x-publishable-api-key": options.publishableApiKey }
|
|
54
|
+
: {}),
|
|
55
|
+
...(init?.headers as Record<string, string>),
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const res = await fetchImpl(`${baseUrl}${path}`, {
|
|
59
|
+
credentials: "include",
|
|
60
|
+
...init,
|
|
61
|
+
headers,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const json = (await res.json().catch(() => ({}))) as Record<string, unknown>
|
|
65
|
+
if (!res.ok) {
|
|
66
|
+
throw new MedusaError(
|
|
67
|
+
MedusaError.Types.UNEXPECTED_STATE,
|
|
68
|
+
String(json.message || json.error || `HTTP ${res.status}`)
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
return json as T
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
admin: {
|
|
76
|
+
listBarcodes(filters?: { product_id?: string }) {
|
|
77
|
+
const qs = filters?.product_id
|
|
78
|
+
? `?product_id=${encodeURIComponent(filters.product_id)}`
|
|
79
|
+
: ""
|
|
80
|
+
return request<{
|
|
81
|
+
barcodes: Array<Record<string, unknown>>
|
|
82
|
+
count: number
|
|
83
|
+
overview: Record<string, unknown>
|
|
84
|
+
}>(`/admin/barcodes${qs}`)
|
|
85
|
+
},
|
|
86
|
+
lookup(payload: LookupBarcodeBody) {
|
|
87
|
+
return request<BarcodeLookupChainResult>("/admin/barcodes/lookup", {
|
|
88
|
+
method: "POST",
|
|
89
|
+
body: JSON.stringify(payload),
|
|
90
|
+
})
|
|
91
|
+
},
|
|
92
|
+
createFromBarcode(payload: CreateFromBarcodeBody) {
|
|
93
|
+
return request<Record<string, unknown>>(
|
|
94
|
+
"/admin/barcodes/create-from-barcode",
|
|
95
|
+
{
|
|
96
|
+
method: "POST",
|
|
97
|
+
body: JSON.stringify(payload),
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
},
|
|
101
|
+
batchImport(payload: BatchBarcodeImportBody) {
|
|
102
|
+
return request<Record<string, unknown>>("/admin/barcodes/batch", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: JSON.stringify(payload),
|
|
105
|
+
})
|
|
106
|
+
},
|
|
107
|
+
bulkGenerate(payload: BulkGenerateBarcodesBody) {
|
|
108
|
+
return request<Record<string, unknown>>(
|
|
109
|
+
"/admin/barcodes/bulk-generate",
|
|
110
|
+
{
|
|
111
|
+
method: "POST",
|
|
112
|
+
body: JSON.stringify(payload),
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
},
|
|
116
|
+
quickScan(payload: QuickScanAdjustBody) {
|
|
117
|
+
return request<Record<string, unknown>>("/admin/barcodes/scan", {
|
|
118
|
+
method: "POST",
|
|
119
|
+
body: JSON.stringify(payload),
|
|
120
|
+
})
|
|
121
|
+
},
|
|
122
|
+
listTags(filters?: { product_id?: string; target_id?: string }) {
|
|
123
|
+
const params = new URLSearchParams()
|
|
124
|
+
if (filters?.product_id) params.set("product_id", filters.product_id)
|
|
125
|
+
if (filters?.target_id) params.set("target_id", filters.target_id)
|
|
126
|
+
const qs = params.toString() ? `?${params.toString()}` : ""
|
|
127
|
+
return request<{
|
|
128
|
+
tags: Array<Record<string, unknown>>
|
|
129
|
+
count: number
|
|
130
|
+
}>(`/admin/barcodes/tags${qs}`)
|
|
131
|
+
},
|
|
132
|
+
createTag(payload: CreateBarcodeTagBody) {
|
|
133
|
+
return request<{ tag: Record<string, unknown> }>(
|
|
134
|
+
"/admin/barcodes/tags",
|
|
135
|
+
{
|
|
136
|
+
method: "POST",
|
|
137
|
+
body: JSON.stringify(payload),
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
},
|
|
141
|
+
updateTag(id: string, payload: UpdateBarcodeTagBody) {
|
|
142
|
+
return request<{ tag: Record<string, unknown> }>(
|
|
143
|
+
`/admin/barcodes/tags/${encodeURIComponent(id)}`,
|
|
144
|
+
{
|
|
145
|
+
method: "PATCH",
|
|
146
|
+
body: JSON.stringify(payload),
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
},
|
|
150
|
+
deleteTag(id: string) {
|
|
151
|
+
return request<{ id: string; deleted: boolean }>(
|
|
152
|
+
`/admin/barcodes/tags/${encodeURIComponent(id)}`,
|
|
153
|
+
{ method: "DELETE" }
|
|
154
|
+
)
|
|
155
|
+
},
|
|
156
|
+
listTemplates() {
|
|
157
|
+
return request<{ templates: LabelTemplateSpec[]; count: number }>(
|
|
158
|
+
"/admin/barcodes/templates"
|
|
159
|
+
)
|
|
160
|
+
},
|
|
161
|
+
createTemplate(payload: CreateLabelTemplateBody) {
|
|
162
|
+
return request<{ template: Record<string, unknown> }>(
|
|
163
|
+
"/admin/barcodes/templates",
|
|
164
|
+
{
|
|
165
|
+
method: "POST",
|
|
166
|
+
body: JSON.stringify(payload),
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
},
|
|
170
|
+
printLabels(payload: PrintLabelsBody) {
|
|
171
|
+
return request<LabelPrintOutput>("/admin/barcodes/print", {
|
|
172
|
+
method: "POST",
|
|
173
|
+
body: JSON.stringify(payload),
|
|
174
|
+
})
|
|
175
|
+
},
|
|
176
|
+
listCountSessions() {
|
|
177
|
+
return request<{
|
|
178
|
+
sessions: Array<Record<string, unknown>>
|
|
179
|
+
count: number
|
|
180
|
+
}>("/admin/barcodes/count-sessions")
|
|
181
|
+
},
|
|
182
|
+
createCountSession(payload: CreateCountSessionBody) {
|
|
183
|
+
return request<Record<string, unknown>>(
|
|
184
|
+
"/admin/barcodes/count-sessions",
|
|
185
|
+
{
|
|
186
|
+
method: "POST",
|
|
187
|
+
body: JSON.stringify(payload),
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
},
|
|
191
|
+
recordCountScan(sessionId: string, payload: RecordCountScanBody) {
|
|
192
|
+
return request<Record<string, unknown>>(
|
|
193
|
+
`/admin/barcodes/count-sessions/${encodeURIComponent(
|
|
194
|
+
sessionId
|
|
195
|
+
)}/scan`,
|
|
196
|
+
{
|
|
197
|
+
method: "POST",
|
|
198
|
+
body: JSON.stringify(payload),
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
},
|
|
202
|
+
applyCountSession(sessionId: string, payload?: ApplyCountSessionBody) {
|
|
203
|
+
return request<Record<string, unknown>>(
|
|
204
|
+
`/admin/barcodes/count-sessions/${encodeURIComponent(
|
|
205
|
+
sessionId
|
|
206
|
+
)}/apply`,
|
|
207
|
+
{
|
|
208
|
+
method: "POST",
|
|
209
|
+
body: JSON.stringify(payload || {}),
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
},
|
|
213
|
+
listCache() {
|
|
214
|
+
return request<{
|
|
215
|
+
cache_entries: Array<Record<string, unknown>>
|
|
216
|
+
count: number
|
|
217
|
+
}>("/admin/barcodes/cache")
|
|
218
|
+
},
|
|
219
|
+
purgeCache(clearAll = false) {
|
|
220
|
+
const qs = clearAll ? "?all=true" : ""
|
|
221
|
+
return request<{ purged_count: number }>(`/admin/barcodes/cache${qs}`, {
|
|
222
|
+
method: "DELETE",
|
|
223
|
+
})
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
store: {
|
|
227
|
+
resolveScan(code: string) {
|
|
228
|
+
return request<Record<string, unknown>>(
|
|
229
|
+
`/store/barcodes/${encodeURIComponent(code)}`
|
|
230
|
+
)
|
|
231
|
+
},
|
|
232
|
+
getSvgUrl(code: string, symbology?: BarcodeSymbology) {
|
|
233
|
+
const sym = symbology
|
|
234
|
+
? `&symbology=${encodeURIComponent(symbology)}`
|
|
235
|
+
: ""
|
|
236
|
+
return `${baseUrl}/store/barcodes/${encodeURIComponent(
|
|
237
|
+
code
|
|
238
|
+
)}?format=svg${sym}`
|
|
239
|
+
},
|
|
240
|
+
verifyAuthenticity(code: string, signature: string) {
|
|
241
|
+
return request<{
|
|
242
|
+
valid: boolean
|
|
243
|
+
code: string
|
|
244
|
+
reason: string
|
|
245
|
+
tag: Record<string, unknown> | null
|
|
246
|
+
}>(`/store/barcodes/${encodeURIComponent(code)}/verify`, {
|
|
247
|
+
method: "POST",
|
|
248
|
+
body: JSON.stringify({ signature }),
|
|
249
|
+
})
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Subscribers
|
|
2
|
+
|
|
3
|
+
Event subscribers registered by `medusa-plugin-barcode` under `src/subscribers/`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
subscribers/
|
|
7
|
+
└── product-created.ts auto-assigns GS1 in-store EAN-13 barcodes on product/variant creation
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## `product-created.ts` (`productBarcodeSubscriber`)
|
|
13
|
+
|
|
14
|
+
| Property | Value |
|
|
15
|
+
| -------------------- | ------------------------------------------------------------------- |
|
|
16
|
+
| **File** | `src/subscribers/product-created.ts` |
|
|
17
|
+
| **Events** | `["product-variant.created", "product.created"]` |
|
|
18
|
+
| **Option Guard** | `options.autoGenerateVariantBarcode !== false` (enabled by default) |
|
|
19
|
+
| **Workflow Invoked** | `bulkGenerateVariantBarcodesWorkflow` |
|
|
20
|
+
|
|
21
|
+
### Behavior
|
|
22
|
+
|
|
23
|
+
Whenever Medusa emits `product-variant.created` or `product.created`:
|
|
24
|
+
|
|
25
|
+
1. `productBarcodeSubscriber` resolves `BARCODE_MODULE` (`"barcode"`) from `container` and reads `await barcodeService.getModuleOptions()`.
|
|
26
|
+
2. If `options.autoGenerateVariantBarcode === false`, the subscriber exits immediately without modifying the variant.
|
|
27
|
+
3. Otherwise, it extracts `event.data?.variant_id || event.data?.id` and executes `bulkGenerateVariantBarcodesWorkflow(container).run(...)` with:
|
|
28
|
+
- `variant_ids: [variantId]`
|
|
29
|
+
- `prefix: options.internalBarcodePrefix || "200"` (3-digit GS1 in-store prefix `200`–`299`)
|
|
30
|
+
- `overwrite: false` (never overwrites an existing barcode already set on the variant)
|
|
31
|
+
4. The workflow assigns a valid 13-digit GS1 EAN-13 barcode (plus matching `ean` and `upc` fields) on the variant in `Modules.PRODUCT` and creates a corresponding `BarcodeTag` row.
|
|
32
|
+
5. Any runtime error is caught non-fatally so product creation in Medusa is never blocked.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
|
|
36
|
+
import { bulkGenerateVariantBarcodesWorkflow } from "../workflows"
|
|
37
|
+
import type { BarcodeModuleService } from "../modules/barcode/service"
|
|
38
|
+
import { BARCODE_MODULE } from "../modules/barcode/types"
|
|
39
|
+
|
|
40
|
+
export default async function productBarcodeSubscriber({
|
|
41
|
+
event,
|
|
42
|
+
container,
|
|
43
|
+
}: SubscriberArgs<{ id?: string; variant_id?: string }>) {
|
|
44
|
+
try {
|
|
45
|
+
const barcodeService = container.resolve(
|
|
46
|
+
BARCODE_MODULE
|
|
47
|
+
) as BarcodeModuleService
|
|
48
|
+
const options = await barcodeService.getModuleOptions()
|
|
49
|
+
if (options.autoGenerateVariantBarcode === false) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const variantId = event.data?.variant_id || event.data?.id
|
|
54
|
+
if (!variantId) {
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await bulkGenerateVariantBarcodesWorkflow(container).run({
|
|
59
|
+
input: {
|
|
60
|
+
variant_ids: [variantId],
|
|
61
|
+
prefix: options.internalBarcodePrefix || "200",
|
|
62
|
+
overwrite: false,
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
} catch {
|
|
66
|
+
// Non-fatal subscriber execution
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const config: SubscriberConfig = {
|
|
71
|
+
event: ["product-variant.created", "product.created"],
|
|
72
|
+
}
|
|
73
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
|
|
2
|
+
import { bulkGenerateVariantBarcodesWorkflow } from "../workflows"
|
|
3
|
+
import type { BarcodeModuleService } from "../modules/barcode/service"
|
|
4
|
+
import { BARCODE_MODULE } from "../modules/barcode/types"
|
|
5
|
+
|
|
6
|
+
export default async function productBarcodeSubscriber({
|
|
7
|
+
event,
|
|
8
|
+
container,
|
|
9
|
+
}: SubscriberArgs<{ id?: string; variant_id?: string }>) {
|
|
10
|
+
try {
|
|
11
|
+
const barcodeService = container.resolve(
|
|
12
|
+
BARCODE_MODULE
|
|
13
|
+
) as BarcodeModuleService
|
|
14
|
+
const options = await barcodeService.getModuleOptions()
|
|
15
|
+
if (options.autoGenerateVariantBarcode === false) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const isProductEvent =
|
|
20
|
+
event.name === "product.created" && !event.data?.variant_id
|
|
21
|
+
const targetId = isProductEvent
|
|
22
|
+
? event.data?.id
|
|
23
|
+
: event.data?.variant_id || event.data?.id
|
|
24
|
+
|
|
25
|
+
if (!targetId) {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await bulkGenerateVariantBarcodesWorkflow(container).run({
|
|
30
|
+
input: {
|
|
31
|
+
...(isProductEvent
|
|
32
|
+
? { product_ids: [targetId] }
|
|
33
|
+
: { variant_ids: [targetId] }),
|
|
34
|
+
prefix: options.internalBarcodePrefix || "200",
|
|
35
|
+
overwrite: false,
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
} catch {
|
|
39
|
+
// Non-fatal subscriber execution
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const config: SubscriberConfig = {
|
|
44
|
+
event: ["product-variant.created", "product.created"],
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../modules/barcode/types"
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
declare module "@medusajs/ui" {
|
|
2
|
+
import type * as React from "react"
|
|
3
|
+
|
|
4
|
+
export interface ContainerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
children?: React.ReactNode
|
|
6
|
+
}
|
|
7
|
+
export const Container: React.FC<ContainerProps>
|
|
8
|
+
|
|
9
|
+
export interface HeadingProps extends React.HTMLAttributes<HTMLHeadingElement> {
|
|
10
|
+
level?: "h1" | "h2" | "h3"
|
|
11
|
+
children?: React.ReactNode
|
|
12
|
+
}
|
|
13
|
+
export const Heading: React.FC<HeadingProps>
|
|
14
|
+
|
|
15
|
+
export interface TextProps extends React.HTMLAttributes<HTMLParagraphElement> {
|
|
16
|
+
size?: "xsmall" | "small" | "base" | "large" | "xlarge"
|
|
17
|
+
weight?: "regular" | "plus"
|
|
18
|
+
leading?: "normal" | "compact"
|
|
19
|
+
children?: React.ReactNode
|
|
20
|
+
}
|
|
21
|
+
export const Text: React.FC<TextProps>
|
|
22
|
+
|
|
23
|
+
export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
24
|
+
color?: "green" | "red" | "blue" | "orange" | "grey" | "purple"
|
|
25
|
+
size?: "2xsmall" | "xsmall" | "small" | "base" | "large"
|
|
26
|
+
rounded?: "base" | "full"
|
|
27
|
+
children?: React.ReactNode
|
|
28
|
+
}
|
|
29
|
+
export const Badge: React.FC<BadgeProps>
|
|
30
|
+
|
|
31
|
+
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
32
|
+
variant?: "primary" | "secondary" | "transparent" | "danger"
|
|
33
|
+
size?: "small" | "base" | "large" | "xlarge"
|
|
34
|
+
isLoading?: boolean
|
|
35
|
+
children?: React.ReactNode
|
|
36
|
+
}
|
|
37
|
+
export const Button: React.FC<ButtonProps>
|
|
38
|
+
|
|
39
|
+
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
40
|
+
size?: "base" | "small"
|
|
41
|
+
}
|
|
42
|
+
export const Input: React.FC<InputProps>
|
|
43
|
+
|
|
44
|
+
export interface LabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> {
|
|
45
|
+
size?: "xsmall" | "small" | "base" | "large"
|
|
46
|
+
weight?: "regular" | "plus"
|
|
47
|
+
children?: React.ReactNode
|
|
48
|
+
}
|
|
49
|
+
export const Label: React.FC<LabelProps>
|
|
50
|
+
|
|
51
|
+
export interface SwitchProps {
|
|
52
|
+
id?: string
|
|
53
|
+
checked?: boolean
|
|
54
|
+
defaultChecked?: boolean
|
|
55
|
+
disabled?: boolean
|
|
56
|
+
onCheckedChange?: (checked: boolean) => void
|
|
57
|
+
className?: string
|
|
58
|
+
}
|
|
59
|
+
export const Switch: React.FC<SwitchProps>
|
|
60
|
+
|
|
61
|
+
export interface TabsRootProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
62
|
+
defaultValue?: string
|
|
63
|
+
value?: string
|
|
64
|
+
onValueChange?: (value: string) => void
|
|
65
|
+
children?: React.ReactNode
|
|
66
|
+
}
|
|
67
|
+
export interface TabsTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
68
|
+
value: string
|
|
69
|
+
children?: React.ReactNode
|
|
70
|
+
}
|
|
71
|
+
export interface TabsContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
72
|
+
value: string
|
|
73
|
+
children?: React.ReactNode
|
|
74
|
+
}
|
|
75
|
+
export const Tabs: React.FC<TabsRootProps> & {
|
|
76
|
+
List: React.FC<React.HTMLAttributes<HTMLDivElement>>
|
|
77
|
+
Trigger: React.FC<TabsTriggerProps>
|
|
78
|
+
Content: React.FC<TabsContentProps>
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface SelectRootProps {
|
|
82
|
+
size?: "base" | "small"
|
|
83
|
+
value?: string
|
|
84
|
+
defaultValue?: string
|
|
85
|
+
onValueChange?: (value: string) => void
|
|
86
|
+
children?: React.ReactNode
|
|
87
|
+
}
|
|
88
|
+
export interface SelectItemProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
89
|
+
value: string
|
|
90
|
+
children?: React.ReactNode
|
|
91
|
+
}
|
|
92
|
+
export const Select: React.FC<SelectRootProps> & {
|
|
93
|
+
Trigger: React.FC<React.ButtonHTMLAttributes<HTMLButtonElement>>
|
|
94
|
+
Value: React.FC<{ placeholder?: string }>
|
|
95
|
+
Content: React.FC<React.HTMLAttributes<HTMLDivElement>>
|
|
96
|
+
Item: React.FC<SelectItemProps>
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
declare module "react-i18next" {
|
|
101
|
+
export interface I18nInstance {
|
|
102
|
+
language: string
|
|
103
|
+
resolvedLanguage?: string
|
|
104
|
+
changeLanguage: (lng: string) => Promise<void>
|
|
105
|
+
dir: (lng?: string) => "ltr" | "rtl"
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type TFunction = (
|
|
109
|
+
key: string,
|
|
110
|
+
options?: Record<string, string | number | boolean | undefined> | string
|
|
111
|
+
) => string
|
|
112
|
+
|
|
113
|
+
export function useTranslation(ns?: string | string[]): {
|
|
114
|
+
t: TFunction
|
|
115
|
+
i18n: I18nInstance
|
|
116
|
+
ready: boolean
|
|
117
|
+
}
|
|
118
|
+
}
|