@reservation-studio/electron-types 0.0.10 → 0.0.12

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/README.md CHANGED
@@ -1 +1,265 @@
1
1
  # @reservation-studio/electron-types
2
+
3
+ TypeScript type definitions for the Reservation.Studio Electron application.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @reservation-studio/electron-types
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ This package provides TypeScript type definitions for the Reservation.Studio Electron application. It includes interfaces and enums for working with:
14
+
15
+ - Certificate management
16
+ - XML signing
17
+ - HTTP requests
18
+ - Fiscal device operations
19
+ - Application environment and version information
20
+
21
+ ## API Reference
22
+
23
+ ### ReservationStudioElectron
24
+
25
+ The main API object exposed by the Electron application. It's available in the renderer process as `window.ReservationStudioElectron`.
26
+
27
+ ```typescript
28
+ import { ReservationStudioElectron } from '@reservation-studio/electron-types';
29
+
30
+ // Example usage
31
+ const version = await ReservationStudioElectron.version();
32
+ ```
33
+
34
+ ### Certificates
35
+
36
+ Methods for working with certificates:
37
+
38
+ ```typescript
39
+ // List all available certificates
40
+ const certificates = await ReservationStudioElectron.certificates.list();
41
+
42
+ // Validate a certificate PIN
43
+ const isValid = await ReservationStudioElectron.certificates.isValidPin(
44
+ slot,
45
+ pin
46
+ );
47
+ ```
48
+
49
+ ### XML Signing
50
+
51
+ Methods for signing XML documents:
52
+
53
+ ```typescript
54
+ // Sign an XML document
55
+ const signedXml = await ReservationStudioElectron.xml.sign(xml, slot, pin);
56
+ ```
57
+
58
+ ### HTTP Requests
59
+
60
+ Methods for making HTTP requests:
61
+
62
+ ```typescript
63
+ // Make a GET request
64
+ const response = await ReservationStudioElectron.http.get(url, {
65
+ headers: { 'Content-Type': 'application/json' },
66
+ timeout: 5000,
67
+ params: { key: 'value' }
68
+ });
69
+
70
+ // Make a POST request
71
+ const response = await ReservationStudioElectron.http.post(url, data, {
72
+ headers: { 'Content-Type': 'application/json' }
73
+ });
74
+ ```
75
+
76
+ ### Application Information
77
+
78
+ Methods for getting application information:
79
+
80
+ ```typescript
81
+ // Get application version
82
+ const version = await ReservationStudioElectron.version();
83
+
84
+ // Get application environment
85
+ const environment = await ReservationStudioElectron.environment();
86
+
87
+ // Reload the application window
88
+ await ReservationStudioElectron.reload();
89
+ ```
90
+
91
+ ### Fiscal Devices
92
+
93
+ Methods for working with fiscal devices:
94
+
95
+ ```typescript
96
+ // List all available fiscal devices
97
+ const devices = await ReservationStudioElectron.fiscalDevices.list();
98
+
99
+ // Set the active fiscal device
100
+ await ReservationStudioElectron.fiscalDevices.setActiveDevice(serialNumber);
101
+
102
+ // Get the active fiscal device
103
+ const activeDevice =
104
+ await ReservationStudioElectron.fiscalDevices.getActiveDevice();
105
+
106
+ // Print a fiscal receipt
107
+ const receiptNumber =
108
+ await ReservationStudioElectron.fiscalDevices.printReceipt({
109
+ operatorNumber: 1,
110
+ operatorPassword: '1',
111
+ items: [
112
+ {
113
+ name: 'Product 1',
114
+ price: 10.0,
115
+ quantity: 1,
116
+ vatGroup: 'A'
117
+ }
118
+ ],
119
+ payments: [
120
+ {
121
+ type: 'cash',
122
+ amount: 10.0
123
+ }
124
+ ]
125
+ });
126
+
127
+ // Print non-fiscal text
128
+ await ReservationStudioElectron.fiscalDevices.printText('Hello, World!');
129
+
130
+ // Get the last fiscal memory record
131
+ const lastRecord =
132
+ await ReservationStudioElectron.fiscalDevices.getLastFiscalRecord();
133
+
134
+ // Get the fiscal device status
135
+ const status = await ReservationStudioElectron.fiscalDevices.getStatus();
136
+ ```
137
+
138
+ ## Interfaces
139
+
140
+ ### ApiInterface
141
+
142
+ The main interface that defines the structure of the ReservationStudioElectron object.
143
+
144
+ ### CertificateInfo
145
+
146
+ ```typescript
147
+ interface CertificateInfo {
148
+ slot: number;
149
+ name: string;
150
+ serialNumber: string;
151
+ }
152
+ ```
153
+
154
+ ### HttpResponse
155
+
156
+ ```typescript
157
+ interface HttpResponse {
158
+ status: number;
159
+ headers: Record<string, string>;
160
+ data: any;
161
+ error: boolean;
162
+ }
163
+ ```
164
+
165
+ ### HttpOptions
166
+
167
+ ```typescript
168
+ interface HttpOptions {
169
+ headers?: Record<string, string>;
170
+ timeout?: number;
171
+ params?: Record<string, string>;
172
+ }
173
+ ```
174
+
175
+ ### FiscalReceipt
176
+
177
+ ```typescript
178
+ interface FiscalReceipt {
179
+ operatorNumber: number;
180
+ operatorPassword: string;
181
+ uniqueSaleNumber?: string;
182
+ items: FiscalReceiptItem[];
183
+ payments: FiscalPayment[];
184
+ client?: FiscalClient;
185
+ }
186
+ ```
187
+
188
+ ### FiscalReceiptItem
189
+
190
+ ```typescript
191
+ interface FiscalReceiptItem {
192
+ name: string;
193
+ price: number;
194
+ quantity: number;
195
+ vatGroup: string;
196
+ discount?: number;
197
+ }
198
+ ```
199
+
200
+ ### FiscalPayment
201
+
202
+ ```typescript
203
+ interface FiscalPayment {
204
+ type: FiscalPaymentType;
205
+ amount: number;
206
+ }
207
+ ```
208
+
209
+ ### FiscalPaymentType
210
+
211
+ ```typescript
212
+ enum FiscalPaymentType {
213
+ CASH = 'cash',
214
+ CARD = 'card',
215
+ CHECK = 'check',
216
+ TRANSFER = 'transfer'
217
+ }
218
+ ```
219
+
220
+ ### FiscalClient
221
+
222
+ ```typescript
223
+ interface FiscalClient {
224
+ name: string;
225
+ address?: string;
226
+ taxNumber?: string;
227
+ vatNumber?: string;
228
+ }
229
+ ```
230
+
231
+ ### FiscalMemoryRecord
232
+
233
+ ```typescript
234
+ interface FiscalMemoryRecord {
235
+ number: string;
236
+ date: Date;
237
+ total: number;
238
+ }
239
+ ```
240
+
241
+ ### FiscalDeviceStatus
242
+
243
+ ```typescript
244
+ interface FiscalDeviceStatus {
245
+ connected: boolean;
246
+ hasPaper: boolean;
247
+ fiscalMemoryFull: boolean;
248
+ errorCode?: number;
249
+ errorMessage?: string;
250
+ }
251
+ ```
252
+
253
+ ### EnvironmentEnum
254
+
255
+ ```typescript
256
+ enum EnvironmentEnum {
257
+ LOCAL = 'local',
258
+ STAGING = 'staging',
259
+ PRODUCTION = 'production'
260
+ }
261
+ ```
262
+
263
+ ## License
264
+
265
+ Proprietary - Reservation.Studio
@@ -4,6 +4,14 @@ export declare enum IpcActions {
4
4
  XML_SIGN = "xml:sign",
5
5
  GET_VERSION = "get-version",
6
6
  RELOAD_WINDOW = "reload-window",
7
+ ENVIRONMENT = "environment:get",
7
8
  HTTP_GET = "http:get",
8
- HTTP_POST = "http:post"
9
+ HTTP_POST = "http:post",
10
+ FISCAL_LIST = "fiscal:list",
11
+ FISCAL_SET_ACTIVE = "fiscal:set-active",
12
+ FISCAL_GET_ACTIVE = "fiscal:get-active",
13
+ FISCAL_PRINT_RECEIPT = "fiscal:print-receipt",
14
+ FISCAL_PRINT_TEXT = "fiscal:print-text",
15
+ FISCAL_GET_LAST_RECORD = "fiscal:get-last-record",
16
+ FISCAL_GET_STATUS = "fiscal:get-status"
9
17
  }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Enumeration representing different application environments.
3
+ *
4
+ * This enum is used to specify and manage various environments in which
5
+ * the application might run, such as local development, staging, and
6
+ * production environments.
7
+ *
8
+ * Members:
9
+ * - LOCAL: Represents the local development environment.
10
+ * - STAGING: Represents the staging environment.
11
+ * - PRODUCTION: Represents the production environment.
12
+ */
13
+ export declare enum EnvironmentEnum {
14
+ LOCAL = "local",
15
+ STAGING = "staging",
16
+ PRODUCTION = "production"
17
+ }
@@ -1,37 +1,62 @@
1
1
  import { CertificateInfo } from './certificate-info.interface';
2
2
  import { HttpOptions, HttpResponse } from './http.interface';
3
+ import { EnvironmentEnum } from '../enums/envirovment.enum';
4
+ import { FiscalDeviceInfo, FiscalDeviceStatus, FiscalMemoryRecord, FiscalReceipt } from './fiscal-device.interface';
3
5
  export interface ApiInterface {
4
6
  /**
5
- * Represents the certificates functionality for managing and retrieving certificate information.
6
- *
7
- * @property {Function} list Retrieves a list of certificates.
8
- * @returns {Promise<CertificateInfo[]>} A promise that resolves with an array of `CertificateInfo` objects containing details about each certificate.
7
+ * An object representing operations related to certificates.
9
8
  */
10
9
  certificates: {
10
+ /**
11
+ * Retrieves a list of certificate information.
12
+ *
13
+ * @return {Promise<CertificateInfo[]>} A promise that resolves to an array of CertificateInfo objects.
14
+ */
11
15
  list(): Promise<CertificateInfo[]>;
16
+ /**
17
+ * Validates a PIN against a specific slot.
18
+ *
19
+ * @param {number} slot - The numerical identifier of the slot to validate the PIN against.
20
+ * @param {string} pin - The PIN to be validated.
21
+ * @return {Promise<boolean>} A promise that resolves to true if the PIN is valid, otherwise false.
22
+ */
12
23
  isValidPin(slot: number, pin: string): Promise<boolean>;
13
24
  };
14
25
  /**
15
- * An object containing functionality related to XML operations.
16
- *
17
- * @property {function} sign - A function to sign an XML string using a specified slot and PIN.
18
- * @param {string} xml - The XML string to be signed.
19
- * @param {number} slot - The slot number to be used for signing.
20
- * @param {string} pin - The PIN associated with the slot for authentication.
21
- * @returns {Promise<string>} A promise that resolves to the signed XML string.
26
+ * Object representing XML-related operations.
22
27
  */
23
28
  xml: {
29
+ /**
30
+ * Signs the provided XML data using the specified cryptographic token slot and PIN.
31
+ *
32
+ * @param {string} xml - The XML string to be digitally signed.
33
+ * @param {number} slot - The slot number of the cryptographic token to be used for signing.
34
+ * @param {string} pin - The personal identification number (PIN) for accessing the cryptographic token.
35
+ * @return {Promise<string>} - A promise that resolves to the signed XML string.
36
+ */
24
37
  sign(xml: string, slot: number, pin: string): Promise<string>;
25
38
  };
26
39
  /**
27
- * An HTTP utility object that provides methods to make HTTP requests.
28
- * This object can be used to send HTTP POST and GET requests.
29
- *
30
- * @property {function} post - Sends an HTTP POST request to the specified URL with the provided data and optional configurations.
31
- * @property {function} get - Sends an HTTP GET request to the specified URL with optional configurations.
40
+ * A utility object for making HTTP requests, providing methods for sending GET and POST requests.
41
+ * Supports configuration options such as headers, query parameters, and response handling.
32
42
  */
33
43
  http: {
44
+ /**
45
+ * Sends an HTTP POST request to the specified URL with the provided data and options.
46
+ *
47
+ * @param {string} url - The URL to which the POST request is sent.
48
+ * @param {any} data - The payload to be sent in the body of the POST request.
49
+ * @param {HttpOptions} [options] - Optional configuration for the HTTP request, such as headers and parameters.
50
+ * @return {Promise<HttpResponse>} A promise that resolves to the HTTP response object containing status, headers, and data.
51
+ */
34
52
  post(url: string, data: any, options?: HttpOptions): Promise<HttpResponse>;
53
+ /**
54
+ * Sends an HTTP GET request to the specified URL with optional configuration settings.
55
+ *
56
+ * @param {string} url - The target URL to which the GET request will be sent.
57
+ * @param {HttpOptions} [options] - Optional settings to configure the HTTP request, such as headers, query parameters, and other request options.
58
+ * @return {Promise<HttpResponse>} A promise that resolves to the HTTP response containing the status, headers, and data of the response.
59
+ */
35
60
  get(url: string, options?: HttpOptions): Promise<HttpResponse>;
36
61
  };
37
62
  /**
@@ -48,4 +73,64 @@ export interface ApiInterface {
48
73
  * @return {Promise<void>} A promise that resolves when the reload operation is complete.
49
74
  */
50
75
  reload(): Promise<void>;
76
+ /**
77
+ * Retrieves the current application environment.
78
+ *
79
+ * @return {Promise<EnvironmentEnum>} A promise that resolves to the enumeration representing the current environment.
80
+ */
81
+ environment(): Promise<EnvironmentEnum>;
82
+ /**
83
+ * An object representing operations related to fiscal devices.
84
+ * All methods automatically initialize fiscal devices when needed.
85
+ */
86
+ fiscalDevices: {
87
+ /**
88
+ * Gets a list of all detected fiscal devices.
89
+ * Automatically initializes fiscal devices if needed.
90
+ *
91
+ * @return {Promise<FiscalDeviceInfo[]>} A promise that resolves to an array of fiscal device information.
92
+ */
93
+ list(): Promise<FiscalDeviceInfo[]>;
94
+ /**
95
+ * Sets the active fiscal device.
96
+ *
97
+ * @param {string} serialNumber - The serial number of the device to set as active.
98
+ * @return {Promise<void>} A promise that resolves when the device is successfully set as active.
99
+ * @throws {Error} If the device with the specified serial number is not found.
100
+ */
101
+ setActiveDevice(serialNumber: string): Promise<void>;
102
+ /**
103
+ * Gets the active fiscal device.
104
+ *
105
+ * @return {Promise<FiscalDeviceInfo>} A promise that resolves to the active fiscal device information.
106
+ * @throws {Error} If no active device is set.
107
+ */
108
+ getActiveDevice(): Promise<FiscalDeviceInfo>;
109
+ /**
110
+ * Prints a fiscal receipt using the active device.
111
+ *
112
+ * @param {FiscalReceipt} receipt - The receipt to print.
113
+ * @return {Promise<string>} A promise that resolves to the receipt number.
114
+ */
115
+ printReceipt(receipt: FiscalReceipt): Promise<string>;
116
+ /**
117
+ * Prints a non-fiscal text using the active device.
118
+ *
119
+ * @param {string} text - The text to print.
120
+ * @return {Promise<boolean>} A promise that resolves to true if printing was successful.
121
+ */
122
+ printText(text: string): Promise<boolean>;
123
+ /**
124
+ * Gets the last fiscal memory record from the active device.
125
+ *
126
+ * @return {Promise<FiscalMemoryRecord>} A promise that resolves to the last fiscal memory record.
127
+ */
128
+ getLastFiscalRecord(): Promise<FiscalMemoryRecord>;
129
+ /**
130
+ * Gets the status of the active device.
131
+ *
132
+ * @return {Promise<FiscalDeviceStatus>} A promise that resolves to the status of the active device.
133
+ */
134
+ getStatus(): Promise<FiscalDeviceStatus>;
135
+ };
51
136
  }
@@ -4,18 +4,27 @@
4
4
  export interface CertificateInfo {
5
5
  /**
6
6
  * The slot number associated with the certificate.
7
- * This is typically used to identify the location or index of the certificate
8
- * in a storage or hardware module.
9
7
  */
10
8
  slot: number;
11
9
  /**
12
10
  * The name of the certificate.
13
- * This is often used for identification or descriptive purposes.
14
11
  */
15
12
  name: string;
16
13
  /**
17
14
  * The serial number of the certificate.
18
- * This is used to uniquely identify the certificate.
19
15
  */
20
16
  serialNumber: string;
21
17
  }
18
+ /**
19
+ * Interface representing a certificate-based authentication structure.
20
+ */
21
+ export interface CertificateAuth {
22
+ /**
23
+ * Represents the serial number of an item.
24
+ */
25
+ serialNumber: string;
26
+ /**
27
+ * Personal identification code.
28
+ */
29
+ pin: string;
30
+ }
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Interface for fiscal device operations
3
+ */
4
+ export interface FiscalDeviceInterface {
5
+ /**
6
+ * The model name of the fiscal device
7
+ */
8
+ readonly model: string;
9
+ /**
10
+ * The manufacturer of the fiscal device
11
+ */
12
+ readonly manufacturer: string;
13
+ /**
14
+ * The serial number of the fiscal device
15
+ */
16
+ readonly serialNumber: string;
17
+ /**
18
+ * The port path of the fiscal device
19
+ */
20
+ readonly port: string;
21
+ /**
22
+ * Initializes the fiscal device
23
+ *
24
+ * @returns {Promise<boolean>} A promise that resolves to true if initialization was successful
25
+ */
26
+ initialize(): Promise<boolean>;
27
+ /**
28
+ * Checks if the device is connected and responsive
29
+ *
30
+ * @returns {Promise<boolean>} A promise that resolves to true if the device is connected
31
+ */
32
+ isConnected(): Promise<boolean>;
33
+ /**
34
+ * Prints a fiscal receipt
35
+ *
36
+ * @param {FiscalReceipt} receipt - The receipt to print
37
+ * @returns {Promise<string>} A promise that resolves to the receipt number
38
+ */
39
+ printReceipt(receipt: FiscalReceipt): Promise<string>;
40
+ /**
41
+ * Prints a non-fiscal text
42
+ *
43
+ * @param {string} text - The text to print
44
+ * @returns {Promise<boolean>} A promise that resolves to true if printing was successful
45
+ */
46
+ printText(text: string): Promise<boolean>;
47
+ /**
48
+ * Gets the last fiscal memory record
49
+ *
50
+ * @returns {Promise<FiscalMemoryRecord>} A promise that resolves to the last fiscal memory record
51
+ */
52
+ getLastFiscalRecord(): Promise<FiscalMemoryRecord>;
53
+ /**
54
+ * Gets the status of the fiscal device
55
+ *
56
+ * @returns {Promise<FiscalDeviceStatus>} A promise that resolves to the status of the fiscal device
57
+ */
58
+ getStatus(): Promise<FiscalDeviceStatus>;
59
+ /**
60
+ * Closes the connection to the fiscal device
61
+ *
62
+ * @returns {Promise<boolean>} A promise that resolves to true if closing was successful
63
+ */
64
+ close(): Promise<boolean>;
65
+ }
66
+ /**
67
+ * Interface for fiscal receipt
68
+ */
69
+ export interface FiscalReceipt {
70
+ /**
71
+ * The operator number
72
+ */
73
+ operatorNumber: number;
74
+ /**
75
+ * The operator password
76
+ */
77
+ operatorPassword: string;
78
+ /**
79
+ * The unique sale number
80
+ */
81
+ uniqueSaleNumber?: string;
82
+ /**
83
+ * The items in the receipt
84
+ */
85
+ items: FiscalReceiptItem[];
86
+ /**
87
+ * The payments in the receipt
88
+ */
89
+ payments: FiscalPayment[];
90
+ /**
91
+ * The client information (for invoice receipts)
92
+ */
93
+ client?: FiscalClient;
94
+ }
95
+ /**
96
+ * Interface for fiscal receipt item
97
+ */
98
+ export interface FiscalReceiptItem {
99
+ /**
100
+ * The name of the item
101
+ */
102
+ name: string;
103
+ /**
104
+ * The price of the item
105
+ */
106
+ price: number;
107
+ /**
108
+ * The quantity of the item
109
+ */
110
+ quantity: number;
111
+ /**
112
+ * The VAT group of the item
113
+ */
114
+ vatGroup: string;
115
+ /**
116
+ * The discount percentage (optional)
117
+ */
118
+ discount?: number;
119
+ }
120
+ /**
121
+ * Interface for fiscal payment
122
+ */
123
+ export interface FiscalPayment {
124
+ /**
125
+ * The payment type
126
+ */
127
+ type: FiscalPaymentType;
128
+ /**
129
+ * The amount of the payment
130
+ */
131
+ amount: number;
132
+ }
133
+ /**
134
+ * Enum for fiscal payment types
135
+ */
136
+ export declare enum FiscalPaymentType {
137
+ CASH = "cash",
138
+ CARD = "card",
139
+ CHECK = "check",
140
+ TRANSFER = "transfer"
141
+ }
142
+ /**
143
+ * Interface for fiscal client information
144
+ */
145
+ export interface FiscalClient {
146
+ /**
147
+ * The name of the client
148
+ */
149
+ name: string;
150
+ /**
151
+ * The address of the client
152
+ */
153
+ address?: string;
154
+ /**
155
+ * The tax number of the client
156
+ */
157
+ taxNumber?: string;
158
+ /**
159
+ * The VAT number of the client
160
+ */
161
+ vatNumber?: string;
162
+ }
163
+ /**
164
+ * Interface for fiscal memory record
165
+ */
166
+ export interface FiscalMemoryRecord {
167
+ /**
168
+ * The number of the record
169
+ */
170
+ number: string;
171
+ /**
172
+ * The date of the record
173
+ */
174
+ date: Date;
175
+ /**
176
+ * The total amount of the record
177
+ */
178
+ total: number;
179
+ }
180
+ /**
181
+ * Interface for fiscal device status
182
+ */
183
+ export interface FiscalDeviceStatus {
184
+ /**
185
+ * Whether the device is connected
186
+ */
187
+ connected: boolean;
188
+ /**
189
+ * Whether the device has paper
190
+ */
191
+ hasPaper: boolean;
192
+ /**
193
+ * Whether the fiscal memory is full
194
+ */
195
+ fiscalMemoryFull: boolean;
196
+ /**
197
+ * The error code if any
198
+ */
199
+ errorCode?: number;
200
+ /**
201
+ * The error message if any
202
+ */
203
+ errorMessage?: string;
204
+ }
205
+ /**
206
+ * Interface for fiscal device information in list responses
207
+ */
208
+ export interface FiscalDeviceInfo {
209
+ /**
210
+ * The manufacturer of the fiscal device
211
+ */
212
+ manufacturer: string;
213
+ /**
214
+ * The model name of the fiscal device
215
+ */
216
+ model: string;
217
+ /**
218
+ * The serial number of the fiscal device
219
+ */
220
+ serialNumber: string;
221
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reservation-studio/electron-types",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "TypeScript типове за ReservationStudioElectron",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -16,8 +16,8 @@
16
16
  "author": "Venelin Iliev",
17
17
  "license": "Proprietary - Reservation.Studio",
18
18
  "devDependencies": {
19
- "typescript": "^4.5.4",
20
- "@types/node": "^22"
19
+ "@types/node": "^22.16.0",
20
+ "typescript": "^5.2.0"
21
21
  },
22
22
  "files": [
23
23
  "dist"