# Integration Lab / Alexuys

Two original portfolio demo projects. All records are synthetic. These are not client deliveries or claims of production use.

## LeadFlow / n8n

Import `leadflow.n8n.json` into n8n, open the workflow and click Execute workflow. It is inactive by default, has a Manual Trigger and makes no external calls. No credentials are needed. The sample input is editable in the Sample requests node.

Expected summary: **total 4, accepted 2, duplicates 1, invalid 1**. Accepted records have a CRM draft and a notification draft. These are data objects; no CRM record or Telegram message is sent.

The validator normalizes email and whitespace, checks the name, contact, request and non-negative integer budget. Deduplication is limited to one batch, using normalized email plus request text. A different request from the same person is retained. A budget of at least RUB 30,000 gives high priority; this is a rule, not AI scoring.

The browser demo uses exactly the same `leadBatch` function embedded in the workflow. n8n Code nodes are generated with `node projects/integration-lab/build-workflow.cjs` from `assets/integration-lab-core.js`.

CLI setup in a disposable local directory (Node.js version supported by the pinned n8n release):

```sh
npm install n8n@2.40.7
npx n8n import:workflow --input=leadflow.n8n.json
npx n8n execute --id=AlexuysLeadFlowDemo
```

For live use, replace sample input with a properly authenticated trigger. Persist idempotency keys in a database with a unique constraint, configure the actual CRM and notification nodes, and add bounded retries and error monitoring. The demo does not implement these production adapters.

## TradeSync / 1C

A runnable JavaScript model of a bidirectional exchange boundary: a catalogue snapshot enters the store; orders reserve stock and are queued for an accounting system. The browser stores everything in memory; refreshing resets it. It is not a live 1C database or an installed 1C configuration.

Catalogue protocol:

```json
{"revision":1,"items":[{"sku":"001-CHAIR","name":"Forma chair","priceMinor":1899000,"stock":8}]}
```

- `sku`: a stable string, including leading zeros.
- `priceMinor`: integer kopecks, not a floating-point price.
- `stock`: non-negative physical stock; open demo reservations are subtracted.
- `revision`: positive increasing snapshot version. Same or older snapshots are skipped.
- New snapshots conflicting with reservations are rejected. This demo has no fulfilment, cancellation or reservation-release lifecycle.

Order protocol:

```json
{"id":"WEB-001","lines":[{"sku":"001-CHAIR","qty":2}]}
```

All lines are checked before any state change. Duplicate lines are combined. An identical order ID and normalized content return the prior result; changed content under that ID is rejected. Unknown SKUs, invalid quantities or insufficient stock reject the entire order. A successful order reserves stock and calculates its total from server-model prices, not from a supplied order price.

`ExchangeAdapter.bsl` is a small sample common server module for 1C:Enterprise: serialization of this catalogue envelope and parsing of an order envelope. It has **not been executed in a licensed 1C runtime**. It does not query a particular configuration, write registers, reserve real stock or post accounting documents. It is not a `.cfe`/`.epf` installation package. Review and adapt it in an isolated test database before using it in 1C. Its format is this project's custom protocol, not CommerceML.

For production: define configuration-specific mappings, authenticate the exchange, use database transactions and durable idempotency keys, handle fulfilment/cancellation and reject stale snapshots using the source's real version semantics. Test against the target 1C configuration and platform. No such production deployment is claimed here.

## Verification

From the private portfolio source root:

```sh
node projects/integration-lab/build-workflow.cjs
node --test projects/integration-lab/test.cjs
```

Tests cover retries, changed duplicate IDs, atomic failure, aggregated quantities, unknown SKUs, exact integer totals, stale snapshots, reservation conflicts, lead validation and workflow code parity. Runtime execution evidence is recorded in `verification.json` after the n8n CLI check.

## Sources

- n8n Code node: https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.code/
- n8n CLI: https://github.com/n8n-io/n8n-docs/blob/main/docs/deploy/host-n8n/configure-n8n/use-the-command-line.md
- 1C JSON/HTTP example: https://1c-dn.com/blog/work-with-http-services-in-1c-part-2-post-method/

## Кратко по-русски

LeadFlow — запускаемый workflow n8n с тестовыми заявками: проверка, повторы, карточки CRM и сводка. TradeSync — интерактивная модель обмена каталогом и заказами; база 1С не подключена, BSL-модуль в среде 1С не проверялся. В обоих проектах используются вымышленные данные, внешние сообщения не отправляются. Это собственные демопроекты, не коммерческие внедрения.
