memobirdsdk 1.0.0
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 +483 -0
- package/dist/api/bind.d.ts +24 -0
- package/dist/api/bind.d.ts.map +1 -0
- package/dist/api/bind.js +49 -0
- package/dist/api/bind.js.map +1 -0
- package/dist/api/image.d.ts +25 -0
- package/dist/api/image.d.ts.map +1 -0
- package/dist/api/image.js +46 -0
- package/dist/api/image.js.map +1 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +9 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/print.d.ts +71 -0
- package/dist/api/print.d.ts.map +1 -0
- package/dist/api/print.js +147 -0
- package/dist/api/print.js.map +1 -0
- package/dist/api/status.d.ts +24 -0
- package/dist/api/status.d.ts.map +1 -0
- package/dist/api/status.js +47 -0
- package/dist/api/status.js.map +1 -0
- package/dist/client.d.ts +204 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +250 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +18 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +23 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors/APIError.d.ts +16 -0
- package/dist/errors/APIError.d.ts.map +1 -0
- package/dist/errors/APIError.js +21 -0
- package/dist/errors/APIError.js.map +1 -0
- package/dist/errors/MemobirdError.d.ts +13 -0
- package/dist/errors/MemobirdError.d.ts.map +1 -0
- package/dist/errors/MemobirdError.js +18 -0
- package/dist/errors/MemobirdError.js.map +1 -0
- package/dist/errors/NetworkError.d.ts +14 -0
- package/dist/errors/NetworkError.d.ts.map +1 -0
- package/dist/errors/NetworkError.js +18 -0
- package/dist/errors/NetworkError.js.map +1 -0
- package/dist/errors/ValidationError.d.ts +14 -0
- package/dist/errors/ValidationError.d.ts.map +1 -0
- package/dist/errors/ValidationError.js +18 -0
- package/dist/errors/ValidationError.js.map +1 -0
- package/dist/errors/index.d.ts +9 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +9 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/types/api.d.ts +122 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +2 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/common.d.ts +27 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +15 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/config.d.ts +32 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/content-formatter.d.ts +49 -0
- package/dist/utils/content-formatter.d.ts.map +1 -0
- package/dist/utils/content-formatter.js +65 -0
- package/dist/utils/content-formatter.js.map +1 -0
- package/dist/utils/encoding.d.ts +32 -0
- package/dist/utils/encoding.d.ts.map +1 -0
- package/dist/utils/encoding.js +50 -0
- package/dist/utils/encoding.js.map +1 -0
- package/dist/utils/image.d.ts +42 -0
- package/dist/utils/image.d.ts.map +1 -0
- package/dist/utils/image.js +58 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/retry.d.ts +70 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +132 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/timestamp.d.ts +27 -0
- package/dist/utils/timestamp.d.ts.map +1 -0
- package/dist/utils/timestamp.js +38 -0
- package/dist/utils/timestamp.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { RetryConfig } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Retry strategy with exponential backoff
|
|
4
|
+
*
|
|
5
|
+
* Automatically retries failed operations with increasing delays between attempts.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RetryStrategy {
|
|
8
|
+
private config;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new RetryStrategy
|
|
11
|
+
*
|
|
12
|
+
* @param config - Retry configuration options
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const strategy = new RetryStrategy({
|
|
17
|
+
* maxRetries: 3,
|
|
18
|
+
* initialDelay: 1000,
|
|
19
|
+
* backoffMultiplier: 2
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
constructor(config?: RetryConfig);
|
|
24
|
+
/**
|
|
25
|
+
* Executes a function with retry logic
|
|
26
|
+
*
|
|
27
|
+
* @param fn - Async function to execute
|
|
28
|
+
* @returns Promise with function result
|
|
29
|
+
* @throws Error from the function if all retries are exhausted
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const result = await strategy.execute(async () => {
|
|
34
|
+
* return await someApiCall();
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Calculates delay for next retry attempt using exponential backoff
|
|
41
|
+
*
|
|
42
|
+
* @param attemptNumber - Current attempt number (0-indexed)
|
|
43
|
+
* @returns Delay in milliseconds
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* strategy.calculateDelay(0); // 1000ms
|
|
48
|
+
* strategy.calculateDelay(1); // 2000ms
|
|
49
|
+
* strategy.calculateDelay(2); // 4000ms
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
calculateDelay(attemptNumber: number): number;
|
|
53
|
+
/**
|
|
54
|
+
* Determines if error should trigger retry
|
|
55
|
+
*
|
|
56
|
+
* Retries on network errors and specific HTTP status codes (5xx, 408, 429).
|
|
57
|
+
* Does not retry on client errors (4xx except 408, 429).
|
|
58
|
+
*
|
|
59
|
+
* @param error - Error object
|
|
60
|
+
* @returns true if should retry
|
|
61
|
+
*/
|
|
62
|
+
shouldRetry(error: unknown): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Sleep for specified milliseconds
|
|
65
|
+
*
|
|
66
|
+
* @param ms - Milliseconds to sleep
|
|
67
|
+
*/
|
|
68
|
+
private sleep;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAcrD;;;;GAIG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAwB;IAEtC;;;;;;;;;;;;;OAaG;gBACS,MAAM,GAAE,WAAgB;IAIpC;;;;;;;;;;;;;OAaG;IACG,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IA6BlD;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAM7C;;;;;;;;OAQG;IACH,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IA2BpC;;;;OAIG;IACH,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { NetworkError } from '../errors/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Default retry configuration
|
|
4
|
+
*/
|
|
5
|
+
const DEFAULT_RETRY_CONFIG = {
|
|
6
|
+
maxRetries: 3,
|
|
7
|
+
initialDelay: 1000,
|
|
8
|
+
backoffMultiplier: 2,
|
|
9
|
+
maxDelay: 10000,
|
|
10
|
+
retryStatusCodes: [408, 429, 500, 502, 503, 504],
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Retry strategy with exponential backoff
|
|
14
|
+
*
|
|
15
|
+
* Automatically retries failed operations with increasing delays between attempts.
|
|
16
|
+
*/
|
|
17
|
+
export class RetryStrategy {
|
|
18
|
+
config;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new RetryStrategy
|
|
21
|
+
*
|
|
22
|
+
* @param config - Retry configuration options
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const strategy = new RetryStrategy({
|
|
27
|
+
* maxRetries: 3,
|
|
28
|
+
* initialDelay: 1000,
|
|
29
|
+
* backoffMultiplier: 2
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
constructor(config = {}) {
|
|
34
|
+
this.config = { ...DEFAULT_RETRY_CONFIG, ...config };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Executes a function with retry logic
|
|
38
|
+
*
|
|
39
|
+
* @param fn - Async function to execute
|
|
40
|
+
* @returns Promise with function result
|
|
41
|
+
* @throws Error from the function if all retries are exhausted
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const result = await strategy.execute(async () => {
|
|
46
|
+
* return await someApiCall();
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
async execute(fn) {
|
|
51
|
+
let lastError;
|
|
52
|
+
for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
|
|
53
|
+
try {
|
|
54
|
+
return await fn();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
58
|
+
// Don't retry if this was the last attempt
|
|
59
|
+
if (attempt === this.config.maxRetries) {
|
|
60
|
+
throw lastError;
|
|
61
|
+
}
|
|
62
|
+
// Don't retry if error shouldn't trigger retry
|
|
63
|
+
if (!this.shouldRetry(error)) {
|
|
64
|
+
throw lastError;
|
|
65
|
+
}
|
|
66
|
+
// Calculate delay and wait before next attempt
|
|
67
|
+
const delay = this.calculateDelay(attempt);
|
|
68
|
+
await this.sleep(delay);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// This should never be reached, but TypeScript needs it
|
|
72
|
+
throw lastError || new Error('Unknown error during retry');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Calculates delay for next retry attempt using exponential backoff
|
|
76
|
+
*
|
|
77
|
+
* @param attemptNumber - Current attempt number (0-indexed)
|
|
78
|
+
* @returns Delay in milliseconds
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* strategy.calculateDelay(0); // 1000ms
|
|
83
|
+
* strategy.calculateDelay(1); // 2000ms
|
|
84
|
+
* strategy.calculateDelay(2); // 4000ms
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
calculateDelay(attemptNumber) {
|
|
88
|
+
const delay = this.config.initialDelay * Math.pow(this.config.backoffMultiplier, attemptNumber);
|
|
89
|
+
return Math.min(delay, this.config.maxDelay);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Determines if error should trigger retry
|
|
93
|
+
*
|
|
94
|
+
* Retries on network errors and specific HTTP status codes (5xx, 408, 429).
|
|
95
|
+
* Does not retry on client errors (4xx except 408, 429).
|
|
96
|
+
*
|
|
97
|
+
* @param error - Error object
|
|
98
|
+
* @returns true if should retry
|
|
99
|
+
*/
|
|
100
|
+
shouldRetry(error) {
|
|
101
|
+
// Always retry NetworkError
|
|
102
|
+
if (error instanceof NetworkError) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
// Retry on specific HTTP status codes
|
|
106
|
+
if (typeof error === 'object' && error !== null && 'statusCode' in error) {
|
|
107
|
+
const statusCode = error.statusCode;
|
|
108
|
+
return this.config.retryStatusCodes.includes(statusCode);
|
|
109
|
+
}
|
|
110
|
+
// Retry on network-related errors (ECONNRESET, ETIMEDOUT, etc.)
|
|
111
|
+
if (error instanceof Error) {
|
|
112
|
+
const networkErrorCodes = [
|
|
113
|
+
'ECONNRESET',
|
|
114
|
+
'ECONNREFUSED',
|
|
115
|
+
'ETIMEDOUT',
|
|
116
|
+
'ENOTFOUND',
|
|
117
|
+
'ENETUNREACH',
|
|
118
|
+
];
|
|
119
|
+
return networkErrorCodes.some((code) => error.message.includes(code));
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Sleep for specified milliseconds
|
|
125
|
+
*
|
|
126
|
+
* @param ms - Milliseconds to sleep
|
|
127
|
+
*/
|
|
128
|
+
sleep(ms) {
|
|
129
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/utils/retry.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates timestamp in Memobird API format (YYYY-MM-DD HH:mm:ss)
|
|
3
|
+
*
|
|
4
|
+
* @param date - Date object to format (defaults to current date/time)
|
|
5
|
+
* @returns Formatted timestamp string
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const timestamp = generateTimestamp();
|
|
10
|
+
* console.log(timestamp); // '2025-12-29 14:30:45'
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateTimestamp(date?: Date): string;
|
|
14
|
+
/**
|
|
15
|
+
* Validates if a string matches Memobird timestamp format
|
|
16
|
+
*
|
|
17
|
+
* @param timestamp - Timestamp string to validate
|
|
18
|
+
* @returns true if valid format, false otherwise
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* isValidTimestamp('2025-12-29 14:30:45'); // true
|
|
23
|
+
* isValidTimestamp('2025/12/29 14:30:45'); // false
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function isValidTimestamp(timestamp: string): boolean;
|
|
27
|
+
//# sourceMappingURL=timestamp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamp.d.ts","sourceRoot":"","sources":["../../src/utils/timestamp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,IAAiB,GAAG,MAAM,CASjE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAG3D"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates timestamp in Memobird API format (YYYY-MM-DD HH:mm:ss)
|
|
3
|
+
*
|
|
4
|
+
* @param date - Date object to format (defaults to current date/time)
|
|
5
|
+
* @returns Formatted timestamp string
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const timestamp = generateTimestamp();
|
|
10
|
+
* console.log(timestamp); // '2025-12-29 14:30:45'
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function generateTimestamp(date = new Date()) {
|
|
14
|
+
const year = date.getFullYear();
|
|
15
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
16
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
17
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
|
18
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
19
|
+
const seconds = String(date.getSeconds()).padStart(2, '0');
|
|
20
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validates if a string matches Memobird timestamp format
|
|
24
|
+
*
|
|
25
|
+
* @param timestamp - Timestamp string to validate
|
|
26
|
+
* @returns true if valid format, false otherwise
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* isValidTimestamp('2025-12-29 14:30:45'); // true
|
|
31
|
+
* isValidTimestamp('2025/12/29 14:30:45'); // false
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function isValidTimestamp(timestamp) {
|
|
35
|
+
const pattern = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
|
|
36
|
+
return pattern.test(timestamp);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=timestamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../../src/utils/timestamp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAa,IAAI,IAAI,EAAE;IACvD,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACvD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAE3D,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;AAClE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,MAAM,OAAO,GAAG,uCAAuC,CAAC;IACxD,OAAO,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "memobirdsdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for Memobird (咕咕机) thermal printer API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"build:examples": "tsc -p tsconfig.examples.json",
|
|
18
|
+
"prepublishOnly": "npm run build",
|
|
19
|
+
"test": "npm run build && npm run build:examples && node examples/test.js",
|
|
20
|
+
"example:basic": "npm run build && npm run build:examples && node examples/basic-usage.js",
|
|
21
|
+
"example:text": "npm run build && npm run build:examples && node examples/print-text.js",
|
|
22
|
+
"example:image": "npm run build && npm run build:examples && node examples/print-image.js",
|
|
23
|
+
"example:advanced": "npm run build && npm run build:examples && node examples/advanced.js"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"memobird",
|
|
27
|
+
"thermal-printer",
|
|
28
|
+
"printer",
|
|
29
|
+
"sdk",
|
|
30
|
+
"gugumachine",
|
|
31
|
+
"iot",
|
|
32
|
+
"typescript",
|
|
33
|
+
"api-client"
|
|
34
|
+
],
|
|
35
|
+
"author": "",
|
|
36
|
+
"license": "ISC",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/yourusername/memobirdsdk.git"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/yourusername/memobirdsdk/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/yourusername/memobirdsdk#readme",
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE"
|
|
52
|
+
],
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"dotenv": "^17.2.3",
|
|
55
|
+
"got": "^14.6.5",
|
|
56
|
+
"iconv-lite": "^0.6.3"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/dotenv": "^6.1.1",
|
|
60
|
+
"@types/node": "^20.19.27",
|
|
61
|
+
"typescript": "5.3"
|
|
62
|
+
}
|
|
63
|
+
}
|