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.
Files changed (94) hide show
  1. package/README.md +483 -0
  2. package/dist/api/bind.d.ts +24 -0
  3. package/dist/api/bind.d.ts.map +1 -0
  4. package/dist/api/bind.js +49 -0
  5. package/dist/api/bind.js.map +1 -0
  6. package/dist/api/image.d.ts +25 -0
  7. package/dist/api/image.d.ts.map +1 -0
  8. package/dist/api/image.js +46 -0
  9. package/dist/api/image.js.map +1 -0
  10. package/dist/api/index.d.ts +9 -0
  11. package/dist/api/index.d.ts.map +1 -0
  12. package/dist/api/index.js +9 -0
  13. package/dist/api/index.js.map +1 -0
  14. package/dist/api/print.d.ts +71 -0
  15. package/dist/api/print.d.ts.map +1 -0
  16. package/dist/api/print.js +147 -0
  17. package/dist/api/print.js.map +1 -0
  18. package/dist/api/status.d.ts +24 -0
  19. package/dist/api/status.d.ts.map +1 -0
  20. package/dist/api/status.js +47 -0
  21. package/dist/api/status.js.map +1 -0
  22. package/dist/client.d.ts +204 -0
  23. package/dist/client.d.ts.map +1 -0
  24. package/dist/client.js +250 -0
  25. package/dist/client.js.map +1 -0
  26. package/dist/constants.d.ts +18 -0
  27. package/dist/constants.d.ts.map +1 -0
  28. package/dist/constants.js +23 -0
  29. package/dist/constants.js.map +1 -0
  30. package/dist/errors/APIError.d.ts +16 -0
  31. package/dist/errors/APIError.d.ts.map +1 -0
  32. package/dist/errors/APIError.js +21 -0
  33. package/dist/errors/APIError.js.map +1 -0
  34. package/dist/errors/MemobirdError.d.ts +13 -0
  35. package/dist/errors/MemobirdError.d.ts.map +1 -0
  36. package/dist/errors/MemobirdError.js +18 -0
  37. package/dist/errors/MemobirdError.js.map +1 -0
  38. package/dist/errors/NetworkError.d.ts +14 -0
  39. package/dist/errors/NetworkError.d.ts.map +1 -0
  40. package/dist/errors/NetworkError.js +18 -0
  41. package/dist/errors/NetworkError.js.map +1 -0
  42. package/dist/errors/ValidationError.d.ts +14 -0
  43. package/dist/errors/ValidationError.d.ts.map +1 -0
  44. package/dist/errors/ValidationError.js +18 -0
  45. package/dist/errors/ValidationError.js.map +1 -0
  46. package/dist/errors/index.d.ts +9 -0
  47. package/dist/errors/index.d.ts.map +1 -0
  48. package/dist/errors/index.js +9 -0
  49. package/dist/errors/index.js.map +1 -0
  50. package/dist/index.d.ts +21 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +25 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/types/api.d.ts +122 -0
  55. package/dist/types/api.d.ts.map +1 -0
  56. package/dist/types/api.js +2 -0
  57. package/dist/types/api.js.map +1 -0
  58. package/dist/types/common.d.ts +27 -0
  59. package/dist/types/common.d.ts.map +1 -0
  60. package/dist/types/common.js +15 -0
  61. package/dist/types/common.js.map +1 -0
  62. package/dist/types/config.d.ts +32 -0
  63. package/dist/types/config.d.ts.map +1 -0
  64. package/dist/types/config.js +2 -0
  65. package/dist/types/config.js.map +1 -0
  66. package/dist/types/index.d.ts +8 -0
  67. package/dist/types/index.d.ts.map +1 -0
  68. package/dist/types/index.js +8 -0
  69. package/dist/types/index.js.map +1 -0
  70. package/dist/utils/content-formatter.d.ts +49 -0
  71. package/dist/utils/content-formatter.d.ts.map +1 -0
  72. package/dist/utils/content-formatter.js +65 -0
  73. package/dist/utils/content-formatter.js.map +1 -0
  74. package/dist/utils/encoding.d.ts +32 -0
  75. package/dist/utils/encoding.d.ts.map +1 -0
  76. package/dist/utils/encoding.js +50 -0
  77. package/dist/utils/encoding.js.map +1 -0
  78. package/dist/utils/image.d.ts +42 -0
  79. package/dist/utils/image.d.ts.map +1 -0
  80. package/dist/utils/image.js +58 -0
  81. package/dist/utils/image.js.map +1 -0
  82. package/dist/utils/index.d.ts +10 -0
  83. package/dist/utils/index.d.ts.map +1 -0
  84. package/dist/utils/index.js +10 -0
  85. package/dist/utils/index.js.map +1 -0
  86. package/dist/utils/retry.d.ts +70 -0
  87. package/dist/utils/retry.d.ts.map +1 -0
  88. package/dist/utils/retry.js +132 -0
  89. package/dist/utils/retry.js.map +1 -0
  90. package/dist/utils/timestamp.d.ts +27 -0
  91. package/dist/utils/timestamp.d.ts.map +1 -0
  92. package/dist/utils/timestamp.js +38 -0
  93. package/dist/utils/timestamp.js.map +1 -0
  94. package/package.json +63 -0
@@ -0,0 +1,71 @@
1
+ import type { Got } from 'got';
2
+ import type { PrintResponse } from '../types/index.js';
3
+ /**
4
+ * Sends print content to a Memobird device
5
+ *
6
+ * @param client - Got HTTP client instance
7
+ * @param ak - Access Key
8
+ * @param printcontent - Formatted print content (T:base64 or P:base64)
9
+ * @param memobirdID - Device ID
10
+ * @param userID - User ID from binding
11
+ * @returns Promise resolving to print response
12
+ * @throws {APIError} If API returns error response
13
+ * @throws {NetworkError} If network request fails
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const response = await printPaper(client, ak, 'T:SGVsbG8=', 'device-id', 123);
18
+ * console.log('Print ID:', response.printcontentid);
19
+ * ```
20
+ */
21
+ export declare function printPaper(client: Got, ak: string, printcontent: string, memobirdID: string, userID: number): Promise<PrintResponse>;
22
+ /**
23
+ * Prints content from a web URL
24
+ *
25
+ * Note: Works best with static or server-rendered pages. AJAX-rendered content may fail.
26
+ * Images must use complete URLs, and CSS should be inline.
27
+ *
28
+ * @param client - Got HTTP client instance
29
+ * @param ak - Access Key
30
+ * @param printUrl - URL of the web page to print
31
+ * @param memobirdID - Device ID
32
+ * @param userID - User ID from binding
33
+ * @returns Promise resolving to print response
34
+ * @throws {APIError} If API returns error response
35
+ * @throws {NetworkError} If network request fails
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const response = await printFromUrl(
40
+ * client,
41
+ * ak,
42
+ * 'https://example.com/page',
43
+ * 'device-id',
44
+ * 123
45
+ * );
46
+ * ```
47
+ */
48
+ export declare function printFromUrl(client: Got, ak: string, printUrl: string, memobirdID: string, userID: number): Promise<PrintResponse>;
49
+ /**
50
+ * Prints content from HTML source
51
+ *
52
+ * HTML must have inline CSS and complete image URLs.
53
+ * The HTML is automatically converted to GBK Base64 and URL encoded.
54
+ *
55
+ * @param client - Got HTTP client instance
56
+ * @param ak - Access Key
57
+ * @param htmlSource - HTML source code
58
+ * @param memobirdID - Device ID
59
+ * @param userID - User ID from binding
60
+ * @returns Promise resolving to print response
61
+ * @throws {APIError} If API returns error response
62
+ * @throws {NetworkError} If network request fails
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const html = '<html><body><h1>Hello</h1></body></html>';
67
+ * const response = await printFromHtml(client, ak, html, 'device-id', 123);
68
+ * ```
69
+ */
70
+ export declare function printFromHtml(client: Got, ak: string, htmlSource: string, memobirdID: string, userID: number): Promise<PrintResponse>;
71
+ //# sourceMappingURL=print.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print.d.ts","sourceRoot":"","sources":["../../src/api/print.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,KAAK,EAEV,aAAa,EAGd,MAAM,mBAAmB,CAAC;AAK3B;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,GAAG,EACX,EAAE,EAAE,MAAM,EACV,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,CAAC,CAkCxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,GAAG,EACX,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,CAAC,CAkCxB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,GAAG,EACX,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,CAAC,CAsCxB"}
@@ -0,0 +1,147 @@
1
+ import { APIError, NetworkError } from '../errors/index.js';
2
+ import { generateTimestamp, textToGBKBase64 } from '../utils/index.js';
3
+ import { API_SUCCESS_CODE } from '../constants.js';
4
+ /**
5
+ * Sends print content to a Memobird device
6
+ *
7
+ * @param client - Got HTTP client instance
8
+ * @param ak - Access Key
9
+ * @param printcontent - Formatted print content (T:base64 or P:base64)
10
+ * @param memobirdID - Device ID
11
+ * @param userID - User ID from binding
12
+ * @returns Promise resolving to print response
13
+ * @throws {APIError} If API returns error response
14
+ * @throws {NetworkError} If network request fails
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const response = await printPaper(client, ak, 'T:SGVsbG8=', 'device-id', 123);
19
+ * console.log('Print ID:', response.printcontentid);
20
+ * ```
21
+ */
22
+ export async function printPaper(client, ak, printcontent, memobirdID, userID) {
23
+ try {
24
+ const requestData = {
25
+ ak,
26
+ timestamp: generateTimestamp(),
27
+ printcontent,
28
+ memobirdID,
29
+ userID,
30
+ };
31
+ const response = await client.post('printpaper', {
32
+ form: requestData,
33
+ });
34
+ const data = response.body;
35
+ if (data.showapi_res_code !== API_SUCCESS_CODE) {
36
+ throw new APIError(`Failed to print: ${data.showapi_res_error}`, data.showapi_res_code, data.showapi_res_error);
37
+ }
38
+ return data;
39
+ }
40
+ catch (error) {
41
+ if (error instanceof APIError) {
42
+ throw error;
43
+ }
44
+ throw new NetworkError(`Network error while printing: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
45
+ }
46
+ }
47
+ /**
48
+ * Prints content from a web URL
49
+ *
50
+ * Note: Works best with static or server-rendered pages. AJAX-rendered content may fail.
51
+ * Images must use complete URLs, and CSS should be inline.
52
+ *
53
+ * @param client - Got HTTP client instance
54
+ * @param ak - Access Key
55
+ * @param printUrl - URL of the web page to print
56
+ * @param memobirdID - Device ID
57
+ * @param userID - User ID from binding
58
+ * @returns Promise resolving to print response
59
+ * @throws {APIError} If API returns error response
60
+ * @throws {NetworkError} If network request fails
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const response = await printFromUrl(
65
+ * client,
66
+ * ak,
67
+ * 'https://example.com/page',
68
+ * 'device-id',
69
+ * 123
70
+ * );
71
+ * ```
72
+ */
73
+ export async function printFromUrl(client, ak, printUrl, memobirdID, userID) {
74
+ try {
75
+ const requestData = {
76
+ ak,
77
+ timestamp: generateTimestamp(),
78
+ printUrl,
79
+ memobirdID,
80
+ userID,
81
+ };
82
+ const response = await client.post('printpaperFromUrl', {
83
+ form: requestData,
84
+ });
85
+ const data = response.body;
86
+ if (data.showapi_res_code !== API_SUCCESS_CODE) {
87
+ throw new APIError(`Failed to print from URL: ${data.showapi_res_error}`, data.showapi_res_code, data.showapi_res_error);
88
+ }
89
+ return data;
90
+ }
91
+ catch (error) {
92
+ if (error instanceof APIError) {
93
+ throw error;
94
+ }
95
+ throw new NetworkError(`Network error while printing from URL: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
96
+ }
97
+ }
98
+ /**
99
+ * Prints content from HTML source
100
+ *
101
+ * HTML must have inline CSS and complete image URLs.
102
+ * The HTML is automatically converted to GBK Base64 and URL encoded.
103
+ *
104
+ * @param client - Got HTTP client instance
105
+ * @param ak - Access Key
106
+ * @param htmlSource - HTML source code
107
+ * @param memobirdID - Device ID
108
+ * @param userID - User ID from binding
109
+ * @returns Promise resolving to print response
110
+ * @throws {APIError} If API returns error response
111
+ * @throws {NetworkError} If network request fails
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const html = '<html><body><h1>Hello</h1></body></html>';
116
+ * const response = await printFromHtml(client, ak, html, 'device-id', 123);
117
+ * ```
118
+ */
119
+ export async function printFromHtml(client, ak, htmlSource, memobirdID, userID) {
120
+ try {
121
+ // Convert HTML to GBK Base64, then URL encode
122
+ const gbkBase64 = textToGBKBase64(htmlSource);
123
+ const urlEncoded = encodeURIComponent(gbkBase64);
124
+ const requestData = {
125
+ ak,
126
+ timestamp: generateTimestamp(),
127
+ printHtml: urlEncoded,
128
+ memobirdID,
129
+ userID,
130
+ };
131
+ const response = await client.post('printpaperFromHtml', {
132
+ form: requestData,
133
+ });
134
+ const data = response.body;
135
+ if (data.showapi_res_code !== API_SUCCESS_CODE) {
136
+ throw new APIError(`Failed to print from HTML: ${data.showapi_res_error}`, data.showapi_res_code, data.showapi_res_error);
137
+ }
138
+ return data;
139
+ }
140
+ catch (error) {
141
+ if (error instanceof APIError) {
142
+ throw error;
143
+ }
144
+ throw new NetworkError(`Network error while printing from HTML: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
145
+ }
146
+ }
147
+ //# sourceMappingURL=print.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print.js","sourceRoot":"","sources":["../../src/api/print.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAW,EACX,EAAU,EACV,YAAoB,EACpB,UAAkB,EAClB,MAAc;IAEd,IAAI,CAAC;QACH,MAAM,WAAW,GAAiB;YAChC,EAAE;YACF,SAAS,EAAE,iBAAiB,EAAE;YAC9B,YAAY;YACZ,UAAU;YACV,MAAM;SACP,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAgB,YAAY,EAAE;YAC9D,IAAI,EAAE,WAAW;SAClB,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;QAE3B,IAAI,IAAI,CAAC,gBAAgB,KAAK,gBAAgB,EAAE,CAAC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ACd,CAAC;QACD,MAAM,IAAI,YAAY,CACpB,2CAA2C,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACnG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAC3C,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { Got } from 'got';
2
+ import type { PrintStatusResponse } from '../types/index.js';
3
+ /**
4
+ * Gets the print status of a submitted print job
5
+ *
6
+ * @param client - Got HTTP client instance
7
+ * @param ak - Access Key
8
+ * @param printcontentid - Print content ID from print response
9
+ * @returns Promise resolving to print status response
10
+ * @throws {APIError} If API returns error response
11
+ * @throws {NetworkError} If network request fails
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const status = await getPrintStatus(client, ak, '12345');
16
+ * if (status.printflag === 1) {
17
+ * console.log('Print completed');
18
+ * } else {
19
+ * console.log('Print pending or failed');
20
+ * }
21
+ * ```
22
+ */
23
+ export declare function getPrintStatus(client: Got, ak: string, printcontentid: string): Promise<PrintStatusResponse>;
24
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/api/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,KAAK,EAAsB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAKjF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,GAAG,EACX,EAAE,EAAE,MAAM,EACV,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,mBAAmB,CAAC,CAgC9B"}
@@ -0,0 +1,47 @@
1
+ import { APIError, NetworkError } from '../errors/index.js';
2
+ import { generateTimestamp } from '../utils/index.js';
3
+ import { API_SUCCESS_CODE } from '../constants.js';
4
+ /**
5
+ * Gets the print status of a submitted print job
6
+ *
7
+ * @param client - Got HTTP client instance
8
+ * @param ak - Access Key
9
+ * @param printcontentid - Print content ID from print response
10
+ * @returns Promise resolving to print status response
11
+ * @throws {APIError} If API returns error response
12
+ * @throws {NetworkError} If network request fails
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const status = await getPrintStatus(client, ak, '12345');
17
+ * if (status.printflag === 1) {
18
+ * console.log('Print completed');
19
+ * } else {
20
+ * console.log('Print pending or failed');
21
+ * }
22
+ * ```
23
+ */
24
+ export async function getPrintStatus(client, ak, printcontentid) {
25
+ try {
26
+ const requestData = {
27
+ ak,
28
+ timestamp: generateTimestamp(),
29
+ printcontentid,
30
+ };
31
+ const response = await client.post('getprintstatus', {
32
+ form: requestData,
33
+ });
34
+ const data = response.body;
35
+ if (data.showapi_res_code !== API_SUCCESS_CODE) {
36
+ throw new APIError(`Failed to get print status: ${data.showapi_res_error}`, data.showapi_res_code, data.showapi_res_error);
37
+ }
38
+ return data;
39
+ }
40
+ catch (error) {
41
+ if (error instanceof APIError) {
42
+ throw error;
43
+ }
44
+ throw new NetworkError(`Network error while getting print status: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
45
+ }
46
+ }
47
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/api/status.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAW,EACX,EAAU,EACV,cAAsB;IAEtB,IAAI,CAAC;QACH,MAAM,WAAW,GAAuB;YACtC,EAAE;YACF,SAAS,EAAE,iBAAiB,EAAE;YAC9B,cAAc;SACf,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAsB,gBAAgB,EAAE;YACxE,IAAI,EAAE,WAAW;SAClB,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;QAE3B,IAAI,IAAI,CAAC,gBAAgB,KAAK,gBAAgB,EAAE,CAAC;YAC/C,MAAM,IAAI,QAAQ,CAChB,+BAA+B,IAAI,CAAC,iBAAiB,EAAE,EACvD,IAAI,CAAC,gBAAgB,EACrB,IAAI,CAAC,iBAAiB,CACvB,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;YAC9B,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,IAAI,YAAY,CACpB,6CAA6C,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACrG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAC3C,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,204 @@
1
+ import type { MemobirdConfig, BindUserResponse, PrintResponse, PrintStatusResponse, ConvertImageResponse } from './types/index.js';
2
+ /**
3
+ * Main Memobird SDK client for interacting with the Memobird API
4
+ *
5
+ * This class provides a convenient interface for all Memobird operations including
6
+ * user binding, printing text/images, checking print status, and converting images.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const client = new MemobirdClient({
11
+ * ak: 'your-access-key-from-open.memobird.cn'
12
+ * });
13
+ *
14
+ * // Bind user to device
15
+ * const bindResult = await client.bindUser('device-id', 'user-123');
16
+ *
17
+ * // Print text (auto-converts to GBK)
18
+ * await client.printText('Hello World!', 'device-id', bindResult.showapi_userid!);
19
+ * ```
20
+ */
21
+ export declare class MemobirdClient {
22
+ private config;
23
+ private httpClient;
24
+ private retryStrategy;
25
+ /**
26
+ * Creates a new MemobirdClient instance
27
+ *
28
+ * @param config - SDK configuration options
29
+ * @param config.ak - Access Key from open.memobird.cn (required)
30
+ * @param config.baseUrl - Base URL for API (default: 'http://open.memobird.cn/home')
31
+ * @param config.timeout - Request timeout in ms (default: 30000)
32
+ * @param config.retry - Retry configuration
33
+ * @param config.httpOptions - Additional got HTTP client options
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const client = new MemobirdClient({
38
+ * ak: 'your-access-key',
39
+ * timeout: 60000,
40
+ * retry: {
41
+ * maxRetries: 5,
42
+ * initialDelay: 2000
43
+ * }
44
+ * });
45
+ * ```
46
+ */
47
+ constructor(config: MemobirdConfig);
48
+ /**
49
+ * Binds a user identifier to a Memobird device
50
+ *
51
+ * This creates an association between your user ID and a physical device.
52
+ * The device ID can be obtained by double-clicking the physical device,
53
+ * which will print out the device ID.
54
+ *
55
+ * @param memobirdID - Device ID from the physical device
56
+ * @param useridentifying - Your unique user identifier
57
+ * @returns Promise resolving to binding response with showapi_userid
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const response = await client.bindUser('fb93bfff504c020a', 'user-123');
62
+ * console.log('User ID:', response.showapi_userid);
63
+ * ```
64
+ */
65
+ bindUser(memobirdID: string, useridentifying: string): Promise<BindUserResponse>;
66
+ /**
67
+ * Prints text content to a Memobird device
68
+ *
69
+ * Text is automatically converted from UTF-8 to GBK Base64 encoding as required by the API.
70
+ * Supports Chinese characters and other multi-byte text.
71
+ *
72
+ * @param text - Text content to print
73
+ * @param memobirdID - Device ID
74
+ * @param userID - User ID from binding response
75
+ * @returns Promise resolving to print response with printcontentid
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const response = await client.printText(
80
+ * '你好世界!Hello World!',
81
+ * 'device-id',
82
+ * 123
83
+ * );
84
+ * console.log('Print ID:', response.printcontentid);
85
+ * ```
86
+ */
87
+ printText(text: string, memobirdID: string, userID: number): Promise<PrintResponse>;
88
+ /**
89
+ * Prints image content to a Memobird device
90
+ *
91
+ * The image must be in monochrome bitmap format. Use {@link convertImageToMonochrome}
92
+ * to convert JPG/PNG images to the required format first.
93
+ *
94
+ * @param base64Image - Monochrome bitmap Base64 string
95
+ * @param memobirdID - Device ID
96
+ * @param userID - User ID from binding response
97
+ * @returns Promise resolving to print response
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * // First convert image
102
+ * const converted = await client.convertImageToMonochrome(jpgBase64);
103
+ *
104
+ * // Then print
105
+ * const response = await client.printImage(
106
+ * converted.result!,
107
+ * 'device-id',
108
+ * 123
109
+ * );
110
+ * ```
111
+ */
112
+ printImage(base64Image: string, memobirdID: string, userID: number): Promise<PrintResponse>;
113
+ /**
114
+ * Prints content from a web URL
115
+ *
116
+ * Note: This works best with static or server-rendered pages. Pages rendered
117
+ * with AJAX may not work properly. Images must use complete URLs and CSS should
118
+ * be inline for best results.
119
+ *
120
+ * @param url - URL of the web page to print
121
+ * @param memobirdID - Device ID
122
+ * @param userID - User ID from binding response
123
+ * @returns Promise resolving to print response
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const response = await client.printFromUrl(
128
+ * 'https://example.com/page',
129
+ * 'device-id',
130
+ * 123
131
+ * );
132
+ * ```
133
+ */
134
+ printFromUrl(url: string, memobirdID: string, userID: number): Promise<PrintResponse>;
135
+ /**
136
+ * Prints content from HTML source
137
+ *
138
+ * The HTML is automatically converted to GBK Base64 and URL encoded.
139
+ * For best results:
140
+ * - Use inline CSS (no external stylesheets)
141
+ * - Use complete URLs for images (not relative paths)
142
+ * - Keep content size reasonable
143
+ *
144
+ * @param html - HTML source code
145
+ * @param memobirdID - Device ID
146
+ * @param userID - User ID from binding response
147
+ * @returns Promise resolving to print response
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const html = `
152
+ * <html>
153
+ * <body style="font-family: sans-serif;">
154
+ * <h1>Hello World</h1>
155
+ * <p>This is a test.</p>
156
+ * </body>
157
+ * </html>
158
+ * `;
159
+ * const response = await client.printFromHtml(html, 'device-id', 123);
160
+ * ```
161
+ */
162
+ printFromHtml(html: string, memobirdID: string, userID: number): Promise<PrintResponse>;
163
+ /**
164
+ * Gets the print status of a submitted print job
165
+ *
166
+ * @param printcontentid - Print content ID from print response (can be string or number)
167
+ * @returns Promise resolving to print status response
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const printResponse = await client.printText('Hello', 'device-id', 123);
172
+ * const status = await client.getPrintStatus(printResponse.printcontentid!);
173
+ *
174
+ * if (status.printflag === 1) {
175
+ * console.log('Print completed successfully');
176
+ * } else {
177
+ * console.log('Print pending or failed');
178
+ * }
179
+ * ```
180
+ */
181
+ getPrintStatus(printcontentid: string | number): Promise<PrintStatusResponse>;
182
+ /**
183
+ * Converts a JPG or PNG image to monochrome bitmap format
184
+ *
185
+ * The Memobird printer requires images in monochrome bitmap format.
186
+ * Use this method to convert standard images before printing.
187
+ * For best results, images should be 384px wide (the printer paper width).
188
+ *
189
+ * @param base64Image - JPG or PNG image as Base64 string
190
+ * @returns Promise resolving to converted image response with monochrome bitmap
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * const jpgBase64 = '...'; // Your JPG image
195
+ * const response = await client.convertImageToMonochrome(jpgBase64);
196
+ * const monochromeBase64 = response.result!;
197
+ *
198
+ * // Now print the converted image
199
+ * await client.printImage(monochromeBase64, 'device-id', 123);
200
+ * ```
201
+ */
202
+ convertImageToMonochrome(base64Image: string): Promise<ConvertImageResponse>;
203
+ }
204
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAS1B;;;;;;;;;;;;;;;;;;GAkBG;AACH,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