platform-types 1.10.747 → 1.10.748
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/dist/cjs/print.js +37 -1
- package/dist/print.d.ts +116 -4
- package/dist/print.js +36 -0
- package/package.json +1 -1
package/dist/cjs/print.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LABEL_TEMPLATE_IDS = void 0;
|
|
3
|
+
exports.PRINT_DISPATCH_SKIP_REASONS = exports.LABEL_TEMPLATE_IDS = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* The five label footprints the app's `LABEL_TEMPLATES` ships; `^PW`/`^LL`
|
|
6
6
|
* presets on the api's ZPL producer.
|
|
@@ -19,3 +19,39 @@ exports.LABEL_TEMPLATE_IDS = void 0;
|
|
|
19
19
|
* consumer; treat it as a set. `producto` is the default template.
|
|
20
20
|
*/
|
|
21
21
|
exports.LABEL_TEMPLATE_IDS = ['producto', 'precio', 'estante', 'envio', 'inventario'];
|
|
22
|
+
/**
|
|
23
|
+
* Why the BE dispatch did not hand a print job to a connection — the four codes
|
|
24
|
+
* `wsPostPrinter` writes as `PrintJobSummary.errorCode` and reports per job in
|
|
25
|
+
* {@link PrintDispatchOutcome}.
|
|
26
|
+
*
|
|
27
|
+
* - `AGENT_OFFLINE` — the connection exists but its agent stopped heartbeating;
|
|
28
|
+
* or the agent has no connection at all although the job named it (a targeted
|
|
29
|
+
* agent's socket vanished before dispatch, or none of the agents a job was
|
|
30
|
+
* narrowed to is connected — one entry per named agent).
|
|
31
|
+
* - `PRINTER_INACTIVE` — the resolved rule names a printer the operator paused, the
|
|
32
|
+
* registry no longer holds, or the agent's latest printer report left out
|
|
33
|
+
* (unplugged or renamed).
|
|
34
|
+
* - `PRINTER_RAW_UNSUPPORTED` — a raw job (ESC/POS, ZPL) resolved to a printer
|
|
35
|
+
* that never declared that dialect, or resolved no rule at all; routing fails
|
|
36
|
+
* CLOSED rather than send a control stream to an unknown printer. The two
|
|
37
|
+
* causes are told apart by `printerId` — see {@link PrintDispatchOutcome}.
|
|
38
|
+
* - `NO_PRINTER_CONNECTED` — emitted only when the job reached nobody and skipped
|
|
39
|
+
* nobody without naming an agent: the store has no printer connection at all
|
|
40
|
+
* (or the job was narrowed to an empty agent list). A job that named its agents
|
|
41
|
+
* and found none of them connected is `AGENT_OFFLINE` instead.
|
|
42
|
+
*
|
|
43
|
+
* A runtime value, not `declare global`, for the same reason as
|
|
44
|
+
* `LABEL_TEMPLATE_IDS`: a client switches on these codes and may need to
|
|
45
|
+
* enumerate them. The api's `printRouting.ts` constants are checked against this
|
|
46
|
+
* tuple with `satisfies`, so a code cannot be spelled two ways.
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { PRINT_DISPATCH_SKIP_REASONS, type PrintDispatchSkipReason } from 'platform-types';
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
exports.PRINT_DISPATCH_SKIP_REASONS = [
|
|
53
|
+
'AGENT_OFFLINE',
|
|
54
|
+
'PRINTER_INACTIVE',
|
|
55
|
+
'PRINTER_RAW_UNSUPPORTED',
|
|
56
|
+
'NO_PRINTER_CONNECTED',
|
|
57
|
+
];
|
package/dist/print.d.ts
CHANGED
|
@@ -17,6 +17,113 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const LABEL_TEMPLATE_IDS: readonly ["producto", "precio", "estante", "envio", "inventario"];
|
|
19
19
|
export type LabelTemplateId = (typeof LABEL_TEMPLATE_IDS)[number];
|
|
20
|
+
/**
|
|
21
|
+
* Why the BE dispatch did not hand a print job to a connection — the four codes
|
|
22
|
+
* `wsPostPrinter` writes as `PrintJobSummary.errorCode` and reports per job in
|
|
23
|
+
* {@link PrintDispatchOutcome}.
|
|
24
|
+
*
|
|
25
|
+
* - `AGENT_OFFLINE` — the connection exists but its agent stopped heartbeating;
|
|
26
|
+
* or the agent has no connection at all although the job named it (a targeted
|
|
27
|
+
* agent's socket vanished before dispatch, or none of the agents a job was
|
|
28
|
+
* narrowed to is connected — one entry per named agent).
|
|
29
|
+
* - `PRINTER_INACTIVE` — the resolved rule names a printer the operator paused, the
|
|
30
|
+
* registry no longer holds, or the agent's latest printer report left out
|
|
31
|
+
* (unplugged or renamed).
|
|
32
|
+
* - `PRINTER_RAW_UNSUPPORTED` — a raw job (ESC/POS, ZPL) resolved to a printer
|
|
33
|
+
* that never declared that dialect, or resolved no rule at all; routing fails
|
|
34
|
+
* CLOSED rather than send a control stream to an unknown printer. The two
|
|
35
|
+
* causes are told apart by `printerId` — see {@link PrintDispatchOutcome}.
|
|
36
|
+
* - `NO_PRINTER_CONNECTED` — emitted only when the job reached nobody and skipped
|
|
37
|
+
* nobody without naming an agent: the store has no printer connection at all
|
|
38
|
+
* (or the job was narrowed to an empty agent list). A job that named its agents
|
|
39
|
+
* and found none of them connected is `AGENT_OFFLINE` instead.
|
|
40
|
+
*
|
|
41
|
+
* A runtime value, not `declare global`, for the same reason as
|
|
42
|
+
* `LABEL_TEMPLATE_IDS`: a client switches on these codes and may need to
|
|
43
|
+
* enumerate them. The api's `printRouting.ts` constants are checked against this
|
|
44
|
+
* tuple with `satisfies`, so a code cannot be spelled two ways.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { PRINT_DISPATCH_SKIP_REASONS, type PrintDispatchSkipReason } from 'platform-types';
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const PRINT_DISPATCH_SKIP_REASONS: readonly ["AGENT_OFFLINE", "PRINTER_INACTIVE", "PRINTER_RAW_UNSUPPORTED", "NO_PRINTER_CONNECTED"];
|
|
51
|
+
export type PrintDispatchSkipReason = (typeof PRINT_DISPATCH_SKIP_REASONS)[number];
|
|
52
|
+
/**
|
|
53
|
+
* What the BE dispatch of ONE print job did, as of the moment the handler
|
|
54
|
+
* answered. Written by `wsPostPrinter` and returned by the handlers that queue
|
|
55
|
+
* jobs: `POST /orders {mode:'receipt'}` and `POST /products {mode:'tag'}`.
|
|
56
|
+
*
|
|
57
|
+
* ⚠️ `reached > 0` means the frame was queued to that many live agent
|
|
58
|
+
* connections — NOT that paper came out. The agent's ack settles the job
|
|
59
|
+
* (`printed`/`error`) later, on the job's state timeline.
|
|
60
|
+
*
|
|
61
|
+
* `reached === 0` always comes with at least one `skipped` entry. A job narrowed
|
|
62
|
+
* to agents none of which is connected carries one `{ reason: 'AGENT_OFFLINE', agentId }`
|
|
63
|
+
* per named agent; any other job that reached nobody and skipped nobody carries
|
|
64
|
+
* one `{ reason: 'NO_PRINTER_CONNECTED' }`. Either way it is the same code the
|
|
65
|
+
* job's terminal `error` row records. A job can also be mixed — reached some
|
|
66
|
+
* connections and skipped others.
|
|
67
|
+
*/
|
|
68
|
+
export interface PrintDispatchOutcome {
|
|
69
|
+
jobId: string;
|
|
70
|
+
/** How many printer connections the frame was queued to. */
|
|
71
|
+
reached: number;
|
|
72
|
+
/**
|
|
73
|
+
* One entry per connection the dispatch deliberately left out (or per named
|
|
74
|
+
* agent that had no connection), each with ONE reason (never the `+`-joined
|
|
75
|
+
* form `PrintJobSummary.errorCode` can carry). `agentId`/`printerId` are
|
|
76
|
+
* present when known: `printerId` is the printer the rule resolved to, and
|
|
77
|
+
* both are absent on `NO_PRINTER_CONNECTED`.
|
|
78
|
+
*
|
|
79
|
+
* `PRINTER_RAW_UNSUPPORTED` WITHOUT `printerId`: no rule could be resolved for
|
|
80
|
+
* the job's use case on that agent — no `PrintRule` for it, a connection with
|
|
81
|
+
* no `agentId` yet, or a job sent with no use case — so no printer could be
|
|
82
|
+
* verified (fix: add a rule). WITH `printerId`: a rule routed the job to that
|
|
83
|
+
* printer, which does not declare the raw format (fix: declare the format on
|
|
84
|
+
* the printer).
|
|
85
|
+
*/
|
|
86
|
+
skipped: {
|
|
87
|
+
reason: PrintDispatchSkipReason;
|
|
88
|
+
agentId?: string;
|
|
89
|
+
printerId?: string;
|
|
90
|
+
}[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The `data` shape of the handlers that report each queued print job's dispatch
|
|
94
|
+
* outcome: the order receipt, the invoice ESC/POS receipt and the product tag.
|
|
95
|
+
* Other print endpoints (`POST /print`, the invoice PDF print, the test page)
|
|
96
|
+
* still answer `{ jobId }` without `outcomes`. `OrderReceiptPrintData`,
|
|
97
|
+
* `InvoiceReceiptPrintData` and `ProductTagPrintData` are this shape under the name
|
|
98
|
+
* of the endpoint that returns it — aliases rather than empty `extends`, which
|
|
99
|
+
* `@typescript-eslint/no-empty-object-type` refuses.
|
|
100
|
+
*/
|
|
101
|
+
export interface PrintJobsQueuedData {
|
|
102
|
+
/** `jobIds[0]` — kept for clients that read a single id. */
|
|
103
|
+
jobId: string;
|
|
104
|
+
jobIds: string[];
|
|
105
|
+
/** One per job, index-aligned with `jobIds`. */
|
|
106
|
+
outcomes: PrintDispatchOutcome[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* `data` of `POST /orders {mode:'receipt'}`, written by `orders/_receipt.ts`.
|
|
110
|
+
* One job per distinct printer render profile, so a store whose printers
|
|
111
|
+
* disagree on `columns`/`drawerKick` gets several.
|
|
112
|
+
*/
|
|
113
|
+
export type OrderReceiptPrintData = PrintJobsQueuedData;
|
|
114
|
+
/**
|
|
115
|
+
* `data` of the invoice ESC/POS receipt (`POST /invoices {mode:'printEscpos'}`),
|
|
116
|
+
* written by `invoices/_printEscpos.ts` — one job per printer render profile, as
|
|
117
|
+
* for the order receipt.
|
|
118
|
+
*/
|
|
119
|
+
export type InvoiceReceiptPrintData = PrintJobsQueuedData;
|
|
120
|
+
/**
|
|
121
|
+
* `data` of `POST /products {mode:'tag', notifyCloudPrint: true}`, written by
|
|
122
|
+
* `products/_tag.ts`: the ZPL job (when the store has a `zpl` agent) first, then
|
|
123
|
+
* one PDF job per requested item — unless the store has `zpl` agents and no PDF
|
|
124
|
+
* agent, when there is no PDF job at all.
|
|
125
|
+
*/
|
|
126
|
+
export type ProductTagPrintData = PrintJobsQueuedData;
|
|
20
127
|
declare global {
|
|
21
128
|
type PrintJobState = 'queued' | 'sent' | 'printed' | 'error' | 'cancelled';
|
|
22
129
|
type PrintContentType = 'pdf_uri' | 'pdf_base64' | 'raw_uri' | 'raw_base64';
|
|
@@ -83,8 +190,11 @@ declare global {
|
|
|
83
190
|
interface PrintAgentSummary {
|
|
84
191
|
/**
|
|
85
192
|
* Stable per-install id the agent mints on first run and reuses. The right
|
|
86
|
-
* handle for list keys and future per-agent actions.
|
|
87
|
-
*
|
|
193
|
+
* handle for list keys and future per-agent actions. Resolved the way
|
|
194
|
+
* dispatch resolves it: a connection whose listing copy carries none gets a
|
|
195
|
+
* consistent read of its own SOCKET row. Absent only when that leaves it
|
|
196
|
+
* unresolved — a pre-heartbeat build that never reported one, or a failed
|
|
197
|
+
* read — so a UI still needs a fallback label.
|
|
88
198
|
*/
|
|
89
199
|
agentId?: string;
|
|
90
200
|
/** This connection's own liveness — NOT the store-wide aggregate. */
|
|
@@ -444,8 +554,10 @@ declare global {
|
|
|
444
554
|
detail?: string;
|
|
445
555
|
/**
|
|
446
556
|
* Machine-readable failure classification, when one is recognised. BE-side
|
|
447
|
-
* dispatch
|
|
448
|
-
*
|
|
557
|
+
* dispatch (`wsPostPrinter`) writes one of `PrintDispatchSkipReason` —
|
|
558
|
+
* `AGENT_OFFLINE` / `PRINTER_INACTIVE` / `PRINTER_RAW_UNSUPPORTED` /
|
|
559
|
+
* `NO_PRINTER_CONNECTED` — or, when skips disagree, the distinct codes
|
|
560
|
+
* sorted and joined by `+`; an agent `ACK_FAILED` can classify to `PRINTER_PAUSED` /
|
|
449
561
|
* `NO_PRINTER_ASSIGNED` / `PRINTER_NOT_FOUND`. Unrecognised agent
|
|
450
562
|
* text stays in `detail` only, so absence of a code does NOT mean success.
|
|
451
563
|
*/
|
package/dist/print.js
CHANGED
|
@@ -16,3 +16,39 @@
|
|
|
16
16
|
* consumer; treat it as a set. `producto` is the default template.
|
|
17
17
|
*/
|
|
18
18
|
export const LABEL_TEMPLATE_IDS = ['producto', 'precio', 'estante', 'envio', 'inventario'];
|
|
19
|
+
/**
|
|
20
|
+
* Why the BE dispatch did not hand a print job to a connection — the four codes
|
|
21
|
+
* `wsPostPrinter` writes as `PrintJobSummary.errorCode` and reports per job in
|
|
22
|
+
* {@link PrintDispatchOutcome}.
|
|
23
|
+
*
|
|
24
|
+
* - `AGENT_OFFLINE` — the connection exists but its agent stopped heartbeating;
|
|
25
|
+
* or the agent has no connection at all although the job named it (a targeted
|
|
26
|
+
* agent's socket vanished before dispatch, or none of the agents a job was
|
|
27
|
+
* narrowed to is connected — one entry per named agent).
|
|
28
|
+
* - `PRINTER_INACTIVE` — the resolved rule names a printer the operator paused, the
|
|
29
|
+
* registry no longer holds, or the agent's latest printer report left out
|
|
30
|
+
* (unplugged or renamed).
|
|
31
|
+
* - `PRINTER_RAW_UNSUPPORTED` — a raw job (ESC/POS, ZPL) resolved to a printer
|
|
32
|
+
* that never declared that dialect, or resolved no rule at all; routing fails
|
|
33
|
+
* CLOSED rather than send a control stream to an unknown printer. The two
|
|
34
|
+
* causes are told apart by `printerId` — see {@link PrintDispatchOutcome}.
|
|
35
|
+
* - `NO_PRINTER_CONNECTED` — emitted only when the job reached nobody and skipped
|
|
36
|
+
* nobody without naming an agent: the store has no printer connection at all
|
|
37
|
+
* (or the job was narrowed to an empty agent list). A job that named its agents
|
|
38
|
+
* and found none of them connected is `AGENT_OFFLINE` instead.
|
|
39
|
+
*
|
|
40
|
+
* A runtime value, not `declare global`, for the same reason as
|
|
41
|
+
* `LABEL_TEMPLATE_IDS`: a client switches on these codes and may need to
|
|
42
|
+
* enumerate them. The api's `printRouting.ts` constants are checked against this
|
|
43
|
+
* tuple with `satisfies`, so a code cannot be spelled two ways.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { PRINT_DISPATCH_SKIP_REASONS, type PrintDispatchSkipReason } from 'platform-types';
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export const PRINT_DISPATCH_SKIP_REASONS = [
|
|
50
|
+
'AGENT_OFFLINE',
|
|
51
|
+
'PRINTER_INACTIVE',
|
|
52
|
+
'PRINTER_RAW_UNSUPPORTED',
|
|
53
|
+
'NO_PRINTER_CONNECTED',
|
|
54
|
+
];
|