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,122 @@
1
+ /**
2
+ * Base response structure for all API calls
3
+ */
4
+ export interface BaseResponse {
5
+ /** Return code, 1 for success, other values for failure */
6
+ showapi_res_code: number;
7
+ /** Error message when showapi_res_code !== 1 */
8
+ showapi_res_error: string;
9
+ }
10
+ /**
11
+ * Request parameters for binding a user to a device
12
+ */
13
+ export interface BindUserRequest {
14
+ /** Access Key */
15
+ ak: string;
16
+ /** Timestamp in format 'YYYY-MM-DD HH:mm:ss' */
17
+ timestamp: string;
18
+ /** Memobird device ID (obtained by double-clicking the device) */
19
+ memobirdID: string;
20
+ /** User unique identifier */
21
+ useridentifying: string;
22
+ }
23
+ /**
24
+ * Response from binding a user to a device
25
+ */
26
+ export interface BindUserResponse extends BaseResponse {
27
+ /** User ID returned after successful binding */
28
+ showapi_userid?: number;
29
+ }
30
+ /**
31
+ * Request parameters for printing content
32
+ */
33
+ export interface PrintRequest {
34
+ /** Access Key */
35
+ ak: string;
36
+ /** Timestamp in format 'YYYY-MM-DD HH:mm:ss' */
37
+ timestamp: string;
38
+ /** Print content in format 'T:base64text' or 'P:base64image' */
39
+ printcontent: string;
40
+ /** Memobird device ID */
41
+ memobirdID: string;
42
+ /** User ID from binding response */
43
+ userID: number;
44
+ }
45
+ /**
46
+ * Response from print operations
47
+ */
48
+ export interface PrintResponse extends BaseResponse {
49
+ /** 1 if printed, 0 or other values if not printed */
50
+ result?: number;
51
+ /** Unique ID for the print content */
52
+ printcontentid?: number;
53
+ /** Device GUID */
54
+ smartGuid?: string;
55
+ }
56
+ /**
57
+ * Request parameters for checking print status
58
+ */
59
+ export interface PrintStatusRequest {
60
+ /** Access Key */
61
+ ak: string;
62
+ /** Timestamp in format 'YYYY-MM-DD HH:mm:ss' */
63
+ timestamp: string;
64
+ /** Print content ID from print response */
65
+ printcontentid: string;
66
+ }
67
+ /**
68
+ * Response from print status check
69
+ */
70
+ export interface PrintStatusResponse extends BaseResponse {
71
+ /** 1 if printed, 0 or other values if not printed */
72
+ printflag?: number;
73
+ /** Print content ID */
74
+ printcontentID?: string;
75
+ }
76
+ /**
77
+ * Request parameters for converting image to monochrome bitmap
78
+ */
79
+ export interface ConvertImageRequest {
80
+ /** Access Key */
81
+ ak: string;
82
+ /** JPG or PNG image as Base64 string */
83
+ imgBase64String: string;
84
+ }
85
+ /**
86
+ * Response from image conversion
87
+ */
88
+ export interface ConvertImageResponse extends BaseResponse {
89
+ /** Monochrome bitmap Base64 string ready for printing */
90
+ result?: string;
91
+ }
92
+ /**
93
+ * Request parameters for printing from URL
94
+ */
95
+ export interface PrintFromUrlRequest {
96
+ /** Access Key */
97
+ ak: string;
98
+ /** Timestamp in format 'YYYY-MM-DD HH:mm:ss' */
99
+ timestamp: string;
100
+ /** URL of the web page to print */
101
+ printUrl: string;
102
+ /** Memobird device ID */
103
+ memobirdID: string;
104
+ /** User ID from binding response */
105
+ userID: number;
106
+ }
107
+ /**
108
+ * Request parameters for printing from HTML
109
+ */
110
+ export interface PrintFromHtmlRequest {
111
+ /** Access Key */
112
+ ak: string;
113
+ /** Timestamp in format 'YYYY-MM-DD HH:mm:ss' */
114
+ timestamp: string;
115
+ /** HTML source as GBK Base64 + URL encoded */
116
+ printHtml: string;
117
+ /** Memobird device ID */
118
+ memobirdID: string;
119
+ /** User ID from binding response */
120
+ userID: number;
121
+ }
122
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,gBAAgB,EAAE,MAAM,CAAC;IAEzB,gDAAgD;IAChD,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,iBAAiB;IACjB,EAAE,EAAE,MAAM,CAAC;IAEX,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAElB,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IAEnB,6BAA6B;IAC7B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,iBAAiB;IACjB,EAAE,EAAE,MAAM,CAAC;IAEX,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAElB,gEAAgE;IAChE,YAAY,EAAE,MAAM,CAAC;IAErB,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IAEnB,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,sCAAsC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,kBAAkB;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iBAAiB;IACjB,EAAE,EAAE,MAAM,CAAC;IAEX,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAElB,2CAA2C;IAC3C,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,uBAAuB;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iBAAiB;IACjB,EAAE,EAAE,MAAM,CAAC;IAEX,wCAAwC;IACxC,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iBAAiB;IACjB,EAAE,EAAE,MAAM,CAAC;IAEX,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAElB,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IAEjB,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IAEnB,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,iBAAiB;IACjB,EAAE,EAAE,MAAM,CAAC;IAEX,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAElB,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAElB,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IAEnB,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Content type for print operations
3
+ */
4
+ export type ContentType = 'text' | 'image';
5
+ /**
6
+ * Print status values
7
+ */
8
+ export declare enum PrintStatus {
9
+ /** Print completed successfully */
10
+ PRINTED = 1,
11
+ /** Print pending or failed */
12
+ PENDING = 0
13
+ }
14
+ /**
15
+ * API success code
16
+ */
17
+ export declare const API_SUCCESS_CODE = 1;
18
+ /**
19
+ * Content item for mixed content printing
20
+ */
21
+ export interface ContentItem {
22
+ /** Type of content */
23
+ type: ContentType;
24
+ /** Content string (text or base64 image) */
25
+ content: string;
26
+ }
27
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C;;GAEG;AACH,oBAAY,WAAW;IACrB,mCAAmC;IACnC,OAAO,IAAI;IACX,8BAA8B;IAC9B,OAAO,IAAI;CACZ;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,sBAAsB;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Print status values
3
+ */
4
+ export var PrintStatus;
5
+ (function (PrintStatus) {
6
+ /** Print completed successfully */
7
+ PrintStatus[PrintStatus["PRINTED"] = 1] = "PRINTED";
8
+ /** Print pending or failed */
9
+ PrintStatus[PrintStatus["PENDING"] = 0] = "PENDING";
10
+ })(PrintStatus || (PrintStatus = {}));
11
+ /**
12
+ * API success code
13
+ */
14
+ export const API_SUCCESS_CODE = 1;
15
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,mCAAmC;IACnC,mDAAW,CAAA;IACX,8BAA8B;IAC9B,mDAAW,CAAA;AACb,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { Options } from 'got';
2
+ /**
3
+ * Retry configuration for failed requests
4
+ */
5
+ export interface RetryConfig {
6
+ /** Maximum number of retry attempts (default: 3) */
7
+ maxRetries?: number;
8
+ /** Initial delay in milliseconds before first retry (default: 1000) */
9
+ initialDelay?: number;
10
+ /** Multiplier for exponential backoff (default: 2) */
11
+ backoffMultiplier?: number;
12
+ /** Maximum delay in milliseconds between retries (default: 10000) */
13
+ maxDelay?: number;
14
+ /** HTTP status codes that should trigger a retry (default: [408, 429, 500, 502, 503, 504]) */
15
+ retryStatusCodes?: number[];
16
+ }
17
+ /**
18
+ * Memobird SDK configuration
19
+ */
20
+ export interface MemobirdConfig {
21
+ /** Access Key obtained from open.memobird.cn */
22
+ ak: string;
23
+ /** Base URL for API requests (default: 'http://open.memobird.cn/home') */
24
+ baseUrl?: string;
25
+ /** HTTP request timeout in milliseconds (default: 30000) */
26
+ timeout?: number;
27
+ /** Retry configuration for failed requests */
28
+ retry?: RetryConfig;
29
+ /** Custom got HTTP client options */
30
+ httpOptions?: Partial<Options>;
31
+ }
32
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,sDAAsD;IACtD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,8FAA8F;IAC9F,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,EAAE,EAAE,MAAM,CAAC;IAEX,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,WAAW,CAAC;IAEpB,qCAAqC;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CAChC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Type definitions for Memobird SDK
3
+ * @module types
4
+ */
5
+ export * from './api.js';
6
+ export * from './common.js';
7
+ export * from './config.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Type definitions for Memobird SDK
3
+ * @module types
4
+ */
5
+ export * from './api.js';
6
+ export * from './common.js';
7
+ export * from './config.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,49 @@
1
+ import type { ContentItem } from '../types/index.js';
2
+ /**
3
+ * Formats text content with T: prefix for printing
4
+ *
5
+ * Automatically converts UTF-8 text to GBK Base64 encoding as required by the API.
6
+ *
7
+ * @param text - Text content to print
8
+ * @returns Formatted print content (T:base64...)
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const formatted = formatTextContent('Hello World');
13
+ * // Returns: 'T:SGVsbG8gV29ybGQ='
14
+ * ```
15
+ */
16
+ export declare function formatTextContent(text: string): string;
17
+ /**
18
+ * Formats image content with P: prefix for printing
19
+ *
20
+ * @param base64Image - Monochrome bitmap Base64 image (should be pre-converted)
21
+ * @returns Formatted print content (P:base64...)
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const formatted = formatImageContent(monochromeBase64);
26
+ * // Returns: 'P:Qk0OAgAAAAAAAD4A...'
27
+ * ```
28
+ */
29
+ export declare function formatImageContent(base64Image: string): string;
30
+ /**
31
+ * Formats mixed content (text and images) for printing
32
+ *
33
+ * Combines multiple text and image items with pipe (|) separator.
34
+ *
35
+ * @param items - Array of content items with type and content
36
+ * @returns Formatted print content with T: and P: prefixes
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const formatted = formatMixedContent([
41
+ * { type: 'text', content: 'Hello' },
42
+ * { type: 'image', content: 'base64imagedata' },
43
+ * { type: 'text', content: 'World' }
44
+ * ]);
45
+ * // Returns: 'T:SGVsbG8=|P:base64imagedata|T:V29ybGQ='
46
+ * ```
47
+ */
48
+ export declare function formatMixedContent(items: ContentItem[]): string;
49
+ //# sourceMappingURL=content-formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-formatter.d.ts","sourceRoot":"","sources":["../../src/utils/content-formatter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAU/D"}
@@ -0,0 +1,65 @@
1
+ import { textToGBKBase64 } from './encoding.js';
2
+ /**
3
+ * Formats text content with T: prefix for printing
4
+ *
5
+ * Automatically converts UTF-8 text to GBK Base64 encoding as required by the API.
6
+ *
7
+ * @param text - Text content to print
8
+ * @returns Formatted print content (T:base64...)
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const formatted = formatTextContent('Hello World');
13
+ * // Returns: 'T:SGVsbG8gV29ybGQ='
14
+ * ```
15
+ */
16
+ export function formatTextContent(text) {
17
+ const gbkBase64 = textToGBKBase64(text);
18
+ return `T:${gbkBase64}`;
19
+ }
20
+ /**
21
+ * Formats image content with P: prefix for printing
22
+ *
23
+ * @param base64Image - Monochrome bitmap Base64 image (should be pre-converted)
24
+ * @returns Formatted print content (P:base64...)
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const formatted = formatImageContent(monochromeBase64);
29
+ * // Returns: 'P:Qk0OAgAAAAAAAD4A...'
30
+ * ```
31
+ */
32
+ export function formatImageContent(base64Image) {
33
+ return `P:${base64Image}`;
34
+ }
35
+ /**
36
+ * Formats mixed content (text and images) for printing
37
+ *
38
+ * Combines multiple text and image items with pipe (|) separator.
39
+ *
40
+ * @param items - Array of content items with type and content
41
+ * @returns Formatted print content with T: and P: prefixes
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const formatted = formatMixedContent([
46
+ * { type: 'text', content: 'Hello' },
47
+ * { type: 'image', content: 'base64imagedata' },
48
+ * { type: 'text', content: 'World' }
49
+ * ]);
50
+ * // Returns: 'T:SGVsbG8=|P:base64imagedata|T:V29ybGQ='
51
+ * ```
52
+ */
53
+ export function formatMixedContent(items) {
54
+ return items
55
+ .map((item) => {
56
+ if (item.type === 'text') {
57
+ return formatTextContent(item.content);
58
+ }
59
+ else {
60
+ return formatImageContent(item.content);
61
+ }
62
+ })
63
+ .join('|');
64
+ }
65
+ //# sourceMappingURL=content-formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-formatter.js","sourceRoot":"","sources":["../../src/utils/content-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,KAAK,SAAS,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB;IACpD,OAAO,KAAK,WAAW,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAoB;IACrD,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACzB,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Converts UTF-8 text to GBK encoded Base64 string
3
+ *
4
+ * This is required for Chinese characters in print content according to Memobird API documentation.
5
+ * The API expects Chinese text to be GBK encoded before Base64 conversion.
6
+ *
7
+ * @param text - UTF-8 text to convert
8
+ * @returns GBK Base64 encoded string
9
+ * @throws {ValidationError} If encoding fails
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const encoded = textToGBKBase64('你好世界');
14
+ * console.log(encoded); // Outputs GBK Base64 string
15
+ * ```
16
+ */
17
+ export declare function textToGBKBase64(text: string): string;
18
+ /**
19
+ * Decodes GBK Base64 string back to UTF-8 text
20
+ *
21
+ * @param gbkBase64 - GBK Base64 encoded string
22
+ * @returns UTF-8 decoded text
23
+ * @throws {ValidationError} If decoding fails
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const decoded = gbkBase64ToText(encodedString);
28
+ * console.log(decoded); // Outputs: '你好世界'
29
+ * ```
30
+ */
31
+ export declare function gbkBase64ToText(gbkBase64: string): string;
32
+ //# sourceMappingURL=encoding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/utils/encoding.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUpD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAUzD"}
@@ -0,0 +1,50 @@
1
+ import iconv from 'iconv-lite';
2
+ import { ValidationError } from '../errors/index.js';
3
+ /**
4
+ * Converts UTF-8 text to GBK encoded Base64 string
5
+ *
6
+ * This is required for Chinese characters in print content according to Memobird API documentation.
7
+ * The API expects Chinese text to be GBK encoded before Base64 conversion.
8
+ *
9
+ * @param text - UTF-8 text to convert
10
+ * @returns GBK Base64 encoded string
11
+ * @throws {ValidationError} If encoding fails
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const encoded = textToGBKBase64('你好世界');
16
+ * console.log(encoded); // Outputs GBK Base64 string
17
+ * ```
18
+ */
19
+ export function textToGBKBase64(text) {
20
+ try {
21
+ const gbkBuffer = iconv.encode(text, 'gbk');
22
+ return gbkBuffer.toString('base64');
23
+ }
24
+ catch (error) {
25
+ throw new ValidationError(`Failed to encode text to GBK Base64: ${error instanceof Error ? error.message : String(error)}`, 'text');
26
+ }
27
+ }
28
+ /**
29
+ * Decodes GBK Base64 string back to UTF-8 text
30
+ *
31
+ * @param gbkBase64 - GBK Base64 encoded string
32
+ * @returns UTF-8 decoded text
33
+ * @throws {ValidationError} If decoding fails
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const decoded = gbkBase64ToText(encodedString);
38
+ * console.log(decoded); // Outputs: '你好世界'
39
+ * ```
40
+ */
41
+ export function gbkBase64ToText(gbkBase64) {
42
+ try {
43
+ const buffer = Buffer.from(gbkBase64, 'base64');
44
+ return iconv.decode(buffer, 'gbk');
45
+ }
46
+ catch (error) {
47
+ throw new ValidationError(`Failed to decode GBK Base64 to text: ${error instanceof Error ? error.message : String(error)}`, 'gbkBase64');
48
+ }
49
+ }
50
+ //# sourceMappingURL=encoding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/utils/encoding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5C,OAAO,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,eAAe,CACvB,wCAAwC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAChG,MAAM,CACP,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,eAAe,CAAC,SAAiB;IAC/C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAChD,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,eAAe,CACvB,wCAAwC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAChG,WAAW,CACZ,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Validates if a string is a valid Base64 encoded string
3
+ *
4
+ * @param base64String - String to validate
5
+ * @returns true if valid Base64
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * isValidBase64Image('SGVsbG8gV29ybGQ='); // true
10
+ * isValidBase64Image('not-base64!@#'); // false
11
+ * ```
12
+ */
13
+ export declare function isValidBase64Image(base64String: string): boolean;
14
+ /**
15
+ * Strips Base64 data URL prefix if present
16
+ *
17
+ * Removes 'data:image/...;base64,' prefix from data URLs.
18
+ *
19
+ * @param base64String - Base64 string (may include data URL prefix)
20
+ * @returns Clean Base64 string without prefix
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * stripDataUrlPrefix('data:image/png;base64,iVBORw0KG...');
25
+ * // Returns: 'iVBORw0KG...'
26
+ * ```
27
+ */
28
+ export declare function stripDataUrlPrefix(base64String: string): string;
29
+ /**
30
+ * Reads an image file and converts it to Base64
31
+ *
32
+ * @param filePath - Path to image file
33
+ * @returns Promise resolving to Base64 encoded image
34
+ * @throws {ValidationError} If file cannot be read
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const base64 = await imageFileToBase64('./image.jpg');
39
+ * ```
40
+ */
41
+ export declare function imageFileToBase64(filePath: string): Promise<string>;
42
+ //# sourceMappingURL=image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/utils/image.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAGhE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAG/D;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAUzE"}
@@ -0,0 +1,58 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import { ValidationError } from '../errors/index.js';
3
+ /**
4
+ * Validates if a string is a valid Base64 encoded string
5
+ *
6
+ * @param base64String - String to validate
7
+ * @returns true if valid Base64
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * isValidBase64Image('SGVsbG8gV29ybGQ='); // true
12
+ * isValidBase64Image('not-base64!@#'); // false
13
+ * ```
14
+ */
15
+ export function isValidBase64Image(base64String) {
16
+ const base64Pattern = /^[A-Za-z0-9+/]+=*$/;
17
+ return base64Pattern.test(base64String) && base64String.length % 4 === 0;
18
+ }
19
+ /**
20
+ * Strips Base64 data URL prefix if present
21
+ *
22
+ * Removes 'data:image/...;base64,' prefix from data URLs.
23
+ *
24
+ * @param base64String - Base64 string (may include data URL prefix)
25
+ * @returns Clean Base64 string without prefix
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * stripDataUrlPrefix('data:image/png;base64,iVBORw0KG...');
30
+ * // Returns: 'iVBORw0KG...'
31
+ * ```
32
+ */
33
+ export function stripDataUrlPrefix(base64String) {
34
+ const dataUrlPattern = /^data:image\/[a-z]+;base64,/i;
35
+ return base64String.replace(dataUrlPattern, '');
36
+ }
37
+ /**
38
+ * Reads an image file and converts it to Base64
39
+ *
40
+ * @param filePath - Path to image file
41
+ * @returns Promise resolving to Base64 encoded image
42
+ * @throws {ValidationError} If file cannot be read
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const base64 = await imageFileToBase64('./image.jpg');
47
+ * ```
48
+ */
49
+ export async function imageFileToBase64(filePath) {
50
+ try {
51
+ const buffer = await fs.readFile(filePath);
52
+ return buffer.toString('base64');
53
+ }
54
+ catch (error) {
55
+ throw new ValidationError(`Failed to read image file: ${error instanceof Error ? error.message : String(error)}`, 'filePath');
56
+ }
57
+ }
58
+ //# sourceMappingURL=image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/utils/image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAC,YAAoB;IACrD,MAAM,aAAa,GAAG,oBAAoB,CAAC;IAC3C,OAAO,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAAC,YAAoB;IACrD,MAAM,cAAc,GAAG,8BAA8B,CAAC;IACtD,OAAO,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,QAAgB;IACtD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC3C,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,eAAe,CACvB,8BAA8B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EACtF,UAAU,CACX,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Utility functions for Memobird SDK
3
+ * @module utils
4
+ */
5
+ export * from './encoding.js';
6
+ export * from './timestamp.js';
7
+ export * from './content-formatter.js';
8
+ export * from './image.js';
9
+ export * from './retry.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Utility functions for Memobird SDK
3
+ * @module utils
4
+ */
5
+ export * from './encoding.js';
6
+ export * from './timestamp.js';
7
+ export * from './content-formatter.js';
8
+ export * from './image.js';
9
+ export * from './retry.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}