@ordereat-uy/printer-bridge-client 0.0.5
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/client.d.ts +48 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +208 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +73 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +28 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AvailablePrinter, BridgeClientOptions, BridgeConnectionStatus, BridgeStatusResponse, PrinterConfig, PrintJob, PrintResponse, WsEvent } from './types.js';
|
|
2
|
+
type EventHandler = (event: WsEvent) => void;
|
|
3
|
+
export declare class PrintBridgeClient {
|
|
4
|
+
private options;
|
|
5
|
+
private ws;
|
|
6
|
+
private handlers;
|
|
7
|
+
private typedHandlers;
|
|
8
|
+
private reconnectTimer;
|
|
9
|
+
private reconnectAttempts;
|
|
10
|
+
private _status;
|
|
11
|
+
private _autoReconnect;
|
|
12
|
+
constructor(options?: BridgeClientOptions);
|
|
13
|
+
get status(): BridgeConnectionStatus;
|
|
14
|
+
get isConnected(): boolean;
|
|
15
|
+
connect(): void;
|
|
16
|
+
disconnect(): void;
|
|
17
|
+
/** Subscribe to all WebSocket events */
|
|
18
|
+
on(handler: EventHandler): () => void;
|
|
19
|
+
/** Subscribe to a specific event type */
|
|
20
|
+
on(eventType: WsEvent['type'], handler: EventHandler): () => void;
|
|
21
|
+
off(handler: EventHandler): void;
|
|
22
|
+
off(eventType: WsEvent['type'], handler: EventHandler): void;
|
|
23
|
+
getStatus(): Promise<BridgeStatusResponse>;
|
|
24
|
+
getAvailablePrinters(): Promise<AvailablePrinter[]>;
|
|
25
|
+
getConfiguredPrinters(): Promise<PrinterConfig[]>;
|
|
26
|
+
getPrinters(): Promise<{
|
|
27
|
+
available: AvailablePrinter[];
|
|
28
|
+
configured: PrinterConfig[];
|
|
29
|
+
}>;
|
|
30
|
+
addPrinter(config: {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
address: string;
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
}): Promise<PrinterConfig>;
|
|
36
|
+
updatePrinter(id: string, updates: Partial<Omit<PrinterConfig, 'id'>>): Promise<PrinterConfig>;
|
|
37
|
+
removePrinter(id: string): Promise<void>;
|
|
38
|
+
print(printerKey: string, data: Uint8Array | ArrayBuffer): Promise<PrintResponse>;
|
|
39
|
+
getRecentJobs(limit?: number): Promise<PrintJob[]>;
|
|
40
|
+
private fetch;
|
|
41
|
+
private setStatus;
|
|
42
|
+
private dispatchEvent;
|
|
43
|
+
private scheduleReconnect;
|
|
44
|
+
private clearReconnectTimer;
|
|
45
|
+
private uint8ArrayToBase64;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,aAAa,EACb,QAAQ,EACR,aAAa,EACb,OAAO,EACR,MAAM,YAAY,CAAC;AAEpB,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AAS7C,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,aAAa,CAAwC;IAC7D,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,OAAO,CAA0C;IAC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AAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IAWjF,aAAa,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;YAMtC,KAAK;IAqBnB,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,kBAAkB;CAQ3B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
const DEFAULT_OPTIONS = {
|
|
2
|
+
url: 'http://localhost:9120',
|
|
3
|
+
wsUrl: 'ws://localhost:9120/ws',
|
|
4
|
+
reconnectInterval: 3000,
|
|
5
|
+
maxReconnectAttempts: Infinity,
|
|
6
|
+
};
|
|
7
|
+
export class PrintBridgeClient {
|
|
8
|
+
options;
|
|
9
|
+
ws = null;
|
|
10
|
+
handlers = new Set();
|
|
11
|
+
typedHandlers = new Map();
|
|
12
|
+
reconnectTimer = null;
|
|
13
|
+
reconnectAttempts = 0;
|
|
14
|
+
_status = 'disconnected';
|
|
15
|
+
_autoReconnect = true;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
18
|
+
}
|
|
19
|
+
// ── Connection Status ──────────────────────────────────────────────
|
|
20
|
+
get status() {
|
|
21
|
+
return this._status;
|
|
22
|
+
}
|
|
23
|
+
get isConnected() {
|
|
24
|
+
return this._status === 'connected';
|
|
25
|
+
}
|
|
26
|
+
// ── WebSocket Lifecycle ────────────────────────────────────────────
|
|
27
|
+
connect() {
|
|
28
|
+
if (this.ws && (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this._autoReconnect = true;
|
|
32
|
+
this.setStatus('connecting');
|
|
33
|
+
try {
|
|
34
|
+
this.ws = new WebSocket(this.options.wsUrl);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
this.setStatus('error');
|
|
38
|
+
this.scheduleReconnect();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.ws.onopen = () => {
|
|
42
|
+
this.reconnectAttempts = 0;
|
|
43
|
+
this.setStatus('connected');
|
|
44
|
+
};
|
|
45
|
+
this.ws.onmessage = (event) => {
|
|
46
|
+
try {
|
|
47
|
+
const wsEvent = JSON.parse(event.data);
|
|
48
|
+
this.dispatchEvent(wsEvent);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Ignore invalid messages
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
this.ws.onclose = () => {
|
|
55
|
+
this.ws = null;
|
|
56
|
+
if (this._autoReconnect) {
|
|
57
|
+
this.setStatus('disconnected');
|
|
58
|
+
this.scheduleReconnect();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
this.ws.onerror = () => {
|
|
62
|
+
// onclose will fire after this
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
disconnect() {
|
|
66
|
+
this._autoReconnect = false;
|
|
67
|
+
this.clearReconnectTimer();
|
|
68
|
+
if (this.ws) {
|
|
69
|
+
this.ws.close();
|
|
70
|
+
this.ws = null;
|
|
71
|
+
}
|
|
72
|
+
this.setStatus('disconnected');
|
|
73
|
+
}
|
|
74
|
+
on(handlerOrType, maybeHandler) {
|
|
75
|
+
if (typeof handlerOrType === 'function') {
|
|
76
|
+
this.handlers.add(handlerOrType);
|
|
77
|
+
return () => { this.handlers.delete(handlerOrType); };
|
|
78
|
+
}
|
|
79
|
+
const type = handlerOrType;
|
|
80
|
+
const handler = maybeHandler;
|
|
81
|
+
if (!this.typedHandlers.has(type)) {
|
|
82
|
+
this.typedHandlers.set(type, new Set());
|
|
83
|
+
}
|
|
84
|
+
this.typedHandlers.get(type).add(handler);
|
|
85
|
+
return () => { this.typedHandlers.get(type)?.delete(handler); };
|
|
86
|
+
}
|
|
87
|
+
off(handlerOrType, maybeHandler) {
|
|
88
|
+
if (typeof handlerOrType === 'function') {
|
|
89
|
+
this.handlers.delete(handlerOrType);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.typedHandlers.get(handlerOrType)?.delete(maybeHandler);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// ── HTTP API ──────────────────────────────────────────────────────
|
|
96
|
+
async getStatus() {
|
|
97
|
+
return this.fetch('/api/status');
|
|
98
|
+
}
|
|
99
|
+
async getAvailablePrinters() {
|
|
100
|
+
return this.fetch('/api/printers/available');
|
|
101
|
+
}
|
|
102
|
+
async getConfiguredPrinters() {
|
|
103
|
+
return this.fetch('/api/printers/configured');
|
|
104
|
+
}
|
|
105
|
+
async getPrinters() {
|
|
106
|
+
const [available, configured] = await Promise.all([
|
|
107
|
+
this.getAvailablePrinters(),
|
|
108
|
+
this.getConfiguredPrinters(),
|
|
109
|
+
]);
|
|
110
|
+
return { available, configured };
|
|
111
|
+
}
|
|
112
|
+
async addPrinter(config) {
|
|
113
|
+
return this.fetch('/api/printers', {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
headers: { 'Content-Type': 'application/json' },
|
|
116
|
+
body: JSON.stringify(config),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async updatePrinter(id, updates) {
|
|
120
|
+
return this.fetch('/api/printers', {
|
|
121
|
+
method: 'POST',
|
|
122
|
+
headers: { 'Content-Type': 'application/json' },
|
|
123
|
+
body: JSON.stringify({ id, ...updates }),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async removePrinter(id) {
|
|
127
|
+
await this.fetch(`/api/printers/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
128
|
+
}
|
|
129
|
+
async print(printerKey, data) {
|
|
130
|
+
const bytes = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
|
|
131
|
+
const base64 = this.uint8ArrayToBase64(bytes);
|
|
132
|
+
return this.fetch('/api/print', {
|
|
133
|
+
method: 'POST',
|
|
134
|
+
headers: { 'Content-Type': 'application/json' },
|
|
135
|
+
body: JSON.stringify({ printerId: printerKey, data: base64 }),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async getRecentJobs(limit = 20) {
|
|
139
|
+
return this.fetch(`/api/jobs/recent?limit=${limit}`);
|
|
140
|
+
}
|
|
141
|
+
// ── Private Helpers ───────────────────────────────────────────────
|
|
142
|
+
async fetch(path, init) {
|
|
143
|
+
const url = `${this.options.url}${path}`;
|
|
144
|
+
const response = await globalThis.fetch(url, init);
|
|
145
|
+
if (response.status === 204)
|
|
146
|
+
return undefined;
|
|
147
|
+
if (!response.ok) {
|
|
148
|
+
const body = await response.text();
|
|
149
|
+
let message;
|
|
150
|
+
try {
|
|
151
|
+
const json = JSON.parse(body);
|
|
152
|
+
message = json.error ?? `HTTP ${response.status}`;
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
message = body || `HTTP ${response.status}`;
|
|
156
|
+
}
|
|
157
|
+
throw new Error(message);
|
|
158
|
+
}
|
|
159
|
+
return response.json();
|
|
160
|
+
}
|
|
161
|
+
setStatus(status) {
|
|
162
|
+
if (this._status === status)
|
|
163
|
+
return;
|
|
164
|
+
this._status = status;
|
|
165
|
+
}
|
|
166
|
+
dispatchEvent(event) {
|
|
167
|
+
for (const handler of this.handlers) {
|
|
168
|
+
try {
|
|
169
|
+
handler(event);
|
|
170
|
+
}
|
|
171
|
+
catch { /* ignore handler errors */ }
|
|
172
|
+
}
|
|
173
|
+
const typed = this.typedHandlers.get(event.type);
|
|
174
|
+
if (typed) {
|
|
175
|
+
for (const handler of typed) {
|
|
176
|
+
try {
|
|
177
|
+
handler(event);
|
|
178
|
+
}
|
|
179
|
+
catch { /* ignore handler errors */ }
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
scheduleReconnect() {
|
|
184
|
+
this.clearReconnectTimer();
|
|
185
|
+
if (this.reconnectAttempts >= this.options.maxReconnectAttempts)
|
|
186
|
+
return;
|
|
187
|
+
const delay = Math.min(this.options.reconnectInterval * Math.pow(1.5, this.reconnectAttempts), 30000);
|
|
188
|
+
this.reconnectTimer = setTimeout(() => {
|
|
189
|
+
this.reconnectAttempts++;
|
|
190
|
+
this.connect();
|
|
191
|
+
}, delay);
|
|
192
|
+
}
|
|
193
|
+
clearReconnectTimer() {
|
|
194
|
+
if (this.reconnectTimer) {
|
|
195
|
+
clearTimeout(this.reconnectTimer);
|
|
196
|
+
this.reconnectTimer = null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
uint8ArrayToBase64(bytes) {
|
|
200
|
+
// Browser-compatible base64 encoding
|
|
201
|
+
let binary = '';
|
|
202
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
203
|
+
binary += String.fromCharCode(bytes[i]);
|
|
204
|
+
}
|
|
205
|
+
return btoa(binary);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAaA,MAAM,eAAe,GAAkC;IACrD,GAAG,EAAE,uBAAuB;IAC5B,KAAK,EAAE,wBAAwB;IAC/B,iBAAiB,EAAE,IAAI;IACvB,oBAAoB,EAAE,QAAQ;CAC/B,CAAC;AAEF,MAAM,OAAO,iBAAiB;IACpB,OAAO,CAAgC;IACvC,EAAE,GAAqB,IAAI,CAAC;IAC5B,QAAQ,GAAG,IAAI,GAAG,EAAgB,CAAC;IACnC,aAAa,GAAG,IAAI,GAAG,EAA6B,CAAC;IACrD,cAAc,GAAyC,IAAI,CAAC;IAC5D,iBAAiB,GAAG,CAAC,CAAC;IACtB,OAAO,GAA2B,cAAc,CAAC;IACjD,cAAc,GAAG,IAAI,CAAC;IAE9B,YAAY,OAA6B;QACvC,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,EAAE,CAA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C;AAChD,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,QAAQ,EACR,aAAa,EACb,OAAO,GACR,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export interface PrinterConfig {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
address: string;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
status?: PrinterStatus;
|
|
7
|
+
}
|
|
8
|
+
export type PrinterStatus = 'idle' | 'printing' | 'error' | 'offline' | 'missing' | 'unknown';
|
|
9
|
+
export interface AvailablePrinter {
|
|
10
|
+
name: string;
|
|
11
|
+
status: PrinterStatus;
|
|
12
|
+
isDefault: boolean;
|
|
13
|
+
configured: boolean;
|
|
14
|
+
configuredAs?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface PrintJob {
|
|
17
|
+
id: string;
|
|
18
|
+
printerId: string;
|
|
19
|
+
status: 'queued' | 'printing' | 'completed' | 'failed';
|
|
20
|
+
error?: string;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
completedAt?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface BridgeStatusResponse {
|
|
25
|
+
status: string;
|
|
26
|
+
version: string;
|
|
27
|
+
uptime: number;
|
|
28
|
+
queueLength: number;
|
|
29
|
+
nativePrinterAvailable: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface PrintResponse {
|
|
32
|
+
jobId: string;
|
|
33
|
+
status: string;
|
|
34
|
+
queuePosition: number;
|
|
35
|
+
}
|
|
36
|
+
export type BridgeConnectionStatus = 'connecting' | 'connected' | 'disconnected' | 'error';
|
|
37
|
+
export type WsEvent = {
|
|
38
|
+
type: 'bridge:status';
|
|
39
|
+
status: 'ready';
|
|
40
|
+
} | {
|
|
41
|
+
type: 'printer:status';
|
|
42
|
+
printerId: string;
|
|
43
|
+
status: PrinterStatus;
|
|
44
|
+
} | {
|
|
45
|
+
type: 'printer:missing';
|
|
46
|
+
printerId: string;
|
|
47
|
+
printerName: string;
|
|
48
|
+
} | {
|
|
49
|
+
type: 'job:queued';
|
|
50
|
+
job: PrintJob;
|
|
51
|
+
} | {
|
|
52
|
+
type: 'job:started';
|
|
53
|
+
jobId: string;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'job:completed';
|
|
56
|
+
jobId: string;
|
|
57
|
+
} | {
|
|
58
|
+
type: 'job:failed';
|
|
59
|
+
jobId: string;
|
|
60
|
+
error: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'job:retry';
|
|
63
|
+
jobId: string;
|
|
64
|
+
attempt: number;
|
|
65
|
+
error: string;
|
|
66
|
+
};
|
|
67
|
+
export interface BridgeClientOptions {
|
|
68
|
+
url?: string;
|
|
69
|
+
wsUrl?: string;
|
|
70
|
+
reconnectInterval?: number;
|
|
71
|
+
maxReconnectAttempts?: number;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAE9F,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,C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IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzE,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ordereat-uy/printer-bridge-client",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"dev": "tsc --watch",
|
|
19
|
+
"build": "tsc"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/juanmanuelrot/oe-printing-bridge"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^5.7.3"
|
|
27
|
+
}
|
|
28
|
+
}
|