lumnik. / scenarios All scenarios · Français

The wrong bar code caught at import

Goal Catch wrong bar codes at import.

A catalogue export carries EAN-13 bar codes, some of them wrong. No built-in transformer computes the check digit.

manifests/ean-check.kts
// Operator-provided: checks an EAN-13 bar code and says why one is wrong.@Suppress("UNCHECKED_CAST")val cells = bindings["cells"] as MutableMap<String, Any?>val ean = (cells["ean"] as? String)?.trim().orEmpty()cells["ean_status"] = if (!Regex("\\d{13}").matches(ean)) {    "malformed"} else {    val sum = ean.take(12).mapIndexed { i, c -> (c - '0') * (if (i % 2 == 0) 1 else 3) }.sum()    if ((10 - sum % 10) % 10 == ean[12] - '0') "valid" else "wrong-check-digit"}
manifests/ean-draft.kts
// Draft, deliberately broken: lm validate must refuse it (line 8).@Suppress("UNCHECKED_CAST")val cells = bindings["cells"] as MutableMap<String, Any?>val ean = (cells["ean"] as? String)?.trim().orEmpty()cells["ean_status"] = if (!Regex("\\d{13}").matches(ean)) {    "malformed"} else {    val sum: Int = ean.take(12).mapIndexed { i, c -> (c - '0') * (if (i % 2 == 0) 1 else 3) }  // ERROR HERE: mapIndexed gives a List<Int>, not an Int    if ((10 - sum % 10) % 10 == ean[12] - '0') "valid" else "wrong-check-digit"}
manifests/10-catalogue.yaml
apiVersion: connectors.lumnik.io/v1kind: Connectormetadata:  name: scenario-ean-b  connector_type: csv-file  scopes: [catalogue]spec:  transport:    kind: local    path: /tmp/lumnik-scenario/catalogue-ean-check/b/catalogue.csv  parser:    has_header: true  after_process: none  mapping:    cell:      - kotlin:          script: hooks:ean-check-b.kts   # put in the hub's hooks directory by the operator
catalogue.csv
sku,label,ean
ART-101,Plateau inox 30 cm,2001234000000
ART-102,Bac gastro 1/1,2001234000017
ART-103,Spatule silicone,2001234000024
ART-104,Pince de service,2001234000032
ART-105,Fouet 25 cm,2001234000048
ART-106,Louche 12 cl,2001234000055
ART-107,Planche à découper,2001234000062
ART-108,Passoire 24 cm,2001234000074
ART-109,Écumoire inox,2001234000086
ART-110,Couteau d'office,200123400009

Limits

  • A script runs with all the hub's rights: only the operator installs one.
  • A replaced script applies from the next batch, never mid-batch.
  • The script runs on CSV imports.
  • Synthetic catalogue, codes under the 200 prefix, reserved for in-store use.

Catalogue · EAN-13

A wrong bar code reaches the till.

The product does not scan. The customer waits.

The catalogue export carries 10 EAN-13 codes. Three are wrong.

Fictional catalogue · synthetic data

The problem

The last digit is computed.

  • An EAN-13 ends with a check digit.
  • A typing error makes it wrong.
  • No standard tool checks it at import.

The rule

The operator drops a script. The manifest names it.

mapping:
  cell:
    - kotlin:
        script: hooks:ean-check.kts

2 manifests, 24 lines. One script, 10 lines.

Before any import

A wrong script is refused at validation.

  • Line 8, column 20.
  • No connector created.
  • Nothing imported.

The result

Every code gets a verdict.

  • 7 valid codes.
  • 2 wrong check digits: ART-104, ART-108.
  • 1 code of 12 digits: ART-110.

Real values, replay of 28 October 2026.

Security

The script holds all the hub's rights.

  • Only the operator installs it.
  • The integrator picks it by name.
  • The SHA-256 fingerprint says which version runs.

Try it

The scenario replays end to end.

Scripts, refusal, import: each step is published with its output.

This scenario runs on lumnik Open, free and open source.

Try lumnik Open →